Skip to content

Commit

Permalink
Fix chain metadata parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy committed Dec 19, 2023
1 parent 7f9d789 commit 07094a1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"[typescript]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand Down
11 changes: 5 additions & 6 deletions src/features/chains/chainConfig.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { z } from 'zod';

import { ChainMetadata, ChainMetadataSchema, MultiProvider } from '@hyperlane-xyz/sdk';
import { ChainMetadata, ChainMetadataSchemaObject, MultiProvider } from '@hyperlane-xyz/sdk';

import { logger } from '../../utils/logger';

export const ChainConfigSchema = z.record(
ChainMetadataSchema.and(
z.object({ mailbox: z.string().optional(), interchainGasPaymaster: z.string().optional() }),
),
);
export const ChainConfigSchema = ChainMetadataSchemaObject.extend({
mailbox: z.string().optional(),
interchainGasPaymaster: z.string().optional(),
});

export type ChainConfig = ChainMetadata & { mailbox?: Address; interchainGasPaymaster?: Address };

Expand Down
29 changes: 29 additions & 0 deletions src/features/chains/chainconfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { tryParseChainConfig } from './chainConfig';

const validConfig = {
chainId: 12345,
name: 'mytestnet',
protocol: 'ethereum',
rpcUrls: [{ http: 'https://fakerpc.com' }],
blockExplorers: [
{
name: 'FakeScan',
family: 'other',
url: 'https://fakeexplorer.com',
apiUrl: 'https://fakeexplorer.com',
},
],
blocks: { confirmations: 1, estimateBlockTime: 10 },
mailbox: '0x14999bccB37118713891DAAA1D5959a02E206C1f',
};

describe('chain configs', () => {
it('parses valid config', async () => {
const result = tryParseChainConfig(JSON.stringify(validConfig));
expect(result.success).toBe(true);
});
it('rejects invalid config', async () => {
const result = tryParseChainConfig(JSON.stringify({ ...validConfig, chainId: undefined }));
expect(result.success).toBe(false);
});
});

0 comments on commit 07094a1

Please sign in to comment.