Skip to content

Commit

Permalink
L2->L1 ETH bridging unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
karlb committed Nov 27, 2023
1 parent 5b61854 commit cd11911
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 4 additions & 0 deletions packages/contracts-bedrock/src/L2/L2StandardBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ contract L2StandardBridge is StandardBridge, ISemver {
}
}

/* Removed for Celo: Additional backwards compatibility no needed
/// @notice Emits the legacy WithdrawalInitiated event followed by the ETHBridgeInitiated event.
/// This is necessary for backwards compatibility with the legacy bridge.
/// @inheritdoc StandardBridge
Expand All @@ -199,6 +201,8 @@ contract L2StandardBridge is StandardBridge, ISemver {
super._emitETHBridgeInitiated(_from, _to, _amount, _extraData);
}
*/

/// @notice Emits the legacy DepositFinalized event followed by the ETHBridgeFinalized event.
/// This is necessary for backwards compatibility with the legacy bridge.
/// @inheritdoc StandardBridge
Expand Down
22 changes: 11 additions & 11 deletions packages/contracts-bedrock/test/L2StandardBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { OptimismMintableERC20 } from "src/universal/OptimismMintableERC20.sol";
contract L2StandardBridge_Test is Bridge_Initializer {
using stdStorage for StdStorage;

event Burn(address indexed account, uint256 amount);

/// @dev Tests that the bridge is initialized correctly.
function test_initialize_succeeds() external {
assertEq(address(l2StandardBridge.messenger()), address(l2CrossDomainMessenger));
Expand All @@ -30,9 +32,6 @@ contract L2StandardBridge_Test is Bridge_Initializer {

/// @dev Tests that the bridge receives ETH and successfully initiates a withdrawal.
function test_receive_succeeds() external {
// TODO: update test
return;

assertEq(address(l2ToL1MessagePasser).balance, 0);
uint256 nonce = l2CrossDomainMessenger.messageNonce();

Expand All @@ -44,7 +43,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
nonce,
address(l2StandardBridge),
address(l1StandardBridge),
100,
0,
200_000,
message
);
Expand All @@ -53,14 +52,14 @@ contract L2StandardBridge_Test is Bridge_Initializer {
nonce: nonce,
sender: address(l2CrossDomainMessenger),
target: address(l1CrossDomainMessenger),
value: 100,
value: 0,
gasLimit: baseGas,
data: withdrawalData
})
);

vm.expectEmit(true, true, true, true);
emit WithdrawalInitiated(address(0), Predeploys.LEGACY_ERC20_ETH, alice, alice, 100, hex"");
emit Burn(alice, 100);

vm.expectEmit(true, true, true, true);
emit ETHBridgeInitiated(alice, alice, 100, hex"");
Expand All @@ -71,7 +70,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
nonce,
address(l2CrossDomainMessenger),
address(l1CrossDomainMessenger),
100,
0,
baseGas,
withdrawalData,
withdrawalHash
Expand All @@ -83,7 +82,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {

// SentMessageExtension1 event emitted by the CrossDomainMessenger
vm.expectEmit(true, true, true, true, address(l2CrossDomainMessenger));
emit SentMessageExtension1(address(l2StandardBridge), 100);
emit SentMessageExtension1(address(l2StandardBridge), 0);

vm.expectCall(
address(l2CrossDomainMessenger),
Expand All @@ -105,10 +104,9 @@ contract L2StandardBridge_Test is Bridge_Initializer {
)
);

deal(address(bridgedETH), alice, 100, true);
vm.prank(alice, alice);
(bool success,) = address(l2StandardBridge).call{ value: 100 }(hex"");
assertEq(success, true);
assertEq(address(l2ToL1MessagePasser).balance, 100);
l2StandardBridge.withdraw(address(bridgedETH), 100, 200_000, hex"");
}

/// @dev Tests that `withdraw` reverts if the amount is not equal to the value sent.
Expand All @@ -126,6 +124,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
assertTrue(alice.balance >= 100);
assertEq(Predeploys.L2_TO_L1_MESSAGE_PASSER.balance, 0);

/*
vm.expectEmit(true, true, true, true, address(l2StandardBridge));
emit WithdrawalInitiated({
l1Token: address(0),
Expand All @@ -135,6 +134,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
amount: 100,
data: hex""
});
*/

vm.expectEmit(true, true, true, true, address(l2StandardBridge));
emit ETHBridgeInitiated({ from: alice, to: alice, amount: 100, data: hex"" });
Expand Down
4 changes: 4 additions & 0 deletions packages/contracts-bedrock/test/setup/Setup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { L1StandardBridge } from "src/L1/L1StandardBridge.sol";
import { AddressManager } from "src/legacy/AddressManager.sol";
import { L1ERC721Bridge } from "src/L1/L1ERC721Bridge.sol";
import { AddressAliasHelper } from "src/vendor/AddressAliasHelper.sol";
import { BridgedETH } from "src/celo/BridgedETH.sol";

/// @title Setup
/// @dev This contact is responsible for setting up the contracts in state. It currently
Expand Down Expand Up @@ -60,6 +61,7 @@ contract Setup is Deploy {
LegacyMessagePasser legacyMessagePasser = LegacyMessagePasser(Predeploys.LEGACY_MESSAGE_PASSER);
GovernanceToken governanceToken = GovernanceToken(Predeploys.GOVERNANCE_TOKEN);
LegacyERC20ETH legacyERC20ETH = LegacyERC20ETH(Predeploys.LEGACY_ERC20_ETH);
BridgedETH bridgedETH = BridgedETH(Predeploys.BRIDGED_ETH);

function setUp() public virtual override {
Deploy.setUp();
Expand Down Expand Up @@ -172,6 +174,8 @@ contract Setup is Deploy {
vm.prank(governanceToken.owner());
governanceToken.transferOwnership(finalSystemOwner);

vm.etch(address(bridgedETH), address(new BridgedETH(address(l2StandardBridge))).code);

vm.label(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY, "OptimismMintableERC20Factory");
vm.label(Predeploys.LEGACY_ERC20_ETH, "LegacyERC20ETH");
vm.label(Predeploys.L2_STANDARD_BRIDGE, "L2StandardBridge");
Expand Down

0 comments on commit cd11911

Please sign in to comment.