difftreelog
Merge pull request #78 from usetech-llc/feature/NFTPAR-247_removeFromWhiteList
in: master
Add tests for removeFromWhiteList
3 files changed
tests/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",
tests/src/removeFromWhiteList.test.tsdiffbeforeafterboth1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import { default as usingApi } from './substrate/substrate-api';4import {5 createCollectionExpectSuccess,6 destroyCollectionExpectSuccess,7 enableWhiteListExpectSuccess,8 addToWhiteListExpectSuccess,9 removeFromWhiteListExpectSuccess,10 isWhitelisted,11 findNotExistingCollection,12 removeFromWhiteListExpectFailure,13 disableWhiteListExpectSuccess,14} from './util/helpers';15import { IKeyringPair } from '@polkadot/types/types';16import privateKey from './substrate/privateKey';1718chai.use(chaiAsPromised);19const expect = chai.expect;2021describe('Integration Test removeFromWhiteList', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;2425 before(async () => {26 await usingApi(async (api) => {27 alice = privateKey('//Alice');28 bob = privateKey('//Bob');29 });30 });3132 it('ensure bob is not in whitelist after removal', async () => {33 await usingApi(async () => {34 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });35 await enableWhiteListExpectSuccess(alice, collectionId);36 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);3738 await removeFromWhiteListExpectSuccess(alice, collectionId, bob.address);39 expect(await isWhitelisted(collectionId, bob.address)).to.be.false;40 });41 });4243 it('allows removal from collection with unset whitelist status', async () => {44 await usingApi(async () => {45 const collectionWithoutWhitelistId = await createCollectionExpectSuccess();46 await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);47 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);48 await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);4950 await removeFromWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);51 });52 });53});5455describe('Negative Integration Test removeFromWhiteList', () => {56 let alice: IKeyringPair;57 let bob: IKeyringPair;5859 before(async () => {60 await usingApi(async (api) => {61 alice = privateKey('//Alice');62 bob = privateKey('//Bob');63 });64 });6566 it('fails on removal from not existing collection', async () => {67 await usingApi(async (api) => {68 const collectionId = await findNotExistingCollection(api);6970 await removeFromWhiteListExpectFailure(alice, collectionId, bob.address);71 });72 });7374 it('fails on removal from removed collection', async () => {75 await usingApi(async () => {76 const collectionId = await createCollectionExpectSuccess();77 await enableWhiteListExpectSuccess(alice, collectionId);78 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);79 await destroyCollectionExpectSuccess(collectionId);8081 await removeFromWhiteListExpectFailure(alice, collectionId, bob.address);82 });83 });84});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -645,11 +645,14 @@
return newItemId;
}
-export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
+export async function setPublicAccessModeExpectSuccess(
+ sender: IKeyringPair, collectionId: number,
+ accessMode: 'Normal' | 'WhiteList',
+) {
await usingApi(async (api) => {
// Run the transaction
- const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
+ const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
@@ -659,10 +662,18 @@
// What to expect
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- expect(collection.Access).to.be.equal('WhiteList');
+ expect(collection.Access).to.be.equal(accessMode);
});
}
+export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
+ await setPublicAccessModeExpectSuccess(sender, collectionId, 'WhiteList');
+}
+
+export async function disableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
+ await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');
+}
+
export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {
await usingApi(async (api) => {
@@ -680,6 +691,14 @@
});
}
+export async function isWhitelisted(collectionId: number, address: string) {
+ let whitelisted: boolean = false;
+ await usingApi(async (api) => {
+ whitelisted = (await api.query.nft.whiteList(collectionId, address)).toJSON() as unknown as boolean;
+ });
+ return whitelisted;
+}
+
export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
await usingApi(async (api) => {
@@ -702,6 +721,32 @@
});
}
+export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
+ await usingApi(async (api) => {
+ // Run the transaction
+ const tx = api.tx.nft.removeFromWhiteList(collectionId, address);
+ const events = await submitTransactionAsync(sender, tx);
+ const result = getGenericResult(events);
+
+ // What to expect
+ // tslint:disable-next-line:no-unused-expression
+ expect(result.success).to.be.true;
+ });
+}
+
+export async function removeFromWhiteListExpectFailure(sender: IKeyringPair, collectionId: number, address: string) {
+ await usingApi(async (api) => {
+ // Run the transaction
+ const tx = api.tx.nft.removeFromWhiteList(collectionId, address);
+ const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+ const result = getGenericResult(events);
+
+ // What to expect
+ // tslint:disable-next-line:no-unused-expression
+ expect(result.success).to.be.false;
+ });
+}
+
export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)
: Promise<ICollectionInterface | null> => {
return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;