|
| 1 | +import { expect } from 'chai'; |
| 2 | + |
| 3 | +import { ChainAddresses } from '@hyperlane-xyz/registry'; |
| 4 | +import { |
| 5 | + DerivedWarpRouteDeployConfig, |
| 6 | + TokenType, |
| 7 | + WarpRouteDeployConfig, |
| 8 | +} from '@hyperlane-xyz/sdk'; |
| 9 | +import { Address, ProtocolType, assert } from '@hyperlane-xyz/utils'; |
| 10 | + |
| 11 | +import { readYamlOrJson, writeYamlOrJson } from '../../../utils/files.js'; |
| 12 | +import { HyperlaneE2ECoreTestCommands } from '../../commands/core.js'; |
| 13 | +import { HyperlaneE2EWarpTestCommands } from '../../commands/warp.js'; |
| 14 | +import { |
| 15 | + BURN_ADDRESS_BY_PROTOCOL, |
| 16 | + CORE_CONFIG_PATH_BY_PROTOCOL, |
| 17 | + CORE_READ_CONFIG_PATH_BY_PROTOCOL, |
| 18 | + DEFAULT_E2E_TEST_TIMEOUT, |
| 19 | + HYP_DEPLOYER_ADDRESS_BY_PROTOCOL, |
| 20 | + HYP_KEY_BY_PROTOCOL, |
| 21 | + REGISTRY_PATH, |
| 22 | + TEST_CHAIN_METADATA_BY_PROTOCOL, |
| 23 | + TEST_CHAIN_NAMES_BY_PROTOCOL, |
| 24 | + WARP_READ_OUTPUT_PATH, |
| 25 | + getWarpCoreConfigPath, |
| 26 | + getWarpDeployConfigPath, |
| 27 | + getWarpId, |
| 28 | +} from '../../constants.js'; |
| 29 | + |
| 30 | +describe('hyperlane warp apply (Radix E2E tests)', async function () { |
| 31 | + this.timeout(DEFAULT_E2E_TEST_TIMEOUT); |
| 32 | + |
| 33 | + const nativeTokenData = |
| 34 | + TEST_CHAIN_METADATA_BY_PROTOCOL.radix.CHAIN_NAME_1.nativeToken; |
| 35 | + assert( |
| 36 | + nativeTokenData, |
| 37 | + `Expected native token data to be defined for chain ${TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_1}`, |
| 38 | + ); |
| 39 | + const nativeTokenAddress = nativeTokenData.denom; |
| 40 | + assert( |
| 41 | + nativeTokenAddress, |
| 42 | + `Expected native token address to be defined for ${TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_1}`, |
| 43 | + ); |
| 44 | + |
| 45 | + let chain1CoreAddress: ChainAddresses; |
| 46 | + const hyperlaneCore1 = new HyperlaneE2ECoreTestCommands( |
| 47 | + ProtocolType.Radix, |
| 48 | + TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_1, |
| 49 | + REGISTRY_PATH, |
| 50 | + CORE_CONFIG_PATH_BY_PROTOCOL.radix, |
| 51 | + CORE_READ_CONFIG_PATH_BY_PROTOCOL.radix.CHAIN_NAME_1, |
| 52 | + ); |
| 53 | + |
| 54 | + let chain2CoreAddress: ChainAddresses; |
| 55 | + const hyperlaneCore2 = new HyperlaneE2ECoreTestCommands( |
| 56 | + ProtocolType.Radix, |
| 57 | + TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_2, |
| 58 | + REGISTRY_PATH, |
| 59 | + CORE_CONFIG_PATH_BY_PROTOCOL.radix, |
| 60 | + CORE_READ_CONFIG_PATH_BY_PROTOCOL.radix.CHAIN_NAME_2, |
| 61 | + ); |
| 62 | + |
| 63 | + const WARP_CORE_PATH = getWarpCoreConfigPath(nativeTokenData.symbol, [ |
| 64 | + TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_1, |
| 65 | + ]); |
| 66 | + const WARP_DEPLOY_PATH = getWarpDeployConfigPath(nativeTokenData.symbol, [ |
| 67 | + TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_1, |
| 68 | + ]); |
| 69 | + const WARP_ROUTE_ID = getWarpId(nativeTokenData.symbol, [ |
| 70 | + TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_1, |
| 71 | + ]); |
| 72 | + |
| 73 | + const hyperlaneWarp = new HyperlaneE2EWarpTestCommands( |
| 74 | + ProtocolType.Radix, |
| 75 | + REGISTRY_PATH, |
| 76 | + WARP_CORE_PATH, |
| 77 | + ); |
| 78 | + |
| 79 | + before(async function () { |
| 80 | + [chain1CoreAddress, chain2CoreAddress] = await Promise.all([ |
| 81 | + hyperlaneCore1.deployOrUseExistingCore(HYP_KEY_BY_PROTOCOL.radix), |
| 82 | + hyperlaneCore2.deployOrUseExistingCore(HYP_KEY_BY_PROTOCOL.radix), |
| 83 | + ]); |
| 84 | + }); |
| 85 | + |
| 86 | + let warpDeployConfig: WarpRouteDeployConfig; |
| 87 | + beforeEach(async () => { |
| 88 | + warpDeployConfig = { |
| 89 | + [TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_1]: { |
| 90 | + type: TokenType.collateral, |
| 91 | + token: nativeTokenAddress, |
| 92 | + mailbox: chain1CoreAddress.mailbox, |
| 93 | + owner: HYP_DEPLOYER_ADDRESS_BY_PROTOCOL.radix, |
| 94 | + name: nativeTokenData.name, |
| 95 | + symbol: nativeTokenData.symbol, |
| 96 | + decimals: nativeTokenData.decimals, |
| 97 | + }, |
| 98 | + [TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_2]: { |
| 99 | + type: TokenType.synthetic, |
| 100 | + mailbox: chain2CoreAddress.mailbox, |
| 101 | + owner: HYP_DEPLOYER_ADDRESS_BY_PROTOCOL.radix, |
| 102 | + name: nativeTokenData.name, |
| 103 | + symbol: nativeTokenData.symbol, |
| 104 | + decimals: nativeTokenData.decimals, |
| 105 | + }, |
| 106 | + }; |
| 107 | + |
| 108 | + writeYamlOrJson(WARP_DEPLOY_PATH, warpDeployConfig); |
| 109 | + await hyperlaneWarp.deployRaw({ |
| 110 | + warpRouteId: WARP_ROUTE_ID, |
| 111 | + skipConfirmationPrompts: true, |
| 112 | + privateKey: HYP_KEY_BY_PROTOCOL.radix, |
| 113 | + }); |
| 114 | + }); |
| 115 | + |
| 116 | + it('should not update if there are no owner changes', async () => { |
| 117 | + const output = await hyperlaneWarp.applyRaw({ |
| 118 | + warpRouteId: WARP_ROUTE_ID, |
| 119 | + hypKey: HYP_KEY_BY_PROTOCOL.radix, |
| 120 | + }); |
| 121 | + |
| 122 | + expect(output.text()).to.include( |
| 123 | + 'Warp config is the same as target. No updates needed.', |
| 124 | + ); |
| 125 | + }); |
| 126 | + |
| 127 | + const testCases: { |
| 128 | + description: string; |
| 129 | + chain1TokenOwner: string; |
| 130 | + chain2TokenOwner: string; |
| 131 | + }[] = [ |
| 132 | + { |
| 133 | + description: 'should burn owner address on chain 1', |
| 134 | + chain1TokenOwner: BURN_ADDRESS_BY_PROTOCOL.radix, |
| 135 | + chain2TokenOwner: HYP_DEPLOYER_ADDRESS_BY_PROTOCOL.radix, |
| 136 | + }, |
| 137 | + { |
| 138 | + description: 'should burn owner address on chain 2', |
| 139 | + chain1TokenOwner: HYP_DEPLOYER_ADDRESS_BY_PROTOCOL.radix, |
| 140 | + chain2TokenOwner: BURN_ADDRESS_BY_PROTOCOL.radix, |
| 141 | + }, |
| 142 | + { |
| 143 | + description: 'should transfer ownership of all the tokens', |
| 144 | + chain1TokenOwner: BURN_ADDRESS_BY_PROTOCOL.radix, |
| 145 | + chain2TokenOwner: BURN_ADDRESS_BY_PROTOCOL.radix, |
| 146 | + }, |
| 147 | + ]; |
| 148 | + |
| 149 | + for (const { description, chain1TokenOwner, chain2TokenOwner } of testCases) { |
| 150 | + it(description, async function () { |
| 151 | + const expectedChain1TokenOwner: Address = chain1TokenOwner; |
| 152 | + const expectedChain2TokenOwner: Address = chain2TokenOwner; |
| 153 | + |
| 154 | + warpDeployConfig[TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_1].owner = |
| 155 | + chain1TokenOwner; |
| 156 | + warpDeployConfig[TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_2].owner = |
| 157 | + chain2TokenOwner; |
| 158 | + |
| 159 | + writeYamlOrJson(WARP_DEPLOY_PATH, warpDeployConfig); |
| 160 | + |
| 161 | + await hyperlaneWarp.applyRaw({ |
| 162 | + warpRouteId: WARP_ROUTE_ID, |
| 163 | + hypKey: HYP_KEY_BY_PROTOCOL.radix, |
| 164 | + }); |
| 165 | + |
| 166 | + await hyperlaneWarp.readRaw({ |
| 167 | + warpRouteId: WARP_ROUTE_ID, |
| 168 | + outputPath: WARP_READ_OUTPUT_PATH, |
| 169 | + }); |
| 170 | + |
| 171 | + const updatedWarpDeployConfig: DerivedWarpRouteDeployConfig = |
| 172 | + readYamlOrJson(WARP_READ_OUTPUT_PATH); |
| 173 | + |
| 174 | + expect( |
| 175 | + updatedWarpDeployConfig[TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_1] |
| 176 | + .owner, |
| 177 | + ).to.eq(expectedChain1TokenOwner); |
| 178 | + expect( |
| 179 | + updatedWarpDeployConfig[TEST_CHAIN_NAMES_BY_PROTOCOL.radix.CHAIN_NAME_2] |
| 180 | + .owner, |
| 181 | + ).to.eq(expectedChain2TokenOwner); |
| 182 | + }); |
| 183 | + } |
| 184 | +}); |
0 commit comments