-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into dev-governance-refactor
- Loading branch information
Showing
5 changed files
with
64 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.24; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
|
||
import {safeCallWithMinGas} from "src/utils/SafeCallMinGas.sol"; | ||
|
||
contract BasicRecipient { | ||
bool public callWasValid; | ||
|
||
function validCall() external { | ||
callWasValid = true; | ||
} | ||
} | ||
contract FallbackRecipient { | ||
bytes public received; | ||
|
||
fallback() external payable { | ||
received = msg.data; | ||
} | ||
} | ||
|
||
contract SafeCallWithMinGasTests is Test { | ||
|
||
function test_basic_nonExistent(uint256 gas, uint256 value, bytes memory theData) public { | ||
vm.assume(gas < 30_000_000); | ||
// Call to non existent succeeds | ||
address nonExistent = address(0x123123123); | ||
assert(nonExistent.code.length == 0); | ||
|
||
safeCallWithMinGas(address(0x123123123), gas, value, theData); | ||
} | ||
|
||
function test_basic_contractData(uint256 gas, uint256 value, bytes memory theData) public { | ||
vm.assume(gas < 30_000_000); | ||
vm.assume(gas > 50_000 + theData.length * 2_100); /// @audit Approximation | ||
FallbackRecipient recipient = new FallbackRecipient(); | ||
// Call to non existent succeeds | ||
|
||
vm.deal(address(this), value); | ||
|
||
safeCallWithMinGas(address(recipient), gas, value, theData); | ||
assertEq(keccak256(recipient.received()), keccak256(theData), "same data"); | ||
} | ||
function test_basic_contractCall() public { | ||
BasicRecipient recipient = new BasicRecipient(); | ||
// Call to non existent succeeds | ||
|
||
safeCallWithMinGas(address(recipient), 35_000, 0, abi.encodeCall(BasicRecipient.validCall, ())); | ||
assertEq(recipient.callWasValid(), true, "Call success"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters