Commit 36eeae15 authored by Maurelian's avatar Maurelian

test(ctb): Add bridge tests for the new bridge interface

parent b56a2409
......@@ -72,12 +72,7 @@ contract L1StandardBridge_Receive_Test is Bridge_Initializer {
contract L1StandardBridge_Receive_TestFail {}
contract L1StandardBridge_DepositETH_Test is Bridge_Initializer {
// depositETH
// - emits ETHDepositInitiated
// - calls optimismPortal.depositTransaction
// - only EOA
// - ETH ends up in the optimismPortal
function test_depositETH_succeeds() external {
function _preDepositETH() internal {
assertEq(address(op).balance, 0);
uint256 nonce = L1Messenger.messageNonce();
uint256 version = 0; // Internal constant in the OptimismPortal: DEPOSIT_VERSION
......@@ -151,11 +146,35 @@ contract L1StandardBridge_DepositETH_Test is Bridge_Initializer {
emit SentMessageExtension1(address(L1Bridge), 500);
vm.prank(alice, alice);
}
// depositETH
// - emits ETHDepositInitiated
// - emits ETHBridgeInitiated
// - calls optimismPortal.depositTransaction
// - only EOA
// - ETH ends up in the optimismPortal
function test_depositETH_succeeds() external {
_preDepositETH();
L1Bridge.depositETH{ value: 500 }(50000, hex"ff");
assertEq(address(op).balance, 500);
}
}
contract L1StandardBridge_BridgeETH_Test is L1StandardBridge_DepositETH_Test {
// BridgeETH
// - emits ETHDepositInitiated
// - emits ETHBridgeInitiated
// - calls optimismPortal.depositTransaction
// - only EOA
// - ETH ends up in the optimismPortal
function test_bridgeETH_succeeds() external {
_preDepositETH();
L1Bridge.bridgeETH{ value: 500 }(50000, hex"ff");
assertEq(address(op).balance, 500);
}
}
contract L1StandardBridge_DepositETH_TestFail is Bridge_Initializer {
function test_depositETH_notEoa_reverts() external {
// turn alice into a contract
......@@ -168,12 +187,7 @@ contract L1StandardBridge_DepositETH_TestFail is Bridge_Initializer {
}
contract L1StandardBridge_DepositETHTo_Test is Bridge_Initializer {
// depositETHTo
// - emits ETHDepositInitiated
// - calls optimismPortal.depositTransaction
// - EOA or contract can call
// - ETH ends up in the optimismPortal
function test_depositETHTo_succeeds() external {
function _preDepositETHTo() internal {
assertEq(address(op).balance, 0);
uint256 nonce = L1Messenger.messageNonce();
uint256 version = 0; // Internal constant in the OptimismPortal: DEPOSIT_VERSION
......@@ -256,10 +270,33 @@ contract L1StandardBridge_DepositETHTo_Test is Bridge_Initializer {
// deposit eth to bob
vm.prank(alice, alice);
}
// depositETHTo
// - emits ETHDepositInitiated
// - calls optimismPortal.depositTransaction
// - EOA or contract can call
// - ETH ends up in the optimismPortal
function test_depositETHTo_succeeds() external {
_preDepositETHTo();
L1Bridge.depositETHTo{ value: 600 }(bob, 1000, hex"dead");
}
}
contract L1StandardBridge_BridgeETHTo_Test is L1StandardBridge_DepositETHTo_Test {
// BridgeETHTo
// - emits ETHDepositInitiated
// - emits ETHBridgeInitiated
// - calls optimismPortal.depositTransaction
// - only EOA
// - ETH ends up in the optimismPortal
function test_bridgeETHTo_succeeds() external {
_preDepositETHTo();
L1Bridge.bridgeETHTo{ value: 500 }(bob, 50000, hex"ff");
assertEq(address(op).balance, 500);
}
}
contract L1StandardBridge_DepositETHTo_TestFail is Bridge_Initializer {}
contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer {
......
......@@ -119,11 +119,9 @@ contract L2StandardBridge_Test is Bridge_Initializer {
L2Bridge.withdraw(address(Predeploys.LEGACY_ERC20_ETH), 100, 1000, hex"");
}
// withdraw
// - token is burned
// - emits WithdrawalInitiated
// - calls Withdrawer.initiateWithdrawal
function test_withdraw_withdrawingERC20_succeeds() external {
// withdrawTo and BridgeERC20To should behave the same when transferring ERC20 tokens
// so they should share the same setup and expectEmit calls
function _preWithdraw() private {
// Alice has 100 L2Token
deal(address(L2Token), alice, 100, true);
assertEq(L2Token.balanceOf(alice), 100);
......@@ -210,11 +208,30 @@ contract L2StandardBridge_Test is Bridge_Initializer {
);
vm.prank(alice, alice);
}
// withdraw
// - token is burned
// - emits WithdrawalInitiated
// - calls Withdrawer.initiateWithdrawal
function test_withdraw_withdrawingERC20_succeeds() external {
_preWithdraw();
L2Bridge.withdraw(address(L2Token), 100, 1000, hex"");
assertEq(L2Token.balanceOf(alice), 0);
}
// BridgeERC20
// - token is burned
// - emits WithdrawalInitiated
// - calls Withdrawer.initiateWithdrawal
function test_bridgeERC20_succeeds() external {
_preWithdraw();
L2Bridge.bridgeERC20(address(L2Token), address(L1Token), 100, 1000, hex"");
assertEq(L2Token.balanceOf(alice), 0);
}
function test_withdraw_notEOA_reverts() external {
// This contract has 100 L2Token
deal(address(L2Token), address(this), 100, true);
......@@ -223,11 +240,9 @@ contract L2StandardBridge_Test is Bridge_Initializer {
L2Bridge.withdraw(address(L2Token), 100, 1000, hex"");
}
// withdrawTo
// - token is burned
// - emits WithdrawalInitiated w/ correct recipient
// - calls Withdrawer.initiateWithdrawal
function test_withdrawTo_withdrawingERC20_succeeds() external {
// withdrawTo and BridgeERC20To should behave the same when transferring ERC20 tokens
// so they should share the same setup and expectEmit calls
function _preWithdrawTo() private {
deal(address(L2Token), alice, 100, true);
assertEq(L2Token.balanceOf(alice), 100);
uint256 nonce = L2Messenger.messageNonce();
......@@ -313,11 +328,30 @@ contract L2StandardBridge_Test is Bridge_Initializer {
);
vm.prank(alice, alice);
}
// withdrawTo
// - token is burned
// - emits WithdrawalInitiated w/ correct recipient
// - calls Withdrawer.initiateWithdrawal
function test_withdrawTo_withdrawingERC20_succeeds() external {
_preWithdrawTo();
L2Bridge.withdrawTo(address(L2Token), bob, 100, 1000, hex"");
assertEq(L2Token.balanceOf(alice), 0);
}
// bridgeERC20To
// - token is burned
// - emits WithdrawalInitiated w/ correct recipient
// - calls Withdrawer.initiateWithdrawal
function test_bridgeERC20To__succeeds() external {
_preWithdrawTo();
vm.prank(alice, alice);
L2Bridge.bridgeERC20To(address(L2Token), address(L1Token), bob, 100, 1000, hex"");
assertEq(L2Token.balanceOf(alice), 0);
}
// finalizeDeposit
// - only callable by l1TokenBridge
// - supported token pair emits DepositFinalized
......
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