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

difftreelog

source

tests/src/addCollectionAdmin.test.ts4.3 KiBsourcehistory
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      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
45      await createCollectionExpectSuccess();
46    });
47  });
48  it("Can't add collection admin of not existing collection.", async () => {
49    await usingApi(async (api) => {
50      // tslint:disable-next-line: no-bitwise
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      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
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        'Fr4NzY1udSFFLzb2R3qxVQkwz9cZraWkyfH4h3mVVk7BK7P',
71        'DfnTB4z7eUvYRqcGtTpFsLC69o6tvBSC1pEv8vWPZFtCkaK',
72        'HnMAUz7r2G8G3hB27SYNyit5aJmh2a5P4eMdDtACtMFDbam',
73        'DE14BzQ1bDXWPKeLoAqdLAm1GpyAWaWF1knF74cEZeomTBM',
74      ];
75      const collectionId = await createCollectionExpectSuccess();
76
77      const chainLimit = await api.query.nft.chainLimit() as unknown as { collections_admins_limit: BN };
78      const chainLimitNumber = chainLimit.collections_admins_limit.toNumber();
79      expect(chainLimitNumber).to.be.equal(5);
80
81      for (let i = 0; i < chainLimitNumber; i++) {
82        const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, accounts[i]);
83        await submitTransactionAsync(Alice, changeAdminTx);
84        const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
85        adminListAfterAddAdmin.map((item: any) => console.log(item.toString()));
86        expect(adminListAfterAddAdmin).to.be.contains(accounts[i]);
87      }
88
89      const tx = api.tx.nft.addCollectionAdmin(collectionId, accounts[chainLimitNumber]);
90      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
91    });
92  });
93});