difftreelog
test scheduler won't blow up a block
in: master
1 file changed
tests/src/scheduler.seqtest.tsdiffbeforeafterboth146 );146 );147 });147 });148149 itSub('scheduler will not insert more tasks than allowed', async ({helper}) => {150 const maxScheduledPerBlock = 50;151 const scheduledIds = await helper.arrange.makeScheduledIds(maxScheduledPerBlock + 1);152 const fillScheduledIds = scheduledIds.slice(0, maxScheduledPerBlock);153 const extraScheduledId = scheduledIds[maxScheduledPerBlock];154155 // Since the dev node has Instant Seal,156 // we need a larger gap between the current block and the target one.157 //158 // We will schedule `maxScheduledPerBlock` transaction into the target block,159 // so we need at least `maxScheduledPerBlock`-wide gap.160 // We add some additional blocks to this gap to mitigate possible PolkadotJS delays.161 const waitForBlocks = await helper.arrange.isDevNode() ? maxScheduledPerBlock + 5 : 5;162163 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks;164165 const amount = 1n * helper.balance.getOneTokenNominal();166167 const balanceBefore = await helper.balance.getSubstrate(bob.address);168169 // Fill the target block170 for (let i = 0; i < maxScheduledPerBlock; i++) {171 await helper.scheduler.scheduleAt(fillScheduledIds[i], executionBlock)172 .balance.transferToSubstrate(superuser, bob.address, amount);173 }174175 // Try to schedule a task into a full block176 await expect(helper.scheduler.scheduleAt(extraScheduledId, executionBlock)177 .balance.transferToSubstrate(superuser, bob.address, amount))178 .to.be.rejectedWith(/scheduler\.AgendaIsExhausted/);179180 await helper.wait.forParachainBlockNumber(executionBlock);181182 const balanceAfter = await helper.balance.getSubstrate(bob.address);183184 expect(balanceAfter > balanceBefore).to.be.true;185186 const diff = balanceAfter - balanceBefore;187 expect(diff).to.be.equal(amount * BigInt(maxScheduledPerBlock));188 });148189149 itSub.ifWithPallets('Scheduled tasks are transactional', [Pallets.TestUtils], async ({helper}) => {190 itSub.ifWithPallets('Scheduled tasks are transactional', [Pallets.TestUtils], async ({helper}) => {150 const scheduledId = await helper.arrange.makeScheduledId();191 const scheduledId = await helper.arrange.makeScheduledId();