|
| 1 | +import * as chai from 'chai'; |
| 2 | +import chaiAsPromised from 'chai-as-promised'; |
| 3 | +import { Wallet } from 'ethers'; |
| 4 | + |
| 5 | +import { type ChainAddresses } from '@hyperlane-xyz/registry'; |
| 6 | +import { |
| 7 | + TokenType, |
| 8 | + type WarpRouteDeployConfig, |
| 9 | + randomAddress, |
| 10 | +} from '@hyperlane-xyz/sdk'; |
| 11 | +import { |
| 12 | + type Address, |
| 13 | + addressToBytes32, |
| 14 | + assert, |
| 15 | + isObjEmpty, |
| 16 | +} from '@hyperlane-xyz/utils'; |
| 17 | + |
| 18 | +import { readYamlOrJson, writeYamlOrJson } from '../../../utils/files.js'; |
| 19 | +import { deployOrUseExistingCore } from '../commands/core.js'; |
| 20 | +import { getDomainId } from '../commands/helpers.js'; |
| 21 | +import { |
| 22 | + hyperlaneWarpDeploy, |
| 23 | + hyperlaneWarpReadRaw, |
| 24 | + resolveWarpRouteIdForDeploy, |
| 25 | +} from '../commands/warp.js'; |
| 26 | +import { |
| 27 | + ANVIL_KEY, |
| 28 | + CHAIN_NAME_2, |
| 29 | + CHAIN_NAME_3, |
| 30 | + CHAIN_NAME_4, |
| 31 | + CORE_CONFIG_PATH, |
| 32 | + DEFAULT_E2E_TEST_TIMEOUT, |
| 33 | + IS_TRON_TEST, |
| 34 | + TRON_KEY_1, |
| 35 | + WARP_DEPLOY_OUTPUT_PATH, |
| 36 | +} from '../consts.js'; |
| 37 | + |
| 38 | +chai.use(chaiAsPromised); |
| 39 | +const expect = chai.expect; |
| 40 | + |
| 41 | +describe('hyperlane warp deploy with user-specified remote routers', async function () { |
| 42 | + this.timeout(2 * DEFAULT_E2E_TEST_TIMEOUT); |
| 43 | + |
| 44 | + let chain2Addresses: ChainAddresses = {}; |
| 45 | + let chain3Addresses: ChainAddresses = {}; |
| 46 | + let ownerAddress: Address; |
| 47 | + let chain2DomainId: string; |
| 48 | + let chain3DomainId: string; |
| 49 | + let chain4DomainId: string; |
| 50 | + |
| 51 | + before(async function () { |
| 52 | + ownerAddress = new Wallet(ANVIL_KEY).address; |
| 53 | + const chain3Key = IS_TRON_TEST ? TRON_KEY_1 : ANVIL_KEY; |
| 54 | + [chain2Addresses, chain3Addresses] = await Promise.all([ |
| 55 | + deployOrUseExistingCore(CHAIN_NAME_2, CORE_CONFIG_PATH, ANVIL_KEY), |
| 56 | + deployOrUseExistingCore(CHAIN_NAME_3, CORE_CONFIG_PATH, chain3Key), |
| 57 | + ]); |
| 58 | + [chain2DomainId, chain3DomainId, chain4DomainId] = await Promise.all([ |
| 59 | + getDomainId(CHAIN_NAME_2, ANVIL_KEY), |
| 60 | + getDomainId(CHAIN_NAME_3, ANVIL_KEY), |
| 61 | + getDomainId(CHAIN_NAME_4, ANVIL_KEY), |
| 62 | + ]); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should enroll user-specified remote routers for chains not in the deploy config', async function () { |
| 66 | + // Deploy only on anvil2 with remoteRouters pointing to anvil3 (not in deploy config) |
| 67 | + const fakeRemoteRouterAddress = randomAddress(); |
| 68 | + |
| 69 | + const warpConfig: WarpRouteDeployConfig = { |
| 70 | + [CHAIN_NAME_2]: { |
| 71 | + type: TokenType.native, |
| 72 | + mailbox: chain2Addresses.mailbox, |
| 73 | + owner: ownerAddress, |
| 74 | + symbol: 'ETH', |
| 75 | + name: 'Ether', |
| 76 | + remoteRouters: { |
| 77 | + [CHAIN_NAME_3]: { |
| 78 | + address: addressToBytes32(fakeRemoteRouterAddress), |
| 79 | + }, |
| 80 | + }, |
| 81 | + }, |
| 82 | + }; |
| 83 | + |
| 84 | + writeYamlOrJson(WARP_DEPLOY_OUTPUT_PATH, warpConfig); |
| 85 | + const resolvedWarpRouteId = await resolveWarpRouteIdForDeploy({ |
| 86 | + warpDeployPath: WARP_DEPLOY_OUTPUT_PATH, |
| 87 | + }); |
| 88 | + |
| 89 | + await hyperlaneWarpDeploy(WARP_DEPLOY_OUTPUT_PATH, resolvedWarpRouteId); |
| 90 | + |
| 91 | + // Read back the deployed config |
| 92 | + await hyperlaneWarpReadRaw({ |
| 93 | + warpRouteId: resolvedWarpRouteId, |
| 94 | + outputPath: WARP_DEPLOY_OUTPUT_PATH, |
| 95 | + }); |
| 96 | + const deployedConfig = readYamlOrJson( |
| 97 | + WARP_DEPLOY_OUTPUT_PATH, |
| 98 | + ) as WarpRouteDeployConfig; |
| 99 | + |
| 100 | + // Verify the user-specified remote router was enrolled |
| 101 | + const remoteRouters = deployedConfig[CHAIN_NAME_2].remoteRouters; |
| 102 | + assert(remoteRouters, 'Expected remoteRouters to be defined'); |
| 103 | + expect(Object.keys(remoteRouters)).to.include(chain3DomainId); |
| 104 | + expect(remoteRouters[chain3DomainId].address).to.equal( |
| 105 | + addressToBytes32(fakeRemoteRouterAddress), |
| 106 | + ); |
| 107 | + |
| 108 | + // Verify destinationGas defaults to MAX_GAS_OVERHEAD for user-specified remote routers |
| 109 | + const destinationGas = deployedConfig[CHAIN_NAME_2].destinationGas; |
| 110 | + assert(destinationGas, 'Expected destinationGas to be defined'); |
| 111 | + expect(destinationGas[chain3DomainId]).to.equal('68000'); |
| 112 | + }); |
| 113 | + |
| 114 | + it('should enroll user-specified remote routers alongside routers from other deployed chains', async function () { |
| 115 | + // Deploy on both anvil2 and anvil3, but also specify a remote router |
| 116 | + // for anvil4 which is not part of the deployment |
| 117 | + const fakeRemoteRouterAddress = randomAddress(); |
| 118 | + |
| 119 | + const warpConfig: WarpRouteDeployConfig = { |
| 120 | + [CHAIN_NAME_2]: { |
| 121 | + type: TokenType.native, |
| 122 | + mailbox: chain2Addresses.mailbox, |
| 123 | + owner: ownerAddress, |
| 124 | + symbol: 'ETH', |
| 125 | + name: 'Ether', |
| 126 | + remoteRouters: { |
| 127 | + [CHAIN_NAME_4]: { |
| 128 | + address: addressToBytes32(fakeRemoteRouterAddress), |
| 129 | + }, |
| 130 | + }, |
| 131 | + }, |
| 132 | + [CHAIN_NAME_3]: { |
| 133 | + type: TokenType.synthetic, |
| 134 | + mailbox: chain3Addresses.mailbox, |
| 135 | + owner: ownerAddress, |
| 136 | + }, |
| 137 | + }; |
| 138 | + |
| 139 | + writeYamlOrJson(WARP_DEPLOY_OUTPUT_PATH, warpConfig); |
| 140 | + const resolvedWarpRouteId = await resolveWarpRouteIdForDeploy({ |
| 141 | + warpDeployPath: WARP_DEPLOY_OUTPUT_PATH, |
| 142 | + }); |
| 143 | + |
| 144 | + await hyperlaneWarpDeploy(WARP_DEPLOY_OUTPUT_PATH, resolvedWarpRouteId); |
| 145 | + |
| 146 | + // Read back the deployed config for all chains |
| 147 | + await hyperlaneWarpReadRaw({ |
| 148 | + warpRouteId: resolvedWarpRouteId, |
| 149 | + outputPath: WARP_DEPLOY_OUTPUT_PATH, |
| 150 | + }); |
| 151 | + const deployedConfig = readYamlOrJson( |
| 152 | + WARP_DEPLOY_OUTPUT_PATH, |
| 153 | + ) as WarpRouteDeployConfig; |
| 154 | + |
| 155 | + // Verify anvil2 has both: the user-specified anvil4 AND the auto-discovered anvil3 |
| 156 | + const remoteRouters2 = deployedConfig[CHAIN_NAME_2].remoteRouters; |
| 157 | + assert(remoteRouters2, 'Expected remoteRouters to be defined'); |
| 158 | + expect(Object.keys(remoteRouters2)).to.include(chain4DomainId); |
| 159 | + expect(Object.keys(remoteRouters2)).to.include(chain3DomainId); |
| 160 | + expect(remoteRouters2[chain4DomainId].address).to.equal( |
| 161 | + addressToBytes32(fakeRemoteRouterAddress), |
| 162 | + ); |
| 163 | + |
| 164 | + // Verify destinationGas on anvil2 |
| 165 | + const destinationGas2 = deployedConfig[CHAIN_NAME_2].destinationGas; |
| 166 | + assert(destinationGas2, 'Expected destinationGas to be defined'); |
| 167 | + expect(destinationGas2[chain4DomainId]).to.equal('68000'); |
| 168 | + expect(destinationGas2[chain3DomainId]).to.equal('64000'); |
| 169 | + |
| 170 | + // Verify anvil3 does NOT include anvil4 — user-specified routers are scoped per-chain |
| 171 | + const remoteRouters3 = deployedConfig[CHAIN_NAME_3].remoteRouters; |
| 172 | + assert(remoteRouters3, 'Expected remoteRouters to be defined'); |
| 173 | + expect(Object.keys(remoteRouters3)).to.include(chain2DomainId); |
| 174 | + expect(Object.keys(remoteRouters3)).to.not.include(chain4DomainId); |
| 175 | + }); |
| 176 | + |
| 177 | + it('should not enroll any remote routers when none are specified and only one chain is deployed', async function () { |
| 178 | + // Deploy only on anvil2 with NO remoteRouters |
| 179 | + const warpConfig: WarpRouteDeployConfig = { |
| 180 | + [CHAIN_NAME_2]: { |
| 181 | + type: TokenType.native, |
| 182 | + mailbox: chain2Addresses.mailbox, |
| 183 | + owner: ownerAddress, |
| 184 | + symbol: 'ETH', |
| 185 | + name: 'Ether', |
| 186 | + }, |
| 187 | + }; |
| 188 | + |
| 189 | + writeYamlOrJson(WARP_DEPLOY_OUTPUT_PATH, warpConfig); |
| 190 | + const resolvedWarpRouteId = await resolveWarpRouteIdForDeploy({ |
| 191 | + warpDeployPath: WARP_DEPLOY_OUTPUT_PATH, |
| 192 | + }); |
| 193 | + |
| 194 | + await hyperlaneWarpDeploy(WARP_DEPLOY_OUTPUT_PATH, resolvedWarpRouteId); |
| 195 | + |
| 196 | + // Read back the deployed config |
| 197 | + await hyperlaneWarpReadRaw({ |
| 198 | + warpRouteId: resolvedWarpRouteId, |
| 199 | + outputPath: WARP_DEPLOY_OUTPUT_PATH, |
| 200 | + }); |
| 201 | + const deployedConfig = readYamlOrJson( |
| 202 | + WARP_DEPLOY_OUTPUT_PATH, |
| 203 | + ) as WarpRouteDeployConfig; |
| 204 | + |
| 205 | + // Verify no remote routers were enrolled |
| 206 | + const remoteRouters = deployedConfig[CHAIN_NAME_2].remoteRouters; |
| 207 | + expect( |
| 208 | + !remoteRouters || isObjEmpty(remoteRouters), |
| 209 | + 'Expected no remote routers to be enrolled', |
| 210 | + ).to.be.true; |
| 211 | + }); |
| 212 | +}); |
0 commit comments