Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NTFs] Emit CollectionMaxSupplySet on collection create #2626

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 5 additions & 0 deletions substrate/frame/nfts/src/features/create_delete_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {

CollectionConfigOf::<T, I>::insert(&collection, config);
CollectionAccount::<T, I>::insert(&owner, &collection, ());

if let Some(max_supply) = config.max_supply {
Self::deposit_event(Event::CollectionMaxSupplySet { collection, max_supply });
jsidorenko marked this conversation as resolved.
Show resolved Hide resolved
}

Self::deposit_event(event);
Ok(())
}
Expand Down
28 changes: 27 additions & 1 deletion substrate/frame/nfts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,10 @@ fn max_supply_should_work() {
default_collection_config()
));
assert_eq!(CollectionConfigOf::<Test>::get(collection_id).unwrap().max_supply, None);
assert!(!events().contains(&Event::<Test>::CollectionMaxSupplySet {
collection: collection_id,
max_supply,
}));

assert_ok!(Nfts::set_collection_max_supply(
RuntimeOrigin::signed(user_id.clone()),
Expand Down Expand Up @@ -2242,9 +2246,31 @@ fn max_supply_should_work() {
None
));
assert_noop!(
Nfts::mint(RuntimeOrigin::signed(user_id.clone()), collection_id, 2, user_id, None),
Nfts::mint(
RuntimeOrigin::signed(user_id.clone()),
collection_id,
2,
user_id.clone(),
None
),
Error::<Test>::MaxSupplyReached
);

// validate the event gets emitted when we set the max supply on collection create
let collection_id = 1;
assert_ok!(Nfts::force_create(
RuntimeOrigin::root(),
user_id.clone(),
CollectionConfig { max_supply: Some(max_supply), ..default_collection_config() }
));
assert_eq!(
CollectionConfigOf::<Test>::get(collection_id).unwrap().max_supply,
Some(max_supply)
);
assert!(events().contains(&Event::<Test>::CollectionMaxSupplySet {
collection: collection_id,
max_supply,
}));
});
}

Expand Down
Loading