Skip to content

Commit

Permalink
Fix issues with transfers from all different sources and destinations (
Browse files Browse the repository at this point in the history
…#368)

* fix issues with transfers from all different sources and destinations

* update tests

* update tests
  • Loading branch information
mmaurello authored Oct 14, 2024
1 parent ad009de commit 3f105bc
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 75 deletions.
23 changes: 22 additions & 1 deletion packages/builder/fixtures/builderParamsMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import type { BuilderParams, MrlBuilderParams } from '../src';
export const apiMock = {
tx: {
polkadotXcm: { send: vi.fn(() => 'polkadotXcm.send => RESULT') },
xTokens: { transfer: vi.fn(() => 'xTokens.transfer => RESULT') },
xTokens: {
transfer: vi.fn(() => 'xTokens.transfer => RESULT'),
transferMulticurrencies: vi.fn(
() => 'xTokens.transferMulticurrencies => RESULT',
),
},
},
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
} as any;
Expand Down Expand Up @@ -148,6 +153,22 @@ export const mrlBuildParamsMock: MrlBuilderParams = {
},
};

export const mrlBuildParamsSameAssetMock: MrlBuilderParams = {
...buildParamsSameAssetMock,
isAutomatic: true,
moonApi: apiMock,
moonAsset: testAssetAmount,
moonChain: moonbaseAlphaMock,
moonGasLimit: 999_999n,
transact: {
call: '0x4d79207465787420737472696e67',
txWeight: {
refTime: 24_902_375_000n,
proofSize: 62_193n,
},
},
};

export const mrlBuildParamsMock2: MrlBuilderParams = {
...buildParachainParamsMock,
isAutomatic: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,127 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`polkadotXcm > send > should be correct config 1`] = `
exports[`polkadotXcm > send with transferMulticurrencies > should be correct config 1`] = `
ExtrinsicConfig {
"func": "batchAll",
"getArgs": [Function],
"module": "utility",
}
`;

exports[`polkadotXcm > send > should get correct arguments 1`] = `
exports[`polkadotXcm > send with transferMulticurrencies > should get correct arguments 1`] = `
[
[
"xTokens.transferMulticurrencies => RESULT",
"polkadotXcm.send => RESULT",
],
]
`;

exports[`polkadotXcm > send with transferMulticurrencies > should get correct arguments 2`] = `
[
{
"V3": {
"interior": {
"X1": {
"Parachain": 1000,
},
},
"parents": 1,
},
},
{
"V3": [
{
"WithdrawAsset": [
{
"fun": {
"Fungible": 100000000000000000n,
},
"id": {
"Concrete": {
"interior": {
"X1": {
"PalletInstance": 10,
},
},
"parents": 0,
},
},
},
],
},
{
"BuyExecution": {
"fees": {
"fun": {
"Fungible": 100000000000000000n,
},
"id": {
"Concrete": {
"interior": {
"X1": {
"PalletInstance": 10,
},
},
"parents": 0,
},
},
},
"weightLimit": "Unlimited",
},
},
{
"Transact": {
"call": {
"encoded": "0x4d79207465787420737472696e67",
},
"originKind": "SovereignAccount",
"requireWeightAtMost": {
"proofSize": 62193n,
"refTime": 24902375000n,
},
},
},
{
"SetAppendix": [
{
"RefundSurplus": {},
},
{
"DepositAsset": {
"assets": {
"Wild": {
"AllCounted": 1,
},
},
"beneficiary": {
"interior": {
"X1": {
"AccountKey20": {
"key": "0xcd93e4dcf4e6bb23f1c58109113266e9b79cd844",
},
},
},
"parents": 0,
},
},
},
],
},
],
},
]
`;

exports[`polkadotXcm > send with transfers > should be correct config 1`] = `
ExtrinsicConfig {
"func": "batchAll",
"getArgs": [Function],
"module": "utility",
}
`;

exports[`polkadotXcm > send with transfers > should get correct arguments 1`] = `
[
[
"xTokens.transfer => RESULT",
Expand All @@ -18,7 +131,7 @@ exports[`polkadotXcm > send > should get correct arguments 1`] = `
]
`;

exports[`polkadotXcm > send > should get correct arguments 2`] = `
exports[`polkadotXcm > send with transfers > should get correct arguments 2`] = `
[
{
"V3": {
Expand Down Expand Up @@ -99,7 +212,7 @@ exports[`polkadotXcm > send > should get correct arguments 2`] = `
"interior": {
"X1": {
"AccountKey20": {
"key": "0x88275533b5d43292c86d05985c3a6e226fee2bae",
"key": "0xcd93e4dcf4e6bb23f1c58109113266e9b79cd844",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { describe, expect, it, vi } from 'vitest';

import { apiMock, mrlBuildParamsMock } from '../../../../../../fixtures';
import {
apiMock,
mrlBuildParamsMock,
mrlBuildParamsSameAssetMock,
} from '../../../../../../fixtures';
import type { ExtrinsicConfig } from '../../../../../extrinsic';
import { XcmVersion } from '../../../../../extrinsic/ExtrinsicBuilder.interfaces';
import { polkadotXcm } from './polkadotXcm';
Expand All @@ -18,7 +22,7 @@ vi.mock(
);

describe('polkadotXcm', () => {
describe('send', () => {
describe('send with transferMulticurrencies', () => {
const extrinsic = polkadotXcm()
.send()
.build(mrlBuildParamsMock) as ExtrinsicConfig;
Expand All @@ -32,4 +36,19 @@ describe('polkadotXcm', () => {
expect(apiMock.tx.polkadotXcm.send.mock.lastCall).toMatchSnapshot();
});
});

describe('send with transfers', () => {
const extrinsic = polkadotXcm()
.send()
.build(mrlBuildParamsSameAssetMock) as ExtrinsicConfig;

it('should be correct config', () => {
expect(extrinsic).toMatchSnapshot();
});

it('should get correct arguments', () => {
expect(extrinsic.getArgs({} as any)).toMatchSnapshot();
expect(apiMock.tx.polkadotXcm.send.mock.lastCall).toMatchSnapshot();
});
});
});
Loading

0 comments on commit 3f105bc

Please sign in to comment.