1
2
3
4
5
6import { IKeyringPair } from '@polkadot/types/types';
7import chai from 'chai';
8import chaiAsPromised from 'chai-as-promised';
9import privateKey from './substrate/privateKey';
10import usingApi, { submitTransactionExpectFailAsync } from './substrate/substrate-api';
11import {
12 addToWhiteListExpectSuccess,
13 createCollectionExpectSuccess,
14 createItemExpectSuccess,
15 destroyCollectionExpectSuccess,
16 enablePublicMintingExpectSuccess,
17 enableWhiteListExpectSuccess,
18 normalizeAccountId,
19} from './util/helpers';
20
21chai.use(chaiAsPromised);
22const expect = chai.expect;
23
24let Alice: IKeyringPair;
25let Bob: IKeyringPair;
26
27describe('Integration Test ext. addToWhiteList()', () => {
28
29 before(async () => {
30 await usingApi(async (api) => {
31 Alice = privateKey('//Alice');
32 Bob = privateKey('//Bob');
33 });
34 });
35
36 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
37 const collectionId = await createCollectionExpectSuccess();
38 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
39 });
40
41 it('Whitelisted minting: list restrictions', async () => {
42 const collectionId = await createCollectionExpectSuccess();
43 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
44 await enableWhiteListExpectSuccess(Alice, collectionId);
45 await enablePublicMintingExpectSuccess(Alice, collectionId);
46 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
47 });
48});
49
50describe('Negative Integration Test ext. addToWhiteList()', () => {
51
52 it('White list an address in the collection that does not exist', async () => {
53 await usingApi(async (api) => {
54
55 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
56 const Bob = privateKey('//Bob');
57
58 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));
59 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
60 });
61 });
62
63 it('White list an address in the collection that was destroyed', async () => {
64 await usingApi(async (api) => {
65 const Alice = privateKey('//Alice');
66 const Bob = privateKey('//Bob');
67
68 const collectionId = await createCollectionExpectSuccess();
69 await destroyCollectionExpectSuccess(collectionId);
70 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));
71 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
72 });
73 });
74
75 it('White list an address in the collection that does not have white list access enabled', async () => {
76 await usingApi(async (api) => {
77 const Alice = privateKey('//Alice');
78 const Ferdie = privateKey('//Ferdie');
79 const collectionId = await createCollectionExpectSuccess();
80 await enableWhiteListExpectSuccess(Alice, collectionId);
81 await enablePublicMintingExpectSuccess(Alice, collectionId);
82 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Ferdie.address), 'NFT');
83 await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;
84 });
85 });
86
87});