difftreelog
Merge pull request #76 from usetech-llc/feature/NFTPAR-252_setMintPermission
in: master
Add tests for setMintPermission
3 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -36,6 +36,7 @@
"testAddToContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractWhiteList.test.ts",
"testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",
"testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",
+ "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",
"testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
"testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
"testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts"
tests/src/setMintPermission.test.tsdiffbeforeafterboth1import { IKeyringPair } from '@polkadot/types/types';2import privateKey from './substrate/privateKey';3import usingApi from './substrate/substrate-api';4import {5 addToWhiteListExpectSuccess,6 createCollectionExpectSuccess,7 createItemExpectFailure,8 createItemExpectSuccess,9 destroyCollectionExpectSuccess,10 enableWhiteListExpectSuccess,11 findNotExistingCollection,12 setMintPermissionExpectFailure,13 setMintPermissionExpectSuccess,14} from './util/helpers';1516describe('Integration Test setMintPermission', () => {17 let alice: IKeyringPair;18 let bob: IKeyringPair;1920 before(async () => {21 await usingApi(async () => {22 alice = privateKey('//Alice');23 bob = privateKey('//Bob');24 });25 });2627 it('ensure white-listed non-privileged address can mint tokens', async () => {28 await usingApi(async () => {29 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });30 await enableWhiteListExpectSuccess(alice, collectionId);31 await setMintPermissionExpectSuccess(alice, collectionId, true);32 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);3334 await createItemExpectSuccess(bob, collectionId, 'NFT');35 });36 });3738 it('can be enabled twice', async () => {39 await usingApi(async () => {40 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });41 await setMintPermissionExpectSuccess(alice, collectionId, true);42 await setMintPermissionExpectSuccess(alice, collectionId, true);43 });44 });4546 it('can be disabled twice', async () => {47 await usingApi(async () => {48 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });49 await setMintPermissionExpectSuccess(alice, collectionId, true);50 await setMintPermissionExpectSuccess(alice, collectionId, false);51 await setMintPermissionExpectSuccess(alice, collectionId, false);52 });53 });54});5556describe('Negative Integration Test setMintPermission', () => {57 let alice: IKeyringPair;58 let bob: IKeyringPair;5960 before(async () => {61 await usingApi(async () => {62 alice = privateKey('//Alice');63 bob = privateKey('//Bob');64 });65 });6667 it('fails on not existing collection', async () => {68 await usingApi(async (api) => {69 const nonExistingCollection = await findNotExistingCollection(api);70 await setMintPermissionExpectFailure(alice, nonExistingCollection, true);71 });72 });7374 it('fails on removed collection', async () => {75 await usingApi(async () => {76 const removedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });77 await destroyCollectionExpectSuccess(removedCollectionId);7879 await setMintPermissionExpectFailure(alice, removedCollectionId, true);80 });81 });8283 it('fails when not collection owner tries to set mint status', async () => {84 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });85 await enableWhiteListExpectSuccess(alice, collectionId);86 await setMintPermissionExpectFailure(bob, collectionId, true);87 });8889 it('ensure non-white-listed non-privileged address can\'t mint tokens', async () => {90 await usingApi(async () => {91 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });92 await enableWhiteListExpectSuccess(alice, collectionId);93 await setMintPermissionExpectSuccess(alice, collectionId, true);9495 await createItemExpectFailure(bob, collectionId, 'NFT');96 });97 });98});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -645,6 +645,17 @@
return newItemId;
}
+export async function createItemExpectFailure(
+ sender: IKeyringPair, collectionId: number, createMode: string, owner: string = sender.address) {
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.createItem(collectionId, owner, createMode);
+ const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+ const result = getCreateItemResult(events);
+
+ expect(result.success).to.be.false;
+ });
+}
+
export async function setPublicAccessModeExpectSuccess(
sender: IKeyringPair, collectionId: number,
accessMode: 'Normal' | 'WhiteList',
@@ -674,11 +685,11 @@
await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');
}
-export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {
+export async function setMintPermissionExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {
await usingApi(async (api) => {
// Run the transaction
- const tx = api.tx.nft.setMintPermission(collectionId, true);
+ const tx = api.tx.nft.setMintPermission(collectionId, enabled);
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
@@ -686,8 +697,24 @@
const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
// What to expect
+ // tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- expect(collection.MintMode).to.be.equal(true);
+ expect(collection.MintMode).to.be.equal(enabled);
+ });
+}
+
+export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {
+ await setMintPermissionExpectSuccess(sender, collectionId, true);
+}
+
+export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {
+ await usingApi(async (api) => {
+ // Run the transaction
+ const tx = api.tx.nft.setMintPermission(collectionId, enabled);
+ const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+ const result = getCreateCollectionResult(events);
+ // tslint:disable-next-line:no-unused-expression
+ expect(result.success).to.be.false;
});
}