difftreelog
tests fix
in: master
2 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -17,7 +17,8 @@
},
"scripts": {
"test": "mocha --timeout 9999999 -r ts-node/register ./**/*.test.ts",
- "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts"
+ "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",
+ "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts"
},
"author": "",
"license": "Apache 2.0",
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth1import chai from 'chai';
2import chaiAsPromised from 'chai-as-promised';
3import privateKey from './substrate/privateKey';
4import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
5import { createCollectionExpectSuccess } from './util/helpers';
6
7chai.use(chaiAsPromised);
8const expect = chai.expect;
9
10describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {
11 it('Add collection admin.', async () => {
12 await usingApi(async (api) => {
13 const collectionId = await createCollectionExpectSuccess();
14 const alice = privateKey('//Alice');
15 const bob = privateKey('//Bob');
16
17 const collection: any = (await api.query.nft.collection(collectionId));
18 expect(collection.Owner.toString()).to.be.eq(alice.address);
19
20 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, bob.address);
21 await submitTransactionAsync(alice, changeAdminTx);
22
23 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
24 expect(adminListAfterAddAdmin).to.be.contains(bob.address);
25 });
26 });
27});
28
29describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {
30 it("Not owner can't add collection admin.", async () => {
31 await usingApi(async (api) => {
32 const collectionId = await createCollectionExpectSuccess();
33 const alice = privateKey('//Alice');
34 const nonOwner = privateKey('//Bob_stash');
35
36 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, alice.address);
37 await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;
38
39 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
40 expect(adminListAfterAddAdmin).not.to.be.contains(alice.address);
41
42 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
43 await createCollectionExpectSuccess();
44 });
45 });
46 it("Can't add collection admin of not existing collection.", async () => {
47 await usingApi(async (api) => {
48 // tslint:disable-next-line: no-bitwise
49 const collectionId = (1 << 32) - 1;
50 const alice = privateKey('//Alice');
51 const bob = privateKey('//Bob');
52
53 const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, bob.address);
54 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
55
56 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
57 await createCollectionExpectSuccess();
58 });
59 });
60});
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 '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});