Skip to content

Commit 3f105bc

Browse files
authored
Fix issues with transfers from all different sources and destinations (#368)
* fix issues with transfers from all different sources and destinations * update tests * update tests
1 parent ad009de commit 3f105bc

File tree

12 files changed

+306
-75
lines changed

12 files changed

+306
-75
lines changed

packages/builder/fixtures/builderParamsMock.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import type { BuilderParams, MrlBuilderParams } from '../src';
1313
export const apiMock = {
1414
tx: {
1515
polkadotXcm: { send: vi.fn(() => 'polkadotXcm.send => RESULT') },
16-
xTokens: { transfer: vi.fn(() => 'xTokens.transfer => RESULT') },
16+
xTokens: {
17+
transfer: vi.fn(() => 'xTokens.transfer => RESULT'),
18+
transferMulticurrencies: vi.fn(
19+
() => 'xTokens.transferMulticurrencies => RESULT',
20+
),
21+
},
1722
},
1823
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
1924
} as any;
@@ -148,6 +153,22 @@ export const mrlBuildParamsMock: MrlBuilderParams = {
148153
},
149154
};
150155

156+
export const mrlBuildParamsSameAssetMock: MrlBuilderParams = {
157+
...buildParamsSameAssetMock,
158+
isAutomatic: true,
159+
moonApi: apiMock,
160+
moonAsset: testAssetAmount,
161+
moonChain: moonbaseAlphaMock,
162+
moonGasLimit: 999_999n,
163+
transact: {
164+
call: '0x4d79207465787420737472696e67',
165+
txWeight: {
166+
refTime: 24_902_375_000n,
167+
proofSize: 62_193n,
168+
},
169+
},
170+
};
171+
151172
export const mrlBuildParamsMock2: MrlBuilderParams = {
152173
...buildParachainParamsMock,
153174
isAutomatic: true,

packages/builder/src/mrl/providers/wormhole/extrinsic/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap

Lines changed: 117 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,127 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`polkadotXcm > send > should be correct config 1`] = `
3+
exports[`polkadotXcm > send with transferMulticurrencies > should be correct config 1`] = `
44
ExtrinsicConfig {
55
"func": "batchAll",
66
"getArgs": [Function],
77
"module": "utility",
88
}
99
`;
1010

11-
exports[`polkadotXcm > send > should get correct arguments 1`] = `
11+
exports[`polkadotXcm > send with transferMulticurrencies > should get correct arguments 1`] = `
12+
[
13+
[
14+
"xTokens.transferMulticurrencies => RESULT",
15+
"polkadotXcm.send => RESULT",
16+
],
17+
]
18+
`;
19+
20+
exports[`polkadotXcm > send with transferMulticurrencies > should get correct arguments 2`] = `
21+
[
22+
{
23+
"V3": {
24+
"interior": {
25+
"X1": {
26+
"Parachain": 1000,
27+
},
28+
},
29+
"parents": 1,
30+
},
31+
},
32+
{
33+
"V3": [
34+
{
35+
"WithdrawAsset": [
36+
{
37+
"fun": {
38+
"Fungible": 100000000000000000n,
39+
},
40+
"id": {
41+
"Concrete": {
42+
"interior": {
43+
"X1": {
44+
"PalletInstance": 10,
45+
},
46+
},
47+
"parents": 0,
48+
},
49+
},
50+
},
51+
],
52+
},
53+
{
54+
"BuyExecution": {
55+
"fees": {
56+
"fun": {
57+
"Fungible": 100000000000000000n,
58+
},
59+
"id": {
60+
"Concrete": {
61+
"interior": {
62+
"X1": {
63+
"PalletInstance": 10,
64+
},
65+
},
66+
"parents": 0,
67+
},
68+
},
69+
},
70+
"weightLimit": "Unlimited",
71+
},
72+
},
73+
{
74+
"Transact": {
75+
"call": {
76+
"encoded": "0x4d79207465787420737472696e67",
77+
},
78+
"originKind": "SovereignAccount",
79+
"requireWeightAtMost": {
80+
"proofSize": 62193n,
81+
"refTime": 24902375000n,
82+
},
83+
},
84+
},
85+
{
86+
"SetAppendix": [
87+
{
88+
"RefundSurplus": {},
89+
},
90+
{
91+
"DepositAsset": {
92+
"assets": {
93+
"Wild": {
94+
"AllCounted": 1,
95+
},
96+
},
97+
"beneficiary": {
98+
"interior": {
99+
"X1": {
100+
"AccountKey20": {
101+
"key": "0xcd93e4dcf4e6bb23f1c58109113266e9b79cd844",
102+
},
103+
},
104+
},
105+
"parents": 0,
106+
},
107+
},
108+
},
109+
],
110+
},
111+
],
112+
},
113+
]
114+
`;
115+
116+
exports[`polkadotXcm > send with transfers > should be correct config 1`] = `
117+
ExtrinsicConfig {
118+
"func": "batchAll",
119+
"getArgs": [Function],
120+
"module": "utility",
121+
}
122+
`;
123+
124+
exports[`polkadotXcm > send with transfers > should get correct arguments 1`] = `
12125
[
13126
[
14127
"xTokens.transfer => RESULT",
@@ -18,7 +131,7 @@ exports[`polkadotXcm > send > should get correct arguments 1`] = `
18131
]
19132
`;
20133

21-
exports[`polkadotXcm > send > should get correct arguments 2`] = `
134+
exports[`polkadotXcm > send with transfers > should get correct arguments 2`] = `
22135
[
23136
{
24137
"V3": {
@@ -99,7 +212,7 @@ exports[`polkadotXcm > send > should get correct arguments 2`] = `
99212
"interior": {
100213
"X1": {
101214
"AccountKey20": {
102-
"key": "0x88275533b5d43292c86d05985c3a6e226fee2bae",
215+
"key": "0xcd93e4dcf4e6bb23f1c58109113266e9b79cd844",
103216
},
104217
},
105218
},

