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

difftreelog

test scheduled tx should take a fee

Daniel Shiposha2022-08-18parent: #07b1ed5.patch.diff
in: master

2 files changed

modifiedtest-pallets/utils/src/lib.rsdiffbeforeafterboth
70 Err(<Error<T>>::TriggerRollback.into())70 Err(<Error<T>>::TriggerRollback.into())
71 }71 }
72
73 #[pallet::weight(100_000_000)]
74 pub fn just_take_fee(_origin: OriginFor<T>) -> DispatchResult {
75 Ok(())
76 }
72 }77 }
73}78}
7479
modifiedtests/src/.outdated/scheduler.test.tsdiffbeforeafterboth
--- a/tests/src/.outdated/scheduler.test.ts
+++ b/tests/src/.outdated/scheduler.test.ts
@@ -216,6 +216,56 @@
     });
   });
 
+  it('Scheduled tasks should take some fees', async function() {
+    await requirePallets(this, [Pallets.TestUtils]);
+
+    await usingApi(async api => {
+      const scheduledId = makeScheduledId();
+      const waitForBlocks = 10;
+      const period = 2;
+      const repetitions = 1;
+
+      const dummyTxFeeAmount = 100_000_000;
+
+      const dummyTx = api.tx.testUtils.justTakeFee();
+
+      await expect(scheduleAfter(
+        api,
+        dummyTx,
+        alice,
+        waitForBlocks,
+        scheduledId,
+        period,
+        repetitions,
+      )).to.not.be.rejected;
+
+      const aliceInitBalance = await getFreeBalance(alice);
+      let diff;
+
+      await waitNewBlocks(waitForBlocks + 1);
+
+      const aliceBalanceAfterFirst = await getFreeBalance(alice);
+      expect(
+        aliceBalanceAfterFirst < aliceInitBalance,
+        '[after execution #1] Scheduled task should take a fee',
+      ).to.be.true;
+
+      diff = aliceInitBalance - aliceBalanceAfterFirst;
+      expect(diff).to.be.equal(dummyTxFeeAmount, 'Scheduled task should take the right amount of fees');
+
+      await waitNewBlocks(period);
+
+      const aliceBalanceAfterSecond = await getFreeBalance(alice);
+      expect(
+        aliceBalanceAfterSecond < aliceBalanceAfterFirst,
+        '[after execution #2] Scheduled task should take a fee',
+      ).to.be.true;
+
+      diff = aliceBalanceAfterFirst - aliceBalanceAfterSecond;
+      expect(diff).to.be.equal(dummyTxFeeAmount, 'Scheduled task should take the right amount of fees');
+    });
+  });
+
   // FIXME What purpose of this test?
   it.skip('Can schedule a scheduled operation of canceling the scheduled operation', async () => {
     await usingApi(async api => {