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

difftreelog

Merge pull request #170 from UniqueNetwork/feature/CORE-161

kozyrevdev2021-08-13parents: #9a3373d #83994a5.patch.diff
in: master
Feature/core 161

2 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,22 @@
 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,
+  setCollectionSponsorExpectFailure,
+  confirmSponsorshipExpectFailure,
+  removeCollectionSponsorExpectFailure,
+  enableWhiteListExpectFail,
+  setMintPermissionExpectFailure,
+  destroyCollectionExpectFailure,
+  setPublicAccessModeExpectSuccess,
+} from './util/helpers';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
@@ -31,6 +46,97 @@
   });
 });
 
+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(submitTransactionExpectFailAsync(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 setPublicAccessModeExpectSuccess(bob, collectionId, 'WhiteList');
+      await enableWhiteListExpectSuccess(bob, collectionId);
+      await setMintPermissionExpectSuccess(bob, collectionId, true);
+      await destroyCollectionExpectSuccess(collectionId, '//Bob');
+    });
+  });
+
+  it('New collectionOwner has access to changeCollectionOwner', 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);
+
+      const changeOwnerTx2 = api.tx.nft.changeCollectionOwner(collectionId, charlie.address);
+      await submitTransactionAsync(bob, changeOwnerTx2);
+  
+      // ownership lost
+      const collectionAfterOwnerChange2: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+      expect(collectionAfterOwnerChange2.Owner).to.be.deep.eq(charlie.address);
+    });
+  });
+});
+
 describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
   it('Not owner can\'t change owner.', async () => {
     await usingApi(async api => {
@@ -81,4 +187,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(submitTransactionExpectFailAsync(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 setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');
+      await confirmSponsorshipExpectFailure(collectionId, '//Alice');
+      await removeCollectionSponsorExpectFailure(collectionId, '//Alice');
+
+      const collectionLimits = {
+        AccountTokenOwnershipLimit: 1,
+        SponsoredMintSize: 1,
+        TokenLimit: 1,
+        SponsorTimeout: 1,
+        OwnerCanTransfer: true,
+        OwnerCanDestroy: true,
+      };
+      const tx1 = api.tx.nft.setCollectionLimits(
+        collectionId,
+        collectionLimits,
+      );
+      await expect(submitTransactionExpectFailAsync(alice, tx1)).to.be.rejected;
+
+      await enableWhiteListExpectFail(alice, collectionId);
+      await setMintPermissionExpectFailure(alice, collectionId, true);
+      await destroyCollectionExpectFailure(collectionId, '//Alice');
+    });
+  });
 });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
431 });431 });
432}432}
433433
434export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {434export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {
435 await usingApi(async (api) => {435 await usingApi(async (api) => {
436436
437 // Run the transaction437 // Run the transaction
438 const alicePrivateKey = privateKey('//Alice');438 const senderPrivateKey = privateKey(sender);
439 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);439 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
440 const events = await submitTransactionAsync(alicePrivateKey, tx);440 const events = await submitTransactionAsync(senderPrivateKey, tx);
441 const result = getGenericResult(events);441 const result = getGenericResult(events);
442442
443 // Get the collection443 // Get the collection
451 });451 });
452}452}
453453
454export async function removeCollectionSponsorExpectSuccess(collectionId: number) {454export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {
455 await usingApi(async (api) => {455 await usingApi(async (api) => {
456456
457 // Run the transaction457 // Run the transaction
458 const alicePrivateKey = privateKey('//Alice');458 const alicePrivateKey = privateKey(sender);
459 const tx = api.tx.nft.removeCollectionSponsor(collectionId);459 const tx = api.tx.nft.removeCollectionSponsor(collectionId);
460 const events = await submitTransactionAsync(alicePrivateKey, tx);460 const events = await submitTransactionAsync(alicePrivateKey, tx);
461 const result = getGenericResult(events);461 const result = getGenericResult(events);
1006 });1006 });
1007}1007}
1008
1009export async function setPublicAccessModeExpectFail(
1010 sender: IKeyringPair, collectionId: number,
1011 accessMode: 'Normal' | 'WhiteList',
1012) {
1013 await usingApi(async (api) => {
1014
1015 // Run the transaction
1016 const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);
1017 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
1018 const result = getGenericResult(events);
1019
1020 // What to expect
1021 // tslint:disable-next-line:no-unused-expression
1022 expect(result.success).to.be.false;
1023 });
1024}
10081025
1009export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {1026export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
1010 await setPublicAccessModeExpectSuccess(sender, collectionId, 'WhiteList');1027 await setPublicAccessModeExpectSuccess(sender, collectionId, 'WhiteList');
1011}1028}
1029
1030export async function enableWhiteListExpectFail(sender: IKeyringPair, collectionId: number) {
1031 await setPublicAccessModeExpectFail(sender, collectionId, 'WhiteList');
1032}
10121033
1013export async function disableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {1034export async function disableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
1014 await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');1035 await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');