Skip to content

Commit

Permalink
Upgrade test
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Aug 31, 2024
1 parent 001c990 commit 5db1285
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@ contract Gateway is IGateway, IInitializable, IUpgradable {
revert Unauthorized();
}

if (data.length == 0) {
return;
}

CoreStorage.Layout storage core = CoreStorage.layout();

Config memory config = abi.decode(data, (Config));
Expand Down
80 changes: 80 additions & 0 deletions contracts/test/ForkMigration.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.25;

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

import {IUpgradable} from "../src/interfaces/IUpgradable.sol";
import {IGateway} from "../src/interfaces/IGateway.sol";
import {Gateway} from "../src/Gateway.sol";
import {AgentExecutor} from "../src/AgentExecutor.sol";
import {UpgradeParams, SetOperatingModeParams, OperatingMode} from "../src/Params.sol";
import {ChannelID, ParaID, OperatingMode} from "../src/Types.sol";
import {UD60x18, ud60x18} from "prb/math/src/UD60x18.sol";

function mDot(uint32 value) pure returns (uint128) {
return value * (10 ** 7);
}

function dot(uint32 value) pure returns (uint128) {
return value * (10 ** 10);
}

contract ForkUpgradeTest is Test {
address private constant GatewayProxy = 0x27ca963C279c93801941e1eB8799c23f407d68e7;

function setUp() public {
vm.createSelectFork("https://rpc.tenderly.co/fork/b77e07b8-ad6d-4e83-b5be-30a2001964aa", 20645700);
vm.allowCheatcodes(GatewayProxy);
forkUpgrade();
}

function forkUpgrade() public {
// AgentExecutor
AgentExecutor executor = new AgentExecutor();

// Gateway implementation
Gateway newLogic = new Gateway(
0x6eD05bAa904df3DE117EcFa638d4CB84e1B8A00C,
address(executor),
ParaID.wrap(1002),
0x03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314,
10,
dot(2)
);

Gateway.Config memory initializerParams = Gateway.Config({
mode: OperatingMode.Normal,
deliveryCost: mDot(100), // 0.1 DOT
registerTokenFee: 0.002 ether,
assetHubParaID: ParaID.wrap(1000),
assetHubAgentID: 0x81c5ab2571199e3188135178f3c2c8e2d268be1313d029b30f534fa579b69b79,
assetHubCreateAssetFee: mDot(100), // 0.1 DOT
assetHubReserveTransferFee: mDot(100), // 0.1 DOT
exchangeRate: ud60x18(0.0024e18),
multiplier: ud60x18(1.33e18),
rescueOperator: 0x4B8a782D4F03ffcB7CE1e95C5cfe5BFCb2C8e967
});

UpgradeParams memory params = UpgradeParams({
impl: address(newLogic),
implCodeHash: address(newLogic).codehash,
initParams: bytes("") //abi.encode(initializerParams)
});

vm.startPrank(GatewayProxy);
vm.expectEmit(true, false, false, false);
emit IUpgradable.Upgraded(address(newLogic));

Gateway(GatewayProxy).upgrade(abi.encode(params));
vm.stopPrank();
}

function testSanityCheck() public {
(uint64 inbound, uint64 outbound) = IGateway(GatewayProxy).channelNoncesOf(
ChannelID.wrap(0xc173fac324158e77fb5840738a1a541f633cbec8884c6a601c567d2b376a0539)
);
assertEq(inbound, 13);
assertEq(outbound, 172);
}
}

0 comments on commit 5db1285

Please sign in to comment.