UNPKG

@hyperlane-xyz/cli

Version:

A command-line utility for common Hyperlane operations

172 lines 9.64 kB
import { expect } from 'chai'; import { Wallet } from 'ethers'; import { TokenType, } from '@hyperlane-xyz/sdk'; import { readYamlOrJson, writeYamlOrJson } from '../../utils/files.js'; import { ANVIL_KEY, CHAIN_NAME_2, CHAIN_NAME_3, CORE_CONFIG_PATH, DEFAULT_E2E_TEST_TIMEOUT, E2E_TEST_BURN_ADDRESS, EXAMPLES_PATH, TEMP_PATH, WARP_CONFIG_PATH_2, WARP_CONFIG_PATH_EXAMPLE, WARP_CORE_CONFIG_PATH_2, deployOrUseExistingCore, extendWarpConfig, getCombinedWarpRoutePath, getDomainId, } from '../commands/helpers.js'; import { hyperlaneWarpApply, hyperlaneWarpDeploy, readWarpConfig, } from '../commands/warp.js'; describe('hyperlane warp apply basic extension tests', async function () { this.timeout(2 * DEFAULT_E2E_TEST_TIMEOUT); let chain2Addresses = {}; before(async function () { await deployOrUseExistingCore(CHAIN_NAME_2, CORE_CONFIG_PATH, ANVIL_KEY); chain2Addresses = await deployOrUseExistingCore(CHAIN_NAME_3, CORE_CONFIG_PATH, ANVIL_KEY); // Create a new warp config using the example const warpConfig = readYamlOrJson(WARP_CONFIG_PATH_EXAMPLE); const anvil2Config = { anvil2: { ...warpConfig.anvil1 } }; writeYamlOrJson(WARP_CONFIG_PATH_2, anvil2Config); }); beforeEach(async function () { await hyperlaneWarpDeploy(WARP_CONFIG_PATH_2); }); it('should extend an existing warp route', async () => { // Read existing config into a file const warpConfigPath = `${TEMP_PATH}/warp-route-deployment-2.yaml`; await readWarpConfig(CHAIN_NAME_2, WARP_CORE_CONFIG_PATH_2, warpConfigPath); // Extend with new config const config = { decimals: 18, mailbox: chain2Addresses.mailbox, name: 'Ether', owner: new Wallet(ANVIL_KEY).address, symbol: 'ETH', type: TokenType.native, }; await extendWarpConfig({ chain: CHAIN_NAME_2, chainToExtend: CHAIN_NAME_3, extendedConfig: config, warpCorePath: WARP_CORE_CONFIG_PATH_2, warpDeployPath: warpConfigPath, }); const COMBINED_WARP_CORE_CONFIG_PATH = getCombinedWarpRoutePath('ETH', [ CHAIN_NAME_2, CHAIN_NAME_3, ]); // Check that chain2 is enrolled in chain1 const updatedWarpDeployConfig1 = await readWarpConfig(CHAIN_NAME_2, COMBINED_WARP_CORE_CONFIG_PATH, warpConfigPath); const chain2Id = await getDomainId(CHAIN_NAME_3, ANVIL_KEY); const remoteRouterKeys1 = Object.keys(updatedWarpDeployConfig1[CHAIN_NAME_2].remoteRouters); expect(remoteRouterKeys1).to.include(chain2Id); // Check that chain1 is enrolled in chain2 const updatedWarpDeployConfig2 = await readWarpConfig(CHAIN_NAME_3, COMBINED_WARP_CORE_CONFIG_PATH, warpConfigPath); const chain1Id = await getDomainId(CHAIN_NAME_2, ANVIL_KEY); const remoteRouterKeys2 = Object.keys(updatedWarpDeployConfig2[CHAIN_NAME_3].remoteRouters); expect(remoteRouterKeys2).to.include(chain1Id); }); it('should extend an existing warp route with json strategy', async () => { // Read existing config into a file const warpConfigPath = `${TEMP_PATH}/warp-route-deployment-2.yaml`; await readWarpConfig(CHAIN_NAME_2, WARP_CORE_CONFIG_PATH_2, warpConfigPath); // Extend with new config const config = { decimals: 18, mailbox: chain2Addresses.mailbox, name: 'Ether', owner: new Wallet(ANVIL_KEY).address, symbol: 'ETH', type: TokenType.native, }; await extendWarpConfig({ chain: CHAIN_NAME_2, chainToExtend: CHAIN_NAME_3, extendedConfig: config, warpCorePath: WARP_CORE_CONFIG_PATH_2, warpDeployPath: warpConfigPath, strategyUrl: `${EXAMPLES_PATH}/submit/strategy/json-rpc-chain-strategy.yaml`, }); const COMBINED_WARP_CORE_CONFIG_PATH = getCombinedWarpRoutePath('ETH', [ CHAIN_NAME_2, CHAIN_NAME_3, ]); // Check that chain2 is enrolled in chain1 const updatedWarpDeployConfig1 = await readWarpConfig(CHAIN_NAME_2, COMBINED_WARP_CORE_CONFIG_PATH, warpConfigPath); const chain2Id = await getDomainId(CHAIN_NAME_3, ANVIL_KEY); const remoteRouterKeys1 = Object.keys(updatedWarpDeployConfig1[CHAIN_NAME_2].remoteRouters); expect(remoteRouterKeys1).to.include(chain2Id); // Check that chain1 is enrolled in chain2 const updatedWarpDeployConfig2 = await readWarpConfig(CHAIN_NAME_3, COMBINED_WARP_CORE_CONFIG_PATH, warpConfigPath); const chain1Id = await getDomainId(CHAIN_NAME_2, ANVIL_KEY); const remoteRouterKeys2 = Object.keys(updatedWarpDeployConfig2[CHAIN_NAME_3].remoteRouters); expect(remoteRouterKeys2).to.include(chain1Id); }); it('should extend an existing warp route and update the owner', async () => { const warpDeployPath = `${TEMP_PATH}/warp-route-deployment-2.yaml`; // Burn anvil2 owner in config const warpDeployConfig = await readWarpConfig(CHAIN_NAME_2, WARP_CORE_CONFIG_PATH_2, warpDeployPath); warpDeployConfig[CHAIN_NAME_2].owner = E2E_TEST_BURN_ADDRESS; // Extend with new config const randomOwner = new Wallet(ANVIL_KEY).address; const extendedConfig = { decimals: 18, mailbox: chain2Addresses.mailbox, name: 'Ether', owner: randomOwner, symbol: 'ETH', type: TokenType.native, }; // Remove remoteRouters and destinationGas as they are written in readWarpConfig warpDeployConfig[CHAIN_NAME_2].remoteRouters = undefined; warpDeployConfig[CHAIN_NAME_2].destinationGas = undefined; warpDeployConfig[CHAIN_NAME_3] = extendedConfig; writeYamlOrJson(warpDeployPath, warpDeployConfig); await hyperlaneWarpApply(warpDeployPath, WARP_CORE_CONFIG_PATH_2); const COMBINED_WARP_CORE_CONFIG_PATH = getCombinedWarpRoutePath('ETH', [ CHAIN_NAME_2, CHAIN_NAME_3, ]); const updatedWarpDeployConfig_2 = await readWarpConfig(CHAIN_NAME_2, COMBINED_WARP_CORE_CONFIG_PATH, warpDeployPath); const updatedWarpDeployConfig_3 = await readWarpConfig(CHAIN_NAME_3, COMBINED_WARP_CORE_CONFIG_PATH, warpDeployPath); // Check that anvil2 owner is burned expect(updatedWarpDeployConfig_2.anvil2.owner).to.equal(E2E_TEST_BURN_ADDRESS); // Also, anvil3 owner is not burned expect(updatedWarpDeployConfig_3.anvil3.owner).to.equal(randomOwner); // Check that both chains enrolled const chain2Id = await getDomainId(CHAIN_NAME_2, ANVIL_KEY); const chain3Id = await getDomainId(CHAIN_NAME_3, ANVIL_KEY); const remoteRouterKeys2 = Object.keys(updatedWarpDeployConfig_2[CHAIN_NAME_2].remoteRouters); const remoteRouterKeys3 = Object.keys(updatedWarpDeployConfig_3[CHAIN_NAME_3].remoteRouters); expect(remoteRouterKeys2).to.include(chain3Id); expect(remoteRouterKeys3).to.include(chain2Id); }); it('should extend an existing warp route and update all destination domains', async () => { // Read existing config into a file const warpConfigPath = `${TEMP_PATH}/warp-route-deployment-2.yaml`; const warpDeployConfig = await readWarpConfig(CHAIN_NAME_2, WARP_CORE_CONFIG_PATH_2, warpConfigPath); warpDeployConfig[CHAIN_NAME_2].gas = 7777; // Extend with new config const GAS = 694200; const extendedConfig = { decimals: 18, mailbox: chain2Addresses.mailbox, name: 'Ether', owner: new Wallet(ANVIL_KEY).address, symbol: 'ETH', type: TokenType.native, gas: GAS, }; // Remove remoteRouters and destinationGas as they are written in readWarpConfig warpDeployConfig[CHAIN_NAME_2].remoteRouters = undefined; warpDeployConfig[CHAIN_NAME_2].destinationGas = undefined; warpDeployConfig[CHAIN_NAME_3] = extendedConfig; writeYamlOrJson(warpConfigPath, warpDeployConfig); await hyperlaneWarpApply(warpConfigPath, WARP_CORE_CONFIG_PATH_2); const COMBINED_WARP_CORE_CONFIG_PATH = getCombinedWarpRoutePath('ETH', [ CHAIN_NAME_2, CHAIN_NAME_3, ]); // Check that chain2 is enrolled in chain1 const updatedWarpDeployConfig_2 = await readWarpConfig(CHAIN_NAME_2, COMBINED_WARP_CORE_CONFIG_PATH, warpConfigPath); const chain2Id = await getDomainId(CHAIN_NAME_2, ANVIL_KEY); const chain3Id = await getDomainId(CHAIN_NAME_3, ANVIL_KEY); // Destination gas should be set in the existing chain (chain2) to include the extended chain (chain3) const destinationGas_2 = updatedWarpDeployConfig_2[CHAIN_NAME_2].destinationGas; expect(Object.keys(destinationGas_2)).to.include(chain3Id); expect(destinationGas_2[chain3Id]).to.equal(GAS.toString()); // Destination gas should be set for the extended chain (chain3) const updatedWarpDeployConfig_3 = await readWarpConfig(CHAIN_NAME_3, COMBINED_WARP_CORE_CONFIG_PATH, warpConfigPath); const destinationGas_3 = updatedWarpDeployConfig_3[CHAIN_NAME_3].destinationGas; expect(Object.keys(destinationGas_3)).to.include(chain2Id); expect(destinationGas_3[chain2Id]).to.equal('7777'); }); }); //# sourceMappingURL=warp-extend-basic.e2e-test.js.map