difftreelog
Merge pull request #68 from usetech-llc/feature/NFTPAR-234
in: master
Feature/nftpar 234
3 files changed
tests/src/addToWhiteList.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/addToWhiteList.test.ts
@@ -0,0 +1,81 @@
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
+import usingApi, { submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import {
+ addToWhiteListExpectSuccess,
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+ destroyCollectionExpectSuccess,
+ enablePublicMintingExpectSuccess,
+ enableWhiteListExpectSuccess,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+
+describe.only('Integration Test ext. addToWhiteList()', () => {
+
+ before(async () => {
+ await usingApi(async (api) => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ });
+ });
+
+ it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ });
+
+ it('Whitelisted minting: list restrictions', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ await enableWhiteListExpectSuccess(Alice, collectionId);
+ await enablePublicMintingExpectSuccess(Alice, collectionId);
+ await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
+ });
+});
+
+describe.only('Negative Integration Test ext. addToWhiteList()', () => {
+
+ it('White list an address in the collection that does not exist', async () => {
+ await usingApi(async (api) => {
+ // tslint:disable-next-line: no-bitwise
+ const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ const Bob = privateKey('//Bob');
+
+ const tx = api.tx.nft.addToWhiteList(collectionId, Bob.address);
+ await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ });
+ });
+
+ it('White list an address in the collection that was destroyed', async () => {
+ await usingApi(async (api) => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+ // tslint:disable-next-line: no-bitwise
+ const collectionId = await createCollectionExpectSuccess();
+ await destroyCollectionExpectSuccess(collectionId);
+ const tx = api.tx.nft.addToWhiteList(collectionId, Bob.address);
+ await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ });
+ });
+
+ it('White list an address in the collection that does not have white list access enabled', async () => {
+ await usingApi(async (api) => {
+ const Alice = privateKey('//Alice');
+ const Ferdie = privateKey('//Ferdie');
+ const collectionId = await createCollectionExpectSuccess();
+ await enableWhiteListExpectSuccess(Alice, collectionId);
+ await enablePublicMintingExpectSuccess(Alice, collectionId);
+ const tx = api.tx.nft.createItem(collectionId, Ferdie.address, 'NFT');
+ await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;
+ });
+ });
+
+});
tests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/toggleContractWhiteList.test.ts
+++ b/tests/src/toggleContractWhiteList.test.ts
@@ -33,7 +33,7 @@
});
});
- it.only(`Only whitelisted account can call contract`, async () => {
+ it(`Only whitelisted account can call contract`, async () => {
await usingApi(async api => {
const bob = privateKey("//Bob");
tests/src/util/helpers.tsdiffbeforeafterboth620export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {620export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {621 await usingApi(async (api) => {621 await usingApi(async (api) => {622623 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();622624623 // Run the transaction625 // Run the transaction624 const tx = api.tx.nft.addToWhiteList(collectionId, address);626 const tx = api.tx.nft.addToWhiteList(collectionId, address);625 const events = await submitTransactionAsync(sender, tx);627 const events = await submitTransactionAsync(sender, tx);626 const result = getGenericResult(events);628 const result = getGenericResult(events);627629628 // Get the collection629 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();630 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();630631631 // What to expect632 // What to expect632 // tslint:disable-next-line:no-unused-expression633 // tslint:disable-next-line:no-unused-expression633 expect(result.success).to.be.true;634 expect(result.success).to.be.true;635 // tslint:disable-next-line: no-unused-expression636 expect(whiteListedBefore).to.be.false;637 // tslint:disable-next-line: no-unused-expression634 expect(collection.MintMode).to.be.equal(true);638 expect(whiteListedAfter).to.be.true;635 });639 });636}640}637641