difftreelog
tests fixes
in: master
1 file changed
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth1import { 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});
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, destroyCollectionExpectSuccess} 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 it('Add admin using added collection admin.', async () => {
31 await usingApi(async (api) => {
32 const collectionId = await createCollectionExpectSuccess();
33 const Alice = privateKey('//Alice');
34 const Bob = privateKey('//Bob');
35 const Charlie = privateKey('//CHARLIE');
36
37 const collection: any = (await api.query.nft.collection(collectionId));
38 expect(collection.Owner.toString()).to.be.eq(Alice.address);
39
40 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
41 await submitTransactionAsync(Alice, changeAdminTx);
42
43 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
44 expect(adminListAfterAddAdmin).to.be.contains(Bob.address);
45
46 const changeAdminTxCharlie = api.tx.nft.addCollectionAdmin(collectionId, Charlie.address);
47 await submitTransactionAsync(Bob, changeAdminTxCharlie);
48 const adminListAfterAddNewAdmin: any = (await api.query.nft.adminList(collectionId));
49 expect(adminListAfterAddNewAdmin).to.be.contains(Charlie.address);
50 });
51 });
52});
53
54describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {
55 it("Not owner can't add collection admin.", async () => {
56 await usingApi(async (api) => {
57 const collectionId = await createCollectionExpectSuccess();
58 const alice = privateKey('//Alice');
59 const nonOwner = privateKey('//Bob_stash');
60
61 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, alice.address);
62 await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;
63
64 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
65 expect(adminListAfterAddAdmin).not.to.be.contains(alice.address);
66
67 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
68 await createCollectionExpectSuccess();
69 });
70 });
71 it("Can't add collection admin of not existing collection.", async () => {
72 await usingApi(async (api) => {
73 // tslint:disable-next-line: no-bitwise
74 const collectionId = (1 << 32) - 1;
75 const alice = privateKey('//Alice');
76 const bob = privateKey('//Bob');
77
78 const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, bob.address);
79 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
80
81 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
82 await createCollectionExpectSuccess();
83 });
84 });
85
86 it("Can't add collection admin of destroyed collection.", async () => {
87 await usingApi(async (api) => {
88 const collectionId = await createCollectionExpectSuccess();
89 const Alice = privateKey('//Alice');
90 const Bob = privateKey('//Bob');
91 await destroyCollectionExpectSuccess(collectionId);
92 const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
93 await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;
94
95 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
96 await createCollectionExpectSuccess();
97 });
98 });
99
100 it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {
101 await usingApi(async (api: ApiPromise) => {
102 const Alice = privateKey('//Alice');
103 const accounts = [
104 'GsvVmjr1CBHwQHw84pPHMDxgNY3iBLz6Qn7qS3CH8qPhrHz',
105 'FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP',
106 'JKspFU6ohf1Grg3Phdzj2pSgWvsYWzSfKghhfzMbdhNBWs5',
107 'Fr4NzY1udSFFLzb2R3qxVQkwz9cZraWkyfH4h3mVVk7BK7P',
108 'DfnTB4z7eUvYRqcGtTpFsLC69o6tvBSC1pEv8vWPZFtCkaK',
109 'HnMAUz7r2G8G3hB27SYNyit5aJmh2a5P4eMdDtACtMFDbam',
110 'DE14BzQ1bDXWPKeLoAqdLAm1GpyAWaWF1knF74cEZeomTBM',
111 ];
112 const collectionId = await createCollectionExpectSuccess();
113
114 const chainLimit = await api.query.nft.chainLimit() as unknown as { collections_admins_limit: BN };
115 const chainLimitNumber = chainLimit.collections_admins_limit.toNumber();
116 expect(chainLimitNumber).to.be.equal(5);
117
118 for (let i = 0; i < chainLimitNumber; i++) {
119 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, accounts[i]);
120 await submitTransactionAsync(Alice, changeAdminTx);
121 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
122 expect(adminListAfterAddAdmin).to.be.contains(accounts[i]);
123 }
124
125 const tx = api.tx.nft.addCollectionAdmin(collectionId, accounts[chainLimitNumber]);
126 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
127 });
128 });
129});