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