Add inspect trait for asset roles (#11738)

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
girazoki
2022-09-13 02:12:09 +02:00
committed by GitHub
parent 0c8ad7a6cc
commit b74e584e02
4 changed files with 72 additions and 0 deletions
@@ -263,3 +263,23 @@ impl<T: Config<I>, I: 'static> fungibles::approvals::Mutate<<T as SystemConfig>:
Self::do_transfer_approved(asset, owner, delegate, dest, amount)
}
}
impl<T: Config<I>, I: 'static> fungibles::roles::Inspect<<T as SystemConfig>::AccountId>
for Pallet<T, I>
{
fn owner(asset: T::AssetId) -> Option<<T as SystemConfig>::AccountId> {
Asset::<T, I>::get(asset).map(|x| x.owner)
}
fn issuer(asset: T::AssetId) -> Option<<T as SystemConfig>::AccountId> {
Asset::<T, I>::get(asset).map(|x| x.issuer)
}
fn admin(asset: T::AssetId) -> Option<<T as SystemConfig>::AccountId> {
Asset::<T, I>::get(asset).map(|x| x.admin)
}
fn freezer(asset: T::AssetId) -> Option<<T as SystemConfig>::AccountId> {
Asset::<T, I>::get(asset).map(|x| x.freezer)
}
}
+22
View File
@@ -977,3 +977,25 @@ fn transfer_large_asset() {
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, amount - 1));
})
}
#[test]
fn querying_roles_should_work() {
new_test_ext().execute_with(|| {
use frame_support::traits::tokens::fungibles::roles::Inspect;
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
assert_ok!(Assets::set_team(
Origin::signed(1),
0,
// Issuer
2,
// Admin
3,
// Freezer
4,
));
assert_eq!(Assets::owner(0), Some(1));
assert_eq!(Assets::issuer(0), Some(2));
assert_eq!(Assets::admin(0), Some(3));
assert_eq!(Assets::freezer(0), Some(4));
});
}