diff --git a/substrate/srml/balances/src/lib.rs b/substrate/srml/balances/src/lib.rs index 775d83e33b..68044a3898 100644 --- a/substrate/srml/balances/src/lib.rs +++ b/substrate/srml/balances/src/lib.rs @@ -644,7 +644,7 @@ where who: &T::AccountId, value: Self::Balance, ) -> Self::PositiveImbalance { - let (imbalance, _) = Self::ensure_free_balance_is(who, Self::free_balance(who) + value); + let (imbalance, _) = Self::make_free_balance_be(who, Self::free_balance(who) + value); if let SignedImbalance::Positive(p) = imbalance { p } else { @@ -653,7 +653,7 @@ where } } - fn ensure_free_balance_is(who: &T::AccountId, balance: T::Balance) -> ( + fn make_free_balance_be(who: &T::AccountId, balance: T::Balance) -> ( SignedImbalance, UpdateBalanceOutcome ) { diff --git a/substrate/srml/contract/src/account_db.rs b/substrate/srml/contract/src/account_db.rs index e7dc144161..1ea763800a 100644 --- a/substrate/srml/contract/src/account_db.rs +++ b/substrate/srml/contract/src/account_db.rs @@ -122,7 +122,7 @@ impl AccountDb for DirectAccountDb { for (address, changed) in s.into_iter() { let trieid = >::get_or_create_trieid(&self, &address); if let Some(balance) = changed.balance { - let (imbalance, outcome) = balances::Module::::ensure_free_balance_is(&address, balance); + let (imbalance, outcome) = balances::Module::::make_free_balance_be(&address, balance); total_imbalance = total_imbalance.merge(imbalance); if let UpdateBalanceOutcome::AccountKilled = outcome { // Account killed. This will ultimately lead to calling `OnFreeBalanceZero` callback diff --git a/substrate/srml/staking/src/tests.rs b/substrate/srml/staking/src/tests.rs index 86b583fab8..f1ca3cbc03 100644 --- a/substrate/srml/staking/src/tests.rs +++ b/substrate/srml/staking/src/tests.rs @@ -105,7 +105,7 @@ fn invulnerability_should_work() { // Make account 11 invulnerable assert_ok!(Staking::set_invulnerables(vec![11])); // Give account 11 some funds - let _ = Balances::ensure_free_balance_is(&11, 70); + let _ = Balances::make_free_balance_be(&11, 70); // There is no slash grace -- slash immediately. assert_eq!(Staking::offline_slash_grace(), 0); // Account 11 has not been slashed @@ -134,7 +134,7 @@ fn offline_should_slash_and_kick() { // Test that an offline validator gets slashed and kicked with_externalities(&mut ExtBuilder::default().build(), || { // Give account 10 some balance - let _ = Balances::ensure_free_balance_is(&11, 1000); + let _ = Balances::make_free_balance_be(&11, 1000); // Confirm account 10 is a validator assert!(>::exists(&11)); // Validators get slashed immediately @@ -164,7 +164,7 @@ fn offline_grace_should_delay_slashing() { // Tests that with grace, slashing is delayed with_externalities(&mut ExtBuilder::default().build(), || { // Initialize account 10 with balance - let _ = Balances::ensure_free_balance_is(&11, 70); + let _ = Balances::make_free_balance_be(&11, 70); // Verify account 11 has balance assert_eq!(Balances::free_balance(&11), 70); @@ -205,8 +205,8 @@ fn max_unstake_threshold_works() { with_externalities(&mut ExtBuilder::default().build(), || { const MAX_UNSTAKE_THRESHOLD: u32 = 10; // Two users with maximum possible balance - let _ = Balances::ensure_free_balance_is(&11, u64::max_value()); - let _ = Balances::ensure_free_balance_is(&21, u64::max_value()); + let _ = Balances::make_free_balance_be(&11, u64::max_value()); + let _ = Balances::make_free_balance_be(&21, u64::max_value()); // Give them full exposure as a staker >::insert(&11, Exposure { total: 1000000, own: 1000000, others: vec![]}); @@ -301,7 +301,7 @@ fn rewards_should_work() { // check the balance of a validator accounts. assert_eq!(Balances::total_balance(&11), 1000); // and the nominator (to-be) - let _ = Balances::ensure_free_balance_is(&2, 500); + let _ = Balances::make_free_balance_be(&2, 500); assert_eq!(Balances::total_balance(&2), 500); // add a dummy nominator. @@ -446,7 +446,7 @@ fn staking_should_work() { assert_eq!(Staking::bonding_duration(), 2); // put some money in account that we'll use. - for i in 1..5 { let _ = Balances::ensure_free_balance_is(&i, 2000); } + for i in 1..5 { let _ = Balances::make_free_balance_be(&i, 2000); } // --- Block 1: System::set_block_number(1); @@ -635,7 +635,7 @@ fn nominating_and_rewards_should_work() { // give the man some money let initial_balance = 1000; for i in [1, 2, 3, 4, 5, 10, 11, 20, 21].iter() { - let _ = Balances::ensure_free_balance_is(i, initial_balance); + let _ = Balances::make_free_balance_be(i, initial_balance); } // record their balances. @@ -719,7 +719,7 @@ fn nominators_also_get_slashed() { // give the man some money. let initial_balance = 1000; for i in [1, 2, 3, 10].iter() { - let _ = Balances::ensure_free_balance_is(i, initial_balance); + let _ = Balances::make_free_balance_be(i, initial_balance); } // 2 will nominate for 10 @@ -879,7 +879,7 @@ fn cannot_transfer_staked_balance() { assert_noop!(Balances::transfer(Origin::signed(11), 20, 1), "account liquidity restrictions prevent withdrawal"); // Give account 11 extra free balance - let _ = Balances::ensure_free_balance_is(&11, 10000); + let _ = Balances::make_free_balance_be(&11, 10000); // Confirm that account 11 can now transfer some balance assert_ok!(Balances::transfer(Origin::signed(11), 20, 1)); }); @@ -921,7 +921,7 @@ fn cannot_reserve_staked_balance() { assert_noop!(Balances::reserve(&11, 1), "account liquidity restrictions prevent withdrawal"); // Give account 11 extra free balance - let _ = Balances::ensure_free_balance_is(&11, 10000); + let _ = Balances::make_free_balance_be(&11, 10000); // Confirm account 11 can now reserve balance assert_ok!(Balances::reserve(&11, 1)); }); @@ -1029,7 +1029,7 @@ fn validator_payment_prefs_work() { // check the balance of a validator's stash accounts. assert_eq!(Balances::total_balance(&11), validator_initial_balance); // and the nominator (to-be) - let _ = Balances::ensure_free_balance_is(&2, 500); + let _ = Balances::make_free_balance_be(&2, 500); // add a dummy nominator. // NOTE: this nominator is being added 'manually', use '.nominate()' to do it realistically. @@ -1101,7 +1101,7 @@ fn bond_extra_works() { assert_eq!(Staking::ledger(&10), Some(StakingLedger { stash: 11, total: 1000, active: 1000, unlocking: vec![] })); // Give account 11 some large free balance greater than total - let _ = Balances::ensure_free_balance_is(&11, 1000000); + let _ = Balances::make_free_balance_be(&11, 1000000); // Call the bond_extra function from controller, add only 100 assert_ok!(Staking::bond_extra(Origin::signed(10), 100)); @@ -1134,7 +1134,7 @@ fn bond_extra_and_withdraw_unbonded_works() { assert_ok!(Staking::set_bonding_duration(2)); // Give account 11 some large free balance greater than total - let _ = Balances::ensure_free_balance_is(&11, 1000000); + let _ = Balances::make_free_balance_be(&11, 1000000); // Initial config should be correct assert_eq!(Staking::sessions_per_era(), 1); @@ -1232,8 +1232,8 @@ fn slot_stake_is_least_staked_validator_and_limits_maximum_punishment() { assert_eq!(Staking::stakers(&21).total, 2000); // Give the man some money. - let _ = Balances::ensure_free_balance_is(&10, 1000); - let _ = Balances::ensure_free_balance_is(&20, 1000); + let _ = Balances::make_free_balance_be(&10, 1000); + let _ = Balances::make_free_balance_be(&20, 1000); // We confirm initialized slot_stake is this value assert_eq!(Staking::slot_stake(), Staking::stakers(&11).total); diff --git a/substrate/srml/support/src/traits.rs b/substrate/srml/support/src/traits.rs index 30f441fd21..144e8af772 100644 --- a/substrate/srml/support/src/traits.rs +++ b/substrate/srml/support/src/traits.rs @@ -355,7 +355,7 @@ pub trait Currency { /// /// Returns a signed imbalance and status to indicate if the account was successfully updated or update /// has led to killing of the account. - fn ensure_free_balance_is( + fn make_free_balance_be( who: &AccountId, balance: Self::Balance, ) -> (