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
--- /dev/null
+++ b/tests/src/collision-tests/adminDestroyCollection.test.ts
@@ -0,0 +1,60 @@
+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('Deleting a collection while add address to whitelist: ', () => {
+  // tslint:disable-next-line: max-line-length
+  it('Adding an address to the collection whitelist in a block by the admin, and deleting the collection by the owner ', 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 addWhitelistAdm = api.tx.nft.addToWhiteList(collectionId, Ferdie.address);
+      const destroyCollection = api.tx.nft.destroyCollection(collectionId);
+      await Promise.all
+      ([
+        addWhitelistAdm.signAndSend(Bob),
+        destroyCollection.signAndSend(Alice),
+      ]);
+      await timeoutPromise(10000);
+      let whiteList: boolean = false;
+      whiteList = (await api.query.nft.whiteList(collectionId, Ferdie.address)).toJSON() as boolean;
+      // tslint:disable-next-line: no-unused-expression
+      expect(whiteList).to.be.false;
+    });
+  });
+});
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
before · tests/src/collision-tests/tokenLimitsOff.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 } from '../substrate/substrate-api';7import {8  addToWhiteListExpectSuccess,9  createCollectionExpectSuccess,10  getCreateItemResult,11  setMintPermissionExpectSuccess,12} from '../util/helpers';1314chai.use(chaiAsPromised);15const expect = chai.expect;16interface ITokenDataType {17  Owner: number[];18  ConstData: number[];19  VariableData: number[];20}21let Alice: IKeyringPair;22let Bob: IKeyringPair;23let Ferdie: IKeyringPair;2425const AccountTokenOwnershipLimit = 4;26const SponsoredMintSize = 4294967295;27const TokenLimit = 4;28const SponsorTimeout = 14400;29const OwnerCanTransfer = false;30const OwnerCanDestroy = false;3132before(async () => {33  await usingApi(async () => {34    Alice = privateKey('//Alice');35    Bob = privateKey('//Bob');36    Ferdie = privateKey('//Ferdie');37  });38});3940describe('Token limit exceeded collection: ', () => {41  // tslint:disable-next-line: max-line-length42  it('The number of tokens created in the collection from different addresses exceeds the allowed collection limit ', async () => {43    await usingApi(async (api) => {44      const collectionId = await createCollectionExpectSuccess();45      await setMintPermissionExpectSuccess(Alice, collectionId, true);46      await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);47      await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);48      const setCollectionLim = api.tx.nft.setCollectionLimits(49        collectionId,50        {51          AccountTokenOwnershipLimit,52          SponsoredMintSize,53          TokenLimit,54          // tslint:disable-next-line: object-literal-sort-keys55          SponsorTimeout,56          OwnerCanTransfer,57          OwnerCanDestroy,58        },59      );60      const subTx = await submitTransactionAsync(Alice, setCollectionLim);61      const subTxTesult = getCreateItemResult(subTx);62      // tslint:disable-next-line:no-unused-expression63      expect(subTxTesult.success).to.be.true;64      const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));65      await timeoutPromise(10000);66      //67      const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];68      const mintItemOne = api.tx.nft69        .createMultipleItems(collectionId, Ferdie.address, args);70      const mintItemTwo = api.tx.nft71        .createMultipleItems(collectionId, Bob.address, args);72      await Promise.all73      ([74        mintItemOne.signAndSend(Ferdie),75        mintItemTwo.signAndSend(Bob),76      ]);77      await timeoutPromise(10000);78      const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;79      expect(itemsListIndexAfter.toNumber()).to.be.equal(6); // Maybe 4? TokenLimit = 4.80      const token1Data = await api.query.nft.nftItemList(collectionId, 1) as unknown as ITokenDataType;81      const token2Data = await api.query.nft.nftItemList(collectionId, 2) as unknown as ITokenDataType;82      const token3Data = await api.query.nft.nftItemList(collectionId, 3) as unknown as ITokenDataType;83      const token4Data = await api.query.nft.nftItemList(collectionId, 4) as unknown as ITokenDataType;84      const token5Data = await api.query.nft.nftItemList(collectionId, 5) as unknown as ITokenDataType;85      const token6Data = await api.query.nft.nftItemList(collectionId, 6) as unknown as ITokenDataType;8687      expect(token1Data.Owner.toString()).to.be.equal(Bob.address);88      expect(token2Data.Owner.toString()).to.be.equal(Bob.address);89      expect(token3Data.Owner.toString()).to.be.equal(Bob.address);90      expect(token4Data.Owner.toString()).to.be.equal(Ferdie.address);91      expect(token5Data.Owner.toString()).to.be.equal(Ferdie.address);92      expect(token6Data.Owner.toString()).to.be.equal(Ferdie.address);93    });94  });95});
after · tests/src/collision-tests/tokenLimitsOff.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 } from '../substrate/substrate-api';7import {8  addToWhiteListExpectSuccess,9  createCollectionExpectSuccess,10  getCreateItemResult,11  setMintPermissionExpectSuccess,12} from '../util/helpers';1314chai.use(chaiAsPromised);15const expect = chai.expect;16interface ITokenDataType {17  Owner: number[];18  ConstData: number[];19  VariableData: number[];20}21let Alice: IKeyringPair;22let Bob: IKeyringPair;23let Ferdie: IKeyringPair;2425const AccountTokenOwnershipLimit = 4;26const SponsoredMintSize = 4294967295;27const TokenLimit = 4;28const SponsorTimeout = 14400;29const OwnerCanTransfer = false;30const OwnerCanDestroy = false;3132before(async () => {33  await usingApi(async () => {34    Alice = privateKey('//Alice');35    Bob = privateKey('//Bob');36    Ferdie = privateKey('//Ferdie');37  });38});3940describe('Token limit exceeded collection: ', () => {41  // tslint:disable-next-line: max-line-length42  it('The number of tokens created in the collection from different addresses exceeds the allowed collection limit ', async () => {43    await usingApi(async (api) => {44      const collectionId = await createCollectionExpectSuccess();45      await setMintPermissionExpectSuccess(Alice, collectionId, true);46      await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);47      await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);48      const setCollectionLim = api.tx.nft.setCollectionLimits(49        collectionId,50        {51          AccountTokenOwnershipLimit,52          SponsoredMintSize,53          TokenLimit,54          // tslint:disable-next-line: object-literal-sort-keys55          SponsorTimeout,56          OwnerCanTransfer,57          OwnerCanDestroy,58        },59      );60      const subTx = await submitTransactionAsync(Alice, setCollectionLim);61      const subTxTesult = getCreateItemResult(subTx);62      // tslint:disable-next-line:no-unused-expression63      expect(subTxTesult.success).to.be.true;64      const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));65      await timeoutPromise(10000);66      //67      const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];68      const mintItemOne = api.tx.nft69        .createMultipleItems(collectionId, Ferdie.address, args);70      const mintItemTwo = api.tx.nft71        .createMultipleItems(collectionId, Bob.address, args);72      await Promise.all73      ([74        mintItemOne.signAndSend(Ferdie),75        mintItemTwo.signAndSend(Bob),76      ]);77      await timeoutPromise(10000);78      const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;79      expect(itemsListIndexAfter.toNumber()).to.be.equal(3);80      // TokenLimit = 4. The first transaction is successful. The second should fail. (bug: NFTPAR-367)81    });82  });83});