Commit c24298e7 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #7969 from ethereum-optimism/ctb/message-passer-fuzz

contracts-bedrock: fuzz message passer
parents 405cb36b 961c966f
...@@ -291,9 +291,6 @@ L2StandardBridge_Test:test_initialize_succeeds() (gas: 26316) ...@@ -291,9 +291,6 @@ L2StandardBridge_Test:test_initialize_succeeds() (gas: 26316)
L2StandardBridge_Test:test_receive_succeeds() (gas: 177125) L2StandardBridge_Test:test_receive_succeeds() (gas: 177125)
L2StandardBridge_Test:test_withdraw_ether_succeeds() (gas: 143366) L2StandardBridge_Test:test_withdraw_ether_succeeds() (gas: 143366)
L2StandardBridge_Test:test_withdraw_insufficientValue_reverts() (gas: 16552) L2StandardBridge_Test:test_withdraw_insufficientValue_reverts() (gas: 16552)
L2ToL1MessagePasserTest:test_burn_succeeds() (gas: 112530)
L2ToL1MessagePasserTest:test_initiateWithdrawal_fromContract_succeeds() (gas: 70343)
L2ToL1MessagePasserTest:test_initiateWithdrawal_fromEOA_succeeds() (gas: 75830)
LegacyERC20ETH_Test:test_approve_doesNotExist_reverts() (gas: 10702) LegacyERC20ETH_Test:test_approve_doesNotExist_reverts() (gas: 10702)
LegacyERC20ETH_Test:test_burn_doesNotExist_reverts() (gas: 10637) LegacyERC20ETH_Test:test_burn_doesNotExist_reverts() (gas: 10637)
LegacyERC20ETH_Test:test_crossDomain_succeeds() (gas: 6341) LegacyERC20ETH_Test:test_crossDomain_succeeds() (gas: 6341)
......
...@@ -72,37 +72,56 @@ contract L2ToL1MessagePasserTest is CommonTest { ...@@ -72,37 +72,56 @@ contract L2ToL1MessagePasserTest is CommonTest {
/// @dev Tests that `initiateWithdrawal` succeeds and emits the correct MessagePassed /// @dev Tests that `initiateWithdrawal` succeeds and emits the correct MessagePassed
/// log when called by a contract. /// log when called by a contract.
function test_initiateWithdrawal_fromContract_succeeds() external { function testFuzz_initiateWithdrawal_fromContract_succeeds(
address _target,
uint256 _gasLimit,
uint256 _value,
bytes memory _data
)
external
{
bytes32 withdrawalHash = Hashing.hashWithdrawal( bytes32 withdrawalHash = Hashing.hashWithdrawal(
Types.WithdrawalTransaction(messagePasser.messageNonce(), address(this), address(4), 100, 64000, hex"") Types.WithdrawalTransaction({
nonce: messagePasser.messageNonce(),
sender: address(this),
target: _target,
value: _value,
gasLimit: _gasLimit,
data: _data
})
); );
vm.expectEmit(true, true, true, true); vm.expectEmit(address(messagePasser));
emit MessagePassed(messagePasser.messageNonce(), address(this), address(4), 100, 64000, hex"", withdrawalHash); emit MessagePassed(
messagePasser.messageNonce(), address(this), _target, _value, _gasLimit, _data, withdrawalHash
);
vm.deal(address(this), 2 ** 64); vm.deal(address(this), _value);
messagePasser.initiateWithdrawal{ value: 100 }(address(4), 64000, hex""); messagePasser.initiateWithdrawal{ value: _value }(_target, _gasLimit, _data);
} }
/// @dev Tests that `initiateWithdrawal` succeeds and emits the correct MessagePassed /// @dev Tests that `initiateWithdrawal` succeeds and emits the correct MessagePassed
/// log when called by an EOA. /// log when called by an EOA.
function test_initiateWithdrawal_fromEOA_succeeds() external { function testFuzz_initiateWithdrawal_fromEOA_succeeds(
uint256 gasLimit = 64000; uint256 _gasLimit,
address target = address(4); address _target,
uint256 value = 100; uint256 _value,
bytes memory data = hex"ff"; bytes memory _data
)
external
{
uint256 nonce = messagePasser.messageNonce(); uint256 nonce = messagePasser.messageNonce();
// EOA emulation // EOA emulation
vm.prank(alice, alice); vm.prank(alice, alice);
vm.deal(alice, 2 ** 64); vm.deal(alice, _value);
bytes32 withdrawalHash = bytes32 withdrawalHash =
Hashing.hashWithdrawal(Types.WithdrawalTransaction(nonce, alice, target, value, gasLimit, data)); Hashing.hashWithdrawal(Types.WithdrawalTransaction(nonce, alice, _target, _value, _gasLimit, _data));
vm.expectEmit(true, true, true, true); vm.expectEmit(address(messagePasser));
emit MessagePassed(nonce, alice, target, value, gasLimit, data, withdrawalHash); emit MessagePassed(nonce, alice, _target, _value, _gasLimit, _data, withdrawalHash);
messagePasser.initiateWithdrawal{ value: value }(target, gasLimit, data); messagePasser.initiateWithdrawal{ value: _value }({ _target: _target, _gasLimit: _gasLimit, _data: _data });
// the sent messages mapping is filled // the sent messages mapping is filled
assertEq(messagePasser.sentMessages(withdrawalHash), true); assertEq(messagePasser.sentMessages(withdrawalHash), true);
...@@ -111,12 +130,14 @@ contract L2ToL1MessagePasserTest is CommonTest { ...@@ -111,12 +130,14 @@ contract L2ToL1MessagePasserTest is CommonTest {
} }
/// @dev Tests that `burn` succeeds and destroys the ETH held in the contract. /// @dev Tests that `burn` succeeds and destroys the ETH held in the contract.
function test_burn_succeeds() external { function testFuzz_burn_succeeds(uint256 _value, address _target, uint256 _gasLimit, bytes memory _data) external {
messagePasser.initiateWithdrawal{ value: NON_ZERO_VALUE }(NON_ZERO_ADDRESS, NON_ZERO_GASLIMIT, NON_ZERO_DATA); vm.deal(address(this), _value);
messagePasser.initiateWithdrawal{ value: _value }({ _target: _target, _gasLimit: _gasLimit, _data: _data });
assertEq(address(messagePasser).balance, NON_ZERO_VALUE); assertEq(address(messagePasser).balance, _value);
vm.expectEmit(true, false, false, false); vm.expectEmit(true, false, false, false);
emit WithdrawerBalanceBurnt(NON_ZERO_VALUE); emit WithdrawerBalanceBurnt(_value);
messagePasser.burn(); messagePasser.burn();
// The Withdrawer should have no balance // The Withdrawer should have no balance
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment