mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 06:31:03 +00:00
Better Handle Dead Accounts in Balances (#7843)
* Don't mutate storage when account is dead and should stay dead * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * more concrete storage noop Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
This commit is contained in:
@@ -40,7 +40,7 @@ macro_rules! decl_tests {
|
||||
use crate::*;
|
||||
use sp_runtime::{FixedPointNumber, traits::{SignedExtension, BadOrigin}};
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok, assert_err,
|
||||
assert_noop, assert_storage_noop, assert_ok, assert_err,
|
||||
traits::{
|
||||
LockableCurrency, LockIdentifier, WithdrawReasons,
|
||||
Currency, ReservableCurrency, ExistenceRequirement::AllowDeath, StoredMap
|
||||
@@ -796,5 +796,28 @@ macro_rules! decl_tests {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn operations_on_dead_account_should_not_change_state() {
|
||||
// These functions all use `mutate_account` which may introduce a storage change when
|
||||
// the account never existed to begin with, and shouldn't exist in the end.
|
||||
<$ext_builder>::default()
|
||||
.existential_deposit(0)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
assert!(!<Test as Config>::AccountStore::is_explicit(&1337));
|
||||
|
||||
// Unreserve
|
||||
assert_storage_noop!(assert_eq!(Balances::unreserve(&1337, 42), 42));
|
||||
// Reserve
|
||||
assert_noop!(Balances::reserve(&1337, 42), Error::<Test, _>::InsufficientBalance);
|
||||
// Slash Reserve
|
||||
assert_storage_noop!(assert_eq!(Balances::slash_reserved(&1337, 42).1, 42));
|
||||
// Repatriate Reserve
|
||||
assert_noop!(Balances::repatriate_reserved(&1337, &1338, 42, Status::Free), Error::<Test, _>::DeadAccount);
|
||||
// Slash
|
||||
assert_storage_noop!(assert_eq!(Balances::slash(&1337, 42).1, 42));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user