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
Allow to set the max supply for collection #11441
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -17,8 +17,7 @@ | |
|
|
||
| //! Tests for Uniques pallet. | ||
|
|
||
| use super::*; | ||
| use crate::mock::*; | ||
| use crate::{mock::*, Event, *}; | ||
| use frame_support::{assert_noop, assert_ok, traits::Currency}; | ||
| use pallet_balances::Error as BalancesError; | ||
| use sp_std::prelude::*; | ||
|
|
@@ -71,6 +70,18 @@ fn attributes(collection: u32) -> Vec<(Option<u32>, Vec<u8>, Vec<u8>)> { | |
| s | ||
| } | ||
|
|
||
| fn events() -> Vec<Event<Test>> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I keep seeing this pattern in every pallet 🙈
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to have a more advanced function to test the events, for example, to check that some event is within the array, but has different params. That would help to understand whether the params are wrong or the event wasn't emitted
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do it. 👍 |
||
| let result = System::events() | ||
| .into_iter() | ||
| .map(|r| r.event) | ||
| .filter_map(|e| if let mock::Event::Uniques(inner) = e { Some(inner) } else { None }) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| System::reset_events(); | ||
|
|
||
| result | ||
| } | ||
|
|
||
| #[test] | ||
| fn basic_setup_works() { | ||
| new_test_ext().execute_with(|| { | ||
|
|
@@ -633,3 +644,45 @@ fn cancel_approval_works_with_force() { | |
| ); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn max_supply_should_work() { | ||
| new_test_ext().execute_with(|| { | ||
| let collection_id = 0; | ||
| let user_id = 1; | ||
| let max_supply = 2; | ||
|
|
||
| // validate set_collection_max_supply | ||
| assert_ok!(Uniques::force_create(Origin::root(), collection_id, user_id, true)); | ||
| assert!(!CollectionMaxSupply::<Test>::contains_key(collection_id)); | ||
|
|
||
| assert_ok!(Uniques::set_collection_max_supply( | ||
| Origin::signed(user_id), | ||
| collection_id, | ||
| max_supply | ||
| )); | ||
| assert_eq!(CollectionMaxSupply::<Test>::get(collection_id).unwrap(), max_supply); | ||
|
|
||
| assert!(events().contains(&Event::<Test>::CollectionMaxSupplySet { | ||
ggwpez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| collection: collection_id, | ||
| max_supply, | ||
| })); | ||
|
|
||
| assert_noop!( | ||
| Uniques::set_collection_max_supply( | ||
| Origin::signed(user_id), | ||
| collection_id, | ||
| max_supply + 1 | ||
| ), | ||
| Error::<Test>::MaxSupplyAlreadySet | ||
| ); | ||
|
|
||
| // validate we can't mint more to max supply | ||
| assert_ok!(Uniques::mint(Origin::signed(user_id), collection_id, 0, user_id)); | ||
| assert_ok!(Uniques::mint(Origin::signed(user_id), collection_id, 1, user_id)); | ||
| assert_noop!( | ||
| Uniques::mint(Origin::signed(user_id), collection_id, 2, user_id), | ||
| Error::<Test>::MaxSupplyReached | ||
| ); | ||
| }); | ||
| } | ||
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.