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
36eeae15
Commit
36eeae15
authored
Jan 19, 2023
by
Maurelian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(ctb): Add bridge tests for the new bridge interface
parent
b56a2409
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
22 deletions
+93
-22
L1StandardBridge.t.sol
...s/contracts-bedrock/contracts/test/L1StandardBridge.t.sol
+49
-12
L2StandardBridge.t.sol
...s/contracts-bedrock/contracts/test/L2StandardBridge.t.sol
+44
-10
No files found.
packages/contracts-bedrock/contracts/test/L1StandardBridge.t.sol
View file @
36eeae15
...
...
@@ -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 {
...
...
packages/contracts-bedrock/contracts/test/L2StandardBridge.t.sol
View file @
36eeae15
...
...
@@ -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
...
...
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