Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Sep 9, 2022
1 parent bae48b5 commit 6ea4ae6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
33 changes: 18 additions & 15 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -241,40 +241,43 @@ ERC721Test:testTransferFromApproveAll(uint256,address) (runs: 256, μ: 93182, ~:
ERC721Test:testTransferFromSelf() (gas: 64776)
ERC721Test:testTransferFromSelf(uint256,address) (runs: 256, μ: 65061, ~: 65061)
FixedPointMathLibTest:testDivWadDown() (gas: 864)
FixedPointMathLibTest:testDivWadDown(uint256,uint256) (runs: 256, μ: 670, ~: 776)
FixedPointMathLibTest:testDivWadDownEdgeCases() (gas: 423)
FixedPointMathLibTest:testDivWadUp() (gas: 981)
FixedPointMathLibTest:testDivWadDown(uint256,uint256) (runs: 256, μ: 714, ~: 820)
FixedPointMathLibTest:testDivWadDownEdgeCases() (gas: 446)
FixedPointMathLibTest:testDivWadUp() (gas: 1003)
FixedPointMathLibTest:testDivWadUp(uint256,uint256) (runs: 256, μ: 845, ~: 1016)
FixedPointMathLibTest:testDivWadUpEdgeCases() (gas: 482)
FixedPointMathLibTest:testDivWadUpEdgeCases() (gas: 504)
FixedPointMathLibTest:testFailDivWadDownOverflow(uint256,uint256) (runs: 256, μ: 423, ~: 397)
FixedPointMathLibTest:testFailDivWadDownZeroDenominator() (gas: 362)
FixedPointMathLibTest:testFailDivWadDownZeroDenominator(uint256) (runs: 256, μ: 419, ~: 419)
FixedPointMathLibTest:testFailDivWadUpOverflow(uint256,uint256) (runs: 256, μ: 401, ~: 375)
FixedPointMathLibTest:testFailDivWadDownZeroDenominator() (gas: 320)
FixedPointMathLibTest:testFailDivWadDownZeroDenominator(uint256) (runs: 256, μ: 397, ~: 397)
FixedPointMathLibTest:testFailDivWadUpOverflow(uint256,uint256) (runs: 256, μ: 423, ~: 397)
FixedPointMathLibTest:testFailDivWadUpZeroDenominator() (gas: 342)
FixedPointMathLibTest:testFailDivWadUpZeroDenominator(uint256) (runs: 256, μ: 396, ~: 396)
FixedPointMathLibTest:testFailMulDivDownOverflow(uint256,uint256,uint256) (runs: 256, μ: 460, ~: 437)
FixedPointMathLibTest:testFailMulDivDownZeroDenominator() (gas: 316)
FixedPointMathLibTest:testFailMulDivDownZeroDenominator(uint256,uint256) (runs: 256, μ: 395, ~: 395)
FixedPointMathLibTest:testFailMulDivUpOverflow(uint256,uint256,uint256) (runs: 256, μ: 482, ~: 459)
FixedPointMathLibTest:testFailMulDivUpOverflow(uint256,uint256,uint256) (runs: 256, μ: 438, ~: 415)
FixedPointMathLibTest:testFailMulDivUpZeroDenominator() (gas: 317)
FixedPointMathLibTest:testFailMulDivUpZeroDenominator(uint256,uint256) (runs: 256, μ: 394, ~: 394)
FixedPointMathLibTest:testFailMulWadDownOverflow(uint256,uint256) (runs: 256, μ: 380, ~: 342)
FixedPointMathLibTest:testFailMulWadUpOverflow(uint256,uint256) (runs: 256, μ: 380, ~: 342)
FixedPointMathLibTest:testFailMulDivUpZeroDenominator(uint256,uint256) (runs: 256, μ: 416, ~: 416)
FixedPointMathLibTest:testFailMulWadDownOverflow(uint256,uint256) (runs: 256, μ: 425, ~: 387)
FixedPointMathLibTest:testFailMulWadUpOverflow(uint256,uint256) (runs: 256, μ: 425, ~: 387)
FixedPointMathLibTest:testMulDivDown() (gas: 1861)
FixedPointMathLibTest:testMulDivDown(uint256,uint256,uint256) (runs: 256, μ: 669, ~: 771)
FixedPointMathLibTest:testMulDivDownEdgeCases() (gas: 751)
FixedPointMathLibTest:testMulDivUp() (gas: 2273)
FixedPointMathLibTest:testMulDivUp(uint256,uint256,uint256) (runs: 256, μ: 835, ~: 1054)
FixedPointMathLibTest:testMulDivUpEdgeCases() (gas: 846)
FixedPointMathLibTest:testMulWadDown() (gas: 821)
FixedPointMathLibTest:testMulDivUpEdgeCases() (gas: 823)
FixedPointMathLibTest:testMulWadDown() (gas: 844)
FixedPointMathLibTest:testMulWadDown(uint256,uint256) (runs: 256, μ: 683, ~: 810)
FixedPointMathLibTest:testMulWadDownEdgeCases() (gas: 886)
FixedPointMathLibTest:testMulWadDownEdgeCases() (gas: 843)
FixedPointMathLibTest:testMulWadUp() (gas: 959)
FixedPointMathLibTest:testMulWadUp(uint256,uint256) (runs: 256, μ: 806, ~: 1051)
FixedPointMathLibTest:testMulWadUpEdgeCases() (gas: 1002)
FixedPointMathLibTest:testRPow() (gas: 2142)
FixedPointMathLibTest:testSqrt() (gas: 521)
FixedPointMathLibTest:testSqrt(uint256) (runs: 256, μ: 1065, ~: 1113)
FixedPointMathLibTest:testSqrt(uint256) (runs: 256, μ: 1043, ~: 1091)
FixedPointMathLibTest:testSqrtBack(uint256) (runs: 256, μ: 16876, ~: 340)
FixedPointMathLibTest:testSqrtBackHashed(uint256) (runs: 256, μ: 65176, ~: 65644)
FixedPointMathLibTest:testSqrtBackHashedSingle() (gas: 65128)
LibStringTest:testDifferentiallyFuzzToString(uint256,bytes) (runs: 256, μ: 21006, ~: 9531)
LibStringTest:testToString() (gas: 10047)
LibStringTest:testToStringDirty() (gas: 8123)
Expand Down
18 changes: 18 additions & 0 deletions src/test/FixedPointMathLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,22 @@ contract FixedPointMathLibTest is DSTestPlus {

assertTrue(root * root <= x && next * next > x);
}

function testSqrtBack(uint256 x) public {
unchecked {
x >>= 128;
while (x != 0) {
assertEq(FixedPointMathLib.sqrt(x * x), x);
x >>= 1;
}
}
}

function testSqrtBackHashed(uint256 x) public {
testSqrtBack(uint256(keccak256(abi.encode(x))));
}

function testSqrtBackHashedSingle() public {
testSqrtBackHashed(123);
}
}

0 comments on commit 6ea4ae6

Please sign in to comment.