Skip to content

add tests for tokens #579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,16 @@ pub mod module {
type WeightInfo: WeightInfo;

/// The minimum amount required to keep an account.
/// It's deprecated to config 0 as ED for any currency_id,
/// zero ED will retain account even if its total is zero.
/// Since accounts of orml_tokens are also used as providers of
/// System::AccountInfo, zero ED may cause some problems.
type ExistentialDeposits: GetByKey<Self::CurrencyId, Self::Balance>;

/// Handler to burn or transfer account's dust
type OnDust: OnDust<Self::AccountId, Self::CurrencyId, Self::Balance>;

#[pallet::constant]
type MaxLocks: Get<u32>;

// The whitelist of accounts that will not be reaped even if its total
Expand Down
49 changes: 49 additions & 0 deletions tokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,55 @@ fn remove_account_work() {
});
}

#[test]
fn reap_account_will_dec_providers_work() {
ExtBuilder::default()
.balances(vec![(ALICE, DOT, 100), (ALICE, ETH, 100), (ALICE, BTC, 100)])
.build()
.execute_with(|| {
assert_eq!(System::providers(&ALICE), 3);
assert_eq!(System::account_exists(&ALICE), true);
assert_eq!(Accounts::<Runtime>::contains_key(ALICE, DOT), true);

assert_ok!(Tokens::do_transfer(
DOT,
&ALICE,
&BOB,
100,
ExistenceRequirement::AllowDeath
));
assert_eq!(System::providers(&ALICE), 2);
assert_eq!(System::account_exists(&ALICE), true);
assert_eq!(Accounts::<Runtime>::contains_key(ALICE, DOT), false);

// ED of ETH is zero, the account will retain even if the total is zero,
// will not dec_providers
assert_eq!(Accounts::<Runtime>::contains_key(ALICE, ETH), true);
assert_ok!(Tokens::do_transfer(
ETH,
&ALICE,
&BOB,
100,
ExistenceRequirement::AllowDeath
));
assert_eq!(System::providers(&ALICE), 2);
assert_eq!(System::account_exists(&ALICE), true);
assert_eq!(Accounts::<Runtime>::contains_key(ALICE, ETH), true);

assert_eq!(Accounts::<Runtime>::contains_key(ALICE, BTC), true);
assert_ok!(Tokens::do_transfer(
BTC,
&ALICE,
&BOB,
100,
ExistenceRequirement::AllowDeath
));
assert_eq!(System::providers(&ALICE), 1);
assert_eq!(System::account_exists(&ALICE), true);
assert_eq!(Accounts::<Runtime>::contains_key(ALICE, BTC), false);
});
}

#[test]
fn dust_removal_work() {
ExtBuilder::default()
Expand Down