1234567891011121314151617import {expect, itSched, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {DevUniqueHelper} 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({filename: __filename});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;50 51 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;159 160 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.event(415 waitForBlocks,416 'scheduler',417 'PriorityChanged',418 );419420 expect(priorityChanged !== null).to.be.true;421422 const [blockNumber, index] = priorityChanged!.event.data[0].toJSON() as any[];423 expect(blockNumber).to.be.equal(executionBlock);424 expect(index).to.be.equal(0);425426 expect(priorityChanged!.event.data[1].toString()).to.be.equal(priority.toString());427 });428429 itSub('Prioritized operations execute in valid order', async ({helper}) => {430 const [431 scheduledFirstId,432 scheduledSecondId,433 ] = helper.arrange.makeScheduledIds(2);434435 const currentBlockNumber = await helper.chain.getLatestBlockNumber();436 const blocksBeforeExecution = 6;437 const firstExecutionBlockNumber = currentBlockNumber + blocksBeforeExecution;438439 const prioHigh = 0;440 const prioLow = 255;441442 const periodic = {443 period: 6,444 repetitions: 2,445 };446447 const amount = 1n * helper.balance.getOneTokenNominal();448449 450 await helper.getSudo().scheduler.scheduleAt(firstExecutionBlockNumber, {451 scheduledId: scheduledFirstId,452 priority: prioLow,453 periodic,454 }).balance.forceTransferToSubstrate(superuser, alice.address, bob.address, amount);455456 await helper.getSudo().scheduler.scheduleAt(firstExecutionBlockNumber, {457 scheduledId: scheduledSecondId,458 priority: prioHigh,459 periodic,460 }).balance.forceTransferToSubstrate(superuser, alice.address, bob.address, amount);461462 const capture = await helper.arrange.captureEvents('scheduler', 'Dispatched');463464 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber);465466 467 await helper.getSudo().scheduler.changePriority(superuser, scheduledFirstId, prioHigh);468 await helper.getSudo().scheduler.changePriority(superuser, scheduledSecondId, prioLow);469470 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber + periodic.period);471472 const dispatchEvents = capture.extractCapturedEvents();473 expect(dispatchEvents.length).to.be.equal(4);474475 const dispatchedIds = dispatchEvents.map(r => r.event.data[1].toString());476477 const firstExecuctionIds = [dispatchedIds[0], dispatchedIds[1]];478 const secondExecuctionIds = [dispatchedIds[2], dispatchedIds[3]];479480 expect(firstExecuctionIds[0]).to.be.equal(scheduledSecondId);481 expect(firstExecuctionIds[1]).to.be.equal(scheduledFirstId);482483 expect(secondExecuctionIds[0]).to.be.equal(scheduledFirstId);484 expect(secondExecuctionIds[1]).to.be.equal(scheduledSecondId);485 });486487 itSched('Periodic operations always can be rescheduled', async (scheduleKind, {helper}) => {488 const maxScheduledPerBlock = 50;489 const numFilledBlocks = 3;490 const ids = helper.arrange.makeScheduledIds(numFilledBlocks * maxScheduledPerBlock + 1);491 const periodicId = scheduleKind == 'named' ? ids[0] : undefined;492 const fillIds = ids.slice(1);493494 const fillScheduleFn = scheduleKind == 'named' ? 'scheduleNamed' : 'schedule';495496 const initTestVal = 0;497 const firstExecTestVal = 1;498 const secondExecTestVal = 2;499 await helper.testUtils.setTestValue(alice, initTestVal);500501 const currentBlockNumber = await helper.chain.getLatestBlockNumber();502 const blocksBeforeExecution = 8;503 const firstExecutionBlockNumber = currentBlockNumber + blocksBeforeExecution;504505 const period = 5;506507 const periodic = {508 period,509 repetitions: 2,510 };511512 513 const txs = [];514 for (let offset = 0; offset < numFilledBlocks; offset ++) {515 for (let i = 0; i < maxScheduledPerBlock; i++) {516517 const scheduledTx = helper.constructApiCall('api.tx.balances.transfer', [bob.address, 1n]);518519 const when = firstExecutionBlockNumber + period + offset;520 const mandatoryArgs = [when, null, null, scheduledTx];521 const scheduleArgs = scheduleKind == 'named'522 ? [fillIds[i + offset * maxScheduledPerBlock], ...mandatoryArgs]523 : mandatoryArgs;524525 const tx = helper.constructApiCall(`api.tx.scheduler.${fillScheduleFn}`, scheduleArgs);526527 txs.push(tx);528 }529 }530 await helper.executeExtrinsic(alice, 'api.tx.testUtils.batchAll', [txs], true);531532 await helper.scheduler.scheduleAt<DevUniqueHelper>(firstExecutionBlockNumber, {533 scheduledId: periodicId,534 periodic,535 }).testUtils.incTestValue(alice);536537 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber);538 expect(await helper.testUtils.testValue()).to.be.equal(firstExecTestVal);539540 await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber + period + numFilledBlocks);541542 543 for (let i = 0; i < numFilledBlocks; i++) {544 expect(await helper.testUtils.testValue(firstExecutionBlockNumber + period + i)).to.be.equal(firstExecTestVal);545 }546547 548 expect(await helper.testUtils.testValue()).to.be.equal(secondExecTestVal);549 });550551 itSched('scheduled operations does not change nonce', async (scheduleKind, {helper}) => {552 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;553 const blocksBeforeExecution = 4;554555 await helper.scheduler556 .scheduleAfter<DevUniqueHelper>(blocksBeforeExecution, {scheduledId})557 .balance.transferToSubstrate(alice, bob.address, 1n);558 const executionBlock = await helper.chain.getLatestBlockNumber() + blocksBeforeExecution + 1;559560 const initNonce = await helper.chain.getNonce(alice.address);561562 await helper.wait.forParachainBlockNumber(executionBlock);563564 const finalNonce = await helper.chain.getNonce(alice.address);565566 expect(initNonce).to.be.equal(finalNonce);567 });568});569570describe('Negative Test: Scheduling', () => {571 let alice: IKeyringPair;572 let bob: IKeyringPair;573574 before(async function() {575 await usingPlaygrounds(async (helper, privateKey) => {576 requirePalletsOrSkip(this, helper, [Pallets.Scheduler]);577578 const donor = await privateKey({filename: __filename});579 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);580581 await helper.testUtils.enable();582 });583 });584585 itSub("Can't overwrite a scheduled ID", async ({helper}) => {586 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});587 const token = await collection.mintToken(alice);588589 const scheduledId = helper.arrange.makeScheduledId();590 const waitForBlocks = 4;591592 await token.scheduleAfter(waitForBlocks, {scheduledId})593 .transfer(alice, {Substrate: bob.address});594 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;595596 const scheduled = helper.scheduler.scheduleAfter(waitForBlocks, {scheduledId});597 await expect(scheduled.balance.transferToSubstrate(alice, bob.address, 1n * helper.balance.getOneTokenNominal()))598 .to.be.rejectedWith(/scheduler\.FailedToSchedule/);599600 const bobsBalanceBefore = await helper.balance.getSubstrate(bob.address);601602 await helper.wait.forParachainBlockNumber(executionBlock);603604 const bobsBalanceAfter = await helper.balance.getSubstrate(bob.address);605606 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});607 expect(bobsBalanceBefore).to.be.equal(bobsBalanceAfter);608 });609610 itSub("Can't cancel an operation which is not scheduled", async ({helper}) => {611 const scheduledId = helper.arrange.makeScheduledId();612 await expect(helper.scheduler.cancelScheduled(alice, scheduledId))613 .to.be.rejectedWith(/scheduler\.NotFound/);614 });615616 itSub("Can't cancel a non-owned scheduled operation", async ({helper}) => {617 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});618 const token = await collection.mintToken(alice);619620 const scheduledId = helper.arrange.makeScheduledId();621 const waitForBlocks = 4;622623 await token.scheduleAfter(waitForBlocks, {scheduledId})624 .transfer(alice, {Substrate: bob.address});625 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;626627 await expect(helper.scheduler.cancelScheduled(bob, scheduledId))628 .to.be.rejectedWith(/BadOrigin/);629630 await helper.wait.forParachainBlockNumber(executionBlock);631632 expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});633 });634635 itSched("Regular user can't set prioritized scheduled operation", async (scheduleKind, {helper}) => {636 const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;637 const waitForBlocks = 4;638639 const amount = 42n * helper.balance.getOneTokenNominal();640641 const balanceBefore = await helper.balance.getSubstrate(bob.address);642643 const scheduled = helper.scheduler.scheduleAfter(waitForBlocks, {scheduledId, priority: 42});644 645 await expect(scheduled.balance.transferToSubstrate(alice, bob.address, amount))646 .to.be.rejectedWith(/BadOrigin/);647648 const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;649650 await helper.wait.forParachainBlockNumber(executionBlock);651652 const balanceAfter = await helper.balance.getSubstrate(bob.address);653654 expect(balanceAfter).to.be.equal(balanceBefore);655 });656657 itSub("Regular user can't change scheduled operation's priority", async ({helper}) => {658 const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});659 const token = await collection.mintToken(bob);660661 const scheduledId = helper.arrange.makeScheduledId();662 const waitForBlocks = 4;663664 await token.scheduleAfter(waitForBlocks, {scheduledId})665 .transfer(bob, {Substrate: alice.address});666667 const priority = 112;668 await expect(helper.scheduler.changePriority(alice, scheduledId, priority))669 .to.be.rejectedWith(/BadOrigin/);670671 const priorityChanged = await helper.wait.event(672 waitForBlocks,673 'scheduler',674 'PriorityChanged',675 );676677 expect(priorityChanged === null).to.be.true;678 });679});680681682describe.skip('Sponsoring scheduling', () => {683 684 685686 687 688 689 690 691 692693 it('Can sponsor scheduling a transaction', async () => {694 695 696 697698 699 700 701702 703 704 705 706 707 708 709 710 711 712 });713714 it('Schedules and dispatches a transaction even if the caller has no funds at the time of the dispatch', async () => {715 716 717 718719 720721 722 723 724725 726 727 728729 730 731 732733 734 735 736737 738 739 740 741 742 743 744 745746 747 748749 750 751 });752753 it('Sponsor going bankrupt does not impact a scheduled transaction', async () => {754 755756 757 758 759 760761 762 763764 765 766767 768 769770 771 772 773 774775 776 777778 779 780 });781782 it('Exceeding sponsor rate limit without having enough funds prevents scheduling a periodic transaction', async () => {783 784 785 786787 788 789790 791 792793 794795 796 797 798799 800 801 802 803804 805806 807 808 });809});