git.delta.rocks / unique-network / refs/commits / 5ea65b7821a4

difftreelog

refactor draft move xcm tests to playgrounds

Daniel Shiposha2022-10-06parent: #f2ade55.patch.diff
in: master

3 files changed

modifiedtests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import chai from 'chai';
18import chaiAsPromised from 'chai-as-promised';
19
20import {WsProvider} from '@polkadot/api';
21import {ApiOptions} from '@polkadot/api/types';
22import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
23import usingApi, {executeTransaction} from './../substrate/substrate-api';18import {executeTransaction} from './../substrate/substrate-api';
24import {bigIntToDecimals, describe_xcm, getGenericResult, paraSiblingSovereignAccount, normalizeAccountId} from './../deprecated-helpers/helpers';19import {bigIntToDecimals, getGenericResult, paraSiblingSovereignAccount} from './../deprecated-helpers/helpers';
25import waitNewBlocks from './../substrate/wait-new-blocks';
26import getBalance from './../substrate/get-balance';20import getBalance from './../substrate/get-balance';
27
28
29chai.use(chaiAsPromised);
30const expect = chai.expect;21import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';
3122
32const STATEMINE_CHAIN = 1000;23const STATEMINE_CHAIN = 1000;
33const UNIQUE_CHAIN = 2095;24const UNIQUE_CHAIN = 2095;
3425
35const RELAY_PORT = '9844';26const RELAY_PORT = '9844';
36const UNIQUE_PORT = '9944';27const STATEMINE_PORT = '9948';
28
37const STATEMINE_PORT = '9948';29const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;
30const statemineUrl = 'ws://127.0.0.1:' + STATEMINE_PORT;
31
38const STATEMINE_PALLET_INSTANCE = 50;32const STATEMINE_PALLET_INSTANCE = 50;
39const ASSET_ID = 100;33const ASSET_ID = 100;
40const ASSET_METADATA_DECIMALS = 18;34const ASSET_METADATA_DECIMALS = 18;
41const ASSET_METADATA_NAME = 'USDT';35const ASSET_METADATA_NAME = 'USDT';
42const ASSET_METADATA_DESCRIPTION = 'USDT';36const ASSET_METADATA_DESCRIPTION = 'USDT';
43const ASSET_METADATA_MINIMAL_BALANCE = 1;37const ASSET_METADATA_MINIMAL_BALANCE = 1n;
4438
45const WESTMINT_DECIMALS = 12;39const WESTMINT_DECIMALS = 12;
4640
49// 10,000.00 (ten thousands) USDT43// 10,000.00 (ten thousands) USDT
50const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 44const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n;
5145
52describe_xcm('[XCM] Integration test: Exchanging USDT with Westmint', () => {46describeXcm('[XCM] Integration test: Exchanging USDT with Westmint', () => {
53 let alice: IKeyringPair;47 let alice: IKeyringPair;
54 let bob: IKeyringPair;48 let bob: IKeyringPair;
55 49
6963
7064
71 before(async () => {65 before(async () => {
72 await usingApi(async (api, privateKeyWrapper) => {66 await usingPlaygrounds(async (_helper, privateKey) => {
73 alice = privateKeyWrapper('//Alice');67 alice = privateKey('//Alice');
74 bob = privateKeyWrapper('//Bob'); // funds donor68 bob = privateKey('//Bob'); // funds donor
75 });69 });
76
77 const statemineApiOptions: ApiOptions = {
78 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),
79 };
80
81 const uniqueApiOptions: ApiOptions = {
82 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),
83 };
84
85 const relayApiOptions: ApiOptions = {
86 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),
87 };
8870
89 await usingApi(async (api) => {71 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {
72 const api = helper.getApi();
9073
91 // 350.00 (three hundred fifty) DOT74 // 350.00 (three hundred fifty) DOT
92 const fundingAmount = 3_500_000_000_000; 75 const fundingAmount = 3_500_000_000_000;
115 const result4 = getGenericResult(events4);98 const result4 = getGenericResult(events4);
116 expect(result4.success).to.be.true;99 expect(result4.success).to.be.true;
117100
118 }, statemineApiOptions);101 });
119102
120103
121 await usingApi(async (api) => {104 await usingPlaygrounds(async (helper) => {
122
123 const location = {105 const location = {
124 V1: {106 V1: {
144 decimals: ASSET_METADATA_DECIMALS,126 decimals: ASSET_METADATA_DECIMALS,
145 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,127 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,
146 };128 };
147 //registerForeignAsset(owner, location, metadata)
148 const tx = api.tx.foreignAssets.registerForeignAsset(alice.addressRaw, location, metadata);129 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);
149 const sudoTx = api.tx.sudo.sudo(tx as any);130 // const tx = api.tx.foreignAssets.registerForeignAsset(alice.addressRaw, location, metadata);
150 const events = await executeTransaction(api, alice, sudoTx);131 // const sudoTx = api.tx.sudo.sudo(tx as any);
151 const result = getGenericResult(events);132 // const events = await executeTransaction(api, alice, sudoTx);
152 expect(result.success).to.be.true;133 // const result = getGenericResult(events);
153134 // expect(result.success).to.be.true;
135
136 // [balanceOpalBefore] = await getBalance(api, [alice.address]);
154 [balanceOpalBefore] = await getBalance(api, [alice.address]);137 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);
155138
156 }, uniqueApiOptions);139 });
157140
158141
159 // Providing the relay currency to the unique sender account142 // Providing the relay currency to the unique sender account
160 await usingApi(async (api) => {143 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {
144 const api = helper.getApi();
145
161 const destination = {146 const destination = {
162 V1: {147 V1: {
205 const events = await executeTransaction(api, alice, tx);190 const events = await executeTransaction(api, alice, tx);
206 const result = getGenericResult(events);191 const result = getGenericResult(events);
207 expect(result.success).to.be.true;192 expect(result.success).to.be.true;
208 }, relayApiOptions);193 });
209 194
210 });195 });
211196
212 it('Should connect and send USDT from Westmint to Opal', async () => {197 itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {
213
214 const statemineApiOptions: ApiOptions = {
215 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),
216 };
217
218 const uniqueApiOptions: ApiOptions = {
219 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),
220 };
221
222 await usingApi(async (api) => {198 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {
199 const api = helper.getApi();
223200
224 const dest = {201 const dest = {
225 V1: {202 V1: {
288 );265 );
289 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;266 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;
290267
291 }, statemineApiOptions);268 });
292269
293270
294 // ensure that asset has been delivered271 // ensure that asset has been delivered
295 await usingApi(async (api) => {272 // await waitNewBlocks(api, 3);
296 await waitNewBlocks(api, 3);273 await helper.wait.newBlocks(3);
274
297 // expext collection id will be with id 1275 // expext collection id will be with id 1
276 // const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();
298 const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();277 const free = await helper.ft.getBalance(1, {Substrate: alice.address});
299278
279 // [balanceOpalAfter] = await getBalance(api, [alice.address]);
300 [balanceOpalAfter] = await getBalance(api, [alice.address]);280 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);
301281
302 // commission has not paid in USDT token282 // commission has not paid in USDT token
303 expect(free == TRANSFER_AMOUNT).to.be.true;283 expect(free == TRANSFER_AMOUNT).to.be.true;
312 bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),292 bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),
313 );293 );
314
315 }, uniqueApiOptions);
316
317 });294 });
318295
319 it('Should connect and send USDT from Unique to Statemine back', async () => {296 itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {
320
321 const uniqueApiOptions: ApiOptions = {297 const api = helper.getApi();
322 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),298
323 };
324
325 const statemineApiOptions: ApiOptions = {
326 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),
327 };
328
329 await usingApi(async (api) => {
330 const destination = {299 const destination = {
331 V1: {300 V1: {
332 parents: 1,301 parents: 1,
371 // the commission has been paid in parachain native token340 // the commission has been paid in parachain native token
372 [balanceOpalFinal] = await getBalance(api, [alice.address]);341 [balanceOpalFinal] = await getBalance(api, [alice.address]);
373 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;342 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;
374 }, uniqueApiOptions);
375343
376 await usingApi(async (api) => {344 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {
345 // await waitNewBlocks(api, 3);
377 await waitNewBlocks(api, 3);346 await helper.wait.newBlocks(3);
378 347
348 const api = helper.getApi();
349
379 // The USDT token never paid fees. Its amount not changed from begin value.350 // The USDT token never paid fees. Its amount not changed from begin value.
380 // Also check that xcm transfer has been succeeded 351 // Also check that xcm transfer has been succeeded
381 const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;352 const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;
382 expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;353 expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;
383 }, statemineApiOptions);354 });
384 });355 });
385356
386 it('Should connect and send Relay token to Unique', async () => {357 itSub('Should connect and send Relay token to Unique', async ({helper}) => {
387
388 const uniqueApiOptions: ApiOptions = {358 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;
389 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),359
390 };360 // [balanceBobBefore] = await getBalance(api, [bob.address]);
391361 // balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
392 const uniqueApiOptions2: ApiOptions = {362 balanceBobBefore = await helper.balance.getSubstrate(bob.address);
393 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),363
394 };364 // TODO
395
396 const relayApiOptions: ApiOptions = {
397 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),
398 };
399
400 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;
401
402 await usingApi(async (api) => {
403 [balanceBobBefore] = await getBalance(api, [bob.address]);
404 balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);365 balanceBobRelayTokenBefore = BigInt(((await helper.getApi().query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
405
406 }, uniqueApiOptions);
407366
408 // Providing the relay currency to the unique sender account367 // Providing the relay currency to the unique sender account
409 await usingApi(async (api) => {368 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {
369 const api = helper.getApi();
370
410 const destination = {371 const destination = {
411 V1: {372 V1: {
454 const events = await executeTransaction(api, bob, tx);415 const events = await executeTransaction(api, bob, tx);
455 const result = getGenericResult(events);416 const result = getGenericResult(events);
456 expect(result.success).to.be.true;417 expect(result.success).to.be.true;
457 }, relayApiOptions);418 });
458 419
459420
460 await usingApi(async (api) => {421 // await waitNewBlocks(api, 3);
461 await waitNewBlocks(api, 3);422 await helper.wait.newBlocks(3);
462423
424 // [balanceBobAfter] = await getBalance(api, [bob.address]);
425 // balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
463 [balanceBobAfter] = await getBalance(api, [bob.address]);426 balanceBobAfter = await helper.balance.getSubstrate(bob.address);
427
428 // TODO
464 balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);429 balanceBobRelayTokenAfter = BigInt(((await helper.getApi().query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
430
465 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 431 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;
466 console.log(432 console.log(
473 );439 );
474 expect(balanceBobBefore == balanceBobAfter).to.be.true;440 expect(balanceBobBefore == balanceBobAfter).to.be.true;
475 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;441 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;
476 }, uniqueApiOptions2);
477
478 });442 });
479443
480 it('Should connect and send Relay token back', async () => {444 itSub('Should connect and send Relay token back', async ({helper}) => {
481 const uniqueApiOptions: ApiOptions = {
482 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),
483 };
484
485 await usingApi(async (api) => {
486 const destination = {445 const destination = {
487 V1: {446 V1: {
488 parents: 1,447 parents: 1,
512 const feeItem = 0;471 const feeItem = 0;
513 const destWeight = 500000000000;472 const destWeight = 500000000000;
514473
474 // TODO
475 const api = helper.getApi();
515 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);476 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);
516 const events = await executeTransaction(api, bob, tx);477 const events = await executeTransaction(api, bob, tx);
517 const result = getGenericResult(events);478 const result = getGenericResult(events);
518 expect(result.success).to.be.true;479 expect(result.success).to.be.true;
519480
481 // [balanceBobFinal] = await getBalance(api, [bob.address]);
520 [balanceBobFinal] = await getBalance(api, [bob.address]);482 balanceBobFinal = await helper.balance.getSubstrate(bob.address);
521 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);483 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);
522
523 }, uniqueApiOptions);
524 });484 });
525485
526});486});
modifiedtests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import chai from 'chai';17import {Keyring} from '@polkadot/api';
18import chaiAsPromised from 'chai-as-promised';
19
20import {WsProvider, Keyring} from '@polkadot/api';
21import {ApiOptions} from '@polkadot/api/types';
22import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';19import {submitTransactionAsync} from '../substrate/substrate-api';
24import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../deprecated-helpers/helpers';20import {getGenericResult, generateKeyringPair, waitEvent, bigIntToDecimals} from '../deprecated-helpers/helpers';
25import {MultiLocation} from '@polkadot/types/interfaces';21import {MultiLocation} from '@polkadot/types/interfaces';
26import {blake2AsHex} from '@polkadot/util-crypto';22import {blake2AsHex} from '@polkadot/util-crypto';
27import waitNewBlocks from '../substrate/wait-new-blocks';
28import getBalance from '../substrate/get-balance';23import getBalance from '../substrate/get-balance';
29import {XcmV2TraitsOutcome, XcmV2TraitsError} from '../interfaces';24import {XcmV2TraitsOutcome, XcmV2TraitsError} from '../interfaces';
25import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';
3026
31chai.use(chaiAsPromised);
32const expect = chai.expect;
33
34const QUARTZ_CHAIN = 2095;27const QUARTZ_CHAIN = 2095;
35const KARURA_CHAIN = 2000;28const KARURA_CHAIN = 2000;
36const MOONRIVER_CHAIN = 2023;29const MOONRIVER_CHAIN = 2023;
39const KARURA_PORT = 9946;32const KARURA_PORT = 9946;
40const MOONRIVER_PORT = 9947;33const MOONRIVER_PORT = 9947;
4134
35const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;
36const karuraUrl = 'ws://127.0.0.1:' + KARURA_PORT;
37const moonriverUrl = 'ws://127.0.0.1:' + MOONRIVER_PORT;
38
42const KARURA_DECIMALS = 12;39const KARURA_DECIMALS = 12;
4340
44const TRANSFER_AMOUNT = 2000000000000000000000000n;41const TRANSFER_AMOUNT = 2000000000000000000000000n;
4542
46function parachainApiOptions(port: number): ApiOptions {
47 return {
48 provider: new WsProvider('ws://127.0.0.1:' + port.toString()),
49 };
50}
51
52function karuraOptions(): ApiOptions {
53 return parachainApiOptions(KARURA_PORT);
54}
55
56function moonriverOptions(): ApiOptions {
57 return parachainApiOptions(MOONRIVER_PORT);
58}
59
60function relayOptions(): ApiOptions {
61 return parachainApiOptions(RELAY_PORT);
62}
63
64describe_xcm('[XCM] Integration test: Exchanging tokens with Karura', () => {43describeXcm('[XCM] Integration test: Exchanging tokens with Karura', () => {
65 let alice: IKeyringPair;44 let alice: IKeyringPair;
66 let randomAccount: IKeyringPair;45 let randomAccount: IKeyringPair;
6746
76 let balanceQuartzForeignTokenFinal: bigint;55 let balanceQuartzForeignTokenFinal: bigint;
7756
78 before(async () => {57 before(async () => {
79 await usingApi(async (api, privateKeyWrapper) => {58 await usingPlaygrounds(async (helper, privateKey) => {
80 const keyringSr25519 = new Keyring({type: 'sr25519'});59 const keyringSr25519 = new Keyring({type: 'sr25519'});
8160
82 alice = privateKeyWrapper('//Alice');61 alice = privateKey('//Alice');
83 randomAccount = generateKeyringPair(keyringSr25519);62 randomAccount = generateKeyringPair(keyringSr25519);
84 });63 });
8564
86 // Karura side65 // Karura side
87 await usingApi(66 await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
88 async (api) => {
89 const destination = {67 const api = helper.getApi();
90 V0: {
91 X2: [
92 'Parent',
93 {
94 Parachain: QUARTZ_CHAIN,
95 },
96 ],
97 },
98 };
9968
100 const metadata = {69 const destination = {
101 name: 'QTZ',70 V0: {
71 X2: [
102 symbol: 'QTZ',72 'Parent',
103 decimals: 18,73 {
74 Parachain: QUARTZ_CHAIN,
104 minimalBalance: 1,75 },
105 };76 ],
77 },
78 };
10679
107 const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);80 const metadata = {
108 const sudoTx = api.tx.sudo.sudo(tx as any);81 name: 'QTZ',
109 const events = await submitTransactionAsync(alice, sudoTx);82 symbol: 'QTZ',
83 decimals: 18,
110 const result = getGenericResult(events);84 minimalBalance: 1,
111 expect(result.success).to.be.true;85 };
11286
113 const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);87 const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);
114 const events1 = await submitTransactionAsync(alice, tx1);88 const sudoTx = api.tx.sudo.sudo(tx as any);
89 const events = await submitTransactionAsync(alice, sudoTx);
115 const result1 = getGenericResult(events1);90 const result = getGenericResult(events);
116 expect(result1.success).to.be.true;91 expect(result.success).to.be.true;
11792
118 [balanceKaruraTokenInit] = await getBalance(api, [randomAccount.address]);93 const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
119 {94 const events1 = await submitTransactionAsync(alice, tx1);
120 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
121 balanceQuartzForeignTokenInit = BigInt(free);95 const result1 = getGenericResult(events1);
122 }96 expect(result1.success).to.be.true;
123 },
124 karuraOptions(),
125 );
12697
98 [balanceKaruraTokenInit] = await getBalance(api, [randomAccount.address]);
99 {
100 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
101 balanceQuartzForeignTokenInit = BigInt(free);
102 }
103 });
104
127 // Quartz side105 // Quartz side
128 await usingApi(async (api) => {106 await usingPlaygrounds(async (helper) => {
129 const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);107 // const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);
130 const events0 = await submitTransactionAsync(alice, tx0);108 // const events0 = await submitTransactionAsync(alice, tx0);
131 const result0 = getGenericResult(events0);109 // const result0 = getGenericResult(events0);
132 expect(result0.success).to.be.true;110 // expect(result0.success).to.be.true;
111 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);
133112
134 [balanceQuartzTokenInit] = await getBalance(api, [randomAccount.address]);113 // [balanceQuartzTokenInit] = await getBalance(api, [randomAccount.address]);
114 balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccount.address);
135 });115 });
136 });116 });
137117
138 it('Should connect and send QTZ to Karura', async () => {118 itSub('Should connect and send QTZ to Karura', async ({helper}) => {
139119
140 // Quartz side120 // Quartz side
141 await usingApi(async (api) => {121 const destination = {
122 V0: {
123 X2: [
124 'Parent',
125 {
126 Parachain: KARURA_CHAIN,
127 },
128 ],
129 },
130 };
142131
143 const destination = {132 const beneficiary = {
144 V0: {133 V0: {
145 X2: [134 X1: {
146 'Parent',135 AccountId32: {
147 {
148 Parachain: KARURA_CHAIN,136 network: 'Any',
149 },137 id: randomAccount.addressRaw,
150 ],138 },
151 },139 },
152 };140 },
141 };
153142
154 const beneficiary = {143 const assets = {
155 V0: {144 V1: [
145 {
156 X1: {146 id: {
157 AccountId32: {147 Concrete: {
158 network: 'Any',148 parents: 0,
159 id: randomAccount.addressRaw,149 interior: 'Here',
160 },150 },
161 },151 },
152 fun: {
153 Fungible: TRANSFER_AMOUNT,
154 },
162 },155 },
163 };156 ],
157 };
164158
165 const assets = {159 const feeAssetItem = 0;
166 V1: [
167 {
168 id: {
169 Concrete: {
170 parents: 0,
171 interior: 'Here',
172 },
173 },
174 fun: {
175 Fungible: TRANSFER_AMOUNT,
176 },
177 },
178 ],
179 };
180160
181 const feeAssetItem = 0;161 const weightLimit = {
162 Limited: 5000000000,
163 };
182164
183 const weightLimit = {165 // TODO
166 const tx = helper.getApi().tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
184 Limited: 5000000000,167 const events = await submitTransactionAsync(randomAccount, tx);
185 };168 const result = getGenericResult(events);
169 expect(result.success).to.be.true;
186170
187 const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);171 // [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccount.address]);
188 const events = await submitTransactionAsync(randomAccount, tx);
189 const result = getGenericResult(events);172 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
190 expect(result.success).to.be.true;
191173
192 [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccount.address]);174 const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
175 console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
176 expect(qtzFees > 0n).to.be.true;
193177
194 const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
195 console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
196 expect(qtzFees > 0n).to.be.true;
197 });
198
199 // Karura side178 // Karura side
200 await usingApi(179 await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
201 async (api) => {
202 await waitNewBlocks(api, 3);180 // await waitNewBlocks(api, 3);
203 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;181 await helper.wait.newBlocks(3);
204 balanceQuartzForeignTokenMiddle = BigInt(free);
205182
206 [balanceKaruraTokenMiddle] = await getBalance(api, [randomAccount.address]);183 // TODO
184 const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
185 balanceQuartzForeignTokenMiddle = BigInt(free);
207186
208 const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;187 // [balanceKaruraTokenMiddle] = await getBalance(api, [randomAccount.address]);
209 const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;188 balanceKaruraTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
210189
211 console.log(190 const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;
191 const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;
192
193 console.log(
212 '[Quartz -> Karura] transaction fees on Karura: %s KAR',194 '[Quartz -> Karura] transaction fees on Karura: %s KAR',
213 bigIntToDecimals(karFees, KARURA_DECIMALS),195 bigIntToDecimals(karFees, KARURA_DECIMALS),
214 );196 );
215 console.log('[Quartz -> Karura] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));197 console.log('[Quartz -> Karura] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
216 expect(karFees == 0n).to.be.true;198 expect(karFees == 0n).to.be.true;
217 expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;199 expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
218 },200 });
219 karuraOptions(),
220 );
221 });201 });
222202
223 it('Should connect to Karura and send QTZ back', async () => {203 itSub('Should connect to Karura and send QTZ back', async ({helper}) => {
224204
225 // Karura side205 // Karura side
226 await usingApi(206 await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
227 async (api) => {
228 const destination = {207 const destination = {
229 V1: {208 V1: {
230 parents: 1,209 parents: 1,
231 interior: {210 interior: {
232 X2: [211 X2: [
233 {Parachain: QUARTZ_CHAIN},212 {Parachain: QUARTZ_CHAIN},
234 {213 {
235 AccountId32: {214 AccountId32: {
236 network: 'Any',215 network: 'Any',
237 id: randomAccount.addressRaw,216 id: randomAccount.addressRaw,
238 },
239 },217 },
240 ],218 },
241 },219 ],
242 },220 },
243 };221 },
222 };
244223
245 const id = {224 const id = {
246 ForeignAsset: 0,225 ForeignAsset: 0,
247 };226 };
248227
249 const destWeight = 50000000;228 const destWeight = 50000000;
250229
251 const tx = api.tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);230 // TODO
231 const tx = helper.getApi().tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
252 const events = await submitTransactionAsync(randomAccount, tx);232 const events = await submitTransactionAsync(randomAccount, tx);
253 const result = getGenericResult(events);233 const result = getGenericResult(events);
254 expect(result.success).to.be.true;234 expect(result.success).to.be.true;
255235
256 [balanceKaruraTokenFinal] = await getBalance(api, [randomAccount.address]);236 // [balanceKaruraTokenFinal] = await getBalance(api, [randomAccount.address]);
257 {237 balanceKaruraTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
238 {
258 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;239 // TODO
240 const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;
259 balanceQuartzForeignTokenFinal = BigInt(free);241 balanceQuartzForeignTokenFinal = BigInt(free);
260 }242 }
261243
262 const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;244 const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;
263 const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;245 const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;
264246
265 console.log(247 console.log(
266 '[Karura -> Quartz] transaction fees on Karura: %s KAR',248 '[Karura -> Quartz] transaction fees on Karura: %s KAR',
267 bigIntToDecimals(karFees, KARURA_DECIMALS),249 bigIntToDecimals(karFees, KARURA_DECIMALS),
268 );250 );
269 console.log('[Karura -> Quartz] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));251 console.log('[Karura -> Quartz] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
270252
271 expect(karFees > 0).to.be.true;253 expect(karFees > 0).to.be.true;
272 expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;254 expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
273 },255 });
274 karuraOptions(),
275 );
276256
277 // Quartz side257 // Quartz side
278 await usingApi(async (api) => {258 // await waitNewBlocks(api, 3);
279 await waitNewBlocks(api, 3);259 await helper.wait.newBlocks(3);
280260
281 [balanceQuartzTokenFinal] = await getBalance(api, [randomAccount.address]);261 // [balanceQuartzTokenFinal] = await getBalance(api, [randomAccount.address]);
282 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;262 balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
263 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
283 expect(actuallyDelivered > 0).to.be.true;264 expect(actuallyDelivered > 0).to.be.true;
284265
285 console.log('[Karura -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));266 console.log('[Karura -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
286267
287 const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;268 const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
288 console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));269 console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
289 expect(qtzFees == 0n).to.be.true;270 expect(qtzFees == 0n).to.be.true;
290 });
291 });271 });
292});272});
293273
294// These tests are relevant only when the foreign asset pallet is disabled274// These tests are relevant only when the foreign asset pallet is disabled
295describe_xcm('[XCM] Integration test: Quartz rejects non-native tokens', () => {275describeXcm('[XCM] Integration test: Quartz rejects non-native tokens', () => {
296 let alice: IKeyringPair;276 let alice: IKeyringPair;
297277
298 before(async () => {278 before(async () => {
299 await usingApi(async (api, privateKeyWrapper) => {279 await usingPlaygrounds(async (_helper, privateKey) => {
300 alice = privateKeyWrapper('//Alice');280 alice = privateKey('//Alice');
301 });281 });
302 });282 });
303283
304 it('Quartz rejects tokens from the Relay', async () => {284 itSub('Quartz rejects tokens from the Relay', async ({helper}) => {
305 await usingApi(async (api) => {285 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {
306 const destination = {286 const destination = {
307 V1: {287 V1: {
308 parents: 0,288 parents: 0,
346 Limited: 5_000_000_000,326 Limited: 5_000_000_000,
347 };327 };
348328
349 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);329 // TODO
330 const tx = helper.getApi().tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
350 const events = await submitTransactionAsync(alice, tx);331 const events = await submitTransactionAsync(alice, tx);
351 const result = getGenericResult(events);332 const result = getGenericResult(events);
352 expect(result.success).to.be.true;333 expect(result.success).to.be.true;
353 }, relayOptions());334 });
354335
355 await usingApi(async api => {336 const maxWaitBlocks = 3;
356 const maxWaitBlocks = 3;
357 const dmpQueueExecutedDownward = await waitEvent(
358 api,
359 maxWaitBlocks,
360 'dmpQueue',
361 'ExecutedDownward',
362 );
363337
364 expect(338 // TODO
339 const dmpQueueExecutedDownward = await waitEvent(
365 dmpQueueExecutedDownward != null,340 helper.getApi(),
341 maxWaitBlocks,
366 '[Relay] dmpQueue.ExecutedDownward event is expected',342 'dmpQueue',
343 'ExecutedDownward',
367 ).to.be.true;344 );
368345
369 const event = dmpQueueExecutedDownward!.event;346 expect(
347 dmpQueueExecutedDownward != null,
370 const outcome = event.data[1] as XcmV2TraitsOutcome;348 '[Relay] dmpQueue.ExecutedDownward event is expected',
349 ).to.be.true;
371350
372 expect(351 const event = dmpQueueExecutedDownward!.event;
373 outcome.isIncomplete,
374 '[Relay] The outcome of the XCM should be `Incomplete`',352 const outcome = event.data[1] as XcmV2TraitsOutcome;
375 ).to.be.true;
376353
377 const incomplete = outcome.asIncomplete;354 expect(
355 outcome.isIncomplete,
356 '[Relay] The outcome of the XCM should be `Incomplete`',
357 ).to.be.true;
358
359 const incomplete = outcome.asIncomplete;
378 expect(360 expect(
379 incomplete[1].toString() == 'AssetNotFound',361 incomplete[1].toString() == 'AssetNotFound',
380 '[Relay] The XCM error should be `AssetNotFound`',362 '[Relay] The XCM error should be `AssetNotFound`',
381 ).to.be.true;363 ).to.be.true;
382 });
383 });364 });
384365
385 it('Quartz rejects KAR tokens from Karura', async () => {366 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
386 await usingApi(async (api) => {367 await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
387 const destination = {368 const destination = {
388 V1: {369 V1: {
389 parents: 1,370 parents: 1,
407388
408 const destWeight = 50000000;389 const destWeight = 50000000;
409390
410 const tx = api.tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);391 // TODO
392 const tx = helper.getApi().tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
411 const events = await submitTransactionAsync(alice, tx);393 const events = await submitTransactionAsync(alice, tx);
412 const result = getGenericResult(events);394 const result = getGenericResult(events);
413 expect(result.success).to.be.true;395 expect(result.success).to.be.true;
414 }, karuraOptions());396 });
415397
416 await usingApi(async api => {398 const maxWaitBlocks = 3;
417 const maxWaitBlocks = 3;
418 const xcmpQueueFailEvent = await waitEvent(api, maxWaitBlocks, 'xcmpQueue', 'Fail');
419399
420 expect(400 // TODO
421 xcmpQueueFailEvent != null,401 const xcmpQueueFailEvent = await waitEvent(helper.getApi(), maxWaitBlocks, 'xcmpQueue', 'Fail');
422 '[Karura] xcmpQueue.FailEvent event is expected',
423 ).to.be.true;
424402
425 const event = xcmpQueueFailEvent!.event;403 expect(
404 xcmpQueueFailEvent != null,
426 const outcome = event.data[1] as XcmV2TraitsError;405 '[Karura] xcmpQueue.FailEvent event is expected',
406 ).to.be.true;
427407
428 expect(408 const event = xcmpQueueFailEvent!.event;
409 const outcome = event.data[1] as XcmV2TraitsError;
410
411 expect(
429 outcome.isUntrustedReserveLocation,412 outcome.isUntrustedReserveLocation,
430 '[Karura] The XCM error should be `UntrustedReserveLocation`',413 '[Karura] The XCM error should be `UntrustedReserveLocation`',
431 ).to.be.true;414 ).to.be.true;
432 });
433 });415 });
434});416});
435417
436describe_xcm('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {418describeXcm('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
437419
438 // Quartz constants420 // Quartz constants
439 let quartzAlice: IKeyringPair;421 let quartzAlice: IKeyringPair;
478 let balanceMovrTokenFinal: bigint;460 let balanceMovrTokenFinal: bigint;
479461
480 before(async () => {462 before(async () => {
481 await usingApi(async (api, privateKeyWrapper) => {463 await usingPlaygrounds(async (_helper, privateKey) => {
482 const keyringEth = new Keyring({type: 'ethereum'});464 const keyringEth = new Keyring({type: 'ethereum'});
483 const keyringSr25519 = new Keyring({type: 'sr25519'});465 const keyringSr25519 = new Keyring({type: 'sr25519'});
484466
485 quartzAlice = privateKeyWrapper('//Alice');467 quartzAlice = privateKey('//Alice');
486 randomAccountQuartz = generateKeyringPair(keyringSr25519);468 randomAccountQuartz = generateKeyringPair(keyringSr25519);
487 randomAccountMoonriver = generateKeyringPair(keyringEth);469 randomAccountMoonriver = generateKeyringPair(keyringEth);
488470
489 balanceForeignQtzTokenInit = 0n;471 balanceForeignQtzTokenInit = 0n;
490 });472 });
491473
492 await usingApi(474 await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {
493 async (api) => {475 // TODO
494476
495 // >>> Sponsoring Dorothy >>>477 const api = helper.getApi();
496 console.log('Sponsoring Dorothy.......');
497 const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);
498 const events0 = await submitTransactionAsync(alithAccount, tx0);
499 const result0 = getGenericResult(events0);
500 expect(result0.success).to.be.true;
501 console.log('Sponsoring Dorothy.......DONE');
502 // <<< Sponsoring Dorothy <<<
503478
504 const sourceLocation: MultiLocation = api.createType(479 // >>> Sponsoring Dorothy >>>
480 console.log('Sponsoring Dorothy.......');
505 'MultiLocation',481 // const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);
506 {482 // const events0 = await submitTransactionAsync(alithAccount, tx0);
507 parents: 1,483 // const result0 = getGenericResult(events0);
508 interior: {X1: {Parachain: QUARTZ_CHAIN}},484 // expect(result0.success).to.be.true;
485 await helper.balance.transferToSubstrate(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);
509 },486 console.log('Sponsoring Dorothy.......DONE');
510 );487 // <<< Sponsoring Dorothy <<<
511488
512 quartzAssetLocation = {XCM: sourceLocation};489 const sourceLocation: MultiLocation = api.createType(
513 const existentialDeposit = 1;490 'MultiLocation',
491 {
514 const isSufficient = true;492 parents: 1,
515 const unitsPerSecond = '1';493 interior: {X1: {Parachain: QUARTZ_CHAIN}},
516 const numAssetsWeightHint = 0;494 },
495 );
517496
518 const registerTx = api.tx.assetManager.registerForeignAsset(497 quartzAssetLocation = {XCM: sourceLocation};
519 quartzAssetLocation,
520 quartzAssetMetadata,498 const existentialDeposit = 1;
521 existentialDeposit,499 const isSufficient = true;
522 isSufficient,500 const unitsPerSecond = '1';
523 );
524 console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');501 const numAssetsWeightHint = 0;
525502
526 const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(503 const registerTx = api.tx.assetManager.registerForeignAsset(
527 quartzAssetLocation,504 quartzAssetLocation,
528 unitsPerSecond,505 quartzAssetMetadata,
529 numAssetsWeightHint,506 existentialDeposit,
530 );507 isSufficient,
531 console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');508 );
509 console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
532510
533 const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);511 const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
512 quartzAssetLocation,
513 unitsPerSecond,
514 numAssetsWeightHint,
515 );
534 console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');516 console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');
535517
536 // >>> Note motion preimage >>>518 const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);
537 console.log('Note motion preimage.......');
538 const encodedProposal = batchCall?.method.toHex() || '';
539 const proposalHash = blake2AsHex(encodedProposal);
540 console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
541 console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);519 console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');
542 console.log('Encoded length %d', encodedProposal.length);
543520
544 const tx1 = api.tx.democracy.notePreimage(encodedProposal);521 // >>> Note motion preimage >>>
522 console.log('Note motion preimage.......');
545 const events1 = await submitTransactionAsync(baltatharAccount, tx1);523 const encodedProposal = batchCall?.method.toHex() || '';
546 const result1 = getGenericResult(events1);524 const proposalHash = blake2AsHex(encodedProposal);
547 expect(result1.success).to.be.true;525 console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
548 console.log('Note motion preimage.......DONE');526 console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
549 // <<< Note motion preimage <<<527 console.log('Encoded length %d', encodedProposal.length);
550528
551 // >>> Propose external motion through council >>>529 const tx1 = api.tx.democracy.notePreimage(encodedProposal);
552 console.log('Propose external motion through council.......');
553 const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);
554 const tx2 = api.tx.councilCollective.propose(530 const events1 = await submitTransactionAsync(baltatharAccount, tx1);
555 councilVotingThreshold,
556 externalMotion,
557 externalMotion.encodedLength,531 const result1 = getGenericResult(events1);
558 );
559 const events2 = await submitTransactionAsync(baltatharAccount, tx2);532 expect(result1.success).to.be.true;
560 const result2 = getGenericResult(events2);533 console.log('Note motion preimage.......DONE');
561 expect(result2.success).to.be.true;534 // <<< Note motion preimage <<<
562535
563 const encodedMotion = externalMotion?.method.toHex() || '';536 // >>> Propose external motion through council >>>
537 console.log('Propose external motion through council.......');
538 const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);
539 const tx2 = api.tx.councilCollective.propose(
564 const motionHash = blake2AsHex(encodedMotion);540 councilVotingThreshold,
541 externalMotion,
542 externalMotion.encodedLength,
543 );
544 const events2 = await submitTransactionAsync(baltatharAccount, tx2);
565 console.log('Motion hash is %s', motionHash);545 const result2 = getGenericResult(events2);
546 expect(result2.success).to.be.true;
566547
567 const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);548 const encodedMotion = externalMotion?.method.toHex() || '';
568 {
569 const events3 = await submitTransactionAsync(dorothyAccount, tx3);
570 const result3 = getGenericResult(events3);549 const motionHash = blake2AsHex(encodedMotion);
571 expect(result3.success).to.be.true;550 console.log('Motion hash is %s', motionHash);
572 }
573 {
574 const events3 = await submitTransactionAsync(baltatharAccount, tx3);
575 const result3 = getGenericResult(events3);
576 expect(result3.success).to.be.true;
577 }
578551
579 const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);552 const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);
580 const events4 = await submitTransactionAsync(dorothyAccount, tx4);553 {
554 const events3 = await submitTransactionAsync(dorothyAccount, tx3);
581 const result4 = getGenericResult(events4);555 const result3 = getGenericResult(events3);
582 expect(result4.success).to.be.true;556 expect(result3.success).to.be.true;
583 console.log('Propose external motion through council.......DONE');557 }
558 {
559 const events3 = await submitTransactionAsync(baltatharAccount, tx3);
560 const result3 = getGenericResult(events3);
584 // <<< Propose external motion through council <<<561 expect(result3.success).to.be.true;
562 }
585563
586 // >>> Fast track proposal through technical committee >>>564 const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);
587 console.log('Fast track proposal through technical committee.......');
588 const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
589 const tx5 = api.tx.techCommitteeCollective.propose(565 const events4 = await submitTransactionAsync(dorothyAccount, tx4);
590 technicalCommitteeThreshold,
591 fastTrack,
592 fastTrack.encodedLength,566 const result4 = getGenericResult(events4);
593 );567 expect(result4.success).to.be.true;
594 const events5 = await submitTransactionAsync(alithAccount, tx5);568 console.log('Propose external motion through council.......DONE');
595 const result5 = getGenericResult(events5);569 // <<< Propose external motion through council <<<
596 expect(result5.success).to.be.true;
597570
598 const encodedFastTrack = fastTrack?.method.toHex() || '';571 // >>> Fast track proposal through technical committee >>>
572 console.log('Fast track proposal through technical committee.......');
573 const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
599 const fastTrackHash = blake2AsHex(encodedFastTrack);574 const tx5 = api.tx.techCommitteeCollective.propose(
575 technicalCommitteeThreshold,
576 fastTrack,
577 fastTrack.encodedLength,
578 );
579 const events5 = await submitTransactionAsync(alithAccount, tx5);
600 console.log('FastTrack hash is %s', fastTrackHash);580 const result5 = getGenericResult(events5);
581 expect(result5.success).to.be.true;
601582
602 const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;583 const encodedFastTrack = fastTrack?.method.toHex() || '';
603 const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);584 const fastTrackHash = blake2AsHex(encodedFastTrack);
604 {
605 const events6 = await submitTransactionAsync(baltatharAccount, tx6);
606 const result6 = getGenericResult(events6);585 console.log('FastTrack hash is %s', fastTrackHash);
607 expect(result6.success).to.be.true;
608 }
609 {
610 const events6 = await submitTransactionAsync(alithAccount, tx6);
611 const result6 = getGenericResult(events6);
612 expect(result6.success).to.be.true;
613 }
614586
615 const tx7 = api.tx.techCommitteeCollective587 const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;
616 .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);588 const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);
617 const events7 = await submitTransactionAsync(baltatharAccount, tx7);589 {
590 const events6 = await submitTransactionAsync(baltatharAccount, tx6);
618 const result7 = getGenericResult(events7);591 const result6 = getGenericResult(events6);
619 expect(result7.success).to.be.true;592 expect(result6.success).to.be.true;
620 console.log('Fast track proposal through technical committee.......DONE');593 }
594 {
595 const events6 = await submitTransactionAsync(alithAccount, tx6);
621 // <<< Fast track proposal through technical committee <<<596 const result6 = getGenericResult(events6);
597 expect(result6.success).to.be.true;
598 }
622599
623 // >>> Referendum voting >>>600 const tx7 = api.tx.techCommitteeCollective
624 console.log('Referendum voting.......');
625 const tx8 = api.tx.democracy.vote(
626 0,601 .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);
627 {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},
628 );
629 const events8 = await submitTransactionAsync(dorothyAccount, tx8);602 const events7 = await submitTransactionAsync(baltatharAccount, tx7);
630 const result8 = getGenericResult(events8);603 const result7 = getGenericResult(events7);
631 expect(result8.success).to.be.true;604 expect(result7.success).to.be.true;
632 console.log('Referendum voting.......DONE');605 console.log('Fast track proposal through technical committee.......DONE');
633 // <<< Referendum voting <<<606 // <<< Fast track proposal through technical committee <<<
634607
635 // >>> Acquire Quartz AssetId Info on Moonriver >>>608 // >>> Referendum voting >>>
636 console.log('Acquire Quartz AssetId Info on Moonriver.......');609 console.log('Referendum voting.......');
610 const tx8 = api.tx.democracy.vote(
611 0,
612 {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},
613 );
614 const events8 = await submitTransactionAsync(dorothyAccount, tx8);
615 const result8 = getGenericResult(events8);
616 expect(result8.success).to.be.true;
617 console.log('Referendum voting.......DONE');
618 // <<< Referendum voting <<<
637619
638 // Wait for the democracy execute620 // >>> Acquire Quartz AssetId Info on Moonriver >>>
639 await waitNewBlocks(api, 5);621 console.log('Acquire Quartz AssetId Info on Moonriver.......');
640622
641 assetId = (await api.query.assetManager.assetTypeId({623 // Wait for the democracy execute
642 XCM: sourceLocation,624 // await waitNewBlocks(api, 5);
643 })).toString();625 await helper.wait.newBlocks(5);
644626
645 console.log('QTZ asset ID is %s', assetId);627 assetId = (await api.query.assetManager.assetTypeId({
646 console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');
647 // >>> Acquire Quartz AssetId Info on Moonriver >>>628 XCM: sourceLocation,
629 })).toString();
648630
649 // >>> Sponsoring random Account >>>631 console.log('QTZ asset ID is %s', assetId);
650 console.log('Sponsoring random Account.......');
651 const tx10 = api.tx.balances.transfer(randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
652 const events10 = await submitTransactionAsync(baltatharAccount, tx10);632 console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');
653 const result10 = getGenericResult(events10);
654 expect(result10.success).to.be.true;
655 console.log('Sponsoring random Account.......DONE');
656 // <<< Sponsoring random Account <<<633 // >>> Acquire Quartz AssetId Info on Moonriver >>>
657634
658 [balanceMovrTokenInit] = await getBalance(api, [randomAccountMoonriver.address]);635 // >>> Sponsoring random Account >>>
636 console.log('Sponsoring random Account.......');
637 // const tx10 = api.tx.balances.transfer(randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
659 },638 // const events10 = await submitTransactionAsync(baltatharAccount, tx10);
660 moonriverOptions(),639 // const result10 = getGenericResult(events10);
640 // expect(result10.success).to.be.true;
641 await helper.balance.transferToSubstrate(baltatharAccount, randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
661 );642 console.log('Sponsoring random Account.......DONE');
643 // <<< Sponsoring random Account <<<
662644
663 await usingApi(async (api) => {645 // [balanceMovrTokenInit] = await getBalance(api, [randomAccountMoonriver.address]);
664 const tx0 = api.tx.balances.transfer(randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);
665 const events0 = await submitTransactionAsync(quartzAlice, tx0);646 balanceMovrTokenInit = await helper.balance.getSubstrate(randomAccountMoonriver.address);
666 const result0 = getGenericResult(events0);647 });
667 expect(result0.success).to.be.true;
668648
669 [balanceQuartzTokenInit] = await getBalance(api, [randomAccountQuartz.address]);649 await usingPlaygrounds(async (helper) => {
650 // const tx0 = api.tx.balances.transfer(randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);
651 // const events0 = await submitTransactionAsync(quartzAlice, tx0);
652 // const result0 = getGenericResult(events0);
653 // expect(result0.success).to.be.true;
654 await helper.balance.transferToSubstrate(quartzAlice, randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);
655
656 // [balanceQuartzTokenInit] = await getBalance(api, [randomAccountQuartz.address]);
657 balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccountQuartz.address);
670 });658 });
671 });659 });
672660
673 it('Should connect and send QTZ to Moonriver', async () => {661 itSub('Should connect and send QTZ to Moonriver', async ({helper}) => {
674 await usingApi(async (api) => {
675 const currencyId = {662 const currencyId = {
676 NativeAssetId: 'Here',663 NativeAssetId: 'Here',
677 };664 };
678 const dest = {665 const dest = {
679 V1: {666 V1: {
680 parents: 1,667 parents: 1,
681 interior: {668 interior: {
682 X2: [669 X2: [
683 {Parachain: MOONRIVER_CHAIN},670 {Parachain: MOONRIVER_CHAIN},
684 {AccountKey20: {network: 'Any', key: randomAccountMoonriver.address}},671 {AccountKey20: {network: 'Any', key: randomAccountMoonriver.address}},
685 ],672 ],
686 },
687 },673 },
688 };674 },
689 const amount = TRANSFER_AMOUNT;675 };
676 const amount = TRANSFER_AMOUNT;
690 const destWeight = 850000000;677 const destWeight = 850000000;
691678
692 const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);679 // TODO
680 const tx = helper.getApi().tx.xTokens.transfer(currencyId, amount, dest, destWeight);
693 const events = await submitTransactionAsync(randomAccountQuartz, tx);681 const events = await submitTransactionAsync(randomAccountQuartz, tx);
694 const result = getGenericResult(events);682 const result = getGenericResult(events);
695 expect(result.success).to.be.true;683 expect(result.success).to.be.true;
696684
697 [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccountQuartz.address]);685 // [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccountQuartz.address]);
698 expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;686 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccountQuartz.address);
687 expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;
699688
700 const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;689 const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
701 console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', bigIntToDecimals(transactionFees));690 console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', bigIntToDecimals(transactionFees));
702 expect(transactionFees > 0).to.be.true;691 expect(transactionFees > 0).to.be.true;
703 });
704692
705 await usingApi(693 await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {
706 async (api) => {
707 await waitNewBlocks(api, 3);694 // await waitNewBlocks(api, 3);
695 await helper.wait.newBlocks(3);
708696
709 [balanceMovrTokenMiddle] = await getBalance(api, [randomAccountMoonriver.address]);697 // [balanceMovrTokenMiddle] = await getBalance(api, [randomAccountMoonriver.address]);
698 balanceMovrTokenMiddle = await helper.balance.getSubstrate(randomAccountMoonriver.address);
710699
711 const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;700 const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;
712 console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',bigIntToDecimals(movrFees));701 console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',bigIntToDecimals(movrFees));
713 expect(movrFees == 0n).to.be.true;702 expect(movrFees == 0n).to.be.true;
714703
715 const qtzRandomAccountAsset = (704 // TODO
705 const qtzRandomAccountAsset = (
716 await api.query.assets.account(assetId, randomAccountMoonriver.address)706 await helper.getApi().query.assets.account(assetId, randomAccountMoonriver.address)
717 ).toJSON()! as any;707 ).toJSON()! as any;
718708
719 balanceForeignQtzTokenMiddle = BigInt(qtzRandomAccountAsset['balance']);709 balanceForeignQtzTokenMiddle = BigInt(qtzRandomAccountAsset['balance']);
720 const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;710 const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;
721 console.log('[Quartz -> Moonriver] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));711 console.log('[Quartz -> Moonriver] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
722 expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;712 expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
723 },713 });
724 moonriverOptions(),
725 );
726 });714 });
727715
728 it('Should connect to Moonriver and send QTZ back', async () => {716 itSub('Should connect to Moonriver and send QTZ back', async ({helper}) => {
729 await usingApi(717 await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {
730 async (api) => {
731 const asset = {718 const asset = {
732 V1: {719 V1: {
733 id: {720 id: {
734 Concrete: {721 Concrete: {
735 parents: 1,722 parents: 1,
736 interior: {723 interior: {
737 X1: {Parachain: QUARTZ_CHAIN},724 X1: {Parachain: QUARTZ_CHAIN},
738 },
739 },725 },
740 },726 },
741 fun: {
742 Fungible: TRANSFER_AMOUNT,
743 },
744 },727 },
745 };728 fun: {
746 const destination = {
747 V1: {
748 parents: 1,729 Fungible: TRANSFER_AMOUNT,
749 interior: {
750 X2: [
751 {Parachain: QUARTZ_CHAIN},
752 {AccountId32: {network: 'Any', id: randomAccountQuartz.addressRaw}},
753 ],
754 },
755 },730 },
756 };731 },
732 };
757 const destWeight = 50000000;733 const destination = {
734 V1: {
735 parents: 1,
736 interior: {
737 X2: [
738 {Parachain: QUARTZ_CHAIN},
739 {AccountId32: {network: 'Any', id: randomAccountQuartz.addressRaw}},
740 ],
741 },
742 },
743 };
744 const destWeight = 50000000;
758745
759 const tx = api.tx.xTokens.transferMultiasset(asset, destination, destWeight);746 // TODO
747 const tx = helper.getApi().tx.xTokens.transferMultiasset(asset, destination, destWeight);
760 const events = await submitTransactionAsync(randomAccountMoonriver, tx);748 const events = await submitTransactionAsync(randomAccountMoonriver, tx);
761 const result = getGenericResult(events);749 const result = getGenericResult(events);
762 expect(result.success).to.be.true;750 expect(result.success).to.be.true;
763751
764 [balanceMovrTokenFinal] = await getBalance(api, [randomAccountMoonriver.address]);752 // [balanceMovrTokenFinal] = await getBalance(api, [randomAccountMoonriver.address]);
753 balanceMovrTokenFinal = await helper.balance.getSubstrate(randomAccountMoonriver.address);
765754
766 const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;755 const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;
767 console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', bigIntToDecimals(movrFees));756 console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', bigIntToDecimals(movrFees));
768 expect(movrFees > 0).to.be.true;757 expect(movrFees > 0).to.be.true;
769758
770 const qtzRandomAccountAsset = (759 const qtzRandomAccountAsset = (
771 await api.query.assets.account(assetId, randomAccountMoonriver.address)760 await helper.getApi().query.assets.account(assetId, randomAccountMoonriver.address)
772 ).toJSON()! as any;761 ).toJSON()! as any;
773762
774 expect(qtzRandomAccountAsset).to.be.null;763 expect(qtzRandomAccountAsset).to.be.null;
775764
776 balanceForeignQtzTokenFinal = 0n;765 balanceForeignQtzTokenFinal = 0n;
777766
778 const qtzOutcomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenFinal;767 const qtzOutcomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenFinal;
779 console.log('[Quartz -> Moonriver] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));768 console.log('[Quartz -> Moonriver] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
780 expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;769 expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
781 },770 });
782 moonriverOptions(),
783 );
784771
785 await usingApi(async (api) => {772 // await waitNewBlocks(api, 3);
786 await waitNewBlocks(api, 3);773 await helper.wait.newBlocks(3);
787774
788 [balanceQuartzTokenFinal] = await getBalance(api, [randomAccountQuartz.address]);775 // [balanceQuartzTokenFinal] = await getBalance(api, [randomAccountQuartz.address]);
789 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;776 balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccountQuartz.address);
777 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
790 expect(actuallyDelivered > 0).to.be.true;778 expect(actuallyDelivered > 0).to.be.true;
791779
792 console.log('[Moonriver -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));780 console.log('[Moonriver -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
793781
794 const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;782 const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
795 console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));783 console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
796 expect(qtzFees == 0n).to.be.true;784 expect(qtzFees == 0n).to.be.true;
797 });
798 });785 });
799});786});
800787
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
16
17import chai from 'chai';
18import chaiAsPromised from 'chai-as-promised';
1916
20import {WsProvider, Keyring} from '@polkadot/api';17import {Keyring} from '@polkadot/api';
21import {ApiOptions} from '@polkadot/api/types';
22import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';19import {submitTransactionAsync} from '../substrate/substrate-api';
24import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../deprecated-helpers/helpers';20import {getGenericResult, generateKeyringPair, waitEvent, bigIntToDecimals} from '../deprecated-helpers/helpers';
25import {MultiLocation} from '@polkadot/types/interfaces';21import {MultiLocation} from '@polkadot/types/interfaces';
26import {blake2AsHex} from '@polkadot/util-crypto';22import {blake2AsHex} from '@polkadot/util-crypto';
27import waitNewBlocks from '../substrate/wait-new-blocks';
28import getBalance from '../substrate/get-balance';23import getBalance from '../substrate/get-balance';
29import {XcmV2TraitsError, XcmV2TraitsOutcome} from '../interfaces';24import {XcmV2TraitsError, XcmV2TraitsOutcome} from '../interfaces';
30
31chai.use(chaiAsPromised);
32const expect = chai.expect;25import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';
3326
34const UNIQUE_CHAIN = 2037;27const UNIQUE_CHAIN = 2037;
35const ACALA_CHAIN = 2000;28const ACALA_CHAIN = 2000;
39const ACALA_PORT = 9946;32const ACALA_PORT = 9946;
40const MOONBEAM_PORT = 9947;33const MOONBEAM_PORT = 9947;
4134
42const ACALA_DECIMALS = 12;35const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;
43
44const TRANSFER_AMOUNT = 2000000000000000000000000n;36const acalaUrl = 'ws://127.0.0.1:' + ACALA_PORT;
45
46function parachainApiOptions(port: number): ApiOptions {
47 return {
48 provider: new WsProvider('ws://127.0.0.1:' + port.toString()),37const moonbeamUrl = 'ws://127.0.0.1:' + MOONBEAM_PORT;
49 };38
50}
51
52function acalaOptions(): ApiOptions {
53 return parachainApiOptions(ACALA_PORT);39const ACALA_DECIMALS = 12;
54}40
55
56function moonbeamOptions(): ApiOptions {
57 return parachainApiOptions(MOONBEAM_PORT);41const TRANSFER_AMOUNT = 2000000000000000000000000n;
58}
59
60function relayOptions(): ApiOptions {
61 return parachainApiOptions(RELAY_PORT);
62}
6342
64describe_xcm('[XCM] Integration test: Exchanging tokens with Acala', () => {43describeXcm('[XCM] Integration test: Exchanging tokens with Acala', () => {
65 let alice: IKeyringPair;44 let alice: IKeyringPair;
66 let randomAccount: IKeyringPair;45 let randomAccount: IKeyringPair;
6746
76 let balanceUniqueForeignTokenFinal: bigint;55 let balanceUniqueForeignTokenFinal: bigint;
7756
78 before(async () => {57 before(async () => {
79 await usingApi(async (api, privateKeyWrapper) => {58 await usingPlaygrounds(async (_helper, privateKey) => {
80 const keyringSr25519 = new Keyring({type: 'sr25519'});59 const keyringSr25519 = new Keyring({type: 'sr25519'});
8160
82 alice = privateKeyWrapper('//Alice');61 alice = privateKey('//Alice');
83 randomAccount = generateKeyringPair(keyringSr25519);62 randomAccount = generateKeyringPair(keyringSr25519);
84 });63 });
8564
86 // Acala side65 // Acala side
87 await usingApi(66 await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {
88 async (api) => {
89 const destination = {67 const destination = {
90 V0: {68 V0: {
91 X2: [69 X2: [
104 minimalBalance: 1,82 minimalBalance: 1,
105 };83 };
10684
85 // TODO
107 const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);86 const tx = helper.getApi().tx.assetRegistry.registerForeignAsset(destination, metadata);
108 const sudoTx = api.tx.sudo.sudo(tx as any);87 const sudoTx = helper.getApi().tx.sudo.sudo(tx as any);
109 const events = await submitTransactionAsync(alice, sudoTx);88 const events = await submitTransactionAsync(alice, sudoTx);
110 const result = getGenericResult(events);89 const result = getGenericResult(events);
111 expect(result.success).to.be.true;90 expect(result.success).to.be.true;
11291
92 // const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
93 // const events1 = await submitTransactionAsync(alice, tx1);
94 // const result1 = getGenericResult(events1);
95 // expect(result1.success).to.be.true;
113 const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);96 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10000000000000n);
114 const events1 = await submitTransactionAsync(alice, tx1);97
115 const result1 = getGenericResult(events1);98 // [balanceAcalaTokenInit] = await getBalance(api, [randomAccount.address]);
116 expect(result1.success).to.be.true;
117
118 [balanceAcalaTokenInit] = await getBalance(api, [randomAccount.address]);99 balanceAcalaTokenInit = await helper.balance.getSubstrate(randomAccount.address);
119 {100 {
101 // TODO
120 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;102 const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
121 balanceUniqueForeignTokenInit = BigInt(free);103 balanceUniqueForeignTokenInit = BigInt(free);
122 }104 }
123 },105 });
124 acalaOptions(),
125 );
126106
127 // Unique side107 // Unique side
128 await usingApi(async (api) => {108 await usingPlaygrounds(async (helper) => {
109 // const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);
110 // const events0 = await submitTransactionAsync(alice, tx0);
111 // const result0 = getGenericResult(events0);
112 // expect(result0.success).to.be.true;
129 const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);113 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);
130 const events0 = await submitTransactionAsync(alice, tx0);114
131 const result0 = getGenericResult(events0);115 // [balanceUniqueTokenInit] = await getBalance(api, [randomAccount.address]);
132 expect(result0.success).to.be.true;
133
134 [balanceUniqueTokenInit] = await getBalance(api, [randomAccount.address]);116 balanceUniqueTokenInit = await helper.balance.getSubstrate(randomAccount.address);
135 });117 });
136 });118 });
137119
138 it('Should connect and send UNQ to Acala', async () => {120 itSub('Should connect and send UNQ to Acala', async ({helper}) => {
139121
140 // Unique side122 // Unique side
141 await usingApi(async (api) => {
142
143 const destination = {123 const destination = {
144 V0: {124 V0: {
184 Limited: 5000000000,164 Limited: 5000000000,
185 };165 };
186166
167 // TODO
187 const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);168 const tx = helper.getApi().tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
188 const events = await submitTransactionAsync(randomAccount, tx);169 const events = await submitTransactionAsync(randomAccount, tx);
189 const result = getGenericResult(events);170 const result = getGenericResult(events);
190 expect(result.success).to.be.true;171 expect(result.success).to.be.true;
191172
173 // [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);
192 [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);174 balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
193175
194 const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;176 const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
195 console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));177 console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
196 expect(unqFees > 0n).to.be.true;178 expect(unqFees > 0n).to.be.true;
197 });
198179
199 // Acala side180 // Acala side
200 await usingApi(181 await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {
201 async (api) => {182 // await waitNewBlocks(api, 3);
202 await waitNewBlocks(api, 3);183 await helper.wait.newBlocks(3);
184
185 // TODO
203 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;186 const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
204 balanceUniqueForeignTokenMiddle = BigInt(free);187 balanceUniqueForeignTokenMiddle = BigInt(free);
205188
189 // [balanceAcalaTokenMiddle] = await getBalance(api, [randomAccount.address]);
206 [balanceAcalaTokenMiddle] = await getBalance(api, [randomAccount.address]);190 balanceAcalaTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
207191
208 const acaFees = balanceAcalaTokenInit - balanceAcalaTokenMiddle;192 const acaFees = balanceAcalaTokenInit - balanceAcalaTokenMiddle;
209 const unqIncomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenInit;193 const unqIncomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenInit;
215 console.log('[Unique -> Acala] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));199 console.log('[Unique -> Acala] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));
216 expect(acaFees == 0n).to.be.true;200 expect(acaFees == 0n).to.be.true;
217 expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;201 expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
218 },202 });
219 acalaOptions(),
220 );
221 });203 });
222204
223 it('Should connect to Acala and send UNQ back', async () => {205 itSub('Should connect to Acala and send UNQ back', async ({helper}) => {
224206
225 // Acala side207 // Acala side
226 await usingApi(208 await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {
227 async (api) => {
228 const destination = {209 const destination = {
229 V1: {210 V1: {
230 parents: 1,211 parents: 1,
248229
249 const destWeight = 50000000;230 const destWeight = 50000000;
250231
232 // TODO
251 const tx = api.tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);233 const tx = helper.getApi().tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
252 const events = await submitTransactionAsync(randomAccount, tx);234 const events = await submitTransactionAsync(randomAccount, tx);
253 const result = getGenericResult(events);235 const result = getGenericResult(events);
254 expect(result.success).to.be.true;236 expect(result.success).to.be.true;
255237
238 // [balanceAcalaTokenFinal] = await getBalance(api, [randomAccount.address]);
256 [balanceAcalaTokenFinal] = await getBalance(api, [randomAccount.address]);239 balanceAcalaTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
257 {240 {
241 // TODO
258 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;242 const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;
259 balanceUniqueForeignTokenFinal = BigInt(free);243 balanceUniqueForeignTokenFinal = BigInt(free);
260 }244 }
261245
270254
271 expect(acaFees > 0).to.be.true;255 expect(acaFees > 0).to.be.true;
272 expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;256 expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
273 },257 });
274 acalaOptions(),258
275 );259 // await waitNewBlocks(api, 3);
276
277 // Unique side
278 await usingApi(async (api) => {
279 await waitNewBlocks(api, 3);260 await helper.wait.newBlocks(3);
280261
262 // [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);
281 [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);263 balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
282 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;264 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
283 expect(actuallyDelivered > 0).to.be.true;265 expect(actuallyDelivered > 0).to.be.true;
284266
287 const unqFees = TRANSFER_AMOUNT - actuallyDelivered;269 const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
288 console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));270 console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
289 expect(unqFees == 0n).to.be.true;271 expect(unqFees == 0n).to.be.true;
290 });
291 });272 });
292});273});
293274
294// These tests are relevant only when the foreign asset pallet is disabled275// These tests are relevant only when the foreign asset pallet is disabled
295describe_xcm('[XCM] Integration test: Unique rejects non-native tokens', () => {276describeXcm('[XCM] Integration test: Unique rejects non-native tokens', () => {
296 let alice: IKeyringPair;277 let alice: IKeyringPair;
297278
298 before(async () => {279 before(async () => {
299 await usingApi(async (api, privateKeyWrapper) => {280 await usingPlaygrounds(async (_helper, privateKey) => {
300 alice = privateKeyWrapper('//Alice');281 alice = privateKey('//Alice');
301 });282 });
302 });283 });
303284
304 it('Unique rejects tokens from the Relay', async () => {285 itSub('Unique rejects tokens from the Relay', async ({helper}) => {
305 await usingApi(async (api) => {286 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {
306 const destination = {287 const destination = {
307 V1: {288 V1: {
308 parents: 0,289 parents: 0,
346 Limited: 5_000_000_000,327 Limited: 5_000_000_000,
347 };328 };
348329
330 // TODO
349 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);331 const tx = helper.getApi().tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
350 const events = await submitTransactionAsync(alice, tx);332 const events = await submitTransactionAsync(alice, tx);
351 const result = getGenericResult(events);333 const result = getGenericResult(events);
352 expect(result.success).to.be.true;334 expect(result.success).to.be.true;
353 }, relayOptions());335 });
354336
355 await usingApi(async api => {
356 const maxWaitBlocks = 3;337 const maxWaitBlocks = 3;
338
339 // TODO
357 const dmpQueueExecutedDownward = await waitEvent(340 const dmpQueueExecutedDownward = await waitEvent(
358 api,341 helper.getApi(),
359 maxWaitBlocks,342 maxWaitBlocks,
360 'dmpQueue',343 'dmpQueue',
361 'ExecutedDownward',344 'ExecutedDownward',
379 incomplete[1].toString() == 'AssetNotFound',362 incomplete[1].toString() == 'AssetNotFound',
380 '[Relay] The XCM error should be `AssetNotFound`',363 '[Relay] The XCM error should be `AssetNotFound`',
381 ).to.be.true;364 ).to.be.true;
382 });
383 });365 });
384366
385 it('Unique rejects ACA tokens from Acala', async () => {367 itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {
386 await usingApi(async (api) => {368 await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {
387 const destination = {369 const destination = {
388 V1: {370 V1: {
389 parents: 1,371 parents: 1,
407389
408 const destWeight = 50000000;390 const destWeight = 50000000;
409391
392 // TODO
410 const tx = api.tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);393 const tx = helper.getApi().tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
411 const events = await submitTransactionAsync(alice, tx);394 const events = await submitTransactionAsync(alice, tx);
412 const result = getGenericResult(events);395 const result = getGenericResult(events);
413 expect(result.success).to.be.true;396 expect(result.success).to.be.true;
414 }, acalaOptions());397 });
415398
416 await usingApi(async api => {
417 const maxWaitBlocks = 3;399 const maxWaitBlocks = 3;
400
401 // TODO
418 const xcmpQueueFailEvent = await waitEvent(api, maxWaitBlocks, 'xcmpQueue', 'Fail');402 const xcmpQueueFailEvent = await waitEvent(helper.getApi(), maxWaitBlocks, 'xcmpQueue', 'Fail');
419403
420 expect(404 expect(
421 xcmpQueueFailEvent != null,405 xcmpQueueFailEvent != null,
429 outcome.isUntrustedReserveLocation,413 outcome.isUntrustedReserveLocation,
430 '[Acala] The XCM error should be `UntrustedReserveLocation`',414 '[Acala] The XCM error should be `UntrustedReserveLocation`',
431 ).to.be.true;415 ).to.be.true;
432 });
433 });416 });
434});417});
435418
436describe_xcm('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => {419describeXcm('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => {
437420
438 // Unique constants421 // Unique constants
439 let uniqueAlice: IKeyringPair;422 let uniqueAlice: IKeyringPair;
478 let balanceGlmrTokenFinal: bigint;461 let balanceGlmrTokenFinal: bigint;
479462
480 before(async () => {463 before(async () => {
481 await usingApi(async (api, privateKeyWrapper) => {464 await usingPlaygrounds(async (_helper, privateKey) => {
482 const keyringEth = new Keyring({type: 'ethereum'});465 const keyringEth = new Keyring({type: 'ethereum'});
483 const keyringSr25519 = new Keyring({type: 'sr25519'});466 const keyringSr25519 = new Keyring({type: 'sr25519'});
484467
485 uniqueAlice = privateKeyWrapper('//Alice');468 uniqueAlice = privateKey('//Alice');
486 randomAccountUnique = generateKeyringPair(keyringSr25519);469 randomAccountUnique = generateKeyringPair(keyringSr25519);
487 randomAccountMoonbeam = generateKeyringPair(keyringEth);470 randomAccountMoonbeam = generateKeyringPair(keyringEth);
488471
489 balanceForeignUnqTokenInit = 0n;472 balanceForeignUnqTokenInit = 0n;
490 });473 });
491474
492 await usingApi(475 await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {
493 async (api) => {476 // TODO
477
478 const api = helper.getApi();
494479
495 // >>> Sponsoring Dorothy >>>480 // >>> Sponsoring Dorothy >>>
496 console.log('Sponsoring Dorothy.......');481 console.log('Sponsoring Dorothy.......');
482 // const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);
483 // const events0 = await submitTransactionAsync(alithAccount, tx0);
484 // const result0 = getGenericResult(events0);
485 // expect(result0.success).to.be.true;
497 const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);486 await helper.balance.transferToSubstrate(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);
498 const events0 = await submitTransactionAsync(alithAccount, tx0);
499 const result0 = getGenericResult(events0);
500 expect(result0.success).to.be.true;
501 console.log('Sponsoring Dorothy.......DONE');487 console.log('Sponsoring Dorothy.......DONE');
502 // <<< Sponsoring Dorothy <<<488 // <<< Sponsoring Dorothy <<<
503489
636 console.log('Acquire Unique AssetId Info on Moonbeam.......');622 console.log('Acquire Unique AssetId Info on Moonbeam.......');
637623
638 // Wait for the democracy execute624 // Wait for the democracy execute
625 // await waitNewBlocks(api, 5);
639 await waitNewBlocks(api, 5);626 await helper.wait.newBlocks(5);
640627
641 assetId = (await api.query.assetManager.assetTypeId({628 assetId = (await api.query.assetManager.assetTypeId({
642 XCM: sourceLocation,629 XCM: sourceLocation,
648635
649 // >>> Sponsoring random Account >>>636 // >>> Sponsoring random Account >>>
650 console.log('Sponsoring random Account.......');637 console.log('Sponsoring random Account.......');
638 // const tx10 = api.tx.balances.transfer(randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);
639 // const events10 = await submitTransactionAsync(baltatharAccount, tx10);
640 // const result10 = getGenericResult(events10);
641 // expect(result10.success).to.be.true;
651 const tx10 = api.tx.balances.transfer(randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);642 await helper.balance.transferToSubstrate(baltatharAccount, randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);
652 const events10 = await submitTransactionAsync(baltatharAccount, tx10);
653 const result10 = getGenericResult(events10);
654 expect(result10.success).to.be.true;
655 console.log('Sponsoring random Account.......DONE');643 console.log('Sponsoring random Account.......DONE');
656 // <<< Sponsoring random Account <<<644 // <<< Sponsoring random Account <<<
657645
658 [balanceGlmrTokenInit] = await getBalance(api, [randomAccountMoonbeam.address]);646 [balanceGlmrTokenInit] = await getBalance(api, [randomAccountMoonbeam.address]);
659 },647 });
660 moonbeamOptions(),
661 );
662648
663 await usingApi(async (api) => {649 await usingPlaygrounds(async (helper) => {
650 // const tx0 = api.tx.balances.transfer(randomAccountUnique.address, 10n * TRANSFER_AMOUNT);
651 // const events0 = await submitTransactionAsync(uniqueAlice, tx0);
652 // const result0 = getGenericResult(events0);
653 // expect(result0.success).to.be.true;
664 const tx0 = api.tx.balances.transfer(randomAccountUnique.address, 10n * TRANSFER_AMOUNT);654 await helper.balance.transferToSubstrate(uniqueAlice, randomAccountUnique.address, 10n * TRANSFER_AMOUNT);
665 const events0 = await submitTransactionAsync(uniqueAlice, tx0);655
666 const result0 = getGenericResult(events0);656 // [balanceUniqueTokenInit] = await getBalance(api, [randomAccountUnique.address]);
667 expect(result0.success).to.be.true;
668
669 [balanceUniqueTokenInit] = await getBalance(api, [randomAccountUnique.address]);657 balanceUniqueTokenInit = await helper.balance.getSubstrate(randomAccountUnique.address);
670 });658 });
671 });659 });
672660
673 it('Should connect and send UNQ to Moonbeam', async () => {661 itSub('Should connect and send UNQ to Moonbeam', async ({helper}) => {
674 await usingApi(async (api) => {
675 const currencyId = {662 const currencyId = {
676 NativeAssetId: 'Here',663 NativeAssetId: 'Here',
677 };664 };
689 const amount = TRANSFER_AMOUNT;676 const amount = TRANSFER_AMOUNT;
690 const destWeight = 850000000;677 const destWeight = 850000000;
691678
679 // TODO
692 const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);680 const tx = helper.getApi().tx.xTokens.transfer(currencyId, amount, dest, destWeight);
693 const events = await submitTransactionAsync(randomAccountUnique, tx);681 const events = await submitTransactionAsync(randomAccountUnique, tx);
694 const result = getGenericResult(events);682 const result = getGenericResult(events);
695 expect(result.success).to.be.true;683 expect(result.success).to.be.true;
696684
685 // [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccountUnique.address]);
697 [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccountUnique.address]);686 balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccountUnique.address);
698 expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;687 expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;
699688
700 const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;689 const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
701 console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', bigIntToDecimals(transactionFees));690 console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', bigIntToDecimals(transactionFees));
702 expect(transactionFees > 0).to.be.true;691 expect(transactionFees > 0).to.be.true;
703 });
704692
705 await usingApi(693 await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {
706 async (api) => {694 // await waitNewBlocks(api, 3);
707 await waitNewBlocks(api, 3);695 await helper.wait.newBlocks(3);
708696
697 // [balanceGlmrTokenMiddle] = await getBalance(api, [randomAccountMoonbeam.address]);
709 [balanceGlmrTokenMiddle] = await getBalance(api, [randomAccountMoonbeam.address]);698 balanceGlmrTokenMiddle = await helper.balance.getSubstrate(randomAccountMoonbeam.address);
710699
711 const glmrFees = balanceGlmrTokenInit - balanceGlmrTokenMiddle;700 const glmrFees = balanceGlmrTokenInit - balanceGlmrTokenMiddle;
712 console.log('[Unique -> Moonbeam] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));701 console.log('[Unique -> Moonbeam] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));
713 expect(glmrFees == 0n).to.be.true;702 expect(glmrFees == 0n).to.be.true;
714703
704 // TODO
715 const unqRandomAccountAsset = (705 const unqRandomAccountAsset = (
716 await api.query.assets.account(assetId, randomAccountMoonbeam.address)706 await helper.getApi().query.assets.account(assetId, randomAccountMoonbeam.address)
717 ).toJSON()! as any;707 ).toJSON()! as any;
718708
719 balanceForeignUnqTokenMiddle = BigInt(unqRandomAccountAsset['balance']);709 balanceForeignUnqTokenMiddle = BigInt(unqRandomAccountAsset['balance']);
720 const unqIncomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenInit;710 const unqIncomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenInit;
721 console.log('[Unique -> Moonbeam] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));711 console.log('[Unique -> Moonbeam] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));
722 expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;712 expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
723 },713 });
724 moonbeamOptions(),
725 );
726 });714 });
727715
728 it('Should connect to Moonbeam and send UNQ back', async () => {716 itSub('Should connect to Moonbeam and send UNQ back', async ({helper}) => {
729 await usingApi(717 await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {
730 async (api) => {
731 const asset = {718 const asset = {
732 V1: {719 V1: {
733 id: {720 id: {
756 };743 };
757 const destWeight = 50000000;744 const destWeight = 50000000;
758745
746 // TODO
759 const tx = api.tx.xTokens.transferMultiasset(asset, destination, destWeight);747 const tx = helper.getApi().tx.xTokens.transferMultiasset(asset, destination, destWeight);
760 const events = await submitTransactionAsync(randomAccountMoonbeam, tx);748 const events = await submitTransactionAsync(randomAccountMoonbeam, tx);
761 const result = getGenericResult(events);749 const result = getGenericResult(events);
762 expect(result.success).to.be.true;750 expect(result.success).to.be.true;
763751
752 // [balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);
764 [balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);753 balanceGlmrTokenFinal = await helper.balance.getSubstrate(randomAccountMoonbeam.address);
765754
766 const glmrFees = balanceGlmrTokenMiddle - balanceGlmrTokenFinal;755 const glmrFees = balanceGlmrTokenMiddle - balanceGlmrTokenFinal;
767 console.log('[Moonbeam -> Unique] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));756 console.log('[Moonbeam -> Unique] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));
768 expect(glmrFees > 0).to.be.true;757 expect(glmrFees > 0).to.be.true;
769758
759 // TODO
770 const unqRandomAccountAsset = (760 const unqRandomAccountAsset = (
771 await api.query.assets.account(assetId, randomAccountMoonbeam.address)761 await helper.getApi().query.assets.account(assetId, randomAccountMoonbeam.address)
772 ).toJSON()! as any;762 ).toJSON()! as any;
773763
774 expect(unqRandomAccountAsset).to.be.null;764 expect(unqRandomAccountAsset).to.be.null;
778 const unqOutcomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenFinal;768 const unqOutcomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenFinal;
779 console.log('[Unique -> Moonbeam] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));769 console.log('[Unique -> Moonbeam] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));
780 expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;770 expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
781 },771 });
782 moonbeamOptions(),772
783 );773 // await waitNewBlocks(api, 3);
784
785 await usingApi(async (api) => {
786 await waitNewBlocks(api, 3);774 await helper.wait.newBlocks(3);
787775
776 // [balanceUniqueTokenFinal] = await getBalance(api, [randomAccountUnique.address]);
788 [balanceUniqueTokenFinal] = await getBalance(api, [randomAccountUnique.address]);777 balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccountUnique.address);
789 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;778 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
790 expect(actuallyDelivered > 0).to.be.true;779 expect(actuallyDelivered > 0).to.be.true;
791780
794 const unqFees = TRANSFER_AMOUNT - actuallyDelivered;783 const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
795 console.log('[Moonbeam -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));784 console.log('[Moonbeam -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
796 expect(unqFees == 0n).to.be.true;785 expect(unqFees == 0n).to.be.true;
797 });
798 });786 });
799});787});
800788