From adaedeeb46aa9f94e8898f80ee2ed8fc37b11b74 Mon Sep 17 00:00:00 2001 From: Elmar Kenigs Date: Tue, 12 Mar 2024 16:59:11 +0200 Subject: [PATCH] Fixed and added unit test --- .../builder/fixtures/builderParamsMock.ts | 11 ++ .../__snapshots__/polkadotXcm.test.ts.snap | 108 +++++++++++++++++- .../pallets/polkadotXcm/polkadotXcm.test.ts | 36 ++++-- .../pallets/polkadotXcm/polkadotXcm.ts | 3 +- 4 files changed, 145 insertions(+), 13 deletions(-) diff --git a/packages/builder/fixtures/builderParamsMock.ts b/packages/builder/fixtures/builderParamsMock.ts index adcdaa22..8c408b18 100644 --- a/packages/builder/fixtures/builderParamsMock.ts +++ b/packages/builder/fixtures/builderParamsMock.ts @@ -54,6 +54,17 @@ export const buildParamsMock: ExtrinsicConfigBuilderPrams = { source: alphanetAssetHubMock, }; +export const buildParamsSameAssetMock: ExtrinsicConfigBuilderPrams = { + address: '0xeF46c7649270C912704fB09B75097f6E32208b85', + amount: 99_000_000_000n, + asset: 'USDT', + destination: moonbaseAlphaMock, + fee: 5_000_000_000n, + feeAsset: 'USDT', + palletInstance: 10, + source: alphanetAssetHubMock, +}; + export const buildParachainParamsMock: ExtrinsicConfigBuilderPrams = { address: 'wd84XqsQ4LVzhmTBVd4s5ApGt9sBnnk8K7Q5PhBwwhxwqgm1u', amount: 99_000_000_000n, diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap b/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap index 28783af1..7b45c1e8 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap @@ -109,9 +109,29 @@ exports[`polkadotXcm limitedReserveTransferAssets parachain should get correct a }, }, }, + { + "fun": { + "Fungible": 5000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "PalletInstance": 10, + }, + { + "GeneralIndex": "RMRK", + }, + ], + }, + "parents": 0, + }, + }, + }, ], }, - 0, + 1, "Unlimited", ] `; @@ -173,7 +193,89 @@ exports[`polkadotXcm limitedReserveTransferAssets x1 should get correct argument ] `; -exports[`polkadotXcm limitedReserveTransferAssets x2 should be correct config 1`] = ` +exports[`polkadotXcm limitedReserveTransferAssets x2 different assets should be correct config 1`] = ` +ExtrinsicConfig { + "func": "limitedReserveTransferAssets", + "getArgs": [Function], + "module": "polkadotXcm", + "type": "Substrate", +} +`; + +exports[`polkadotXcm limitedReserveTransferAssets x2 different assets should get correct arguments 1`] = ` +[ + { + "V1": { + "interior": { + "X1": { + "Parachain": 1000, + }, + }, + "parents": 1, + }, + }, + { + "V1": { + "interior": { + "X1": { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + }, + "parents": 0, + }, + }, + { + "V1": [ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "PalletInstance": 10, + }, + { + "GeneralIndex": "USDT", + }, + ], + }, + "parents": 0, + }, + }, + }, + { + "fun": { + "Fungible": 5000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "PalletInstance": 10, + }, + { + "GeneralIndex": "RMRK", + }, + ], + }, + "parents": 0, + }, + }, + }, + ], + }, + 1, + "Unlimited", +] +`; + +exports[`polkadotXcm limitedReserveTransferAssets x2 the same asset should be correct config 1`] = ` ExtrinsicConfig { "func": "limitedReserveTransferAssets", "getArgs": [Function], @@ -182,7 +284,7 @@ ExtrinsicConfig { } `; -exports[`polkadotXcm limitedReserveTransferAssets x2 should get correct arguments 1`] = ` +exports[`polkadotXcm limitedReserveTransferAssets x2 the same asset should get correct arguments 1`] = ` [ { "V1": { diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts index 62dab60e..4ad917b3 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts @@ -1,6 +1,7 @@ import { buildParachainParamsMock, buildParamsMock, + buildParamsSameAssetMock, } from '../../../../fixtures'; import { polkadotXcm } from './polkadotXcm'; @@ -37,17 +38,34 @@ describe('polkadotXcm', () => { }); describe('x2', () => { - const extrinsic = polkadotXcm() - .limitedReserveTransferAssets() - .X2() - .build(buildParamsMock); - - it('should be correct config', () => { - expect(extrinsic).toMatchSnapshot(); + describe('the same asset', () => { + const extrinsic = polkadotXcm() + .limitedReserveTransferAssets() + .X2() + .build(buildParamsSameAssetMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); }); - it('should get correct arguments', () => { - expect(extrinsic.getArgs()).toMatchSnapshot(); + describe('different assets', () => { + const extrinsic = polkadotXcm() + .limitedReserveTransferAssets() + .X2() + .build(buildParamsMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); }); }); diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts index 7877b2fa..34b4d36e 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts @@ -71,7 +71,8 @@ export function polkadotXcm() { module: pallet, func, getArgs: (extrinsicFunction) => { - const isAssetDifferent = params.asset !== params.feeAsset; + const isAssetDifferent = + !!params.feeAsset && params.asset !== params.feeAsset; const asset = [ { id: {