Skip to content

Commit

Permalink
update registry from npm dependency to use cdn hosted data
Browse files Browse the repository at this point in the history
  • Loading branch information
marshacb committed Nov 17, 2023
1 parent c259cd2 commit 3b45e58
Show file tree
Hide file tree
Showing 37 changed files with 4,406 additions and 171 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"dependencies": {
"@polkadot/api": "^10.9.1",
"@substrate/asset-transfer-api-registry": "^0.2.11"
"@substrate/asset-transfer-api-registry": "^0.2.11",
"node-fetch": "2.6.7"
}
}
34 changes: 10 additions & 24 deletions src/AssetTransferApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ import { mockSystemApi } from './testHelpers/mockSystemApi';
import { mockWeightInfo } from './testHelpers/mockWeightInfo';
import { Direction, UnsignedTransaction } from './types';
import { AssetType } from './types';
import { mockAssetRegistry } from './testHelpers/mockAssetRegistry';
import { Registry } from './registry';

const mockSubmittableExt = mockSystemApi.registry.createType(
'Extrinsic',
'0xfc041f0801010100411f0100010100c224aad9c6f3bbd784120e9fceee5bfd22a62c69144ee673f76d6a34d280de160104000002043205040091010000000000'
) as SubmittableExtrinsic<'promise', ISubmittableResult>;

const systemAssetsApi = new AssetTransferApi(adjustedMockSystemApi, 'statemine', 2);
const relayAssetsApi = new AssetTransferApi(adjustedMockRelayApi, 'kusama', 2);
const moonriverAssetsApi = new AssetTransferApi(adjustedMockMoonriverParachainApi, 'moonriver', 2);
const systemAssetsRegistry = new Registry('statemine', mockAssetRegistry);
const systemAssetsApi = new AssetTransferApi(adjustedMockSystemApi, 'statemine', 2, systemAssetsRegistry);

const relayAssetsRegistry = new Registry('kusama', mockAssetRegistry);
const relayAssetsApi = new AssetTransferApi(adjustedMockRelayApi, 'kusama', 2, relayAssetsRegistry);

const moonriverAssetsRegistry = new Registry('moonriver', mockAssetRegistry);
const moonriverAssetsApi = new AssetTransferApi(adjustedMockMoonriverParachainApi, 'moonriver', 2, moonriverAssetsRegistry);

