git.delta.rocks / unique-network / refs/commits / 23e0b8caf5e4

difftreelog

source

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