git.delta.rocks / unique-network / refs/commits / 7c95ae985972

difftreelog

CORE-161. Change collection owner integration tests

str-mv2021-07-29parent: #e961e84.patch.diff
in: master

3 files changed

modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -7,7 +7,15 @@
 import chaiAsPromised from 'chai-as-promised';
 import privateKey from './substrate/privateKey';
 import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import { createCollectionExpectSuccess, addCollectionAdminExpectSuccess } from './util/helpers';
+import { createCollectionExpectSuccess, 
+  addCollectionAdminExpectSuccess,
+  setCollectionSponsorExpectSuccess,
+  confirmSponsorshipExpectSuccess,
+  removeCollectionSponsorExpectSuccess,
+  enableWhiteListExpectSuccess,
+  setMintPermissionExpectSuccess,
+  destroyCollectionExpectSuccess,
+} from './util/helpers';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
@@ -31,6 +39,71 @@
   });
 });
 
+describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {
+  it('Changing the owner of the collection is not allowed for the former owner', async () => {
+    await usingApi(async api => {
+      const collectionId = await createCollectionExpectSuccess();
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
+
+      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+      expect(collection.Owner).to.be.deep.eq(alice.address);
+
+      const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
+      await submitTransactionAsync(alice, changeOwnerTx);
+
+      const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);
+      await expect(submitTransactionAsync(alice, badChangeOwnerTx)).to.be.rejected;
+
+      const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
+    });
+  });
+
+  it('New collectionOwner has access to sponsorship management operations in the collection', async () => {
+    await usingApi(async api => {
+      const collectionId = await createCollectionExpectSuccess();
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
+      const charlie = privateKey('//Charlie');
+
+      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+      expect(collection.Owner).to.be.deep.eq(alice.address);
+
+      const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
+      await submitTransactionAsync(alice, changeOwnerTx);
+
+      const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
+
+      // After changing the owner of the collection, all privileged methods are available to the new owner
+      // The new owner of the collection has access to sponsorship management operations in the collection
+      await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');
+      await confirmSponsorshipExpectSuccess(collectionId, '//Charlie');
+      await removeCollectionSponsorExpectSuccess(collectionId, '//Bob');
+
+      // The new owner of the collection has access to operations for managing the collection parameters
+      const collectionLimits = {
+        AccountTokenOwnershipLimit: 1,
+        SponsoredMintSize: 1,
+        TokenLimit: 1,
+        SponsorTimeout: 1,
+        OwnerCanTransfer: true,
+        OwnerCanDestroy: true,
+      };
+      const tx1 = api.tx.nft.setCollectionLimits(
+        collectionId,
+        collectionLimits,
+      );
+      await submitTransactionAsync(bob, tx1);
+
+      await enableWhiteListExpectSuccess(bob, collectionId);
+      await setMintPermissionExpectSuccess(bob, collectionId, true);
+      await destroyCollectionExpectSuccess(collectionId, '//Bob');
+    });
+  });
+});
+
 describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
   it('Not owner can\'t change owner.', async () => {
     await usingApi(async api => {
@@ -81,4 +154,47 @@
       await createCollectionExpectSuccess();
     });
   });
+
+  it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {
+    await usingApi(async api => {
+      const collectionId = await createCollectionExpectSuccess();
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
+      const charlie = privateKey('//Charlie');
+
+      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+      expect(collection.Owner).to.be.deep.eq(alice.address);
+
+      const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
+      await submitTransactionAsync(alice, changeOwnerTx);
+
+      const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);
+      await expect(submitTransactionAsync(alice, badChangeOwnerTx)).to.be.rejected;
+
+      const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
+
+      await expect(setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Alice')).to.be.rejected;
+      await expect(confirmSponsorshipExpectSuccess(collectionId, '//Alice')).to.be.rejected;
+      await expect(removeCollectionSponsorExpectSuccess(collectionId, '//Alice')).to.be.rejected;
+
+      const collectionLimits = {
+        AccountTokenOwnershipLimit: 1,
+        SponsoredMintSize: 1,
+        TokenLimit: 1,
+        SponsorTimeout: 1,
+        OwnerCanTransfer: true,
+        OwnerCanDestroy: true,
+      };
+      const tx1 = api.tx.nft.setCollectionLimits(
+        collectionId,
+        collectionLimits,
+      );
+      await expect(submitTransactionAsync(alice, tx1)).to.be.rejected;
+
+      await expect(enableWhiteListExpectSuccess(alice, collectionId)).to.be.rejected;
+      await expect(setMintPermissionExpectSuccess(alice, collectionId, true)).to.be.rejected;
+      await expect(destroyCollectionExpectSuccess(collectionId, '//Alice')).to.be.rejected;
+    });
+  });
 });
modifiedtests/src/setChainLimits.test.tsdiffbeforeafterboth
before · tests/src/setChainLimits.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//56import { IKeyringPair } from '@polkadot/types/types';7import privateKey from './substrate/privateKey';8import usingApi from './substrate/substrate-api';9import {10  createCollectionExpectSuccess,11  addCollectionAdminExpectSuccess,12  setChainLimitsExpectFailure,13  IChainLimits,14} from './util/helpers';1516describe.only('Negative Integration Test setChainLimits', () => {17  let alice: IKeyringPair;18  let bob: IKeyringPair;19  let dave: IKeyringPair;20  let limits: IChainLimits;2122  before(async () => {23    await usingApi(async () => {24      alice = privateKey('//Alice');25      bob = privateKey('//Bob');26      dave = privateKey('//Dave');27      limits = {28        CollectionNumbersLimit : 1,29        AccountTokenOwnershipLimit: 1,30        CollectionsAdminsLimit: 1,31        CustomDataLimit: 1,32        NftSponsorTransferTimeout: 1,33        FungibleSponsorTransferTimeout: 1,34        RefungibleSponsorTransferTimeout: 1,35        OffchainSchemaLimit: 1,36        VariableOnChainSchemaLimit: 1,37        ConstOnChainSchemaLimit: 1,38      };39    });40  });4142  it('Collection owner cannot set chain limits', async () => {43    await createCollectionExpectSuccess({ mode: { type: 'NFT' } });44    await setChainLimitsExpectFailure(alice, limits);45  });4647  it('Collection admin cannot set chain limits', async () => {48    const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });49    await addCollectionAdminExpectSuccess(alice, collectionId, bob);50    await setChainLimitsExpectFailure(bob, limits);51  });52  53  it('Regular user cannot set chain limits', async () => {54    await setChainLimitsExpectFailure(dave, limits);55  });56});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -431,13 +431,13 @@
   });
 }
 
-export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {
+export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {
   await usingApi(async (api) => {
 
     // Run the transaction
-    const alicePrivateKey = privateKey('//Alice');
+    const senderPrivateKey = privateKey(sender);
     const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
-    const events = await submitTransactionAsync(alicePrivateKey, tx);
+    const events = await submitTransactionAsync(senderPrivateKey, tx);
     const result = getGenericResult(events);
 
     // Get the collection
@@ -451,11 +451,11 @@
   });
 }
 
-export async function removeCollectionSponsorExpectSuccess(collectionId: number) {
+export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {
   await usingApi(async (api) => {
 
     // Run the transaction
-    const alicePrivateKey = privateKey('//Alice');
+    const alicePrivateKey = privateKey(sender);
     const tx = api.tx.nft.removeCollectionSponsor(collectionId);
     const events = await submitTransactionAsync(alicePrivateKey, tx);
     const result = getGenericResult(events);