1
2import { ApiPromise, Keyring } from '@polkadot/api';
3import { IKeyringPair } from '@polkadot/types/types';
4import chai from 'chai';
5import chaiAsPromised from 'chai-as-promised';
6import privateKey from './substrate/privateKey';
7import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
8import {
9 addToWhiteListExpectSuccess,
10 createCollectionExpectSuccess,
11 createItemExpectSuccess,
12 destroyCollectionExpectSuccess,
13 enablePublicMintingExpectSuccess,
14 enableWhiteListExpectSuccess,
15} from './util/helpers';
16import { utf16ToStr } from './util/util';
17
18chai.use(chaiAsPromised);
19const expect = chai.expect;
20
21let Alice: IKeyringPair;
22let Bob: IKeyringPair;
23
24describe('Integration Test setPublicAccessMode(): ', () => {
25 before(async () => {
26 await usingApi(async (api) => {
27 Alice = privateKey('//Alice');
28 Bob = privateKey('//Bob');
29 });
30 });
31
32 it('Run extrinsic with collection id parameters, set the whitelist mode for the collection', async () => {
33 await usingApi(async (api: ApiPromise) => {
34 const collectionId: number = await createCollectionExpectSuccess();
35 await enableWhiteListExpectSuccess(Alice, collectionId);
36 await enablePublicMintingExpectSuccess(Alice, collectionId);
37 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
38 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
39 });
40 });
41
42 it('Whitelisted collection limits', async () => {
43 await usingApi(async (api: ApiPromise) => {
44 const collectionId = await createCollectionExpectSuccess();
45 await enableWhiteListExpectSuccess(Alice, collectionId);
46 await enablePublicMintingExpectSuccess(Alice, collectionId);
47 const tx = api.tx.nft.createItem(collectionId, Bob.address, 'NFT');
48 await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
49 });
50 });
51});
52
53describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {
54 it('Set a non-existent collection', async () => {
55 await usingApi(async (api: ApiPromise) => {
56
57 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
58 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
59 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
60 });
61 });
62
63 it('Set the collection that has been deleted', async () => {
64 await usingApi(async (api: ApiPromise) => {
65
66 const collectionId = await createCollectionExpectSuccess();
67 await destroyCollectionExpectSuccess(collectionId);
68 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
69 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
70 });
71 });
72
73 it('Re-set the list mode already set in quantity', async () => {
74 await usingApi(async (api: ApiPromise) => {
75 const collectionId: number = await createCollectionExpectSuccess();
76 await enableWhiteListExpectSuccess(Alice, collectionId);
77 await enableWhiteListExpectSuccess(Alice, collectionId);
78 });
79 });
80
81 it('Execute method not on behalf of the collection owner', async () => {
82 await usingApi(async (api: ApiPromise) => {
83
84 const collectionId = await createCollectionExpectSuccess();
85 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
86 await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
87 });
88 });
89});