Commit 8c86a7d6 authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: loadAllocs support

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 https://github.com/ethereum-optimism/optimism/pull/8144.
parent 2119f381
...@@ -13,7 +13,7 @@ contract FeeVault_Test is Bridge_Initializer { ...@@ -13,7 +13,7 @@ contract FeeVault_Test is Bridge_Initializer {
function test_constructor_l1FeeVault_succeeds() external { function test_constructor_l1FeeVault_succeeds() external {
assertEq(l1FeeVault.RECIPIENT(), cfg.l1FeeVaultRecipient()); assertEq(l1FeeVault.RECIPIENT(), cfg.l1FeeVaultRecipient());
assertEq(l1FeeVault.MIN_WITHDRAWAL_AMOUNT(), cfg.l1FeeVaultMinimumWithdrawalAmount()); 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. /// @dev Tests that the constructor sets the correct values.
......
...@@ -5,6 +5,7 @@ pragma solidity 0.8.15; ...@@ -5,6 +5,7 @@ pragma solidity 0.8.15;
import { CommonTest } from "test/setup/CommonTest.sol"; import { CommonTest } from "test/setup/CommonTest.sol";
import { Reverter } from "test/mocks/Callers.sol"; import { Reverter } from "test/mocks/Callers.sol";
import { StandardBridge } from "src/universal/StandardBridge.sol"; import { StandardBridge } from "src/universal/StandardBridge.sol";
import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol";
// Libraries // Libraries
import { Predeploys } from "src/libraries/Predeploys.sol"; import { Predeploys } from "src/libraries/Predeploys.sol";
...@@ -17,8 +18,8 @@ import { SequencerFeeVault } from "src/L2/SequencerFeeVault.sol"; ...@@ -17,8 +18,8 @@ import { SequencerFeeVault } from "src/L2/SequencerFeeVault.sol";
contract SequencerFeeVault_Test is CommonTest { contract SequencerFeeVault_Test is CommonTest {
address recipient; address recipient;
/// @dev Sets up the test suite.
/// @dev Sets up the test suite.
function setUp() public override { function setUp() public override {
super.setUp(); super.setUp();
recipient = cfg.sequencerFeeVaultRecipient(); recipient = cfg.sequencerFeeVaultRecipient();
...@@ -38,6 +39,7 @@ contract SequencerFeeVault_Test is CommonTest { ...@@ -38,6 +39,7 @@ contract SequencerFeeVault_Test is CommonTest {
function test_receive_succeeds() external { function test_receive_succeeds() external {
uint256 balance = address(sequencerFeeVault).balance; uint256 balance = address(sequencerFeeVault).balance;
vm.deal(alice, 100);
vm.prank(alice); vm.prank(alice);
(bool success,) = address(sequencerFeeVault).call{ value: 100 }(hex""); (bool success,) = address(sequencerFeeVault).call{ value: 100 }(hex"");
...@@ -56,14 +58,6 @@ contract SequencerFeeVault_Test is CommonTest { ...@@ -56,14 +58,6 @@ contract SequencerFeeVault_Test is CommonTest {
/// @dev Tests that `withdraw` successfully initiates a withdrawal to L1. /// @dev Tests that `withdraw` successfully initiates a withdrawal to L1.
function test_withdraw_toL1_succeeds() external { 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; uint256 amount = sequencerFeeVault.MIN_WITHDRAWAL_AMOUNT() + 1;
vm.deal(address(sequencerFeeVault), amount); vm.deal(address(sequencerFeeVault), amount);
...@@ -99,11 +93,21 @@ contract SequencerFeeVault_Test is CommonTest { ...@@ -99,11 +93,21 @@ contract SequencerFeeVault_Test is CommonTest {
} }
contract SequencerFeeVault_L2Withdrawal_Test is CommonTest { contract SequencerFeeVault_L2Withdrawal_Test is CommonTest {
/// @dev a cache for the config fee recipient
address recipient; address recipient;
/// @dev Sets up the test suite.
/// @dev Sets up the test suite.
function setUp() public override { function setUp() public override {
super.setUp(); 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(); recipient = cfg.sequencerFeeVaultRecipient();
} }
......
...@@ -9,20 +9,14 @@ import { FFIInterface } from "test/setup/FFIInterface.sol"; ...@@ -9,20 +9,14 @@ import { FFIInterface } from "test/setup/FFIInterface.sol";
/// @title CommonTest /// @title CommonTest
/// @dev An extenstion to `Test` that sets up the optimism smart contracts. /// @dev An extenstion to `Test` that sets up the optimism smart contracts.
contract CommonTest is Setup, Test, Events { contract CommonTest is Setup, Test, Events {
address alice = address(128); address alice;
address bob = address(256); address bob;
bytes32 constant nonZeroHash = keccak256(abi.encode("NON_ZERO")); bytes32 constant nonZeroHash = keccak256(abi.encode("NON_ZERO"));
FFIInterface ffi; FFIInterface ffi;
function setUp() public virtual override { 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(); Setup.setUp();
ffi = new FFIInterface(); ffi = new FFIInterface();
...@@ -33,6 +27,11 @@ contract CommonTest is Setup, Test, Events { ...@@ -33,6 +27,11 @@ contract CommonTest is Setup, Test, Events {
vm.warp(cfg.l2OutputOracleStartingTimestamp() + 1); vm.warp(cfg.l2OutputOracleStartingTimestamp() + 1);
vm.roll(cfg.l2OutputOracleStartingBlockNumber() + 1); vm.roll(cfg.l2OutputOracleStartingBlockNumber() + 1);
alice = makeAddr("alice");
bob = makeAddr("bob");
vm.deal(alice, 10000 ether);
vm.deal(bob, 10000 ether);
// Deploy L1 // Deploy L1
Setup.L1(); Setup.L1();
// Deploy L2 // Deploy L2
......
...@@ -28,6 +28,7 @@ import { L1StandardBridge } from "src/L1/L1StandardBridge.sol"; ...@@ -28,6 +28,7 @@ import { L1StandardBridge } from "src/L1/L1StandardBridge.sol";
import { AddressManager } from "src/legacy/AddressManager.sol"; import { AddressManager } from "src/legacy/AddressManager.sol";
import { L1ERC721Bridge } from "src/L1/L1ERC721Bridge.sol"; import { L1ERC721Bridge } from "src/L1/L1ERC721Bridge.sol";
import { AddressAliasHelper } from "src/vendor/AddressAliasHelper.sol"; import { AddressAliasHelper } from "src/vendor/AddressAliasHelper.sol";
import { SafeCall } from "src/libraries/SafeCall.sol";
/// @title Setup /// @title Setup
/// @dev This contact is responsible for setting up the contracts in state. It currently /// @dev This contact is responsible for setting up the contracts in state. It currently
...@@ -108,65 +109,8 @@ contract Setup is Deploy { ...@@ -108,65 +109,8 @@ contract Setup is Deploy {
/// @dev Sets up the L2 contracts. Depends on `L1()` being called first. /// @dev Sets up the L2 contracts. Depends on `L1()` being called first.
function L2(DeployConfig cfg) public { function L2(DeployConfig cfg) public {
// Set up L2. There are currently no proxies set in the L2 initialization. string memory allocsPath = string.concat(vm.projectRoot(), "/.testdata/genesis.json");
vm.etch( vm.loadAllocs(allocsPath);
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(payable(l1StandardBridge))).code);
vm.etch(
address(l2OptimismMintableERC20Factory),
address(new OptimismMintableERC20Factory(address(l2StandardBridge))).code
);
vm.etch(address(legacyERC20ETH), address(new LegacyERC20ETH()).code);
vm.etch(
address(l2ERC721Bridge),
address(new L2ERC721Bridge(address(l2CrossDomainMessenger), address(l1ERC721Bridge))).code
);
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)
);
// Set the governance token's owner to be the final system owner // Set the governance token's owner to be the final system owner
address finalSystemOwner = cfg.finalSystemOwner(); address finalSystemOwner = cfg.finalSystemOwner();
......
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