git.delta.rocks / unique-network / refs/commits / 104a9a3f8121

difftreelog

Merge pull request #78 from usetech-llc/feature/NFTPAR-247_removeFromWhiteList

Greg Zaitsev2021-02-03parents: #3f3b2f7 #70ccc05.patch.diff
in: master
Add tests for removeFromWhiteList

3 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -25,6 +25,7 @@
     "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",
     "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
     "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
+    "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",
     "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
     "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
     "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",
addedtests/src/removeFromWhiteList.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/removeFromWhiteList.test.ts
@@ -0,0 +1,84 @@
+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;
+
+  before(async () => {
+    await usingApi(async (api) => {
+      alice = privateKey('//Alice');
+      bob = privateKey('//Bob');
+    });
+  });
+
+  it('ensure bob is not in whitelist after removal', async () => {
+    await usingApi(async () => {
+      const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+      await enableWhiteListExpectSuccess(alice, collectionId);
+      await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+
+      await removeFromWhiteListExpectSuccess(alice, collectionId, bob.address);
+      expect(await isWhitelisted(collectionId, bob.address)).to.be.false;
+    });
+  });
+
+  it('allows removal from collection with unset whitelist status', async () => {
+    await usingApi(async () => {
+      const collectionWithoutWhitelistId = await createCollectionExpectSuccess();
+      await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
+      await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);
+      await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
+
+      await removeFromWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);
+    });
+  });
+});
+
+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);
+    });
+  });
+});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
645 return newItemId;645 return newItemId;
646}646}
647647
648export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {648export async function setPublicAccessModeExpectSuccess(
649 sender: IKeyringPair, collectionId: number,
650 accessMode: 'Normal' | 'WhiteList',
651) {
649 await usingApi(async (api) => {652 await usingApi(async (api) => {
650653
651 // Run the transaction654 // Run the transaction
652 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');655 const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);
653 const events = await submitTransactionAsync(sender, tx);656 const events = await submitTransactionAsync(sender, tx);
654 const result = getGenericResult(events);657 const result = getGenericResult(events);
655658
659 // What to expect662 // What to expect
660 // tslint:disable-next-line:no-unused-expression663 // tslint:disable-next-line:no-unused-expression
661 expect(result.success).to.be.true;664 expect(result.success).to.be.true;
662 expect(collection.Access).to.be.equal('WhiteList');665 expect(collection.Access).to.be.equal(accessMode);
663 });666 });
664}667}
668
669export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
670 await setPublicAccessModeExpectSuccess(sender, collectionId, 'WhiteList');
671}
672
673export async function disableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
674 await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');
675}
665676
666export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {677export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {
667 await usingApi(async (api) => {678 await usingApi(async (api) => {
680 });691 });
681}692}
693
694export async function isWhitelisted(collectionId: number, address: string) {
695 let whitelisted: boolean = false;
696 await usingApi(async (api) => {
697 whitelisted = (await api.query.nft.whiteList(collectionId, address)).toJSON() as unknown as boolean;
698 });
699 return whitelisted;
700}
682701
683export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {702export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
684 await usingApi(async (api) => {703 await usingApi(async (api) => {
702 });721 });
703}722}
723
724export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
725 await usingApi(async (api) => {
726 // Run the transaction
727 const tx = api.tx.nft.removeFromWhiteList(collectionId, address);
728 const events = await submitTransactionAsync(sender, tx);
729 const result = getGenericResult(events);
730
731 // What to expect
732 // tslint:disable-next-line:no-unused-expression
733 expect(result.success).to.be.true;
734 });
735}
736
737export async function removeFromWhiteListExpectFailure(sender: IKeyringPair, collectionId: number, address: string) {
738 await usingApi(async (api) => {
739 // Run the transaction
740 const tx = api.tx.nft.removeFromWhiteList(collectionId, address);
741 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
742 const result = getGenericResult(events);
743
744 // What to expect
745 // tslint:disable-next-line:no-unused-expression
746 expect(result.success).to.be.false;
747 });
748}
704749
705export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)750export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)
706 : Promise<ICollectionInterface | null> => {751 : Promise<ICollectionInterface | null> => {