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
4bf21aec
Unverified
Commit
4bf21aec
authored
Dec 16, 2024
by
Michael Amadi
Committed by
GitHub
Dec 16, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add depositETH test for optimismPortal and optimismPortal2 (#13423)
parent
f3e1c3c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
0 deletions
+82
-0
OptimismPortal.t.sol
packages/contracts-bedrock/test/L1/OptimismPortal.t.sol
+41
-0
OptimismPortal2.t.sol
packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol
+41
-0
No files found.
packages/contracts-bedrock/test/L1/OptimismPortal.t.sol
View file @
4bf21aec
...
...
@@ -570,6 +570,47 @@ contract OptimismPortal_Test is CommonTest {
// Check that the balance has been correctly updated
assertEq(optimismPortal.balance(), address(optimismPortal).balance);
}
/// @dev Tests that the donateETH function donates ETH and does no state read/write
function test_donateETH_succeeds(uint256 _amount) external {
vm.startPrank(alice);
vm.deal(alice, _amount);
uint256 preBalance = address(optimismPortal).balance;
vm.startStateDiffRecording();
optimismPortal.donateETH{ value: _amount }();
VmSafe.AccountAccess[] memory accountAccesses = vm.stopAndReturnStateDiff();
// not necessary since it's checked below
assertEq(address(optimismPortal).balance, preBalance + _amount);
// 0 for extcodesize of proxy before being called by this test,
// 1 for the call to the proxy by the pranked address
// 2 for the delegate call to the impl by the proxy
assertEq(accountAccesses.length, 3);
assertEq(uint8(accountAccesses[1].kind), uint8(VmSafe.AccountAccessKind.Call));
assertEq(uint8(accountAccesses[2].kind), uint8(VmSafe.AccountAccessKind.DelegateCall));
// to of 1 is the optimism portal proxy
assertEq(accountAccesses[1].account, address(optimismPortal));
// accessor is the pranked address
assertEq(accountAccesses[1].accessor, alice);
// value is the amount of ETH donated
assertEq(accountAccesses[1].value, _amount);
// old balance is the balance of the optimism portal before the donation
assertEq(accountAccesses[1].oldBalance, preBalance);
// new balance is the balance of the optimism portal after the donation
assertEq(accountAccesses[1].newBalance, preBalance + _amount);
// data is the selector of the donateETH function
assertEq(accountAccesses[1].data, abi.encodePacked(optimismPortal.donateETH.selector));
// reverted of alice call to proxy is false
assertEq(accountAccesses[1].reverted, false);
// reverted of delegate call of proxy to impl is false
assertEq(accountAccesses[2].reverted, false);
// storage accesses of delegate call of proxy to impl is empty (No storage read or write!)
assertEq(accountAccesses[2].storageAccesses.length, 0);
}
}
contract OptimismPortal_FinalizeWithdrawal_Test is CommonTest {
...
...
packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol
View file @
4bf21aec
...
...
@@ -421,6 +421,47 @@ contract OptimismPortal2_Test is CommonTest {
// Check that the balance has been correctly updated
assertEq(optimismPortal2.balance(), address(optimismPortal2).balance);
}
/// @dev Tests that the donateETH function donates ETH and does no state read/write
function test_donateETH_succeeds(uint256 _amount) external {
vm.startPrank(alice);
vm.deal(alice, _amount);
uint256 preBalance = address(optimismPortal2).balance;
vm.startStateDiffRecording();
optimismPortal2.donateETH{ value: _amount }();
VmSafe.AccountAccess[] memory accountAccesses = vm.stopAndReturnStateDiff();
// not necessary since it's checked below
assertEq(address(optimismPortal2).balance, preBalance + _amount);
// 0 for extcodesize of proxy before being called by this test,
// 1 for the call to the proxy by the pranked address
// 2 for the delegate call to the impl by the proxy
assertEq(accountAccesses.length, 3);
assertEq(uint8(accountAccesses[1].kind), uint8(VmSafe.AccountAccessKind.Call));
assertEq(uint8(accountAccesses[2].kind), uint8(VmSafe.AccountAccessKind.DelegateCall));
// to of 1 is the optimism portal proxy
assertEq(accountAccesses[1].account, address(optimismPortal2));
// accessor is the pranked address
assertEq(accountAccesses[1].accessor, alice);
// value is the amount of ETH donated
assertEq(accountAccesses[1].value, _amount);
// old balance is the balance of the optimism portal before the donation
assertEq(accountAccesses[1].oldBalance, preBalance);
// new balance is the balance of the optimism portal after the donation
assertEq(accountAccesses[1].newBalance, preBalance + _amount);
// data is the selector of the donateETH function
assertEq(accountAccesses[1].data, abi.encodePacked(optimismPortal2.donateETH.selector));
// reverted of alice call to proxy is false
assertEq(accountAccesses[1].reverted, false);
// reverted of delegate call of proxy to impl is false
assertEq(accountAccesses[2].reverted, false);
// storage accesses of delegate call of proxy to impl is empty (No storage read or write!)
assertEq(accountAccesses[2].storageAccesses.length, 0);
}
}
contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
...
...
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