diff --git a/runtime/vara/src/integration_tests.rs b/runtime/vara/src/integration_tests.rs index fbc17eef11f..86f9204b798 100644 --- a/runtime/vara/src/integration_tests.rs +++ b/runtime/vara/src/integration_tests.rs @@ -28,7 +28,7 @@ use sp_consensus_babe::{ }; use sp_core::{ed25519, sr25519, Pair}; use sp_keyring::AccountKeyring; -use sp_runtime::{Digest, DigestItem}; +use sp_runtime::{traits::Zero, Digest, DigestItem}; const ENDOWMENT: u128 = 100 * UNITS; const STASH: u128 = 10 * UNITS; @@ -57,6 +57,7 @@ pub(crate) fn on_initialize(new_block_number: BlockNumberFor) { Babe::on_initialize(new_block_number); Balances::on_initialize(new_block_number); Authorship::on_initialize(new_block_number); + Treasury::on_initialize(new_block_number); GearProgram::on_initialize(new_block_number); GearMessenger::on_initialize(new_block_number); Gear::on_initialize(new_block_number); @@ -72,6 +73,7 @@ pub(crate) fn on_finalize(current_blk: BlockNumberFor) { Gear::on_finalize(current_blk); GearMessenger::on_finalize(current_blk); GearProgram::on_finalize(current_blk); + Treasury::on_finalize(current_blk); Authorship::on_finalize(current_blk); Balances::on_finalize(current_blk); Grandpa::on_finalize(current_blk); @@ -176,6 +178,7 @@ impl ExtBuilder { .assimilate_storage(&mut storage) .unwrap(); + #[cfg(feature = "dev")] SudoConfig { key: self.root } .assimilate_storage(&mut storage) .unwrap(); @@ -352,3 +355,88 @@ fn tokens_locking_works() { ); }); } + +#[test] +fn dust_treasury() { + init_logger(); + + let alice = AccountKeyring::Alice; + let bob = AccountKeyring::Bob; + let charlie = AccountKeyring::Charlie; + let dave = AccountKeyring::Dave; + let eve = AccountKeyring::Eve; + let ferdie = AccountKeyring::Ferdie; + + ExtBuilder::default() + .initial_authorities(vec![ + ( + alice.into(), + charlie.into(), + alice.public(), + ed25519::Pair::from_string("//Alice", None) + .unwrap() + .public(), + alice.public(), + alice.public(), + ), + ( + bob.into(), + dave.into(), + bob.public(), + ed25519::Pair::from_string("//Bob", None).unwrap().public(), + bob.public(), + bob.public(), + ), + ]) + .stash(STASH) + .endowment(ENDOWMENT) + .endowed_accounts(vec![ + charlie.into(), + dave.into(), + eve.into(), + Treasury::account_id(), + ]) + .vested_accounts(vec![ + (dave.into(), 10, 100, 10 * UNITS), // 1 TOKEN unlocked per block + (eve.into(), 10, 100, 10 * UNITS), + ]) + .root(alice.into()) + .build() + .execute_with(|| { + let acc_data = System::account(ferdie.to_account_id()).data; + + // Ferdie have zero balance + assert_eq!(acc_data.free, Zero::zero()); + + let pot = Treasury::pot(); + + // Treasury have free funds + assert_eq!(pot, ENDOWMENT - EXISTENTIAL_DEPOSIT); + + // Transfer EXISTENTIAL_DEPOSIT to ferdie + assert_ok!(Balances::transfer( + RuntimeOrigin::signed(dave.to_account_id()), + sp_runtime::MultiAddress::Id(ferdie.to_account_id()), + EXISTENTIAL_DEPOSIT + )); + + run_to_block(2); + + assert_eq!( + System::account(ferdie.to_account_id()).data.free, + EXISTENTIAL_DEPOSIT + ); + + // Transfer half of EXISTENTIAL_DEPOSIT + assert_ok!(Balances::transfer( + RuntimeOrigin::signed(ferdie.to_account_id()), + sp_runtime::MultiAddress::Id(dave.to_account_id()), + EXISTENTIAL_DEPOSIT / 2 + )); + + run_to_block(3); + + // Check that dust is in Treasury + assert_eq!(Treasury::pot(), pot + EXISTENTIAL_DEPOSIT / 2); + }); +} diff --git a/runtime/vara/src/lib.rs b/runtime/vara/src/lib.rs index 11b503790d2..53cf57b67fa 100644 --- a/runtime/vara/src/lib.rs +++ b/runtime/vara/src/lib.rs @@ -334,7 +334,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); + type DustRemoval = Treasury; type ExistentialDeposit = ConstU128; type AccountStore = System; type WeightInfo = weights::pallet_balances::SubstrateWeight;