git.delta.rocks / unique-network / refs/commits / 9f829acfc3d3

difftreelog

refactor use playgrounds in quartz xcm tests

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

1 file changed

modifiedtests/src/xcm/xcmQuartz.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 {XcmV2TraitsOutcome, XcmV2TraitsError} from '../interfaces';21import {XcmV2TraitsOutcome, XcmV2TraitsError} from '../interfaces';
25import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';22import {itSub, expect, describeXcm, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds} from '../util/playgrounds';
2623
27const QUARTZ_CHAIN = 2095;24const QUARTZ_CHAIN = 2095;
28const KARURA_CHAIN = 2000;25const KARURA_CHAIN = 2000;
63 });60 });
6461
65 // Karura side62 // Karura side
66 await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {63 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
67 const api = helper.getApi();
68
69 const destination = {64 const destination = {
70 V0: {65 V0: {
71 X2: [66 X2: [
81 name: 'QTZ',76 name: 'QTZ',
82 symbol: 'QTZ',77 symbol: 'QTZ',
83 decimals: 18,78 decimals: 18,
84 minimalBalance: 1,79 minimalBalance: 1n,
85 };80 };
8681
87 const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);82 await helper.getSudo().assetRegistry.registerForeignAsset(alice, destination, metadata);
88 const sudoTx = api.tx.sudo.sudo(tx as any);83 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10000000000000n);
89 const events = await submitTransactionAsync(alice, sudoTx);
90 const result = getGenericResult(events);
91 expect(result.success).to.be.true;
92
93 const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
94 const events1 = await submitTransactionAsync(alice, tx1);84 balanceKaruraTokenInit = await helper.balance.getSubstrate(randomAccount.address);
95 const result1 = getGenericResult(events1);
96 expect(result1.success).to.be.true;
97
98 [balanceKaruraTokenInit] = await getBalance(api, [randomAccount.address]);
99 {85 balanceQuartzForeignTokenInit = await helper.tokens.accounts(randomAccount.address, {ForeignAsset: 0});
100 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
101 balanceQuartzForeignTokenInit = BigInt(free);
102 }
103 });86 });
10487
105 // Quartz side
106 await usingPlaygrounds(async (helper) => {88 await usingPlaygrounds(async (helper) => {
107 // const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);
108 // const events0 = await submitTransactionAsync(alice, tx0);
109 // const result0 = getGenericResult(events0);
110 // expect(result0.success).to.be.true;
111 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);89 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);
112
113 // [balanceQuartzTokenInit] = await getBalance(api, [randomAccount.address]);
114 balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccount.address);90 balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccount.address);
115 });91 });
116 });92 });
11793
118 itSub('Should connect and send QTZ to Karura', async ({helper}) => {94 itSub('Should connect and send QTZ to Karura', async ({helper}) => {
119
120 // Quartz side
121 const destination = {95 const destination = {
122 V0: {96 V0: {
123 X2: [97 X2: [
157 };131 };
158132
159 const feeAssetItem = 0;133 const feeAssetItem = 0;
134 const weightLimit = 5000000000;
160135
161 const weightLimit = {136 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, weightLimit);
162 Limited: 5000000000,
163 };
164
165 // TODO
166 const tx = helper.getApi().tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
167 const events = await submitTransactionAsync(randomAccount, tx);
168 const result = getGenericResult(events);
169 expect(result.success).to.be.true;
170
171 // [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccount.address]);
172 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);137 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
173138
174 const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;139 const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
175 console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));140 console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
176 expect(qtzFees > 0n).to.be.true;141 expect(qtzFees > 0n).to.be.true;
177142
178 // Karura side143 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
179 await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
180 // await waitNewBlocks(api, 3);
181 await helper.wait.newBlocks(3);144 await helper.wait.newBlocks(3);
182
183 // TODO145 balanceQuartzForeignTokenMiddle = await helper.tokens.accounts(randomAccount.address, {ForeignAsset: 0});
184 const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
185 balanceQuartzForeignTokenMiddle = BigInt(free);
186
187 // [balanceKaruraTokenMiddle] = await getBalance(api, [randomAccount.address]);
188 balanceKaruraTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);146 balanceKaruraTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
189147
190 const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;148 const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;
201 });159 });
202160
203 itSub('Should connect to Karura and send QTZ back', async ({helper}) => {161 itSub('Should connect to Karura and send QTZ back', async ({helper}) => {
204
205 // Karura side
206 await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {162 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
207 const destination = {163 const destination = {
208 V1: {164 V1: {
209 parents: 1,165 parents: 1,
227183
228 const destWeight = 50000000;184 const destWeight = 50000000;
229185
230 // TODO186 await helper.xTokens.transfer(randomAccount, id, TRANSFER_AMOUNT, destination, destWeight);
231 const tx = helper.getApi().tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
232 const events = await submitTransactionAsync(randomAccount, tx);
233 const result = getGenericResult(events);
234 expect(result.success).to.be.true;
235
236 // [balanceKaruraTokenFinal] = await getBalance(api, [randomAccount.address]);
237 balanceKaruraTokenFinal = await helper.balance.getSubstrate(randomAccount.address);187 balanceKaruraTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
238 {188 balanceQuartzForeignTokenFinal = await helper.tokens.accounts(randomAccount.address, id);
239 // TODO
240 const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;
241 balanceQuartzForeignTokenFinal = BigInt(free);
242 }
243189
244 const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;190 const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;
245 const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;191 const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;
254 expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;200 expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
255 });201 });
256202
257 // Quartz side
258 // await waitNewBlocks(api, 3);
259 await helper.wait.newBlocks(3);203 await helper.wait.newBlocks(3);
260204
261 // [balanceQuartzTokenFinal] = await getBalance(api, [randomAccount.address]);
262 balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccount.address);205 balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
263 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;206 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
264 expect(actuallyDelivered > 0).to.be.true;207 expect(actuallyDelivered > 0).to.be.true;
282 });225 });
283226
284 itSub('Quartz rejects tokens from the Relay', async ({helper}) => {227 itSub('Quartz rejects tokens from the Relay', async ({helper}) => {
285 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {228 await usingRelayPlaygrounds(relayUrl, async (helper) => {
286 const destination = {229 const destination = {
287 V1: {230 V1: {
288 parents: 0,231 parents: 0,
321 };264 };
322265
323 const feeAssetItem = 0;266 const feeAssetItem = 0;
267 const weightLimit = 5_000_000_000;
324268
325 const weightLimit = {269 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, weightLimit);
326 Limited: 5_000_000_000,
327 };
328
329 // TODO
330 const tx = helper.getApi().tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
331 const events = await submitTransactionAsync(alice, tx);
332 const result = getGenericResult(events);
333 expect(result.success).to.be.true;
334 });270 });
335271
336 const maxWaitBlocks = 3;272 const maxWaitBlocks = 3;
337273
338 // TODO274 const dmpQueueExecutedDownward = await helper.wait.event(maxWaitBlocks, 'dmpQueue', 'ExecutedDownward');
339 const dmpQueueExecutedDownward = await waitEvent(
340 helper.getApi(),
341 maxWaitBlocks,
342 'dmpQueue',
343 'ExecutedDownward',
344 );
345275
346 expect(276 expect(
347 dmpQueueExecutedDownward != null,277 dmpQueueExecutedDownward != null,
364 });294 });
365295
366 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {296 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
367 await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {297 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
368 const destination = {298 const destination = {
369 V1: {299 V1: {
370 parents: 1,300 parents: 1,
388318
389 const destWeight = 50000000;319 const destWeight = 50000000;
390320
391 // TODO321 await helper.xTokens.transfer(alice, id, 100_000_000_000n, destination, destWeight);
392 const tx = helper.getApi().tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
393 const events = await submitTransactionAsync(alice, tx);
394 const result = getGenericResult(events);
395 expect(result.success).to.be.true;
396 });322 });
397323
398 const maxWaitBlocks = 3;324 const maxWaitBlocks = 3;
399325
400 // TODO326 const xcmpQueueFailEvent = await helper.wait.event(maxWaitBlocks, 'xcmpQueue', 'Fail');
401 const xcmpQueueFailEvent = await waitEvent(helper.getApi(), maxWaitBlocks, 'xcmpQueue', 'Fail');
402327
403 expect(328 expect(
404 xcmpQueueFailEvent != null,329 xcmpQueueFailEvent != null,
427 // Moonriver constants352 // Moonriver constants
428 let assetId: string;353 let assetId: string;
429354
430 const moonriverKeyring = new Keyring({type: 'ethereum'});
431 const alithPrivateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';
432 const baltatharPrivateKey = '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b';
433 const dorothyPrivateKey = '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68';
434
435 const alithAccount = moonriverKeyring.addFromUri(alithPrivateKey, undefined, 'ethereum');
436 const baltatharAccount = moonriverKeyring.addFromUri(baltatharPrivateKey, undefined, 'ethereum');
437 const dorothyAccount = moonriverKeyring.addFromUri(dorothyPrivateKey, undefined, 'ethereum');
438
439 const councilVotingThreshold = 2;355 const councilVotingThreshold = 2;
440 const technicalCommitteeThreshold = 2;356 const technicalCommitteeThreshold = 2;
441 const votingPeriod = 3;357 const votingPeriod = 3;
446 symbol: 'xcQTZ',362 symbol: 'xcQTZ',
447 decimals: 18,363 decimals: 18,
448 isFrozen: false,364 isFrozen: false,
449 minimalBalance: 1,365 minimalBalance: 1n,
450 };366 };
451367
452 let balanceQuartzTokenInit: bigint;368 let balanceQuartzTokenInit: bigint;
471 balanceForeignQtzTokenInit = 0n;387 balanceForeignQtzTokenInit = 0n;
472 });388 });
473389
474 await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {390 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {
475 // TODO391 const alithAccount = helper.account.alithAccount();
392 const baltatharAccount = helper.account.baltatharAccount();
393 const dorothyAccount = helper.account.dorothyAccount();
476394
477 const api = helper.getApi();
478
479 // >>> Sponsoring Dorothy >>>395 // >>> Sponsoring Dorothy >>>
480 console.log('Sponsoring Dorothy.......');396 console.log('Sponsoring Dorothy.......');
481 // const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);397 await helper.balance.transferToEthereum(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);
482 // const events0 = await submitTransactionAsync(alithAccount, tx0);
483 // const result0 = getGenericResult(events0);
484 // expect(result0.success).to.be.true;
485 await helper.balance.transferToSubstrate(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);
486 console.log('Sponsoring Dorothy.......DONE');398 console.log('Sponsoring Dorothy.......DONE');
487 // <<< Sponsoring Dorothy <<<399 // <<< Sponsoring Dorothy <<<
488400
489 const sourceLocation: MultiLocation = api.createType(401 quartzAssetLocation = {
490 'MultiLocation',402 XCM: {
491 {
492 parents: 1,403 parents: 1,
493 interior: {X1: {Parachain: QUARTZ_CHAIN}},404 interior: {X1: {Parachain: QUARTZ_CHAIN}},
494 },405 },
495 );406 };
496
497 quartzAssetLocation = {XCM: sourceLocation};
498 const existentialDeposit = 1;407 const existentialDeposit = 1n;
499 const isSufficient = true;408 const isSufficient = true;
500 const unitsPerSecond = '1';409 const unitsPerSecond = 1n;
501 const numAssetsWeightHint = 0;410 const numAssetsWeightHint = 0;
502411
503 const registerTx = api.tx.assetManager.registerForeignAsset(412 const encodedProposal = helper.assetManager.makeRegisterForeignAssetProposal({
504 quartzAssetLocation,413 location: quartzAssetLocation,
505 quartzAssetMetadata,414 metadata: quartzAssetMetadata,
506 existentialDeposit,415 existentialDeposit,
507 isSufficient,416 isSufficient,
508 );
509 console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
510
511 const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
512 quartzAssetLocation,
513 unitsPerSecond,417 unitsPerSecond,
514 numAssetsWeightHint,418 numAssetsWeightHint,
515 );419 });
516 console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');420 const proposalHash = blake2AsHex(encodedProposal);
517421
518 const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);422 console.log('Encoded proposal for registerForeignAsset & setAssetUnitsPerSecond is %s', encodedProposal);
423 console.log('Encoded length %d', encodedProposal.length);
519 console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');424 console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
520425
521 // >>> Note motion preimage >>>426 // >>> Note motion preimage >>>
522 console.log('Note motion preimage.......');427 console.log('Note motion preimage.......');
523 const encodedProposal = batchCall?.method.toHex() || '';428 await helper.democracy.notePreimage(baltatharAccount, encodedProposal);
524 const proposalHash = blake2AsHex(encodedProposal);
525 console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
526 console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
527 console.log('Encoded length %d', encodedProposal.length);
528
529 const tx1 = api.tx.democracy.notePreimage(encodedProposal);
530 const events1 = await submitTransactionAsync(baltatharAccount, tx1);
531 const result1 = getGenericResult(events1);
532 expect(result1.success).to.be.true;
533 console.log('Note motion preimage.......DONE');429 console.log('Note motion preimage.......DONE');
534 // <<< Note motion preimage <<<430 // <<< Note motion preimage <<<
535431
536 // >>> Propose external motion through council >>>432 // >>> Propose external motion through council >>>
537 console.log('Propose external motion through council.......');433 console.log('Propose external motion through council.......');
538 const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);434 const externalMotion = helper.democracy.externalProposeMajority(proposalHash);
539 const tx2 = api.tx.councilCollective.propose(
540 councilVotingThreshold,
541 externalMotion,
542 externalMotion.encodedLength,
543 );
544 const events2 = await submitTransactionAsync(baltatharAccount, tx2);
545 const result2 = getGenericResult(events2);
546 expect(result2.success).to.be.true;
547
548 const encodedMotion = externalMotion?.method.toHex() || '';435 const encodedMotion = externalMotion?.method.toHex() || '';
549 const motionHash = blake2AsHex(encodedMotion);436 const motionHash = blake2AsHex(encodedMotion);
550 console.log('Motion hash is %s', motionHash);437 console.log('Motion hash is %s', motionHash);
551438
552 const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);439 await helper.collective.council.propose(baltatharAccount, councilVotingThreshold, externalMotion, externalMotion.encodedLength);
553 {
554 const events3 = await submitTransactionAsync(dorothyAccount, tx3);
555 const result3 = getGenericResult(events3);
556 expect(result3.success).to.be.true;
557 }
558 {
559 const events3 = await submitTransactionAsync(baltatharAccount, tx3);
560 const result3 = getGenericResult(events3);
561 expect(result3.success).to.be.true;
562 }
563440
564 const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);441 const councilProposalIdx = await helper.collective.council.proposalCount() - 1;
565 const events4 = await submitTransactionAsync(dorothyAccount, tx4);442 await helper.collective.council.vote(dorothyAccount, motionHash, councilProposalIdx, true);
566 const result4 = getGenericResult(events4);443 await helper.collective.council.vote(baltatharAccount, motionHash, councilProposalIdx, true);
444
567 expect(result4.success).to.be.true;445 await helper.collective.council.close(dorothyAccount, motionHash, councilProposalIdx, 1_000_000_000, externalMotion.encodedLength);
568 console.log('Propose external motion through council.......DONE');446 console.log('Propose external motion through council.......DONE');
569 // <<< Propose external motion through council <<<447 // <<< Propose external motion through council <<<
570448
571 // >>> Fast track proposal through technical committee >>>449 // >>> Fast track proposal through technical committee >>>
572 console.log('Fast track proposal through technical committee.......');450 console.log('Fast track proposal through technical committee.......');
573 const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);451 const fastTrack = helper.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
574 const tx5 = api.tx.techCommitteeCollective.propose(
575 technicalCommitteeThreshold,
576 fastTrack,
577 fastTrack.encodedLength,
578 );
579 const events5 = await submitTransactionAsync(alithAccount, tx5);
580 const result5 = getGenericResult(events5);
581 expect(result5.success).to.be.true;
582
583 const encodedFastTrack = fastTrack?.method.toHex() || '';452 const encodedFastTrack = fastTrack?.method.toHex() || '';
584 const fastTrackHash = blake2AsHex(encodedFastTrack);453 const fastTrackHash = blake2AsHex(encodedFastTrack);
585 console.log('FastTrack hash is %s', fastTrackHash);454 console.log('FastTrack hash is %s', fastTrackHash);
586455
587 const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;456 await helper.collective.techCommittee.propose(alithAccount, technicalCommitteeThreshold, fastTrack, fastTrack.encodedLength);
588 const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);
589 {
590 const events6 = await submitTransactionAsync(baltatharAccount, tx6);
591 const result6 = getGenericResult(events6);
592 expect(result6.success).to.be.true;
593 }
594 {
595 const events6 = await submitTransactionAsync(alithAccount, tx6);
596 const result6 = getGenericResult(events6);
597 expect(result6.success).to.be.true;
598 }
599457
600 const tx7 = api.tx.techCommitteeCollective458 const techProposalIdx = await helper.collective.techCommittee.proposalCount() - 1;
601 .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);459 await helper.collective.techCommittee.vote(baltatharAccount, fastTrackHash, techProposalIdx, true);
602 const events7 = await submitTransactionAsync(baltatharAccount, tx7);460 await helper.collective.techCommittee.vote(alithAccount, fastTrackHash, techProposalIdx, true);
461
603 const result7 = getGenericResult(events7);462 await helper.collective.techCommittee.close(baltatharAccount, fastTrackHash, techProposalIdx, 1_000_000_000, fastTrack.encodedLength);
604 expect(result7.success).to.be.true;
605 console.log('Fast track proposal through technical committee.......DONE');463 console.log('Fast track proposal through technical committee.......DONE');
606 // <<< Fast track proposal through technical committee <<<464 // <<< Fast track proposal through technical committee <<<
607465
608 // >>> Referendum voting >>>466 // >>> Referendum voting >>>
609 console.log('Referendum voting.......');467 console.log('Referendum voting.......');
610 const tx8 = api.tx.democracy.vote(468 await helper.democracy.referendumVote(dorothyAccount, 0, {
611 0,469 balance: 10_000_000_000_000_000_000n,
612 {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},470 vote: {aye: true, conviction: 1},
613 );471 });
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');472 console.log('Referendum voting.......DONE');
618 // <<< Referendum voting <<<473 // <<< Referendum voting <<<
619474
620 // >>> Acquire Quartz AssetId Info on Moonriver >>>475 // >>> Acquire Quartz AssetId Info on Moonriver >>>
621 console.log('Acquire Quartz AssetId Info on Moonriver.......');476 console.log('Acquire Quartz AssetId Info on Moonriver.......');
622477
623 // Wait for the democracy execute478 // Wait for the democracy execute
624 // await waitNewBlocks(api, 5);
625 await helper.wait.newBlocks(5);479 await helper.wait.newBlocks(5);
626480
627 assetId = (await api.query.assetManager.assetTypeId({481 assetId = (await helper.assetManager.assetTypeId(quartzAssetLocation)).toString();
628 XCM: sourceLocation,
629 })).toString();
630482
631 console.log('QTZ asset ID is %s', assetId);483 console.log('QTZ asset ID is %s', assetId);
632 console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');484 console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');
633 // >>> Acquire Quartz AssetId Info on Moonriver >>>485 // >>> Acquire Quartz AssetId Info on Moonriver >>>
634486
635 // >>> Sponsoring random Account >>>487 // >>> Sponsoring random Account >>>
636 console.log('Sponsoring random Account.......');488 console.log('Sponsoring random Account.......');
637 // const tx10 = api.tx.balances.transfer(randomAccountMoonriver.address, 11_000_000_000_000_000_000n);489 await helper.balance.transferToEthereum(baltatharAccount, randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
638 // const events10 = await submitTransactionAsync(baltatharAccount, tx10);
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);
642 console.log('Sponsoring random Account.......DONE');490 console.log('Sponsoring random Account.......DONE');
643 // <<< Sponsoring random Account <<<491 // <<< Sponsoring random Account <<<
644492
645 // [balanceMovrTokenInit] = await getBalance(api, [randomAccountMoonriver.address]);493 balanceMovrTokenInit = await helper.balance.getEthereum(randomAccountMoonriver.address);
646 balanceMovrTokenInit = await helper.balance.getSubstrate(randomAccountMoonriver.address);
647 });494 });
648495
649 await usingPlaygrounds(async (helper) => {496 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);497 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);498 balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccountQuartz.address);
658 });499 });
659 });500 });
676 const amount = TRANSFER_AMOUNT;517 const amount = TRANSFER_AMOUNT;
677 const destWeight = 850000000;518 const destWeight = 850000000;
678519
679 // TODO520 await helper.xTokens.transfer(randomAccountQuartz, currencyId, amount, dest, destWeight);
680 const tx = helper.getApi().tx.xTokens.transfer(currencyId, amount, dest, destWeight);
681 const events = await submitTransactionAsync(randomAccountQuartz, tx);
682 const result = getGenericResult(events);
683 expect(result.success).to.be.true;
684521
685 // [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccountQuartz.address]);
686 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccountQuartz.address);522 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccountQuartz.address);
687 expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;523 expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;
688524
689 const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;525 const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
690 console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', bigIntToDecimals(transactionFees));526 console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', bigIntToDecimals(transactionFees));
691 expect(transactionFees > 0).to.be.true;527 expect(transactionFees > 0).to.be.true;
692528
693 await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {529 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {
694 // await waitNewBlocks(api, 3);
695 await helper.wait.newBlocks(3);530 await helper.wait.newBlocks(3);
696531
697 // [balanceMovrTokenMiddle] = await getBalance(api, [randomAccountMoonriver.address]);532 balanceMovrTokenMiddle = await helper.balance.getEthereum(randomAccountMoonriver.address);
698 balanceMovrTokenMiddle = await helper.balance.getSubstrate(randomAccountMoonriver.address);
699533
700 const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;534 const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;
701 console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',bigIntToDecimals(movrFees));535 console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',bigIntToDecimals(movrFees));
702 expect(movrFees == 0n).to.be.true;536 expect(movrFees == 0n).to.be.true;
703
704 // TODO
705 const qtzRandomAccountAsset = (
706 await helper.getApi().query.assets.account(assetId, randomAccountMoonriver.address)
707 ).toJSON()! as any;
708537
709 balanceForeignQtzTokenMiddle = BigInt(qtzRandomAccountAsset['balance']);538 balanceForeignQtzTokenMiddle = (await helper.assets.account(assetId, randomAccountMoonriver.address))!; // BigInt(qtzRandomAccountAsset['balance']);
710 const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;539 const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;
711 console.log('[Quartz -> Moonriver] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));540 console.log('[Quartz -> Moonriver] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
712 expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;541 expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
713 });542 });
714 });543 });
715544
716 itSub('Should connect to Moonriver and send QTZ back', async ({helper}) => {545 itSub('Should connect to Moonriver and send QTZ back', async ({helper}) => {
717 await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {546 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {
718 const asset = {547 const asset = {
719 V1: {548 V1: {
720 id: {549 id: {
743 };572 };
744 const destWeight = 50000000;573 const destWeight = 50000000;
745574
746 // TODO575 await helper.xTokens.transferMultiasset(randomAccountMoonriver, asset, destination, destWeight);
747 const tx = helper.getApi().tx.xTokens.transferMultiasset(asset, destination, destWeight);
748 const events = await submitTransactionAsync(randomAccountMoonriver, tx);
749 const result = getGenericResult(events);
750 expect(result.success).to.be.true;
751576
752 // [balanceMovrTokenFinal] = await getBalance(api, [randomAccountMoonriver.address]);577 balanceMovrTokenFinal = await helper.balance.getEthereum(randomAccountMoonriver.address);
753 balanceMovrTokenFinal = await helper.balance.getSubstrate(randomAccountMoonriver.address);
754578
755 const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;579 const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;
756 console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', bigIntToDecimals(movrFees));580 console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', bigIntToDecimals(movrFees));
757 expect(movrFees > 0).to.be.true;581 expect(movrFees > 0).to.be.true;
758582
759 const qtzRandomAccountAsset = (583 const qtzRandomAccountAsset = await helper.assets.account(assetId, randomAccountMoonriver.address);
760 await helper.getApi().query.assets.account(assetId, randomAccountMoonriver.address)
761 ).toJSON()! as any;
762584
763 expect(qtzRandomAccountAsset).to.be.null;585 expect(qtzRandomAccountAsset).to.be.null;
764586
769 expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;591 expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
770 });592 });
771593
772 // await waitNewBlocks(api, 3);
773 await helper.wait.newBlocks(3);594 await helper.wait.newBlocks(3);
774595
775 // [balanceQuartzTokenFinal] = await getBalance(api, [randomAccountQuartz.address]);
776 balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccountQuartz.address);596 balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccountQuartz.address);
777 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;597 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
778 expect(actuallyDelivered > 0).to.be.true;598 expect(actuallyDelivered > 0).to.be.true;