mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 20:21:01 +00:00
[FRAME] Introduce force_adjust_total_issuance (#3001)
Add `Balances::force_adjust_total_issuance` as preparation for fixing https://github.com/polkadot-fellows/runtimes/issues/147. Important changes in `substrate/frame/balances/src/lib.rs`. TODO: - [x] Update weights --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: command-bot <> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
committed by
GitHub
parent
4220503d28
commit
5a6f6d33d3
@@ -18,9 +18,16 @@
|
||||
//! Tests regarding the functionality of the dispatchables/extrinsics.
|
||||
|
||||
use super::*;
|
||||
use frame_support::traits::tokens::Preservation::Expendable;
|
||||
use crate::{
|
||||
AdjustmentDirection::{Decrease as Dec, Increase as Inc},
|
||||
Event,
|
||||
};
|
||||
use frame_support::traits::{fungible::Unbalanced, tokens::Preservation::Expendable};
|
||||
use fungible::{hold::Mutate as HoldMutate, Inspect, Mutate};
|
||||
|
||||
/// Alice account ID for more readable tests.
|
||||
const ALICE: u64 = 1;
|
||||
|
||||
#[test]
|
||||
fn default_indexing_on_new_accounts_should_not_work2() {
|
||||
ExtBuilder::default()
|
||||
@@ -222,3 +229,109 @@ fn upgrade_accounts_should_work() {
|
||||
assert_eq!(System::consumers(&7), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[docify::export]
|
||||
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();
|
||||
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();
|
||||
assert_eq!(old_ti + 32, new_ti, "Should increase by 32");
|
||||
|
||||
// If Alice tries to call it, it errors:
|
||||
assert_noop!(
|
||||
Balances::force_adjust_total_issuance(RawOrigin::Signed(ALICE).into(), Inc, 32),
|
||||
BadOrigin,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
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();
|
||||
|
||||
// Increase works:
|
||||
assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Inc, 32));
|
||||
assert_eq!(Balances::total_issuance(), ti + 32);
|
||||
System::assert_last_event(RuntimeEvent::Balances(Event::TotalIssuanceForced {
|
||||
old: 64,
|
||||
new: 96,
|
||||
}));
|
||||
|
||||
// Decrease works:
|
||||
assert_ok!(Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Dec, 64));
|
||||
assert_eq!(Balances::total_issuance(), ti - 32);
|
||||
System::assert_last_event(RuntimeEvent::Balances(Event::TotalIssuanceForced {
|
||||
old: 96,
|
||||
new: 32,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
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 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);
|
||||
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn force_adjust_total_issuance_rejects_zero_delta() {
|
||||
ExtBuilder::default().build_and_execute_with(|| {
|
||||
assert_noop!(
|
||||
Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Inc, 0),
|
||||
Error::<Test>::DeltaZero,
|
||||
);
|
||||
assert_noop!(
|
||||
Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Dec, 0),
|
||||
Error::<Test>::DeltaZero,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn force_adjust_total_issuance_rejects_more_than_inactive() {
|
||||
ExtBuilder::default().build_and_execute_with(|| {
|
||||
assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), 1337, 64));
|
||||
Balances::deactivate(16u32.into());
|
||||
|
||||
assert_eq!(Balances::total_issuance(), 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!(Balances::active_issuance(), 0);
|
||||
// Errors with more than 48:
|
||||
assert_noop!(
|
||||
Balances::force_adjust_total_issuance(RawOrigin::Root.into(), Dec, 1),
|
||||
Error::<Test>::IssuanceDeactivated,
|
||||
);
|
||||
// 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!(Balances::active_issuance(), 10);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -126,8 +126,10 @@ impl pallet_transaction_payment::Config for Test {
|
||||
type FeeMultiplierUpdate = ();
|
||||
}
|
||||
|
||||
pub(crate) type Balance = u64;
|
||||
|
||||
impl Config for Test {
|
||||
type Balance = u64;
|
||||
type Balance = Balance;
|
||||
type DustRemoval = DustTrap;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
|
||||
Reference in New Issue
Block a user