Skip to content

Commit

Permalink
test: aadd native_fungible_transfer_works()
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Jul 31, 2024
1 parent 2e9b73e commit 52f37fb
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pallets/api/src/fungibles/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use frame_support::{
const ASSET: u32 = 42;

#[test]
fn transfer_works() {
fn fungible_transfer_works() {
new_test_ext().execute_with(|| {
let amount: Balance = 100 * UNIT;
create_asset_and_mint_to(ALICE, ASSET, ALICE, amount);
Expand All @@ -27,6 +27,18 @@ fn transfer_works() {
});
}

#[test]
fn native_fungible_transfer_works() {
new_test_ext().execute_with(|| {
let amount: Balance = 100 * UNIT;
set_native_balance(ALICE, amount);
let balance_before_transfer = Balances::free_balance(&BOB);
assert_ok!(Fungibles::transfer(signed(ALICE), NativeOrWithId::Native, BOB, amount / 2));
let balance_after_transfer = Balances::free_balance(&BOB);
assert_eq!(balance_after_transfer, balance_before_transfer + amount / 2);
});
}

#[test]
fn transfer_from_works() {
new_test_ext().execute_with(|| {
Expand Down Expand Up @@ -219,6 +231,10 @@ fn mint_asset(owner: AccountId, asset_id: AssetId, to: AccountId, value: Balance
assert_ok!(Assets::mint(signed(owner), asset_id, to, value));
}

fn set_native_balance(to: AccountId, value: Balance) {
assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), to, value));
}

fn create_asset_and_mint_to(owner: AccountId, asset_id: AssetId, to: AccountId, value: Balance) {
create_asset(owner, asset_id, 1);
mint_asset(owner, asset_id, to, value)
Expand Down

0 comments on commit 52f37fb

Please sign in to comment.