Skip to content

Commit

Permalink
Merge pull request #244 from lidofinance/fix/fix-sealable-calls-unit-…
Browse files Browse the repository at this point in the history
…tests

Fix sealable calls unit tests
  • Loading branch information
Psirex authored Dec 25, 2024
2 parents af9970e + 1781a4f commit 04a82d7
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions test/unit/libraries/SealableCalls.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {ISealable, SealableCalls} from "contracts/libraries/SealableCalls.sol";

import {UnitTest} from "test/utils/unit-test.sol";

uint256 constant BLOCK_GAS_LIMIT = 30_000_000;

error CustomSealableError(string message);

contract SealableCallsTest is UnitTest {
Expand Down Expand Up @@ -104,11 +106,11 @@ contract SealableCallsTest is UnitTest {
}

// ---
// Other Precompiles (Split in 2 parts because of out of gas)
// Other Precompile Calls Are Not Successful
// ---

function test_callGetResumeSinceTimestamp_IsCallSucceed_CorrectResult_On_Other_Precompiles_Part1() external {
for (uint160 i = 1; i < 8; ++i) {
function test_callGetResumeSinceTimestamp_IsCallSucceed_CorrectResult_On_Other_Precompiles() external {
for (uint160 i = 1; i < 12; ++i) {
// Skip SHA-256 and RIPEMD-160 precompiles which lead to false positive results
if (i == 0x2 || i == 0x3) continue;
_assertGetResumeSinceTimestampCallResult({
Expand All @@ -119,16 +121,6 @@ contract SealableCallsTest is UnitTest {
}
}

function test_callGetResumeSinceTimestamp_IsCallSucceed_CorrectResult_On_Other_Precompiles_Part2() external {
for (uint160 i = 8; i < 12; ++i) {
_assertGetResumeSinceTimestampCallResult({
sealable: address(i),
isCallSucceed: false,
resumeSinceTimestamp: 0
});
}
}

// ---
// Helper Test Methods
// ---
Expand All @@ -147,7 +139,8 @@ contract SealableCallsTest is UnitTest {
uint256 resumeSinceTimestamp
) internal {
(bool isCallSucceedActual, uint256 resumeSinceTimestampActual) =
SealableCalls.callGetResumeSinceTimestamp(sealable);
// Limit the maximum gas cost for the call to mimic mainnet behavior
this.external__getResumeSinceTimestampCall{gas: BLOCK_GAS_LIMIT}(sealable);

assertEq(isCallSucceedActual, isCallSucceed, "Unexpected isCallSucceed value");
assertEq(resumeSinceTimestampActual, resumeSinceTimestamp, "Unexpected resumeSinceTimestamp value");
Expand All @@ -156,4 +149,8 @@ contract SealableCallsTest is UnitTest {
function _mockSealableResumeSinceTimestampReverts(address sealable, bytes memory revertReason) internal {
vm.mockCallRevert(sealable, abi.encodeWithSelector(ISealable.getResumeSinceTimestamp.selector), revertReason);
}

function external__getResumeSinceTimestampCall(address sealable) external returns (bool, uint256) {
return SealableCalls.callGetResumeSinceTimestamp(sealable);
}
}

0 comments on commit 04a82d7

Please sign in to comment.