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

difftreelog

fix test both scheduling variants - anon and named

Daniel Shiposha2022-11-10parent: #786ff7e.patch.diff
in: master

8 files changed

modifiedtests/src/eth/scheduling.test.tsdiffbeforeafterboth
--- a/tests/src/eth/scheduling.test.ts
+++ b/tests/src/eth/scheduling.test.ts
@@ -15,7 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {expect} from 'chai';
-import {EthUniqueHelper, itEth} from './util';
+import {EthUniqueHelper, itSchedEth} from './util';
 import {Pallets, usingPlaygrounds} from '../util';
 
 describe('Scheduing EVM smart contracts', () => {
@@ -26,11 +26,11 @@
     });
   });
 
-  itEth.ifWithPallets('Successfully schedules and periodically executes an EVM contract', [Pallets.Scheduler], async ({helper, privateKey}) => {
+  itSchedEth.ifWithPallets('Successfully schedules and periodically executes an EVM contract', [Pallets.Scheduler], async (scheduleKind, {helper, privateKey}) => {
     const donor = await privateKey({filename: __filename});
     const [alice] = await helper.arrange.createAccounts([1000n], donor);
 
-    const scheduledId = await helper.arrange.makeScheduledId();
+    const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;
 
     const deployer = await helper.eth.createAccountWithBalance(alice);
     const flipper = await helper.eth.deployFlipper(deployer);
@@ -44,7 +44,7 @@
       repetitions: 2,
     };
 
-    await helper.scheduler.scheduleAfter<EthUniqueHelper>(scheduledId, waitForBlocks, {periodic})
+    await helper.scheduler.scheduleAfter<EthUniqueHelper>(waitForBlocks, {scheduledId, periodic})
       .eth.sendEVM(
         alice,
         flipper.options.address,
modifiedtests/src/eth/util/index.tsdiffbeforeafterboth
--- a/tests/src/eth/util/index.ts
+++ b/tests/src/eth/util/index.ts
@@ -8,6 +8,7 @@
 
 import {EthUniqueHelper} from './playgrounds/unique.dev';
 import {SilentLogger, SilentConsole} from '../../util/playgrounds/unique.dev';
+import {SchedKind} from '../../util';
 
 export {EthUniqueHelper} from './playgrounds/unique.dev';
 
@@ -81,3 +82,19 @@
 itEthIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise<IKeyringPair> }) => any) => itEthIfWithPallet(name, required, cb, {only: true});
 itEthIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise<IKeyringPair> }) => any) => itEthIfWithPallet(name, required, cb, {skip: true});
 itEth.ifWithPallets = itEthIfWithPallet;
