Commit 9697e37a authored by Maurelian's avatar Maurelian Committed by GitHub

feat: add etchLabelAndAllow (#13651)

* feat: add etchLabelAndAllow

* fix: Buggy artifacts path prefix

* feat: Add overloaded etchLabelAndAllow with path arg

* remove no-op type cast
parent 86cfe6d6
......@@ -86,10 +86,16 @@ contract DeployAuthSystem is Script {
function etchIOContracts() public returns (DeployAuthSystemInput dasi_, DeployAuthSystemOutput daso_) {
(dasi_, daso_) = getIOContracts();
vm.etch(address(dasi_), type(DeployAuthSystemInput).runtimeCode);
vm.etch(address(daso_), type(DeployAuthSystemOutput).runtimeCode);
vm.allowCheatcodes(address(dasi_));
vm.allowCheatcodes(address(daso_));
DeployUtils.etchLabelAndAllowCheatcodes({
_etchTo: address(dasi_),
_cname: "DeployAuthSystemInput",
_artifactPath: "DeployAuthSystem.s.sol:DeployAuthSystemInput"
});
DeployUtils.etchLabelAndAllowCheatcodes({
_etchTo: address(daso_),
_cname: "DeployAuthSystemOutput",
_artifactPath: "DeployAuthSystem.s.sol:DeployAuthSystemOutput"
});
}
function getIOContracts() public view returns (DeployAuthSystemInput dasi_, DeployAuthSystemOutput daso_) {
......
......@@ -843,8 +843,18 @@ contract DeployImplementations is Script {
function etchIOContracts() public returns (DeployImplementationsInput dii_, DeployImplementationsOutput dio_) {
(dii_, dio_) = getIOContracts();
vm.etch(address(dii_), type(DeployImplementationsInput).runtimeCode);
vm.etch(address(dio_), type(DeployImplementationsOutput).runtimeCode);
DeployUtils.etchLabelAndAllowCheatcodes({
_etchTo: address(dii_),
_cname: "DeployImplementationsInput",
_artifactPath: "DeployImplementations.s.sol:DeployImplementationsInput"
});
DeployUtils.etchLabelAndAllowCheatcodes({
_etchTo: address(dio_),
_cname: "DeployImplementationsOutput",
_artifactPath: "DeployImplementations.s.sol:DeployImplementationsOutput"
});
}
function getIOContracts() public view returns (DeployImplementationsInput dii_, DeployImplementationsOutput dio_) {
......
......@@ -436,10 +436,16 @@ contract DeploySuperchain is Script {
// When interacting with the script programmatically (e.g. in a Solidity test), this must be called.
function etchIOContracts() public returns (DeploySuperchainInput dsi_, DeploySuperchainOutput dso_) {
(dsi_, dso_) = getIOContracts();
vm.etch(address(dsi_), type(DeploySuperchainInput).runtimeCode);
vm.etch(address(dso_), type(DeploySuperchainOutput).runtimeCode);
vm.allowCheatcodes(address(dsi_));
vm.allowCheatcodes(address(dso_));
DeployUtils.etchLabelAndAllowCheatcodes({
_etchTo: address(dsi_),
_cname: "DeploySuperchainInput",
_artifactPath: "DeploySuperchain.s.sol:DeploySuperchainInput"
});
DeployUtils.etchLabelAndAllowCheatcodes({
_etchTo: address(dso_),
_cname: "DeploySuperchainOutput",
_artifactPath: "DeploySuperchain.s.sol:DeploySuperchainOutput"
});
}
// This returns the addresses of the IO contracts for this script.
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Testing
import { console } from "forge-std/console.sol";
import { Script } from "forge-std/Script.sol";
// Scripts
import { Artifacts } from "scripts/Artifacts.s.sol";
import { Config } from "scripts/libraries/Config.sol";
import { DeployConfig } from "scripts/deploy/DeployConfig.s.sol";
import { console } from "forge-std/console.sol";
import { Process } from "scripts/libraries/Process.sol";
import { DeployUtils } from "scripts/libraries/DeployUtils.sol";
/// @title Deployer
/// @author tynes
......@@ -20,16 +24,12 @@ abstract contract Deployer is Script {
/// @notice Sets up the artifacts contract.
function setUp() public virtual {
vm.etch(address(artifacts), vm.getDeployedCode("Artifacts.s.sol:Artifacts"));
vm.label(address(cfg), "Artifacts");
vm.allowCheatcodes(address(artifacts));
DeployUtils.etchLabelAndAllowCheatcodes({ _etchTo: address(artifacts), _cname: "Artifacts" });
artifacts.setUp();
console.log("Commit hash: %s", gitCommitHash());
vm.etch(address(cfg), vm.getDeployedCode("DeployConfig.s.sol:DeployConfig"));
vm.label(address(cfg), "DeployConfig");
vm.allowCheatcodes(address(cfg));
DeployUtils.etchLabelAndAllowCheatcodes({ _etchTo: address(cfg), _cname: "DeployConfig" });
cfg.read(Config.deployConfigPath());
}
......
......@@ -364,4 +364,23 @@ library DeployUtils {
require(val == type(uint8).max, "DeployUtils: storage value is not 0xff at the given slot and offset");
}
}
/// @notice Etches a contract, labels it, and allows cheatcodes for it.
/// @param _etchTo Address of the contract to etch.
/// @param _cname The contract name (also used to label the contract).
/// @param _artifactPath The path to the artifact to etch.
function etchLabelAndAllowCheatcodes(address _etchTo, string memory _cname, string memory _artifactPath) internal {
vm.etch(_etchTo, vm.getDeployedCode(_artifactPath));
vm.label(_etchTo, _cname);
vm.allowCheatcodes(_etchTo);
}
/// @notice Etches a contract, labels it, and allows cheatcodes for it.
/// @param _etchTo Address of the contract to etch.
/// @param _cname The contract name (also used to label the contract). MUST be the name of both the file and the
/// contract.
function etchLabelAndAllowCheatcodes(address _etchTo, string memory _cname) internal {
string memory artifactPath = string.concat(_cname, ".s.sol:", _cname);
etchLabelAndAllowCheatcodes(_etchTo, _cname, artifactPath);
}
}
......@@ -12,6 +12,8 @@ import { Fork, LATEST_FORK } from "scripts/libraries/Config.sol";
import { L2Genesis, L1Dependencies } from "scripts/L2Genesis.s.sol";
import { OutputMode, Fork, ForkUtils } from "scripts/libraries/Config.sol";
import { Artifacts } from "scripts/Artifacts.s.sol";
import { DeployUtils } from "scripts/libraries/DeployUtils.sol";
// Libraries
import { Predeploys } from "src/libraries/Predeploys.sol";
import { Preinstalls } from "src/libraries/Preinstalls.sol";
......@@ -134,9 +136,7 @@ contract Setup {
console.log("Setup: L1 setup start!");
// 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));
DeployUtils.etchLabelAndAllowCheatcodes({ _etchTo: address(deploy), _cname: "Deploy" });
_isForkTest = vm.envOr("FORK_TEST", false);
if (_isForkTest) {
......@@ -147,8 +147,7 @@ contract Setup {
);
// Overwrite the Deploy.s.sol contract with the ForkLive.s.sol contract
vm.etch(address(deploy), vm.getDeployedCode("ForkLive.s.sol:ForkLive"));
vm.label(address(deploy), "ForkLive");
DeployUtils.etchLabelAndAllowCheatcodes({ _etchTo: address(deploy), _cname: "ForkLive" });
}
// deploy.setUp() will either:
......
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