describe('AssetTransferAPI', () => {
describe('establishDirection', () => {
Expand Down Expand Up @@ -357,27 +364,6 @@ describe('AssetTransferAPI', () => {
});
});

describe('Opts', () => {
it('Should correctly read in the injectedRegistry option', () => {
const injectedRegistry = {
polkadot: {
'9876': {
tokens: ['TST'],
assetsInfo: {},
foreignAssetsInfo: {},
specName: 'testing',
poolPairsInfo: {},
},
},
};
const mockSystemAssetsApi = new AssetTransferApi(adjustedMockSystemApi, 'statemine', 2, {
injectedRegistry,
});

expect(mockSystemAssetsApi._opts.injectedRegistry).toStrictEqual(injectedRegistry);
});
});

describe('fetchFeeInfo', () => {
it('Should correctly fetch estimate for submittable extrinsic xcm', async () => {
const submittableFeeInfo = await systemAssetsApi.fetchFeeInfo(mockSubmittableExt, 'submittable');
Expand Down
7 changes: 2 additions & 5 deletions src/AssetTransferApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import { Registry } from './registry';
import { sanitizeAddress } from './sanitize/sanitizeAddress';
import {
AssetCallType,
AssetTransferApiOpts,
AssetType,
ConstructedFormat,
Direction,
Expand Down Expand Up @@ -78,17 +77,15 @@ import { validateNumber } from './validate';
*/
export class AssetTransferApi {
readonly _api: ApiPromise;
readonly _opts: AssetTransferApiOpts;
readonly _specName: string;
readonly _safeXcmVersion: number;
readonly registry: Registry;

constructor(api: ApiPromise, specName: string, safeXcmVersion: number, opts: AssetTransferApiOpts = {}) {
constructor(api: ApiPromise, specName: string, safeXcmVersion: number, registry: Registry) {
this._api = api;
this._opts = opts;
this._specName = specName;
this._safeXcmVersion = safeXcmVersion;
this.registry = new Registry(specName, this._opts);
this.registry = registry;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { Registry } from '../../registry';
import { adjustedMockSystemApi } from '../../testHelpers/adjustedMockSystemApi';
import { Direction } from '../../types';
import { limitedReserveTransferAssets } from './limitedReserveTransferAssets';
import { mockAssetRegistry } from '../../testHelpers/mockAssetRegistry';

describe('limitedReserveTransferAssets', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);
describe('SystemToPara', () => {
const isLiquidTokenTransfer = false;
it('Should correctly construct a tx for a system parachain with V2', async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmCalls/polkadotXcm/limitedTeleportAssets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { Registry } from '../../registry';
import { mockSystemApi } from '../../testHelpers/mockSystemApi';
import { Direction } from '../../types';
import { limitedTeleportAssets } from './limitedTeleportAssets';
import { mockAssetRegistry } from '../../testHelpers/mockAssetRegistry';

describe('limitedTeleportAssets', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);
describe('SystemToPara', () => {
const isLiquidTokenTransfer = false;
it('Should correctly construct a tx for a system parachain with V2', async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmCalls/polkadotXcm/reserveTransferAssets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { Registry } from '../../registry';
import { adjustedMockSystemApi } from '../../testHelpers/adjustedMockSystemApi';
import { Direction } from '../../types';
import { reserveTransferAssets } from './reserveTransferAssets';
import { mockAssetRegistry } from '../../testHelpers/mockAssetRegistry';

describe('reserveTransferAssets', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);
describe('SystemToPara', () => {
const isLiquidTokenTransfer = false;
it('Should correctly construct a tx for a system parachain with V2', async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmCalls/polkadotXcm/teleportAssets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { Registry } from '../../registry';
import { mockSystemApi } from '../../testHelpers/mockSystemApi';
import { Direction } from '../../types';
import { teleportAssets } from './teleportAssets';
import { mockAssetRegistry } from '../../testHelpers/mockAssetRegistry';

describe('teleportAssets', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);
describe('SystemToPara', () => {
const isLiquidTokenTransfer = false;
it('Should correctly construct a tx for a system parachain with V2', async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmCalls/xTokens/transferMultiAsset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { adjustedMockMoonriverParachainApi } from '../../testHelpers/adjustedMoc
import { Direction } from '../../types';
import { XcmPalletName } from '../util/establishXcmPallet';
import { transferMultiasset } from './transferMultiasset';
import { mockAssetRegistry } from '../../testHelpers/mockAssetRegistry';

describe('transferMultiasset', () => {
describe('ParaToSystem', () => {
const registry = new Registry('moonriver', {});
const registry = new Registry('moonriver', mockAssetRegistry);

it('Should correctly construct an Unlimited transferMultiasset tx for V2', async () => {
const ext = await transferMultiasset(
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmCalls/xTokens/transferMultiAssetWithFee.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { adjustedMockMoonriverParachainApi } from '../../testHelpers/adjustedMoc
import { Direction } from '../../types';
import { XcmPalletName } from '../util/establishXcmPallet';
import { transferMultiassetWithFee } from './transferMultiassetWithFee';
import { mockAssetRegistry } from '../../testHelpers/mockAssetRegistry';

describe('transferMultiassetWithFee', () => {
describe('ParaToSystem', () => {
const registry = new Registry('moonriver', {});
const registry = new Registry('moonriver', mockAssetRegistry);

it('Should correctly construct an Unlimited transferMultiassetWithFee tx for V2', async () => {
const isLimited = false;
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmCalls/xTokens/transferMultiAssets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { adjustedMockMoonriverParachainApi } from '../../testHelpers/adjustedMoc
import { Direction } from '../../types';
import { XcmPalletName } from '../util/establishXcmPallet';
import { transferMultiassets } from './transferMultiassets';
import { mockAssetRegistry } from '../../testHelpers/mockAssetRegistry';

describe('transferMultiassets', () => {
describe('ParaToSystem', () => {
const registry = new Registry('moonriver', {});
const registry = new Registry('moonriver', mockAssetRegistry);

it('Should correctly construct an Unlimited transferMultiassets tx for V2', async () => {
const isLimited = false;
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmTypes/ParaToPara.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import { Registry } from '../registry';
import { mockMoonriverParachainApi } from '../testHelpers/mockMoonriverParachainApi';
import { ParaToPara } from './ParaToPara';
import { mockAssetRegistry } from '../testHelpers/mockAssetRegistry';

describe('ParaToPara', () => {
const registry = new Registry('kusama', {});
const registry = new Registry('kusama', mockAssetRegistry);
describe('Beneficiary', () => {
it('Should work for V2', () => {
const beneficiary = ParaToPara.createBeneficiary(
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmTypes/ParaToRelay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import { Registry } from '../registry';
import { adjustedMockMoonriverParachainApi } from '../testHelpers/adjustedMockMoonriverParachainApi';
import { ParaToRelay } from './ParaToRelay';
import { mockAssetRegistry } from '../testHelpers/mockAssetRegistry';

describe('ParaToRelay', () => {
const registry = new Registry('Moonriver', {});
const registry = new Registry('Moonriver', mockAssetRegistry);
const assetOpts = {
registry,
isLiquidTokenTransfer: false,
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmTypes/ParaToSystem.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import { Registry } from '../registry';
import { mockMoonriverParachainApi } from '../testHelpers/mockMoonriverParachainApi';
import { ParaToSystem } from './ParaToSystem';
import { mockAssetRegistry } from '../testHelpers/mockAssetRegistry';

describe('ParaToSystem', () => {
const registry = new Registry('kusama', {});
const registry = new Registry('kusama', mockAssetRegistry);
describe('Beneficiary', () => {
it('Should work for V2', () => {
const beneficiary = ParaToSystem.createBeneficiary(
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmTypes/RelayToPara.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import { Registry } from '../registry';
import { mockRelayApi } from '../testHelpers/mockRelayApi';
import { RelayToPara } from './RelayToPara';
import { mockAssetRegistry } from '../testHelpers/mockAssetRegistry';

describe('RelayToPara XcmVersioned Generation', () => {
const registry = new Registry('kusama', {});
const registry = new Registry('kusama', mockAssetRegistry);
describe('Beneficiary', () => {
it('Should work for V2', () => {
const beneficiary = RelayToPara.createBeneficiary(
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmTypes/RelayToSystem.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import { Registry } from '../registry';
import { mockRelayApi } from '../testHelpers/mockRelayApi';
import { RelayToSystem } from './RelayToSystem';
import { mockAssetRegistry } from '../testHelpers/mockAssetRegistry';

describe('RelayToSystem XcmVersioned Generation', () => {
const registry = new Registry('kusama', {});
const registry = new Registry('kusama', mockAssetRegistry);
describe('Beneficiary', () => {
it('Should work for V2', () => {
const beneficiary = RelayToSystem.createBeneficiary(
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmTypes/SystemToPara.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { mockSystemApi } from '../testHelpers/mockSystemApi';
import { SystemToPara } from './SystemToPara';
import { createSystemToParaMultiAssets } from './SystemToPara';
import { FungibleStrMultiAsset } from './types';
import { mockAssetRegistry } from '../testHelpers/mockAssetRegistry';

describe('SystemToPara XcmVersioned Generation', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);
describe('Beneficiary', () => {
it('Should work for V2', () => {
const beneficiary = SystemToPara.createBeneficiary(
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmTypes/SystemToRelay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import { Registry } from '../registry';
import { mockSystemApi } from '../testHelpers/mockSystemApi';
import { SystemToRelay } from './SystemToRelay';
import { mockAssetRegistry } from '../testHelpers/mockAssetRegistry';

describe('SystemToRelay XcmVersioned Generation', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);

describe('Beneficiary', () => {
it('Should work for V2', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmTypes/SystemToSystem.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import { Registry } from '../registry';
import { mockSystemApi } from '../testHelpers/mockSystemApi';
import { SystemToSystem } from './SystemToSystem';
import { mockAssetRegistry } from '../testHelpers/mockAssetRegistry';

describe('SystemToSystem XcmVersioned Generation', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);

describe('Beneficiary', () => {
it('Should work for V2', () => {
Expand Down
11 changes: 6 additions & 5 deletions src/createXcmTypes/util/assetIdsContainsRelayAsset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@

import { Registry } from '../../registry';
import { assetIdsContainRelayAsset } from './assetIdsContainsRelayAsset';
import { mockAssetRegistry } from '../../testHelpers/mockAssetRegistry';

describe('assetIdsContainsRelayAsset', () => {
it('Should return true when assetIds contains relay chain symbol', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);
const assetIds = ['ksm', 'usdt', 'usdc'];

const result = assetIdsContainRelayAsset(assetIds, registry);

expect(result).toEqual(true);
});
it('Should return true when assetIds is an empty array', () => {
const registry = new Registry('statemint', {});
const registry = new Registry('statemint', mockAssetRegistry);
const assetIds = ['dot', 'usdt', 'usdc'];

const result = assetIdsContainRelayAsset(assetIds, registry);

expect(result).toEqual(true);
});
it('Should return true when assetIds contains the relay assets multilocation', () => {
const registry = new Registry('asset-hub-polkadot', {});
const registry = new Registry('asset-hub-polkadot', mockAssetRegistry);
const assetIds = [
`{"parents": 1, "interior": {"Here": ''}}`,
`{"parents": 1, interior: {"X1": {"Parachain": "2023"}}}`,
Expand All @@ -32,15 +33,15 @@ describe('assetIdsContainsRelayAsset', () => {
expect(result).toEqual(true);
});
it('Should return false when assetIds does not contain the relay assets multilocation', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);
const assetIds = [`{"parents": 1, interior: {"X1": {"Parachain": "2023"}}}`];

const result = assetIdsContainRelayAsset(assetIds, registry);

expect(result).toEqual(false);
});
it('Should return false when assetIds does not contain the relay assets symbol', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);
const assetIds = ['usdc', 'usdt'];

const result = assetIdsContainRelayAsset(assetIds, registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import { Registry } from '../../registry';
import { foreignAssetMultiLocationIsInCacheOrRegistry } from './foreignAssetMultiLocationIsInCacheOrRegistry';
import { mockAssetRegistry } from '../../testHelpers/mockAssetRegistry';

describe('foreignAssetMultiLocationIsInCacheOrRegistry', () => {
it('Should return true if a given foreign asset multilocation exists in the asset api registry', () => {
const expected = true;
const multiLocation = '{"parents":1,"interior":{ "X2":[{"Parachain":2125},{"GeneralIndex":0}]}}';
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);

const foreignAssetExistsInRegistry = foreignAssetMultiLocationIsInCacheOrRegistry(multiLocation, registry, 2);

Expand All @@ -17,7 +18,7 @@ describe('foreignAssetMultiLocationIsInCacheOrRegistry', () => {
it('Should return false if a given foreign asset multilocation does not exist in the asset api registry', () => {
const expected = false;
const multiLocation = '{"parents":"1","interior":{"X1": {"Parachain":"200100510"}}}';
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);

const foreignAssetExistsInRegistry = foreignAssetMultiLocationIsInCacheOrRegistry(multiLocation, registry, 2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import { Registry } from '../../registry';
import { adjustedMockSystemApi } from '../../testHelpers/adjustedMockSystemApi';
import { foreignAssetsMultiLocationExists } from './foreignAssetsMultiLocationExists';
import { mockAssetRegistry } from '../../testHelpers/mockAssetRegistry';
import { ChainInfoRegistry } from 'src/registry/types';

describe('foreignMultiAssetMultiLocationExists', () => {
const registry = new Registry('statemine', {});
const registry = new Registry('statemine', mockAssetRegistry);

it('Should return true for an existing foreign asset multilocation', async () => {
const expected = true;
Expand Down Expand Up @@ -57,7 +59,7 @@ describe('foreignMultiAssetMultiLocationExists', () => {
},
},
},
});
} as unknown as ChainInfoRegistry);
const multiLocation = '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}';

await foreignAssetsMultiLocationExists(adjustedMockSystemApi, emptyRegistry, multiLocation, 2);
Expand Down
Loading

0 comments on commit 3b45e58

Please sign in to comment.