Skip to content

Commit

Permalink
fix: etching in fuzzing test.
Browse files Browse the repository at this point in the history
  • Loading branch information
blmalone committed Sep 12, 2024
1 parent 70c7857 commit 0176df9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
21 changes: 11 additions & 10 deletions packages/contracts-bedrock/scripts/DeployImplementations.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.15;

import { Script } from "forge-std/Script.sol";
import "forge-std/console.sol";

import { ProxyAdmin } from "src/universal/ProxyAdmin.sol";
import { Proxy } from "src/universal/Proxy.sol";
Expand Down Expand Up @@ -185,7 +186,7 @@ contract DeployImplementationsOutput is Script {
DeployUtils.assertValidContractAddresses(addrs);
}

function opsm() public view returns (OPStackManager) {
function opsm() public returns (OPStackManager) {
DeployUtils.assertValidContractAddress(address(outputs.opsm));
// We prank as the zero address due to the Proxy's `proxyCallIfNotAdmin` modifier.
vm.prank(address(0));
Expand Down Expand Up @@ -317,22 +318,22 @@ contract DeployImplementations is Script {
{
SuperchainConfig superchainConfigProxy = _dii.superchainConfigProxy();
ProtocolVersions protocolVersionsProxy = _dii.protocolVersionsProxy();
ProxyAdmin proxyAdmin = _dii.superchainProxyAdmin();
address proxyAdminOwner = proxyAdmin.owner();

// In this case, DeployImplementations script needs to deploy a proxy contract and the opsm contract.
// To deploy a proxy contract, you need to know the proxy admin.
// However, this proxy admin is not deployed until the OPStackManager.
// Not using blueprint because we don't have access to l2ChainId.

// Setting proxy admin to msg.sender because ProxyAdmin is not deployed yet.
vm.broadcast(msg.sender);
Proxy proxy = new Proxy(address(_dii.superchainProxyAdmin()));
vm.startBroadcast(proxyAdminOwner);
Proxy proxy = new Proxy(address(proxyAdmin));
OPStackManager opsm = new OPStackManager({
_superchainConfig: superchainConfigProxy,
_protocolVersions: protocolVersionsProxy,
_blueprints: blueprints
});
proxy.upgradeTo(address(opsm));
vm.stopBroadcast();

// We broadcast as the proxyAdminOwner address due to the ProxyAdmin's `onlyOwner` modifier.
vm.broadcast(proxyAdminOwner);
proxyAdmin.upgrade(payable(proxy), address(opsm));

opsmProxy_ = OPStackManager(address(proxy));
}

Expand Down
9 changes: 1 addition & 8 deletions packages/contracts-bedrock/scripts/libraries/DeployUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@ library DeployUtils {
require(_who.code.length > 0, string.concat("DeployUtils: no code at ", LibString.toHexStringChecksummed(_who)));
}

function assertEIP1967ImplementationSet(address _proxy) internal {
function assertEIP1967Implementation(address _proxy) internal {
address implementation = Proxy(payable(_proxy)).implementation();
assertValidContractAddress(implementation);
}

function assertEIP1967Implementation(address _proxy) internal view {
(bool success, bytes memory result) = _proxy.staticcall(abi.encodeWithSignature("implementation()"));
require(success, "DeployUtils: EIP1967 implementation check failed");
address implementation = abi.decode(result, (address));
assertValidContractAddress(implementation);
}

function assertValidContractAddresses(address[] memory _addrs) internal view {
// Assert that all addresses are non-zero and have code.
// We use LibString to avoid the need for adding cheatcodes to this contract.
Expand Down
6 changes: 6 additions & 0 deletions packages/contracts-bedrock/test/DeployImplementations.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ contract DeployImplementations_Test is Test {
// This is a requirement in the PreimageOracle contract.
_input.challengePeriodSeconds = bound(_input.challengePeriodSeconds, 0, type(uint64).max);

// Must configure the ProxyAdmin contract.
ProxyAdmin proxyAdmin = new ProxyAdmin(msg.sender);
_input.superchainProxyAdmin = proxyAdmin;
vm.etch(address(_input.superchainProxyAdmin), address(proxyAdmin).code);

DeployImplementationsOutput.Output memory output = deployImplementations.run(_input);

// Assert that individual input fields were properly set based on the input struct.
Expand All @@ -285,6 +290,7 @@ contract DeployImplementations_Test is Test {
address(output.optimismMintableERC20FactoryImpl), address(dio.optimismMintableERC20FactoryImpl()), "1400"
);
assertEq(address(output.disputeGameFactoryImpl), address(dio.disputeGameFactoryImpl()), "1450");
assertEq(address(output.opsm), address(dio.opsm()), "1475");

// Assert that the full input and output structs were properly set.
assertEq(keccak256(abi.encode(_input)), keccak256(abi.encode(DeployImplementationsInput(dii).input())), "1500");
Expand Down

0 comments on commit 0176df9

Please sign in to comment.