diff --git a/test/DateTimeLib.t.sol b/test/DateTimeLib.t.sol index 099412a16..4ad904d77 100644 --- a/test/DateTimeLib.t.sol +++ b/test/DateTimeLib.t.sol @@ -543,48 +543,120 @@ contract DateTimeLibTest is SoladyTest { assertTrue(a.hour == b.hour && a.minute == b.minute && a.second == b.second); } + function addYears(uint256 timestamp, uint256 numYears) public pure returns (uint256) { + return DateTimeLib.addYears(timestamp, numYears); + } + + function subYears(uint256 timestamp, uint256 numYears) public pure returns (uint256) { + return DateTimeLib.subYears(timestamp, numYears); + } + + function diffYears(uint256 timestamp, uint256 numYears) public pure returns (uint256) { + return DateTimeLib.diffYears(timestamp, numYears); + } + + function addMonths(uint256 timestamp, uint256 numMonths) public pure returns (uint256) { + return DateTimeLib.addMonths(timestamp, numMonths); + } + + function subMonths(uint256 timestamp, uint256 numMonths) public pure returns (uint256) { + return DateTimeLib.subMonths(timestamp, numMonths); + } + + function diffMonths(uint256 timestamp, uint256 numMonths) public pure returns (uint256) { + return DateTimeLib.diffMonths(timestamp, numMonths); + } + + function addDays(uint256 timestamp, uint256 numDays) public pure returns (uint256) { + return DateTimeLib.addDays(timestamp, numDays); + } + + function subDays(uint256 timestamp, uint256 numDays) public pure returns (uint256) { + return DateTimeLib.subDays(timestamp, numDays); + } + + function diffDays(uint256 timestamp, uint256 numDays) public pure returns (uint256) { + return DateTimeLib.diffDays(timestamp, numDays); + } + + function addHours(uint256 timestamp, uint256 numHours) public pure returns (uint256) { + return DateTimeLib.addHours(timestamp, numHours); + } + + function subHours(uint256 timestamp, uint256 numHours) public pure returns (uint256) { + return DateTimeLib.subHours(timestamp, numHours); + } + + function diffHours(uint256 timestamp, uint256 numHours) public pure returns (uint256) { + return DateTimeLib.diffHours(timestamp, numHours); + } + + function addMinutes(uint256 timestamp, uint256 numMinutes) public pure returns (uint256) { + return DateTimeLib.addMinutes(timestamp, numMinutes); + } + + function subMinutes(uint256 timestamp, uint256 numMinutes) public pure returns (uint256) { + return DateTimeLib.subMinutes(timestamp, numMinutes); + } + + function diffMinutes(uint256 timestamp, uint256 numMinutes) public pure returns (uint256) { + return DateTimeLib.diffMinutes(timestamp, numMinutes); + } + + function addSeconds(uint256 timestamp, uint256 numSeconds) public pure returns (uint256) { + return DateTimeLib.addSeconds(timestamp, numSeconds); + } + + function subSeconds(uint256 timestamp, uint256 numSeconds) public pure returns (uint256) { + return DateTimeLib.subSeconds(timestamp, numSeconds); + } + + function diffSeconds(uint256 timestamp, uint256 numSeconds) public pure returns (uint256) { + return DateTimeLib.diffSeconds(timestamp, numSeconds); + } + function testDateTimeArithmeticReverts() public { vm.expectRevert(stdError.arithmeticError); - DateTimeLib.addYears(2 ** 128 - 1, 2 ** 255 - 1); + this.addYears(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.subYears(2 ** 128 - 1, 2 ** 255 - 1); + this.subYears(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.diffYears(2 ** 128 - 1, 2 ** 127 - 1); + this.diffYears(2 ** 128 - 1, 2 ** 127 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.addMonths(2 ** 128 - 1, 2 ** 255 - 1); + this.addMonths(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.subMonths(2 ** 128 - 1, 2 ** 255 - 1); + this.subMonths(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.diffMonths(2 ** 128 - 1, 2 ** 127 - 1); + this.diffMonths(2 ** 128 - 1, 2 ** 127 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.addDays(2 ** 128 - 1, 2 ** 255 - 1); + this.addDays(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.subDays(2 ** 128 - 1, 2 ** 255 - 1); + this.subDays(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.diffDays(2 ** 128 - 1, 2 ** 127 - 1); + this.diffDays(2 ** 128 - 1, 2 ** 127 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.addHours(2 ** 128 - 1, 2 ** 255 - 1); + this.addHours(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.subHours(2 ** 128 - 1, 2 ** 255 - 1); + this.subHours(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.diffHours(2 ** 128 - 1, 2 ** 127 - 1); + this.diffHours(2 ** 128 - 1, 2 ** 127 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.addMinutes(2 ** 128 - 1, 2 ** 255 - 1); + this.addMinutes(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.subMinutes(2 ** 128 - 1, 2 ** 255 - 1); + this.subMinutes(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.diffMinutes(2 ** 128 - 1, 2 ** 127 - 1); + this.diffMinutes(2 ** 128 - 1, 2 ** 127 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.addSeconds(2 ** 128 - 1, 2 ** 255 - 1); + this.addSeconds(2 ** 256 - 1, 2 ** 256 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.subSeconds(2 ** 128 - 1, 2 ** 255 - 1); + this.subSeconds(2 ** 128 - 1, 2 ** 255 - 1); vm.expectRevert(stdError.arithmeticError); - DateTimeLib.diffSeconds(2 ** 128 - 1, 2 ** 127 - 1); + this.diffSeconds(2 ** 128 - 1, 2 ** 127 - 1); } function testAddSubDiffMonths(uint256 timestamp, uint256 numMonths) public { diff --git a/test/ECDSA.t.sol b/test/ECDSA.t.sol index feeac0b1e..799b79813 100644 --- a/test/ECDSA.t.sol +++ b/test/ECDSA.t.sol @@ -339,10 +339,10 @@ contract ECDSATest is SoladyTest { function testBytesToEthSignedMessageHashExceedsMaxLengthReverts() public { vm.expectRevert(); - _testBytesToEthSignedMessageHash(999999 + 1); + this._testBytesToEthSignedMessageHash(999999 + 1); } - function _testBytesToEthSignedMessageHash(uint256 n) internal brutalizeMemory { + function _testBytesToEthSignedMessageHash(uint256 n) public brutalizeMemory { bytes memory message; /// @solidity memory-safe-assembly assembly { diff --git a/test/ERC20Votes.t.sol b/test/ERC20Votes.t.sol index dd18be866..19fa7727a 100644 --- a/test/ERC20Votes.t.sol +++ b/test/ERC20Votes.t.sol @@ -322,26 +322,26 @@ contract ERC20VotesTest is SoladyTest { lengthSlot = uint256(keccak256(abi.encode(lengthSlot, "hehe"))); uint256 key = _randomUniform() & 0xf; if (_randomChance(2)) { - _checkpointPushDiff(lengthSlot, key, type(uint256).max - 10, true); + this.checkpointPushDiff(lengthSlot, key, type(uint256).max - 10, true); key += _randomUniform() & 0xf; uint256 amount = _randomUniform() % 20; if (amount <= 10) { - _checkpointPushDiff(lengthSlot, key, amount, true); + this.checkpointPushDiff(lengthSlot, key, amount, true); assertEq(_checkpointLatest(lengthSlot), type(uint256).max - 10 + amount); } else { vm.expectRevert(ERC20Votes.ERC5805CheckpointValueOverflow.selector); - _checkpointPushDiff(lengthSlot, key, amount, true); + this.checkpointPushDiff(lengthSlot, key, amount, true); } } else { - _checkpointPushDiff(lengthSlot, key, 10, true); + this.checkpointPushDiff(lengthSlot, key, 10, true); key += _randomUniform() & 0xf; uint256 amount = _randomUniform() % 20; if (amount <= 10) { - _checkpointPushDiff(lengthSlot, key, amount, false); + this.checkpointPushDiff(lengthSlot, key, amount, false); assertEq(_checkpointLatest(lengthSlot), 10 - amount); } else { vm.expectRevert(ERC20Votes.ERC5805CheckpointValueUnderflow.selector); - _checkpointPushDiff(lengthSlot, key, amount, false); + this.checkpointPushDiff(lengthSlot, key, amount, false); } } } @@ -470,6 +470,13 @@ contract ERC20VotesTest is SoladyTest { } } + function checkpointPushDiff(uint256 lengthSlot, uint256 key, uint256 amount, bool isAdd) + public + returns (uint256 oldValue, uint256 newValue) + { + return _checkpointPushDiff(lengthSlot, key, amount, isAdd); + } + /// @dev Pushes a checkpoint. function _checkpointPushDiff(uint256 lengthSlot, uint256 key, uint256 amount, bool isAdd) private diff --git a/test/EnumerableSetLib.t.sol b/test/EnumerableSetLib.t.sol index 4a6c1dcc2..cd60a988f 100644 --- a/test/EnumerableSetLib.t.sol +++ b/test/EnumerableSetLib.t.sol @@ -471,7 +471,7 @@ contract EnumerableSetLibTest is SoladyTest { assertEq(addressSet.at(i), values[i]); } vm.expectRevert(EnumerableSetLib.IndexOutOfBounds.selector); - addressSetAt(_bound(_random(), values.length, type(uint256).max)); + this.addressSetAt(_bound(_random(), values.length, type(uint256).max)); } } @@ -481,7 +481,7 @@ contract EnumerableSetLibTest is SoladyTest { assertEq(bytes32Set.at(i), values[i]); } vm.expectRevert(EnumerableSetLib.IndexOutOfBounds.selector); - bytes32SetAt(_bound(_random(), values.length, type(uint256).max)); + this.bytes32SetAt(_bound(_random(), values.length, type(uint256).max)); } } diff --git a/test/FixedPointMathLib.t.sol b/test/FixedPointMathLib.t.sol index be3d77d5b..f1846eb49 100644 --- a/test/FixedPointMathLib.t.sol +++ b/test/FixedPointMathLib.t.sol @@ -330,10 +330,14 @@ contract FixedPointMathLibTest is SoladyTest { FixedPointMathLib.lambertW0Wad(_LAMBERT_W0_MIN); for (int256 i = 0; i <= 10; ++i) { vm.expectRevert(FixedPointMathLib.OutOfDomain.selector); - FixedPointMathLib.lambertW0Wad(_LAMBERT_W0_MIN - 1 - i); + this.lambertW0Wad(_LAMBERT_W0_MIN - 1 - i); } vm.expectRevert(FixedPointMathLib.OutOfDomain.selector); - FixedPointMathLib.lambertW0Wad(-type(int256).max); + this.lambertW0Wad(-type(int256).max); + } + + function lambertW0Wad(int256 x) public pure returns (int256) { + return FixedPointMathLib.lambertW0Wad(x); } function _checkLambertW0Wad(int256 x, int256 expected) internal { @@ -672,7 +676,7 @@ contract FixedPointMathLibTest is SoladyTest { function testDivWadZeroDenominatorReverts() public { vm.expectRevert(FixedPointMathLib.DivWadFailed.selector); - FixedPointMathLib.divWad(1e18, 0); + this.divWad(1e18, 0); } function testDivWadUp() public { @@ -692,7 +696,7 @@ contract FixedPointMathLibTest is SoladyTest { function testDivWadUpZeroDenominatorReverts() public { vm.expectRevert(FixedPointMathLib.DivWadFailed.selector); - FixedPointMathLib.divWadUp(1e18, 0); + this.divWadUp(1e18, 0); } function testMulDiv() public { @@ -718,7 +722,7 @@ contract FixedPointMathLibTest is SoladyTest { function testMulDivZeroDenominatorReverts() public { vm.expectRevert(FixedPointMathLib.MulDivFailed.selector); - FixedPointMathLib.mulDiv(1e18, 1e18, 0); + this.mulDiv(1e18, 1e18, 0); } function testMulDivUp() public { @@ -744,7 +748,11 @@ contract FixedPointMathLibTest is SoladyTest { function testMulDivUpZeroDenominator() public { vm.expectRevert(FixedPointMathLib.MulDivFailed.selector); - FixedPointMathLib.mulDivUp(1e18, 1e18, 0); + this.mulDivUp(1e18, 1e18, 0); + } + + function mulDivUp(uint256 x, uint256 y, uint256 d) public pure returns (uint256) { + return FixedPointMathLib.mulDivUp(x, y, d); } function testLnWad() public { @@ -784,13 +792,18 @@ contract FixedPointMathLibTest is SoladyTest { function testLnWadNegativeReverts() public { vm.expectRevert(FixedPointMathLib.LnWadUndefined.selector); - FixedPointMathLib.lnWad(-1); - FixedPointMathLib.lnWad(-2 ** 255); + this.lnWad(-1); + vm.expectRevert(FixedPointMathLib.LnWadUndefined.selector); + this.lnWad(-2 ** 255); } function testLnWadOverflowReverts() public { vm.expectRevert(FixedPointMathLib.LnWadUndefined.selector); - FixedPointMathLib.lnWad(0); + this.lnWad(0); + } + + function lnWad(int256 x) public pure returns (int256) { + return FixedPointMathLib.lnWad(x); } function testRPow() public { @@ -809,8 +822,13 @@ contract FixedPointMathLibTest is SoladyTest { function testRPowOverflowReverts() public { vm.expectRevert(FixedPointMathLib.RPowOverflow.selector); - FixedPointMathLib.rpow(2, type(uint128).max, 1); - FixedPointMathLib.rpow(type(uint128).max, 3, 1); + this.rpow(2, type(uint128).max, 1); + vm.expectRevert(FixedPointMathLib.RPowOverflow.selector); + this.rpow(type(uint128).max, 3, 1); + } + + function rpow(uint256 x, uint256 y, uint256 b) public pure returns (uint256) { + return FixedPointMathLib.rpow(x, y, b); } function testSqrt() public { @@ -1089,19 +1107,23 @@ contract FixedPointMathLibTest is SoladyTest { function testFullMulDivAlwaysRevertsIfDivisorIsZero(uint256 a, uint256 b) public { vm.expectRevert(FixedPointMathLib.FullMulDivFailed.selector); - FixedPointMathLib.fullMulDivUp(a, b, 0); + this.fullMulDivUp(a, b, 0); + } + + function fullMulDivUp(uint256 a, uint256 b, uint256 d) public pure returns (uint256) { + return FixedPointMathLib.fullMulDivUp(a, b, d); } function testFullMulDivUpRevertsIfRoundedUpResultOverflowsCase1() public { vm.expectRevert(FixedPointMathLib.FullMulDivFailed.selector); - FixedPointMathLib.fullMulDivUp( + this.fullMulDivUp( 535006138814359, 432862656469423142931042426214547535783388063929571229938474969, 2 ); } function testFullMulDivUpRevertsIfRoundedUpResultOverflowsCase2() public { vm.expectRevert(FixedPointMathLib.FullMulDivFailed.selector); - FixedPointMathLib.fullMulDivUp( + this.fullMulDivUp( 115792089237316195423570985008687907853269984659341747863450311749907997002549, 115792089237316195423570985008687907853269984659341747863450311749907997002550, 115792089237316195423570985008687907853269984653042931687443039491902864365164 @@ -1118,7 +1140,7 @@ contract FixedPointMathLibTest is SoladyTest { function testFullMulDiv(uint256 a, uint256 b, uint256 d) public returns (uint256 result) { if (d == 0) { vm.expectRevert(FixedPointMathLib.FullMulDivFailed.selector); - FixedPointMathLib.fullMulDiv(a, b, d); + this.fullMulDiv(a, b, d); return 0; } @@ -1141,7 +1163,7 @@ contract FixedPointMathLibTest is SoladyTest { } if (prod1 >= d) { vm.expectRevert(FixedPointMathLib.FullMulDivFailed.selector); - FixedPointMathLib.fullMulDiv(a, b, d); + this.fullMulDiv(a, b, d); return 0; } @@ -1228,7 +1250,7 @@ contract FixedPointMathLibTest is SoladyTest { (x, y) = _sampleEdgeCases(x, y); if (_mulWadWillFail(x, y)) { vm.expectRevert(FixedPointMathLib.MulWadFailed.selector); - FixedPointMathLib.mulWad(x, y); + this.mulWad(x, y); return; } uint256 result = FixedPointMathLib.mulWad(x, y); @@ -1236,6 +1258,10 @@ contract FixedPointMathLibTest is SoladyTest { assertEq(FixedPointMathLib.rawMulWad(x, y), result); } + function mulWad(uint256 x, uint256 y) public pure returns (uint256) { + return FixedPointMathLib.mulWad(x, y); + } + function sMulWadOriginal(int256 x, int256 y) public pure returns (int256) { return (x * y) / 1e18; } @@ -1250,7 +1276,7 @@ contract FixedPointMathLibTest is SoladyTest { (x, y) = _sampleEdgeCases(x, y); if (_sMulWadWillFail(x, y)) { vm.expectRevert(FixedPointMathLib.SMulWadFailed.selector); - FixedPointMathLib.sMulWad(x, y); + this.sMulWad(x, y); return; } int256 result = FixedPointMathLib.sMulWad(x, y); @@ -1258,16 +1284,24 @@ contract FixedPointMathLibTest is SoladyTest { assertEq(FixedPointMathLib.rawSMulWad(x, y), result); } + function sMulWad(int256 x, int256 y) public pure returns (int256) { + return FixedPointMathLib.sMulWad(x, y); + } + function testMulWadUp(uint256 x, uint256 y) public { (x, y) = _sampleEdgeCases(x, y); if (_mulWadWillFail(x, y)) { vm.expectRevert(FixedPointMathLib.MulWadFailed.selector); - FixedPointMathLib.mulWadUp(x, y); + this.mulWadUp(x, y); return; } assertEq(FixedPointMathLib.mulWadUp(x, y), x * y == 0 ? 0 : (x * y - 1) / 1e18 + 1); } + function mulWadUp(uint256 x, uint256 y) public pure returns (uint256) { + return FixedPointMathLib.mulWadUp(x, y); + } + function divWadOriginal(uint256 x, uint256 y) public pure returns (uint256) { return (x * 1e18) / y; } @@ -1282,7 +1316,7 @@ contract FixedPointMathLibTest is SoladyTest { (x, y) = _sampleEdgeCases(x, y); if (_divWadWillFail(x, y)) { vm.expectRevert(FixedPointMathLib.DivWadFailed.selector); - FixedPointMathLib.divWad(x, y); + this.divWad(x, y); return; } uint256 result = FixedPointMathLib.divWad(x, y); @@ -1290,6 +1324,10 @@ contract FixedPointMathLibTest is SoladyTest { assertEq(FixedPointMathLib.rawDivWad(x, y), result); } + function divWad(uint256 x, uint256 y) public pure returns (uint256) { + return FixedPointMathLib.divWad(x, y); + } + function sDivWadOriginal(int256 x, int256 y) public pure returns (int256) { return (x * 1e18) / y; } @@ -1304,7 +1342,7 @@ contract FixedPointMathLibTest is SoladyTest { (x, y) = _sampleEdgeCases(x, y); if (_sDivWadWillFail(x, y)) { vm.expectRevert(FixedPointMathLib.SDivWadFailed.selector); - FixedPointMathLib.sDivWad(x, y); + this.sDivWad(x, y); return; } int256 result = FixedPointMathLib.sDivWad(x, y); @@ -1312,16 +1350,24 @@ contract FixedPointMathLibTest is SoladyTest { assertEq(FixedPointMathLib.rawSDivWad(x, y), result); } + function sDivWad(int256 x, int256 y) public pure returns (int256) { + return FixedPointMathLib.sDivWad(x, y); + } + function testDivWadUp(uint256 x, uint256 y) public { (x, y) = _sampleEdgeCases(x, y); if (_divWadWillFail(x, y)) { vm.expectRevert(FixedPointMathLib.DivWadFailed.selector); - FixedPointMathLib.divWadUp(x, y); + this.divWadUp(x, y); return; } assertEq(FixedPointMathLib.divWadUp(x, y), x == 0 ? 0 : (x * 1e18 - 1) / y + 1); } + function divWadUp(uint256 x, uint256 y) public pure returns (uint256) { + return FixedPointMathLib.divWadUp(x, y); + } + function mulDivOriginal(uint256 x, uint256 y, uint256 denominator) public pure @@ -1345,22 +1391,24 @@ contract FixedPointMathLibTest is SoladyTest { (x, y) = _sampleEdgeCases(x, y); if (_mulDivWillFail(x, y, denominator)) { vm.expectRevert(FixedPointMathLib.MulDivFailed.selector); - FixedPointMathLib.mulDiv(x, y, denominator); + this.mulDiv(x, y, denominator); return; } - assertEq(FixedPointMathLib.mulDiv(x, y, denominator), (x * y) / denominator); + assertEq(this.mulDiv(x, y, denominator), (x * y) / denominator); + } + + function mulDiv(uint256 x, uint256 y, uint256 d) public pure returns (uint256) { + return FixedPointMathLib.mulDiv(x, y, d); } function testMulDivUp(uint256 x, uint256 y, uint256 denominator) public { (x, y) = _sampleEdgeCases(x, y); if (_mulDivWillFail(x, y, denominator)) { vm.expectRevert(FixedPointMathLib.MulDivFailed.selector); - FixedPointMathLib.mulDivUp(x, y, denominator); + this.mulDivUp(x, y, denominator); + return; } - assertEq( - FixedPointMathLib.mulDivUp(x, y, denominator), - x * y == 0 ? 0 : (x * y - 1) / denominator + 1 - ); + assertEq(this.mulDivUp(x, y, denominator), x * y == 0 ? 0 : (x * y - 1) / denominator + 1); } function testCbrt(uint256 x) public { @@ -1628,7 +1676,11 @@ contract FixedPointMathLibTest is SoladyTest { } } vm.expectRevert(FixedPointMathLib.FactorialOverflow.selector); - FixedPointMathLib.factorial(58); + this.factorial(58); + } + + function factorial(uint256 x) public pure returns (uint256) { + return FixedPointMathLib.factorial(x); } function testFactorialOriginal() public { @@ -1912,6 +1964,14 @@ contract FixedPointMathLibTest is SoladyTest { assertEq(exponent, expectedExponent); } + function unpackSci(uint256 packed) public pure returns (uint256) { + return FixedPointMathLib.unpackSci(packed); + } + + function packSci(uint256 x) public pure returns (uint256) { + return FixedPointMathLib.packSci(x); + } + function testPackUnpackSci(uint256) public { unchecked { uint256 x = (_random() & 0x1) * 10 ** (_random() % 70); @@ -1958,7 +2018,7 @@ contract FixedPointMathLibTest is SoladyTest { unchecked { uint256 x = (1 << (mantissaSize + 1)) - 1; vm.expectRevert(FixedPointMathLib.MantissaOverflow.selector); - FixedPointMathLib.packSci(x); + this.packSci(x); } } diff --git a/test/LibClone.t.sol b/test/LibClone.t.sol index 96f0eef36..c401335d1 100644 --- a/test/LibClone.t.sol +++ b/test/LibClone.t.sol @@ -325,23 +325,111 @@ contract LibCloneTest is SoladyTest { _checkBehavesLikeProxy(instance); } + function argsOnClone(address instance) public view returns (bytes memory) { + return LibClone.argsOnClone(instance); + } + + function argsOnClone(address instance, uint256 start) public view returns (bytes memory) { + return LibClone.argsOnClone(instance, start); + } + + function argsOnClone(address instance, uint256 start, uint256 end) + public + view + returns (bytes memory) + { + return LibClone.argsOnClone(instance, start, end); + } + + function argsOnERC1967(address instance) public view returns (bytes memory) { + return LibClone.argsOnERC1967(instance); + } + + function argsOnERC1967(address instance, uint256 start) public view returns (bytes memory) { + return LibClone.argsOnERC1967(instance, start); + } + + function argsOnERC1967(address instance, uint256 start, uint256 end) + public + view + returns (bytes memory) + { + return LibClone.argsOnERC1967(instance, start, end); + } + + function argsOnERC1967I(address instance) public view returns (bytes memory) { + return LibClone.argsOnERC1967I(instance); + } + + function argsOnERC1967I(address instance, uint256 start) public view returns (bytes memory) { + return LibClone.argsOnERC1967I(instance, start); + } + + function argsOnERC1967I(address instance, uint256 start, uint256 end) + public + view + returns (bytes memory) + { + return LibClone.argsOnERC1967I(instance, start, end); + } + + function argsOnERC1967BeaconProxy(address instance) public view returns (bytes memory) { + return LibClone.argsOnERC1967BeaconProxy(instance); + } + + function argsOnERC1967BeaconProxy(address instance, uint256 start) + public + view + returns (bytes memory) + { + return LibClone.argsOnERC1967BeaconProxy(instance, start); + } + + function argsOnERC1967BeaconProxy(address instance, uint256 start, uint256 end) + public + view + returns (bytes memory) + { + return LibClone.argsOnERC1967BeaconProxy(instance, start, end); + } + + function argsOnERC1967IBeaconProxy(address instance) public view returns (bytes memory) { + return LibClone.argsOnERC1967IBeaconProxy(instance); + } + + function argsOnERC1967IBeaconProxy(address instance, uint256 start) + public + view + returns (bytes memory) + { + return LibClone.argsOnERC1967IBeaconProxy(instance, start); + } + + function argsOnERC1967IBeaconProxy(address instance, uint256 start, uint256 end) + public + view + returns (bytes memory) + { + return LibClone.argsOnERC1967IBeaconProxy(instance, start, end); + } + function testSlicingRevertsOnZeroCodeAddress(address instance) public { while (instance.code.length != 0) instance = _randomNonZeroAddress(); if (_randomChance(4)) { _maybeBrutalizeMemory(); if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnClone(instance)); + _mustCompute(this.argsOnClone(instance)); return; } if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnClone(instance, _random())); + _mustCompute(this.argsOnClone(instance, _random())); return; } if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnClone(instance, _random(), _random())); + _mustCompute(this.argsOnClone(instance, _random(), _random())); return; } instance = LibClone.clone(address(this), ""); @@ -354,17 +442,17 @@ contract LibCloneTest is SoladyTest { _maybeBrutalizeMemory(); if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967(instance)); + _mustCompute(this.argsOnERC1967(instance)); return; } if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967(instance, _random())); + _mustCompute(this.argsOnERC1967(instance, _random())); return; } if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967(instance, _random(), _random())); + _mustCompute(this.argsOnERC1967(instance, _random(), _random())); return; } instance = LibClone.deployERC1967(address(this), ""); @@ -377,17 +465,17 @@ contract LibCloneTest is SoladyTest { _maybeBrutalizeMemory(); if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967I(instance)); + _mustCompute(this.argsOnERC1967I(instance)); return; } if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967I(instance, _random())); + _mustCompute(this.argsOnERC1967I(instance, _random())); return; } if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967I(instance, _random(), _random())); + _mustCompute(this.argsOnERC1967I(instance, _random(), _random())); return; } instance = LibClone.deployERC1967I(address(this), ""); @@ -400,17 +488,17 @@ contract LibCloneTest is SoladyTest { _maybeBrutalizeMemory(); if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967BeaconProxy(instance)); + _mustCompute(this.argsOnERC1967BeaconProxy(instance)); return; } if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967BeaconProxy(instance, _random())); + _mustCompute(this.argsOnERC1967BeaconProxy(instance, _random())); return; } if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967BeaconProxy(instance, _random(), _random())); + _mustCompute(this.argsOnERC1967BeaconProxy(instance, _random(), _random())); return; } instance = LibClone.deployERC1967BeaconProxy(address(this), ""); @@ -423,17 +511,17 @@ contract LibCloneTest is SoladyTest { _maybeBrutalizeMemory(); if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967IBeaconProxy(instance)); + _mustCompute(this.argsOnERC1967IBeaconProxy(instance)); return; } if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967IBeaconProxy(instance, _random())); + _mustCompute(this.argsOnERC1967IBeaconProxy(instance, _random())); return; } if (_randomChance(4)) { vm.expectRevert(); - _mustCompute(LibClone.argsOnERC1967IBeaconProxy(instance, _random(), _random())); + _mustCompute(this.argsOnERC1967IBeaconProxy(instance, _random(), _random())); return; } instance = LibClone.deployERC1967IBeaconProxy(address(this), ""); diff --git a/test/LibPRNG.t.sol b/test/LibPRNG.t.sol index 198ef35dd..1aa8e5533 100644 --- a/test/LibPRNG.t.sol +++ b/test/LibPRNG.t.sol @@ -586,7 +586,7 @@ contract LibPRNGTest is SoladyTest { function testLazyShufflerRevertsOnZeroLengthNext() public { vm.expectRevert(LibPRNG.LazyShuffleFinished.selector); - lazyShufflerNext(_random()); + this.lazyShufflerNext(_random()); } function testLazyShufflerRevertsOnFinshedNext(uint256 n) public { @@ -598,7 +598,7 @@ contract LibPRNGTest is SoladyTest { } } vm.expectRevert(LibPRNG.LazyShuffleFinished.selector); - lazyShufflerNext(_random()); + this.lazyShufflerNext(_random()); } function lazyShufflerInitialize(uint256 n) public { diff --git a/test/LibString.t.sol b/test/LibString.t.sol index 17dec0689..e761351cb 100644 --- a/test/LibString.t.sol +++ b/test/LibString.t.sol @@ -193,7 +193,11 @@ contract LibStringTest is SoladyTest { function testToHexStringFixedLengthInsufficientLength() public { vm.expectRevert(LibString.HexLengthInsufficient.selector); - LibString.toHexString(0x4132, 1); + this.toHexString(0x4132, 1); + } + + function toHexString(uint256 x, uint256 l) public pure returns (string memory) { + return LibString.toHexString(x, l); } function testToHexStringFixedLengthUint256Max() public { @@ -1569,7 +1573,11 @@ contract LibStringTest is SoladyTest { "12345678901234567890123456789012" ); vm.expectRevert(LibString.TooBigForSmallString.selector); - LibString.toSmallString("123456789012345678901234567890123"); + this.toSmallString("123456789012345678901234567890123"); + } + + function toSmallString(string memory s) public pure returns (bytes32) { + return LibString.toSmallString(s); } function testSetAndGetStringStorage() public { diff --git a/test/MinHeapLib.t.sol b/test/MinHeapLib.t.sol index 918e76ed0..2549cd3dd 100644 --- a/test/MinHeapLib.t.sol +++ b/test/MinHeapLib.t.sol @@ -19,13 +19,17 @@ contract MinHeapLibTest is SoladyTest { function testHeapRoot(uint256 x) public { if (_randomChance(2)) { vm.expectRevert(MinHeapLib.HeapIsEmpty.selector); - heap0.root(); + this.root(); } heap0.data.push(x); assertEq(heap0.length(), 1); assertEq(heap0.root(), x); } + function root() public view returns (uint256) { + return heap0.root(); + } + function testHeapPushAndPop(uint256) public { unchecked { uint256 n = _random() % 8; @@ -311,18 +315,22 @@ contract MinHeapLibTest is SoladyTest { function testHeapEnqueueZeroMaxLengthReverts(uint256) public { if (_randomChance(2)) { vm.expectRevert(MinHeapLib.HeapIsEmpty.selector); - heap0.enqueue(_random(), 0); + this.enqueue(_random(), 0); } - heap0.enqueue(_random(), 1); + this.enqueue(_random(), 1); + } + + function enqueue(uint256 x, uint256 cap) public { + heap0.enqueue(x, cap); } function testHeapReplaceOrPopEmptyHeapReverts(uint256) public { if (_randomChance(2)) { vm.expectRevert(MinHeapLib.HeapIsEmpty.selector); if (_randomChance(2)) { - heap0.replace(_random()); + this.replace(_random()); } else { - heap0.pop(); + this.pop(); } } heap0.push(_random()); @@ -333,17 +341,30 @@ contract MinHeapLibTest is SoladyTest { } } + function replace(uint256 x) public { + heap0.replace(x); + } + + function pop() public { + heap0.pop(); + } + function testMemHeapRoot(uint256 x) public brutalizeMemory { MinHeapLib.MemHeap memory heapA; if (_randomChance(2)) { vm.expectRevert(MinHeapLib.HeapIsEmpty.selector); - heapA.root(); + this.emptyMemHeapRoot(); } heapA.push(x); assertEq(heapA.length(), 1); assertEq(heapA.root(), x); } + function emptyMemHeapRoot() public pure { + MinHeapLib.MemHeap memory heapA; + heapA.root(); + } + function testMemHeapPushAndPop(uint256) public brutalizeMemory { MinHeapLib.MemHeap memory heapA; unchecked { @@ -594,20 +615,21 @@ contract MinHeapLibTest is SoladyTest { MinHeapLib.MemHeap memory heapA; if (_randomChance(2)) { vm.expectRevert(MinHeapLib.HeapIsEmpty.selector); - heapA.enqueue(_random(), 0); + this.memHeapEnqueueZeroMaxLengthReverts(_random()); } heapA.enqueue(_random(), 1); } + function memHeapEnqueueZeroMaxLengthReverts(uint256 x) public pure { + MinHeapLib.MemHeap memory heapA; + heapA.enqueue(x, 0); + } + function testMemHeapReplaceOrPopEmptyHeapReverts(uint256) public { MinHeapLib.MemHeap memory heapA; if (_randomChance(2)) { vm.expectRevert(MinHeapLib.HeapIsEmpty.selector); - if (_randomChance(2)) { - heapA.replace(_random()); - } else { - heapA.pop(); - } + this.memHeapReplaceOrPopEmptyHeapReverts(_random(), _randomChance(2)); } heapA.push(_random()); if (_randomChance(2)) { @@ -617,6 +639,15 @@ contract MinHeapLibTest is SoladyTest { } } + function memHeapReplaceOrPopEmptyHeapReverts(uint256 x, bool r) public pure { + MinHeapLib.MemHeap memory heapA; + if (r) { + heapA.replace(x); + } else { + heapA.pop(); + } + } + function testMemHeapEnqueueGas() public pure { MinHeapLib.MemHeap memory heapA; LibPRNG.PRNG memory prng; diff --git a/test/RedBlackTree.t.sol b/test/RedBlackTree.t.sol index a56ff1000..559581f00 100644 --- a/test/RedBlackTree.t.sol +++ b/test/RedBlackTree.t.sol @@ -344,7 +344,7 @@ contract RedBlackTreeLibTest is SoladyTest { assertEq(ptrs[i].value(), 0); vm.expectRevert(RedBlackTreeLib.PointerOutOfBounds.selector); _brutalizeScratchSpace(); - ptrs[i].remove(); + this.remove(ptrs[i]); } for (uint256 i; i < 256; ++i) { _brutalizeScratchSpace(); @@ -354,6 +354,18 @@ contract RedBlackTreeLibTest is SoladyTest { } } + function find(uint256 x) public view { + tree.find(x); + } + + function insert(uint256 x) public { + tree.insert(x); + } + + function remove(bytes32 ptr) public { + ptr.remove(); + } + function testRedBlackTreeInsertOneGas() public { unchecked { for (uint256 i; i != 1; ++i) { @@ -426,11 +438,11 @@ contract RedBlackTreeLibTest is SoladyTest { function testRedBlackTreeRejectsEmptyValue() public { vm.expectRevert(RedBlackTreeLib.ValueIsEmpty.selector); - tree.insert(0); - vm.expectRevert(RedBlackTreeLib.ValueIsEmpty.selector); - tree.remove(0); + this.insert(0); + vm.expectRevert(RedBlackTreeLib.ValueDoesNotExist.selector); + this.remove(0); vm.expectRevert(RedBlackTreeLib.ValueIsEmpty.selector); - tree.find(0); + this.find(0); } function testRedBlackTreeRemoveViaPointer() public { @@ -442,11 +454,11 @@ contract RedBlackTreeLibTest is SoladyTest { ptr.remove(); vm.expectRevert(RedBlackTreeLib.PointerOutOfBounds.selector); - ptr.remove(); + this.remove(ptr); ptr = bytes32(0); vm.expectRevert(RedBlackTreeLib.ValueDoesNotExist.selector); - ptr.remove(); + this.remove(ptr); } function testRedBlackTreeTryInsertAndRemove() public { @@ -470,7 +482,7 @@ contract RedBlackTreeLibTest is SoladyTest { sstore(ptr, or(sload(ptr), sub(shl(31, 1), 1))) } vm.expectRevert(RedBlackTreeLib.TreeIsFull.selector); - tree.insert(2); + this.insert(2); assertEq(tree.size(), 2 ** 31 - 1); } diff --git a/test/SSTORE2.t.sol b/test/SSTORE2.t.sol index d19f47a4e..1879df5c3 100644 --- a/test/SSTORE2.t.sol +++ b/test/SSTORE2.t.sol @@ -40,23 +40,35 @@ contract SSTORE2Test is SoladyTest { _maybeBrutalizeMemory(); if (_randomChance(2)) { vm.expectRevert(); - _mustCompute(SSTORE2.read(pointer)); + _mustCompute(this.read(pointer)); return; } if (_randomChance(2)) { vm.expectRevert(); - _mustCompute(SSTORE2.read(pointer, _random())); + _mustCompute(this.read(pointer, _random())); return; } if (_randomChance(2)) { vm.expectRevert(); - _mustCompute(SSTORE2.read(pointer, _random(), _random())); + _mustCompute(this.read(pointer, _random(), _random())); return; } pointer = SSTORE2.write(""); - assertEq(SSTORE2.read(pointer), ""); - assertEq(SSTORE2.read(pointer, _random()), ""); - assertEq(SSTORE2.read(pointer, _random(), _random()), ""); + assertEq(this.read(pointer), ""); + assertEq(this.read(pointer, _random()), ""); + assertEq(this.read(pointer, _random(), _random()), ""); + } + + function read(address pointer) public view returns (bytes memory) { + return SSTORE2.read(pointer); + } + + function read(address pointer, uint256 start) public view returns (bytes memory) { + return SSTORE2.read(pointer, start); + } + + function read(address pointer, uint256 start, uint256 end) public view returns (bytes memory) { + return SSTORE2.read(pointer, start, end); } function _mustCompute(bytes memory s) internal { diff --git a/test/SafeCastLib.t.sol b/test/SafeCastLib.t.sol index 041b315a4..4a64da9bc 100644 --- a/test/SafeCastLib.t.sol +++ b/test/SafeCastLib.t.sol @@ -5,6 +5,378 @@ import "./utils/SoladyTest.sol"; import {SafeCastLib} from "../src/utils/SafeCastLib.sol"; contract SafeCastLibTest is SoladyTest { + function toUint8(uint256 x) public pure returns (uint8) { + return SafeCastLib.toUint8(x); + } + + function toUint16(uint256 x) public pure returns (uint16) { + return SafeCastLib.toUint16(x); + } + + function toUint24(uint256 x) public pure returns (uint24) { + return SafeCastLib.toUint24(x); + } + + function toUint32(uint256 x) public pure returns (uint32) { + return SafeCastLib.toUint32(x); + } + + function toUint40(uint256 x) public pure returns (uint40) { + return SafeCastLib.toUint40(x); + } + + function toUint48(uint256 x) public pure returns (uint48) { + return SafeCastLib.toUint48(x); + } + + function toUint56(uint256 x) public pure returns (uint56) { + return SafeCastLib.toUint56(x); + } + + function toUint64(uint256 x) public pure returns (uint64) { + return SafeCastLib.toUint64(x); + } + + function toUint72(uint256 x) public pure returns (uint72) { + return SafeCastLib.toUint72(x); + } + + function toUint80(uint256 x) public pure returns (uint80) { + return SafeCastLib.toUint80(x); + } + + function toUint88(uint256 x) public pure returns (uint88) { + return SafeCastLib.toUint88(x); + } + + function toUint96(uint256 x) public pure returns (uint96) { + return SafeCastLib.toUint96(x); + } + + function toUint104(uint256 x) public pure returns (uint104) { + return SafeCastLib.toUint104(x); + } + + function toUint112(uint256 x) public pure returns (uint112) { + return SafeCastLib.toUint112(x); + } + + function toUint120(uint256 x) public pure returns (uint120) { + return SafeCastLib.toUint120(x); + } + + function toUint128(uint256 x) public pure returns (uint128) { + return SafeCastLib.toUint128(x); + } + + function toUint136(uint256 x) public pure returns (uint136) { + return SafeCastLib.toUint136(x); + } + + function toUint144(uint256 x) public pure returns (uint144) { + return SafeCastLib.toUint144(x); + } + + function toUint152(uint256 x) public pure returns (uint152) { + return SafeCastLib.toUint152(x); + } + + function toUint160(uint256 x) public pure returns (uint160) { + return SafeCastLib.toUint160(x); + } + + function toUint168(uint256 x) public pure returns (uint168) { + return SafeCastLib.toUint168(x); + } + + function toUint176(uint256 x) public pure returns (uint176) { + return SafeCastLib.toUint176(x); + } + + function toUint184(uint256 x) public pure returns (uint184) { + return SafeCastLib.toUint184(x); + } + + function toUint192(uint256 x) public pure returns (uint192) { + return SafeCastLib.toUint192(x); + } + + function toUint200(uint256 x) public pure returns (uint200) { + return SafeCastLib.toUint200(x); + } + + function toUint208(uint256 x) public pure returns (uint208) { + return SafeCastLib.toUint208(x); + } + + function toUint216(uint256 x) public pure returns (uint216) { + return SafeCastLib.toUint216(x); + } + + function toUint224(uint256 x) public pure returns (uint224) { + return SafeCastLib.toUint224(x); + } + + function toUint232(uint256 x) public pure returns (uint232) { + return SafeCastLib.toUint232(x); + } + + function toUint240(uint256 x) public pure returns (uint240) { + return SafeCastLib.toUint240(x); + } + + function toUint248(uint256 x) public pure returns (uint248) { + return SafeCastLib.toUint248(x); + } + + function toInt8(int256 x) public pure returns (int8) { + return SafeCastLib.toInt8(x); + } + + function toInt16(int256 x) public pure returns (int16) { + return SafeCastLib.toInt16(x); + } + + function toInt24(int256 x) public pure returns (int24) { + return SafeCastLib.toInt24(x); + } + + function toInt32(int256 x) public pure returns (int32) { + return SafeCastLib.toInt32(x); + } + + function toInt40(int256 x) public pure returns (int40) { + return SafeCastLib.toInt40(x); + } + + function toInt48(int256 x) public pure returns (int48) { + return SafeCastLib.toInt48(x); + } + + function toInt56(int256 x) public pure returns (int56) { + return SafeCastLib.toInt56(x); + } + + function toInt64(int256 x) public pure returns (int64) { + return SafeCastLib.toInt64(x); + } + + function toInt72(int256 x) public pure returns (int72) { + return SafeCastLib.toInt72(x); + } + + function toInt80(int256 x) public pure returns (int80) { + return SafeCastLib.toInt80(x); + } + + function toInt88(int256 x) public pure returns (int88) { + return SafeCastLib.toInt88(x); + } + + function toInt96(int256 x) public pure returns (int96) { + return SafeCastLib.toInt96(x); + } + + function toInt104(int256 x) public pure returns (int104) { + return SafeCastLib.toInt104(x); + } + + function toInt112(int256 x) public pure returns (int112) { + return SafeCastLib.toInt112(x); + } + + function toInt120(int256 x) public pure returns (int120) { + return SafeCastLib.toInt120(x); + } + + function toInt128(int256 x) public pure returns (int128) { + return SafeCastLib.toInt128(x); + } + + function toInt136(int256 x) public pure returns (int136) { + return SafeCastLib.toInt136(x); + } + + function toInt144(int256 x) public pure returns (int144) { + return SafeCastLib.toInt144(x); + } + + function toInt152(int256 x) public pure returns (int152) { + return SafeCastLib.toInt152(x); + } + + function toInt160(int256 x) public pure returns (int160) { + return SafeCastLib.toInt160(x); + } + + function toInt168(int256 x) public pure returns (int168) { + return SafeCastLib.toInt168(x); + } + + function toInt176(int256 x) public pure returns (int176) { + return SafeCastLib.toInt176(x); + } + + function toInt184(int256 x) public pure returns (int184) { + return SafeCastLib.toInt184(x); + } + + function toInt192(int256 x) public pure returns (int192) { + return SafeCastLib.toInt192(x); + } + + function toInt200(int256 x) public pure returns (int200) { + return SafeCastLib.toInt200(x); + } + + function toInt208(int256 x) public pure returns (int208) { + return SafeCastLib.toInt208(x); + } + + function toInt216(int256 x) public pure returns (int216) { + return SafeCastLib.toInt216(x); + } + + function toInt224(int256 x) public pure returns (int224) { + return SafeCastLib.toInt224(x); + } + + function toInt232(int256 x) public pure returns (int232) { + return SafeCastLib.toInt232(x); + } + + function toInt240(int256 x) public pure returns (int240) { + return SafeCastLib.toInt240(x); + } + + function toInt248(int256 x) public pure returns (int248) { + return SafeCastLib.toInt248(x); + } + + function toInt8(uint256 x) public pure returns (int8) { + return SafeCastLib.toInt8(x); + } + + function toInt16(uint256 x) public pure returns (int16) { + return SafeCastLib.toInt16(x); + } + + function toInt24(uint256 x) public pure returns (int24) { + return SafeCastLib.toInt24(x); + } + + function toInt32(uint256 x) public pure returns (int32) { + return SafeCastLib.toInt32(x); + } + + function toInt40(uint256 x) public pure returns (int40) { + return SafeCastLib.toInt40(x); + } + + function toInt48(uint256 x) public pure returns (int48) { + return SafeCastLib.toInt48(x); + } + + function toInt56(uint256 x) public pure returns (int56) { + return SafeCastLib.toInt56(x); + } + + function toInt64(uint256 x) public pure returns (int64) { + return SafeCastLib.toInt64(x); + } + + function toInt72(uint256 x) public pure returns (int72) { + return SafeCastLib.toInt72(x); + } + + function toInt80(uint256 x) public pure returns (int80) { + return SafeCastLib.toInt80(x); + } + + function toInt88(uint256 x) public pure returns (int88) { + return SafeCastLib.toInt88(x); + } + + function toInt96(uint256 x) public pure returns (int96) { + return SafeCastLib.toInt96(x); + } + + function toInt104(uint256 x) public pure returns (int104) { + return SafeCastLib.toInt104(x); + } + + function toInt112(uint256 x) public pure returns (int112) { + return SafeCastLib.toInt112(x); + } + + function toInt120(uint256 x) public pure returns (int120) { + return SafeCastLib.toInt120(x); + } + + function toInt128(uint256 x) public pure returns (int128) { + return SafeCastLib.toInt128(x); + } + + function toInt136(uint256 x) public pure returns (int136) { + return SafeCastLib.toInt136(x); + } + + function toInt144(uint256 x) public pure returns (int144) { + return SafeCastLib.toInt144(x); + } + + function toInt152(uint256 x) public pure returns (int152) { + return SafeCastLib.toInt152(x); + } + + function toInt160(uint256 x) public pure returns (int160) { + return SafeCastLib.toInt160(x); + } + + function toInt168(uint256 x) public pure returns (int168) { + return SafeCastLib.toInt168(x); + } + + function toInt176(uint256 x) public pure returns (int176) { + return SafeCastLib.toInt176(x); + } + + function toInt184(uint256 x) public pure returns (int184) { + return SafeCastLib.toInt184(x); + } + + function toInt192(uint256 x) public pure returns (int192) { + return SafeCastLib.toInt192(x); + } + + function toInt200(uint256 x) public pure returns (int200) { + return SafeCastLib.toInt200(x); + } + + function toInt208(uint256 x) public pure returns (int208) { + return SafeCastLib.toInt208(x); + } + + function toInt216(uint256 x) public pure returns (int216) { + return SafeCastLib.toInt216(x); + } + + function toInt224(uint256 x) public pure returns (int224) { + return SafeCastLib.toInt224(x); + } + + function toInt232(uint256 x) public pure returns (int232) { + return SafeCastLib.toInt232(x); + } + + function toInt240(uint256 x) public pure returns (int240) { + return SafeCastLib.toInt240(x); + } + + function toInt248(uint256 x) public pure returns (int248) { + return SafeCastLib.toInt248(x); + } + function testSafeCastUintToUint(uint256 x, uint256 r) public { do { r = r % 31; @@ -12,279 +384,279 @@ contract SafeCastLibTest is SoladyTest { assertEq(SafeCastLib.toUint8(uint8(x)), uint8(x)); if (x >= 1 << 8) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint8(x); + this.toUint8(x); } else { - assertEq(SafeCastLib.toUint8(x), uint8(x)); + assertEq(this.toUint8(x), uint8(x)); } } if (r == 1) { assertEq(SafeCastLib.toUint16(uint16(x)), uint16(x)); if (x >= 1 << 16) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint16(x); + this.toUint16(x); } else { - assertEq(SafeCastLib.toUint16(x), uint16(x)); + assertEq(this.toUint16(x), uint16(x)); } } if (r == 2) { assertEq(SafeCastLib.toUint24(uint24(x)), uint24(x)); if (x >= 1 << 24) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint24(x); + this.toUint24(x); } else { - assertEq(SafeCastLib.toUint24(x), uint24(x)); + assertEq(this.toUint24(x), uint24(x)); } } if (r == 3) { assertEq(SafeCastLib.toUint32(uint32(x)), uint32(x)); if (x >= 1 << 32) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint32(x); + this.toUint32(x); } else { - assertEq(SafeCastLib.toUint32(x), uint32(x)); + assertEq(this.toUint32(x), uint32(x)); } } if (r == 4) { assertEq(SafeCastLib.toUint40(uint40(x)), uint40(x)); if (x >= 1 << 40) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint40(x); + this.toUint40(x); } else { - assertEq(SafeCastLib.toUint40(x), uint40(x)); + assertEq(this.toUint40(x), uint40(x)); } } if (r == 5) { assertEq(SafeCastLib.toUint48(uint48(x)), uint48(x)); if (x >= 1 << 48) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint48(x); + this.toUint48(x); } else { - assertEq(SafeCastLib.toUint48(x), uint48(x)); + assertEq(this.toUint48(x), uint48(x)); } } if (r == 6) { assertEq(SafeCastLib.toUint56(uint56(x)), uint56(x)); if (x >= 1 << 56) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint56(x); + this.toUint56(x); } else { - assertEq(SafeCastLib.toUint56(x), uint56(x)); + assertEq(this.toUint56(x), uint56(x)); } } if (r == 7) { assertEq(SafeCastLib.toUint64(uint64(x)), uint64(x)); if (x >= 1 << 64) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint64(x); + this.toUint64(x); } else { - assertEq(SafeCastLib.toUint64(x), uint64(x)); + assertEq(this.toUint64(x), uint64(x)); } } if (r == 8) { assertEq(SafeCastLib.toUint72(uint72(x)), uint72(x)); if (x >= 1 << 72) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint72(x); + this.toUint72(x); } else { - assertEq(SafeCastLib.toUint72(x), uint72(x)); + assertEq(this.toUint72(x), uint72(x)); } } if (r == 9) { assertEq(SafeCastLib.toUint80(uint80(x)), uint80(x)); if (x >= 1 << 80) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint80(x); + this.toUint80(x); } else { - assertEq(SafeCastLib.toUint80(x), uint80(x)); + assertEq(this.toUint80(x), uint80(x)); } } if (r == 10) { assertEq(SafeCastLib.toUint88(uint88(x)), uint88(x)); if (x >= 1 << 88) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint88(x); + this.toUint88(x); } else { - assertEq(SafeCastLib.toUint88(x), uint88(x)); + assertEq(this.toUint88(x), uint88(x)); } } if (r == 11) { assertEq(SafeCastLib.toUint96(uint96(x)), uint96(x)); if (x >= 1 << 96) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint96(x); + this.toUint96(x); } else { - assertEq(SafeCastLib.toUint96(x), uint96(x)); + assertEq(this.toUint96(x), uint96(x)); } } if (r == 12) { assertEq(SafeCastLib.toUint104(uint104(x)), uint104(x)); if (x >= 1 << 104) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint104(x); + this.toUint104(x); } else { - assertEq(SafeCastLib.toUint104(x), uint104(x)); + assertEq(this.toUint104(x), uint104(x)); } } if (r == 13) { assertEq(SafeCastLib.toUint112(uint112(x)), uint112(x)); if (x >= 1 << 112) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint112(x); + this.toUint112(x); } else { - assertEq(SafeCastLib.toUint112(x), uint112(x)); + assertEq(this.toUint112(x), uint112(x)); } } if (r == 14) { assertEq(SafeCastLib.toUint120(uint120(x)), uint120(x)); if (x >= 1 << 120) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint120(x); + this.toUint120(x); } else { - assertEq(SafeCastLib.toUint120(x), uint120(x)); + assertEq(this.toUint120(x), uint120(x)); } } if (r == 15) { assertEq(SafeCastLib.toUint128(uint128(x)), uint128(x)); if (x >= 1 << 128) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint128(x); + this.toUint128(x); } else { - assertEq(SafeCastLib.toUint128(x), uint128(x)); + assertEq(this.toUint128(x), uint128(x)); } } if (r == 16) { assertEq(SafeCastLib.toUint136(uint136(x)), uint136(x)); if (x >= 1 << 136) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint136(x); + this.toUint136(x); } else { - assertEq(SafeCastLib.toUint136(x), uint136(x)); + assertEq(this.toUint136(x), uint136(x)); } } if (r == 17) { assertEq(SafeCastLib.toUint144(uint144(x)), uint144(x)); if (x >= 1 << 144) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint144(x); + this.toUint144(x); } else { - assertEq(SafeCastLib.toUint144(x), uint144(x)); + assertEq(this.toUint144(x), uint144(x)); } } if (r == 18) { assertEq(SafeCastLib.toUint152(uint152(x)), uint152(x)); if (x >= 1 << 152) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint152(x); + this.toUint152(x); } else { - assertEq(SafeCastLib.toUint152(x), uint152(x)); + assertEq(this.toUint152(x), uint152(x)); } } if (r == 19) { assertEq(SafeCastLib.toUint160(uint160(x)), uint160(x)); if (x >= 1 << 160) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint160(x); + this.toUint160(x); } else { - assertEq(SafeCastLib.toUint160(x), uint160(x)); + assertEq(this.toUint160(x), uint160(x)); } } if (r == 20) { assertEq(SafeCastLib.toUint168(uint168(x)), uint168(x)); if (x >= 1 << 168) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint168(x); + this.toUint168(x); } else { - assertEq(SafeCastLib.toUint168(x), uint168(x)); + assertEq(this.toUint168(x), uint168(x)); } } if (r == 21) { assertEq(SafeCastLib.toUint176(uint176(x)), uint176(x)); if (x >= 1 << 176) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint176(x); + this.toUint176(x); } else { - assertEq(SafeCastLib.toUint176(x), uint176(x)); + assertEq(this.toUint176(x), uint176(x)); } } if (r == 22) { assertEq(SafeCastLib.toUint184(uint184(x)), uint184(x)); if (x >= 1 << 184) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint184(x); + this.toUint184(x); } else { - assertEq(SafeCastLib.toUint184(x), uint184(x)); + assertEq(this.toUint184(x), uint184(x)); } } if (r == 23) { assertEq(SafeCastLib.toUint192(uint192(x)), uint192(x)); if (x >= 1 << 192) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint192(x); + this.toUint192(x); } else { - assertEq(SafeCastLib.toUint192(x), uint192(x)); + assertEq(this.toUint192(x), uint192(x)); } } if (r == 24) { assertEq(SafeCastLib.toUint200(uint200(x)), uint200(x)); if (x >= 1 << 200) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint200(x); + this.toUint200(x); } else { - assertEq(SafeCastLib.toUint200(x), uint200(x)); + assertEq(this.toUint200(x), uint200(x)); } } if (r == 25) { assertEq(SafeCastLib.toUint208(uint208(x)), uint208(x)); if (x >= 1 << 208) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint208(x); + this.toUint208(x); } else { - assertEq(SafeCastLib.toUint208(x), uint208(x)); + assertEq(this.toUint208(x), uint208(x)); } } if (r == 26) { assertEq(SafeCastLib.toUint216(uint216(x)), uint216(x)); if (x >= 1 << 216) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint216(x); + this.toUint216(x); } else { - assertEq(SafeCastLib.toUint216(x), uint216(x)); + assertEq(this.toUint216(x), uint216(x)); } } if (r == 27) { assertEq(SafeCastLib.toUint224(uint224(x)), uint224(x)); if (x >= 1 << 224) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint224(x); + this.toUint224(x); } else { - assertEq(SafeCastLib.toUint224(x), uint224(x)); + assertEq(this.toUint224(x), uint224(x)); } } if (r == 28) { assertEq(SafeCastLib.toUint232(uint232(x)), uint232(x)); if (x >= 1 << 232) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint232(x); + this.toUint232(x); } else { - assertEq(SafeCastLib.toUint232(x), uint232(x)); + assertEq(this.toUint232(x), uint232(x)); } } if (r == 29) { assertEq(SafeCastLib.toUint240(uint240(x)), uint240(x)); if (x >= 1 << 240) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint240(x); + this.toUint240(x); } else { - assertEq(SafeCastLib.toUint240(x), uint240(x)); + assertEq(this.toUint240(x), uint240(x)); } } if (r == 30) { assertEq(SafeCastLib.toUint248(uint248(x)), uint248(x)); if (x >= 1 << 248) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint248(x); + this.toUint248(x); } else { - assertEq(SafeCastLib.toUint248(x), uint248(x)); + assertEq(this.toUint248(x), uint248(x)); } } r = _random(); @@ -351,279 +723,279 @@ contract SafeCastLibTest is SoladyTest { assertEq(SafeCastLib.toInt8(int8(x)), int8(x)); if (int8(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt8(x); + this.toInt8(x); } else { - assertEq(SafeCastLib.toInt8(x), int8(x)); + assertEq(this.toInt8(x), int8(x)); } } if (r == 1) { - assertEq(SafeCastLib.toInt16(int16(x)), int16(x)); + assertEq(this.toInt16(int16(x)), int16(x)); if (int16(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt16(x); + this.toInt16(x); } else { - assertEq(SafeCastLib.toInt16(x), int16(x)); + assertEq(this.toInt16(x), int16(x)); } } if (r == 2) { - assertEq(SafeCastLib.toInt24(int24(x)), int24(x)); + assertEq(this.toInt24(int24(x)), int24(x)); if (int24(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt24(x); + this.toInt24(x); } else { - assertEq(SafeCastLib.toInt24(x), int24(x)); + assertEq(this.toInt24(x), int24(x)); } } if (r == 3) { - assertEq(SafeCastLib.toInt32(int32(x)), int32(x)); + assertEq(this.toInt32(int32(x)), int32(x)); if (int32(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt32(x); + this.toInt32(x); } else { - assertEq(SafeCastLib.toInt32(x), int32(x)); + assertEq(this.toInt32(x), int32(x)); } } if (r == 4) { - assertEq(SafeCastLib.toInt40(int40(x)), int40(x)); + assertEq(this.toInt40(int40(x)), int40(x)); if (int40(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt40(x); + this.toInt40(x); } else { - assertEq(SafeCastLib.toInt40(x), int40(x)); + assertEq(this.toInt40(x), int40(x)); } } if (r == 5) { - assertEq(SafeCastLib.toInt48(int48(x)), int48(x)); + assertEq(this.toInt48(int48(x)), int48(x)); if (int48(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt48(x); + this.toInt48(x); } else { - assertEq(SafeCastLib.toInt48(x), int48(x)); + assertEq(this.toInt48(x), int48(x)); } } if (r == 6) { - assertEq(SafeCastLib.toInt56(int56(x)), int56(x)); + assertEq(this.toInt56(int56(x)), int56(x)); if (int56(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt56(x); + this.toInt56(x); } else { - assertEq(SafeCastLib.toInt56(x), int56(x)); + assertEq(this.toInt56(x), int56(x)); } } if (r == 7) { - assertEq(SafeCastLib.toInt64(int64(x)), int64(x)); + assertEq(this.toInt64(int64(x)), int64(x)); if (int64(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt64(x); + this.toInt64(x); } else { - assertEq(SafeCastLib.toInt64(x), int64(x)); + assertEq(this.toInt64(x), int64(x)); } } if (r == 8) { - assertEq(SafeCastLib.toInt72(int72(x)), int72(x)); + assertEq(this.toInt72(int72(x)), int72(x)); if (int72(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt72(x); + this.toInt72(x); } else { - assertEq(SafeCastLib.toInt72(x), int72(x)); + assertEq(this.toInt72(x), int72(x)); } } if (r == 9) { - assertEq(SafeCastLib.toInt80(int80(x)), int80(x)); + assertEq(this.toInt80(int80(x)), int80(x)); if (int80(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt80(x); + this.toInt80(x); } else { - assertEq(SafeCastLib.toInt80(x), int80(x)); + assertEq(this.toInt80(x), int80(x)); } } if (r == 10) { - assertEq(SafeCastLib.toInt88(int88(x)), int88(x)); + assertEq(this.toInt88(int88(x)), int88(x)); if (int88(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt88(x); + this.toInt88(x); } else { - assertEq(SafeCastLib.toInt88(x), int88(x)); + assertEq(this.toInt88(x), int88(x)); } } if (r == 11) { - assertEq(SafeCastLib.toInt96(int96(x)), int96(x)); + assertEq(this.toInt96(int96(x)), int96(x)); if (int96(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt96(x); + this.toInt96(x); } else { - assertEq(SafeCastLib.toInt96(x), int96(x)); + assertEq(this.toInt96(x), int96(x)); } } if (r == 12) { - assertEq(SafeCastLib.toInt104(int104(x)), int104(x)); + assertEq(this.toInt104(int104(x)), int104(x)); if (int104(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt104(x); + this.toInt104(x); } else { - assertEq(SafeCastLib.toInt104(x), int104(x)); + assertEq(this.toInt104(x), int104(x)); } } if (r == 13) { - assertEq(SafeCastLib.toInt112(int112(x)), int112(x)); + assertEq(this.toInt112(int112(x)), int112(x)); if (int112(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt112(x); + this.toInt112(x); } else { - assertEq(SafeCastLib.toInt112(x), int112(x)); + assertEq(this.toInt112(x), int112(x)); } } if (r == 14) { - assertEq(SafeCastLib.toInt120(int120(x)), int120(x)); + assertEq(this.toInt120(int120(x)), int120(x)); if (int120(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt120(x); + this.toInt120(x); } else { - assertEq(SafeCastLib.toInt120(x), int120(x)); + assertEq(this.toInt120(x), int120(x)); } } if (r == 15) { - assertEq(SafeCastLib.toInt128(int128(x)), int128(x)); + assertEq(this.toInt128(int128(x)), int128(x)); if (int128(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt128(x); + this.toInt128(x); } else { - assertEq(SafeCastLib.toInt128(x), int128(x)); + assertEq(this.toInt128(x), int128(x)); } } if (r == 16) { - assertEq(SafeCastLib.toInt136(int136(x)), int136(x)); + assertEq(this.toInt136(int136(x)), int136(x)); if (int136(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt136(x); + this.toInt136(x); } else { - assertEq(SafeCastLib.toInt136(x), int136(x)); + assertEq(this.toInt136(x), int136(x)); } } if (r == 17) { - assertEq(SafeCastLib.toInt144(int144(x)), int144(x)); + assertEq(this.toInt144(int144(x)), int144(x)); if (int144(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt144(x); + this.toInt144(x); } else { - assertEq(SafeCastLib.toInt144(x), int144(x)); + assertEq(this.toInt144(x), int144(x)); } } if (r == 18) { - assertEq(SafeCastLib.toInt152(int152(x)), int152(x)); + assertEq(this.toInt152(int152(x)), int152(x)); if (int152(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt152(x); + this.toInt152(x); } else { - assertEq(SafeCastLib.toInt152(x), int152(x)); + assertEq(this.toInt152(x), int152(x)); } } if (r == 19) { - assertEq(SafeCastLib.toInt160(int160(x)), int160(x)); + assertEq(this.toInt160(int160(x)), int160(x)); if (int160(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt160(x); + this.toInt160(x); } else { - assertEq(SafeCastLib.toInt160(x), int160(x)); + assertEq(this.toInt160(x), int160(x)); } } if (r == 20) { - assertEq(SafeCastLib.toInt168(int168(x)), int168(x)); + assertEq(this.toInt168(int168(x)), int168(x)); if (int168(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt168(x); + this.toInt168(x); } else { - assertEq(SafeCastLib.toInt168(x), int168(x)); + assertEq(this.toInt168(x), int168(x)); } } if (r == 21) { - assertEq(SafeCastLib.toInt176(int176(x)), int176(x)); + assertEq(this.toInt176(int176(x)), int176(x)); if (int176(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt176(x); + this.toInt176(x); } else { - assertEq(SafeCastLib.toInt176(x), int176(x)); + assertEq(this.toInt176(x), int176(x)); } } if (r == 22) { - assertEq(SafeCastLib.toInt184(int184(x)), int184(x)); + assertEq(this.toInt184(int184(x)), int184(x)); if (int184(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt184(x); + this.toInt184(x); } else { - assertEq(SafeCastLib.toInt184(x), int184(x)); + assertEq(this.toInt184(x), int184(x)); } } if (r == 23) { - assertEq(SafeCastLib.toInt192(int192(x)), int192(x)); + assertEq(this.toInt192(int192(x)), int192(x)); if (int192(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt192(x); + this.toInt192(x); } else { - assertEq(SafeCastLib.toInt192(x), int192(x)); + assertEq(this.toInt192(x), int192(x)); } } if (r == 24) { - assertEq(SafeCastLib.toInt200(int200(x)), int200(x)); + assertEq(this.toInt200(int200(x)), int200(x)); if (int200(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt200(x); + this.toInt200(x); } else { - assertEq(SafeCastLib.toInt200(x), int200(x)); + assertEq(this.toInt200(x), int200(x)); } } if (r == 25) { - assertEq(SafeCastLib.toInt208(int208(x)), int208(x)); + assertEq(this.toInt208(int208(x)), int208(x)); if (int208(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt208(x); + this.toInt208(x); } else { - assertEq(SafeCastLib.toInt208(x), int208(x)); + assertEq(this.toInt208(x), int208(x)); } } if (r == 26) { - assertEq(SafeCastLib.toInt216(int216(x)), int216(x)); + assertEq(this.toInt216(int216(x)), int216(x)); if (int216(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt216(x); + this.toInt216(x); } else { - assertEq(SafeCastLib.toInt216(x), int216(x)); + assertEq(this.toInt216(x), int216(x)); } } if (r == 27) { - assertEq(SafeCastLib.toInt224(int224(x)), int224(x)); + assertEq(this.toInt224(int224(x)), int224(x)); if (int224(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt224(x); + this.toInt224(x); } else { - assertEq(SafeCastLib.toInt224(x), int224(x)); + assertEq(this.toInt224(x), int224(x)); } } if (r == 28) { - assertEq(SafeCastLib.toInt232(int232(x)), int232(x)); + assertEq(this.toInt232(int232(x)), int232(x)); if (int232(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt232(x); + this.toInt232(x); } else { - assertEq(SafeCastLib.toInt232(x), int232(x)); + assertEq(this.toInt232(x), int232(x)); } } if (r == 29) { - assertEq(SafeCastLib.toInt240(int240(x)), int240(x)); + assertEq(this.toInt240(int240(x)), int240(x)); if (int240(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt240(x); + this.toInt240(x); } else { - assertEq(SafeCastLib.toInt240(x), int240(x)); + assertEq(this.toInt240(x), int240(x)); } } if (r == 30) { - assertEq(SafeCastLib.toInt248(int248(x)), int248(x)); + assertEq(this.toInt248(int248(x)), int248(x)); if (int248(x) != x) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt248(x); + this.toInt248(x); } else { - assertEq(SafeCastLib.toInt248(x), int248(x)); + assertEq(this.toInt248(x), int248(x)); } } r = _random(); @@ -679,279 +1051,279 @@ contract SafeCastLibTest is SoladyTest { assertEq(SafeCastLib.toInt8(int256(int8(int256(x)))), int256(int8(int256(x)))); if (x >= 1 << 7) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt8(x); + this.toInt8(x); } else { - assertEq(SafeCastLib.toInt8(x), int8(int256(x))); + assertEq(this.toInt8(x), int8(int256(x))); } } if (r == 1) { assertEq(SafeCastLib.toInt16(int256(int16(int256(x)))), int256(int16(int256(x)))); if (x >= 1 << 15) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt16(x); + this.toInt16(x); } else { - assertEq(SafeCastLib.toInt16(x), int16(int256(x))); + assertEq(this.toInt16(x), int16(int256(x))); } } if (r == 2) { assertEq(SafeCastLib.toInt24(int256(int24(int256(x)))), int256(int24(int256(x)))); if (x >= 1 << 23) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt24(x); + this.toInt24(x); } else { - assertEq(SafeCastLib.toInt24(x), int24(int256(x))); + assertEq(this.toInt24(x), int24(int256(x))); } } if (r == 3) { assertEq(SafeCastLib.toInt32(int256(int32(int256(x)))), int256(int32(int256(x)))); if (x >= 1 << 31) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt32(x); + this.toInt32(x); } else { - assertEq(SafeCastLib.toInt32(x), int32(int256(x))); + assertEq(this.toInt32(x), int32(int256(x))); } } if (r == 4) { assertEq(SafeCastLib.toInt40(int256(int40(int256(x)))), int256(int40(int256(x)))); if (x >= 1 << 39) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt40(x); + this.toInt40(x); } else { - assertEq(SafeCastLib.toInt40(x), int40(int256(x))); + assertEq(this.toInt40(x), int40(int256(x))); } } if (r == 5) { assertEq(SafeCastLib.toInt48(int256(int48(int256(x)))), int256(int48(int256(x)))); if (x >= 1 << 47) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt48(x); + this.toInt48(x); } else { - assertEq(SafeCastLib.toInt48(x), int48(int256(x))); + assertEq(this.toInt48(x), int48(int256(x))); } } if (r == 6) { assertEq(SafeCastLib.toInt56(int256(int56(int256(x)))), int256(int56(int256(x)))); if (x >= 1 << 55) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt56(x); + this.toInt56(x); } else { - assertEq(SafeCastLib.toInt56(x), int56(int256(x))); + assertEq(this.toInt56(x), int56(int256(x))); } } if (r == 7) { assertEq(SafeCastLib.toInt64(int256(int64(int256(x)))), int256(int64(int256(x)))); if (x >= 1 << 63) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt64(x); + this.toInt64(x); } else { - assertEq(SafeCastLib.toInt64(x), int64(int256(x))); + assertEq(this.toInt64(x), int64(int256(x))); } } if (r == 8) { assertEq(SafeCastLib.toInt72(int256(int72(int256(x)))), int256(int72(int256(x)))); if (x >= 1 << 71) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt72(x); + this.toInt72(x); } else { - assertEq(SafeCastLib.toInt72(x), int72(int256(x))); + assertEq(this.toInt72(x), int72(int256(x))); } } if (r == 9) { assertEq(SafeCastLib.toInt80(int256(int80(int256(x)))), int256(int80(int256(x)))); if (x >= 1 << 79) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt80(x); + this.toInt80(x); } else { - assertEq(SafeCastLib.toInt80(x), int80(int256(x))); + assertEq(this.toInt80(x), int80(int256(x))); } } if (r == 10) { assertEq(SafeCastLib.toInt88(int256(int88(int256(x)))), int256(int88(int256(x)))); if (x >= 1 << 87) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt88(x); + this.toInt88(x); } else { - assertEq(SafeCastLib.toInt88(x), int88(int256(x))); + assertEq(this.toInt88(x), int88(int256(x))); } } if (r == 11) { assertEq(SafeCastLib.toInt96(int256(int96(int256(x)))), int256(int96(int256(x)))); if (x >= 1 << 95) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt96(x); + this.toInt96(x); } else { - assertEq(SafeCastLib.toInt96(x), int96(int256(x))); + assertEq(this.toInt96(x), int96(int256(x))); } } if (r == 12) { assertEq(SafeCastLib.toInt104(int256(int104(int256(x)))), int256(int104(int256(x)))); if (x >= 1 << 103) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt104(x); + this.toInt104(x); } else { - assertEq(SafeCastLib.toInt104(x), int104(int256(x))); + assertEq(this.toInt104(x), int104(int256(x))); } } if (r == 13) { assertEq(SafeCastLib.toInt112(int256(int112(int256(x)))), int256(int112(int256(x)))); if (x >= 1 << 111) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt112(x); + this.toInt112(x); } else { - assertEq(SafeCastLib.toInt112(x), int112(int256(x))); + assertEq(this.toInt112(x), int112(int256(x))); } } if (r == 14) { assertEq(SafeCastLib.toInt120(int256(int120(int256(x)))), int256(int120(int256(x)))); if (x >= 1 << 119) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt120(x); + this.toInt120(x); } else { - assertEq(SafeCastLib.toInt120(x), int120(int256(x))); + assertEq(this.toInt120(x), int120(int256(x))); } } if (r == 15) { assertEq(SafeCastLib.toInt128(int256(int128(int256(x)))), int256(int128(int256(x)))); if (x >= 1 << 127) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt128(x); + this.toInt128(x); } else { - assertEq(SafeCastLib.toInt128(x), int128(int256(x))); + assertEq(this.toInt128(x), int128(int256(x))); } } if (r == 16) { assertEq(SafeCastLib.toInt136(int256(int136(int256(x)))), int256(int136(int256(x)))); if (x >= 1 << 135) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt136(x); + this.toInt136(x); } else { - assertEq(SafeCastLib.toInt136(x), int136(int256(x))); + assertEq(this.toInt136(x), int136(int256(x))); } } if (r == 17) { assertEq(SafeCastLib.toInt144(int256(int144(int256(x)))), int256(int144(int256(x)))); if (x >= 1 << 143) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt144(x); + this.toInt144(x); } else { - assertEq(SafeCastLib.toInt144(x), int144(int256(x))); + assertEq(this.toInt144(x), int144(int256(x))); } } if (r == 18) { assertEq(SafeCastLib.toInt152(int256(int152(int256(x)))), int256(int152(int256(x)))); if (x >= 1 << 151) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt152(x); + this.toInt152(x); } else { - assertEq(SafeCastLib.toInt152(x), int152(int256(x))); + assertEq(this.toInt152(x), int152(int256(x))); } } if (r == 19) { assertEq(SafeCastLib.toInt160(int256(int160(int256(x)))), int256(int160(int256(x)))); if (x >= 1 << 159) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt160(x); + this.toInt160(x); } else { - assertEq(SafeCastLib.toInt160(x), int160(int256(x))); + assertEq(this.toInt160(x), int160(int256(x))); } } if (r == 20) { assertEq(SafeCastLib.toInt168(int256(int168(int256(x)))), int256(int168(int256(x)))); if (x >= 1 << 167) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt168(x); + this.toInt168(x); } else { - assertEq(SafeCastLib.toInt168(x), int168(int256(x))); + assertEq(this.toInt168(x), int168(int256(x))); } } if (r == 21) { assertEq(SafeCastLib.toInt176(int256(int176(int256(x)))), int256(int176(int256(x)))); if (x >= 1 << 175) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt176(x); + this.toInt176(x); } else { - assertEq(SafeCastLib.toInt176(x), int176(int256(x))); + assertEq(this.toInt176(x), int176(int256(x))); } } if (r == 22) { assertEq(SafeCastLib.toInt184(int256(int184(int256(x)))), int256(int184(int256(x)))); if (x >= 1 << 183) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt184(x); + this.toInt184(x); } else { - assertEq(SafeCastLib.toInt184(x), int184(int256(x))); + assertEq(this.toInt184(x), int184(int256(x))); } } if (r == 23) { assertEq(SafeCastLib.toInt192(int256(int192(int256(x)))), int256(int192(int256(x)))); if (x >= 1 << 191) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt192(x); + this.toInt192(x); } else { - assertEq(SafeCastLib.toInt192(x), int192(int256(x))); + assertEq(this.toInt192(x), int192(int256(x))); } } if (r == 24) { assertEq(SafeCastLib.toInt200(int256(int200(int256(x)))), int256(int200(int256(x)))); if (x >= 1 << 199) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt200(x); + this.toInt200(x); } else { - assertEq(SafeCastLib.toInt200(x), int200(int256(x))); + assertEq(this.toInt200(x), int200(int256(x))); } } if (r == 25) { assertEq(SafeCastLib.toInt208(int256(int208(int256(x)))), int256(int208(int256(x)))); if (x >= 1 << 207) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt208(x); + this.toInt208(x); } else { - assertEq(SafeCastLib.toInt208(x), int208(int256(x))); + assertEq(this.toInt208(x), int208(int256(x))); } } if (r == 26) { assertEq(SafeCastLib.toInt216(int256(int216(int256(x)))), int256(int216(int256(x)))); if (x >= 1 << 215) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt216(x); + this.toInt216(x); } else { - assertEq(SafeCastLib.toInt216(x), int216(int256(x))); + assertEq(this.toInt216(x), int216(int256(x))); } } if (r == 27) { assertEq(SafeCastLib.toInt224(int256(int224(int256(x)))), int256(int224(int256(x)))); if (x >= 1 << 223) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt224(x); + this.toInt224(x); } else { - assertEq(SafeCastLib.toInt224(x), int224(int256(x))); + assertEq(this.toInt224(x), int224(int256(x))); } } if (r == 28) { assertEq(SafeCastLib.toInt232(int256(int232(int256(x)))), int256(int232(int256(x)))); if (x >= 1 << 231) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt232(x); + this.toInt232(x); } else { - assertEq(SafeCastLib.toInt232(x), int232(int256(x))); + assertEq(this.toInt232(x), int232(int256(x))); } } if (r == 29) { assertEq(SafeCastLib.toInt240(int256(int240(int256(x)))), int256(int240(int256(x)))); if (x >= 1 << 239) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt240(x); + this.toInt240(x); } else { - assertEq(SafeCastLib.toInt240(x), int240(int256(x))); + assertEq(this.toInt240(x), int240(int256(x))); } } if (r == 30) { assertEq(SafeCastLib.toInt248(int256(int248(int256(x)))), int256(int248(int256(x)))); if (x >= 1 << 247) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt248(x); + this.toInt248(x); } else { - assertEq(SafeCastLib.toInt248(x), int248(int256(x))); + assertEq(this.toInt248(x), int248(int256(x))); } } r = _random(); @@ -967,21 +1339,29 @@ contract SafeCastLibTest is SoladyTest { } } + function toInt256(uint256 x) public pure returns (int256) { + return SafeCastLib.toInt256(x); + } + function testSafeCastToInt256(uint256 x) public { if (x > uint256(type(int256).max)) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toInt256(x); + this.toInt256(x); } else { - assertEq(SafeCastLib.toInt256(x), int256(x)); + assertEq(this.toInt256(x), int256(x)); } } + function toUint256(int256 x) public pure returns (uint256) { + return SafeCastLib.toUint256(x); + } + function testSafeCastToUint256(int256 x) public { if (x < 0) { vm.expectRevert(SafeCastLib.Overflow.selector); - SafeCastLib.toUint256(x); + this.toUint256(x); } else { - assertEq(SafeCastLib.toUint256(x), uint256(x)); + assertEq(this.toUint256(x), uint256(x)); } }