git.delta.rocks / unique-network / refs/commits / 54428b004949

difftreelog

tests: add tests for removeFromWhiteList

Yaroslav Bolyukin2021-01-27parent: #6e7b40e.patch.diff
in: master

2 files changed

modifiedtests/package.jsondiffbeforeafterboth
before · tests/package.json
1{2  "name": "NftTests",3  "version": "1.0.0",4  "description": "Substrate Nft tests",5  "main": "",6  "devDependencies": {7    "@polkadot/dev": "^0.52.11",8    "@polkadot/ts": "^0.3.41",9    "@types/chai": "^4.2.12",10    "@types/chai-as-promised": "^7.1.3",11    "@types/mocha": "^8.0.3",12    "chai": "^4.2.0",13    "mocha": "^8.1.1",14    "ts-node": "^9.0.0",15    "tslint": "^5.20.1",16    "typescript": "^3.9.7"17  },18  "scripts": {19    "test": "mocha --timeout 9999999 -r ts-node/register ./**/*.test.ts",20    "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",21    "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",22    "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",23    "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",24    "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",25    "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",26    "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",27    "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",28    "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",29    "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",30    "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",31    "testToggleContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractWhiteList.test.ts",32    "testAddToContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractWhiteList.test.ts",33    "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",34    "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts"35  },36  "author": "",37  "license": "Apache 2.0",38  "homepage": "",39  "dependencies": {40    "@polkadot/api": "^2.3.1",41    "@polkadot/api-contract": "^2.3.1",42    "@polkadot/types": "^2.3.1",43    "@polkadot/util": "^3.4.1",44    "bignumber.js": "^9.0.0",45    "chai-as-promised": "^7.1.1"46  },47  "standard": {48    "globals": [49      "it",50      "assert",51      "beforeEach",52      "afterEach",53      "describe",54      "contract",55      "artifacts"56    ]57  }58}
after · tests/package.json
1{2  "name": "NftTests",3  "version": "1.0.0",4  "description": "Substrate Nft tests",5  "main": "",6  "devDependencies": {7    "@polkadot/dev": "^0.52.11",8    "@polkadot/ts": "^0.3.41",9    "@types/chai": "^4.2.12",10    "@types/chai-as-promised": "^7.1.3",11    "@types/mocha": "^8.0.3",12    "chai": "^4.2.0",13    "mocha": "^8.1.1",14    "ts-node": "^9.0.0",15    "tslint": "^5.20.1",16    "typescript": "^3.9.7"17  },18  "scripts": {19    "test": "mocha --timeout 9999999 -r ts-node/register ./**/*.test.ts",20    "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",21    "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",22    "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",23    "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",24    "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",25    "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",26    "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",27    "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",28    "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",29    "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",30    "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",31    "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",32    "testToggleContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractWhiteList.test.ts",33    "testAddToContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractWhiteList.test.ts",34    "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",35    "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts"36  },37  "author": "",38  "license": "Apache 2.0",39  "homepage": "",40  "dependencies": {41    "@polkadot/api": "^2.3.1",42    "@polkadot/api-contract": "^2.3.1",43    "@polkadot/types": "^2.3.1",44    "@polkadot/util": "^3.4.1",45    "bignumber.js": "^9.0.0",46    "chai-as-promised": "^7.1.1"47  },48  "standard": {49    "globals": [50      "it",51      "assert",52      "beforeEach",53      "afterEach",54      "describe",55      "contract",56      "artifacts"57    ]58  }59}
addedtests/src/removeFromWhiteList.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/removeFromWhiteList.test.ts
@@ -0,0 +1,87 @@
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import { default as usingApi } from './substrate/substrate-api';
+import {
+  createCollectionExpectSuccess,
+  destroyCollectionExpectSuccess,
+  enableWhiteListExpectSuccess,
+  addToWhiteListExpectSuccess,
+  removeFromWhiteListExpectSuccess,
+  isWhitelisted,
+  findNotExistingCollection,
+  removeFromWhiteListExpectFailure,
+  disableWhiteListExpectSuccess,
+} from './util/helpers';
+import { IKeyringPair } from '@polkadot/types/types';
+import privateKey from './substrate/privateKey';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Integration Test removeFromWhiteList', () => {
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+  let collectionId: number;
+
+  before(async () => {
+    await usingApi(async (api) => {
+      alice = privateKey('//Alice');
+      bob = privateKey('//Bob');
+      collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+      await enableWhiteListExpectSuccess(alice, collectionId);
+      await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+    });
+  });
+
+  it('remove bob from whitelist', async () => {
+    await usingApi(async () => {
+      await removeFromWhiteListExpectSuccess(alice, collectionId, bob.address);
+    });
+  });
+
+  it('ensure bob is no longer in whitelist', async () => {
+    expect(await isWhitelisted(collectionId, bob.address)).to.be.false;
+  });
+});
+
+describe('Negative Integration Test removeFromWhiteList', () => {
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+
+  before(async () => {
+    await usingApi(async (api) => {
+      alice = privateKey('//Alice');
+      bob = privateKey('//Bob');
+    });
+  });
+
+  it('fails on removal from not existing collection', async () => {
+    await usingApi(async (api) => {
+      const collectionId = await findNotExistingCollection(api);
+
+      await removeFromWhiteListExpectFailure(alice, collectionId, bob.address);
+    });
+  });
+
+  it('fails on removal from removed collection', async () => {
+    await usingApi(async () => {
+      const collectionId = await createCollectionExpectSuccess();
+      await enableWhiteListExpectSuccess(alice, collectionId);
+      await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+      await destroyCollectionExpectSuccess(collectionId);
+
+      await removeFromWhiteListExpectFailure(alice, collectionId, bob.address);
+    });
+  });
+
+  it('fails on removal from collection with unset whitelist status', async () => {
+    await usingApi(async () => {
+      const collectionId = await createCollectionExpectSuccess();
+      await enableWhiteListExpectSuccess(alice, collectionId);
+      await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+      await disableWhiteListExpectSuccess(alice, collectionId);
+
+      await removeFromWhiteListExpectFailure(alice, collectionId, bob.address);
+    });
+  });
+});