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
before · test-pallets/utils/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819pub use pallet::*;2021#[frame_support::pallet]22pub mod pallet {23	use frame_support::pallet_prelude::*;24	use frame_system::pallet_prelude::*;2526	#[pallet::config]27	pub trait Config: frame_system::Config {28		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;29	}3031	#[pallet::event]32	#[pallet::generate_deposit(pub(super) fn deposit_event)]33	pub enum Event<T: Config> {34		ValueIsSet,35		ShouldRollback,36	}3738	#[pallet::pallet]39	#[pallet::generate_store(pub(super) trait Store)]40	pub struct Pallet<T>(_);4142	#[pallet::storage]43	#[pallet::getter(fn something)]44	pub type TestValue<T> = StorageValue<_, u32, ValueQuery>;4546	#[pallet::error]47	pub enum Error<T> {48		TriggerRollback,49	}5051	#[pallet::call]52	impl<T: Config> Pallet<T> {53		#[pallet::weight(10_000)]54		pub fn set_test_value(origin: OriginFor<T>, value: u32) -> DispatchResult {55			ensure_signed(origin)?;5657			<TestValue<T>>::put(value);5859			Self::deposit_event(Event::ValueIsSet);6061			Ok(())62		}6364		#[pallet::weight(10_000)]65		pub fn set_test_value_and_rollback(origin: OriginFor<T>, value: u32) -> DispatchResult {66			Self::set_test_value(origin, value)?;6768			Self::deposit_event(Event::ShouldRollback);6970			Err(<Error<T>>::TriggerRollback.into())71		}72	}73}
after · test-pallets/utils/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819pub use pallet::*;2021#[frame_support::pallet]22pub mod pallet {23	use frame_support::pallet_prelude::*;24	use frame_system::pallet_prelude::*;2526	#[pallet::config]27	pub trait Config: frame_system::Config {28		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;29	}3031	#[pallet::event]32	#[pallet::generate_deposit(pub(super) fn deposit_event)]33	pub enum Event<T: Config> {34		ValueIsSet,35		ShouldRollback,36	}3738	#[pallet::pallet]39	#[pallet::generate_store(pub(super) trait Store)]40	pub struct Pallet<T>(_);4142	#[pallet::storage]43	#[pallet::getter(fn something)]44	pub type TestValue<T> = StorageValue<_, u32, ValueQuery>;4546	#[pallet::error]47	pub enum Error<T> {48		TriggerRollback,49	}5051	#[pallet::call]52	impl<T: Config> Pallet<T> {53		#[pallet::weight(10_000)]54		pub fn set_test_value(origin: OriginFor<T>, value: u32) -> DispatchResult {55			ensure_signed(origin)?;5657			<TestValue<T>>::put(value);5859			Self::deposit_event(Event::ValueIsSet);6061			Ok(())62		}6364		#[pallet::weight(10_000)]65		pub fn set_test_value_and_rollback(origin: OriginFor<T>, value: u32) -> DispatchResult {66			Self::set_test_value(origin, value)?;6768			Self::deposit_event(Event::ShouldRollback);6970			Err(<Error<T>>::TriggerRollback.into())71		}7273		#[pallet::weight(100_000_000)]74		pub fn just_take_fee(_origin: OriginFor<T>) -> DispatchResult {75			Ok(())76		}77	}78}
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 => {