Skip to content

Commit

Permalink
fix: hyperlane warp send out of order for --origin --destination (#5131)
Browse files Browse the repository at this point in the history
### Description
Fix ordering issue where --origin and --destination are sent out of
order. For example, when --origin is zircuit, and --destination is
ethereum, `warp send` will send from origin ethereum to destination
zircuit.

### Testing
Manual/Unit Tests
  • Loading branch information
ltyu authored Jan 9, 2025
1 parent 350ae79 commit 2d018fa
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-starfishes-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': minor
---

Fix hyperlane warp send where --origin and --destination are out of order
9 changes: 7 additions & 2 deletions typescript/cli/src/commands/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { stringify as yamlStringify } from 'yaml';
import { CommandModule } from 'yargs';

import { ChainName, ChainSubmissionStrategySchema } from '@hyperlane-xyz/sdk';
import { objFilter } from '@hyperlane-xyz/utils';
import { assert, objFilter } from '@hyperlane-xyz/utils';

import { runWarpRouteCheck } from '../check/warp.js';
import {
Expand Down Expand Up @@ -309,7 +309,12 @@ const send: CommandModuleWithWriteContext<
'Select the destination chain:',
);

chains = chains.filter((c) => c === origin || c === destination);
chains = [origin, destination].filter((c) => chains.includes(c));

assert(
chains.length === 2,
`Origin (${origin}) or destination (${destination}) are not part of the warp route.`,
);
}

logBlue(`🚀 Sending a message for chains: ${chains.join(' ➡️ ')}`);
Expand Down
51 changes: 50 additions & 1 deletion typescript/cli/src/tests/warp-deploy.e2e-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import {
deployToken,
sendWarpRouteMessageRoundTrip,
} from './commands/helpers.js';
import { hyperlaneWarpDeploy, readWarpConfig } from './commands/warp.js';
import {
hyperlaneWarpDeploy,
hyperlaneWarpSendRelay,
readWarpConfig,
} from './commands/warp.js';

chai.use(chaiAsPromised);
const expect = chai.expect;
Expand Down Expand Up @@ -198,4 +202,49 @@ describe('hyperlane warp deploy e2e tests', async function () {
normalizeConfig(hook),
);
});

it('should send a message from origin to destination in the correct order', async function () {
const warpConfig: WarpRouteDeployConfig = {
[CHAIN_NAME_2]: {
type: TokenType.collateralVaultRebase,
token: vault.address,
mailbox: chain2Addresses.mailbox,
owner: chain2Addresses.mailbox,
},
[CHAIN_NAME_3]: {
type: TokenType.syntheticRebase,
mailbox: chain3Addresses.mailbox,
owner: chain3Addresses.mailbox,
collateralChainName: CHAIN_NAME_2,
},
};

writeYamlOrJson(WARP_CONFIG_PATH, warpConfig);
await hyperlaneWarpDeploy(WARP_CONFIG_PATH);

// Try to send a transaction with the origin destination
const { stdout: chain2Tochain3Stdout } = await hyperlaneWarpSendRelay(
CHAIN_NAME_2,
CHAIN_NAME_3,
WARP_CORE_CONFIG_PATH_2_3,
);
expect(chain2Tochain3Stdout).to.include('anvil2 ➡️ anvil3');

// Send another message with swapped origin destination
const { stdout: chain3Tochain2Stdout } = await hyperlaneWarpSendRelay(
CHAIN_NAME_3,
CHAIN_NAME_2,
WARP_CORE_CONFIG_PATH_2_3,
);
expect(chain3Tochain2Stdout).to.include('anvil3 ➡️ anvil2');

// Should throw if invalid origin or destination
await hyperlaneWarpSendRelay(
'anvil1',
CHAIN_NAME_3,
WARP_CORE_CONFIG_PATH_2_3,
).should.be.rejectedWith(
'Error: Origin (anvil1) or destination (anvil3) are not part of the warp route.',
);
});
});

0 comments on commit 2d018fa

Please sign in to comment.