Skip to content

Commit

Permalink
fix(bug): added support for checkMetadataHash SignedExtension (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
bee344 authored Jul 3, 2024
1 parent c02d5bd commit 36d4318
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 195 deletions.
7 changes: 4 additions & 3 deletions src/AssetTransferApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { adjustedMockMoonriverNoXTokensParachainApi } from './testHelpers/adjust
import { adjustedMockRelayApiNoLimitedReserveTransferAssets } from './testHelpers/adjustedMockRelayApiNoLimitedReserveTransferAssets';
import { adjustedMockRelayApi } from './testHelpers/adjustedMockRelayApiV9420';
import { adjustedMockSystemApi } from './testHelpers/adjustedMockSystemApiV1004000';
import { adjustedMockSystemApiV1011000 } from './testHelpers/adjustedMockSystemApiV1011000';
import { adjustedMockSystemApiV1014000 } from './testHelpers/adjustedMockSystemApiV1014000';
import { mockSystemApi } from './testHelpers/mockSystemApi';
import { mockWeightInfo } from './testHelpers/mockWeightInfo';
import { AssetCallType, Direction, ResolvedCallInfo, UnsignedTransaction, XcmBaseArgs, XcmDirection } from './types';
Expand Down Expand Up @@ -50,7 +50,7 @@ const bifrostAssetsApi = new AssetTransferApi(adjustedMockBifrostParachainApi, '
const moonriverAssetsNoXTokensApi = new AssetTransferApi(adjustedMockMoonriverNoXTokensParachainApi, 'moonriver', 2, {
registryType: 'NPM',
});
const westmintAssetsApi = new AssetTransferApi(adjustedMockSystemApiV1011000, 'westmint', 4, {
const westmintAssetsApi = new AssetTransferApi(adjustedMockSystemApiV1014000, 'westmint', 4, {
registryType: 'NPM',
});

Expand Down Expand Up @@ -181,7 +181,7 @@ describe('AssetTransferAPI', () => {
);
expect(res.format).toEqual('payload');
expect(res.tx.toHex()).toEqual(
'0xf81f0801010100411f0100010100c224aad9c6f3bbd784120e9fceee5bfd22a62c69144ee673f76d6a34d280de16010400000204320504009101000000000045022800010000cc240000040000000000000000000000000000000000000000000000000000000000000000000000be2554aa8a0151eb4d706308c47d16996af391e4c5e499c7cbef24259b7d4503',
'0xf81f0801010100411f0100010100c224aad9c6f3bbd784120e9fceee5bfd22a62c69144ee673f76d6a34d280de16010400000204320504009101000000000045022800010000e0510f00040000000000000000000000000000000000000000000000000000000000000000000000be2554aa8a0151eb4d706308c47d16996af391e4c5e499c7cbef24259b7d4503',
);
});
it('Should construct the correct submittable', async () => {
Expand Down Expand Up @@ -638,6 +638,7 @@ describe('AssetTransferAPI', () => {
format: 'payload',
keepAlive: true,
sendersAddr: 'FBeL7DanUDs5SZrxZY1CizMaPgG9vZgJgvr52C2dg81SsF1',
paysWithFeeOrigin: '1984',
},
);

Expand Down
3 changes: 3 additions & 0 deletions src/AssetTransferApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,9 @@ export class AssetTransferApi {
blockNumber: blockNumber.toHex(),
era: era.toHex(),
genesisHash: this.api.genesisHash.toHex(),
metadataHash: null,
method: method.toHex(),
mode: this.api.registry.createType('u8', 0).toHex(),
nonce: nonce.toHex(),
signedExtensions: [
'CheckNonZeroSender',
Expand All @@ -811,6 +813,7 @@ export class AssetTransferApi {
'CheckNonce',
'CheckWeight',
'ChargeAssetTxPayment',
'CheckMetadataHash',
],
tip: this.api.registry.createType('Compact<Balance>', 0).toHex(),
version: tx.version,
Expand Down
8 changes: 4 additions & 4 deletions src/createXcmCalls/polkadotXcm/claimAssets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Registry } from '../../registry';
import { adjustedMockSystemApi } from '../../testHelpers/adjustedMockSystemApiV1004000';
import { adjustedMockSystemApiV1011000 } from '../../testHelpers/adjustedMockSystemApiV1011000';
import { adjustedMockSystemApiV1014000 } from '../../testHelpers/adjustedMockSystemApiV1014000';
import { claimAssets } from './claimAssets';

describe('claimAssets', () => {
Expand All @@ -16,7 +16,7 @@ describe('claimAssets', () => {
const beneficiaryAddress = '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b';

const ext = await claimAssets(
adjustedMockSystemApiV1011000,
adjustedMockSystemApiV1014000,
registry,
specName,
assetIds,
Expand All @@ -41,7 +41,7 @@ describe('claimAssets', () => {
const beneficiaryAddress = '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b';

const ext = await claimAssets(
adjustedMockSystemApiV1011000,
adjustedMockSystemApiV1014000,
registry,
specName,
assets,
Expand All @@ -66,7 +66,7 @@ describe('claimAssets', () => {
const beneficiaryAddress = '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b';

const ext = await claimAssets(
adjustedMockSystemApiV1011000,
adjustedMockSystemApiV1014000,
registry,
specName,
assets,
Expand Down
6 changes: 3 additions & 3 deletions src/createXcmCalls/polkadotXcm/transferAssets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { ApiPromise } from '@polkadot/api';

import { Registry } from '../../registry';
import { adjustedMockSystemApiV1011000 } from '../../testHelpers/adjustedMockSystemApiV1011000';
import { adjustedMockSystemApiV1014000 } from '../../testHelpers/adjustedMockSystemApiV1014000';
import { adjustedMockWestendRelayApiV1007001 } from '../../testHelpers/adjustedMockWestendRelayApiV1007001';
import { Direction, XcmBaseArgs, XcmDirection } from '../../types';
import { transferAssets } from './transferAssets';
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('transferAssets', () => {

const isLiquidTokenTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
direction: Direction.SystemToRelay as XcmDirection,
destAddr: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
assetIds: ['wnd'],
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('transferAssets', () => {

const isLiquidTokenTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
direction: Direction.SystemToPara as XcmDirection,
destAddr: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
assetIds: ['1'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Parity Technologies (UK) Ltd.

import { Registry } from '../../registry';
import { adjustedMockSystemApiV1011000 } from '../../testHelpers/adjustedMockSystemApiV1011000';
import { adjustedMockSystemApiV1014000 } from '../../testHelpers/adjustedMockSystemApiV1014000';
import { Direction, XcmBaseArgs, XcmDirection } from '../../types';
import { transferAssetsUsingTypeAndThen } from './transferAssetsUsingTypeAndThen';

Expand All @@ -12,7 +12,7 @@ describe('transferAssetsUsingTypeAndThen', () => {
const registry = new Registry('asset-hub-rococo', {});
const isLiquidTokenTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
direction: Direction.SystemToBridge as XcmDirection,
destAddr: '0x6E733286C3Dc52C67b8DAdFDd634eD9c3Fb05B5B',
assetIds: [
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('transferAssetsUsingTypeAndThen', () => {
const registry = new Registry('asset-hub-rococo', {});
const isLiquidTokenTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
direction: Direction.SystemToBridge as XcmDirection,
destAddr: '0x6E733286C3Dc52C67b8DAdFDd634eD9c3Fb05B5B',
assetIds: [
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('transferAssetsUsingTypeAndThen', () => {
const registry = new Registry('asset-hub-westend', {});
const isLiquidTokenTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
direction: Direction.SystemToBridge as XcmDirection,
destAddr: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
assetIds: [
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('transferAssetsUsingTypeAndThen', () => {
const registry = new Registry('asset-hub-westend', {});
const isLiquidTokenTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
direction: Direction.SystemToBridge as XcmDirection,
destAddr: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
assetIds: [
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('transferAssetsUsingTypeAndThen', () => {
const registry = new Registry('asset-hub-rococo', {});
const isLiquidTokenTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
direction: Direction.SystemToBridge as XcmDirection,
destAddr: '0x6E733286C3Dc52C67b8DAdFDd634eD9c3Fb05B5B',
assetIds: [
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('transferAssetsUsingTypeAndThen', () => {
const registry = new Registry('asset-hub-westend', {});
const isLiquidTokenTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
direction: Direction.SystemToBridge as XcmDirection,
destAddr: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
assetIds: [
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('transferAssetsUsingTypeAndThen', () => {
const registry = new Registry('asset-hub-westend', {});
const isLiquidTokenTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
direction: Direction.SystemToBridge as XcmDirection,
destAddr: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
assetIds: [
Expand Down
6 changes: 3 additions & 3 deletions src/createXcmTypes/RelayToBridge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Parity Technologies (UK) Ltd.

import { Registry } from '../registry';
import { adjustedMockSystemApiV1011000 } from '../testHelpers/adjustedMockSystemApiV1011000';
import { adjustedMockSystemApiV1014000 } from '../testHelpers/adjustedMockSystemApiV1014000';
import { RelayToBridge } from './RelayToBridge';

describe('RelayToBridge', () => {
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('RelayToBridge', () => {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
},
);

Expand Down Expand Up @@ -183,7 +183,7 @@ describe('RelayToBridge', () => {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
},
);

Expand Down
6 changes: 3 additions & 3 deletions src/createXcmTypes/SystemToBridge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Parity Technologies (UK) Ltd.

import { Registry } from '../registry';
import { adjustedMockSystemApiV1011000 } from '../testHelpers/adjustedMockSystemApiV1011000';
import { adjustedMockSystemApiV1014000 } from '../testHelpers/adjustedMockSystemApiV1014000';
import { SystemToBridge } from './SystemToBridge';

describe('SystemToBridge', () => {
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('SystemToBridge', () => {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
},
);

Expand Down Expand Up @@ -185,7 +185,7 @@ describe('SystemToBridge', () => {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api: adjustedMockSystemApiV1011000,
api: adjustedMockSystemApiV1014000,
},
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2024 Parity Technologies (UK) Ltd.

import { AssetTransferApi } from '../../AssetTransferApi';
import { adjustedMockSystemApiV1011000 } from '../../testHelpers/adjustedMockSystemApiV1011000';
import { adjustedMockSystemApiV1014000 } from '../../testHelpers/adjustedMockSystemApiV1014000';
import { getPaysWithFeeOriginAssetLocationFromRegistry } from './getPaysWithFeeOriginAssetLocationFromRegistry';

describe('getPaysWithFeeOriginAssetLocationFromRegistry', () => {
const assetHubAPI = new AssetTransferApi(adjustedMockSystemApiV1011000, 'asset-hub-westend', 4, {
const assetHubAPI = new AssetTransferApi(adjustedMockSystemApiV1014000, 'asset-hub-westend', 4, {
registryType: 'NPM',
});

Expand Down
Loading

0 comments on commit 36d4318

Please sign in to comment.