Skip to content

Commit

Permalink
contracts-bedrock: loadAllocs support
Browse files Browse the repository at this point in the history
Small tweaks to the L2 contracts tests to make the
new method of setting up the L2 state work. This depends
on the latest build of `ci-builder` and updating the
foundry version in #8144.
  • Loading branch information
tynes committed Nov 20, 2023
1 parent 8809a31 commit 6faf923
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 81 deletions.
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/test/FeeVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract FeeVault_Test is Bridge_Initializer {
function test_constructor_l1FeeVault_succeeds() external {
assertEq(l1FeeVault.RECIPIENT(), cfg.l1FeeVaultRecipient());
assertEq(l1FeeVault.MIN_WITHDRAWAL_AMOUNT(), cfg.l1FeeVaultMinimumWithdrawalAmount());
assertEq(uint8(l1FeeVault.WITHDRAWAL_NETWORK()), uint8(FeeVault.WithdrawalNetwork.L2));
assertEq(uint8(l1FeeVault.WITHDRAWAL_NETWORK()), uint8(FeeVault.WithdrawalNetwork.L1));
}

/// @dev Tests that the constructor sets the correct values.
Expand Down
32 changes: 18 additions & 14 deletions packages/contracts-bedrock/test/SequencerFeeVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity 0.8.15;
import { CommonTest } from "test/setup/CommonTest.sol";
import { Reverter } from "test/mocks/Callers.sol";
import { StandardBridge } from "src/universal/StandardBridge.sol";
import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol";

// Libraries
import { Predeploys } from "src/libraries/Predeploys.sol";
Expand All @@ -17,8 +18,8 @@ import { SequencerFeeVault } from "src/L2/SequencerFeeVault.sol";

contract SequencerFeeVault_Test is CommonTest {
address recipient;
/// @dev Sets up the test suite.

/// @dev Sets up the test suite.
function setUp() public override {
super.setUp();
recipient = cfg.sequencerFeeVaultRecipient();
Expand All @@ -38,6 +39,7 @@ contract SequencerFeeVault_Test is CommonTest {
function test_receive_succeeds() external {
uint256 balance = address(sequencerFeeVault).balance;

vm.deal(alice, 100);
vm.prank(alice);
(bool success,) = address(sequencerFeeVault).call{ value: 100 }(hex"");

Expand All @@ -56,23 +58,15 @@ contract SequencerFeeVault_Test is CommonTest {

/// @dev Tests that `withdraw` successfully initiates a withdrawal to L1.
function test_withdraw_toL1_succeeds() external {
// Set the code with the withdrawal network set to L1
vm.etch(
Predeploys.SEQUENCER_FEE_WALLET,
address(
new SequencerFeeVault(cfg.sequencerFeeVaultRecipient(), cfg.sequencerFeeVaultMinimumWithdrawalAmount(), FeeVault.WithdrawalNetwork.L1)
).code
);

uint256 amount = sequencerFeeVault.MIN_WITHDRAWAL_AMOUNT() + 1;
vm.deal(address(sequencerFeeVault), amount);

// No ether has been withdrawn yet
assertEq(sequencerFeeVault.totalProcessed(), 0);

vm.expectEmit(true, true, true, true, address(Predeploys.SEQUENCER_FEE_WALLET));
vm.expectEmit(address(Predeploys.SEQUENCER_FEE_WALLET));
emit Withdrawal(address(sequencerFeeVault).balance, sequencerFeeVault.RECIPIENT(), address(this));
vm.expectEmit(true, true, true, true, address(Predeploys.SEQUENCER_FEE_WALLET));
vm.expectEmit(address(Predeploys.SEQUENCER_FEE_WALLET));
emit Withdrawal(
address(sequencerFeeVault).balance,
sequencerFeeVault.RECIPIENT(),
Expand All @@ -99,11 +93,21 @@ contract SequencerFeeVault_Test is CommonTest {
}

contract SequencerFeeVault_L2Withdrawal_Test is CommonTest {
/// @dev a cache for the config fee recipient
address recipient;
/// @dev Sets up the test suite.

/// @dev Sets up the test suite.
function setUp() public override {
super.setUp();

// Alter the deployment to use WithdrawalNetwork.L2
vm.etch(
EIP1967Helper.getImplementation(Predeploys.SEQUENCER_FEE_WALLET),
address(
new SequencerFeeVault(cfg.sequencerFeeVaultRecipient(), cfg.sequencerFeeVaultMinimumWithdrawalAmount(), FeeVault.WithdrawalNetwork.L2)
).code
);

recipient = cfg.sequencerFeeVaultRecipient();
}

Expand All @@ -115,9 +119,9 @@ contract SequencerFeeVault_L2Withdrawal_Test is CommonTest {
// No ether has been withdrawn yet
assertEq(sequencerFeeVault.totalProcessed(), 0);

vm.expectEmit(true, true, true, true, address(Predeploys.SEQUENCER_FEE_WALLET));
vm.expectEmit(address(Predeploys.SEQUENCER_FEE_WALLET));
emit Withdrawal(address(sequencerFeeVault).balance, sequencerFeeVault.RECIPIENT(), address(this));
vm.expectEmit(true, true, true, true, address(Predeploys.SEQUENCER_FEE_WALLET));
vm.expectEmit(address(Predeploys.SEQUENCER_FEE_WALLET));
emit Withdrawal(
address(sequencerFeeVault).balance,
sequencerFeeVault.RECIPIENT(),
Expand Down
15 changes: 7 additions & 8 deletions packages/contracts-bedrock/test/setup/CommonTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ import { FFIInterface } from "test/setup/FFIInterface.sol";
/// @title CommonTest
/// @dev An extenstion to `Test` that sets up the optimism smart contracts.
contract CommonTest is Setup, Test, Events {
address alice = address(128);
address bob = address(256);
address alice;
address bob;

bytes32 constant nonZeroHash = keccak256(abi.encode("NON_ZERO"));

FFIInterface ffi;

function setUp() public virtual override {
vm.deal(alice, type(uint64).max);
vm.deal(bob, type(uint64).max);

vm.label(alice, "alice");
vm.label(bob, "bob");

Setup.setUp();
ffi = new FFIInterface();

Expand All @@ -33,6 +27,11 @@ contract CommonTest is Setup, Test, Events {
vm.warp(cfg.l2OutputOracleStartingTimestamp() + 1);
vm.roll(cfg.l2OutputOracleStartingBlockNumber() + 1);

alice = makeAddr("alice");
bob = makeAddr("bob");
vm.deal(alice, 10000 ether);
vm.deal(bob, 10000 ether);

// Deploy L1
Setup.L1();
// Deploy L2
Expand Down
62 changes: 4 additions & 58 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 { SafeCall } from "src/libraries/SafeCall.sol";

/// @title Setup
/// @dev This contact is responsible for setting up the contracts in state. It currently
Expand Down Expand Up @@ -108,64 +109,9 @@ contract Setup is Deploy {

/// @dev Sets up the L2 contracts. Depends on `L1()` being called first.
function L2(DeployConfig cfg) public {
// Set up L2. There are currently no proxies set in the L2 initialization.
vm.etch(
address(l2CrossDomainMessenger), address(new L2CrossDomainMessenger(address(l1CrossDomainMessenger))).code
);
l2CrossDomainMessenger.initialize();

vm.etch(address(l2ToL1MessagePasser), address(new L2ToL1MessagePasser()).code);

vm.etch(
address(l2StandardBridge), address(new L2StandardBridge(StandardBridge(payable(l1StandardBridge)))).code
);
l2StandardBridge.initialize();

vm.etch(address(l2OptimismMintableERC20Factory), address(new OptimismMintableERC20Factory()).code);
l2OptimismMintableERC20Factory.initialize(address(l2StandardBridge));

vm.etch(address(legacyERC20ETH), address(new LegacyERC20ETH()).code);

vm.etch(address(l2ERC721Bridge), address(new L2ERC721Bridge(address(l1ERC721Bridge))).code);
l2ERC721Bridge.initialize();

vm.etch(
address(sequencerFeeVault),
address(
new SequencerFeeVault(cfg.sequencerFeeVaultRecipient(), cfg.sequencerFeeVaultMinimumWithdrawalAmount(), FeeVault.WithdrawalNetwork.L2)
).code
);
vm.etch(
address(baseFeeVault),
address(
new BaseFeeVault(cfg.baseFeeVaultRecipient(), cfg.baseFeeVaultMinimumWithdrawalAmount(), FeeVault.WithdrawalNetwork.L1)
).code
);
vm.etch(
address(l1FeeVault),
address(
new L1FeeVault(cfg.l1FeeVaultRecipient(), cfg.l1FeeVaultMinimumWithdrawalAmount(), FeeVault.WithdrawalNetwork.L2)
).code
);

vm.etch(address(l1Block), address(new L1Block()).code);

vm.etch(address(gasPriceOracle), address(new GasPriceOracle()).code);

vm.etch(address(legacyMessagePasser), address(new LegacyMessagePasser()).code);

vm.etch(address(governanceToken), address(new GovernanceToken()).code);
// Set the ERC20 token name and symbol
vm.store(
address(governanceToken),
bytes32(uint256(3)),
bytes32(0x4f7074696d69736d000000000000000000000000000000000000000000000010)
);
vm.store(
address(governanceToken),
bytes32(uint256(4)),
bytes32(0x4f50000000000000000000000000000000000000000000000000000000000004)
);
string memory projectRoot = vm.projectRoot();
string memory allocsPath = string.concat(projectRoot, "/.testdata/genesis.json");
vm.loadAllocs(allocsPath);

// Set the governance token's owner to be the final system owner
address finalSystemOwner = cfg.finalSystemOwner();
Expand Down

0 comments on commit 6faf923

Please sign in to comment.