From 1bdfb29587800a00aad62acb7222b77b6c2701e7 Mon Sep 17 00:00:00 2001
From: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>
Date: Fri, 8 Dec 2023 12:26:13 +0200
Subject: [PATCH] [NTFs] Emit CollectionMaxSupplySet on collection create
 (#2626)

Closes #2293

if the max_supply is set during the collection creation, we emit the
`CollectionMaxSupplySet` event
---
 .../src/features/create_delete_collection.rs  |  6 ++++
 substrate/frame/nfts/src/tests.rs             | 28 ++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/substrate/frame/nfts/src/features/create_delete_collection.rs b/substrate/frame/nfts/src/features/create_delete_collection.rs
index e343ad18e50..f03df7fdd4f 100644
--- a/substrate/frame/nfts/src/features/create_delete_collection.rs
+++ b/substrate/frame/nfts/src/features/create_delete_collection.rs
@@ -66,7 +66,13 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
 
 		CollectionConfigOf::<T, I>::insert(&collection, config);
 		CollectionAccount::<T, I>::insert(&owner, &collection, ());
+
 		Self::deposit_event(event);
+
+		if let Some(max_supply) = config.max_supply {
+			Self::deposit_event(Event::CollectionMaxSupplySet { collection, max_supply });
+		}
+
 		Ok(())
 	}
 
diff --git a/substrate/frame/nfts/src/tests.rs b/substrate/frame/nfts/src/tests.rs
index aeebf51b7c7..0c32aea2be0 100644
--- a/substrate/frame/nfts/src/tests.rs
+++ b/substrate/frame/nfts/src/tests.rs
@@ -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()),
@@ -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,
+		}));
 	});
 }
 
-- 
GitLab