Skip to content

Commit

Permalink
Update testnet preview matcher (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 authored Jun 28, 2024
1 parent 4de4b30 commit 25ae9b5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 54 deletions.
6 changes: 6 additions & 0 deletions npm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @penumbra-labs/registry

## 9.1.1

### Patch Changes

- Fix testnet-preview parsing

## 9.1.0

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@penumbra-labs/registry",
"version": "9.1.0",
"version": "9.1.1",
"description": "Chain and asset registry for Penumbra",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand All @@ -26,7 +26,7 @@
"tsup": "^8.1.0",
"typescript": "^5.5.2",
"typescript-eslint": "^7.14.1",
"vite": "^5.3.1",
"vite": "^5.3.2",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.6.0"
},
Expand Down
66 changes: 33 additions & 33 deletions npm/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion npm/src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('ChainRegistryClient', () => {
});

it('handles preview chain IDs by swapping them', () => {
const registry = client.get('penumbra-testnet-deimos-7-711be12a');
const registry = client.get('penumbra-testnet-deimos-7-xf2dbce94');
expect(registry).toBeInstanceOf(Registry);
expect(registry.chainId).toEqual('penumbra-testnet-deimos-7');
});
Expand Down
16 changes: 8 additions & 8 deletions npm/src/utils/testnet-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { deriveTestnetChainIdFromPreview, isTestnetPreviewChainId } from './test

describe('testnet-preview helper', () => {
it('should correctly identify testnet-preview chain-id', () => {
expect(isTestnetPreviewChainId('penumbra-testnet-deimos-6-711be12a')).toBeTruthy();
expect(isTestnetPreviewChainId('penumbra-testnet-deimos-222-711be12a')).toBeTruthy();
expect(isTestnetPreviewChainId('penumbra-testnet-rhea-8b2dfc5c')).toBeTruthy();
expect(isTestnetPreviewChainId('penumbra-testnet-tethy12-8777cb20')).toBeTruthy();
expect(isTestnetPreviewChainId('penumbra-testnet-deimos-8-xf2dbce94')).toBeTruthy();
expect(isTestnetPreviewChainId('penumbra-testnet-deimos-x0044bb22')).toBeTruthy();
expect(isTestnetPreviewChainId('penumbra-testnet-rhea-xff99ee10')).toBeTruthy();
expect(isTestnetPreviewChainId('penumbra-testnet-tethy12-xb4d8f9a0')).toBeTruthy();
});

it('should not identify chain-id as testnet-preview', () => {
Expand All @@ -16,13 +16,13 @@ describe('testnet-preview helper', () => {
});

it('should correctly derive testnet chain-id from testnet-preview chain-id', () => {
expect(deriveTestnetChainIdFromPreview('penumbra-testnet-deimos-6-711be12a')).toEqual(
'penumbra-testnet-deimos-6',
expect(deriveTestnetChainIdFromPreview('penumbra-testnet-deimos-8-xf2dbce94')).toEqual(
'penumbra-testnet-deimos-8',
);
expect(deriveTestnetChainIdFromPreview('penumbra-testnet-rhea-8b2dfc5c')).toEqual(
expect(deriveTestnetChainIdFromPreview('penumbra-testnet-rhea-x0044bb22')).toEqual(
'penumbra-testnet-rhea',
);
expect(deriveTestnetChainIdFromPreview('penumbra-testnet-tethys12-8777cb20')).toEqual(
expect(deriveTestnetChainIdFromPreview('penumbra-testnet-tethys12-xb4d8f9a0')).toEqual(
'penumbra-testnet-tethys12',
);
});
Expand Down
17 changes: 7 additions & 10 deletions npm/src/utils/testnet-parser.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
const TESTNET_PREVIEW_PATTERN = /^(penumbra-testnet-(?:\w+-)*\w+)-[a-f0-9]{8}$/;

export const isTestnetPreviewChainId = (chainId: string) => {
return TESTNET_PREVIEW_PATTERN.test(chainId);
// Test preview chain ids end with -x followed by a hexadecimal string
export const isTestnetPreviewChainId = (chainId: string): boolean => {
const previewRegex = /-x[0-9a-f]+$/i;
return previewRegex.test(chainId);
};

export const deriveTestnetChainIdFromPreview = (previewChainId: string): string | undefined => {
const match = previewChainId.match(TESTNET_PREVIEW_PATTERN);
if (match) {
return match[1];
}
return undefined;
export const deriveTestnetChainIdFromPreview = (previewChainId: string): string => {
const index = previewChainId.lastIndexOf('-x');
return previewChainId.substring(0, index);
};

0 comments on commit 25ae9b5

Please sign in to comment.