git.delta.rocks / unique-network / refs/commits / c18879f1d0cb

difftreelog

refactor use playgrounds in unique xcm tests

Daniel Shiposha2022-10-10parent: #9f829ac.patch.diff
in: master

1 file changed

modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
1616
17import {Keyring} from '@polkadot/api';17import {Keyring} from '@polkadot/api';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {submitTransactionAsync} from '../substrate/substrate-api';19import {generateKeyringPair, bigIntToDecimals} from '../deprecated-helpers/helpers';
20import {getGenericResult, generateKeyringPair, waitEvent, bigIntToDecimals} from '../deprecated-helpers/helpers';
21import {MultiLocation} from '@polkadot/types/interfaces';
22import {blake2AsHex} from '@polkadot/util-crypto';20import {blake2AsHex} from '@polkadot/util-crypto';
23import getBalance from '../substrate/get-balance';
24import {XcmV2TraitsError, XcmV2TraitsOutcome} from '../interfaces';21import {XcmV2TraitsError, XcmV2TraitsOutcome} from '../interfaces';
25import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';22import {itSub, expect, describeXcm, usingPlaygrounds, usingAcalaPlaygrounds, usingRelayPlaygrounds, usingMoonbeamPlaygrounds} from '../util/playgrounds';
2623
27const UNIQUE_CHAIN = 2037;24const UNIQUE_CHAIN = 2037;
28const ACALA_CHAIN = 2000;25const ACALA_CHAIN = 2000;
62 randomAccount = generateKeyringPair(keyringSr25519);59 randomAccount = generateKeyringPair(keyringSr25519);
63 });60 });
6461
65 // Acala side62 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
66 await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {
67 const destination = {63 const destination = {
68 V0: {64 V0: {
69 X2: [65 X2: [
79 name: 'UNQ',75 name: 'UNQ',
80 symbol: 'UNQ',76 symbol: 'UNQ',
81 decimals: 18,77 decimals: 18,
82 minimalBalance: 1,78 minimalBalance: 1n,
83 };79 };
8480
85 // TODO81 await helper.getSudo().assetRegistry.registerForeignAsset(alice, destination, metadata);
86 const tx = helper.getApi().tx.assetRegistry.registerForeignAsset(destination, metadata);
87 const sudoTx = helper.getApi().tx.sudo.sudo(tx as any);
88 const events = await submitTransactionAsync(alice, sudoTx);
89 const result = getGenericResult(events);
90 expect(result.success).to.be.true;
91
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;
96 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10000000000000n);82 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10000000000000n);
97
98 // [balanceAcalaTokenInit] = await getBalance(api, [randomAccount.address]);
99 balanceAcalaTokenInit = await helper.balance.getSubstrate(randomAccount.address);83 balanceAcalaTokenInit = await helper.balance.getSubstrate(randomAccount.address);
100 {84 balanceUniqueForeignTokenInit = await helper.tokens.accounts(randomAccount.address, {ForeignAsset: 0});
101 // TODO
102 const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
103 balanceUniqueForeignTokenInit = BigInt(free);
104 }
105 });85 });
10686
107 // Unique side
108 await usingPlaygrounds(async (helper) => {87 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;
113 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);88 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);
114
115 // [balanceUniqueTokenInit] = await getBalance(api, [randomAccount.address]);
116 balanceUniqueTokenInit = await helper.balance.getSubstrate(randomAccount.address);89 balanceUniqueTokenInit = await helper.balance.getSubstrate(randomAccount.address);
117 });90 });
118 });91 });
11992
120 itSub('Should connect and send UNQ to Acala', async ({helper}) => {93 itSub('Should connect and send UNQ to Acala', async ({helper}) => {
12194
122 // Unique side
123 const destination = {95 const destination = {
124 V0: {96 V0: {
125 X2: [97 X2: [
159 };131 };
160132
161 const feeAssetItem = 0;133 const feeAssetItem = 0;
134 const weightLimit = 5000000000;
162135
163 const weightLimit = {136 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, weightLimit);
164 Limited: 5000000000,
165 };
166137
167 // TODO
168 const tx = helper.getApi().tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
169 const events = await submitTransactionAsync(randomAccount, tx);
170 const result = getGenericResult(events);
171 expect(result.success).to.be.true;
172
173 // [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);
174 balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);138 balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
175139
176 const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;140 const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
177 console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));141 console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
178 expect(unqFees > 0n).to.be.true;142 expect(unqFees > 0n).to.be.true;
179143
180 // Acala side144 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
181 await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {
182 // await waitNewBlocks(api, 3);
183 await helper.wait.newBlocks(3);145 await helper.wait.newBlocks(3);
184146
185 // TODO147 balanceUniqueForeignTokenMiddle = await helper.tokens.accounts(randomAccount.address, {ForeignAsset: 0});
186 const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
187 balanceUniqueForeignTokenMiddle = BigInt(free);
188
189 // [balanceAcalaTokenMiddle] = await getBalance(api, [randomAccount.address]);
190 balanceAcalaTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);148 balanceAcalaTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
191149
192 const acaFees = balanceAcalaTokenInit - balanceAcalaTokenMiddle;150 const acaFees = balanceAcalaTokenInit - balanceAcalaTokenMiddle;
203 });161 });
204162
205 itSub('Should connect to Acala and send UNQ back', async ({helper}) => {163 itSub('Should connect to Acala and send UNQ back', async ({helper}) => {
206
207 // Acala side
208 await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {164 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
209 const destination = {165 const destination = {
210 V1: {166 V1: {
211 parents: 1,167 parents: 1,
229185
230 const destWeight = 50000000;186 const destWeight = 50000000;
231187
232 // TODO188 await helper.xTokens.transfer(randomAccount, id, TRANSFER_AMOUNT, destination, destWeight);
233 const tx = helper.getApi().tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
234 const events = await submitTransactionAsync(randomAccount, tx);
235 const result = getGenericResult(events);
236 expect(result.success).to.be.true;
237189
238 // [balanceAcalaTokenFinal] = await getBalance(api, [randomAccount.address]);
239 balanceAcalaTokenFinal = await helper.balance.getSubstrate(randomAccount.address);190 balanceAcalaTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
240 {191 balanceUniqueForeignTokenFinal = await helper.tokens.accounts(randomAccount.address, id);
241 // TODO
242 const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;
243 balanceUniqueForeignTokenFinal = BigInt(free);
244 }
245192
246 const acaFees = balanceAcalaTokenMiddle - balanceAcalaTokenFinal;193 const acaFees = balanceAcalaTokenMiddle - balanceAcalaTokenFinal;
247 const unqOutcomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenFinal;194 const unqOutcomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenFinal;
256 expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;203 expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
257 });204 });
258205
259 // await waitNewBlocks(api, 3);
260 await helper.wait.newBlocks(3);206 await helper.wait.newBlocks(3);
261207
262 // [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);
263 balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccount.address);208 balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
264 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;209 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
265 expect(actuallyDelivered > 0).to.be.true;210 expect(actuallyDelivered > 0).to.be.true;
283 });228 });
284229
285 itSub('Unique rejects tokens from the Relay', async ({helper}) => {230 itSub('Unique rejects tokens from the Relay', async ({helper}) => {
286 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {231 await usingRelayPlaygrounds(relayUrl, async (helper) => {
287 const destination = {232 const destination = {
288 V1: {233 V1: {
289 parents: 0,234 parents: 0,
322 };267 };
323268
324 const feeAssetItem = 0;269 const feeAssetItem = 0;
270 const weightLimit = 5_000_000_000;
325271
326 const weightLimit = {272 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, weightLimit);
327 Limited: 5_000_000_000,
328 };
329
330 // TODO
331 const tx = helper.getApi().tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
332 const events = await submitTransactionAsync(alice, tx);
333 const result = getGenericResult(events);
334 expect(result.success).to.be.true;
335 });273 });
336274
337 const maxWaitBlocks = 3;275 const maxWaitBlocks = 3;
338276
339 // TODO277 const dmpQueueExecutedDownward = await helper.wait.event(maxWaitBlocks, 'dmpQueue', 'ExecutedDownward');
340 const dmpQueueExecutedDownward = await waitEvent(
341 helper.getApi(),
342 maxWaitBlocks,
343 'dmpQueue',
344 'ExecutedDownward',
345 );
346278
347 expect(279 expect(
348 dmpQueueExecutedDownward != null,280 dmpQueueExecutedDownward != null,
365 });297 });
366298
367 itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {299 itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {
368 await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {300 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
369 const destination = {301 const destination = {
370 V1: {302 V1: {
371 parents: 1,303 parents: 1,
389321
390 const destWeight = 50000000;322 const destWeight = 50000000;
391323
392 // TODO324 await helper.xTokens.transfer(alice, id, 100_000_000_000n, destination, destWeight);
393 const tx = helper.getApi().tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
394 const events = await submitTransactionAsync(alice, tx);
395 const result = getGenericResult(events);
396 expect(result.success).to.be.true;
397 });325 });
398326
399 const maxWaitBlocks = 3;327 const maxWaitBlocks = 3;
400328
401 // TODO329 const xcmpQueueFailEvent = await helper.wait.event(maxWaitBlocks, 'xcmpQueue', 'Fail');
402 const xcmpQueueFailEvent = await waitEvent(helper.getApi(), maxWaitBlocks, 'xcmpQueue', 'Fail');
403330
404 expect(331 expect(
405 xcmpQueueFailEvent != null,332 xcmpQueueFailEvent != null,
416 });343 });
417});344});
418345
419describeXcm('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => {346describe.only('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => {
420347
421 // Unique constants348 // Unique constants
422 let uniqueAlice: IKeyringPair;349 let uniqueAlice: IKeyringPair;
447 symbol: 'xcUNQ',374 symbol: 'xcUNQ',
448 decimals: 18,375 decimals: 18,
449 isFrozen: false,376 isFrozen: false,
450 minimalBalance: 1,377 minimalBalance: 1n,
451 };378 };
452379
453 let balanceUniqueTokenInit: bigint;380 let balanceUniqueTokenInit: bigint;
472 balanceForeignUnqTokenInit = 0n;399 balanceForeignUnqTokenInit = 0n;
473 });400 });
474401
475 await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {402 await usingMoonbeamPlaygrounds(moonbeamUrl, async (helper) => {
476 // TODO
477
478 const api = helper.getApi();
479
480 // >>> Sponsoring Dorothy >>>403 // >>> Sponsoring Dorothy >>>
481 console.log('Sponsoring Dorothy.......');404 console.log('Sponsoring Dorothy.......');
482 // const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);405 await helper.balance.transferToEthereum(alithAccount, 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;
486 await helper.balance.transferToSubstrate(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);
487 console.log('Sponsoring Dorothy.......DONE');406 console.log('Sponsoring Dorothy.......DONE');
488 // <<< Sponsoring Dorothy <<<407 // <<< Sponsoring Dorothy <<<
489408
490 const sourceLocation: MultiLocation = api.createType(409 uniqueAssetLocation = {
491 'MultiLocation',410 XCM: {
492 {
493 parents: 1,411 parents: 1,
494 interior: {X1: {Parachain: UNIQUE_CHAIN}},412 interior: {X1: {Parachain: UNIQUE_CHAIN}},
495 },413 },
496 );414 };
497
498 uniqueAssetLocation = {XCM: sourceLocation};
499 const existentialDeposit = 1;415 const existentialDeposit = 1n;
500 const isSufficient = true;416 const isSufficient = true;
501 const unitsPerSecond = '1';417 const unitsPerSecond = 1n;
502 const numAssetsWeightHint = 0;418 const numAssetsWeightHint = 0;
503419
504 const registerTx = api.tx.assetManager.registerForeignAsset(420 const encodedProposal = helper.assetManager.makeRegisterForeignAssetProposal({
505 uniqueAssetLocation,421 location: uniqueAssetLocation,
506 uniqueAssetMetadata,422 metadata: uniqueAssetMetadata,
507 existentialDeposit,423 existentialDeposit,
508 isSufficient,424 isSufficient,
509 );
510 console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
511
512 const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
513 uniqueAssetLocation,
514 unitsPerSecond,425 unitsPerSecond,
515 numAssetsWeightHint,426 numAssetsWeightHint,
516 );427 });
517 console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');428 const proposalHash = blake2AsHex(encodedProposal);
518429
519 const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);430 console.log('Encoded proposal for registerForeignAsset & setAssetUnitsPerSecond is %s', encodedProposal);
431 console.log('Encoded length %d', encodedProposal.length);
520 console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');432 console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
521433
522 // >>> Note motion preimage >>>434 // >>> Note motion preimage >>>
523 console.log('Note motion preimage.......');435 console.log('Note motion preimage.......');
524 const encodedProposal = batchCall?.method.toHex() || '';436 await helper.democracy.notePreimage(baltatharAccount, encodedProposal);
525 const proposalHash = blake2AsHex(encodedProposal);
526 console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
527 console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
528 console.log('Encoded length %d', encodedProposal.length);
529
530 const tx1 = api.tx.democracy.notePreimage(encodedProposal);
531 const events1 = await submitTransactionAsync(baltatharAccount, tx1);
532 const result1 = getGenericResult(events1);
533 expect(result1.success).to.be.true;
534 console.log('Note motion preimage.......DONE');437 console.log('Note motion preimage.......DONE');
535 // <<< Note motion preimage <<<438 // <<< Note motion preimage <<<
536439
537 // >>> Propose external motion through council >>>440 // >>> Propose external motion through council >>>
538 console.log('Propose external motion through council.......');441 console.log('Propose external motion through council.......');
539 const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);442 const externalMotion = helper.democracy.externalProposeMajority(proposalHash);
540 const tx2 = api.tx.councilCollective.propose(
541 councilVotingThreshold,
542 externalMotion,
543 externalMotion.encodedLength,
544 );
545 const events2 = await submitTransactionAsync(baltatharAccount, tx2);
546 const result2 = getGenericResult(events2);
547 expect(result2.success).to.be.true;
548
549 const encodedMotion = externalMotion?.method.toHex() || '';443 const encodedMotion = externalMotion?.method.toHex() || '';
550 const motionHash = blake2AsHex(encodedMotion);444 const motionHash = blake2AsHex(encodedMotion);
551 console.log('Motion hash is %s', motionHash);445 console.log('Motion hash is %s', motionHash);
552446
553 const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);447 await helper.collective.council.propose(baltatharAccount, councilVotingThreshold, externalMotion, externalMotion.encodedLength);
554 {
555 const events3 = await submitTransactionAsync(dorothyAccount, tx3);
556 const result3 = getGenericResult(events3);
557 expect(result3.success).to.be.true;
558 }
559 {
560 const events3 = await submitTransactionAsync(baltatharAccount, tx3);
561 const result3 = getGenericResult(events3);
562 expect(result3.success).to.be.true;
563 }
564448
565 const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);449 const councilProposalIdx = await helper.collective.council.proposalCount() - 1;
566 const events4 = await submitTransactionAsync(dorothyAccount, tx4);450 await helper.collective.council.vote(dorothyAccount, motionHash, councilProposalIdx, true);
567 const result4 = getGenericResult(events4);451 await helper.collective.council.vote(baltatharAccount, motionHash, councilProposalIdx, true);
452
568 expect(result4.success).to.be.true;453 await helper.collective.council.close(dorothyAccount, motionHash, councilProposalIdx, 1_000_000_000, externalMotion.encodedLength);
569 console.log('Propose external motion through council.......DONE');454 console.log('Propose external motion through council.......DONE');
570 // <<< Propose external motion through council <<<455 // <<< Propose external motion through council <<<
571456
572 // >>> Fast track proposal through technical committee >>>457 // >>> Fast track proposal through technical committee >>>
573 console.log('Fast track proposal through technical committee.......');458 console.log('Fast track proposal through technical committee.......');
574 const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);459 const fastTrack = helper.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
575 const tx5 = api.tx.techCommitteeCollective.propose(
576 technicalCommitteeThreshold,
577 fastTrack,
578 fastTrack.encodedLength,
579 );
580 const events5 = await submitTransactionAsync(alithAccount, tx5);
581 const result5 = getGenericResult(events5);
582 expect(result5.success).to.be.true;
583
584 const encodedFastTrack = fastTrack?.method.toHex() || '';460 const encodedFastTrack = fastTrack?.method.toHex() || '';
585 const fastTrackHash = blake2AsHex(encodedFastTrack);461 const fastTrackHash = blake2AsHex(encodedFastTrack);
586 console.log('FastTrack hash is %s', fastTrackHash);462 console.log('FastTrack hash is %s', fastTrackHash);
587463
588 const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;464 await helper.collective.techCommittee.propose(alithAccount, technicalCommitteeThreshold, fastTrack, fastTrack.encodedLength);
589 const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);
590 {
591 const events6 = await submitTransactionAsync(baltatharAccount, tx6);
592 const result6 = getGenericResult(events6);
593 expect(result6.success).to.be.true;
594 }
595 {
596 const events6 = await submitTransactionAsync(alithAccount, tx6);
597 const result6 = getGenericResult(events6);
598 expect(result6.success).to.be.true;
599 }
600465
601 const tx7 = api.tx.techCommitteeCollective466 const techProposalIdx = await helper.collective.techCommittee.proposalCount() - 1;
602 .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);467 await helper.collective.techCommittee.vote(baltatharAccount, fastTrackHash, techProposalIdx, true);
603 const events7 = await submitTransactionAsync(baltatharAccount, tx7);468 await helper.collective.techCommittee.vote(alithAccount, fastTrackHash, techProposalIdx, true);
469
604 const result7 = getGenericResult(events7);470 await helper.collective.techCommittee.close(baltatharAccount, fastTrackHash, techProposalIdx, 1_000_000_000, fastTrack.encodedLength);
605 expect(result7.success).to.be.true;
606 console.log('Fast track proposal through technical committee.......DONE');471 console.log('Fast track proposal through technical committee.......DONE');
607 // <<< Fast track proposal through technical committee <<<472 // <<< Fast track proposal through technical committee <<<
608473
609 // >>> Referendum voting >>>474 // >>> Referendum voting >>>
610 console.log('Referendum voting.......');475 console.log('Referendum voting.......');
611 const tx8 = api.tx.democracy.vote(476 await helper.democracy.referendumVote(dorothyAccount, 0, {
612 0,477 balance: 10_000_000_000_000_000_000n,
613 {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},478 vote: {aye: true, conviction: 1},
614 );479 });
615 const events8 = await submitTransactionAsync(dorothyAccount, tx8);
616 const result8 = getGenericResult(events8);
617 expect(result8.success).to.be.true;
618 console.log('Referendum voting.......DONE');480 console.log('Referendum voting.......DONE');
619 // <<< Referendum voting <<<481 // <<< Referendum voting <<<
620482
621 // >>> Acquire Unique AssetId Info on Moonbeam >>>483 // >>> Acquire Unique AssetId Info on Moonbeam >>>
622 console.log('Acquire Unique AssetId Info on Moonbeam.......');484 console.log('Acquire Unique AssetId Info on Moonbeam.......');
623485
624 // Wait for the democracy execute486 // Wait for the democracy execute
625 // await waitNewBlocks(api, 5);
626 await helper.wait.newBlocks(5);487 await helper.wait.newBlocks(5);
627488
628 assetId = (await api.query.assetManager.assetTypeId({489 assetId = (await helper.assetManager.assetTypeId(uniqueAssetLocation)).toString();
629 XCM: sourceLocation,
630 })).toString();
631490
632 console.log('UNQ asset ID is %s', assetId);491 console.log('UNQ asset ID is %s', assetId);
633 console.log('Acquire Unique AssetId Info on Moonbeam.......DONE');492 console.log('Acquire Unique AssetId Info on Moonbeam.......DONE');
634 // >>> Acquire Unique AssetId Info on Moonbeam >>>493 // >>> Acquire Unique AssetId Info on Moonbeam >>>
635494
636 // >>> Sponsoring random Account >>>495 // >>> Sponsoring random Account >>>
637 console.log('Sponsoring random Account.......');496 console.log('Sponsoring random Account.......');
638 // const tx10 = api.tx.balances.transfer(randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);497 await helper.balance.transferToEthereum(baltatharAccount, 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;
642 await helper.balance.transferToSubstrate(baltatharAccount, randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);
643 console.log('Sponsoring random Account.......DONE');498 console.log('Sponsoring random Account.......DONE');
644 // <<< Sponsoring random Account <<<499 // <<< Sponsoring random Account <<<
645500
646 [balanceGlmrTokenInit] = await getBalance(api, [randomAccountMoonbeam.address]);501 balanceGlmrTokenInit = await helper.balance.getEthereum(randomAccountMoonbeam.address);
647 });502 });
648503
649 await usingPlaygrounds(async (helper) => {504 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;
654 await helper.balance.transferToSubstrate(uniqueAlice, randomAccountUnique.address, 10n * TRANSFER_AMOUNT);505 await helper.balance.transferToSubstrate(uniqueAlice, randomAccountUnique.address, 10n * TRANSFER_AMOUNT);
655
656 // [balanceUniqueTokenInit] = await getBalance(api, [randomAccountUnique.address]);
657 balanceUniqueTokenInit = await helper.balance.getSubstrate(randomAccountUnique.address);506 balanceUniqueTokenInit = await helper.balance.getSubstrate(randomAccountUnique.address);
658 });507 });
659 });508 });
676 const amount = TRANSFER_AMOUNT;525 const amount = TRANSFER_AMOUNT;
677 const destWeight = 850000000;526 const destWeight = 850000000;
678527
679 // TODO528 await helper.xTokens.transfer(randomAccountUnique, currencyId, amount, dest, destWeight);
680 const tx = helper.getApi().tx.xTokens.transfer(currencyId, amount, dest, destWeight);
681 const events = await submitTransactionAsync(randomAccountUnique, tx);
682 const result = getGenericResult(events);
683 expect(result.success).to.be.true;
684529
685 // [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccountUnique.address]);
686 balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccountUnique.address);530 balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccountUnique.address);
687 expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;531 expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;
688532
689 const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;533 const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
690 console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', bigIntToDecimals(transactionFees));534 console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', bigIntToDecimals(transactionFees));
691 expect(transactionFees > 0).to.be.true;535 expect(transactionFees > 0).to.be.true;
692536
693 await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {537 await usingMoonbeamPlaygrounds(moonbeamUrl, async (helper) => {
694 // await waitNewBlocks(api, 3);
695 await helper.wait.newBlocks(3);538 await helper.wait.newBlocks(3);
696539
697 // [balanceGlmrTokenMiddle] = await getBalance(api, [randomAccountMoonbeam.address]);540 balanceGlmrTokenMiddle = await helper.balance.getEthereum(randomAccountMoonbeam.address);
698 balanceGlmrTokenMiddle = await helper.balance.getSubstrate(randomAccountMoonbeam.address);
699541
700 const glmrFees = balanceGlmrTokenInit - balanceGlmrTokenMiddle;542 const glmrFees = balanceGlmrTokenInit - balanceGlmrTokenMiddle;
701 console.log('[Unique -> Moonbeam] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));543 console.log('[Unique -> Moonbeam] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));
702 expect(glmrFees == 0n).to.be.true;544 expect(glmrFees == 0n).to.be.true;
703545
704 // TODO546 balanceForeignUnqTokenMiddle = (await helper.assets.account(assetId, randomAccountMoonbeam.address))!;
705 const unqRandomAccountAsset = (
706 await helper.getApi().query.assets.account(assetId, randomAccountMoonbeam.address)
707 ).toJSON()! as any;
708547
709 balanceForeignUnqTokenMiddle = BigInt(unqRandomAccountAsset['balance']);
710 const unqIncomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenInit;548 const unqIncomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenInit;
711 console.log('[Unique -> Moonbeam] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));549 console.log('[Unique -> Moonbeam] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));
712 expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;550 expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
713 });551 });
714 });552 });
715553
716 itSub('Should connect to Moonbeam and send UNQ back', async ({helper}) => {554 itSub('Should connect to Moonbeam and send UNQ back', async ({helper}) => {
717 await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {555 await usingMoonbeamPlaygrounds(moonbeamUrl, async (helper) => {
718 const asset = {556 const asset = {
719 V1: {557 V1: {
720 id: {558 id: {
743 };581 };
744 const destWeight = 50000000;582 const destWeight = 50000000;
745583
746 // TODO584 await helper.xTokens.transferMultiasset(randomAccountMoonbeam, asset, destination, destWeight);
747 const tx = helper.getApi().tx.xTokens.transferMultiasset(asset, destination, destWeight);
748 const events = await submitTransactionAsync(randomAccountMoonbeam, tx);
749 const result = getGenericResult(events);
750 expect(result.success).to.be.true;
751585
752 // [balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);586 balanceGlmrTokenFinal = await helper.balance.getEthereum(randomAccountMoonbeam.address);
753 balanceGlmrTokenFinal = await helper.balance.getSubstrate(randomAccountMoonbeam.address);
754587
755 const glmrFees = balanceGlmrTokenMiddle - balanceGlmrTokenFinal;588 const glmrFees = balanceGlmrTokenMiddle - balanceGlmrTokenFinal;
756 console.log('[Moonbeam -> Unique] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));589 console.log('[Moonbeam -> Unique] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));
757 expect(glmrFees > 0).to.be.true;590 expect(glmrFees > 0).to.be.true;
758591
759 // TODO592 const unqRandomAccountAsset = await helper.assets.account(assetId, randomAccountMoonbeam.address);
760 const unqRandomAccountAsset = (
761 await helper.getApi().query.assets.account(assetId, randomAccountMoonbeam.address)
762 ).toJSON()! as any;
763593
764 expect(unqRandomAccountAsset).to.be.null;594 expect(unqRandomAccountAsset).to.be.null;
765595
766 balanceForeignUnqTokenFinal = 0n;596 balanceForeignUnqTokenFinal = 0n;
767597
768 const unqOutcomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenFinal;598 const unqOutcomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenFinal;
769 console.log('[Unique -> Moonbeam] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));599 console.log('[Unique -> Moonbeam] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));
770 expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;600 expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
771 });601 });
772602
773 // await waitNewBlocks(api, 3);
774 await helper.wait.newBlocks(3);603 await helper.wait.newBlocks(3);
775604
776 // [balanceUniqueTokenFinal] = await getBalance(api, [randomAccountUnique.address]);
777 balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccountUnique.address);605 balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccountUnique.address);
778 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;606 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
779 expect(actuallyDelivered > 0).to.be.true;607 expect(actuallyDelivered > 0).to.be.true;