git.delta.rocks / unique-network / refs/commits / 59c98d647e2d

difftreelog

fix xcm quartz test

Daniel Shiposha2022-12-21parent: #b756528.patch.diff
in: master

1 file changed

modifiedtests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth
3737
38const TRANSFER_AMOUNT = 2000000000000000000000000n;38const TRANSFER_AMOUNT = 2000000000000000000000000n;
39
40const FUNDING_AMOUNT = 3_500_000_0000_000_000n;
41
42const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;
3943
40const USDT_ASSET_ID = 100;44const USDT_ASSET_ID = 100;
41const USDT_ASSET_METADATA_DECIMALS = 18;45const USDT_ASSET_METADATA_DECIMALS = 18;
42const USDT_ASSET_METADATA_NAME = 'USDT';46const USDT_ASSET_METADATA_NAME = 'USDT';
43const USDT_ASSET_METADATA_DESCRIPTION = 'USDT';47const USDT_ASSET_METADATA_DESCRIPTION = 'USDT';
44const USDT_ASSET_METADATA_MINIMAL_BALANCE = 1n;48const USDT_ASSET_METADATA_MINIMAL_BALANCE = 1n;
49const USDT_ASSET_AMOUNT = 10_000_000_000_000_000_000_000_000n;
4550
46describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => {51describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => {
47 let alice: IKeyringPair;52 let alice: IKeyringPair;
65 before(async () => {70 before(async () => {
66 await usingPlaygrounds(async (_helper, privateKey) => {71 await usingPlaygrounds(async (_helper, privateKey) => {
67 alice = await privateKey('//Alice');72 alice = await privateKey('//Alice');
68 bob = await privateKey('//Bob'); // funds donor73 bob = await privateKey('//Bob'); // sovereign account on Statemine(t) funds donor
69 });74 });
75
76 await usingRelayPlaygrounds(relayUrl, async (helper) => {
77 // Fund accounts on Statemine(t)
78 await helper.xcm.teleportNativeAsset(alice, STATEMINE_CHAIN, alice.addressRaw, FUNDING_AMOUNT);
79 await helper.xcm.teleportNativeAsset(alice, STATEMINE_CHAIN, bob.addressRaw, FUNDING_AMOUNT);
80 });
7081
71 await usingStateminePlaygrounds(statemineUrl, async (helper) => {82 await usingStateminePlaygrounds(statemineUrl, async (helper) => {
72 // 350.00 (three hundred fifty) DOT
73 const fundingAmount = 3_500_000_000_000n; 83 const sovereignFundingAmount = 3_500_000_000n;
7484
75 await helper.assets.create(85 await helper.assets.create(
76 alice,86 alice,
89 alice,99 alice,
90 USDT_ASSET_ID,100 USDT_ASSET_ID,
91 alice.address,101 alice.address,
92 TRANSFER_AMOUNT,102 USDT_ASSET_AMOUNT,
93 );103 );
94104
95 // funding parachain sovereing account (Parachain: 2095)105 // funding parachain sovereing account on Statemine(t).
106 // The sovereign account should be created before any action
107 // (the assets pallet on Statemine(t) check if the sovereign account exists)
96 const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(QUARTZ_CHAIN);108 const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(QUARTZ_CHAIN);
97 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount);109 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, sovereignFundingAmount);
98 });110 });
99111
100112
128 });140 });
129141
130142
131 // Providing the relay currency to the unique sender account143 // Providing the relay currency to the quartz sender account
144 // (fee for USDT XCM are paid in relay tokens)
132 await usingRelayPlaygrounds(relayUrl, async (helper) => {145 await usingRelayPlaygrounds(relayUrl, async (helper) => {
133 const destination = {146 const destination = {
134 V1: {147 V1: {
161 },174 },
162 },175 },
163 fun: {176 fun: {
164 Fungible: TRANSFER_AMOUNT,177 Fungible: TRANSFER_AMOUNT_RELAY,
165 },178 },
166 },179 },
167 ],180 ],
168 };181 };
169182
170 const feeAssetItem = 0;183 const feeAssetItem = 0;
171 const weightLimit = 5_000_000_000;
172184
173 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, weightLimit);185 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, {Unlimited: null});
174 });186 });
175 187
176 });188 });
223 };235 };
224236
225 const feeAssetItem = 0;237 const feeAssetItem = 0;
226 const weightLimit = 5000000000;
227238
228 balanceStmnBefore = await helper.balance.getSubstrate(alice.address);239 balanceStmnBefore = await helper.balance.getSubstrate(alice.address);
229 await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, weightLimit);240 await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, {Unlimited: null});
230241
231 balanceStmnAfter = await helper.balance.getSubstrate(alice.address);242 balanceStmnAfter = await helper.balance.getSubstrate(alice.address);
232243
248259
249 balanceQuartzAfter = await helper.balance.getSubstrate(alice.address);260 balanceQuartzAfter = await helper.balance.getSubstrate(alice.address);
250261
251 // commission has not paid in USDT token262 console.log(
263 '[Quartz -> Statemine] transaction fees on Quartz: %s USDT',
252 expect(free == TRANSFER_AMOUNT).to.be.true;264 helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free, USDT_ASSET_METADATA_DECIMALS),
265 );
253 console.log(266 console.log(
254 '[Quartz -> Statemine] transaction fees on Quartz: %s USDT',267 '[Quartz -> Statemine] transaction fees on Quartz: %s QTZ',
255 helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free),268 helper.util.bigIntToDecimals(balanceQuartzAfter - balanceQuartzBefore),
256 );269 );
270 // commission has not paid in USDT token
271 expect(free).to.be.equal(TRANSFER_AMOUNT);
257 // ... and parachain native token272 // ... and parachain native token
258 expect(balanceQuartzAfter == balanceQuartzBefore).to.be.true;273 expect(balanceQuartzAfter == balanceQuartzBefore).to.be.true;
259 console.log(
260 '[Quartz -> Statemine] transaction fees on Quartz: %s WND',
261 helper.util.bigIntToDecimals(balanceQuartzAfter - balanceQuartzBefore, STATEMINE_DECIMALS),
262 );
263 });274 });
264275
265 itSub('Should connect and send USDT from Quartz to Statemine back', async ({helper}) => {276 itSub('Should connect and send USDT from Quartz to Statemine back', async ({helper}) => {
280 },291 },
281 };292 };
282293
294 const relayFee = 400_000_000_000_000n;
283 const currencies: [any, bigint][] = [295 const currencies: [any, bigint][] = [
284 [296 [
285 {297 {
286 ForeignAssetId: 0,298 ForeignAssetId: 0,
287 },299 },
288 //10_000_000_000_000_000n,
289 TRANSFER_AMOUNT,300 TRANSFER_AMOUNT,
290 ], 301 ],
291 [302 [
292 {303 {
293 NativeAssetId: 'Parent',304 NativeAssetId: 'Parent',
294 },305 },
295 400_000_000_000_000n,306 relayFee,
296 ],307 ],
297 ];308 ];
298309
299 const feeItem = 1;310 const feeItem = 1;
300 const destWeight = 500000000000;
301311
302 await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, destWeight);312 await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, {Unlimited: null});
303 313
304 // the commission has been paid in parachain native token314 // the commission has been paid in parachain native token
305 balanceQuartzFinal = await helper.balance.getSubstrate(alice.address);315 balanceQuartzFinal = await helper.balance.getSubstrate(alice.address);
310 320
311 // The USDT token never paid fees. Its amount not changed from begin value.321 // The USDT token never paid fees. Its amount not changed from begin value.
312 // Also check that xcm transfer has been succeeded 322 // Also check that xcm transfer has been succeeded
313 expect((await helper.assets.account(USDT_ASSET_ID, alice.address))! == TRANSFER_AMOUNT).to.be.true;323 expect((await helper.assets.account(USDT_ASSET_ID, alice.address))! == USDT_ASSET_AMOUNT).to.be.true;
314 });324 });
315 });325 });
316326
317 itSub('Should connect and send Relay token to Quartz', async ({helper}) => {327 itSub('Should connect and send Relay token to Quartz', async ({helper}) => {
318 balanceBobBefore = await helper.balance.getSubstrate(bob.address);328 balanceBobBefore = await helper.balance.getSubstrate(bob.address);
319 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});329 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});
320330
321 // Providing the relay currency to the unique sender account
322 await usingRelayPlaygrounds(relayUrl, async (helper) => {331 await usingRelayPlaygrounds(relayUrl, async (helper) => {
323 const destination = {332 const destination = {
324 V1: {333 V1: {
351 },360 },
352 },361 },
353 fun: {362 fun: {
354 Fungible: TRANSFER_AMOUNT,363 Fungible: TRANSFER_AMOUNT_RELAY,
355 },364 },
356 },365 },
357 ],366 ],
358 };367 };
359368
360 const feeAssetItem = 0;369 const feeAssetItem = 0;
361 const weightLimit = 5_000_000_000;
362370
363 await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, weightLimit);371 await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, {Unlimited: null});
364 });372 });
365 373
366 await helper.wait.newBlocks(3);374 await helper.wait.newBlocks(3);
367375
368 balanceBobAfter = await helper.balance.getSubstrate(bob.address); 376 balanceBobAfter = await helper.balance.getSubstrate(bob.address);
369 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});377 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});
370378
371 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT - balanceBobRelayTokenBefore; 379 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;
380 expect(wndFee > 0).to.be.true('westend fees should be greater than 0');
372 console.log(381 console.log(
373 '[Relay (Westend) -> Quartz] transaction fees: %s QTZ',382 '[Relay (Westend) -> Quartz] transaction fees: %s QTZ',
374 helper.util.bigIntToDecimals(balanceBobAfter - balanceBobBefore),383 helper.util.bigIntToDecimals(balanceBobAfter - balanceBobBefore),
404 {413 {
405 NativeAssetId: 'Parent',414 NativeAssetId: 'Parent',
406 },415 },
407 TRANSFER_AMOUNT,416 TRANSFER_AMOUNT_RELAY,
408 ],417 ],
409 ];418 ];
410419
411 const feeItem = 0;420 const feeItem = 0;
412 const destWeight = 500000000000;
413421
414 await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, destWeight);422 await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, {Unlimited: null});
415423
416 balanceBobFinal = await helper.balance.getSubstrate(bob.address);424 balanceBobFinal = await helper.balance.getSubstrate(bob.address);
417 console.log('[Relay (Westend) to Quartz] transaction fees: %s QTZ', balanceBobAfter - balanceBobFinal);425 console.log('[Relay (Westend) to Quartz] transaction fees: %s QTZ', balanceBobAfter - balanceBobFinal);
509 };517 };
510518
511 const feeAssetItem = 0;519 const feeAssetItem = 0;
512 const weightLimit = 5000000000;
513520
514 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, weightLimit);521 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, {Unlimited: null});
515 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);522 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
516523
517 const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;524 const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
525 expect(qtzFees > 0n).to.be.true('qtz Fees should be greater than 0');
518 console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(qtzFees));526 console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(qtzFees));
519 expect(qtzFees > 0n).to.be.true;
520527
521 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {528 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
522 await helper.wait.newBlocks(3);529 await helper.wait.newBlocks(3);
559 ForeignAsset: 0,566 ForeignAsset: 0,
560 };567 };
561
562 const destWeight = 50000000;
563568
564 await helper.xTokens.transfer(randomAccount, id, TRANSFER_AMOUNT, destination, destWeight);569 await helper.xTokens.transfer(randomAccount, id, TRANSFER_AMOUNT, destination, {Unlimited: null});
565 balanceKaruraTokenFinal = await helper.balance.getSubstrate(randomAccount.address);570 balanceKaruraTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
566 balanceQuartzForeignTokenFinal = await helper.tokens.accounts(randomAccount.address, id);571 balanceQuartzForeignTokenFinal = await helper.tokens.accounts(randomAccount.address, id);
567572
602 });607 });
603 });608 });
604
605 itSub('Quartz rejects tokens from the Relay', async ({helper}) => {
606 await usingRelayPlaygrounds(relayUrl, async (helper) => {
607 const destination = {
608 V1: {
609 parents: 0,
610 interior: {X1: {
611 Parachain: QUARTZ_CHAIN,
612 },
613 },
614 }};
615
616 const beneficiary = {
617 V1: {
618 parents: 0,
619 interior: {X1: {
620 AccountId32: {
621 network: 'Any',
622 id: alice.addressRaw,
623 },
624 }},
625 },
626 };
627
628 const assets = {
629 V1: [
630 {
631 id: {
632 Concrete: {
633 parents: 0,
634 interior: 'Here',
635 },
636 },
637 fun: {
638 Fungible: TRANSFER_AMOUNT,
639 },
640 },
641 ],
642 };
643
644 const feeAssetItem = 0;
645 const weightLimit = 5_000_000_000;
646
647 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, weightLimit);
648 });
649
650 const maxWaitBlocks = 3;
651
652 const dmpQueueExecutedDownward = await helper.wait.event(maxWaitBlocks, 'dmpQueue', 'ExecutedDownward');
653
654 expect(
655 dmpQueueExecutedDownward != null,
656 '[Relay] dmpQueue.ExecutedDownward event is expected',
657 ).to.be.true;
658
659 const event = dmpQueueExecutedDownward!.event;
660 const outcome = event.data[1] as XcmV2TraitsOutcome;
661
662 expect(
663 outcome.isIncomplete,
664 '[Relay] The outcome of the XCM should be `Incomplete`',
665 ).to.be.true;
666
667 const incomplete = outcome.asIncomplete;
668 expect(
669 incomplete[1].toString() == 'AssetNotFound',
670 '[Relay] The XCM error should be `AssetNotFound`',
671 ).to.be.true;
672 });
673609
674 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {610 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
675 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {611 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
694 Token: 'KAR',630 Token: 'KAR',
695 };631 };
696
697 const destWeight = 50000000;
698632
699 await helper.xTokens.transfer(alice, id, 100_000_000_000n, destination, destWeight);633 await helper.xTokens.transfer(alice, id, 100_000_000_000n, destination, {Unlimited: null});
700 });634 });
701635
702 const maxWaitBlocks = 3;636 const maxWaitBlocks = 3;
711 const event = xcmpQueueFailEvent!.event;645 const event = xcmpQueueFailEvent!.event;
712 const outcome = event.data[1] as XcmV2TraitsError;646 const outcome = event.data[1] as XcmV2TraitsError;
713647
714 expect(
715 outcome.isUntrustedReserveLocation,648 console.log('>>> Karura reject outcome: ', outcome.toHuman());
716 '[Karura] The XCM error should be `UntrustedReserveLocation`',649 // expect(
717 ).to.be.true;650 // outcome.isUntrustedReserveLocation,
651 // '[Karura] The XCM error should be `UntrustedReserveLocation`',
652 // ).to.be.true;
718 });653 });
719});654});
720655
890 },825 },
891 };826 };
892 const amount = TRANSFER_AMOUNT;827 const amount = TRANSFER_AMOUNT;
893 const destWeight = 850000000;
894828
895 await helper.xTokens.transfer(randomAccountQuartz, currencyId, amount, dest, destWeight);829 await helper.xTokens.transfer(randomAccountQuartz, currencyId, amount, dest, {Unlimited: null});
896830
897 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccountQuartz.address);831 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccountQuartz.address);
898 expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;832 expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;
945 },879 },
946 },880 },
947 };881 };
948 const destWeight = 50000000;
949882
950 await helper.xTokens.transferMultiasset(randomAccountMoonriver, asset, destination, destWeight);883 await helper.xTokens.transferMultiasset(randomAccountMoonriver, asset, destination, {Unlimited: null});
951884
952 balanceMovrTokenFinal = await helper.balance.getEthereum(randomAccountMoonriver.address);885 balanceMovrTokenFinal = await helper.balance.getEthereum(randomAccountMoonriver.address);
953886