Skip to content

Commit

Permalink
update asset_exists (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc authored Jan 5, 2023
1 parent 0e23446 commit 4f5a3f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 6 additions & 2 deletions tokens/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ where
}
}

fn asset_exists(_asset: Self::AssetId) -> bool {
false
fn asset_exists(asset: Self::AssetId) -> bool {
if TestKey::contains(&asset) {
true
} else {
B::asset_exists(asset)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions tokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,8 +1750,8 @@ impl<T: Config> fungibles::Inspect<T::AccountId> for Pallet<T> {
Self::withdraw_consequence(who, asset_id, amount, &Self::accounts(who, asset_id))
}

fn asset_exists(_asset: Self::AssetId) -> bool {
false
fn asset_exists(asset: Self::AssetId) -> bool {
TotalIssuance::<T>::contains_key(asset)
}
}

Expand Down
9 changes: 8 additions & 1 deletion tokens/src/tests_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ fn fungibles_inspect_trait_should_work() {
);
assert_ok!(<Tokens as fungibles::Inspect<_>>::can_deposit(DOT, &ALICE, 1, false).into_result());
assert_ok!(<Tokens as fungibles::Inspect<_>>::can_withdraw(DOT, &ALICE, 1).into_result());

assert!(<Tokens as fungibles::Inspect<_>>::asset_exists(DOT));
assert!(!<Tokens as fungibles::Inspect<_>>::asset_exists(BTC));
});
}

Expand Down Expand Up @@ -283,7 +286,7 @@ fn fungibles_inspect_convert_should_work() {
>;

ExtBuilder::default()
.balances(vec![(ALICE, DOT, 100), (BOB, DOT, 100)])
.balances(vec![(ALICE, DOT, 100), (BOB, DOT, 100), (BOB, BTC, 100)])
.build()
.execute_with(|| {
assert_eq!(
Expand All @@ -294,6 +297,10 @@ fn fungibles_inspect_convert_should_work() {
<RebaseTokens as fungibles::Inspect<AccountId>>::total_issuance(DOT),
20000
);

assert!(<Tokens as fungibles::Inspect<_>>::asset_exists(DOT));
assert!(<Tokens as fungibles::Inspect<_>>::asset_exists(BTC));
assert!(!<Tokens as fungibles::Inspect<_>>::asset_exists(ETH));
});
}

Expand Down

0 comments on commit 4f5a3f3

Please sign in to comment.