git.delta.rocks / unique-network / refs/commits / 9a3b0122b66d

difftreelog

Combine transactions and expects

Max Andreev2022-10-25parent: #c521d2f.patch.diff
in: master

2 files changed

modifiedtests/src/addCollectionAdmin.test.tsdiffbeforeafterboth
before · tests/src/addCollectionAdmin.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';1920describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {21  let donor: IKeyringPair;2223  before(async () => {24    await usingPlaygrounds(async (_, privateKey) => {25      donor = await privateKey({filename: __filename});26    });27  });2829  itSub('Add collection admin.', async ({helper}) => {30    const [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);31    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});3233    const collection = await helper.collection.getData(collectionId);34    expect(collection!.normalizedOwner!).to.be.equal(helper.address.normalizeSubstrate(alice.address));3536    await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});3738    const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);39    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});40  });41});4243describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {44  let donor: IKeyringPair;4546  before(async () => {47    await usingPlaygrounds(async (_, privateKey) => {48      donor = await privateKey({filename: __filename});49    });50  });5152  itSub("Not owner can't add collection admin.", async ({helper}) => {53    const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);54    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});5556    const collection = await helper.collection.getData(collectionId);57    expect(collection?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));5859    const changeAdminTxBob = () => helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address});60    const changeAdminTxCharlie = () => helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address});61    await expect(changeAdminTxCharlie()).to.be.rejectedWith(/common\.NoPermission/);62    await expect(changeAdminTxBob()).to.be.rejectedWith(/common\.NoPermission/);6364    const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);65    expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: charlie.address});66    expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: bob.address});67  });6869  itSub("Admin can't add collection admin.", async ({helper}) => {70    const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);71    const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});7273    await collection.addAdmin(alice, {Substrate: bob.address});7475    const adminListAfterAddAdmin = await collection.getAdmins();76    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});7778    const changeAdminTxCharlie = () => collection.addAdmin(bob, {Substrate: charlie.address});79    await expect(changeAdminTxCharlie()).to.be.rejectedWith(/common\.NoPermission/);8081    const adminListAfterAddNewAdmin = await collection.getAdmins();82    expect(adminListAfterAddNewAdmin).to.be.deep.contains({Substrate: bob.address});83    expect(adminListAfterAddNewAdmin).to.be.not.deep.contains({Substrate: charlie.address});84  });8586  itSub("Can't add collection admin of not existing collection.", async ({helper}) => {87    const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);88    const collectionId = (1 << 32) - 1;8990    const addAdminTx = () => helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});91    await expect(addAdminTx()).to.be.rejectedWith(/common\.CollectionNotFound/);9293    // Verifying that nothing bad happened (network is live, new collections can be created, etc.)94    await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});95  });9697  itSub("Can't add an admin to a destroyed collection.", async ({helper}) => {98    const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);99    const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});100101    await collection.burn(alice);102    const addAdminTx = () => collection.addAdmin(alice, {Substrate: bob.address});103    await expect(addAdminTx()).to.be.rejectedWith(/common\.CollectionNotFound/);104105    // Verifying that nothing bad happened (network is live, new collections can be created, etc.)106    await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});107  });108109  itSub('Add an admin to a collection that has reached the maximum number of admins limit', async ({helper}) => {110    const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);111    const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});112113    const chainAdminLimit = (helper.getApi().consts.common.collectionAdminsLimit as any).toNumber();114    expect(chainAdminLimit).to.be.equal(5);115116    for (let i = 0; i < chainAdminLimit; i++) {117      await collection.addAdmin(alice, {Substrate: accounts[i].address});118      const adminListAfterAddAdmin = await collection.getAdmins();119      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: accounts[i].address});120    }121122    const addExtraAdminTx = () => collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address});123    await expect(addExtraAdminTx()).to.be.rejectedWith(/common\.CollectionAdminCountExceeded/);124  });125});
after · tests/src/addCollectionAdmin.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';1920describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {21  let donor: IKeyringPair;2223  before(async () => {24    await usingPlaygrounds(async (_, privateKey) => {25      donor = await privateKey({filename: __filename});26    });27  });2829  itSub('Add collection admin.', async ({helper}) => {30    const [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);31    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});3233    const collection = await helper.collection.getData(collectionId);34    expect(collection!.normalizedOwner!).to.be.equal(helper.address.normalizeSubstrate(alice.address));3536    await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});3738    const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);39    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});40  });41});4243describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {44  let donor: IKeyringPair;4546  before(async () => {47    await usingPlaygrounds(async (_, privateKey) => {48      donor = await privateKey({filename: __filename});49    });50  });5152  itSub("Not owner can't add collection admin.", async ({helper}) => {53    const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);54    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});5556    const collection = await helper.collection.getData(collectionId);57    expect(collection?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));5859    await expect(helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address})).to.be.rejectedWith(/common\.NoPermission/);60    await expect(helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address})).to.be.rejectedWith(/common\.NoPermission/);6162    const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);63    expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: charlie.address});64    expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: bob.address});65  });6667  itSub("Admin can't add collection admin.", async ({helper}) => {68    const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);69    const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});7071    await collection.addAdmin(alice, {Substrate: bob.address});7273    const adminListAfterAddAdmin = await collection.getAdmins();74    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});7576    await expect(collection.addAdmin(bob, {Substrate: charlie.address})).to.be.rejectedWith(/common\.NoPermission/);7778    const adminListAfterAddNewAdmin = await collection.getAdmins();79    expect(adminListAfterAddNewAdmin).to.be.deep.contains({Substrate: bob.address});80    expect(adminListAfterAddNewAdmin).to.be.not.deep.contains({Substrate: charlie.address});81  });8283  itSub("Can't add collection admin of not existing collection.", async ({helper}) => {84    const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);85    const collectionId = (1 << 32) - 1;8687    await expect(helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejectedWith(/common\.CollectionNotFound/);8889    // Verifying that nothing bad happened (network is live, new collections can be created, etc.)90    await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});91  });9293  itSub("Can't add an admin to a destroyed collection.", async ({helper}) => {94    const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);95    const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});9697    await collection.burn(alice);98    await expect(collection.addAdmin(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.CollectionNotFound/);99100    // Verifying that nothing bad happened (network is live, new collections can be created, etc.)101    await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});102  });103104  itSub('Add an admin to a collection that has reached the maximum number of admins limit', async ({helper}) => {105    const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);106    const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});107108    const chainAdminLimit = (helper.getApi().consts.common.collectionAdminsLimit as any).toNumber();109    expect(chainAdminLimit).to.be.equal(5);110111    for (let i = 0; i < chainAdminLimit; i++) {112      await collection.addAdmin(alice, {Substrate: accounts[i].address});113      const adminListAfterAddAdmin = await collection.getAdmins();114      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: accounts[i].address});115    }116117    await expect(collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address})).to.be.rejectedWith(/common\.CollectionAdminCountExceeded/);118  });119});
modifiedtests/src/adminTransferAndBurn.test.tsdiffbeforeafterboth
--- a/tests/src/adminTransferAndBurn.test.ts
+++ b/tests/src/adminTransferAndBurn.test.ts
@@ -36,8 +36,7 @@
     expect(limits.ownerCanTransfer).to.be.true;
 
     const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
-    const transferResult = () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
-    await expect(transferResult()).to.be.rejected;
+    await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address})).to.be.rejected;
 
     await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address});
     const newTokenOwner = await helper.nft.getTokenOwner(collectionId, tokenId);
@@ -52,9 +51,8 @@
     expect(limits.ownerCanTransfer).to.be.true;
 
     const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
-    const burnTxFailed = () => helper.nft.burnToken(alice, collectionId, tokenId);
 
-    await expect(burnTxFailed()).to.be.rejected;
+    await expect(helper.nft.burnToken(alice, collectionId, tokenId)).to.be.rejected;
 
     await helper.nft.burnToken(bob, collectionId, tokenId);
     const token = await helper.nft.getToken(collectionId, tokenId);