@hyperlane-xyz/cli
Version:
A command-line utility for common Hyperlane operations
91 lines • 5.24 kB
JavaScript
import { expect } from 'chai';
import { Wallet } from 'ethers';
import { HookType, TokenType, normalizeConfig, randomAddress, } 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, TEMP_PATH, WARP_CONFIG_PATH_2, WARP_CONFIG_PATH_EXAMPLE, WARP_CORE_CONFIG_PATH_2, deployOrUseExistingCore, extendWarpConfig, getCombinedWarpRoutePath, getDomainId, updateOwner, } from '../commands/helpers.js';
import { hyperlaneWarpApply, hyperlaneWarpDeploy, readWarpConfig, } from '../commands/warp.js';
describe('hyperlane warp apply owner update 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 burn owner address', async function () {
const warpConfigPath = `${TEMP_PATH}/warp-route-deployment-2.yaml`;
await updateOwner(E2E_TEST_BURN_ADDRESS, CHAIN_NAME_2, warpConfigPath, WARP_CORE_CONFIG_PATH_2);
const updatedWarpDeployConfig = await readWarpConfig(CHAIN_NAME_2, WARP_CORE_CONFIG_PATH_2, warpConfigPath);
expect(updatedWarpDeployConfig.anvil2.owner).to.equal(E2E_TEST_BURN_ADDRESS);
});
it('should not update the same owner', async () => {
const warpConfigPath = `${TEMP_PATH}/warp-route-deployment-2.yaml`;
await updateOwner(E2E_TEST_BURN_ADDRESS, CHAIN_NAME_2, warpConfigPath, WARP_CORE_CONFIG_PATH_2);
const { stdout } = await updateOwner(E2E_TEST_BURN_ADDRESS, CHAIN_NAME_2, warpConfigPath, WARP_CORE_CONFIG_PATH_2);
expect(stdout).to.include('Warp config is the same as target. No updates needed.');
});
it('should update hook configuration', async () => {
const warpDeployPath = `${TEMP_PATH}/warp-route-deployment-2.yaml`;
// First read the existing config
const warpDeployConfig = await readWarpConfig(CHAIN_NAME_2, WARP_CORE_CONFIG_PATH_2, warpDeployPath);
// Update with a new hook config
const owner = randomAddress();
warpDeployConfig[CHAIN_NAME_2].hook = {
type: HookType.PROTOCOL_FEE,
beneficiary: owner,
maxProtocolFee: '1000000',
protocolFee: '100000',
owner,
};
// Write the updated config
await writeYamlOrJson(warpDeployPath, warpDeployConfig);
// Apply the changes
await hyperlaneWarpApply(warpDeployPath, WARP_CORE_CONFIG_PATH_2);
// Read back the config to verify changes
const updatedConfig = await readWarpConfig(CHAIN_NAME_2, WARP_CORE_CONFIG_PATH_2, warpDeployPath);
// Verify the hook was updated with all properties
expect(normalizeConfig(updatedConfig[CHAIN_NAME_2].hook)).to.deep.equal(normalizeConfig(warpDeployConfig[CHAIN_NAME_2].hook));
});
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);
});
});
//# sourceMappingURL=warp-apply.e2e-test.js.map