Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vara): Store dust in treasury #3364

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 89 additions & 1 deletion runtime/vara/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,6 +57,7 @@ pub(crate) fn on_initialize(new_block_number: BlockNumberFor<Runtime>) {
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);
Expand All @@ -72,6 +73,7 @@ pub(crate) fn on_finalize(current_blk: BlockNumberFor<Runtime>) {
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);
Expand Down Expand Up @@ -176,6 +178,7 @@ impl ExtBuilder {
.assimilate_storage(&mut storage)
.unwrap();

#[cfg(feature = "dev")]
SudoConfig { key: self.root }
.assimilate_storage(&mut storage)
.unwrap();
Expand Down Expand Up @@ -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);
});
}
2 changes: 1 addition & 1 deletion runtime/vara/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EXISTENTIAL_DEPOSIT>;
type AccountStore = System;
type WeightInfo = weights::pallet_balances::SubstrateWeight<Runtime>;
Expand Down