Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
c24298e7
Unverified
Commit
c24298e7
authored
Nov 01, 2023
by
Mark Tyneway
Committed by
GitHub
Nov 01, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7969 from ethereum-optimism/ctb/message-passer-fuzz
contracts-bedrock: fuzz message passer
parents
405cb36b
961c966f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
23 deletions
+41
-23
.gas-snapshot
packages/contracts-bedrock/.gas-snapshot
+0
-3
L2ToL1MessagePasser.t.sol
packages/contracts-bedrock/test/L2ToL1MessagePasser.t.sol
+41
-20
No files found.
packages/contracts-bedrock/.gas-snapshot
View file @
c24298e7
...
@@ -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)
...
...
packages/contracts-bedrock/test/L2ToL1MessagePasser.t.sol
View file @
c24298e7
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment