Skip to content

Commit

Permalink
feat: Readability improvements to Setup.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
maurelian committed Dec 20, 2024
1 parent 92513ea commit 9d1e5d3
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions packages/contracts-bedrock/test/setup/Setup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,34 +131,39 @@ contract Setup {
/// This is a hack as we are pushing solidity to the edge.
function setUp() public virtual {
console.log("Setup: L1 setup start!");
if (vm.envOr("FORK_TEST", false)) {
string memory forkUrl = vm.envString("FORK_RPC_URL");
_isForkTest = true;
vm.createSelectFork(forkUrl, vm.envUint("FORK_BLOCK_NUMBER"));

// Optimistically etch, label and allow cheatcodes for the Deploy.s.sol contract
vm.etch(address(deploy), vm.getDeployedCode("Deploy.s.sol:Deploy"));
vm.label(address(deploy), "Deploy");
vm.allowCheatcodes(address(deploy));

_isForkTest = vm.envOr("FORK_TEST", false);
if (_isForkTest) {
vm.createSelectFork(vm.envString("FORK_RPC_URL"), vm.envUint("FORK_BLOCK_NUMBER"));
require(
block.chainid == Chains.Sepolia || block.chainid == Chains.Mainnet,
"Setup: ETH_RPC_URL must be set to a production (Sepolia or Mainnet) RPC URL"
);

// Overwrite the Deploy.s.sol contract with the ForkLive.s.sol contract
vm.etch(address(deploy), vm.getDeployedCode("ForkLive.s.sol:ForkLive"));
} else {
vm.etch(address(deploy), vm.getDeployedCode("Deploy.s.sol:Deploy"));
vm.label(address(deploy), "ForkLive");
}

vm.allowCheatcodes(address(deploy));
deploy.setUp();

console.log("Setup: L1 setup done!");

// Return early if this is a fork test
if (_isForkTest) {
console.log("Setup: fork test detected, skipping L2 setup");
} else {
console.log("Setup: L2 setup start!");
vm.etch(address(l2Genesis), vm.getDeployedCode("L2Genesis.s.sol:L2Genesis"));
vm.allowCheatcodes(address(l2Genesis));
l2Genesis.setUp();
console.log("Setup: L2 setup done!");
console.log("Setup: fork test detected, skipping L2 genesis generation");
return;
}

console.log("Setup: L2 setup start!");
vm.etch(address(l2Genesis), vm.getDeployedCode("L2Genesis.s.sol:L2Genesis"));
vm.allowCheatcodes(address(l2Genesis));
l2Genesis.setUp();
console.log("Setup: L2 setup done!");
}

/// @dev Skips tests when running against a forked production network.
Expand Down

0 comments on commit 9d1e5d3

Please sign in to comment.