Skip to content

Commit

Permalink
fix: rococo initialization in the registry
Browse files Browse the repository at this point in the history
  • Loading branch information
TarikGul committed Sep 26, 2023
1 parent 3a99049 commit c002bbe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const SYSTEM_PARACHAINS_NAMES = [
export const POLKADOT_ASSET_HUB_SPEC_NAMES = ['statemint', 'asset-hub-polkadot'];
export const KUSAMA_ASSET_HUB_SPEC_NAMES = ['statemine', 'asset-hub-kusama'];
export const WESTEND_ASSET_HUB_SPEC_NAMES = ['westmint', 'asset-hub-westend'];
// Rococo's asset hub is currently labeled as `statemine` within our registry.
// There I put both names a recognizable just in case it changes in polkadot-js.
export const ROCOCO_ASSET_HUB_SPEC_NAME = ['rococo', 'statemine', 'asset-hub-rococo'];

/**
* The default xcm version to construct a xcm message.
Expand Down
6 changes: 6 additions & 0 deletions src/registry/Registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import type { ForeignAssetsData } from './types';

describe('Registry', () => {
const registry = new Registry('polkadot', {});
describe('initialization', () => {
it('Should initalize rococo correctly', () => {
const registry = new Registry('rococo', {});
expect(registry.relayChain).toEqual('rococo');
});
});
describe('lookupTokenSymbol', () => {
it('Should return the correct result', () => {
const res = registry.lookupTokenSymbol('GLMR');
Expand Down
12 changes: 11 additions & 1 deletion src/registry/findRelayChain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { KUSAMA_ASSET_HUB_SPEC_NAMES, POLKADOT_ASSET_HUB_SPEC_NAMES, WESTEND_ASSET_HUB_SPEC_NAMES } from '../consts';
import {
KUSAMA_ASSET_HUB_SPEC_NAMES,
POLKADOT_ASSET_HUB_SPEC_NAMES,
ROCOCO_ASSET_HUB_SPEC_NAME,
WESTEND_ASSET_HUB_SPEC_NAMES,
} from '../consts';
import { BaseError, BaseErrorsEnum } from '../errors';
import type { ChainInfoRegistry, RelayChains } from './types';
/**
Expand All @@ -21,5 +26,10 @@ export const findRelayChain = (specName: string, registry: ChainInfoRegistry): R
if (westendChains.includes(specName.toLowerCase()) || WESTEND_ASSET_HUB_SPEC_NAMES.includes(specName.toLowerCase()))
return 'westend';

const rococoChains = Object.keys(registry.rococo).map((val) => registry.rococo[val].specName);
if (rococoChains.includes(specName.toLowerCase()) || ROCOCO_ASSET_HUB_SPEC_NAME) {
return 'rococo';
}

throw new BaseError(`Cannot find the relay chain for specName: ${specName}`, BaseErrorsEnum.InternalError);
};

0 comments on commit c002bbe

Please sign in to comment.