diff --git a/frame/assets/src/impl_fungibles.rs b/frame/assets/src/impl_fungibles.rs index 7bec884f4c56b..893d74b6aa306 100644 --- a/frame/assets/src/impl_fungibles.rs +++ b/frame/assets/src/impl_fungibles.rs @@ -81,7 +81,38 @@ impl, I: 'static> fungibles::Inspect<::AccountId } } -impl, I: 'static> fungibles::Mutate<::AccountId> for Pallet {} +impl, I: 'static> fungibles::Mutate<::AccountId> for Pallet { + fn done_mint_into( + asset_id: Self::AssetId, + beneficiary: &::AccountId, + amount: Self::Balance, + ) { + Self::deposit_event(Event::Issued { asset_id, owner: beneficiary.clone(), amount }) + } + + fn done_burn_from( + asset_id: Self::AssetId, + target: &::AccountId, + balance: Self::Balance, + ) { + Self::deposit_event(Event::Burned { asset_id, owner: target.clone(), balance }); + } + + fn done_transfer( + asset_id: Self::AssetId, + source: &::AccountId, + dest: &::AccountId, + amount: Self::Balance, + ) { + Self::deposit_event(Event::Transferred { + asset_id, + from: source.clone(), + to: dest.clone(), + amount, + }); + } +} + impl, I: 'static> fungibles::Balanced<::AccountId> for Pallet { diff --git a/frame/assets/src/tests.rs b/frame/assets/src/tests.rs index 88ba92d0685a9..4dacfac41cb6b 100644 --- a/frame/assets/src/tests.rs +++ b/frame/assets/src/tests.rs @@ -46,9 +46,18 @@ fn transfer_should_never_burn() { while System::inc_consumers(&2).is_ok() {} let _ = System::dec_consumers(&2); + let _ = System::dec_consumers(&2); // Exactly one consumer ref remaining. + assert_eq!(System::consumers(&2), 1); let _ = >::transfer(0, &1, &2, 50, Protect); + System::assert_has_event(RuntimeEvent::Assets(crate::Event::Transferred { + asset_id: 0, + from: 1, + to: 2, + amount: 50, + })); + assert_eq!(Assets::balance(0, 1), 50); assert_eq!(Assets::balance(0, 1) + Assets::balance(0, 2), 100); }); } @@ -59,11 +68,26 @@ fn basic_minting_should_work() { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); assert_ok!(Assets::force_create(RuntimeOrigin::root(), 1, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); + System::assert_last_event(RuntimeEvent::Assets(crate::Event::Issued { + asset_id: 0, + owner: 1, + amount: 100, + })); assert_eq!(Assets::balance(0, 1), 100); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 2, 100)); + System::assert_last_event(RuntimeEvent::Assets(crate::Event::Issued { + asset_id: 0, + owner: 2, + amount: 100, + })); assert_eq!(Assets::balance(0, 2), 100); assert_eq!(asset_ids(), vec![0, 1, 999]); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 1, 1, 100)); + System::assert_last_event(RuntimeEvent::Assets(crate::Event::Issued { + asset_id: 1, + owner: 1, + amount: 100, + })); assert_eq!(Assets::account_balances(1), vec![(0, 100), (999, 100), (1, 100)]); }); } @@ -786,6 +810,11 @@ fn burning_asset_balance_with_positive_balance_should_work() { assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); assert_eq!(Assets::balance(0, 1), 100); assert_ok!(Assets::burn(RuntimeOrigin::signed(1), 0, 1, u64::MAX)); + System::assert_last_event(RuntimeEvent::Assets(crate::Event::Burned { + asset_id: 0, + owner: 1, + balance: 100, + })); assert_eq!(Assets::balance(0, 1), 0); }); }