git.delta.rocks / unique-network / refs/commits / 30e1ae5f0b65

difftreelog

Add collision tests

unknown2021-02-26parent: #2cf6425.patch.diff
in: master
Add tests NFTPAR-218

3 files changed

addedtests/src/collision-tests/adminDestroyCollection.test.tsdiffbeforeafterboth
after · tests/src/collision-tests/adminDestroyCollection.test.ts
1import { IKeyringPair } from '@polkadot/types/types';2import BN from 'bn.js';3import chai from 'chai';4import chaiAsPromised from 'chai-as-promised';5import privateKey from '../substrate/privateKey';6import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';7import {8  createCollectionExpectSuccess,9} from '../util/helpers';1011chai.use(chaiAsPromised);12const expect = chai.expect;13interface ITokenDataType {14  Owner: number[];15  ConstData: number[];16  VariableData: number[];17}18let Alice: IKeyringPair;19let Bob: IKeyringPair;20let Ferdie: IKeyringPair;21let Charlie: IKeyringPair;22let Eve: IKeyringPair;23let Dave: IKeyringPair;2425before(async () => {26  await usingApi(async () => {27    Alice = privateKey('//Alice');28    Bob = privateKey('//Bob');29    Ferdie = privateKey('//Ferdie');30    Charlie = privateKey('//Charlie');31    Eve = privateKey('//Eve');32    Dave = privateKey('//Dave');33  });34});3536describe('Deleting a collection while add address to whitelist: ', () => {37  // tslint:disable-next-line: max-line-length38  it('Adding an address to the collection whitelist in a block by the admin, and deleting the collection by the owner ', async () => {39    await usingApi(async (api) => {40      const collectionId = await createCollectionExpectSuccess();41      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);42      await submitTransactionAsync(Alice, changeAdminTx);43      const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));44      await timeoutPromise(10000);45      //46      const addWhitelistAdm = api.tx.nft.addToWhiteList(collectionId, Ferdie.address);47      const destroyCollection = api.tx.nft.destroyCollection(collectionId);48      await Promise.all49      ([50        addWhitelistAdm.signAndSend(Bob),51        destroyCollection.signAndSend(Alice),52      ]);53      await timeoutPromise(10000);54      let whiteList: boolean = false;55      whiteList = (await api.query.nft.whiteList(collectionId, Ferdie.address)).toJSON() as boolean;56      // tslint:disable-next-line: no-unused-expression57      expect(whiteList).to.be.false;58    });59  });60});
addedtests/src/collision-tests/adminRightsOff.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/collision-tests/adminRightsOff.test.ts
@@ -0,0 +1,61 @@
+import { IKeyringPair } from '@polkadot/types/types';
+import BN from 'bn.js';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from '../substrate/privateKey';
+import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';
+import {
+  createCollectionExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+interface ITokenDataType {
+  Owner: number[];
+  ConstData: number[];
+  VariableData: number[];
+}
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+let Ferdie: IKeyringPair;
+let Charlie: IKeyringPair;
+let Eve: IKeyringPair;
+let Dave: IKeyringPair;
+
+before(async () => {
+  await usingApi(async () => {
+    Alice = privateKey('//Alice');
+    Bob = privateKey('//Bob');
+    Ferdie = privateKey('//Ferdie');
+    Charlie = privateKey('//Charlie');
+    Eve = privateKey('//Eve');
+    Dave = privateKey('//Dave');
+  });
+});
+
+describe('Deprivation of admin rights: ', () => {
+  // tslint:disable-next-line: max-line-length
+  it('In the block, the collection admin adds a token or changes data, and the collection owner deprives the admin of rights ', async () => {
+    await usingApi(async (api) => {
+      const collectionId = await createCollectionExpectSuccess();
+      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+      await submitTransactionAsync(Alice, changeAdminTx);
+      const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
+      await timeoutPromise(10000);
+      //
+      const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
+      const addItemAdm = api.tx.nft.createMultipleItems(collectionId, Bob.address, args);
+      const removeAdm = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);
+      await Promise.all
+      ([
+        addItemAdm.signAndSend(Bob),
+        removeAdm.signAndSend(Alice),
+      ]);
+      await timeoutPromise(10000);
+      const itemsListIndex = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
+      expect(itemsListIndex.toNumber()).to.be.equal(0);
+      const adminList: any = (await api.query.nft.adminList(collectionId));
+      expect(adminList).not.to.be.contains(Bob.address);
+    });
+  });
+});
modifiedtests/src/collision-tests/tokenLimitsOff.test.tsdiffbeforeafterboth
--- a/tests/src/collision-tests/tokenLimitsOff.test.ts
+++ b/tests/src/collision-tests/tokenLimitsOff.test.ts
@@ -76,20 +76,8 @@
       ]);
       await timeoutPromise(10000);
       const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
-      expect(itemsListIndexAfter.toNumber()).to.be.equal(6); // Maybe 4? TokenLimit = 4.
-      const token1Data = await api.query.nft.nftItemList(collectionId, 1) as unknown as ITokenDataType;
-      const token2Data = await api.query.nft.nftItemList(collectionId, 2) as unknown as ITokenDataType;
-      const token3Data = await api.query.nft.nftItemList(collectionId, 3) as unknown as ITokenDataType;
-      const token4Data = await api.query.nft.nftItemList(collectionId, 4) as unknown as ITokenDataType;
-      const token5Data = await api.query.nft.nftItemList(collectionId, 5) as unknown as ITokenDataType;
-      const token6Data = await api.query.nft.nftItemList(collectionId, 6) as unknown as ITokenDataType;
-
-      expect(token1Data.Owner.toString()).to.be.equal(Bob.address);
-      expect(token2Data.Owner.toString()).to.be.equal(Bob.address);
-      expect(token3Data.Owner.toString()).to.be.equal(Bob.address);
-      expect(token4Data.Owner.toString()).to.be.equal(Ferdie.address);
-      expect(token5Data.Owner.toString()).to.be.equal(Ferdie.address);
-      expect(token6Data.Owner.toString()).to.be.equal(Ferdie.address);
+      expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
+      // TokenLimit = 4. The first transaction is successful. The second should fail. (bug: NFTPAR-367)
     });
   });
 });