Skip to content

Commit

Permalink
Update forge deployment scripts in prep for launch (#1183)
Browse files Browse the repository at this point in the history
* Improve forge deployment scripts in prep for launch

* Update smoketests
  • Loading branch information
vgeddes authored Apr 17, 2024
1 parent 0b0c70d commit af101b6
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 97 deletions.
4 changes: 1 addition & 3 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ script = 'scripts'
fs_permissions = [{ access = "read-write", path = "test/data"}, { access = "read", path = "./"}]

ignored_error_codes = [
# DeployScript.sol is never deployed
# DeployLocal.sol is never deployed
5574
]

# no_match_test = "testRegenerateBitField"
21 changes: 21 additions & 0 deletions contracts/scripts/Deploy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
pragma solidity 0.8.23;

import {Script} from "forge-std/Script.sol";
import {GatewayProxy} from "../src/GatewayProxy.sol";
import {Shell} from "../src/Shell.sol";

contract Stage1 is Script {
function setUp() public {}

function run() public {
vm.startBroadcast();

address operator = vm.envAddress("OPERATOR_ADDRESS");
Shell shell = new Shell(operator);
new GatewayProxy(address(shell), bytes(""));

vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {BeefyClient} from "../src/BeefyClient.sol";
import {IGateway} from "../src/interfaces/IGateway.sol";
import {GatewayProxy} from "../src/GatewayProxy.sol";
import {Gateway} from "../src/Gateway.sol";
import {GatewayV2} from "../test/mocks/GatewayMock.sol";
import {MockGatewayV2} from "../test/mocks/MockGatewayV2.sol";
import {Agent} from "../src/Agent.sol";
import {AgentExecutor} from "../src/AgentExecutor.sol";
import {ChannelID, ParaID, OperatingMode} from "../src/Types.sol";
import {SafeNativeTransfer} from "../src/utils/SafeTransfer.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {UD60x18, ud60x18} from "prb/math/src/UD60x18.sol";

contract DeployScript is Script {
contract DeployLocal is Script {
using SafeNativeTransfer for address payable;
using stdJson for string;

Expand Down Expand Up @@ -105,8 +105,8 @@ contract DeployScript is Script {
payable(bridgeHubAgent).safeNativeTransfer(initialDeposit);
payable(assetHubAgent).safeNativeTransfer(initialDeposit);

// Deploy GatewayV2 for testing
new GatewayV2();
// Deploy MockGatewayV2 for testing
new MockGatewayV2();

vm.stopBroadcast();
}
Expand Down
17 changes: 17 additions & 0 deletions contracts/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -eux

forge script "scripts/Deploy.sol:${1}" \
--chain-id 1 \
--rpc-url "${MAINNET_RPC_URL}" \
--ledger \
--mnemonic-derivation-path "${MNEMONIC_DERIVATION_PATH}" \
--broadcast \
--verify \
--verifier etherscan \
--verifier-url "${ETHERSCAN_API_KEY}"
--optimize \
--via-ir \
--optimizer-runs 100000 \
-vvv
4 changes: 2 additions & 2 deletions contracts/src/Shell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ contract Shell is IShell, IUpgradable, IInitializable {
Upgrade.upgrade(impl, implCodeHash, initializerParams);
}

function initialize(bytes memory params) external {
function initialize(bytes memory) external view {
// Prevent initialization of storage in implementation contract
if (ERC1967.load() == address(0)) {
revert Unauthorized();
}
}

function operator() external returns (address) {
function operator() external view returns (address) {
return OPERATOR;
}
}
78 changes: 39 additions & 39 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {IGateway} from "../src/interfaces/IGateway.sol";
import {IInitializable} from "../src/interfaces/IInitializable.sol";
import {IUpgradable} from "../src/interfaces/IUpgradable.sol";
import {Gateway} from "../src/Gateway.sol";
import {GatewayMock, GatewayV2} from "./mocks/GatewayMock.sol";

import {MockGateway} from "./mocks/MockGateway.sol";
import {MockGatewayV2} from "./mocks/MockGatewayV2.sol";
import {GatewayProxy} from "../src/GatewayProxy.sol";

import {AgentExecutor} from "../src/AgentExecutor.sol";
Expand Down Expand Up @@ -66,7 +66,7 @@ contract GatewayTest is Test {
bytes32[] public proof = [bytes32(0x2f9ee6cfdf244060dc28aa46347c5219e303fc95062dd672b4e406ca5c29764b)];
bytes public parachainHeaderProof = bytes("validProof");

GatewayMock public gatewayLogic;
MockGateway public gatewayLogic;
GatewayProxy public gateway;

WETH9 public token;
Expand Down Expand Up @@ -98,7 +98,7 @@ contract GatewayTest is Test {

function setUp() public {
AgentExecutor executor = new AgentExecutor();
gatewayLogic = new GatewayMock(
gatewayLogic = new MockGateway(
address(0),
address(executor),
bridgeHubParaID,
Expand All @@ -118,10 +118,10 @@ contract GatewayTest is Test {
multiplier: multiplier
});
gateway = new GatewayProxy(address(gatewayLogic), abi.encode(config));
GatewayMock(address(gateway)).setCommitmentsAreVerified(true);
MockGateway(address(gateway)).setCommitmentsAreVerified(true);

SetOperatingModeParams memory params = SetOperatingModeParams({mode: OperatingMode.Normal});
GatewayMock(address(gateway)).setOperatingModePublic(abi.encode(params));
MockGateway(address(gateway)).setOperatingModePublic(abi.encode(params));

bridgeHubAgent = IGateway(address(gateway)).agentOf(bridgeHubAgentID);
assetHubAgent = IGateway(address(gateway)).agentOf(assetHubAgentID);
Expand Down Expand Up @@ -236,7 +236,7 @@ contract GatewayTest is Test {

(Command command, bytes memory params) = makeCreateAgentCommand();

GatewayMock(address(gateway)).setCommitmentsAreVerified(false);
MockGateway(address(gateway)).setCommitmentsAreVerified(false);
vm.expectRevert(Gateway.InvalidProof.selector);

hoax(relayer, 1 ether);
Expand Down Expand Up @@ -356,7 +356,7 @@ contract GatewayTest is Test {
});

bytes memory encodedParams = abi.encode(params);
GatewayMock(address(gateway)).agentExecutePublic(encodedParams);
MockGateway(address(gateway)).agentExecutePublic(encodedParams);
}

function testAgentExecutionBadOrigin() public {
Expand All @@ -366,14 +366,14 @@ contract GatewayTest is Test {
});

vm.expectRevert(Gateway.AgentDoesNotExist.selector);
GatewayMock(address(gateway)).agentExecutePublic(abi.encode(params));
MockGateway(address(gateway)).agentExecutePublic(abi.encode(params));
}

function testAgentExecutionBadPayload() public {
AgentExecuteParams memory params = AgentExecuteParams({agentID: assetHubAgentID, payload: ""});

vm.expectRevert(Gateway.InvalidAgentExecutionPayload.selector);
GatewayMock(address(gateway)).agentExecutePublic(abi.encode(params));
MockGateway(address(gateway)).agentExecutePublic(abi.encode(params));
}

function testCreateAgent() public {
Expand All @@ -383,31 +383,31 @@ contract GatewayTest is Test {
vm.expectEmit(false, false, false, false, address(gateway));
emit IGateway.AgentCreated(agentID, address(0));

GatewayMock(address(gateway)).createAgentPublic(abi.encode(params));
MockGateway(address(gateway)).createAgentPublic(abi.encode(params));
}

function testCreateAgentAlreadyCreated() public {
bytes32 agentID = keccak256("123");
CreateAgentParams memory params = CreateAgentParams({agentID: agentID});

GatewayMock(address(gateway)).createAgentPublic(abi.encode(params));
MockGateway(address(gateway)).createAgentPublic(abi.encode(params));

vm.expectRevert(Gateway.AgentAlreadyCreated.selector);
GatewayMock(address(gateway)).createAgentPublic(abi.encode(params));
MockGateway(address(gateway)).createAgentPublic(abi.encode(params));
}

function testCreateChannel() public {
ParaID paraID = ParaID.wrap(3042);
bytes32 agentID = keccak256("3042");

GatewayMock(address(gateway)).createAgentPublic(abi.encode(CreateAgentParams({agentID: agentID})));
MockGateway(address(gateway)).createAgentPublic(abi.encode(CreateAgentParams({agentID: agentID})));

CreateChannelParams memory params =
CreateChannelParams({channelID: paraID.into(), agentID: agentID, mode: OperatingMode.Normal});

vm.expectEmit(true, false, false, true);
emit IGateway.ChannelCreated(paraID.into());
GatewayMock(address(gateway)).createChannelPublic(abi.encode(params));
MockGateway(address(gateway)).createChannelPublic(abi.encode(params));
}

function testCreateChannelFailsAgentDoesNotExist() public {
Expand All @@ -418,22 +418,22 @@ contract GatewayTest is Test {
CreateChannelParams({channelID: paraID.into(), mode: OperatingMode.Normal, agentID: agentID});

vm.expectRevert(Gateway.AgentDoesNotExist.selector);
GatewayMock(address(gateway)).createChannelPublic(abi.encode(params));
MockGateway(address(gateway)).createChannelPublic(abi.encode(params));
}

function testCreateChannelFailsChannelAlreadyExists() public {
ParaID paraID = ParaID.wrap(3042);
bytes32 agentID = keccak256("3042");

GatewayMock(address(gateway)).createAgentPublic(abi.encode(CreateAgentParams({agentID: agentID})));
MockGateway(address(gateway)).createAgentPublic(abi.encode(CreateAgentParams({agentID: agentID})));

CreateChannelParams memory params =
CreateChannelParams({channelID: paraID.into(), agentID: agentID, mode: OperatingMode.Normal});

GatewayMock(address(gateway)).createChannelPublic(abi.encode(params));
MockGateway(address(gateway)).createChannelPublic(abi.encode(params));

vm.expectRevert(Gateway.ChannelAlreadyCreated.selector);
GatewayMock(address(gateway)).createChannelPublic(abi.encode(params));
MockGateway(address(gateway)).createChannelPublic(abi.encode(params));
}

function testUpdateChannel() public {
Expand All @@ -447,7 +447,7 @@ contract GatewayTest is Test {

vm.expectEmit(true, false, false, true);
emit IGateway.ChannelUpdated(assetHubParaID.into());
GatewayMock(address(gateway)).updateChannelPublic(params);
MockGateway(address(gateway)).updateChannelPublic(params);

// Due to the new exchange rate, new fee is halved
uint256 newFee = pricing.deliveryCost;
Expand All @@ -460,7 +460,7 @@ contract GatewayTest is Test {
);

vm.expectRevert(Gateway.ChannelDoesNotExist.selector);
GatewayMock(address(gateway)).updateChannelPublic(params);
MockGateway(address(gateway)).updateChannelPublic(params);
}

function testUpdateChannelSanityChecksForPrimaryGovernanceChannel() public {
Expand All @@ -472,12 +472,12 @@ contract GatewayTest is Test {
);

vm.expectRevert(Gateway.InvalidChannelUpdate.selector);
GatewayMock(address(gateway)).updateChannelPublic(params);
MockGateway(address(gateway)).updateChannelPublic(params);
}

function testUpgrade() public {
// Upgrade to this new logic contract
GatewayV2 newLogic = new GatewayV2();
MockGatewayV2 newLogic = new MockGatewayV2();

UpgradeParams memory params = UpgradeParams({
impl: address(newLogic),
Expand All @@ -489,14 +489,14 @@ contract GatewayTest is Test {
vm.expectEmit(true, false, false, false);
emit IUpgradable.Upgraded(address(newLogic));

GatewayMock(address(gateway)).upgradePublic(abi.encode(params));
MockGateway(address(gateway)).upgradePublic(abi.encode(params));

// Verify that the GatewayV2.initialize was called
assertEq(GatewayV2(address(gateway)).getValue(), 42);
// Verify that the MockGatewayV2.initialize was called
assertEq(MockGatewayV2(address(gateway)).getValue(), 42);
}

function testUpgradeFailOnInitializationFailure() public {
GatewayV2 newLogic = new GatewayV2();
MockGatewayV2 newLogic = new MockGatewayV2();

UpgradeParams memory params = UpgradeParams({
impl: address(newLogic),
Expand All @@ -505,17 +505,17 @@ contract GatewayTest is Test {
});

vm.expectRevert("initialize failed");
GatewayMock(address(gateway)).upgradePublic(abi.encode(params));
MockGateway(address(gateway)).upgradePublic(abi.encode(params));
}

function testUpgradeFailCodeHashMismatch() public {
GatewayV2 newLogic = new GatewayV2();
MockGatewayV2 newLogic = new MockGatewayV2();

UpgradeParams memory params =
UpgradeParams({impl: address(newLogic), implCodeHash: bytes32(0), initParams: abi.encode(42)});

vm.expectRevert(IUpgradable.InvalidCodeHash.selector);
GatewayMock(address(gateway)).upgradePublic(abi.encode(params));
MockGateway(address(gateway)).upgradePublic(abi.encode(params));
}

function testSetOperatingMode() public {
Expand All @@ -524,7 +524,7 @@ contract GatewayTest is Test {
OperatingMode mode = IGateway(address(gateway)).operatingMode();
assertEq(uint256(mode), 0);

GatewayMock(address(gateway)).setOperatingModePublic(abi.encode(params));
MockGateway(address(gateway)).setOperatingModePublic(abi.encode(params));

mode = IGateway(address(gateway)).operatingMode();
assertEq(uint256(mode), 1);
Expand All @@ -538,7 +538,7 @@ contract GatewayTest is Test {
bytes memory params =
abi.encode(TransferNativeFromAgentParams({agentID: assetHubAgentID, recipient: recipient, amount: 3 ether}));

GatewayMock(address(gateway)).transferNativeFromAgentPublic(params);
MockGateway(address(gateway)).transferNativeFromAgentPublic(params);

assertEq(assetHubAgent.balance, 47 ether);
assertEq(recipient.balance, 3 ether);
Expand All @@ -564,7 +564,7 @@ contract GatewayTest is Test {
vm.expectEmit(true, false, false, false);
emit IGateway.OutboundMessageAccepted(assetHubParaID.into(), 1, messageID, bytes(""));

uint256 totalFee = GatewayMock(address(gateway)).quoteRegisterTokenFee();
uint256 totalFee = MockGateway(address(gateway)).quoteRegisterTokenFee();

uint256 balanceBefore = address(this).balance;
IGateway(address(gateway)).registerToken{value: totalFee + 1 ether}(address(token));
Expand Down Expand Up @@ -667,7 +667,7 @@ contract GatewayTest is Test {
// Let gateway lock up to 1 tokens
token.approve(address(gateway), 1);

GatewayMock(address(gateway)).setOperatingModePublic(
MockGateway(address(gateway)).setOperatingModePublic(
abi.encode(SetOperatingModeParams({mode: OperatingMode.RejectingOutboundMessages}))
);

Expand All @@ -679,7 +679,7 @@ contract GatewayTest is Test {
// Let gateway lock up to 1 tokens
token.approve(address(gateway), 1);

GatewayMock(address(gateway)).setOperatingModePublic(
MockGateway(address(gateway)).setOperatingModePublic(
abi.encode(SetOperatingModeParams({mode: OperatingMode.Normal}))
);

Expand All @@ -690,7 +690,7 @@ contract GatewayTest is Test {
bytes memory params = abi.encode(
UpdateChannelParams({channelID: assetHubParaID.into(), mode: OperatingMode.RejectingOutboundMessages})
);
GatewayMock(address(gateway)).updateChannelPublic(params);
MockGateway(address(gateway)).updateChannelPublic(params);

OperatingMode mode = IGateway(address(gateway)).channelOperatingModeOf(assetHubParaID.into());
assertEq(uint256(mode), 1);
Expand All @@ -714,7 +714,7 @@ contract GatewayTest is Test {
Gateway(address(gateway)).initialize("");

vm.expectRevert(Gateway.Unauthorized.selector);
GatewayMock(address(gatewayLogic)).initialize("");
MockGateway(address(gatewayLogic)).initialize("");
}

// Handler functions should not be externally callable
Expand Down Expand Up @@ -786,7 +786,7 @@ contract GatewayTest is Test {
uint256 fee = IGateway(address(gateway)).quoteRegisterTokenFee();
assertEq(fee, 5000000000000000);
// Double the assetHubCreateAssetFee
GatewayMock(address(gateway)).setTokenTransferFeesPublic(
MockGateway(address(gateway)).setTokenTransferFeesPublic(
abi.encode(
SetTokenTransferFeesParams({
assetHubCreateAssetFee: createTokenFee * 2,
Expand All @@ -812,7 +812,7 @@ contract GatewayTest is Test {
uint256 fee = IGateway(address(gateway)).quoteRegisterTokenFee();
assertEq(fee, 5000000000000000);
// Double both the exchangeRate and multiplier. Should lead to an 4x fee increase
GatewayMock(address(gateway)).setPricingParametersPublic(
MockGateway(address(gateway)).setPricingParametersPublic(
abi.encode(
SetPricingParametersParams({
exchangeRate: exchangeRate.mul(convert(2)),
Expand Down
Loading

0 comments on commit af101b6

Please sign in to comment.