difftreelog
Fix addToWhiteList tests
in: master
3 files changed
tests/src/addToWhiteList.test.tsdiffbeforeafterboth1import chai from 'chai';
2import chaiAsPromised from 'chai-as-promised';
3import privateKey from './substrate/privateKey';
4import usingApi, { submitTransactionExpectFailAsync } from './substrate/substrate-api';
5import {
6 addToWhiteListExpectSuccess,
7 createCollectionExpectSuccess,
8 createItemExpectSuccess,
9 destroyCollectionExpectSuccess,
10 enablePublicMintingExpectSuccess,
11 enableWhiteListExpectSuccess,
12} from './util/helpers';
13
14chai.use(chaiAsPromised);
15const expect = chai.expect;
16
17describe('Integration Test ext. addToWhiteList()', () => {
18
19 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
20 await usingApi(async (api) => {
21 const Alice = privateKey('//Alice');
22 const Bob = privateKey('//Bob');
23 const collectionId = await createCollectionExpectSuccess();
24 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
25 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
26 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
27 // tslint:disable-next-line: no-unused-expression
28 expect(whiteListedBefore).to.be.false;
29 // tslint:disable-next-line: no-unused-expression
30 expect(whiteListedAfter).to.be.true;
31 });
32 });
33
34 it('Whitelisted minting: list restrictions', async () => {
35 await usingApi(async (api) => {
36 const Alice = privateKey('//Alice');
37 const Bob = privateKey('//Bob');
38 const collectionId = await createCollectionExpectSuccess();
39 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
40 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
41 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
42 // tslint:disable-next-line: no-unused-expression
43 expect(whiteListedBefore).to.be.false;
44 // tslint:disable-next-line: no-unused-expression
45 expect(whiteListedAfter).to.be.true;
46 await enableWhiteListExpectSuccess(Alice, collectionId);
47 await enablePublicMintingExpectSuccess(Alice, collectionId);
48 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
49 });
50 });
51});
52
53describe('Negative Integration Test ext. addToWhiteList()', () => {
54
55 it('White list an address in the collection that does not exist', async () => {
56 await usingApi(async (api) => {
57 const Alice = privateKey('//Alice');
58 // tslint:disable-next-line: no-bitwise
59 const collectionId = (1 << 32) - 1;
60 const Bob = privateKey('//Bob');
61
62 const tx = api.tx.nft.addToWhiteList(collectionId, Bob.address);
63 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
64 });
65 });
66
67 it('White list an address in the collection that was destroyed', async () => {
68 await usingApi(async (api) => {
69 const Alice = privateKey('//Alice');
70 const Bob = privateKey('//Bob');
71 // tslint:disable-next-line: no-bitwise
72 const collectionId = await createCollectionExpectSuccess();
73 await destroyCollectionExpectSuccess(collectionId);
74 const tx = api.tx.nft.addToWhiteList(collectionId, Bob.address);
75 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
76 });
77 });
78
79 it('White list an address in the collection that does not have white list access enabled', async () => {
80 await usingApi(async (api) => {
81 const Alice = privateKey('//Alice');
82 const Ferdie = privateKey('//Ferdie');
83 const collectionId = await createCollectionExpectSuccess();
84 await enableWhiteListExpectSuccess(Alice, collectionId);
85 await enablePublicMintingExpectSuccess(Alice, collectionId);
86 const tx = api.tx.nft.createItem(collectionId, Ferdie.address, 'NFT');
87 await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;
88 });
89 });
90
91});
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.tsdiffbeforeafterboth--- 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;
});
}