Skip to content

Commit

Permalink
Fix chain file regex and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy committed Apr 22, 2024
1 parent 415519b commit 049a67f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eight-apples-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/registry': patch
---

Fix chain file regex and add tests
2 changes: 1 addition & 1 deletion src/registry/BaseRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ChainMap, ChainMetadata, ChainName } from '@hyperlane-xyz/sdk';
import type { ChainAddresses, MaybePromise } from '../types.js';
import type { IRegistry, RegistryContent, RegistryType } from './IRegistry.js';

export const CHAIN_FILE_REGEX = /chains\/([a-z]+)\/([a-z0-9]+)\.yaml/;
export const CHAIN_FILE_REGEX = /chains\/([a-z0-9]+)\/([a-z]+)\.yaml/;

export abstract class BaseRegistry implements IRegistry {
abstract type: RegistryType;
Expand Down
9 changes: 9 additions & 0 deletions test/unit/registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';

import type { ChainMetadata } from '@hyperlane-xyz/sdk';
import { CHAIN_FILE_REGEX } from '../../src/registry/BaseRegistry.js';
import { GithubRegistry } from '../../src/registry/GithubRegistry.js';
import { LocalRegistry } from '../../src/registry/LocalRegistry.js';
import { ChainAddresses } from '../../src/types.js';
Expand Down Expand Up @@ -76,3 +77,11 @@ describe('Registry utilities', () => {
}).timeout(5_000);
}
});

describe('Registry regex', () => {
it('Matches chain file regex', () => {
expect(CHAIN_FILE_REGEX.test('chains/ethereum/metadata.yaml')).to.be.true;
expect(CHAIN_FILE_REGEX.test('chains/ancient8/addresses.yaml')).to.be.true;
expect(CHAIN_FILE_REGEX.test('chains/_NotAChain/addresses.yaml')).to.be.false;
});
});

0 comments on commit 049a67f

Please sign in to comment.