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

difftreelog

refactor ifWithPallets only with testUtils

Daniel Shiposha2022-11-01parent: #4ad9af7.patch.diff
in: master

1 file changed

modifiedtests/src/scheduler.seqtest.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 {expect, itSub, Pallets, usingPlaygrounds} from './util';17import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {DevUniqueHelper} from './util/playgrounds/unique.dev';19import {DevUniqueHelper} from './util/playgrounds/unique.dev';
2020
23 let bob: IKeyringPair;23 let bob: IKeyringPair;
24 let charlie: IKeyringPair;24 let charlie: IKeyringPair;
2525
26 before(async () => {26 before(async function() {
27 await usingPlaygrounds(async (helper, privateKeyWrapper) => {27 await usingPlaygrounds(async (helper, privateKeyWrapper) => {
28 alice = await privateKeyWrapper('//Alice');28 alice = await privateKeyWrapper('//Alice');
29 bob = await privateKeyWrapper('//Bob');29 bob = await privateKeyWrapper('//Bob');
30 charlie = await privateKeyWrapper('//Charlie');30 charlie = await privateKeyWrapper('//Charlie');
31
32 requirePalletsOrSkip(this, helper, [Pallets.Scheduler]);
3133
32 await helper.testUtils.enable();34 await helper.testUtils.enable();
33 });35 });
34 });36 });
3537
36 itSub.ifWithPallets('Can delay a transfer of an owned token', [Pallets.Scheduler], async ({helper}) => {38 itSub('Can delay a transfer of an owned token', async ({helper}) => {
37 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});39 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});
38 const token = await collection.mintToken(alice);40 const token = await collection.mintToken(alice);
39 const schedulerId = await helper.arrange.makeScheduledId();41 const schedulerId = await helper.arrange.makeScheduledId();
49 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});51 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});
50 });52 });
5153
52 itSub.ifWithPallets('Can transfer funds periodically', [Pallets.Scheduler], async ({helper}) => {54 itSub('Can transfer funds periodically', async ({helper}) => {
53 const scheduledId = await helper.arrange.makeScheduledId();55 const scheduledId = await helper.arrange.makeScheduledId();
54 const waitForBlocks = 1;56 const waitForBlocks = 1;
5557
83 );85 );
84 });86 });
8587
86 itSub.ifWithPallets('Can cancel a scheduled operation which has not yet taken effect', [Pallets.Scheduler], async ({helper}) => {88 itSub('Can cancel a scheduled operation which has not yet taken effect', async ({helper}) => {
87 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});89 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});
88 const token = await collection.mintToken(alice);90 const token = await collection.mintToken(alice);
8991
102 expect(await token.getOwner()).to.be.deep.equal({Substrate: alice.address});104 expect(await token.getOwner()).to.be.deep.equal({Substrate: alice.address});
103 });105 });
104106
105 itSub.ifWithPallets('Can cancel a periodic operation (transfer of funds)', [Pallets.Scheduler], async ({helper}) => {107 itSub('Can cancel a periodic operation (transfer of funds)', async ({helper}) => {
106 const waitForBlocks = 1;108 const waitForBlocks = 1;
107 const periodic = {109 const periodic = {
108 period: 3,110 period: 3,
139 );141 );
140 });142 });
141143
142 itSub.ifWithPallets('Scheduled tasks are transactional', [Pallets.Scheduler, Pallets.TestUtils], async ({helper}) => {144 itSub.ifWithPallets('Scheduled tasks are transactional', [Pallets.TestUtils], async ({helper}) => {
143 const scheduledId = await helper.arrange.makeScheduledId();145 const scheduledId = await helper.arrange.makeScheduledId();
144 const waitForBlocks = 4;146 const waitForBlocks = 4;
145147
158 .to.be.equal(initTestVal);160 .to.be.equal(initTestVal);
159 });161 });
160162
161 itSub.ifWithPallets('Scheduled tasks should take correct fees', [Pallets.Scheduler, Pallets.TestUtils], async function({helper}) {163 itSub.ifWithPallets('Scheduled tasks should take correct fees', [Pallets.TestUtils], async function({helper}) {
162 const scheduledId = await helper.arrange.makeScheduledId();164 const scheduledId = await helper.arrange.makeScheduledId();
163 const waitForBlocks = 4;165 const waitForBlocks = 4;
164 const periodic = {166 const periodic = {
211213
212 // Check if we can cancel a scheduled periodic operation214 // Check if we can cancel a scheduled periodic operation
213 // in the same block in which it is running215 // in the same block in which it is running
214 itSub.ifWithPallets('Can cancel the periodic sheduled tx when the tx is running', [Pallets.Scheduler, Pallets.TestUtils], async ({helper}) => {216 itSub.ifWithPallets('Can cancel the periodic sheduled tx when the tx is running', [Pallets.TestUtils], async ({helper}) => {
215 const currentBlockNumber = await helper.chain.getLatestBlockNumber();217 const currentBlockNumber = await helper.chain.getLatestBlockNumber();
216 const blocksBeforeExecution = 10;218 const blocksBeforeExecution = 10;
217 const firstExecutionBlockNumber = currentBlockNumber + blocksBeforeExecution;219 const firstExecutionBlockNumber = currentBlockNumber + blocksBeforeExecution;
261 }263 }
262 });264 });
263265
264 itSub.ifWithPallets('A scheduled operation can cancel itself', [Pallets.Scheduler, Pallets.TestUtils], async ({helper}) => {266 itSub.ifWithPallets('A scheduled operation can cancel itself', [Pallets.TestUtils], async ({helper}) => {
265 const scheduledId = await helper.arrange.makeScheduledId();267 const scheduledId = await helper.arrange.makeScheduledId();
266 const waitForBlocks = 4;268 const waitForBlocks = 4;
267 const periodic = {269 const periodic = {
296 .to.be.equal(initTestVal + 2);298 .to.be.equal(initTestVal + 2);
297 });299 });
298300
299 itSub.ifWithPallets('Root can cancel any scheduled operation', [Pallets.Scheduler], async ({helper}) => {301 itSub('Root can cancel any scheduled operation', async ({helper}) => {
300 const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});302 const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});
301 const token = await collection.mintToken(bob);303 const token = await collection.mintToken(bob);
302304
313 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});315 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});
314 });316 });
315317
316 itSub.ifWithPallets('Root can set prioritized scheduled operation', [Pallets.Scheduler], async ({helper}) => {318 itSub('Root can set prioritized scheduled operation', async ({helper}) => {
317 const scheduledId = await helper.arrange.makeScheduledId();319 const scheduledId = await helper.arrange.makeScheduledId();
318 const waitForBlocks = 4;320 const waitForBlocks = 4;
319321
335 expect(diff).to.be.equal(amount);337 expect(diff).to.be.equal(amount);
336 });338 });
337339
338 itSub.ifWithPallets("Root can change scheduled operation's priority", [Pallets.Scheduler], async ({helper}) => {340 itSub("Root can change scheduled operation's priority", async ({helper}) => {
339 const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});341 const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});
340 const token = await collection.mintToken(bob);342 const token = await collection.mintToken(bob);
341343
358 expect(priorityChanged!.event.data[2].toString()).to.be.equal(priority.toString());360 expect(priorityChanged!.event.data[2].toString()).to.be.equal(priority.toString());
359 });361 });
360362
361 itSub.ifWithPallets('Prioritized operations executes in valid order', [Pallets.Scheduler], async ({helper}) => {363 itSub('Prioritized operations executes in valid order', async ({helper}) => {
362 const [364 const [
363 scheduledFirstId,365 scheduledFirstId,
364 scheduledSecondId,366 scheduledSecondId,
410 expect(secondExecuctionIds[1]).to.be.equal(scheduledSecondId);412 expect(secondExecuctionIds[1]).to.be.equal(scheduledSecondId);
411 });413 });
412414
413 itSub.ifWithPallets('Periodic operations always can be rescheduled', [Pallets.Scheduler], async ({helper}) => {415 itSub('Periodic operations always can be rescheduled', async ({helper}) => {
414 const maxScheduledPerBlock = 50;416 const maxScheduledPerBlock = 50;
415 const numFilledBlocks = 3;417 const numFilledBlocks = 3;
416 const ids = await helper.arrange.makeScheduledIds(numFilledBlocks * maxScheduledPerBlock + 1);418 const ids = await helper.arrange.makeScheduledIds(numFilledBlocks * maxScheduledPerBlock + 1);
470 let alice: IKeyringPair;472 let alice: IKeyringPair;
471 let bob: IKeyringPair;473 let bob: IKeyringPair;
472474
473 before(async () => {475 before(async function() {
474 await usingPlaygrounds(async (helper, privateKeyWrapper) => {476 await usingPlaygrounds(async (helper, privateKeyWrapper) => {
475 alice = await privateKeyWrapper('//Alice');477 alice = await privateKeyWrapper('//Alice');
476 bob = await privateKeyWrapper('//Bob');478 bob = await privateKeyWrapper('//Bob');
479
480 requirePalletsOrSkip(this, helper, [Pallets.Scheduler]);
477481
478 await helper.testUtils.enable();482 await helper.testUtils.enable();
479 });483 });
480 });484 });
481485
482 itSub.ifWithPallets("Can't overwrite a scheduled ID", [Pallets.Scheduler], async ({helper}) => {486 itSub("Can't overwrite a scheduled ID", async ({helper}) => {
483 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});487 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});
484 const token = await collection.mintToken(alice);488 const token = await collection.mintToken(alice);
485489
503 expect(bobsBalanceBefore).to.be.equal(bobsBalanceAfter);507 expect(bobsBalanceBefore).to.be.equal(bobsBalanceAfter);
504 });508 });
505509
506 itSub.ifWithPallets("Can't cancel an operation which is not scheduled", [Pallets.Scheduler], async ({helper}) => {510 itSub("Can't cancel an operation which is not scheduled", async ({helper}) => {
507 const scheduledId = await helper.arrange.makeScheduledId();511 const scheduledId = await helper.arrange.makeScheduledId();
508 await expect(helper.scheduler.cancelScheduled(alice, scheduledId))512 await expect(helper.scheduler.cancelScheduled(alice, scheduledId))
509 .to.be.rejectedWith(/scheduler\.NotFound/);513 .to.be.rejectedWith(/scheduler\.NotFound/);
510 });514 });
511515
512 itSub.ifWithPallets("Can't cancel a non-owned scheduled operation", [Pallets.Scheduler], async ({helper}) => {516 itSub("Can't cancel a non-owned scheduled operation", async ({helper}) => {
513 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});517 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});
514 const token = await collection.mintToken(alice);518 const token = await collection.mintToken(alice);
515519
527 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});531 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});
528 });532 });
529533
530 itSub.ifWithPallets("Regular user can't set prioritized scheduled operation", [Pallets.Scheduler], async ({helper}) => {534 itSub("Regular user can't set prioritized scheduled operation", async ({helper}) => {
531 const scheduledId = await helper.arrange.makeScheduledId();535 const scheduledId = await helper.arrange.makeScheduledId();
532 const waitForBlocks = 4;536 const waitForBlocks = 4;
533537
547 expect(balanceAfter).to.be.equal(balanceBefore);551 expect(balanceAfter).to.be.equal(balanceBefore);
548 });552 });
549553
550 itSub.ifWithPallets("Regular user can't change scheduled operation's priority", [Pallets.Scheduler], async ({helper}) => {554 itSub("Regular user can't change scheduled operation's priority", async ({helper}) => {
551 const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});555 const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});
552 const token = await collection.mintToken(bob);556 const token = await collection.mintToken(bob);
553557