Skip to content
Snippets Groups Projects
Unverified Commit 868b0fd4 authored by wangjj9219's avatar wangjj9219 Committed by GitHub
Browse files

fix check when allow death (#559)

parent 1095b9c0
No related branches found
No related tags found
No related merge requests found
......@@ -597,7 +597,7 @@ impl<T: Config> Pallet<T> {
Self::ensure_can_withdraw(currency_id, from, amount)?;
let allow_death = existence_requirement == ExistenceRequirement::AllowDeath;
let allow_death = allow_death && !frame_system::Pallet::<T>::is_provider_required(from);
let allow_death = allow_death && frame_system::Pallet::<T>::can_dec_provider(from);
// if from_account does not allow death and non_zero total is below existential
// deposit, would return an error.
ensure!(allow_death || from_account.total() >= ed, Error::<T>::KeepAlive);
......@@ -1285,7 +1285,7 @@ where
let ed = T::ExistentialDeposits::get(&currency_id);
let allow_death = liveness == ExistenceRequirement::AllowDeath;
let allow_death = allow_death && !frame_system::Pallet::<T>::is_provider_required(who);
let allow_death = allow_death && frame_system::Pallet::<T>::can_dec_provider(who);
ensure!(allow_death || account.total() >= ed, Error::<T>::KeepAlive);
Ok(())
......
......@@ -340,6 +340,26 @@ fn transfer_all_should_work() {
});
}
#[test]
fn transfer_failed_when_allow_death_but_cannot_dec_provider() {
ExtBuilder::default()
.one_hundred_for_alice_n_bob()
.build()
.execute_with(|| {
assert_eq!(System::can_dec_provider(&ALICE), true);
assert_ok!(System::inc_consumers(&ALICE));
assert_eq!(System::can_dec_provider(&ALICE), false);
assert_noop!(
Tokens::transfer(Some(ALICE).into(), BOB, DOT, 100),
Error::<Runtime>::KeepAlive
);
assert_ok!(Tokens::deposit(BTC, &ALICE, 100));
assert_eq!(System::can_dec_provider(&ALICE), true);
assert_ok!(Tokens::transfer(Some(ALICE).into(), BOB, DOT, 100));
});
}
#[test]
fn deposit_should_work() {
ExtBuilder::default()
......@@ -593,6 +613,34 @@ fn currency_adapter_ensure_currency_adapter_should_work() {
});
}
#[test]
fn currency_adapter_withdraw_failed_when_allow_death_but_cannot_dec_provider() {
ExtBuilder::default()
.one_hundred_for_alice_n_bob()
.build()
.execute_with(|| {
assert_eq!(System::can_dec_provider(&ALICE), true);
assert_ok!(System::inc_consumers(&ALICE));
assert_eq!(System::can_dec_provider(&ALICE), false);
assert!(TreasuryCurrencyAdapter::withdraw(
&ALICE,
100,
WithdrawReasons::TRANSFER,
ExistenceRequirement::AllowDeath
)
.is_err());
assert_ok!(Tokens::deposit(BTC, &ALICE, 100));
assert_eq!(System::can_dec_provider(&ALICE), true);
assert!(TreasuryCurrencyAdapter::withdraw(
&ALICE,
100,
WithdrawReasons::TRANSFER,
ExistenceRequirement::AllowDeath
)
.is_ok());
});
}
#[test]
fn currency_adapter_burn_must_work() {
ExtBuilder::default()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment