Skip to content

Commit 1dbef1e

Browse files
blmaloneQuentinI
authored andcommitted
Load Alloc For Superchain ops integration testing (ethereum-optimism#14021)
* fix: test * fix: nit checking to see if adding a new env causes the issue. * fix: unused var * fix: adding branhing logic * fix: copying other pr * fix: clarifications around comments.
1 parent 408a5f2 commit 1dbef1e

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

packages/contracts-bedrock/test/setup/ForkLive.s.sol

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,40 @@ contract ForkLive is Deployer {
4949
return vm.envOr("FORK_OP_CHAIN", string("op"));
5050
}
5151

52-
/// @notice Forks, upgrades and tests a production network.
53-
/// @dev This function sets up the system to test by:
54-
/// 1. reading the superchain-registry to get the contract addresses we wish to test from that network.
55-
/// 2. deploying the updated OPCM and implementations of the contracts.
56-
/// 3. upgrading the system using the OPCM.upgrade() function.
52+
/// @dev This function sets up the system to test it as follows:
53+
/// 1. Check if the SUPERCHAIN_OPS_ALLOCS_PATH environment variable was set from superchain ops.
54+
/// 2. If set, load the state from the given path.
55+
/// 3. Read the superchain-registry to get the contract addresses we wish to test from that network.
56+
/// 4. If the environment variable wasn't set, deploy the updated OPCM and implementations of the contracts.
57+
/// 5. Upgrade the system using the OPCM.upgrade() function if useUpgradedFork is true.
5758
function run() public {
58-
// Read the superchain registry and save the addresses to the Artifacts contract.
59-
_readSuperchainRegistry();
60-
61-
// Now deploy the updated OPCM and implementations of the contracts
62-
_deployNewImplementations();
59+
string memory superchainOpsAllocsPath = vm.envOr("SUPERCHAIN_OPS_ALLOCS_PATH", string(""));
60+
61+
bool useOpsRepo = bytes(superchainOpsAllocsPath).length > 0;
62+
if (useOpsRepo) {
63+
console.log("ForkLive: loading state from %s", superchainOpsAllocsPath);
64+
// Set the resultant state from the superchain ops repo upgrades.
65+
// The allocs are generated when simulating an upgrade task that runs vm.dumpState.
66+
// These allocs represent the state of the EVM after the upgrade has been simulated.
67+
vm.loadAllocs(superchainOpsAllocsPath);
68+
// Next, fetch the addresses from the superchain registry. This function uses a local EVM
69+
// to retrieve implementation addresses by reading from proxy addresses provided by the registry.
70+
// Setting the allocs first ensures the correct implementation addresses are retrieved.
71+
_readSuperchainRegistry();
72+
} else {
73+
// Read the superchain registry and save the addresses to the Artifacts contract.
74+
_readSuperchainRegistry();
75+
// Now deploy the updated OPCM and implementations of the contracts
76+
_deployNewImplementations();
77+
}
6378

6479
// Now upgrade the contracts (if the config is set to do so)
6580
if (cfg.useUpgradedFork()) {
81+
require(!useOpsRepo, "ForkLive: cannot upgrade and use ops repo");
6682
console.log("ForkLive: upgrading");
6783
_upgrade();
84+
} else if (useOpsRepo) {
85+
console.log("ForkLive: using ops repo to upgrade");
6886
}
6987
}
7088

0 commit comments

Comments
 (0)