difftreelog
Merge branch 'develop' into feature/NFTPAR-196_sponsor_setVariableMetadata
in: master
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth995995996 let target_collection = Self::get_collection(collection_id)?;996 let target_collection = Self::get_collection(collection_id)?;997997998 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)?;10011001103010301031 let target_collection = Self::get_collection(collection_id)?;1031 let target_collection = Self::get_collection(collection_id)?;103210321033 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)?;103410341035 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 }166616661667 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;166916691670 // check token limit and account token limit1670 // check token limit and account token limit1671 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);167516791676 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);tests/src/createMultipleItems.test.tsdiffbeforeafterboth11import {11import {12 createCollectionExpectSuccess,12 createCollectionExpectSuccess,13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 getGenericResult,14 IReFungibleTokenDataType,15 IReFungibleTokenDataType,16 setCollectionLimitsExpectSuccess,15} from './util/helpers';17} from './util/helpers';161817chai.use(chaiAsPromised);19chai.use(chaiAsPromised);93 });95 });94 });96 });9798 it('Can mint amount of items equals to collection limits', async () => {99 await usingApi(async (api) => {100 const alice = privateKey('//Alice');101102 const collectionId = await createCollectionExpectSuccess();103 await setCollectionLimitsExpectSuccess(alice, collectionId, {104 TokenLimit: 2,105 });106 const args = [107 { nft: ['A', 'A'] },108 { nft: ['B', 'B'] },109 ];110 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, alice.address, args);111 const events = await submitTransactionAsync(alice, createMultipleItemsTx);112 const result = getGenericResult(events);113 expect(result.success).to.be.true;114 });115 });95});116});9611797describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {118describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {176 });197 });177 });198 });199200 it('Fails when minting tokens exceeds collectionLimits amount', async () => {201 await usingApi(async (api) => {202 const alice = privateKey('//Alice');203204 const collectionId = await createCollectionExpectSuccess();205 await setCollectionLimitsExpectSuccess(alice, collectionId, {206 TokenLimit: 1,207 });208 const args = [209 { nft: ['A', 'A'] },210 { nft: ['B', 'B'] },211 ];212 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, alice.address, args);213 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;214 });215 });178});216});179217