Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
73 changes: 73 additions & 0 deletions frame/assets/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,76 @@ fn imbalances_should_work() {
assert_eq!(Assets::total_supply(0), 30);
});
}
#[test]
fn force_metadata_should_work() {
new_test_ext().execute_with(|| {
//force set metadata works
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
assert_ok!(Assets::force_set_metadata(Origin::root(), 0, vec![0u8; 10], vec![0u8; 10], 8, false));
assert!(Metadata::<Test>::contains_key(0));

//overwrites existing metadata
let asset_original_metadata = Metadata::<Test>::get(0);
assert_ok!(Assets::force_set_metadata(Origin::root(), 0, vec![1u8; 10], vec![1u8; 10], 8, false));
assert_ne!(Metadata::<Test>::get(0), asset_original_metadata);

//attempt to set metadata for non-existent asset class
assert_noop!(
Assets::force_set_metadata(Origin::root(), 1, vec![0u8; 10], vec![0u8; 10], 8, false),
Error::<Test>::Unknown
);

//string length limit check
let limit = StringLimit::get() as usize;
assert_noop!(
Assets::force_set_metadata(Origin::root(), 0, vec![0u8; limit + 1], vec![0u8; 10], 8, false),
Error::<Test>::BadMetadata
);
assert_noop!(
Assets::force_set_metadata(Origin::root(), 0, vec![0u8; 10], vec![0u8; limit + 1], 8, false),
Error::<Test>::BadMetadata
);

//force clear metadata works
assert!(Metadata::<Test>::contains_key(0));
assert_ok!(Assets::force_clear_metadata(Origin::root(), 0));
assert!(!Metadata::<Test>::contains_key(0));

//Error handles clearing non-existent asset class
assert_noop!(Assets::force_clear_metadata(Origin::root(), 1), Error::<Test>::Unknown);

});
}

#[test]
fn force_asset_status_should_work(){
new_test_ext().execute_with(|| {
Balances::make_free_balance_be(&1, 10);
assert_ok!(Assets::create(Origin::signed(1), 0, 1, 30));
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));

//force asset status to change min_balance > balance
assert_ok!(Assets::force_asset_status(Origin::root(), 0, 1, 1, 1, 1, 101, true, false));
assert_eq!(Assets::balance(0, 1), 100);
//asset in practice becomes frozen until balance >= min_balance
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows for accounts to have less than min balance, not sure if that is problematic or not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when you transfer 1 asset to this user. Will they accept the 1 asset or will it kill the account?

assert_noop!(
Assets::transfer(Origin::signed(1), 0, 2, 50),
DispatchError::Token(TokenError::BelowMinimum)
);

//force asset status will not execute for non-existent class
assert_noop!(
Assets::force_asset_status(Origin::root(), 1, 1, 1, 1, 1, 90, true, false),
Error::<Test>::Unknown
);

//account drains to completion when funds dip below min_balance
assert_ok!(Assets::force_asset_status(Origin::root(), 0, 1, 1, 1, 1, 90, true, false));
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
assert_eq!(Assets::balance(0, 1), 0);
assert_eq!(Assets::balance(0, 2), 100);
assert_eq!(Assets::total_supply(0), 100);
});

}