git.delta.rocks / unique-network / refs/commits / b995e58942f3

difftreelog

Merge pull request #112 from usetech-llc/feature/NFTPAR-308_limited_owners_control

Greg Zaitsev2021-02-26parents: #6ea0c80 #4bce10c.patch.diff
in: master
Limited owners control

7 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -382,6 +382,8 @@
         AccountTokenLimitExceeded,
         /// Collection limit bounds per collection exceeded
         CollectionLimitBoundsExceeded,
+        /// Tried to enable permissions which are only permitted to be disabled
+        OwnerPermissionsCantBeReverted,
         /// Schema data size limit bound exceeded
         SchemaDataLimitExceeded,
         /// Maximum refungibility exceeded
@@ -639,6 +641,11 @@
             let sender = ensure_signed(origin)?;
             Self::check_owner_permissions(collection_id, sender)?;
 
+            let target_collection = <Collection<T>>::get(collection_id);
+            if !target_collection.limits.owner_can_destroy {
+                fail!(Error::<T>::NoPermission);
+            }
+
             <AddressTokens<T>>::remove_prefix(collection_id);
             <Allowances<T>>::remove_prefix(collection_id);
             <Balance<T>>::remove_prefix(collection_id);
@@ -1022,9 +1029,14 @@
 
             // Transfer permissions check
             let target_collection = <Collection<T>>::get(collection_id);
