diff --git a/prdoc/pr_4967.prdoc b/prdoc/pr_4967.prdoc new file mode 100644 index 000000000000..0ce4219daa1c --- /dev/null +++ b/prdoc/pr_4967.prdoc @@ -0,0 +1,28 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: "Remove `pallet::getter` usage from the balances pallet" + +doc: + - audience: Runtime Dev + description: | + This PR removes the `pallet::getter`s from `pallet-balances`. + The syntax `StorageItem::::get()` should be used instead. + +crates: + - name: pallet-balances + bump: patch + - name: pallet-staking + bump: patch + - name: pallet-treasury + bump: patch + - name: pallet-bounties + bump: patch + - name: pallet-conviction-voting + bump: patch + - name: pallet-democracy + bump: patch + - name: pallet-elections-phragmen + bump: patch + - name: pallet-referenda + bump: patch diff --git a/substrate/frame/balances/src/benchmarking.rs b/substrate/frame/balances/src/benchmarking.rs index e4229f2d7f0f..5740f8081c07 100644 --- a/substrate/frame/balances/src/benchmarking.rs +++ b/substrate/frame/balances/src/benchmarking.rs @@ -288,13 +288,13 @@ mod benchmarks { #[benchmark] fn force_adjust_total_issuance() { - let ti = Balances::::total_issuance(); + let ti = TotalIssuance::::get(); let delta = 123u32.into(); #[extrinsic_call] _(RawOrigin::Root, AdjustmentDirection::Increase, delta); - assert_eq!(Balances::::total_issuance(), ti + delta); + assert_eq!(TotalIssuance::::get(), ti + delta); } /// Benchmark `burn` extrinsic with the worst possible condition - burn kills the account. diff --git a/substrate/frame/balances/src/lib.rs b/substrate/frame/balances/src/lib.rs index ddca685aa012..87d2029d488e 100644 --- a/substrate/frame/balances/src/lib.rs +++ b/substrate/frame/balances/src/lib.rs @@ -408,13 +408,11 @@ pub mod pallet { /// The total units issued in the system. #[pallet::storage] - #[pallet::getter(fn total_issuance)] #[pallet::whitelist_storage] pub type TotalIssuance, I: 'static = ()> = StorageValue<_, T::Balance, ValueQuery>; /// The total units of outstanding deactivated balance in the system. #[pallet::storage] - #[pallet::getter(fn inactive_issuance)] #[pallet::whitelist_storage] pub type InactiveIssuance, I: 'static = ()> = StorageValue<_, T::Balance, ValueQuery>; @@ -452,7 +450,6 @@ pub mod pallet { /// /// Use of locks is deprecated in favour of freezes. See `https://github.com/paritytech/substrate/pull/12951/` #[pallet::storage] - #[pallet::getter(fn locks)] pub type Locks, I: 'static = ()> = StorageMap< _, Blake2_128Concat, @@ -465,7 +462,6 @@ pub mod pallet { /// /// Use of reserves is deprecated in favour of holds. See `https://github.com/paritytech/substrate/pull/12951/` #[pallet::storage] - #[pallet::getter(fn reserves)] pub type Reserves, I: 'static = ()> = StorageMap< _, Blake2_128Concat, @@ -822,6 +818,28 @@ pub mod pallet { } impl, I: 'static> Pallet { + /// Public function to get the total issuance. + pub fn total_issuance() -> T::Balance { + TotalIssuance::::get() + } + + /// Public function to get the inactive issuance. + pub fn inactive_issuance() -> T::Balance { + InactiveIssuance::::get() + } + + /// Public function to access the Locks storage. + pub fn locks(who: &T::AccountId) -> WeakBoundedVec, T::MaxLocks> { + Locks::::get(who) + } + + /// Public function to access the reserves storage. + pub fn reserves( + who: &T::AccountId, + ) -> BoundedVec, T::MaxReserves> { + Reserves::::get(who) + } + fn ed() -> T::Balance { T::ExistentialDeposit::get() } diff --git a/substrate/frame/balances/src/tests/currency_tests.rs b/substrate/frame/balances/src/tests/currency_tests.rs index fb69368a6216..2243859458be 100644 --- a/substrate/frame/balances/src/tests/currency_tests.rs +++ b/substrate/frame/balances/src/tests/currency_tests.rs @@ -407,7 +407,7 @@ fn reward_should_work() { ] ); assert_eq!(Balances::total_balance(&1), 20); - assert_eq!(Balances::total_issuance(), 120); + assert_eq!(pallet_balances::TotalIssuance::::get(), 120); }); } @@ -473,7 +473,7 @@ fn slashing_balance_should_work() { assert!(Balances::slash(&1, 42).1.is_zero()); assert_eq!(Balances::free_balance(1), 1); assert_eq!(Balances::reserved_balance(1), 69); - assert_eq!(Balances::total_issuance(), 70); + assert_eq!(pallet_balances::TotalIssuance::::get(), 70); }); } @@ -488,7 +488,7 @@ fn withdrawing_balance_should_work() { amount: 11, })); assert_eq!(Balances::free_balance(2), 100); - assert_eq!(Balances::total_issuance(), 100); + assert_eq!(pallet_balances::TotalIssuance::::get(), 100); }); } @@ -519,7 +519,7 @@ fn slashing_incomplete_balance_should_work() { assert_eq!(Balances::slash(&1, 69).1, 49); assert_eq!(Balances::free_balance(1), 1); assert_eq!(Balances::reserved_balance(1), 21); - assert_eq!(Balances::total_issuance(), 22); + assert_eq!(pallet_balances::TotalIssuance::::get(), 22); }); } @@ -542,7 +542,7 @@ fn slashing_reserved_balance_should_work() { assert_eq!(Balances::slash_reserved(&1, 42).1, 0); assert_eq!(Balances::reserved_balance(1), 69); assert_eq!(Balances::free_balance(1), 1); - assert_eq!(Balances::total_issuance(), 70); + assert_eq!(pallet_balances::TotalIssuance::::get(), 70); }); } @@ -554,7 +554,7 @@ fn slashing_incomplete_reserved_balance_should_work() { assert_eq!(Balances::slash_reserved(&1, 69).1, 27); assert_eq!(Balances::free_balance(1), 69); assert_eq!(Balances::reserved_balance(1), 0); - assert_eq!(Balances::total_issuance(), 69); + assert_eq!(pallet_balances::TotalIssuance::::get(), 69); }); } @@ -654,12 +654,12 @@ fn transferring_too_high_value_should_not_panic() { fn account_create_on_free_too_low_with_other() { ExtBuilder::default().existential_deposit(100).build_and_execute_with(|| { let _ = Balances::deposit_creating(&1, 100); - assert_eq!(Balances::total_issuance(), 100); + assert_eq!(pallet_balances::TotalIssuance::::get(), 100); // No-op. let _ = Balances::deposit_creating(&2, 50); assert_eq!(Balances::free_balance(2), 0); - assert_eq!(Balances::total_issuance(), 100); + assert_eq!(pallet_balances::TotalIssuance::::get(), 100); }) } @@ -669,14 +669,14 @@ fn account_create_on_free_too_low() { // No-op. let _ = Balances::deposit_creating(&2, 50); assert_eq!(Balances::free_balance(2), 0); - assert_eq!(Balances::total_issuance(), 0); + assert_eq!(pallet_balances::TotalIssuance::::get(), 0); }) } #[test] fn account_removal_on_free_too_low() { ExtBuilder::default().existential_deposit(100).build_and_execute_with(|| { - assert_eq!(Balances::total_issuance(), 0); + assert_eq!(pallet_balances::TotalIssuance::::get(), 0); // Setup two accounts with free balance above the existential threshold. let _ = Balances::deposit_creating(&1, 110); @@ -684,7 +684,7 @@ fn account_removal_on_free_too_low() { assert_eq!(Balances::free_balance(1), 110); assert_eq!(Balances::free_balance(2), 110); - assert_eq!(Balances::total_issuance(), 220); + assert_eq!(pallet_balances::TotalIssuance::::get(), 220); // Transfer funds from account 1 of such amount that after this transfer // the balance of account 1 will be below the existential threshold. @@ -696,18 +696,18 @@ fn account_removal_on_free_too_low() { assert_eq!(Balances::free_balance(2), 130); // Verify that TotalIssuance tracks balance removal when free balance is too low. - assert_eq!(Balances::total_issuance(), 130); + assert_eq!(pallet_balances::TotalIssuance::::get(), 130); }); } #[test] fn burn_must_work() { ExtBuilder::default().monied(true).build_and_execute_with(|| { - let init_total_issuance = Balances::total_issuance(); + let init_total_issuance = pallet_balances::TotalIssuance::::get(); let imbalance = >::burn(10); - assert_eq!(Balances::total_issuance(), init_total_issuance - 10); + assert_eq!(pallet_balances::TotalIssuance::::get(), init_total_issuance - 10); drop(imbalance); - assert_eq!(Balances::total_issuance(), init_total_issuance); + assert_eq!(pallet_balances::TotalIssuance::::get(), init_total_issuance); }); } @@ -1396,7 +1396,7 @@ fn freezing_and_locking_should_work() { #[test] fn self_transfer_noop() { ExtBuilder::default().existential_deposit(100).build_and_execute_with(|| { - assert_eq!(Balances::total_issuance(), 0); + assert_eq!(pallet_balances::TotalIssuance::::get(), 0); let _ = Balances::deposit_creating(&1, 100); // The account is set up properly: @@ -1410,7 +1410,7 @@ fn self_transfer_noop() { ] ); assert_eq!(Balances::free_balance(1), 100); - assert_eq!(Balances::total_issuance(), 100); + assert_eq!(pallet_balances::TotalIssuance::::get(), 100); // Transfers to self are No-OPs: let _g = StorageNoopGuard::new(); @@ -1425,7 +1425,11 @@ fn self_transfer_noop() { assert!(events().is_empty()); assert_eq!(Balances::free_balance(1), 100, "Balance unchanged by self transfer"); - assert_eq!(Balances::total_issuance(), 100, "TI unchanged by self transfers"); + assert_eq!( + pallet_balances::TotalIssuance::::get(), + 100, + "TI unchanged by self transfers" + ); } }); } diff --git a/substrate/frame/balances/src/tests/dispatchable_tests.rs b/substrate/frame/balances/src/tests/dispatchable_tests.rs index ebc9f1b1a369..77e44202e982 100644 --- a/substrate/frame/balances/src/tests/dispatchable_tests.rs +++ b/substrate/frame/balances/src/tests/dispatchable_tests.rs @@ -187,9 +187,9 @@ fn set_balance_handles_killing_account() { #[test] fn set_balance_handles_total_issuance() { ExtBuilder::default().build_and_execute_with(|| { - let old_total_issuance = Balances::total_issuance(); + let old_total_issuance = pallet_balances::TotalIssuance::::get(); assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), 1337, 69)); - assert_eq!(Balances::total_issuance(), old_total_issuance + 69); + assert_eq!(pallet_balances::TotalIssuance::::get(), old_total_issuance + 69); assert_eq!(Balances::total_balance(&1337), 69); assert_eq!(Balances::free_balance(&1337), 69); }); @@ -236,12 +236,12 @@ fn force_adjust_total_issuance_example() { ExtBuilder::default().build_and_execute_with(|| { // First we set the TotalIssuance to 64 by giving Alice a balance of 64. assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), ALICE, 64)); - let old_ti = Balances::total_issuance(); + let old_ti = pallet_balances::TotalIssuance::::get(); assert_eq!(old_ti, 64, "TI should be 64"); // Now test the increase: assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Inc, 32)); - let new_ti = Balances::total_issuance(); + let new_ti = pallet_balances::TotalIssuance::::get(); assert_eq!(old_ti + 32, new_ti, "Should increase by 32"); // If Alice tries to call it, it errors: @@ -256,11 +256,11 @@ fn force_adjust_total_issuance_example() { fn force_adjust_total_issuance_works() { ExtBuilder::default().build_and_execute_with(|| { assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), 1337, 64)); - let ti = Balances::total_issuance(); + let ti = pallet_balances::TotalIssuance::::get(); // Increase works: assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Inc, 32)); - assert_eq!(Balances::total_issuance(), ti + 32); + assert_eq!(pallet_balances::TotalIssuance::::get(), ti + 32); System::assert_last_event(RuntimeEvent::Balances(Event::TotalIssuanceForced { old: 64, new: 96, @@ -268,7 +268,7 @@ fn force_adjust_total_issuance_works() { // Decrease works: assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Dec, 64)); - assert_eq!(Balances::total_issuance(), ti - 32); + assert_eq!(pallet_balances::TotalIssuance::::get(), ti - 32); System::assert_last_event(RuntimeEvent::Balances(Event::TotalIssuanceForced { old: 96, new: 32, @@ -280,19 +280,19 @@ fn force_adjust_total_issuance_works() { fn force_adjust_total_issuance_saturates() { ExtBuilder::default().build_and_execute_with(|| { assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), 1337, 64)); - let ti = Balances::total_issuance(); + let ti = pallet_balances::TotalIssuance::::get(); let max = ::Balance::max_value(); assert_eq!(ti, 64); // Increment saturates: assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Inc, max)); assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Inc, 123)); - assert_eq!(Balances::total_issuance(), max); + assert_eq!(pallet_balances::TotalIssuance::::get(), max); // Decrement saturates: assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Dec, max)); assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Dec, 123)); - assert_eq!(Balances::total_issuance(), 0); + assert_eq!(pallet_balances::TotalIssuance::::get(), 0); }); } @@ -316,13 +316,13 @@ fn force_adjust_total_issuance_rejects_more_than_inactive() { assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), 1337, 64)); Balances::deactivate(16u32.into()); - assert_eq!(Balances::total_issuance(), 64); + assert_eq!(pallet_balances::TotalIssuance::::get(), 64); assert_eq!(Balances::active_issuance(), 48); // Works with up to 48: assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Dec, 40),); assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Dec, 8),); - assert_eq!(Balances::total_issuance(), 16); + assert_eq!(pallet_balances::TotalIssuance::::get(), 16); assert_eq!(Balances::active_issuance(), 0); // Errors with more than 48: assert_noop!( @@ -331,7 +331,7 @@ fn force_adjust_total_issuance_rejects_more_than_inactive() { ); // Increasing again increases the inactive issuance: assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Inc, 10),); - assert_eq!(Balances::total_issuance(), 26); + assert_eq!(pallet_balances::TotalIssuance::::get(), 26); assert_eq!(Balances::active_issuance(), 10); }); } @@ -342,7 +342,7 @@ fn burn_works() { // Prepare account with initial balance let (account, init_balance) = (1, 37); assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), account, init_balance)); - let init_issuance = Balances::total_issuance(); + let init_issuance = pallet_balances::TotalIssuance::::get(); let (keep_alive, allow_death) = (true, false); // 1. Cannot burn more than what's available @@ -358,7 +358,7 @@ fn burn_works() { who: account, amount: burn_amount_1, })); - assert_eq!(Balances::total_issuance(), init_issuance - burn_amount_1); + assert_eq!(pallet_balances::TotalIssuance::::get(), init_issuance - burn_amount_1); assert_eq!(Balances::total_balance(&account), init_balance - burn_amount_1); // 3. Cannot burn funds below existential deposit if `keep_alive` is `true` @@ -375,7 +375,10 @@ fn burn_works() { who: account, amount: burn_amount_2, })); - assert_eq!(Balances::total_issuance(), init_issuance - burn_amount_1 - burn_amount_2); + assert_eq!( + pallet_balances::TotalIssuance::::get(), + init_issuance - burn_amount_1 - burn_amount_2 + ); assert!(Balances::total_balance(&account).is_zero()); }); } diff --git a/substrate/frame/bounties/src/tests.rs b/substrate/frame/bounties/src/tests.rs index 7cd479826745..c152391d807a 100644 --- a/substrate/frame/bounties/src/tests.rs +++ b/substrate/frame/bounties/src/tests.rs @@ -241,13 +241,13 @@ fn accepted_spend_proposal_ignored_outside_spend_period() { #[test] fn unused_pot_should_diminish() { ExtBuilder::default().build_and_execute(|| { - let init_total_issuance = Balances::total_issuance(); + let init_total_issuance = pallet_balances::TotalIssuance::::get(); Balances::make_free_balance_be(&Treasury::account_id(), 101); - assert_eq!(Balances::total_issuance(), init_total_issuance + 100); + assert_eq!(pallet_balances::TotalIssuance::::get(), init_total_issuance + 100); >::on_initialize(2); assert_eq!(Treasury::pot(), 50); - assert_eq!(Balances::total_issuance(), init_total_issuance + 50); + assert_eq!(pallet_balances::TotalIssuance::::get(), init_total_issuance + 50); }); } diff --git a/substrate/frame/conviction-voting/src/tests.rs b/substrate/frame/conviction-voting/src/tests.rs index 78569fb3c9f2..37cdd7a5b338 100644 --- a/substrate/frame/conviction-voting/src/tests.rs +++ b/substrate/frame/conviction-voting/src/tests.rs @@ -172,7 +172,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { fn params_should_work() { new_test_ext().execute_with(|| { assert_eq!(Balances::free_balance(42), 0); - assert_eq!(Balances::total_issuance(), 210); + assert_eq!(pallet_balances::TotalIssuance::::get(), 210); }); } diff --git a/substrate/frame/democracy/src/tests.rs b/substrate/frame/democracy/src/tests.rs index 7d7066c8af69..10e5ee75611d 100644 --- a/substrate/frame/democracy/src/tests.rs +++ b/substrate/frame/democracy/src/tests.rs @@ -185,7 +185,7 @@ fn params_should_work() { new_test_ext().execute_with(|| { assert_eq!(ReferendumCount::::get(), 0); assert_eq!(Balances::free_balance(42), 0); - assert_eq!(Balances::total_issuance(), 210); + assert_eq!(pallet_balances::TotalIssuance::::get(), 210); }); } diff --git a/substrate/frame/democracy/src/tests/lock_voting.rs b/substrate/frame/democracy/src/tests/lock_voting.rs index 31f2e3f3dcc2..7d0b28b9847d 100644 --- a/substrate/frame/democracy/src/tests/lock_voting.rs +++ b/substrate/frame/democracy/src/tests/lock_voting.rs @@ -56,7 +56,7 @@ fn lock_voting_should_work() { // All balances are currently locked. for i in 1..=5 { - assert_eq!(Balances::locks(i), vec![the_lock(i * 10)]); + assert_eq!(pallet_balances::Locks::::get(&i), vec![the_lock(i * 10)]); } fast_forward_to(3); @@ -77,11 +77,11 @@ fn lock_voting_should_work() { assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(2), r)); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 2)); - assert_eq!(Balances::locks(1), vec![]); - assert_eq!(Balances::locks(2), vec![the_lock(20)]); - assert_eq!(Balances::locks(3), vec![the_lock(30)]); - assert_eq!(Balances::locks(4), vec![the_lock(40)]); - assert_eq!(Balances::locks(5), vec![]); + assert_eq!(pallet_balances::Locks::::get(&1), vec![]); + assert_eq!(pallet_balances::Locks::::get(&2), vec![the_lock(20)]); + assert_eq!(pallet_balances::Locks::::get(&3), vec![the_lock(30)]); + assert_eq!(pallet_balances::Locks::::get(&4), vec![the_lock(40)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![]); assert_eq!(Balances::free_balance(42), 2); fast_forward_to(7); @@ -91,12 +91,12 @@ fn lock_voting_should_work() { Error::::NoPermission ); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 4)); - assert_eq!(Balances::locks(4), vec![the_lock(40)]); + assert_eq!(pallet_balances::Locks::::get(&4), vec![the_lock(40)]); fast_forward_to(8); // 4 should now be able to reap and unlock assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 4, r)); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 4)); - assert_eq!(Balances::locks(4), vec![]); + assert_eq!(pallet_balances::Locks::::get(&4), vec![]); fast_forward_to(13); assert_noop!( @@ -104,19 +104,19 @@ fn lock_voting_should_work() { Error::::NoPermission ); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 3)); - assert_eq!(Balances::locks(3), vec![the_lock(30)]); + assert_eq!(pallet_balances::Locks::::get(&3), vec![the_lock(30)]); fast_forward_to(14); assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 3, r)); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 3)); - assert_eq!(Balances::locks(3), vec![]); + assert_eq!(pallet_balances::Locks::::get(&3), vec![]); // 2 doesn't need to reap_vote here because it was already done before. fast_forward_to(25); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 2)); - assert_eq!(Balances::locks(2), vec![the_lock(20)]); + assert_eq!(pallet_balances::Locks::::get(&2), vec![the_lock(20)]); fast_forward_to(26); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 2)); - assert_eq!(Balances::locks(2), vec![]); + assert_eq!(pallet_balances::Locks::::get(&2), vec![]); }); } @@ -137,7 +137,7 @@ fn no_locks_without_conviction_should_work() { assert_eq!(Balances::free_balance(42), 2); assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(2), 1, r)); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 1)); - assert_eq!(Balances::locks(1), vec![]); + assert_eq!(pallet_balances::Locks::::get(&1), vec![]); }); } @@ -198,33 +198,33 @@ fn prior_lockvotes_should_be_enforced() { Error::::NoPermission ); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![the_lock(50)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![the_lock(50)]); fast_forward_to(8); assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.2)); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![the_lock(20)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![the_lock(20)]); fast_forward_to(13); assert_noop!( Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.1), Error::::NoPermission ); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![the_lock(20)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![the_lock(20)]); fast_forward_to(14); assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.1)); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![the_lock(10)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![the_lock(10)]); fast_forward_to(25); assert_noop!( Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.0), Error::::NoPermission ); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![the_lock(10)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![the_lock(10)]); fast_forward_to(26); assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.0)); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![]); }); } @@ -239,26 +239,26 @@ fn single_consolidation_of_lockvotes_should_work_as_before() { fast_forward_to(7); assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.2)); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![the_lock(50)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![the_lock(50)]); fast_forward_to(8); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![the_lock(20)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![the_lock(20)]); fast_forward_to(13); assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.1)); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![the_lock(20)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![the_lock(20)]); fast_forward_to(14); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![the_lock(10)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![the_lock(10)]); fast_forward_to(25); assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.0)); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![the_lock(10)]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![the_lock(10)]); fast_forward_to(26); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![]); }); } @@ -276,15 +276,15 @@ fn multi_consolidation_of_lockvotes_should_be_conservative() { fast_forward_to(8); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert!(Balances::locks(5)[0].amount >= 20); + assert!(pallet_balances::Locks::::get(&5)[0].amount >= 20); fast_forward_to(14); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert!(Balances::locks(5)[0].amount >= 10); + assert!(pallet_balances::Locks::::get(&5)[0].amount >= 10); fast_forward_to(26); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![]); }); } @@ -305,26 +305,26 @@ fn locks_should_persist_from_voting_to_delegation() { assert_ok!(Democracy::delegate(RuntimeOrigin::signed(5), 1, Conviction::Locked3x, 20)); // locked 20. - assert!(Balances::locks(5)[0].amount == 20); + assert!(pallet_balances::Locks::::get(&5)[0].amount == 20); assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(5))); // locked 20 until #14 fast_forward_to(13); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert!(Balances::locks(5)[0].amount == 20); + assert!(pallet_balances::Locks::::get(&5)[0].amount == 20); fast_forward_to(14); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert!(Balances::locks(5)[0].amount >= 10); + assert!(pallet_balances::Locks::::get(&5)[0].amount >= 10); fast_forward_to(25); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert!(Balances::locks(5)[0].amount >= 10); + assert!(pallet_balances::Locks::::get(&5)[0].amount >= 10); fast_forward_to(26); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![]); }); } @@ -347,18 +347,18 @@ fn locks_should_persist_from_delegation_to_voting() { fast_forward_to(8); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert!(Balances::locks(5)[0].amount >= 20); + assert!(pallet_balances::Locks::::get(&5)[0].amount >= 20); fast_forward_to(14); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert!(Balances::locks(5)[0].amount >= 10); + assert!(pallet_balances::Locks::::get(&5)[0].amount >= 10); fast_forward_to(26); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert!(Balances::locks(5)[0].amount >= 5); + assert!(pallet_balances::Locks::::get(&5)[0].amount >= 5); fast_forward_to(48); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![]); }); } diff --git a/substrate/frame/democracy/src/tests/voting.rs b/substrate/frame/democracy/src/tests/voting.rs index 61b80cc97fed..651a2cc8552a 100644 --- a/substrate/frame/democracy/src/tests/voting.rs +++ b/substrate/frame/democracy/src/tests/voting.rs @@ -55,7 +55,7 @@ fn split_vote_cancellation_should_work() { assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r)); assert_eq!(tally(r), Tally { ayes: 0, nays: 0, turnout: 0 }); assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5)); - assert_eq!(Balances::locks(5), vec![]); + assert_eq!(pallet_balances::Locks::::get(&5), vec![]); }); } @@ -152,7 +152,7 @@ fn controversial_low_turnout_voting_should_work() { fn passing_low_turnout_voting_should_work() { new_test_ext().execute_with(|| { assert_eq!(Balances::free_balance(42), 0); - assert_eq!(Balances::total_issuance(), 210); + assert_eq!(pallet_balances::TotalIssuance::::get(), 210); let r = Democracy::inject_referendum( 2, diff --git a/substrate/frame/elections-phragmen/src/lib.rs b/substrate/frame/elections-phragmen/src/lib.rs index 565ead4059d5..6d91448fd185 100644 --- a/substrate/frame/elections-phragmen/src/lib.rs +++ b/substrate/frame/elections-phragmen/src/lib.rs @@ -2195,7 +2195,7 @@ mod tests { assert_eq!(locked_stake_of(&2), 0); assert_eq!(balances(&2), (20, 0)); - assert_eq!(Balances::locks(&2).len(), 0); + assert_eq!(pallet_balances::Locks::::get(&2).len(), 0); }); } diff --git a/substrate/frame/referenda/src/tests.rs b/substrate/frame/referenda/src/tests.rs index 3f859636f7cb..9f851992496c 100644 --- a/substrate/frame/referenda/src/tests.rs +++ b/substrate/frame/referenda/src/tests.rs @@ -30,7 +30,7 @@ fn params_should_work() { ExtBuilder::default().build_and_execute(|| { assert_eq!(ReferendumCount::::get(), 0); assert_eq!(Balances::free_balance(42), 0); - assert_eq!(Balances::total_issuance(), 600); + assert_eq!(pallet_balances::TotalIssuance::::get(), 600); }); } diff --git a/substrate/frame/staking/src/mock.rs b/substrate/frame/staking/src/mock.rs index 7cc8e865916d..4a0209fc5b08 100644 --- a/substrate/frame/staking/src/mock.rs +++ b/substrate/frame/staking/src/mock.rs @@ -664,7 +664,7 @@ pub(crate) fn start_active_era(era_index: EraIndex) { pub(crate) fn current_total_payout_for_duration(duration: u64) -> Balance { let (payout, _rest) = ::EraPayout::era_payout( Staking::eras_total_stake(active_era()), - Balances::total_issuance(), + pallet_balances::TotalIssuance::::get(), duration, ); assert!(payout > 0); @@ -674,7 +674,7 @@ pub(crate) fn current_total_payout_for_duration(duration: u64) -> Balance { pub(crate) fn maximum_payout_for_duration(duration: u64) -> Balance { let (payout, rest) = ::EraPayout::era_payout( Staking::eras_total_stake(active_era()), - Balances::total_issuance(), + pallet_balances::TotalIssuance::::get(), duration, ); payout + rest diff --git a/substrate/frame/staking/src/tests.rs b/substrate/frame/staking/src/tests.rs index 0b6aad4a1b08..ab2c00ca9ccc 100644 --- a/substrate/frame/staking/src/tests.rs +++ b/substrate/frame/staking/src/tests.rs @@ -2069,7 +2069,7 @@ fn bond_with_no_staked_value() { ); // bonded with absolute minimum value possible. assert_ok!(Staking::bond(RuntimeOrigin::signed(1), 5, RewardDestination::Account(1))); - assert_eq!(Balances::locks(&1)[0].amount, 5); + assert_eq!(pallet_balances::Locks::::get(&1)[0].amount, 5); // unbonding even 1 will cause all to be unbonded. assert_ok!(Staking::unbond(RuntimeOrigin::signed(1), 1)); @@ -2090,14 +2090,14 @@ fn bond_with_no_staked_value() { // not yet removed. assert_ok!(Staking::withdraw_unbonded(RuntimeOrigin::signed(1), 0)); assert!(Staking::ledger(1.into()).is_ok()); - assert_eq!(Balances::locks(&1)[0].amount, 5); + assert_eq!(pallet_balances::Locks::::get(&1)[0].amount, 5); mock::start_active_era(3); // poof. Account 1 is removed from the staking system. assert_ok!(Staking::withdraw_unbonded(RuntimeOrigin::signed(1), 0)); assert!(Staking::ledger(1.into()).is_err()); - assert_eq!(Balances::locks(&1).len(), 0); + assert_eq!(pallet_balances::Locks::::get(&1).len(), 0); }); } @@ -3954,7 +3954,7 @@ fn test_multi_page_payout_stakers_by_page() { assert_eq!(actual_exposure_1.own(), 0); assert_eq!(actual_exposure_1.others().len(), 100 - 64); - let pre_payout_total_issuance = Balances::total_issuance(); + let pre_payout_total_issuance = pallet_balances::TotalIssuance::::get(); RewardOnUnbalanceWasCalled::set(false); System::reset_events(); @@ -3975,8 +3975,8 @@ fn test_multi_page_payout_stakers_by_page() { let controller_balance_after_p0_payout = Balances::free_balance(&11); // verify rewards have been paid out but still some left - assert!(Balances::total_issuance() > pre_payout_total_issuance); - assert!(Balances::total_issuance() < pre_payout_total_issuance + payout); + assert!(pallet_balances::TotalIssuance::::get() > pre_payout_total_issuance); + assert!(pallet_balances::TotalIssuance::::get() < pre_payout_total_issuance + payout); // verify the validator has been rewarded assert!(controller_balance_after_p0_payout > controller_balance_before_p0_payout); @@ -3999,7 +3999,11 @@ fn test_multi_page_payout_stakers_by_page() { assert_eq!(Balances::free_balance(&11), controller_balance_after_p0_payout); // verify all rewards have been paid out - assert_eq_error_rate!(Balances::total_issuance(), pre_payout_total_issuance + payout, 2); + assert_eq_error_rate!( + pallet_balances::TotalIssuance::::get(), + pre_payout_total_issuance + payout, + 2 + ); assert!(RewardOnUnbalanceWasCalled::get()); // Top 64 nominators of validator 11 automatically paid out, including the validator @@ -4039,13 +4043,13 @@ fn test_multi_page_payout_stakers_by_page() { // compute and ensure the reward amount is greater than zero. let payout = current_total_payout_for_duration(reward_time_per_era()); - let pre_payout_total_issuance = Balances::total_issuance(); + let pre_payout_total_issuance = pallet_balances::TotalIssuance::::get(); mock::start_active_era(i); RewardOnUnbalanceWasCalled::set(false); mock::make_all_reward_payment(i - 1); assert_eq_error_rate!( - Balances::total_issuance(), + pallet_balances::TotalIssuance::::get(), pre_payout_total_issuance + payout, 2 ); @@ -4171,7 +4175,7 @@ fn test_multi_page_payout_stakers_backward_compatible() { assert_eq!(actual_exposure_1.own(), 0); assert_eq!(actual_exposure_1.others().len(), 100 - 64); - let pre_payout_total_issuance = Balances::total_issuance(); + let pre_payout_total_issuance = pallet_balances::TotalIssuance::::get(); RewardOnUnbalanceWasCalled::set(false); let controller_balance_before_p0_payout = Balances::free_balance(&11); @@ -4186,8 +4190,8 @@ fn test_multi_page_payout_stakers_backward_compatible() { let controller_balance_after_p0_payout = Balances::free_balance(&11); // verify rewards have been paid out but still some left - assert!(Balances::total_issuance() > pre_payout_total_issuance); - assert!(Balances::total_issuance() < pre_payout_total_issuance + payout); + assert!(pallet_balances::TotalIssuance::::get() > pre_payout_total_issuance); + assert!(pallet_balances::TotalIssuance::::get() < pre_payout_total_issuance + payout); // verify the validator has been rewarded assert!(controller_balance_after_p0_payout > controller_balance_before_p0_payout); @@ -4205,7 +4209,11 @@ fn test_multi_page_payout_stakers_backward_compatible() { assert_eq!(Balances::free_balance(&11), controller_balance_after_p0_payout); // verify all rewards have been paid out - assert_eq_error_rate!(Balances::total_issuance(), pre_payout_total_issuance + payout, 2); + assert_eq_error_rate!( + pallet_balances::TotalIssuance::::get(), + pre_payout_total_issuance + payout, + 2 + ); assert!(RewardOnUnbalanceWasCalled::get()); // verify all nominators of validator 11 are paid out, including the validator @@ -4246,13 +4254,13 @@ fn test_multi_page_payout_stakers_backward_compatible() { // compute and ensure the reward amount is greater than zero. let payout = current_total_payout_for_duration(reward_time_per_era()); - let pre_payout_total_issuance = Balances::total_issuance(); + let pre_payout_total_issuance = pallet_balances::TotalIssuance::::get(); mock::start_active_era(i); RewardOnUnbalanceWasCalled::set(false); mock::make_all_reward_payment(i - 1); assert_eq_error_rate!( - Balances::total_issuance(), + pallet_balances::TotalIssuance::::get(), pre_payout_total_issuance + payout, 2 ); diff --git a/substrate/frame/treasury/src/tests.rs b/substrate/frame/treasury/src/tests.rs index 97b735928192..f38a06f1fdf4 100644 --- a/substrate/frame/treasury/src/tests.rs +++ b/substrate/frame/treasury/src/tests.rs @@ -296,13 +296,13 @@ fn accepted_spend_proposal_ignored_outside_spend_period() { #[test] fn unused_pot_should_diminish() { ExtBuilder::default().build().execute_with(|| { - let init_total_issuance = Balances::total_issuance(); + let init_total_issuance = pallet_balances::TotalIssuance::::get(); Balances::make_free_balance_be(&Treasury::account_id(), 101); - assert_eq!(Balances::total_issuance(), init_total_issuance + 100); + assert_eq!(pallet_balances::TotalIssuance::::get(), init_total_issuance + 100); >::on_initialize(2); assert_eq!(Treasury::pot(), 50); - assert_eq!(Balances::total_issuance(), init_total_issuance + 50); + assert_eq!(pallet_balances::TotalIssuance::::get(), init_total_issuance + 50); }); }