Skip to content

Commit

Permalink
Fixed and added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ekenigs committed Mar 12, 2024
1 parent 6cc2759 commit adaedee
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 13 deletions.
11 changes: 11 additions & 0 deletions packages/builder/fixtures/builderParamsMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
`;
Expand Down Expand Up @@ -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],
Expand All @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
buildParachainParamsMock,
buildParamsMock,
buildParamsSameAssetMock,
} from '../../../../fixtures';
import { polkadotXcm } from './polkadotXcm';

Expand Down Expand Up @@ -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();
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit adaedee

Please sign in to comment.