-            ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||
-                Self::is_owner_or_admin_permissions(collection_id, sender.clone()),
-                Error::<T>::NoPermission);
+            ensure!(
+                Self::is_item_owner(sender.clone(), collection_id, item_id) ||
+                (
+                    target_collection.limits.owner_can_transfer &&
+                    Self::is_owner_or_admin_permissions(collection_id, sender.clone())
+                ),
+                Error::<T>::NoPermission
+            );
 
             if target_collection.access == AccessMode::WhiteList {
                 Self::check_white_list(collection_id, &sender)?;
@@ -1098,9 +1110,14 @@
 
             // Transfer permissions check
             let target_collection = <Collection<T>>::get(collection_id);
-            ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||
-                Self::is_owner_or_admin_permissions(collection_id, sender.clone()),
-                Error::<T>::NoPermission);
+            ensure!(
+                Self::is_item_owner(sender.clone(), collection_id, item_id) ||
+                (
+                    target_collection.limits.owner_can_transfer &&
+                    Self::is_owner_or_admin_permissions(collection_id, sender.clone())
+                ),
+                Error::<T>::NoPermission
+            );
 
             if target_collection.access == AccessMode::WhiteList {
                 Self::check_white_list(collection_id, &sender)?;
@@ -1156,8 +1173,14 @@
             Self::is_correct_transfer(collection_id, &target_collection, &recipient)?;
 
             // Transfer permissions check         
-            ensure!(appoved_transfer || Self::is_owner_or_admin_permissions(collection_id, sender.clone()),
-                Error::<T>::NoPermission);
+            ensure!(
+                appoved_transfer || 
+                (
+                    target_collection.limits.owner_can_transfer &&
+                    Self::is_owner_or_admin_permissions(collection_id, sender.clone())
+                ),
+                Error::<T>::NoPermission
+            );
 
             if target_collection.access == AccessMode::WhiteList {
                 Self::check_white_list(collection_id, &sender)?;
@@ -1524,25 +1547,32 @@
         pub fn set_collection_limits(
             origin,
             collection_id: u32,
-            limits: CollectionLimits,
+            new_limits: CollectionLimits,
         ) -> DispatchResult {
             let sender = ensure_signed(origin)?;
             Self::check_owner_permissions(collection_id, sender.clone())?;
             let mut target_collection = <Collection<T>>::get(collection_id);
+            let old_limits = target_collection.limits;
             let chain_limits = ChainLimit::get();
-            let climits = target_collection.limits;
 
             // collection bounds
-            ensure!(limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&
-                limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP,  
+            ensure!(new_limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&
+                new_limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP && 
+                new_limits.sponsored_data_size <= chain_limits.custom_data_limit &&
+                new_limits.sponsored_mint_size <= chain_limits.custom_data_limit,
                 Error::<T>::CollectionLimitBoundsExceeded);
 
             // token_limit   check  prev
-            ensure!(climits.token_limit > limits.token_limit && 
-                limits.token_limit <= chain_limits.account_token_ownership_limit, 
-                Error::<T>::AccountTokenLimitExceeded);
+            ensure!(old_limits.token_limit >= new_limits.token_limit, Error::<T>::CollectionTokenLimitExceeded);
+            ensure!(new_limits.token_limit > 0, Error::<T>::CollectionTokenLimitExceeded);
 
-            target_collection.limits = limits;
+            ensure!(
+                (old_limits.owner_can_transfer || !new_limits.owner_can_transfer) &&
+                (old_limits.owner_can_destroy || !new_limits.owner_can_destroy),
+                Error::<T>::OwnerPermissionsCantBeReverted,
+            );
+
+            target_collection.limits = new_limits;
             <Collection<T>>::insert(collection_id, target_collection);
 
             Ok(())
modifiedtests/src/approve.test.tsdiffbeforeafterboth
--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -3,6 +3,7 @@
 // file 'LICENSE', which is part of this source code package.
 //
 import { ApiPromise } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
 import BN from 'bn.js';
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
@@ -15,6 +16,7 @@
   createFungibleItemExpectSuccess,
   createItemExpectSuccess,
   destroyCollectionExpectSuccess,
+  setCollectionLimitsExpectSuccess,
   transferFromExpectSuccess,
   U128_MAX,
 } from './util/helpers';
@@ -23,10 +25,20 @@
 const expect = chai.expect;
 
 describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
+  let Alice: IKeyringPair;
+  let Bob: IKeyringPair;
+  let Charlie: IKeyringPair;
+
+  before(async () => {
+    await usingApi(async (api) => {
+      Alice = privateKey('//Alice');
+      Bob = privateKey('//Bob');
+      Charlie = privateKey('//Charlie');
+    });
+  });
+
   it('Execute the extrinsic and check approvedList', async () => {
     await usingApi(async (api: ApiPromise) => {
-      const Alice = privateKey('//Alice');
-      const Bob = privateKey('//Bob');
       const nftCollectionId = await createCollectionExpectSuccess();
       // nft
       const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -45,8 +57,6 @@
 
   it('Remove approval by using 0 amount', async () => {
     await usingApi(async (api: ApiPromise) => {
-      const Alice = privateKey('//Alice');
-      const Bob = privateKey('//Bob');
       const nftCollectionId = await createCollectionExpectSuccess();
       // nft
       const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -65,13 +75,30 @@
       await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);
     });
   });
+
+  it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
+    const collectionId = await createCollectionExpectSuccess();
+    const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
+
+    await approveExpectSuccess(collectionId, itemId, Alice, Charlie);
+  });
 });
 
 describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {
+  let Alice: IKeyringPair;
+  let Bob: IKeyringPair;
+  let Charlie: IKeyringPair;
+
+  before(async () => {
+    await usingApi(async (api) => {
+      Alice = privateKey('//Alice');
+      Bob = privateKey('//Bob');
+      Charlie = privateKey('//Charlie');
+    });
+  });
+
   it('Approve for a collection that does not exist', async () => {
     await usingApi(async (api: ApiPromise) => {
-      const Alice = privateKey('//Alice');
-      const Bob = privateKey('//Bob');
       // nft
       const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
       await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);
@@ -86,8 +113,6 @@
 
   it('Approve for a collection that was destroyed', async () => {
     await usingApi(async (api: ApiPromise) => {
-      const Alice = privateKey('//Alice');
-      const Bob = privateKey('//Bob');
       // nft
       const nftCollectionId = await createCollectionExpectSuccess();
       await destroyCollectionExpectSuccess(nftCollectionId);
@@ -106,8 +131,6 @@
 
   it('Approve transfer of a token that does not exist', async () => {
     await usingApi(async (api: ApiPromise) => {
-      const Alice = privateKey('//Alice');
-      const Bob = privateKey('//Bob');
       // nft
       const nftCollectionId = await createCollectionExpectSuccess();
       await approveExpectFail(nftCollectionId, 2, Alice, Bob);
@@ -123,8 +146,6 @@
 
   it('Approve using the address that does not own the approved token', async () => {
     await usingApi(async (api: ApiPromise) => {
-      const Alice = privateKey('//Alice');
-      const Bob = privateKey('//Bob');
       const nftCollectionId = await createCollectionExpectSuccess();
       // nft
       const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -140,4 +161,12 @@
       await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);
     });
   });
+
+  it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
+    const collectionId = await createCollectionExpectSuccess();
+    const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });
+
+    await approveExpectFail(collectionId, itemId, Alice, Charlie);
+  });
 });
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -3,10 +3,12 @@
 // file 'LICENSE', which is part of this source code package.
 //
 
+import { IKeyringPair } from '@polkadot/types/types';
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
 import { default as usingApi } from "./substrate/substrate-api";
-import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, destroyCollectionExpectFailure } from "./util/helpers";
+import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, destroyCollectionExpectFailure, setCollectionLimitsExpectSuccess } from "./util/helpers";
 
 chai.use(chaiAsPromised);
 
@@ -26,6 +28,14 @@
 });
 
 describe('(!negative test!) integration test: ext. destroyCollection():', () => {
+  let alice: IKeyringPair;
+
+  before(async () => {
+    await usingApi(async (api) => {
+      alice = privateKey('//Alice');
+    });
+  });
+
   it('(!negative test!) Destroy a collection that never existed', async () => {
     await usingApi(async (api) => {
       // Find the collection that never existed
@@ -43,4 +53,10 @@
     await destroyCollectionExpectFailure(collectionId, '//Bob');
     await destroyCollectionExpectSuccess(collectionId, '//Alice');
   });
+  it('fails when OwnerCanDestroy == false', async () => {
+    const collectionId = await createCollectionExpectSuccess();
+    await setCollectionLimitsExpectSuccess(alice, collectionId, { OwnerCanDestroy: false });
+
+    await destroyCollectionExpectFailure(collectionId, '//Alice');
+  });
 });
modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -14,6 +14,8 @@
   createCollectionExpectSuccess, getCreatedCollectionCount,
   getCreateItemResult,
   getDetailedCollectionInfo,
+  setCollectionLimitsExpectFailure,
+  setCollectionLimitsExpectSuccess,
 } from './util/helpers';
 
 chai.use(chaiAsPromised);
@@ -26,21 +28,8 @@
 const accountTokenOwnershipLimit = 0;
 const sponsoredDataSize = 0;
 const sponsoredMintSize = 0;
-const tokenLimit = 0;
-
-describe('hooks', () => {
-  before(async () => {
-    await usingApi(async () => {
-      const keyring = new Keyring({ type: 'sr25519' });
-      alice = keyring.addFromUri('//Alice');
-    });
-  });
-  it('choose or create collection for testing', async () => {
-    await usingApi(async () => {
-      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
-    });
-  });
-});
+const sponsorTimeout = 1;
+const tokenLimit = 1;
 
 describe('setCollectionLimits positive', () => {
   let tx;
@@ -48,6 +37,7 @@
     await usingApi(async () => {
       const keyring = new Keyring({ type: 'sr25519' });
       alice = keyring.addFromUri('//Alice');
+      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
     });
   });
   it('execute setCollectionLimits with predefined params ', async () => {
@@ -55,25 +45,28 @@
       tx = api.tx.nft.setCollectionLimits(
         collectionIdForTesting,
         {
-          accountTokenOwnershipLimit,
-          sponsoredDataSize,
-          sponsoredMintSize,
-          tokenLimit,
+          AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
+          SponsoredMintSize: sponsoredDataSize,
+          TokenLimit: tokenLimit,
+          SponsorTimeout: sponsorTimeout,
+          OwnerCanTransfer: true,
+          OwnerCanDestroy: true
         },
       );
       const events = await submitTransactionAsync(alice, tx);
       const result = getCreateItemResult(events);
+
+      // get collection limits defined previously
+      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
+
       // tslint:disable-next-line:no-unused-expression
       expect(result.success).to.be.true;
-    });
-  });
-  it('get collection limits defined in previous test', async () => {
-    await usingApi(async (api: ApiPromise) => {
-      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
       expect(collectionInfo.Limits.AccountTokenOwnershipLimit.toNumber()).to.be.equal(accountTokenOwnershipLimit);
-      expect(collectionInfo.Limits.SponsoredMintSize.toNumber()).to.be.equal(sponsoredMintSize);
+      expect(collectionInfo.Limits.SponsoredMintSize.toNumber()).to.be.equal(sponsoredDataSize);
       expect(collectionInfo.Limits.TokenLimit.toNumber()).to.be.equal(tokenLimit);
-      expect(collectionInfo.Limits.SponsorTimeout.toNumber()).to.be.equal(sponsoredDataSize);
+      expect(collectionInfo.Limits.SponsorTimeout.toNumber()).to.be.equal(sponsorTimeout);
+      expect(collectionInfo.Limits.OwnerCanTransfer.valueOf()).to.be.true;
+      expect(collectionInfo.Limits.OwnerCanDestroy.valueOf()).to.be.true;
     });
   });
 });
