difftreelog
refactor make scheduler test more explicit
in: master
1 file changed
tests/src/.outdated/scheduler.test.tsdiffbeforeafterboth102 const period = 2;102 const period = 2;103 const repetitions = 2;103 const repetitions = 2;104105 const amount = 1n * UNIQUE;104106105 await scheduleTransferFundsExpectSuccess(api, 1n * UNIQUE, alice, bob, waitForBlocks, makeScheduledId(), period, repetitions);107 await scheduleTransferFundsExpectSuccess(api, amount, alice, bob, waitForBlocks, makeScheduledId(), period, repetitions);106 const bobsBalanceBefore = await getFreeBalance(bob);108 const bobsBalanceBefore = await getFreeBalance(bob);107109108 await waitNewBlocks(waitForBlocks + 1);110 await waitNewBlocks(waitForBlocks + 1);109 const bobsBalanceAfterFirst = await getFreeBalance(bob);111 const bobsBalanceAfterFirst = await getFreeBalance(bob);110 expect(bobsBalanceAfterFirst > bobsBalanceBefore, '#1 Balance of the recipient did not increase').to.be.true;112 expect(bobsBalanceAfterFirst)113 .to.be.equal(114 bobsBalanceBefore + 1n * amount,115 '#1 Balance of the recipient should be increased by 1 * amount',116 );111117112 await waitNewBlocks(period);118 await waitNewBlocks(period);113 const bobsBalanceAfterSecond = await getFreeBalance(bob);119 const bobsBalanceAfterSecond = await getFreeBalance(bob);114 expect(bobsBalanceAfterSecond > bobsBalanceAfterFirst, '#2 Balance of the recipient did not increase').to.be.true;120 expect(bobsBalanceAfterSecond)121 .to.be.equal(122 bobsBalanceBefore + 2n * amount,123 '#2 Balance of the recipient should be increased by 2 * amount',124 );115 });125 });116 });126 });117127122 const scheduledId = makeScheduledId();132 const scheduledId = makeScheduledId();123 const waitForBlocks = 4;133 const waitForBlocks = 4;134135 const amount = 1;124136125 await scheduleTransferExpectSuccess(api, collectionId, tokenId, alice, bob, 1, waitForBlocks, scheduledId);137 await scheduleTransferExpectSuccess(api, collectionId, tokenId, alice, bob, amount, waitForBlocks, scheduledId);126 await expect(cancelScheduled(api, alice, scheduledId)).to.not.be.rejected;138 await expect(cancelScheduled(api, alice, scheduledId)).to.not.be.rejected;127139128 await waitNewBlocks(waitForBlocks);140 await waitNewBlocks(waitForBlocks);138 const repetitions = 2;150 const repetitions = 2;139151140 const scheduledId = makeScheduledId();152 const scheduledId = makeScheduledId();153 const amount = 1n * UNIQUE;141154142 const bobsBalanceBefore = await getFreeBalance(bob);155 const bobsBalanceBefore = await getFreeBalance(bob);143 await scheduleTransferFundsExpectSuccess(api, 1n * UNIQUE, alice, bob, waitForBlocks, scheduledId, period, repetitions);156 await scheduleTransferFundsExpectSuccess(api, amount, alice, bob, waitForBlocks, scheduledId, period, repetitions);144157145 await waitNewBlocks(waitForBlocks + 1);158 await waitNewBlocks(waitForBlocks + 1);146 const bobsBalanceAfterFirst = await getFreeBalance(bob);159 const bobsBalanceAfterFirst = await getFreeBalance(bob);147 expect(bobsBalanceAfterFirst > bobsBalanceBefore, '#1 Balance of the recipient did not increase').to.be.true;160 expect(bobsBalanceAfterFirst)161 .to.be.equal(162 bobsBalanceBefore + 1n * amount,163 '#1 Balance of the recipient should be increased by 1 * amount',164 );148165149 await expect(cancelScheduled(api, alice, scheduledId)).to.not.be.rejected;166 await expect(cancelScheduled(api, alice, scheduledId)).to.not.be.rejected;150167151 await waitNewBlocks(period);168 await waitNewBlocks(period);152 const bobsBalanceAfterSecond = await getFreeBalance(bob);169 const bobsBalanceAfterSecond = await getFreeBalance(bob);153 expect(bobsBalanceAfterSecond == bobsBalanceAfterFirst, '#2 Balance of the recipient changed').to.be.true;170 expect(bobsBalanceAfterSecond)171 .to.be.equal(172 bobsBalanceAfterFirst,173 '#2 Balance of the recipient should not be changed',174 );154 });175 });155 });176 });156177178 // FIXME What purpose of this test?157 it('Can schedule a scheduled operation of canceling the scheduled operation', async () => {179 it.skip('Can schedule a scheduled operation of canceling the scheduled operation', async () => {158 await usingApi(async api => {180 await usingApi(async api => {159 const scheduledId = makeScheduledId();181 const scheduledId = makeScheduledId();160182176 await waitNewBlocks(waitForBlocks);197 await waitNewBlocks(waitForBlocks);177198178 // todo:scheduler debug line; doesn't work (and doesn't appear in events) when executed in the same block as the scheduled transaction199 // todo:scheduler debug line; doesn't work (and doesn't appear in events) when executed in the same block as the scheduled transaction179 //await expect(executeTransaction(api, alice, api.tx.scheduler.cancelNamed(scheduledId))).to.not.be.rejected;200 await expect(submitTransactionAsync(alice, api.tx.scheduler.cancelNamed(scheduledId))).to.not.be.rejected;180201181 let schedulerEvents = 0;202 let schedulerEvents = 0;182 for (let i = 0; i < period * repetitions; i++) {203 for (let i = 0; i < period * repetitions; i++) {205 });226 });206 });227 });207228208 it('Can\'t overwrite a scheduled ID', async () => {229 it("Can't overwrite a scheduled ID", async () => {209 await usingApi(async api => {230 await usingApi(async api => {210 const collectionId = await createCollectionExpectSuccess();231 const collectionId = await createCollectionExpectSuccess();211 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');232 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');212 const scheduledId = makeScheduledId();233 const scheduledId = makeScheduledId();234 const waitForBlocks = 4;235 const amount = 1;213236214 await scheduleTransferExpectSuccess(api, collectionId, tokenId, alice, bob, 1, 4, scheduledId);237 await scheduleTransferExpectSuccess(api, collectionId, tokenId, alice, bob, amount, waitForBlocks, scheduledId);215 await expect(scheduleAfter(238 await expect(scheduleAfter(216 api, 239 api, 217 api.tx.balances.transfer(alice.address, 1n * UNIQUE), 240 api.tx.balances.transfer(alice.address, 1n * UNIQUE), 218 bob, 241 bob, 219 2, 242 /* period = */ 2, 220 scheduledId,243 scheduledId,221 )).to.be.rejectedWith(/scheduler\.FailedToSchedule/);244 )).to.be.rejectedWith(/scheduler\.FailedToSchedule/);245222 const bobsBalance = await getFreeBalance(bob);246 const bobsBalanceBefore = await getFreeBalance(bob);223247224 await waitNewBlocks(3);248 await waitNewBlocks(waitForBlocks);225249226 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(bob.address));250 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(bob.address));227 expect(bobsBalance).to.be.equal(await getFreeBalance(bob));251 expect(bobsBalanceBefore).to.be.equal(await getFreeBalance(bob));228 });252 });229 });253 });230254231 it('Can\'t cancel an operation which is not scheduled', async () => {255 it("Can't cancel an operation which is not scheduled", async () => {232 await usingApi(async api => {256 await usingApi(async api => {233 const scheduledId = makeScheduledId();257 const scheduledId = makeScheduledId();234 await expect(cancelScheduled(api, alice, scheduledId)).to.be.rejectedWith(/scheduler\.NotFound/);258 await expect(cancelScheduled(api, alice, scheduledId)).to.be.rejectedWith(/scheduler\.NotFound/);235 });259 });236 });260 });237261238 it('Can\'t cancel a non-owned scheduled operation', async () => {262 it("Can't cancel a non-owned scheduled operation", async () => {239 await usingApi(async api => {263 await usingApi(async api => {240 const collectionId = await createCollectionExpectSuccess();264 const collectionId = await createCollectionExpectSuccess();241 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');265 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');242 const scheduledId = makeScheduledId();266 const scheduledId = makeScheduledId();243 const waitForBlocks = 3;267 const waitForBlocks = 3;268269 const amount = 1;244270245 await scheduleTransferExpectSuccess(api, collectionId, tokenId, alice, bob, 1, waitForBlocks, scheduledId);271 await scheduleTransferExpectSuccess(api, collectionId, tokenId, alice, bob, amount, waitForBlocks, scheduledId);246 await expect(cancelScheduled(api, bob, scheduledId)).to.be.rejected;272 await expect(cancelScheduled(api, bob, scheduledId)).to.be.rejected;247273248 await waitNewBlocks(waitForBlocks);274 await waitNewBlocks(waitForBlocks);