+
+export function itSchedEth(
+  name: string,
+  cb: (schedKind: SchedKind, apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise<IKeyringPair> }) => any,
+  opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {},
+) {
+  itEth(name + ' (anonymous scheduling)', (apis) => cb('anon', apis), opts);
+  itEth(name + ' (named scheduling)', (apis) => cb('named', apis), opts);
+}
+itSchedEth.only = (name: string, cb: (schedKind: SchedKind, apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise<IKeyringPair> }) => any) => itSchedEth(name, cb, {only: true});
+itSchedEth.skip = (name: string, cb: (schedKind: SchedKind, apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise<IKeyringPair> }) => any) => itSchedEth(name, cb, {skip: true});
+itSchedEth.ifWithPallets = itSchedIfWithPallets;
+
+function itSchedIfWithPallets(name: string, required: string[], cb: (schedKind: SchedKind, apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {
+  return itSchedEth(name, cb, {requiredPallets: required, ...opts});
+}
modifiedtests/src/maintenanceMode.seqtest.tsdiffbeforeafterboth
--- a/tests/src/maintenanceMode.seqtest.ts
+++ b/tests/src/maintenanceMode.seqtest.ts
@@ -16,7 +16,7 @@
 
 import {IKeyringPair} from '@polkadot/types/types';
 import {ApiPromise} from '@polkadot/api';
-import {expect, itSub, Pallets, usingPlaygrounds} from './util';
+import {expect, itSched, itSub, Pallets, usingPlaygrounds} from './util';
 import {itEth} from './eth/util';
 
 async function maintenanceEnabled(api: ApiPromise): Promise<boolean> {
@@ -162,7 +162,7 @@
     await expect(helper.balance.transferToSubstrate(bob, superuser.address, 1n)).to.be.fulfilled;
   });
 
-  itSub.ifWithPallets('MM blocks scheduled calls and the scheduler itself', [Pallets.Scheduler], async ({helper}) => {
+  itSched.ifWithPallets('MM blocks scheduled calls and the scheduler itself', [Pallets.Scheduler], async (scheduleKind, {helper}) => {
     const collection = await helper.nft.mintCollection(bob);
 
     const nftBeforeMM = await collection.mintToken(bob);
@@ -175,23 +175,25 @@
       scheduledIdBunkerThroughMM,
       scheduledIdAttemptDuringMM,
       scheduledIdAfterMM,
-    ] = await helper.arrange.makeScheduledIds(5);
+    ] = scheduleKind == 'named'
+      ? helper.arrange.makeScheduledIds(5)
+      : new Array(5);
 
     const blocksToWait = 6;
 
     // Scheduling works before the maintenance
-    await nftBeforeMM.scheduleAfter(scheduledIdBeforeMM, blocksToWait)
+    await nftBeforeMM.scheduleAfter(blocksToWait, {scheduledId: scheduledIdBeforeMM})
       .transfer(bob, {Substrate: superuser.address});
 
     await helper.wait.newBlocks(blocksToWait + 1);
     expect(await nftBeforeMM.getOwner()).to.be.deep.equal({Substrate: superuser.address});
 
     // Schedule a transaction that should occur *during* the maintenance
-    await nftDuringMM.scheduleAfter(scheduledIdDuringMM, blocksToWait)
+    await nftDuringMM.scheduleAfter(blocksToWait, {scheduledId: scheduledIdDuringMM})
       .transfer(bob, {Substrate: superuser.address});
     
     // Schedule a transaction that should occur *after* the maintenance
-    await nftDuringMM.scheduleAfter(scheduledIdBunkerThroughMM, blocksToWait * 2)
+    await nftDuringMM.scheduleAfter(blocksToWait * 2, {scheduledId: scheduledIdBunkerThroughMM})
       .transfer(bob, {Substrate: superuser.address});
 
     await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', []);
@@ -202,7 +204,7 @@
     expect(await nftDuringMM.getOwner()).to.be.deep.equal({Substrate: bob.address});
 
     // Any attempts to schedule a tx during the MM should be rejected
-    await expect(nftDuringMM.scheduleAfter(scheduledIdAttemptDuringMM, blocksToWait)
+    await expect(nftDuringMM.scheduleAfter(blocksToWait, {scheduledId: scheduledIdAttemptDuringMM})
       .transfer(bob, {Substrate: superuser.address}))
       .to.be.rejectedWith(/Invalid Transaction: Transaction call is not expected/);
 
@@ -210,7 +212,7 @@
     expect(await maintenanceEnabled(helper.getApi()), 'MM is ON when it should be OFF').to.be.false;
 
     // Scheduling works after the maintenance
-    await nftAfterMM.scheduleAfter(scheduledIdAfterMM, blocksToWait)
+    await nftAfterMM.scheduleAfter(blocksToWait, {scheduledId: scheduledIdAfterMM})
       .transfer(bob, {Substrate: superuser.address});
     
     await helper.wait.newBlocks(blocksToWait + 1);
modifiedtests/src/scheduler.seqtest.tsdiffbeforeafterboth
--- a/tests/src/scheduler.seqtest.ts
+++ b/tests/src/scheduler.seqtest.ts
@@ -14,7 +14,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';
+import {expect, itSched, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';
 import {IKeyringPair} from '@polkadot/types/types';
 import {DevUniqueHelper} from './util/playgrounds/unique.dev';
 
@@ -36,13 +36,19 @@
     });
   });
 
-  itSub('Can delay a transfer of an owned token', async ({helper}) => {
+  beforeEach(async () => {
+    await usingPlaygrounds(async (helper) => {
+      await helper.wait.noScheduledTasks();
+    });
+  });
+
+  itSched('Can delay a transfer of an owned token', async (scheduleKind, {helper}) => {
     const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});
     const token = await collection.mintToken(alice);
-    const schedulerId = await helper.arrange.makeScheduledId();
+    const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;
     const blocksBeforeExecution = 4;
     
-    await token.scheduleAfter(schedulerId, blocksBeforeExecution)
+    await token.scheduleAfter(blocksBeforeExecution, {scheduledId})
       .transfer(alice, {Substrate: bob.address});
     const executionBlock = await helper.chain.getLatestBlockNumber() + blocksBeforeExecution + 1;
 
@@ -53,8 +59,8 @@
     expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});
   });
 
-  itSub('Can transfer funds periodically', async ({helper}) => {
-    const scheduledId = await helper.arrange.makeScheduledId();
+  itSched('Can transfer funds periodically', async (scheduleKind, {helper}) => {
+    const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;
     const waitForBlocks = 1;
 
     const amount = 1n * helper.balance.getOneTokenNominal();
@@ -65,7 +71,7 @@
 
     const bobsBalanceBefore = await helper.balance.getSubstrate(bob.address);
 
-    await helper.scheduler.scheduleAfter(scheduledId, waitForBlocks, {periodic})
+    await helper.scheduler.scheduleAfter(waitForBlocks, {scheduledId, periodic})
       .balance.transferToSubstrate(alice, bob.address, amount);
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
@@ -92,12 +98,12 @@
     const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});
     const token = await collection.mintToken(alice);
 
-    const scheduledId = await helper.arrange.makeScheduledId();
+    const scheduledId = helper.arrange.makeScheduledId();
     const waitForBlocks = 4;
 
     expect(await token.getOwner()).to.be.deep.equal({Substrate: alice.address});
 
-    await token.scheduleAfter(scheduledId, waitForBlocks)
+    await token.scheduleAfter(waitForBlocks, {scheduledId})
       .transfer(alice, {Substrate: bob.address});
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
@@ -115,13 +121,13 @@
       repetitions: 2,
     };
 
-    const scheduledId = await helper.arrange.makeScheduledId();
+    const scheduledId = helper.arrange.makeScheduledId();
 
     const amount = 1n * helper.balance.getOneTokenNominal();
 
     const bobsBalanceBefore = await helper.balance.getSubstrate(bob.address);
 
-    await helper.scheduler.scheduleAfter(scheduledId, waitForBlocks, {periodic})
+    await helper.scheduler.scheduleAfter(waitForBlocks, {scheduledId, periodic})
       .balance.transferToSubstrate(alice, bob.address, amount);
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
@@ -146,11 +152,16 @@
       );
   });
 
