The following test can be used in the test suite of pallet-balances:
#[test]
fn reap_fails_but_account_gets_dusted() {
ExtBuilder::default()
.existential_deposit(2)
.monied(true)
.build()
.execute_with(|| {
assert_eq!(System::inc_providers(&1), frame_system::IncRefStatus::Existed);
assert_eq!(System::providers(&1), 2);
assert_eq!(Balances::free_balance(1), 20);
assert_ok!(<Balances as Currency<_>>::transfer(&1, &2, 19, AllowDeath));
assert!(System::account_exists(&1));
assert_eq!(Balances::free_balance(1), 0);
assert_eq!(System::providers(&1), 1);
});
}
What we see here is that the account is not reaped in the sense that it still exists, but it does get dusted. This seems to contradict info I got on GitHub, but maybe I'm just reading this wrong (https://github.com/paritytech/polkadot-sdk/issues/227). The docs also say that reference counters prevent the account from being reaped. So I'm starting to get the impression that reaping and dusting are two completely separate processes.
The questions are:
- Is the behavior above expected or is this a bug?
- Are reaping and dusting separate processes?
- How can I whitelist an account in pallet-balances to prevent it from getting dusted?
Edit. I may have misread some of the docs. So apparently we can use consumers to make the transfer error. Doesn't answer any of the questions though.
assert_eq!(Balances::free_balance(1), 0);
According to the claim on GitHub, this should fail.