Commit 4bf21aec authored by Michael Amadi's avatar Michael Amadi Committed by GitHub

add depositETH test for optimismPortal and optimismPortal2 (#13423)

parent f3e1c3c2
......@@ -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 {
......
......@@ -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 {
......
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