UNPKG

@hyperlane-xyz/cli

Version:

A command-line utility for common Hyperlane operations

98 lines 5 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, KeyBoardKeys, WARP_CONFIG_PATH_2, WARP_CONFIG_PATH_EXAMPLE, WARP_CORE_CONFIG_PATH_2, WARP_DEPLOY_OUTPUT_PATH, deployOrUseExistingCore, handlePrompts, } from '../commands/helpers.js'; import { hyperlaneWarpDeploy, hyperlaneWarpReadRaw, readWarpConfig, } from '../commands/warp.js'; describe('hyperlane warp read e2e tests', async function () { this.timeout(DEFAULT_E2E_TEST_TIMEOUT); let anvil2Config; let chain2Addresses = {}; let chain3Addresses = {}; let ownerAddress; before(async function () { [chain2Addresses, chain3Addresses] = await Promise.all([ deployOrUseExistingCore(CHAIN_NAME_2, CORE_CONFIG_PATH, ANVIL_KEY), deployOrUseExistingCore(CHAIN_NAME_3, CORE_CONFIG_PATH, ANVIL_KEY), ]); ownerAddress = new Wallet(ANVIL_KEY).address; }); before(async function () { await deployOrUseExistingCore(CHAIN_NAME_2, CORE_CONFIG_PATH, ANVIL_KEY); // Create a new warp config using the example const exampleWarpConfig = readYamlOrJson(WARP_CONFIG_PATH_EXAMPLE); anvil2Config = { [CHAIN_NAME_2]: { ...exampleWarpConfig.anvil1 } }; writeYamlOrJson(WARP_CONFIG_PATH_2, anvil2Config); }); describe('hyperlane warp read --config ...', () => { it('should exit early if no symbol, chain or warp file have been provided', async () => { await hyperlaneWarpDeploy(WARP_CONFIG_PATH_2); const output = await hyperlaneWarpReadRaw({ outputPath: WARP_CONFIG_PATH_2, }).nothrow(); expect(output.exitCode).to.equal(1); expect(output.text()).to.include('Please specify either a symbol, chain and address or warp file'); }); }); describe('hyperlane warp read --config ... --symbol ...', () => { it('should successfully read the complete warp route config from all the chains', async () => { await hyperlaneWarpDeploy(WARP_CONFIG_PATH_2); const output = await hyperlaneWarpReadRaw({ symbol: 'ETH', outputPath: WARP_CONFIG_PATH_2, }) .stdio('pipe') .nothrow(); expect(output.exitCode).to.equal(0); const warpReadResult = readYamlOrJson(WARP_CONFIG_PATH_2); expect(warpReadResult[CHAIN_NAME_2]).not.to.be.undefined; expect(warpReadResult[CHAIN_NAME_2].type).to.equal(TokenType.native); }); }); describe('hyperlane warp read --symbol ...', () => { it('should successfully read the complete warp route config from all the chains', async () => { const warpConfig = { [CHAIN_NAME_2]: { type: TokenType.native, mailbox: chain2Addresses.mailbox, owner: ownerAddress, }, [CHAIN_NAME_3]: { type: TokenType.synthetic, mailbox: chain3Addresses.mailbox, owner: ownerAddress, }, }; writeYamlOrJson(WARP_DEPLOY_OUTPUT_PATH, warpConfig); await hyperlaneWarpDeploy(WARP_DEPLOY_OUTPUT_PATH); const steps = [ // Select the anvil2-anvil3 ETH route from the selection prompt { check: (currentOutput) => currentOutput.includes('Select from matching warp routes'), input: KeyBoardKeys.ENTER, }, ]; const output = hyperlaneWarpReadRaw({ symbol: 'ETH', outputPath: WARP_DEPLOY_OUTPUT_PATH, }) .stdio('pipe') .nothrow(); const finalOutput = await handlePrompts(output, steps); expect(finalOutput.exitCode).to.equal(0); const warpReadResult = readYamlOrJson(WARP_DEPLOY_OUTPUT_PATH); expect(warpReadResult[CHAIN_NAME_2]).not.to.be.undefined; expect(warpReadResult[CHAIN_NAME_2].type).to.equal(TokenType.native); expect(warpReadResult[CHAIN_NAME_3]).not.to.be.undefined; expect(warpReadResult[CHAIN_NAME_3].type).to.equal(TokenType.synthetic); }); }); describe('hyperlane warp read --chain ... --config ...', () => { it('should be able to read a warp route', async function () { await hyperlaneWarpDeploy(WARP_CONFIG_PATH_2); const warpReadResult = await readWarpConfig(CHAIN_NAME_2, WARP_CORE_CONFIG_PATH_2, WARP_DEPLOY_OUTPUT_PATH); expect(warpReadResult[CHAIN_NAME_2].type).to.be.equal(anvil2Config[CHAIN_NAME_2].type); }); }); }); //# sourceMappingURL=warp-read.e2e-test.js.map