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