diff --git a/substrate/frame/balances/src/lib.rs b/substrate/frame/balances/src/lib.rs index e0f4e1003b..c955d917a6 100644 --- a/substrate/frame/balances/src/lib.rs +++ b/substrate/frame/balances/src/lib.rs @@ -1484,7 +1484,7 @@ where // may not even be a provider. let allow_death = existence_requirement == ExistenceRequirement::AllowDeath; let allow_death = - allow_death && !system::Pallet::::is_provider_required(transactor); + allow_death && system::Pallet::::can_dec_provider(transactor); ensure!( allow_death || from_account.total() >= ed, Error::::KeepAlive diff --git a/substrate/frame/balances/src/tests.rs b/substrate/frame/balances/src/tests.rs index 624c2de618..fd57371b3a 100644 --- a/substrate/frame/balances/src/tests.rs +++ b/substrate/frame/balances/src/tests.rs @@ -76,6 +76,30 @@ macro_rules! decl_tests { }); } + #[test] + fn reap_failed_due_to_provider_and_consumer() { + <$ext_builder>::default().existential_deposit(1).monied(true).build().execute_with(|| { + // SCENARIO: only one provider and there are remaining consumers. + assert_ok!(System::inc_consumers(&1)); + assert!(!System::can_dec_provider(&1)); + assert_noop!( + >::transfer(&1, &2, 10, AllowDeath), + Error::<$test, _>::KeepAlive + ); + assert!(System::account_exists(&1)); + assert_eq!(Balances::free_balance(1), 10); + + // SCENARIO: more than one provider, but will not kill account due to other provider. + assert_eq!(System::inc_providers(&1), frame_system::IncRefStatus::Existed); + assert_eq!(System::providers(&1), 2); + assert!(System::can_dec_provider(&1)); + assert_ok!(>::transfer(&1, &2, 10, AllowDeath)); + assert_eq!(System::providers(&1), 1); + assert!(System::account_exists(&1)); + assert_eq!(Balances::free_balance(1), 0); + }); + } + #[test] fn partial_locking_should_work() { <$ext_builder>::default().existential_deposit(1).monied(true).build().execute_with(|| {