This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
tests for assets pallet #8487
Merged
Merged
tests for assets pallet #8487
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eb66ddf
tests for assets
ferrell-code 9e75595
Update frame/assets/src/tests.rs
ferrell-code 02b5803
Update frame/assets/src/tests.rs
ferrell-code 90fecf5
add force asset status check
ferrell-code d46df60
remove TODO
ferrell-code ae8e12b
actually remove TODO
ferrell-code af352e9
add force asset status tests
ferrell-code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
||
| 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); | ||
| }); | ||
|
|
||
ferrell-code marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.