-  itSub('scheduler will not insert more tasks than allowed', async ({helper}) => {
+  itSched('scheduler will not insert more tasks than allowed', async (scheduleKind, {helper}) => {
     const maxScheduledPerBlock = 50;
-    const scheduledIds = await helper.arrange.makeScheduledIds(maxScheduledPerBlock + 1);
-    const fillScheduledIds = scheduledIds.slice(0, maxScheduledPerBlock);
-    const extraScheduledId = scheduledIds[maxScheduledPerBlock];
+    let fillScheduledIds = new Array(maxScheduledPerBlock);
+    let extraScheduledId = undefined;
+    
+    if (scheduleKind == 'named') {
+      const scheduledIds = helper.arrange.makeScheduledIds(maxScheduledPerBlock + 1);
+      fillScheduledIds = scheduledIds.slice(0, maxScheduledPerBlock);
+      extraScheduledId = scheduledIds[maxScheduledPerBlock];
+    }
 
     // Since the dev node has Instant Seal,
     // we need a larger gap between the current block and the target one.
@@ -168,12 +179,12 @@
 
     // Fill the target block
     for (let i = 0; i < maxScheduledPerBlock; i++) {
-      await helper.scheduler.scheduleAt(fillScheduledIds[i], executionBlock)
+      await helper.scheduler.scheduleAt(executionBlock, {scheduledId: fillScheduledIds[i]})
         .balance.transferToSubstrate(superuser, bob.address, amount);
     }
 
     // Try to schedule a task into a full block
-    await expect(helper.scheduler.scheduleAt(extraScheduledId, executionBlock)
+    await expect(helper.scheduler.scheduleAt(executionBlock, {scheduledId: extraScheduledId})
       .balance.transferToSubstrate(superuser, bob.address, amount))
       .to.be.rejectedWith(/scheduler\.AgendaIsExhausted/);
 
@@ -187,8 +198,8 @@
     expect(diff).to.be.equal(amount * BigInt(maxScheduledPerBlock));
   });
 
-  itSub.ifWithPallets('Scheduled tasks are transactional', [Pallets.TestUtils], async ({helper}) => {
-    const scheduledId = await helper.arrange.makeScheduledId();
+  itSched.ifWithPallets('Scheduled tasks are transactional', [Pallets.TestUtils], async (scheduleKind, {helper}) => {
+    const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;
     const waitForBlocks = 4;
 
     const initTestVal = 42;
@@ -196,7 +207,7 @@
 
     await helper.testUtils.setTestValue(alice, initTestVal);
 
-    await helper.scheduler.scheduleAfter<DevUniqueHelper>(scheduledId, waitForBlocks)
+    await helper.scheduler.scheduleAfter<DevUniqueHelper>(waitForBlocks, {scheduledId})
       .testUtils.setTestValueAndRollback(alice, changedTestVal);
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
@@ -207,8 +218,8 @@
       .to.be.equal(initTestVal);
   });
 
-  itSub.ifWithPallets('Scheduled tasks should take correct fees', [Pallets.TestUtils], async function({helper}) {
-    const scheduledId = await helper.arrange.makeScheduledId();
+  itSched.ifWithPallets('Scheduled tasks should take correct fees', [Pallets.TestUtils], async function(scheduleKind, {helper}) {
+    const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;
     const waitForBlocks = 4;
     const periodic = {
       period: 2,
@@ -221,7 +232,7 @@
     const expectedScheduledFee = (await helper.getPaymentInfo(alice, dummyTx, scheduledLen))
       .partialFee.toBigInt();
 
-    await helper.scheduler.scheduleAfter<DevUniqueHelper>(scheduledId, waitForBlocks, {periodic})
+    await helper.scheduler.scheduleAfter<DevUniqueHelper>(waitForBlocks, {scheduledId, periodic})
       .testUtils.justTakeFee(alice);
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
@@ -267,7 +278,7 @@
     const [
       scheduledId,
       scheduledCancelId,
-    ] = await helper.arrange.makeScheduledIds(2);
+    ] = helper.arrange.makeScheduledIds(2);
 
     const periodic = {
       period: 5,
@@ -280,14 +291,14 @@
 
     await helper.testUtils.setTestValue(alice, initTestVal);
 
-    await helper.scheduler.scheduleAt<DevUniqueHelper>(scheduledId, firstExecutionBlockNumber, {periodic})
+    await helper.scheduler.scheduleAt<DevUniqueHelper>(firstExecutionBlockNumber, {scheduledId, periodic})
       .testUtils.incTestValue(alice);
 
     // Cancel the inc tx after 2 executions
     // *in the same block* in which the second execution is scheduled
     await helper.scheduler.scheduleAt(
-      scheduledCancelId,
       firstExecutionBlockNumber + periodic.period,
+      {scheduledId: scheduledCancelId},
     ).scheduler.cancelScheduled(alice, scheduledId);
 
     await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber);
@@ -310,7 +321,7 @@
   });
 
   itSub.ifWithPallets('A scheduled operation can cancel itself', [Pallets.TestUtils], async ({helper}) => {
-    const scheduledId = await helper.arrange.makeScheduledId();
+    const scheduledId = helper.arrange.makeScheduledId();
     const waitForBlocks = 4;
     const periodic = {
       period: 2,
@@ -322,7 +333,7 @@
 
     await helper.testUtils.setTestValue(alice, initTestVal);
 
-    await helper.scheduler.scheduleAfter<DevUniqueHelper>(scheduledId, waitForBlocks, {periodic})
+    await helper.scheduler.scheduleAfter<DevUniqueHelper>(waitForBlocks, {scheduledId, periodic})
       .testUtils.selfCancelingInc(alice, scheduledId, maxTestVal);
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
@@ -349,10 +360,10 @@
     const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});
     const token = await collection.mintToken(bob);
 
-    const scheduledId = await helper.arrange.makeScheduledId();
+    const scheduledId = helper.arrange.makeScheduledId();
     const waitForBlocks = 4;
 
-    await token.scheduleAfter(scheduledId, waitForBlocks)
+    await token.scheduleAfter(waitForBlocks, {scheduledId})
       .transfer(bob, {Substrate: alice.address});
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
@@ -363,8 +374,8 @@
     expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});
   });
 
-  itSub('Root can set prioritized scheduled operation', async ({helper}) => {
-    const scheduledId = await helper.arrange.makeScheduledId();
+  itSched('Root can set prioritized scheduled operation', async (scheduleKind, {helper}) => {
+    const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;
     const waitForBlocks = 4;
 
     const amount = 42n * helper.balance.getOneTokenNominal();
@@ -372,7 +383,7 @@
     const balanceBefore = await helper.balance.getSubstrate(charlie.address);
 
     await helper.getSudo()
-      .scheduler.scheduleAfter(scheduledId, waitForBlocks, {priority: 42})
+      .scheduler.scheduleAfter(waitForBlocks, {scheduledId, priority: 42})
       .balance.forceTransferToSubstrate(superuser, bob.address, charlie.address, amount);
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
@@ -390,10 +401,10 @@
     const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});
     const token = await collection.mintToken(bob);
 
-    const scheduledId = await helper.arrange.makeScheduledId();
+    const scheduledId = helper.arrange.makeScheduledId();
     const waitForBlocks = 6;
 
-    await token.scheduleAfter(scheduledId, waitForBlocks)
+    await token.scheduleAfter(waitForBlocks, {scheduledId})
       .transfer(bob, {Substrate: alice.address});
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
@@ -419,7 +430,7 @@
     const [
       scheduledFirstId,
       scheduledSecondId,
-    ] = await helper.arrange.makeScheduledIds(2);
+    ] = helper.arrange.makeScheduledIds(2);
 
     const currentBlockNumber = await helper.chain.getLatestBlockNumber();
     const blocksBeforeExecution = 6;
@@ -436,11 +447,17 @@
     const amount = 1n * helper.balance.getOneTokenNominal();
 
     // Scheduler a task with a lower priority first, then with a higher priority
-    await helper.getSudo().scheduler.scheduleAt(scheduledFirstId, firstExecutionBlockNumber, {priority: prioLow, periodic})
-      .balance.forceTransferToSubstrate(superuser, alice.address, bob.address, amount);
+    await helper.getSudo().scheduler.scheduleAt(firstExecutionBlockNumber, {
+      scheduledId: scheduledFirstId,
+      priority: prioLow,
+      periodic,
+    }).balance.forceTransferToSubstrate(superuser, alice.address, bob.address, amount);
 
-    await helper.getSudo().scheduler.scheduleAt(scheduledSecondId, firstExecutionBlockNumber, {priority: prioHigh, periodic})
-      .balance.forceTransferToSubstrate(superuser, alice.address, bob.address, amount);
+    await helper.getSudo().scheduler.scheduleAt(firstExecutionBlockNumber, {
+      scheduledId: scheduledSecondId,
+      priority: prioHigh,
+      periodic,
+    }).balance.forceTransferToSubstrate(superuser, alice.address, bob.address, amount);
 
     const capture = await helper.arrange.captureEvents('scheduler', 'Dispatched');
 
@@ -467,13 +484,15 @@
     expect(secondExecuctionIds[1]).to.be.equal(scheduledSecondId);
   });
 
-  itSub('Periodic operations always can be rescheduled', async ({helper}) => {
+  itSched('Periodic operations always can be rescheduled', async (scheduleKind, {helper}) => {
     const maxScheduledPerBlock = 50;
     const numFilledBlocks = 3;
-    const ids = await helper.arrange.makeScheduledIds(numFilledBlocks * maxScheduledPerBlock + 1);
-    const periodicId = ids[0];
+    const ids = helper.arrange.makeScheduledIds(numFilledBlocks * maxScheduledPerBlock + 1);
+    const periodicId = scheduleKind == 'named' ? ids[0] : undefined;
     const fillIds = ids.slice(1);
 
+    const fillScheduleFn = scheduleKind == 'named' ? 'scheduleNamed' : 'schedule';
+
     const initTestVal = 0;
     const firstExecTestVal = 1;
     const secondExecTestVal = 2;
@@ -498,15 +517,22 @@
         const scheduledTx = helper.constructApiCall('api.tx.balances.transfer', [bob.address, 1n]);
 
         const when = firstExecutionBlockNumber + period + offset;
-        const tx = helper.constructApiCall('api.tx.scheduler.scheduleNamed', [fillIds[i + offset * maxScheduledPerBlock], when, null, null, scheduledTx]);
+        const mandatoryArgs = [when, null, null, scheduledTx];
+        const scheduleArgs = scheduleKind == 'named'
+          ? [fillIds[i + offset * maxScheduledPerBlock], ...mandatoryArgs]
+          : mandatoryArgs;
+
+        const tx = helper.constructApiCall(`api.tx.scheduler.${fillScheduleFn}`, scheduleArgs);
 
         txs.push(tx);
       }
     }
     await helper.executeExtrinsic(alice, 'api.tx.testUtils.batchAll', [txs], true);
 
-    await helper.scheduler.scheduleAt<DevUniqueHelper>(periodicId, firstExecutionBlockNumber, {periodic})
-      .testUtils.incTestValue(alice);
+    await helper.scheduler.scheduleAt<DevUniqueHelper>(firstExecutionBlockNumber, {
+      scheduledId: periodicId,
+      periodic,
+    }).testUtils.incTestValue(alice);
 
     await helper.wait.forParachainBlockNumber(firstExecutionBlockNumber);
     expect(await helper.testUtils.testValue()).to.be.equal(firstExecTestVal);
@@ -522,12 +548,12 @@
     expect(await helper.testUtils.testValue()).to.be.equal(secondExecTestVal);
   });
 
-  itSub('scheduled operations does not change nonce', async ({helper}) => {
-    const scheduledId = await helper.arrange.makeScheduledId();
+  itSched('scheduled operations does not change nonce', async (scheduleKind, {helper}) => {
+    const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;
     const blocksBeforeExecution = 4;
 
     await helper.scheduler
-      .scheduleAfter<DevUniqueHelper>(scheduledId, blocksBeforeExecution)
+      .scheduleAfter<DevUniqueHelper>(blocksBeforeExecution, {scheduledId})
       .balance.transferToSubstrate(alice, bob.address, 1n);
     const executionBlock = await helper.chain.getLatestBlockNumber() + blocksBeforeExecution + 1;
 
@@ -560,14 +586,14 @@
     const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});
     const token = await collection.mintToken(alice);
 
-    const scheduledId = await helper.arrange.makeScheduledId();
+    const scheduledId = helper.arrange.makeScheduledId();
     const waitForBlocks = 4;
 
-    await token.scheduleAfter(scheduledId, waitForBlocks)
+    await token.scheduleAfter(waitForBlocks, {scheduledId})
       .transfer(alice, {Substrate: bob.address});
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
-    const scheduled = helper.scheduler.scheduleAfter(scheduledId, waitForBlocks);
+    const scheduled = helper.scheduler.scheduleAfter(waitForBlocks, {scheduledId});
     await expect(scheduled.balance.transferToSubstrate(alice, bob.address, 1n * helper.balance.getOneTokenNominal()))
       .to.be.rejectedWith(/scheduler\.FailedToSchedule/);
 
@@ -582,7 +608,7 @@
   });
 
   itSub("Can't cancel an operation which is not scheduled", async ({helper}) => {
-    const scheduledId = await helper.arrange.makeScheduledId();
+    const scheduledId = helper.arrange.makeScheduledId();
     await expect(helper.scheduler.cancelScheduled(alice, scheduledId))
       .to.be.rejectedWith(/scheduler\.NotFound/);
   });
@@ -591,10 +617,10 @@
     const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'schd'});
     const token = await collection.mintToken(alice);
 
-    const scheduledId = await helper.arrange.makeScheduledId();
+    const scheduledId = helper.arrange.makeScheduledId();
     const waitForBlocks = 4;
 
-    await token.scheduleAfter(scheduledId, waitForBlocks)
+    await token.scheduleAfter(waitForBlocks, {scheduledId})
       .transfer(alice, {Substrate: bob.address});
     const executionBlock = await helper.chain.getLatestBlockNumber() + waitForBlocks + 1;
 
@@ -606,15 +632,15 @@
     expect(await token.getOwner()).to.be.deep.equal({Substrate: bob.address});
   });
 
