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

difftreelog

test(itest) rescheduling always works

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

1 file changed

modifiedtests/src/scheduler.seqtest.tsdiffbeforeafterboth
410 expect(secondExecuctionIds[1]).to.be.equal(scheduledSecondId);410 expect(secondExecuctionIds[1]).to.be.equal(scheduledSecondId);
411 });411 });
412
413 itSub.ifWithPallets('Periodic operations always can be rescheduled', [Pallets.Scheduler], async ({helper}) => {
414 const maxScheduledPerBlock = 50;
415 const numFilledBlocks = 3;
416 const ids = await helper.arrange.makeScheduledIds(numFilledBlocks * maxScheduledPerBlock + 1);
417 const periodicId = ids[0];
418 const fillIds = ids.slice(1);
419
420 const initTestVal = 0;
421 const firstExecTestVal = 1;
422 const secondExecTestVal = 2;
423 await helper.testUtils.setTestValue(alice, initTestVal);
424
425 const currentBlockNumber = await helper.chain.getLatestBlockNumber();
426 const blocksBeforeExecution = 8;
427 const firstExecutionBlockNumber = currentBlockNumber + blocksBeforeExecution;
428
429 const period = 5;
430
431 const periodic = {
432 period,
433 repetitions: 2,
434 };
435
436 // Fill `numFilledBlocks` blocks beginning from the block in which the second execution should occur
437 const txs = [];
438 for (let offset = 0; offset < numFilledBlocks; offset ++) {
439 for (let i = 0; i < maxScheduledPerBlock; i++) {
440
441 const scheduledTx = helper.constructApiCall('api.tx.balances.transfer', [bob.address, 1n]);
442
443 const when = firstExecutionBlockNumber + period + offset;
444 const tx = helper.constructApiCall('api.tx.scheduler.scheduleNamed', [fillIds[i + offset * maxScheduledPerBlock], when, null, null, scheduledTx]);
445
446 txs.push(tx);
447 }
448 }
449 await helper.executeExtrinsic(alice, 'api.tx.testUtils.batchAll', [txs], true);
450
451 await helper.scheduler.scheduleAt<DevUniqueHelper>(periodicId, firstExecutionBlockNumber, {periodic})
452 .testUtils.incTestValue(alice);
453
454 await helper.wait.newBlocks(blocksBeforeExecution);
455 expect(await helper.testUtils.testValue()).to.be.equal(firstExecTestVal);
456
457 await helper.wait.newBlocks(period + numFilledBlocks);
458
459 // The periodic operation should be postponed by `numFilledBlocks`
460 for (let i = 0; i < numFilledBlocks; i++) {
461 expect(await helper.testUtils.testValue(firstExecutionBlockNumber + period + i)).to.be.equal(firstExecTestVal);
462 }
463
464 // After the `numFilledBlocks` the periodic operation will eventually be executed
465 expect(await helper.testUtils.testValue()).to.be.equal(secondExecTestVal);
466 });
412});467});
413468
414describe('Negative Test: Scheduling', () => {469describe('Negative Test: Scheduling', () => {