From a246f26dcdebea5e8ed03a43793f59d270e06fef Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Tue, 19 Jan 2021 16:38:30 +0000 Subject: [PATCH] Fix addToWhiteList tests --- --- a/tests/src/addToWhiteList.test.ts +++ b/tests/src/addToWhiteList.test.ts @@ -1,3 +1,4 @@ +import { IKeyringPair } from '@polkadot/types/types'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import privateKey from './substrate/privateKey'; @@ -14,49 +15,38 @@ chai.use(chaiAsPromised); const expect = chai.expect; -describe('Integration Test ext. addToWhiteList()', () => { +let Alice: IKeyringPair; +let Bob: IKeyringPair; - it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => { +describe.only('Integration Test ext. addToWhiteList()', () => { + + before(async () => { await usingApi(async (api) => { - const Alice = privateKey('//Alice'); - const Bob = privateKey('//Bob'); - const collectionId = await createCollectionExpectSuccess(); - const whiteListedBefore = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON(); - await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address); - const whiteListedAfter = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON(); - // tslint:disable-next-line: no-unused-expression - expect(whiteListedBefore).to.be.false; - // tslint:disable-next-line: no-unused-expression - expect(whiteListedAfter).to.be.true; + 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 () => { - await usingApi(async (api) => { - const Alice = privateKey('//Alice'); - const Bob = privateKey('//Bob'); - const collectionId = await createCollectionExpectSuccess(); - const whiteListedBefore = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON(); - await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address); - const whiteListedAfter = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON(); - // tslint:disable-next-line: no-unused-expression - expect(whiteListedBefore).to.be.false; - // tslint:disable-next-line: no-unused-expression - expect(whiteListedAfter).to.be.true; - await enableWhiteListExpectSuccess(Alice, collectionId); - await enablePublicMintingExpectSuccess(Alice, collectionId); - await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address); - }); + 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('Negative Integration Test ext. addToWhiteList()', () => { +describe.only('Negative Integration Test ext. addToWhiteList()', () => { it('White list an address in the collection that does not exist', async () => { await usingApi(async (api) => { - const Alice = privateKey('//Alice'); // tslint:disable-next-line: no-bitwise - const collectionId = (1 << 32) - 1; + const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1; const Bob = privateKey('//Bob'); const tx = api.tx.nft.addToWhiteList(collectionId, Bob.address); --- 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"); --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -550,17 +550,21 @@ export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) { await usingApi(async (api) => { + const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON(); + // Run the transaction const tx = api.tx.nft.addToWhiteList(collectionId, address); const events = await submitTransactionAsync(sender, tx); const result = getGenericResult(events); - // Get the collection - const collection: any = (await api.query.nft.collection(collectionId)).toJSON(); + const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON(); // What to expect expect(result.success).to.be.true; - expect(collection.MintMode).to.be.equal(true); + // tslint:disable-next-line: no-unused-expression + expect(whiteListedBefore).to.be.false; + // tslint:disable-next-line: no-unused-expression + expect(whiteListedAfter).to.be.true; }); } -- gitstuff