git.delta.rocks / unique-network / refs/commits / 7319c348eee5

difftreelog

test scheduler won't blow up a block

Daniel Shiposha2022-11-09parent: #1fbfeb7.patch.diff
in: master

1 file changed

modifiedtests/src/scheduler.seqtest.tsdiffbeforeafterboth
146 );146 );
147 });147 });
148
149 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];
154
155 // 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;
162
163 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks;
164
165 const amount = 1n * helper.balance.getOneTokenNominal();
166
167 const balanceBefore = await helper.balance.getSubstrate(bob.address);
168
169 // Fill the target block
170 for (let i = 0; i < maxScheduledPerBlock; i++) {
171 await helper.scheduler.scheduleAt(fillScheduledIds[i], executionBlock)
172 .balance.transferToSubstrate(superuser, bob.address, amount);
173 }
174
175 // Try to schedule a task into a full block
176 await expect(helper.scheduler.scheduleAt(extraScheduledId, executionBlock)
177 .balance.transferToSubstrate(superuser, bob.address, amount))
178 .to.be.rejectedWith(/scheduler\.AgendaIsExhausted/);
179
180 await helper.wait.forParachainBlockNumber(executionBlock);
181
182 const balanceAfter = await helper.balance.getSubstrate(bob.address);
183
184 expect(balanceAfter > balanceBefore).to.be.true;
185
186 const diff = balanceAfter - balanceBefore;
187 expect(diff).to.be.equal(amount * BigInt(maxScheduledPerBlock));
188 });
148189
149 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();