1import { ApiPromise } from '@polkadot/api';
2import BN from 'bn.js';
3import chai from 'chai';
4import chaiAsPromised from 'chai-as-promised';
5import privateKey from './substrate/privateKey';
6import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
7import { createCollectionExpectSuccess } from './util/helpers';
8
9chai.use(chaiAsPromised);
10const expect = chai.expect;
11
12describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {
13 it('Add collection admin.', async () => {
14 await usingApi(async (api) => {
15 const collectionId = await createCollectionExpectSuccess();
16 const alice = privateKey('//Alice');
17 const bob = privateKey('//Bob');
18
19 const collection: any = (await api.query.nft.collection(collectionId));
20 expect(collection.Owner.toString()).to.be.eq(alice.address);
21
22 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, bob.address);
23 await submitTransactionAsync(alice, changeAdminTx);
24
25 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
26 expect(adminListAfterAddAdmin).to.be.contains(bob.address);
27 });
28 });
29});
30
31describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {
32 it("Not owner can't add collection admin.", async () => {
33 await usingApi(async (api) => {
34 const collectionId = await createCollectionExpectSuccess();
35 const alice = privateKey('//Alice');
36 const nonOwner = privateKey('//Bob_stash');
37
38 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, alice.address);
39 await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;
40
41 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
42 expect(adminListAfterAddAdmin).not.to.be.contains(alice.address);
43
44
45 await createCollectionExpectSuccess();
46 });
47 });
48 it("Can't add collection admin of not existing collection.", async () => {
49 await usingApi(async (api) => {
50
51 const collectionId = (1 << 32) - 1;
52 const alice = privateKey('//Alice');
53 const bob = privateKey('//Bob');
54
55 const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, bob.address);
56 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
57
58
59 await createCollectionExpectSuccess();
60 });
61 });
62
63 it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {
64 await usingApi(async (api: ApiPromise) => {
65 const Alice = privateKey('//Alice');
66 const accounts = [
67 'GsvVmjr1CBHwQHw84pPHMDxgNY3iBLz6Qn7qS3CH8qPhrHz',
68 'FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP',
69 'JKspFU6ohf1Grg3Phdzj2pSgWvsYWzSfKghhfzMbdhNBWs5',
70 'JKspFU6ohf1Grg3Phdzj2pSgWvsYWzSfKghhfzMbdhNBWs5',
71 'Fr4NzY1udSFFLzb2R3qxVQkwz9cZraWkyfH4h3mVVk7BK7P',
72 'DfnTB4z7eUvYRqcGtTpFsLC69o6tvBSC1pEv8vWPZFtCkaK',
73 'HnMAUz7r2G8G3hB27SYNyit5aJmh2a5P4eMdDtACtMFDbam',
74 'DE14BzQ1bDXWPKeLoAqdLAm1GpyAWaWF1knF74cEZeomTBM',
75 ];
76 const collectionId = await createCollectionExpectSuccess();
77
78 const chainLimit = await api.query.nft.chainLimit() as unknown as { collections_admins_limit: BN };
79 const chainLimitNumber = chainLimit.collections_admins_limit.toNumber();
80 expect(chainLimitNumber).to.be.equal(5);
81
82 for (let i = 0; i < chainLimitNumber - 1; i++) {
83 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, accounts[i]);
84 await submitTransactionAsync(Alice, changeAdminTx);
85 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
86 adminListAfterAddAdmin.map((item: any) => console.log(item.toString()));
87 expect(adminListAfterAddAdmin).to.be.contains(accounts[i]);
88 }
89
90 const tx = api.tx.nft.addCollectionAdmin(collectionId, accounts[chainLimitNumber - 1]);
91 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
92 });
93 });
94});