1234567891011121314151617import {expect, itSched, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {DevUniqueHelper, Event} from './util/playgrounds/unique.dev';2021describe('Scheduling token and balance transfers', () => {22 let superuser: IKeyringPair;23 let alice: IKeyringPair;24 let bob: IKeyringPair;25 let charlie: IKeyringPair;2627 before(async function() {28 await usingPlaygrounds(async (helper, privateKey) => {29 requirePalletsOrSkip(this, helper, [Pallets.Scheduler]);3031 superuser = await privateKey('//Alice');32 const donor = await privateKey({url: import.meta.url});33 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);3435 await helper.testUtils.enable();36 });37 });3839 beforeEach(async () => {40 await usingPlaygrounds(async (helper) => {41 await helper.wait.noScheduledTasks();42 });43 });4445 itSched('Can delay a transfer of an owned token', async (scheduleKind, {helper}) => {46 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});47 const token = await collection.mintToken(alice);48 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;49 const blocksBeforeExecution = 4;5051 await token.scheduleAfter(blocksBeforeExecution, {scheduledId})52 .transfer(alice, {Substrate: bob.address});53 const executionBlock = await helper.chain.getLatestBlockNumber() + blocksBeforeExecution + 1;5455 expect(await token.getOwner()).to.be.deep.equal({Substrate: alice.address});5657 await helper.wait.forParachainBlockNumber(executionBlock);5859 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});60 });6162 itSched('Can transfer funds periodically', async (scheduleKind, {helper}) => {63 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;64 const waitForBlocks = 1;6566 const amount = 1n * helper.balance.getOneTokenNominal();67 const periodic = {68 period: 2,69 repetitions: 2,70 };7172 const bobsBalanceBefore = await helper.balance.getSubstrate(bob.address);7374 await helper.scheduler.scheduleAfter(waitForBlocks, {scheduledId, periodic})75 .balance.transferToSubstrate(alice, bob.address, amount);76 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;7778 await helper.wait.forParachainBlockNumber(executionBlock);7980 const bobsBalanceAfterFirst = await helper.balance.getSubstrate(bob.address);81 expect(bobsBalanceAfterFirst)82 .to.be.equal(83 bobsBalanceBefore + 1n * amount,84 '#1 Balance of the recipient should be increased by 1 * amount',85 );8687 await helper.wait.forParachainBlockNumber(executionBlock + periodic.period);8889 const bobsBalanceAfterSecond = await helper.balance.getSubstrate(bob.address);90 expect(bobsBalanceAfterSecond)91 .to.be.equal(92 bobsBalanceBefore + 2n * amount,93 '#2 Balance of the recipient should be increased by 2 * amount',94 );95 });9697 itSub('Can cancel a scheduled operation which has not yet taken effect', async ({helper}) => {98 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});99 const token = await collection.mintToken(alice);100101 const scheduledId = helper.arrange.makeScheduledId();102 const waitForBlocks = 4;103104 expect(await token.getOwner()).to.be.deep.equal({Substrate: alice.address});105106 await token.scheduleAfter(waitForBlocks, {scheduledId})107 .transfer(alice, {Substrate: bob.address});108 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;109110 await helper.scheduler.cancelScheduled(alice, scheduledId);111112 await helper.wait.forParachainBlockNumber(executionBlock);113114 expect(await token.getOwner()).to.be.deep.equal({Substrate: alice.address});115 });116117 itSub('Can cancel a periodic operation (transfer of funds)', async ({helper}) => {118 const waitForBlocks = 1;119 const periodic = {120 period: 3,121 repetitions: 2,122 };123124 const scheduledId = helper.arrange.makeScheduledId();125126 const amount = 1n * helper.balance.getOneTokenNominal();127128 const bobsBalanceBefore = await helper.balance.getSubstrate(bob.address);129130 await helper.scheduler.scheduleAfter(waitForBlocks, {scheduledId, periodic})131 .balance.transferToSubstrate(alice, bob.address, amount);132 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;133134 await helper.wait.forParachainBlockNumber(executionBlock);135136 const bobsBalanceAfterFirst = await helper.balance.getSubstrate(bob.address);137138 expect(bobsBalanceAfterFirst)139 .to.be.equal(140 bobsBalanceBefore + 1n * amount,141 '#1 Balance of the recipient should be increased by 1 * amount',142 );143144 await helper.scheduler.cancelScheduled(alice, scheduledId);145 await helper.wait.forParachainBlockNumber(executionBlock + periodic.period);146147 const bobsBalanceAfterSecond = await helper.balance.getSubstrate(bob.address);148 expect(bobsBalanceAfterSecond)149 .to.be.equal(150 bobsBalanceAfterFirst,151 '#2 Balance of the recipient should not be changed',152 );153 });154155 itSched('scheduler will not insert more tasks than allowed', async (scheduleKind, {helper}) => {156 const maxScheduledPerBlock = 50;157 let fillScheduledIds = new Array(maxScheduledPerBlock);158 let extraScheduledId = undefined;159160 if(scheduleKind == 'named') {161 const scheduledIds = helper.arrange.makeScheduledIds(maxScheduledPerBlock + 1);162 fillScheduledIds = scheduledIds.slice(0, maxScheduledPerBlock);163 extraScheduledId = scheduledIds[maxScheduledPerBlock];164 }165166 167 168 169 170 171 172 const waitForBlocks = await helper.arrange.isDevNode() ? maxScheduledPerBlock + 5 : 5;173174 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks;175176 const amount = 1n * helper.balance.getOneTokenNominal();177178 const balanceBefore = await helper.balance.getSubstrate(bob.address);179180 181 for(let i = 0; i < maxScheduledPerBlock; i++) {182 await helper.scheduler.scheduleAt(executionBlock, {scheduledId: fillScheduledIds[i]})183 .balance.transferToSubstrate(superuser, bob.address, amount);184 }185186 187 await expect(helper.scheduler.scheduleAt(executionBlock, {scheduledId: extraScheduledId})188 .balance.transferToSubstrate(superuser, bob.address, amount))189 .to.be.rejectedWith(/scheduler\.AgendaIsExhausted/);190191 await helper.wait.forParachainBlockNumber(executionBlock);192193 const balanceAfter = await helper.balance.getSubstrate(bob.address);194195 expect(balanceAfter > balanceBefore).to.be.true;196197 const diff = balanceAfter - balanceBefore;198 expect(diff).to.be.equal(amount * BigInt(maxScheduledPerBlock));199 });200201 itSched.ifWithPallets('Scheduled tasks are transactional', [Pallets.TestUtils], async (scheduleKind, {helper}) => {202 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;203 const waitForBlocks = 4;204205 const initTestVal = 42;206 const changedTestVal = 111;207208 await helper.testUtils.setTestValue(alice, initTestVal);209210 await helper.scheduler.scheduleAfter<DevUniqueHelper>(waitForBlocks, {scheduledId})211 .testUtils.setTestValueAndRollback(alice, changedTestVal);212 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;213214 await helper.wait.forParachainBlockNumber(executionBlock);215216 const testVal = await helper.testUtils.testValue();217 expect(testVal, 'The test value should NOT be commited')218 .to.be.equal(initTestVal);219 });220221 itSched.ifWithPallets('Scheduled tasks should take correct fees', [Pallets.TestUtils], async function(scheduleKind, {helper}) {222 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;223 const waitForBlocks = 4;224 const periodic = {225 period: 2,226 repetitions: 2,227 };228229 const dummyTx = helper.constructApiCall('api.tx.testUtils.justTakeFee', []);230 const scheduledLen = dummyTx.callIndex.length;231232 const expectedScheduledFee = (await helper.getPaymentInfo(alice, dummyTx, scheduledLen))233 .partialFee.toBigInt();234235 await helper.scheduler.scheduleAfter<DevUniqueHelper>(waitForBlocks, {scheduledId, periodic})236 .testUtils.justTakeFee(alice);237 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;238239 const aliceInitBalance = await helper.balance.getSubstrate(alice.address);240 let diff;241242 await helper.wait.forParachainBlockNumber(executionBlock);243244 const aliceBalanceAfterFirst = await helper.balance.getSubstrate(alice.address);245 expect(246 aliceBalanceAfterFirst < aliceInitBalance,247 '[after execution #1] Scheduled task should take a fee',248 ).to.be.true;249250 diff = aliceInitBalance - aliceBalanceAfterFirst;251 expect(diff).to.be.equal(252 expectedScheduledFee,253 'Scheduled task should take the right amount of fees',254 );255256 await helper.wait.forParachainBlockNumber(executionBlock + periodic.period);257258 const aliceBalanceAfterSecond = await helper.balance.getSubstrate(alice.address);259 expect(260 aliceBalanceAfterSecond < aliceBalanceAfterFirst,261 '[after execution #2] Scheduled task should take a fee',262 ).to.be.true;263264 diff = aliceBalanceAfterFirst - aliceBalanceAfterSecond;265 expect(diff).to.be.equal(266 expectedScheduledFee,267 'Scheduled task should take the right amount of fees',268 );269 });270271 272 273 itSub.ifWithPallets('Can cancel the periodic sheduled tx when the tx is running', [Pallets.TestUtils], async ({helper}) => {274 const currentBlockNumber = await helper.chain.getLatestBlockNumber();275 const blocksBeforeExecution = 10;276 const firstExecutionBlockNumber = currentBlockNumber + blocksBeforeExecution;277278 const [279 scheduledId,280 scheduledCancelId,281 ] = helper.arrange.makeScheduledIds(2);282283 const periodic = {284 period: 5,285 repetitions: 5,286 };287288 const initTestVal = 0;289 const incTestVal = initTestVal + 1;290 const finalTestVal = initTestVal + 2;291292 await helper.testUtils.setTestValue(alice, initTestVal);293294 await helper.scheduler.scheduleAt<DevUniqueHelper>(firstExecutionBlockNumber, {scheduledId, periodic})295 .testUtils.incTestValue(alice);296297 298 299 await helper.scheduler.scheduleAt(300 firstExecutionBlockNumber + periodic.period,301 {scheduledId: scheduledCancelId},302 ).scheduler.cancelScheduled(alice, scheduledId);303304 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber);305306 307 expect(await helper.testUtils.testValue())308 .to.be.equal(incTestVal);309310 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber + periodic.period);311312 313 expect(await helper.testUtils.testValue())314 .to.be.equal(finalTestVal);315316 for(let i = 1; i < periodic.repetitions; i++) {317 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber + periodic.period * (i + 1));318 expect(await helper.testUtils.testValue())319 .to.be.equal(finalTestVal);320 }321 });322323 itSub.ifWithPallets('A scheduled operation can cancel itself', [Pallets.TestUtils], async ({helper}) => {324 const scheduledId = helper.arrange.makeScheduledId();325 const waitForBlocks = 4;326 const periodic = {327 period: 2,328 repetitions: 5,329 };330331 const initTestVal = 0;332 const maxTestVal = 2;333334 await helper.testUtils.setTestValue(alice, initTestVal);335336 await helper.scheduler.scheduleAfter<DevUniqueHelper>(waitForBlocks, {scheduledId, periodic})337 .testUtils.selfCancelingInc(alice, scheduledId, maxTestVal);338 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;339340 await helper.wait.forParachainBlockNumber(executionBlock);341342 343 expect(await helper.testUtils.testValue())344 .to.be.equal(initTestVal + 1);345346 await helper.wait.forParachainBlockNumber(executionBlock + periodic.period);347348 349 expect(await helper.testUtils.testValue())350 .to.be.equal(initTestVal + 2);351352 await helper.wait.forParachainBlockNumber(executionBlock + 2 * periodic.period);353354 355 expect(await helper.testUtils.testValue())356 .to.be.equal(initTestVal + 2);357 });358359 itSub('Root can cancel any scheduled operation', async ({helper}) => {360 const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});361 const token = await collection.mintToken(bob);362363 const scheduledId = helper.arrange.makeScheduledId();364 const waitForBlocks = 4;365366 await token.scheduleAfter(waitForBlocks, {scheduledId})367 .transfer(bob, {Substrate: alice.address});368 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;369370 await helper.getSudo().scheduler.cancelScheduled(superuser, scheduledId);371372 await helper.wait.forParachainBlockNumber(executionBlock);373374 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});375 });376377 itSched('Root can set prioritized scheduled operation', async (scheduleKind, {helper}) => {378 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;379 const waitForBlocks = 4;380381 const amount = 42n * helper.balance.getOneTokenNominal();382383 const balanceBefore = await helper.balance.getSubstrate(charlie.address);384385 await helper.getSudo()386 .scheduler.scheduleAfter(waitForBlocks, {scheduledId, priority: 42})387 .balance.forceTransferToSubstrate(superuser, bob.address, charlie.address, amount);388 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;389390 await helper.wait.forParachainBlockNumber(executionBlock);391392 const balanceAfter = await helper.balance.getSubstrate(charlie.address);393394 expect(balanceAfter > balanceBefore).to.be.true;395396 const diff = balanceAfter - balanceBefore;397 expect(diff).to.be.equal(amount);398 });399400 itSub("Root can change scheduled operation's priority", async ({helper}) => {401 const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});402 const token = await collection.mintToken(bob);403404 const scheduledId = helper.arrange.makeScheduledId();405 const waitForBlocks = 6;406407 await token.scheduleAfter(waitForBlocks, {scheduledId})408 .transfer(bob, {Substrate: alice.address});409 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;410411 const priority = 112;412 await helper.getSudo().scheduler.changePriority(superuser, scheduledId, priority);413414 const priorityChanged = await helper.wait.expectEvent(waitForBlocks, Event.Scheduler.PriorityChanged);415416 const [blockNumber, index] = priorityChanged.task();417 expect(blockNumber).to.be.equal(executionBlock);418 expect(index).to.be.equal(0);419420 expect(priorityChanged.priority().toString()).to.be.equal(priority.toString());421 });422423 itSub('Prioritized operations execute in valid order', async ({helper}) => {424 const [425 scheduledFirstId,426 scheduledSecondId,427 ] = helper.arrange.makeScheduledIds(2);428429 const currentBlockNumber = await helper.chain.getLatestBlockNumber();430 const blocksBeforeExecution = 6;431 const firstExecutionBlockNumber = currentBlockNumber + blocksBeforeExecution;432433 const prioHigh = 0;434 const prioLow = 255;435436 const periodic = {437 period: 6,438 repetitions: 2,439 };440441 const amount = 1n * helper.balance.getOneTokenNominal();442443 444 await helper.getSudo().scheduler.scheduleAt(firstExecutionBlockNumber, {445 scheduledId: scheduledFirstId,446 priority: prioLow,447 periodic,448 }).balance.forceTransferToSubstrate(superuser, alice.address, bob.address, amount);449450 await helper.getSudo().scheduler.scheduleAt(firstExecutionBlockNumber, {451 scheduledId: scheduledSecondId,452 priority: prioHigh,453 periodic,454 }).balance.forceTransferToSubstrate(superuser, alice.address, bob.address, amount);455456 const capture = await helper.arrange.captureEvents('scheduler', 'Dispatched');457458 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber);459460 461 await helper.getSudo().scheduler.changePriority(superuser, scheduledFirstId, prioHigh);462 await helper.getSudo().scheduler.changePriority(superuser, scheduledSecondId, prioLow);463464 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber + periodic.period);465466 const dispatchEvents = capture.extractCapturedEvents();467 expect(dispatchEvents.length).to.be.equal(4);468469 const dispatchedIds = dispatchEvents.map(r => r.event.data[1].toString());470471 const firstExecuctionIds = [dispatchedIds[0], dispatchedIds[1]];472 const secondExecuctionIds = [dispatchedIds[2], dispatchedIds[3]];473474 expect(firstExecuctionIds[0]).to.be.equal(scheduledSecondId);475 expect(firstExecuctionIds[1]).to.be.equal(scheduledFirstId);476477 expect(secondExecuctionIds[0]).to.be.equal(scheduledFirstId);478 expect(secondExecuctionIds[1]).to.be.equal(scheduledSecondId);479 });480481 itSched('Periodic operations always can be rescheduled', async (scheduleKind, {helper}) => {482 const maxScheduledPerBlock = 50;483 const numFilledBlocks = 3;484 const ids = helper.arrange.makeScheduledIds(numFilledBlocks * maxScheduledPerBlock + 1);485 const periodicId = scheduleKind == 'named' ? ids[0] : undefined;486 const fillIds = ids.slice(1);487488 const fillScheduleFn = scheduleKind == 'named' ? 'scheduleNamed' : 'schedule';489490 const initTestVal = 0;491 const firstExecTestVal = 1;492 const secondExecTestVal = 2;493 await helper.testUtils.setTestValue(alice, initTestVal);494495 const currentBlockNumber = await helper.chain.getLatestBlockNumber();496 const blocksBeforeExecution = 8;497 const firstExecutionBlockNumber = currentBlockNumber + blocksBeforeExecution;498499 const period = 5;500501 const periodic = {502 period,503 repetitions: 2,504 };505506 507 const txs = [];508 for(let offset = 0; offset < numFilledBlocks; offset ++) {509 for(let i = 0; i < maxScheduledPerBlock; i++) {510511 const scheduledTx = helper.constructApiCall('api.tx.balances.transfer', [bob.address, 1n]);512513 const when = firstExecutionBlockNumber + period + offset;514 const mandatoryArgs = [when, null, null, scheduledTx];515 const scheduleArgs = scheduleKind == 'named'516 ? [fillIds[i + offset * maxScheduledPerBlock], ...mandatoryArgs]517 : mandatoryArgs;518519 const tx = helper.constructApiCall(`api.tx.scheduler.${fillScheduleFn}`, scheduleArgs);520521 txs.push(tx);522 }523 }524 await helper.executeExtrinsic(alice, 'api.tx.testUtils.batchAll', [txs], true);525526 await helper.scheduler.scheduleAt<DevUniqueHelper>(firstExecutionBlockNumber, {527 scheduledId: periodicId,528 periodic,529 }).testUtils.incTestValue(alice);530531 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber);532 expect(await helper.testUtils.testValue()).to.be.equal(firstExecTestVal);533534 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber + period + numFilledBlocks);535536 537 for(let i = 0; i < numFilledBlocks; i++) {538 expect(await helper.testUtils.testValue(firstExecutionBlockNumber + period + i)).to.be.equal(firstExecTestVal);539 }540541 542 expect(await helper.testUtils.testValue()).to.be.equal(secondExecTestVal);543 });544545 itSched('scheduled operations does not change nonce', async (scheduleKind, {helper}) => {546 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;547 const blocksBeforeExecution = 4;548549 await helper.scheduler550 .scheduleAfter<DevUniqueHelper>(blocksBeforeExecution, {scheduledId})551 .balance.transferToSubstrate(alice, bob.address, 1n);552 const executionBlock = await helper.chain.getLatestBlockNumber() + blocksBeforeExecution + 1;553554 const initNonce = await helper.chain.getNonce(alice.address);555556 await helper.wait.forParachainBlockNumber(executionBlock);557558 const finalNonce = await helper.chain.getNonce(alice.address);559560 expect(initNonce).to.be.equal(finalNonce);561 });562});563564describe('Negative Test: Scheduling', () => {565 let alice: IKeyringPair;566 let bob: IKeyringPair;567568 before(async function() {569 await usingPlaygrounds(async (helper, privateKey) => {570 requirePalletsOrSkip(this, helper, [Pallets.Scheduler]);571572 const donor = await privateKey({url: import.meta.url});573 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);574575 await helper.testUtils.enable();576 });577 });578579 itSub("Can't overwrite a scheduled ID", async ({helper}) => {580 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});581 const token = await collection.mintToken(alice);582583 const scheduledId = helper.arrange.makeScheduledId();584 const waitForBlocks = 4;585586 await token.scheduleAfter(waitForBlocks, {scheduledId})587 .transfer(alice, {Substrate: bob.address});588 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;589590 const scheduled = helper.scheduler.scheduleAfter(waitForBlocks, {scheduledId});591 await expect(scheduled.balance.transferToSubstrate(alice, bob.address, 1n * helper.balance.getOneTokenNominal()))592 .to.be.rejectedWith(/scheduler\.FailedToSchedule/);593594 const bobsBalanceBefore = await helper.balance.getSubstrate(bob.address);595596 await helper.wait.forParachainBlockNumber(executionBlock);597598 const bobsBalanceAfter = await helper.balance.getSubstrate(bob.address);599600 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});601 expect(bobsBalanceBefore).to.be.equal(bobsBalanceAfter);602 });603604 itSub("Can't cancel an operation which is not scheduled", async ({helper}) => {605 const scheduledId = helper.arrange.makeScheduledId();606 await expect(helper.scheduler.cancelScheduled(alice, scheduledId))607 .to.be.rejectedWith(/scheduler\.NotFound/);608 });609610 itSub("Can't cancel a non-owned scheduled operation", async ({helper}) => {611 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});612 const token = await collection.mintToken(alice);613614 const scheduledId = helper.arrange.makeScheduledId();615 const waitForBlocks = 4;616617 await token.scheduleAfter(waitForBlocks, {scheduledId})618 .transfer(alice, {Substrate: bob.address});619 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;620621 await expect(helper.scheduler.cancelScheduled(bob, scheduledId))622 .to.be.rejectedWith(/BadOrigin/);623624 await helper.wait.forParachainBlockNumber(executionBlock);625626 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});627 });628629 itSched("Regular user can't set prioritized scheduled operation", async (scheduleKind, {helper}) => {630 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;631 const waitForBlocks = 4;632633 const amount = 42n * helper.balance.getOneTokenNominal();634635 const balanceBefore = await helper.balance.getSubstrate(bob.address);636637 const scheduled = helper.scheduler.scheduleAfter(waitForBlocks, {scheduledId, priority: 42});638639 await expect(scheduled.balance.transferToSubstrate(alice, bob.address, amount))640 .to.be.rejectedWith(/BadOrigin/);641642 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;643644 await helper.wait.forParachainBlockNumber(executionBlock);645646 const balanceAfter = await helper.balance.getSubstrate(bob.address);647648 expect(balanceAfter).to.be.equal(balanceBefore);649 });650651 itSub("Regular user can't change scheduled operation's priority", async ({helper}) => {652 const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});653 const token = await collection.mintToken(bob);654655 const scheduledId = helper.arrange.makeScheduledId();656 const waitForBlocks = 4;657658 await token.scheduleAfter(waitForBlocks, {scheduledId})659 .transfer(bob, {Substrate: alice.address});660661 const priority = 112;662 await expect(helper.scheduler.changePriority(alice, scheduledId, priority))663 .to.be.rejectedWith(/BadOrigin/);664665 await helper.wait.expectEvent(waitForBlocks, Event.Scheduler.PriorityChanged);666 });667});668669670describe.skip('Sponsoring scheduling', () => {671 672 673674 675 676 677 678 679 680681 it('Can sponsor scheduling a transaction', async () => {682 683 684 685686 687 688 689690 691 692 693 694 695 696 697 698 699 700 });701702 it('Schedules and dispatches a transaction even if the caller has no funds at the time of the dispatch', async () => {703 704 705 706707 708709 710 711 712713 714 715 716717 718 719 720721 722 723 724725 726 727 728 729 730 731 732 733734 735 736737 738 739 });740741 it('Sponsor going bankrupt does not impact a scheduled transaction', async () => {742 743744 745 746 747 748749 750 751752 753 754755 756 757758 759 760 761 762763 764 765766 767 768 });769770 it('Exceeding sponsor rate limit without having enough funds prevents scheduling a periodic transaction', async () => {771 772 773 774775 776 777778 779 780781 782783 784 785 786787 788 789 790 791792 793794 795 796 });797});