git.delta.rocks / unique-network / refs/commits / e3aef6f9aee5

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  normalizeAccountId,
21} from './util/helpers';
22import { utf16ToStr } from './util/util';
23
24chai.use(chaiAsPromised);
25const expect = chai.expect;
26
27let Alice: IKeyringPair;
28let Bob: IKeyringPair;
29
30describe('Integration Test setPublicAccessMode(): ', () => {
31  before(async () => {
32    await usingApi(async (api) => {
33      Alice = privateKey('//Alice');
34      Bob = privateKey('//Bob');
35    });
36  });
37
38  it('Run extrinsic with collection id parameters, set the whitelist mode for the collection', async () => {
39    await usingApi(async (api: ApiPromise) => {
40      const collectionId: number = await createCollectionExpectSuccess();
41      await enableWhiteListExpectSuccess(Alice, collectionId);
42      await enablePublicMintingExpectSuccess(Alice, collectionId);
43      await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
44      await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
45    });
46  });
47
48  it('Whitelisted collection limits', async () => {
49    await usingApi(async (api: ApiPromise) => {
50      const collectionId = await createCollectionExpectSuccess();
51      await enableWhiteListExpectSuccess(Alice, collectionId);
52      await enablePublicMintingExpectSuccess(Alice, collectionId);
53      const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Bob.address), 'NFT');
54      await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
55    });
56  });
57});
58
59describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {
60  it('Set a non-existent collection', async () => {
61    await usingApi(async (api: ApiPromise) => {
62      // tslint:disable-next-line: radix
63      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
64      const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
65      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
66    });
67  });
68
69  it('Set the collection that has been deleted', async () => {
70    await usingApi(async (api: ApiPromise) => {
71      // tslint:disable-next-line: no-bitwise
72      const collectionId = await createCollectionExpectSuccess();
73      await destroyCollectionExpectSuccess(collectionId);
74      const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
75      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
76    });
77  });
78
79  it('Re-set the list mode already set in quantity', async () => {
80    await usingApi(async (api: ApiPromise) => {
81      const collectionId: number = await createCollectionExpectSuccess();
82      await enableWhiteListExpectSuccess(Alice, collectionId);
83      await enableWhiteListExpectSuccess(Alice, collectionId);
84    });
85  });
86
87  it('Execute method not on behalf of the collection owner', async () => {
88    await usingApi(async (api: ApiPromise) => {
89      // tslint:disable-next-line: no-bitwise
90      const collectionId = await createCollectionExpectSuccess();
91      const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
92      await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
93    });
94  });
95});