-  itSub("Regular user can't set prioritized scheduled operation", async ({helper}) => {
-    const scheduledId = await helper.arrange.makeScheduledId();
+  itSched("Regular user can't set prioritized scheduled operation", async (scheduleKind, {helper}) => {
+    const scheduledId = scheduleKind == 'named' ? helper.arrange.makeScheduledId() : undefined;
     const waitForBlocks = 4;
 
     const amount = 42n * helper.balance.getOneTokenNominal();
 
     const balanceBefore = await helper.balance.getSubstrate(bob.address);
 
-    const scheduled = helper.scheduler.scheduleAfter(scheduledId, waitForBlocks, {priority: 42});
+    const scheduled = helper.scheduler.scheduleAfter(waitForBlocks, {scheduledId, priority: 42});
     
     await expect(scheduled.balance.transferToSubstrate(alice, bob.address, amount))
       .to.be.rejectedWith(/BadOrigin/);
@@ -632,10 +658,10 @@
     const collection = await helper.nft.mintCollection(bob, {tokenPrefix: 'schd'});
     const token = await collection.mintToken(bob);
 
-    const scheduledId = await helper.arrange.makeScheduledId();
+    const scheduledId = helper.arrange.makeScheduledId();
     const waitForBlocks = 4;
 
-    await token.scheduleAfter(scheduledId, waitForBlocks)
+    await token.scheduleAfter(waitForBlocks, {scheduledId})
       .transfer(bob, {Substrate: alice.address});
 
     const priority = 112;
modifiedtests/src/util/index.tsdiffbeforeafterboth
--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -130,6 +130,24 @@
 itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});
 itSub.ifWithPallets = itSubIfWithPallet;
 
+export type SchedKind = 'anon' | 'named';
+
+export function itSched(
+  name: string,
+  cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any,
+  opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {},
+) {
+  itSub(name + ' (anonymous scheduling)', (apis) => cb('anon', apis), opts);
+  itSub(name + ' (named scheduling)', (apis) => cb('named', apis), opts);
+}
+itSched.only = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {only: true});
+itSched.skip = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {skip: true});
+itSched.ifWithPallets = itSchedIfWithPallets;
+
+function itSchedIfWithPallets(name: string, required: string[], cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {
+  return itSched(name, cb, {requiredPallets: required, ...opts});
+}
+
 export function describeXCM(title: string, fn: (this: Mocha.Suite) => void, opts: {skip?: boolean} = {}) {
   (process.env.RUN_XCM_TESTS && !opts.skip
     ? describe
modifiedtests/src/util/playgrounds/types.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/types.ts
+++ b/tests/src/util/playgrounds/types.ts
@@ -172,6 +172,7 @@
 }
 
 export interface ISchedulerOptions {
+  scheduledId?: string,
   priority?: number,
   periodic?: {
     period: number,
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -308,9 +308,7 @@
     return encodeAddress(address);
   }
 
-  async makeScheduledIds(num: number): Promise<string[]> {
-    await this.helper.wait.noScheduledTasks();
-
+  makeScheduledIds(num: number): string[] {
     function makeId(slider: number) {
       const scheduledIdSize = 64;
       const hexId = slider.toString(16);
@@ -330,8 +328,8 @@
     return ids;
   }
 
-  async makeScheduledId(): Promise<string> {
-    return (await this.makeScheduledIds(1))[0];
+  makeScheduledId(): string {
+    return (this.makeScheduledIds(1))[0];
   }
 
   async captureEvents(eventSection: string, eventMethod: string): Promise<EventCapture> {
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
2560 }2560 }
25612561
2562 scheduleAt<T extends UniqueHelper>(2562 scheduleAt<T extends UniqueHelper>(
2563 scheduledId: string,
2564 executionBlockNumber: number,2563 executionBlockNumber: number,
2565 options: ISchedulerOptions = {},2564 options: ISchedulerOptions = {},
2566 ) {2565 ) {
2567 return this.schedule<T>('scheduleNamed', scheduledId, executionBlockNumber, options);2566 return this.schedule<T>('schedule', executionBlockNumber, options);
2568 }2567 }
25692568
2570 scheduleAfter<T extends UniqueHelper>(2569 scheduleAfter<T extends UniqueHelper>(
2571 scheduledId: string,
2572 blocksBeforeExecution: number,2570 blocksBeforeExecution: number,
2573 options: ISchedulerOptions = {},2571 options: ISchedulerOptions = {},
2574 ) {2572 ) {
2575 return this.schedule<T>('scheduleNamedAfter', scheduledId, blocksBeforeExecution, options);2573 return this.schedule<T>('scheduleAfter', blocksBeforeExecution, options);
2576 }2574 }
25772575
2578 schedule<T extends UniqueHelper>(2576 schedule<T extends UniqueHelper>(
2579 scheduleFn: 'scheduleNamed' | 'scheduleNamedAfter',2577 scheduleFn: 'schedule' | 'scheduleAfter',
2580 scheduledId: string,
2581 blocksNum: number,2578 blocksNum: number,
2582 options: ISchedulerOptions = {},2579 options: ISchedulerOptions = {},
2583 ) {2580 ) {
2584 // eslint-disable-next-line @typescript-eslint/naming-convention2581 // eslint-disable-next-line @typescript-eslint/naming-convention
2585 const ScheduledHelperType = ScheduledUniqueHelper(this.helper.helperBase);2582 const ScheduledHelperType = ScheduledUniqueHelper(this.helper.helperBase);
2586 return this.helper.clone(ScheduledHelperType, {2583 return this.helper.clone(ScheduledHelperType, {
2587 scheduleFn,2584 scheduleFn,
2588 scheduledId,
2589 blocksNum,2585 blocksNum,
2590 options,2586 options,
2591 }) as T;2587 }) as T;
2874// eslint-disable-next-line @typescript-eslint/naming-convention2870// eslint-disable-next-line @typescript-eslint/naming-convention
2875function ScheduledUniqueHelper<T extends UniqueHelperConstructor>(Base: T) {2871function ScheduledUniqueHelper<T extends UniqueHelperConstructor>(Base: T) {
2876 return class extends Base {2872 return class extends Base {
2877 scheduleFn: 'scheduleNamed' | 'scheduleNamedAfter';2873 scheduleFn: 'schedule' | 'scheduleAfter';
2878 scheduledId: string;
2879 blocksNum: number;2874 blocksNum: number;
2880 options: ISchedulerOptions;2875 options: ISchedulerOptions;
28812876
2882 constructor(...args: any[]) {2877 constructor(...args: any[]) {
2883 const logger = args[0] as ILogger;2878 const logger = args[0] as ILogger;
2884 const options = args[1] as {2879 const options = args[1] as {
2885 scheduleFn: 'scheduleNamed' | 'scheduleNamedAfter',2880 scheduleFn: 'schedule' | 'scheduleAfter',
2886 scheduledId: string,
2887 blocksNum: number,2881 blocksNum: number,
2888 options: ISchedulerOptions2882 options: ISchedulerOptions
2889 };2883 };
28902884
2891 super(logger);2885 super(logger);
28922886
2893 this.scheduleFn = options.scheduleFn;2887 this.scheduleFn = options.scheduleFn;
2894 this.scheduledId = options.scheduledId;
2895 this.blocksNum = options.blocksNum;2888 this.blocksNum = options.blocksNum;
2896 this.options = options.options;2889 this.options = options.options;
2897 }2890 }
28982891
2899 executeExtrinsic(sender: IKeyringPair, scheduledExtrinsic: string, scheduledParams: any[], expectSuccess?: boolean): Promise<ITransactionResult> {2892 executeExtrinsic(sender: IKeyringPair, scheduledExtrinsic: string, scheduledParams: any[], expectSuccess?: boolean): Promise<ITransactionResult> {
2900 const scheduledTx = this.constructApiCall(scheduledExtrinsic, scheduledParams);2893 const scheduledTx = this.constructApiCall(scheduledExtrinsic, scheduledParams);
2894
2901 const extrinsic = 'api.tx.scheduler.' + this.scheduleFn;2895 const mandatorySchedArgs = [
2902
2903 return super.executeExtrinsic(
2904 sender,
2905 extrinsic,
2906 [
2907 this.scheduledId,
2908 this.blocksNum,2896 this.blocksNum,
2909 this.options.periodic ? [this.options.periodic.period, this.options.periodic.repetitions] : null,2897 this.options.periodic ? [this.options.periodic.period, this.options.periodic.repetitions] : null,
2910 this.options.priority ?? null,2898 this.options.priority ?? null,
2911 scheduledTx,2899 scheduledTx,
2912 ],2900 ];
2913 expectSuccess,2901
2914 );2902 let schedArgs;
2903 let scheduleFn;
2904
2905 if (this.options.scheduledId) {
2906 schedArgs = [this.options.scheduledId!, ...mandatorySchedArgs];
2907
2908 if (this.scheduleFn == 'schedule') {
2909 scheduleFn = 'scheduleNamed';
2910 } else if (this.scheduleFn == 'scheduleAfter') {
2911 scheduleFn = 'scheduleNamedAfter';
2912 }
2913 } else {
2914 schedArgs = mandatorySchedArgs;
2915 scheduleFn = this.scheduleFn;
2916 }
2917
2918 const extrinsic = 'api.tx.scheduler.' + scheduleFn;
2919
2920 return super.executeExtrinsic(
2921 sender,
2922 extrinsic,
2923 schedArgs,
2924 expectSuccess,
2925 );
2915 }2926 }
2916 };2927 };
2917}2928}
3046 }3057 }
30473058
3048 scheduleAt<T extends UniqueHelper>(3059 scheduleAt<T extends UniqueHelper>(
3049 scheduledId: string,
3050 executionBlockNumber: number,3060 executionBlockNumber: number,
3051 options: ISchedulerOptions = {},3061 options: ISchedulerOptions = {},
3052 ) {3062 ) {
3053 const scheduledHelper = this.helper.scheduler.scheduleAt<T>(scheduledId, executionBlockNumber, options);3063 const scheduledHelper = this.helper.scheduler.scheduleAt<T>(executionBlockNumber, options);
3054 return new UniqueBaseCollection(this.collectionId, scheduledHelper);3064 return new UniqueBaseCollection(this.collectionId, scheduledHelper);
3055 }3065 }
30563066
3057 scheduleAfter<T extends UniqueHelper>(3067 scheduleAfter<T extends UniqueHelper>(
3058 scheduledId: string,
3059 blocksBeforeExecution: number,3068 blocksBeforeExecution: number,
3060 options: ISchedulerOptions = {},3069 options: ISchedulerOptions = {},
3061 ) {3070 ) {
3062 const scheduledHelper = this.helper.scheduler.scheduleAfter<T>(scheduledId, blocksBeforeExecution, options);3071 const scheduledHelper = this.helper.scheduler.scheduleAfter<T>(blocksBeforeExecution, options);
3063 return new UniqueBaseCollection(this.collectionId, scheduledHelper);3072 return new UniqueBaseCollection(this.collectionId, scheduledHelper);
3064 }3073 }
30653074
3155 }3164 }
31563165
3157 scheduleAt<T extends UniqueHelper>(3166 scheduleAt<T extends UniqueHelper>(
3158 scheduledId: string,
3159 executionBlockNumber: number,3167 executionBlockNumber: number,
3160 options: ISchedulerOptions = {},3168 options: ISchedulerOptions = {},
3161 ) {3169 ) {
3162 const scheduledHelper = this.helper.scheduler.scheduleAt<T>(scheduledId, executionBlockNumber, options);3170 const scheduledHelper = this.helper.scheduler.scheduleAt<T>(executionBlockNumber, options);
3163 return new UniqueNFTCollection(this.collectionId, scheduledHelper);3171 return new UniqueNFTCollection(this.collectionId, scheduledHelper);
3164 }3172 }
31653173
3166 scheduleAfter<T extends UniqueHelper>(3174 scheduleAfter<T extends UniqueHelper>(
3167 scheduledId: string,
3168 blocksBeforeExecution: number,3175 blocksBeforeExecution: number,
3169 options: ISchedulerOptions = {},3176 options: ISchedulerOptions = {},
3170 ) {3177 ) {
3171 const scheduledHelper = this.helper.scheduler.scheduleAfter<T>(scheduledId, blocksBeforeExecution, options);3178 const scheduledHelper = this.helper.scheduler.scheduleAfter<T>(blocksBeforeExecution, options);
3172 return new UniqueNFTCollection(this.collectionId, scheduledHelper);3179 return new UniqueNFTCollection(this.collectionId, scheduledHelper);
3173 }3180 }
31743181
3260 }3267 }
32613268
3262 scheduleAt<T extends UniqueHelper>(3269 scheduleAt<T extends UniqueHelper>(
3263 scheduledId: string,
3264 executionBlockNumber: number,3270 executionBlockNumber: number,
3265 options: ISchedulerOptions = {},3271 options: ISchedulerOptions = {},
3266 ) {3272 ) {
3267 const scheduledHelper = this.helper.scheduler.scheduleAt<T>(scheduledId, executionBlockNumber, options);3273 const scheduledHelper = this.helper.scheduler.scheduleAt<T>(executionBlockNumber, options);
3268 return new UniqueRFTCollection(this.collectionId, scheduledHelper);3274 return new UniqueRFTCollection(this.collectionId, scheduledHelper);
3269 }3275 }
32703276
3271 scheduleAfter<T extends UniqueHelper>(3277 scheduleAfter<T extends UniqueHelper>(
3272 scheduledId: string,
3273 blocksBeforeExecution: number,3278 blocksBeforeExecution: number,
3274 options: ISchedulerOptions = {},3279 options: ISchedulerOptions = {},
3275 ) {3280 ) {
3276 const scheduledHelper = this.helper.scheduler.scheduleAfter<T>(scheduledId, blocksBeforeExecution, options);3281 const scheduledHelper = this.helper.scheduler.scheduleAfter<T>(blocksBeforeExecution, options);
3277 return new UniqueRFTCollection(this.collectionId, scheduledHelper);3282 return new UniqueRFTCollection(this.collectionId, scheduledHelper);
3278 }3283 }
32793284
3329 }3334 }
33303335
3331 scheduleAt<T extends UniqueHelper>(3336 scheduleAt<T extends UniqueHelper>(
3332 scheduledId: string,
3333 executionBlockNumber: number,3337 executionBlockNumber: number,
3334 options: ISchedulerOptions = {},3338 options: ISchedulerOptions = {},
3335 ) {3339 ) {
3336 const scheduledHelper = this.helper.scheduler.scheduleAt<T>(scheduledId, executionBlockNumber, options);3340 const scheduledHelper = this.helper.scheduler.scheduleAt<T>(executionBlockNumber, options);
3337 return new UniqueFTCollection(this.collectionId, scheduledHelper);3341 return new UniqueFTCollection(this.collectionId, scheduledHelper);
3338 }3342 }
33393343
3340 scheduleAfter<T extends UniqueHelper>(3344 scheduleAfter<T extends UniqueHelper>(
3341 scheduledId: string,
3342 blocksBeforeExecution: number,3345 blocksBeforeExecution: number,
3343 options: ISchedulerOptions = {},3346 options: ISchedulerOptions = {},
3344 ) {3347 ) {
3345 const scheduledHelper = this.helper.scheduler.scheduleAfter<T>(scheduledId, blocksBeforeExecution, options);3348 const scheduledHelper = this.helper.scheduler.scheduleAfter<T>(blocksBeforeExecution, options);
3346 return new UniqueFTCollection(this.collectionId, scheduledHelper);3349 return new UniqueFTCollection(this.collectionId, scheduledHelper);
3347 }3350 }
33483351
3388 }3391 }
33893392
3390 scheduleAt<T extends UniqueHelper>(3393 scheduleAt<T extends UniqueHelper>(
3391 scheduledId: string,
3392 executionBlockNumber: number,3394 executionBlockNumber: number,
3393 options: ISchedulerOptions = {},3395 options: ISchedulerOptions = {},
3394 ) {3396 ) {
3395 const scheduledCollection = this.collection.scheduleAt<T>(scheduledId, executionBlockNumber, options);3397 const scheduledCollection = this.collection.scheduleAt<T>(executionBlockNumber, options);
3396 return new UniqueBaseToken(this.tokenId, scheduledCollection);3398 return new UniqueBaseToken(this.tokenId, scheduledCollection);
3397 }3399 }
33983400
3399 scheduleAfter<T extends UniqueHelper>(3401 scheduleAfter<T extends UniqueHelper>(
3400 scheduledId: string,
3401 blocksBeforeExecution: number,3402 blocksBeforeExecution: number,
3402 options: ISchedulerOptions = {},3403 options: ISchedulerOptions = {},
3403 ) {3404 ) {
3404 const scheduledCollection = this.collection.scheduleAfter<T>(scheduledId, blocksBeforeExecution, options);3405 const scheduledCollection = this.collection.scheduleAfter<T>(blocksBeforeExecution, options);
3405 return new UniqueBaseToken(this.tokenId, scheduledCollection);3406 return new UniqueBaseToken(this.tokenId, scheduledCollection);
3406 }3407 }
34073408
3468 }3469 }
34693470
3470 scheduleAt<T extends UniqueHelper>(3471 scheduleAt<T extends UniqueHelper>(
3471 scheduledId: string,
3472 executionBlockNumber: number,3472 executionBlockNumber: number,
3473 options: ISchedulerOptions = {},3473 options: ISchedulerOptions = {},
3474 ) {3474 ) {
3475 const scheduledCollection = this.collection.scheduleAt<T>(scheduledId, executionBlockNumber, options);3475 const scheduledCollection = this.collection.scheduleAt<T>(executionBlockNumber, options);
3476 return new UniqueNFToken(this.tokenId, scheduledCollection);3476 return new UniqueNFToken(this.tokenId, scheduledCollection);
3477 }3477 }
34783478
3479 scheduleAfter<T extends UniqueHelper>(3479 scheduleAfter<T extends UniqueHelper>(
3480 scheduledId: string,
3481 blocksBeforeExecution: number,3480 blocksBeforeExecution: number,
3482 options: ISchedulerOptions = {},3481 options: ISchedulerOptions = {},
3483 ) {3482 ) {
3484 const scheduledCollection = this.collection.scheduleAfter<T>(scheduledId, blocksBeforeExecution, options);3483 const scheduledCollection = this.collection.scheduleAfter<T>(blocksBeforeExecution, options);
3485 return new UniqueNFToken(this.tokenId, scheduledCollection);3484 return new UniqueNFToken(this.tokenId, scheduledCollection);
3486 }3485 }
34873486
3543 }3542 }
35443543
3545 scheduleAt<T extends UniqueHelper>(3544 scheduleAt<T extends UniqueHelper>(
3546 scheduledId: string,
3547 executionBlockNumber: number,3545 executionBlockNumber: number,
3548 options: ISchedulerOptions = {},3546 options: ISchedulerOptions = {},
3549 ) {3547 ) {
3550 const scheduledCollection = this.collection.scheduleAt<T>(scheduledId, executionBlockNumber, options);3548 const scheduledCollection = this.collection.scheduleAt<T>(executionBlockNumber, options);
3551 return new UniqueRFToken(this.tokenId, scheduledCollection);3549 return new UniqueRFToken(this.tokenId, scheduledCollection);
3552 }3550 }
35533551
3554 scheduleAfter<T extends UniqueHelper>(3552 scheduleAfter<T extends UniqueHelper>(
3555 scheduledId: string,
3556 blocksBeforeExecution: number,3553 blocksBeforeExecution: number,
3557 options: ISchedulerOptions = {},3554 options: ISchedulerOptions = {},
3558 ) {3555 ) {
3559 const scheduledCollection = this.collection.scheduleAfter<T>(scheduledId, blocksBeforeExecution, options);3556 const scheduledCollection = this.collection.scheduleAfter<T>(blocksBeforeExecution, options);
3560 return new UniqueRFToken(this.tokenId, scheduledCollection);3557 return new UniqueRFToken(this.tokenId, scheduledCollection);
3561 }3558 }
35623559