Allow SetBalance to handle error when trying to kill acount with reference counter. (#10826)

* bug found

* fix logic

* a little simpler

* add test
This commit is contained in:
Shawn Tabrizi
2022-02-10 12:08:05 +01:00
committed by GitHub
parent 13b7c3ccdf
commit 8d783038c8
2 changed files with 45 additions and 14 deletions
+24
View File
@@ -1239,5 +1239,29 @@ macro_rules! decl_tests {
assert_eq!(Balances::free_balance(&3), 25);
});
}
#[test]
fn set_balance_handles_killing_account() {
<$ext_builder>::default().build().execute_with(|| {
let _ = Balances::deposit_creating(&1, 111);
assert_ok!(frame_system::Pallet::<Test>::inc_consumers(&1));
assert_noop!(
Balances::set_balance(Origin::root(), 1, 0, 0),
DispatchError::ConsumerRemaining,
);
});
}
#[test]
fn set_balance_handles_total_issuance() {
<$ext_builder>::default().build().execute_with(|| {
let old_total_issuance = Balances::total_issuance();
assert_ok!(Balances::set_balance(Origin::root(), 1337, 69, 42));
assert_eq!(Balances::total_issuance(), old_total_issuance + 69 + 42);
assert_eq!(Balances::total_balance(&1337), 69 + 42);
assert_eq!(Balances::free_balance(&1337), 69);
assert_eq!(Balances::reserved_balance(&1337), 42);
});
}
}
}