git.delta.rocks / unique-network / refs/commits / 1868485f67ea

difftreelog

Merge branch 'develop' into feature/NFTPAR-196_sponsor_setVariableMetadata

Yaroslav Bolyukin2021-03-16parents: #73e422c #07649f2.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
995995
996 let target_collection = Self::get_collection(collection_id)?;996 let target_collection = Self::get_collection(collection_id)?;
997997
998 Self::can_create_items_in_collection(&target_collection, &sender, &owner)?;998 Self::can_create_items_in_collection(&target_collection, &sender, &owner, 1)?;
999 Self::validate_create_item_args(&target_collection, &data)?;999 Self::validate_create_item_args(&target_collection, &data)?;
1000 Self::create_item_no_validation(&target_collection, owner, data)?;1000 Self::create_item_no_validation(&target_collection, owner, data)?;
10011001
10301030
1031 let target_collection = Self::get_collection(collection_id)?;1031 let target_collection = Self::get_collection(collection_id)?;
10321032
1033 Self::can_create_items_in_collection(&target_collection, &sender, &owner)?;1033 Self::can_create_items_in_collection(&target_collection, &sender, &owner, items_data.len() as u32)?;
10341034
1035 for data in &items_data {1035 for data in &items_data {
1036 Self::validate_create_item_args(&target_collection, data)?;1036 Self::validate_create_item_args(&target_collection, data)?;
1664 Ok(())1664 Ok(())
1665 }1665 }
16661666
1667 fn can_create_items_in_collection(collection: &CollectionHandle<T>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {1667 fn can_create_items_in_collection(collection: &CollectionHandle<T>, sender: &T::AccountId, owner: &T::AccountId, amount: u32) -> DispatchResult {
1668 let collection_id = collection.id;1668 let collection_id = collection.id;
16691669
1670 // check token limit and account token limit1670 // check token limit and account token limit
1671 let total_items: u32 = ItemListIndex::get(collection_id);1671 let total_items: u32 = ItemListIndex::get(collection_id)
1672 .checked_add(amount)
1673 .ok_or(Error::<T>::CollectionTokenLimitExceeded)?;
1672 let account_items: u32 = <AddressTokens<T>>::get(collection_id, owner).len() as u32;1674 let account_items: u32 = (<AddressTokens<T>>::get(collection_id, owner).len() as u32)
1675 .checked_add(amount)
1676 .ok_or(Error::<T>::AccountTokenLimitExceeded)?;
1673 ensure!(collection.limits.token_limit > total_items, Error::<T>::CollectionTokenLimitExceeded);1677 ensure!(collection.limits.token_limit >= total_items, Error::<T>::CollectionTokenLimitExceeded);
1674 ensure!(collection.limits.account_token_ownership_limit > account_items, Error::<T>::AccountTokenLimitExceeded);1678 ensure!(collection.limits.account_token_ownership_limit >= account_items, Error::<T>::AccountTokenLimitExceeded);
16751679
1676 if !Self::is_owner_or_admin_permissions(collection, sender.clone()) {1680 if !Self::is_owner_or_admin_permissions(collection, sender.clone()) {
1677 ensure!(collection.mint_mode == true, Error::<T>::PublicMintingNotAllowed);1681 ensure!(collection.mint_mode == true, Error::<T>::PublicMintingNotAllowed);
modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -11,7 +11,9 @@
 import {
   createCollectionExpectSuccess,
   destroyCollectionExpectSuccess,
+  getGenericResult,
   IReFungibleTokenDataType,
+  setCollectionLimitsExpectSuccess,
 } from './util/helpers';
 
 chai.use(chaiAsPromised);
@@ -92,6 +94,25 @@
       expect(token3Data.VariableData.toString()).to.be.equal('0x33');
     });
   });
+
+  it('Can mint amount of items equals to collection limits', async () => {
+    await usingApi(async (api) => {
+      const alice = privateKey('//Alice');
+
+      const collectionId = await createCollectionExpectSuccess();
+      await setCollectionLimitsExpectSuccess(alice, collectionId, {
+        TokenLimit: 2,
+      });
+      const args = [
+        { nft: ['A', 'A'] },
+        { nft: ['B', 'B'] },
+      ];
+      const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, alice.address, args);
+      const events = await submitTransactionAsync(alice, createMultipleItemsTx);
+      const result = getGenericResult(events);
+      expect(result.success).to.be.true;
+    });
+  });
 });
 
 describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
@@ -175,4 +196,21 @@
       await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
     });
   });
+
+  it('Fails when minting tokens exceeds collectionLimits amount', async () => {
+    await usingApi(async (api) => {
+      const alice = privateKey('//Alice');
+
+      const collectionId = await createCollectionExpectSuccess();
+      await setCollectionLimitsExpectSuccess(alice, collectionId, {
+        TokenLimit: 1,
+      });
+      const args = [
+        { nft: ['A', 'A'] },
+        { nft: ['B', 'B'] },
+      ];
+      const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, alice.address, args);
+      await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
+    });
+  });
 });