packages/builder/src/mrl/providers/wormhole/extrinsic/polkadotXcm/polkadotXcm.test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { describe, expect, it, vi } from 'vitest';
22

3-
import { apiMock, mrlBuildParamsMock } from '../../../../../../fixtures';
3+
import {
4+
apiMock,
5+
mrlBuildParamsMock,
6+
mrlBuildParamsSameAssetMock,
7+
} from '../../../../../../fixtures';
48
import type { ExtrinsicConfig } from '../../../../../extrinsic';
59
import { XcmVersion } from '../../../../../extrinsic/ExtrinsicBuilder.interfaces';
610
import { polkadotXcm } from './polkadotXcm';
@@ -18,7 +22,7 @@ vi.mock(
1822
);
1923

2024
describe('polkadotXcm', () => {
21-
describe('send', () => {
25+
describe('send with transferMulticurrencies', () => {
2226
const extrinsic = polkadotXcm()
2327
.send()
2428
.build(mrlBuildParamsMock) as ExtrinsicConfig;
@@ -32,4 +36,19 @@ describe('polkadotXcm', () => {
3236
expect(apiMock.tx.polkadotXcm.send.mock.lastCall).toMatchSnapshot();
3337
});
3438
});
39+
40+
describe('send with transfers', () => {
41+
const extrinsic = polkadotXcm()
42+
.send()
43+
.build(mrlBuildParamsSameAssetMock) as ExtrinsicConfig;
44+
45+
it('should be correct config', () => {
46+
expect(extrinsic).toMatchSnapshot();
47+
});
48+
49+
it('should get correct arguments', () => {
50+
expect(extrinsic.getArgs({} as any)).toMatchSnapshot();
51+
expect(apiMock.tx.polkadotXcm.send.mock.lastCall).toMatchSnapshot();
52+
});
53+
});
3554
});

0 commit comments

Comments
 (0)