@@ -85,6 +78,7 @@
       const keyring = new Keyring({ type: 'sr25519' });
       alice = keyring.addFromUri('//Alice');
       bob = keyring.addFromUri('//Bob');
+      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
     });
   });
   it('execute setCollectionLimits for not exists collection', async () => {
@@ -131,4 +125,44 @@
       await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
     });
   });
+
+  it('fails when trying to enable OwnerCanTransfer after it was disabled', async () => {
+    const collectionId = await createCollectionExpectSuccess();
+    await setCollectionLimitsExpectSuccess(alice, collectionId, { 
+      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
+      SponsoredMintSize: sponsoredDataSize,
+      TokenLimit: tokenLimit,
+      SponsorTimeout: sponsorTimeout,
+      OwnerCanTransfer: false,
+      OwnerCanDestroy: true
+    });
+    await setCollectionLimitsExpectFailure(alice, collectionId, { 
+      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
+      SponsoredMintSize: sponsoredDataSize,
+      TokenLimit: tokenLimit,
+      SponsorTimeout: sponsorTimeout,
+      OwnerCanTransfer: true,
+      OwnerCanDestroy: true
+    });
+  });
+
+  it('fails when trying to enable OwnerCanDestroy after it was disabled', async () => {
+    const collectionId = await createCollectionExpectSuccess();
+    await setCollectionLimitsExpectSuccess(alice, collectionId, {
+      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
+      SponsoredMintSize: sponsoredDataSize,
+      TokenLimit: tokenLimit,
+      SponsorTimeout: sponsorTimeout,
+      OwnerCanTransfer: true,
+      OwnerCanDestroy: false
+    });
+    await setCollectionLimitsExpectFailure(alice, collectionId, { 
+      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
+      SponsoredMintSize: sponsoredDataSize,
+      TokenLimit: tokenLimit,
+      SponsorTimeout: sponsorTimeout,
+      OwnerCanTransfer: true,
+      OwnerCanDestroy: true
+    });
+  });
 });
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
before · tests/src/transferFrom.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//5import { ApiPromise } from '@polkadot/api';6import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import { default as usingApi } from './substrate/substrate-api';10import {11  approveExpectFail,12  approveExpectSuccess,13  createCollectionExpectSuccess,14  createFungibleItemExpectSuccess,15  createItemExpectSuccess,16  destroyCollectionExpectSuccess,17  getAllowance,18  transferFromExpectFail,19  transferFromExpectSuccess,20  burnItemExpectSuccess,21} from './util/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {27  it('Execute the extrinsic and check nftItemList - owner of token', async () => {28    await usingApi(async (api: ApiPromise) => {29      const Alice = privateKey('//Alice');30      const Bob = privateKey('//Bob');31      const Charlie = privateKey('//Charlie');32      // nft33      const nftCollectionId = await createCollectionExpectSuccess();34      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');35      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);3637      await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');3839      // fungible40      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});41      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');42      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);43      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');44      // reFungible45      const reFungibleCollectionId = await46        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});47      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');48      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);49      await transferFromExpectSuccess(reFungibleCollectionId,50        newReFungibleTokenId, Bob, Alice, Charlie, 100, 'ReFungible');51    });52  });5354  it('Should reduce allowance if value is big', async () => {55    await usingApi(async () => {56      const alice = privateKey('//Alice');57      const bob = privateKey('//Bob');58      const charlie = privateKey('//Charlie');5960      // fungible61      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});62      const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 500000n });6364      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 500000n);65      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');66      expect((await getAllowance(fungibleCollectionId, newFungibleTokenId, alice.address, bob.address)).toString()).to.equal('0');67    });68  });69});7071describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {72  it('transferFrom for a collection that does not exist', async () => {73    await usingApi(async (api: ApiPromise) => {74      const Alice = privateKey('//Alice');75      const Bob = privateKey('//Bob');76      const Charlie = privateKey('//Charlie');77      // nft78      const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;79      await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);8081      await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);8283      // fungible84      const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;85      await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);8687      await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);88      // reFungible89      const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;90      await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);9192      await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);93    });94  });9596  /* it('transferFrom for a collection that was destroyed', async () => {97    await usingApi(async (api: ApiPromise) => {98      this test copies approve negative test99    });100  }); */101102  /* it('transferFrom a token that does not exist', async () => {103    await usingApi(async (api: ApiPromise) => {104      this test copies approve negative test105    });106  }); */107108  /* it('transferFrom a token that was deleted', async () => {109    await usingApi(async (api: ApiPromise) => {110      this test copies approve negative test111    });112  }); */113114  it('transferFrom for not approved address', async () => {115    await usingApi(async (api: ApiPromise) => {116      const Alice = privateKey('//Alice');117      const Bob = privateKey('//Bob');118      const Charlie = privateKey('//Charlie');119      // nft120      const nftCollectionId = await createCollectionExpectSuccess();121      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');122123      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);124125      // fungible126      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});127      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');128      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);129      // reFungible130      const reFungibleCollectionId = await131        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});132      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');133      await transferFromExpectFail(reFungibleCollectionId,134        newReFungibleTokenId, Bob, Alice, Charlie, 1);135    });136  });137138  it('transferFrom incorrect token count', async () => {139    await usingApi(async (api: ApiPromise) => {140      const Alice = privateKey('//Alice');141      const Bob = privateKey('//Bob');142      const Charlie = privateKey('//Charlie');143      // nft144      const nftCollectionId = await createCollectionExpectSuccess();145      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');146      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);147148      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);149150      // fungible151      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});152      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');153      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);154      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);155      // reFungible156      const reFungibleCollectionId = await157        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});158      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');159      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);160      await transferFromExpectFail(reFungibleCollectionId,161        newReFungibleTokenId, Bob, Alice, Charlie, 2);162    });163  });164165  it('execute transferFrom from account that is not owner of collection', async () => {166    await usingApi(async (api: ApiPromise) => {167      const Alice = privateKey('//Alice');168      const Bob = privateKey('//Bob');169      const Charlie = privateKey('//Charlie');170      const Dave = privateKey('//Dave');171      // nft172      const nftCollectionId = await createCollectionExpectSuccess();173      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');174      try {175        await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);176        await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);177      } catch (e) {178        // tslint:disable-next-line:no-unused-expression179        expect(e).to.be.exist;180      }181182      // await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);183184      // fungible185      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});186      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');187      try {188        await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);189        await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);190      } catch (e) {191        // tslint:disable-next-line:no-unused-expression192        expect(e).to.be.exist;193      }194      // reFungible195      const reFungibleCollectionId = await196        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});197      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');198      try {199        await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);200        await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);201      } catch (e) {202        // tslint:disable-next-line:no-unused-expression203        expect(e).to.be.exist;204      }205    });206  });207  it( 'transferFrom burnt token before approve NFT', async () => {208    await usingApi(async (api: ApiPromise) => {209      const Alice = privateKey('//Alice');210      const Bob = privateKey('//Bob');211      const Charlie = privateKey('//Charlie');212      // nft213      const nftCollectionId = await createCollectionExpectSuccess();214      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');215      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);216      await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);217      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      218    });219  });220  it( 'transferFrom burnt token before approve Fungible', async () => {221    await usingApi(async (api: ApiPromise) => {222    const Alice = privateKey('//Alice');223      const Bob = privateKey('//Bob');224      const Charlie = privateKey('//Charlie');225      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});226      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');227      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);228      await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);229      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);230          231    });232  }); 233  it( 'transferFrom burnt token before approve ReFungible', async () => {234    await usingApi(async (api: ApiPromise) => {235    const Alice = privateKey('//Alice');236      const Bob = privateKey('//Bob');237      const Charlie = privateKey('//Charlie');238      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});239      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');240      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);241      await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);242      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);243          244    });245  });246  247  it( 'transferFrom burnt token after approve NFT', async () => {248    await usingApi(async (api: ApiPromise) => {249      const Alice = privateKey('//Alice');250      const Bob = privateKey('//Bob');251      const Charlie = privateKey('//Charlie');252      // nft253      const nftCollectionId = await createCollectionExpectSuccess();254      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');255      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);256      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);257      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      258    });259  });260  it( 'transferFrom burnt token after approve Fungible', async () => {261    await usingApi(async (api: ApiPromise) => {262    const Alice = privateKey('//Alice');263      const Bob = privateKey('//Bob');264      const Charlie = privateKey('//Charlie');265      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});266      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');267      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);268      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);269      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);270          271    });272  }); 273  it( 'transferFrom burnt token after approve ReFungible', async () => {274    await usingApi(async (api: ApiPromise) => {275    const Alice = privateKey('//Alice');276      const Bob = privateKey('//Bob');277      const Charlie = privateKey('//Charlie');278      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});279      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');280      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);281      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);282      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);283          284    });285  }); 286});
after · tests/src/transferFrom.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//5import { ApiPromise } from '@polkadot/api';6import { IKeyringPair } from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import { default as usingApi } from './substrate/substrate-api';11import {12  approveExpectFail,13  approveExpectSuccess,14  createCollectionExpectSuccess,15  createFungibleItemExpectSuccess,16  createItemExpectSuccess,17  destroyCollectionExpectSuccess,18  getAllowance,19  transferFromExpectFail,20  transferFromExpectSuccess,21  burnItemExpectSuccess,22  setCollectionLimitsExpectSuccess,23} from './util/helpers';2425chai.use(chaiAsPromised);26const expect = chai.expect;2728describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {29  let Alice: IKeyringPair;30  let Bob: IKeyringPair;31  let Charlie: IKeyringPair;3233  before(async () => {34    await usingApi(async (api) => {35      Alice = privateKey('//Alice');36      Bob = privateKey('//Bob');37      Charlie = privateKey('//Charlie');38    });39  });4041  it('Execute the extrinsic and check nftItemList - owner of token', async () => {42    await usingApi(async (api: ApiPromise) => {43      // nft44      const nftCollectionId = await createCollectionExpectSuccess();45      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');46      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);4748      await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');4950      // fungible51      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});52      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');53      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);54      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');55      // reFungible56      const reFungibleCollectionId = await57        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});58      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');59      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);60      await transferFromExpectSuccess(reFungibleCollectionId,61        newReFungibleTokenId, Bob, Alice, Charlie, 100, 'ReFungible');62    });63  });6465  it('Should reduce allowance if value is big', async () => {66    await usingApi(async () => {67      const alice = privateKey('//Alice');68      const bob = privateKey('//Bob');69      const charlie = privateKey('//Charlie');7071      // fungible72      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});73      const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 500000n });7475      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 500000n);76      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');77      expect((await getAllowance(fungibleCollectionId, newFungibleTokenId, alice.address, bob.address)).toString()).to.equal('0');78    });79  });8081  it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {82    const collectionId = await createCollectionExpectSuccess();83    const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);8485    await transferFromExpectSuccess(collectionId, itemId, Alice, Bob, Charlie);86  });87});8889describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {90  let Alice: IKeyringPair;91  let Bob: IKeyringPair;92  let Charlie: IKeyringPair;9394  before(async () => {95    await usingApi(async (api) => {96      Alice = privateKey('//Alice');97      Bob = privateKey('//Bob');98      Charlie = privateKey('//Charlie');99    });100  });101102  it('transferFrom for a collection that does not exist', async () => {103    await usingApi(async (api: ApiPromise) => {104      // nft105      const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;106      await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);107108      await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);109110      // fungible111      const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;112      await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);113114      await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);115      // reFungible116      const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;117      await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);118119      await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);120    });121  });122123  /* it('transferFrom for a collection that was destroyed', async () => {124    await usingApi(async (api: ApiPromise) => {125      this test copies approve negative test126    });127  }); */128129  /* it('transferFrom a token that does not exist', async () => {130    await usingApi(async (api: ApiPromise) => {131      this test copies approve negative test132    });133  }); */134135  /* it('transferFrom a token that was deleted', async () => {136    await usingApi(async (api: ApiPromise) => {137      this test copies approve negative test138    });139  }); */140141  it('transferFrom for not approved address', async () => {142    await usingApi(async (api: ApiPromise) => {143      // nft144      const nftCollectionId = await createCollectionExpectSuccess();145      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');146147      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);148149      // fungible150      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});151      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');152      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);153      // reFungible154      const reFungibleCollectionId = await155        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});156      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');157      await transferFromExpectFail(reFungibleCollectionId,158        newReFungibleTokenId, Bob, Alice, Charlie, 1);159    });160  });161162  it('transferFrom incorrect token count', async () => {163    await usingApi(async (api: ApiPromise) => {164      // nft165      const nftCollectionId = await createCollectionExpectSuccess();166      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');167      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);168169      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);170171      // fungible172      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});173      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');174      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);175      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);176      // reFungible177      const reFungibleCollectionId = await178        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});179      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');180      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);181      await transferFromExpectFail(reFungibleCollectionId,182        newReFungibleTokenId, Bob, Alice, Charlie, 2);183    });184  });185186  it('execute transferFrom from account that is not owner of collection', async () => {187    await usingApi(async (api: ApiPromise) => {188      const Dave = privateKey('//Dave');189      // nft190      const nftCollectionId = await createCollectionExpectSuccess();191      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');192      try {193        await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);194        await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);195      } catch (e) {196        // tslint:disable-next-line:no-unused-expression197        expect(e).to.be.exist;198      }199200      // await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);201202      // fungible203      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});204      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');205      try {206        await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);207        await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);208      } catch (e) {209        // tslint:disable-next-line:no-unused-expression210        expect(e).to.be.exist;211      }212      // reFungible213      const reFungibleCollectionId = await214        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});215      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');216      try {217        await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);218        await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);219      } catch (e) {220        // tslint:disable-next-line:no-unused-expression221        expect(e).to.be.exist;222      }223    });224  });225  it( 'transferFrom burnt token before approve NFT', async () => {226    await usingApi(async (api: ApiPromise) => {227      // nft228      const nftCollectionId = await createCollectionExpectSuccess();229      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');230      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);231      await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);232      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      233    });234  });235  it( 'transferFrom burnt token before approve Fungible', async () => {236    await usingApi(async (api: ApiPromise) => {237      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});238      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');239      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);240      await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);241      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);242          243    });244  }); 245  it( 'transferFrom burnt token before approve ReFungible', async () => {246    await usingApi(async (api: ApiPromise) => {247      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});248      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');249      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);250      await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);251      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);252          253    });254  });255  256  it( 'transferFrom burnt token after approve NFT', async () => {257    await usingApi(async (api: ApiPromise) => {258      // nft259      const nftCollectionId = await createCollectionExpectSuccess();260      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');261      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);262      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);263      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      264    });265  });266  it( 'transferFrom burnt token after approve Fungible', async () => {267    await usingApi(async (api: ApiPromise) => {268      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});269      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');270      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);271      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);272      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);273          274    });275  }); 276  it( 'transferFrom burnt token after approve ReFungible', async () => {277    await usingApi(async (api: ApiPromise) => {278      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});279      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');280      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);281      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);282      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);283          284    });285  });286287  it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {288    const collectionId = await createCollectionExpectSuccess();289    const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);290    await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });291292    await transferFromExpectFail(collectionId, itemId, Alice, Bob, Charlie);293  });294});
modifiedtests/src/types.tsdiffbeforeafterboth
--- a/tests/src/types.ts
+++ b/tests/src/types.ts
@@ -17,6 +17,8 @@
     SponsoredMintSize: BN;
     TokenLimit: BN;
     SponsorTimeout: BN;
+    OwnerCanTransfer: boolean;
+    OwnerCanDestroy: boolean;
   };
   MintMode: boolean;
   Mode: {
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -333,6 +333,36 @@
   });
 }
 
+export async function queryCollectionLimits(collectionId: number) {
+  return await usingApi(async (api) => {
+    return ((await api.query.nft.collection(collectionId)).toJSON() as any).Limits;
+  });
+}
+
+export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {
+  await usingApi(async (api) => {
+    const oldLimits = await queryCollectionLimits(collectionId);
+    const newLimits = { ...oldLimits as any, ...limits };
+    const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);
+    const events = await submitTransactionAsync(sender, tx);
+    const result = getGenericResult(events);
+
+    expect(result.success).to.be.true;
+  });
+}
+
+export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {
+  await usingApi(async (api) => {
+    const oldLimits = await queryCollectionLimits(collectionId);
+    const newLimits = { ...oldLimits as any, ...limits };
+    const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);
+    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+    const result = getGenericResult(events);
+
+    expect(result.success).to.be.false;
+  });
+}
+
 export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {
   await usingApi(async (api) => {