Skip to content

Commit

Permalink
feat: improve warp route unit tests (#358)
Browse files Browse the repository at this point in the history
### Description

- add test for warp route ids
- ensure chain names are in alphabetical order
- ensure each chain name is in the registry
- ensure each token logoURI points to a valid path in registry

### Backward compatibility

### Testing

tests pass

---------

Signed-off-by: pbio <10051819+paulbalaji@users.noreply.github.com>
  • Loading branch information
paulbalaji authored Nov 5, 2024
1 parent 1483680 commit 094e425
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-spoons-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/registry': patch
---

Fix misnamed warp routes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
euphoriatesnet:
euphoriatestnet:
synthetic: "0x120f461C4d95412c4a1BC4e8BE6917C9da404510"
holesky:
collateral: "0x0bA0E052b993E8486AA8dab82c361404F7576573"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# yaml-language-server: $schema=../schema.json
tokens:
- addressOrDenom: "0x120f461C4d95412c4a1BC4e8BE6917C9da404510"
chainName: euphoriatesnet
chainName: euphoriatestnet
connections:
- token: ethereum|holesky|0x0bA0E052b993E8486AA8dab82c361404F7576573
decimals: 18
Expand All @@ -12,7 +12,7 @@ tokens:
chainName: holesky
collateralAddressOrDenom: "0x89C17409dc7222E378A433CE75DDd4dF8a1c4874"
connections:
- token: ethereum|euphoriatesnet|0x120f461C4d95412c4a1BC4e8BE6917C9da404510
- token: ethereum|euphoriatestnet|0x120f461C4d95412c4a1BC4e8BE6917C9da404510
decimals: 18
name: Aura Testing
standard: EvmHypCollateral
Expand Down
52 changes: 51 additions & 1 deletion test/unit/warp-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { expect } from 'chai';

import { MultiProtocolProvider, WarpCore } from '@hyperlane-xyz/sdk';
import { FileSystemRegistry } from '../../src/registry/FileSystemRegistry.js';
import { createWarpRouteConfigId, parseWarpRouteConfigId } from '../../src/registry/warp-utils.js';
import path from 'path';
import fs from 'fs';

describe('Warp Route Configs', () => {
const localRegistry = new FileSystemRegistry({ uri: './' });
const BASE_URI = './';
const localRegistry = new FileSystemRegistry({ uri: BASE_URI });
const chainMetadata = localRegistry.getMetadata();
const multiProvider = new MultiProtocolProvider(chainMetadata);
const routes = localRegistry.getWarpRoutes();
Expand All @@ -17,5 +21,51 @@ describe('Warp Route Configs', () => {
expect(warpCore).to.be.an.instanceOf(WarpCore);
expect(warpCore.tokens.length).to.be.greaterThan(0);
});

it(`Route ${id} has valid chain names`, () => {
const { chainNames } = parseWarpRouteConfigId(id);

// Verify each chain exists in registry
for (const chain of chainNames) {
expect(localRegistry.getChainMetadata(chain), `Chain ${chain} not found in registry`).to.not.be.null;
}
});

it(`Route ${id} has chain names in alphabetical order`, () => {
const { chainNames } = parseWarpRouteConfigId(id);

// Verify chains are in alphabetical order
const sortedChains = [...chainNames].sort();
expect(chainNames).to.deep.equal(sortedChains, 'Chain names must be in alphabetical order');
});

it(`Route ${id} has valid token logoURIs`, () => {
const config = routes[id];
config.tokens.forEach((token) => {
if (token.logoURI) {
expect(fs.existsSync(path.join(BASE_URI, token.logoURI)), `Logo file ${token.logoURI} not found`).to.be.true;
}
});
});

it(`Route ${id} matches derived id from config`, () => {
// Skip check on TIA/forma-stride to avoid breaking changes to forma
if (id === 'TIA/forma-stride') {
return;
}

// Get the symbol and chain names from the config
const config = routes[id];
const { chainNames } = parseWarpRouteConfigId(id);

// Create the ID from the config
const symbol = config.tokens[0].symbol;
const tokenChains = [...new Set(config.tokens.map((token) => token.chainName))];
const derivedId = createWarpRouteConfigId(symbol, tokenChains);
const { chainNames: derivedChainNames } = parseWarpRouteConfigId(derivedId);

// Verify the chain names match
expect(chainNames).to.deep.equal(derivedChainNames, 'Chain names in ID must match derived chain names');
});
}
});

0 comments on commit 094e425

Please sign in to comment.