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
--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -56,10 +56,8 @@
     const collection = await helper.collection.getData(collectionId);
     expect(collection?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));
 
-    const changeAdminTxBob = () => helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address});
-    const changeAdminTxCharlie = () => helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address});
-    await expect(changeAdminTxCharlie()).to.be.rejectedWith(/common\.NoPermission/);
-    await expect(changeAdminTxBob()).to.be.rejectedWith(/common\.NoPermission/);
+    await expect(helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address})).to.be.rejectedWith(/common\.NoPermission/);
+    await expect(helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address})).to.be.rejectedWith(/common\.NoPermission/);
 
     const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);
     expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: charlie.address});
@@ -75,8 +73,7 @@
     const adminListAfterAddAdmin = await collection.getAdmins();
     expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});
 
-    const changeAdminTxCharlie = () => collection.addAdmin(bob, {Substrate: charlie.address});
-    await expect(changeAdminTxCharlie()).to.be.rejectedWith(/common\.NoPermission/);
+    await expect(collection.addAdmin(bob, {Substrate: charlie.address})).to.be.rejectedWith(/common\.NoPermission/);
 
     const adminListAfterAddNewAdmin = await collection.getAdmins();
     expect(adminListAfterAddNewAdmin).to.be.deep.contains({Substrate: bob.address});
@@ -87,8 +84,7 @@
     const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
     const collectionId = (1 << 32) - 1;
 
-    const addAdminTx = () => helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
-    await expect(addAdminTx()).to.be.rejectedWith(/common\.CollectionNotFound/);
+    await expect(helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejectedWith(/common\.CollectionNotFound/);
 
     // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
     await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});
@@ -99,8 +95,7 @@
     const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});
 
     await collection.burn(alice);
-    const addAdminTx = () => collection.addAdmin(alice, {Substrate: bob.address});
-    await expect(addAdminTx()).to.be.rejectedWith(/common\.CollectionNotFound/);
+    await expect(collection.addAdmin(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.CollectionNotFound/);
 
     // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
     await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});
@@ -119,7 +114,6 @@
       expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: accounts[i].address});
     }
 
-    const addExtraAdminTx = () => collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address});
-    await expect(addExtraAdminTx()).to.be.rejectedWith(/common\.CollectionAdminCountExceeded/);
+    await expect(collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address})).to.be.rejectedWith(/common\.CollectionAdminCountExceeded/);
   });
 });
modifiedtests/src/adminTransferAndBurn.test.tsdiffbeforeafterboth
before · tests/src/adminTransferAndBurn.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 {usingPlaygrounds, expect, itSub} from './util';1920describe('Integration Test: ownerCanTransfer allows admins to use only transferFrom/burnFrom:', () => {21  let alice: IKeyringPair;22  let bob: IKeyringPair;23  let charlie: IKeyringPair;2425  before(async () => {26    await usingPlaygrounds(async (helper, privateKey) => {27      const donor = await privateKey({filename: __filename});28      [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);29    });30  });3132  itSub('admin transfers other user\'s token', async ({helper}) => {33    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});34    await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});35    const limits = await helper.collection.getEffectiveLimits(collectionId);36    expect(limits.ownerCanTransfer).to.be.true;3738    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});39    const transferResult = () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});40    await expect(transferResult()).to.be.rejected;4142    await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address});43    const newTokenOwner = await helper.nft.getTokenOwner(collectionId, tokenId);44    expect(newTokenOwner.Substrate).to.be.equal(charlie.address);45  });4647  itSub('admin burns other user\'s token', async ({helper}) => {48    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});4950    await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});51    const limits = await helper.collection.getEffectiveLimits(collectionId);52    expect(limits.ownerCanTransfer).to.be.true;5354    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});55    const burnTxFailed = () => helper.nft.burnToken(alice, collectionId, tokenId);5657    await expect(burnTxFailed()).to.be.rejected;5859    await helper.nft.burnToken(bob, collectionId, tokenId);60    const token = await helper.nft.getToken(collectionId, tokenId);61    expect(token).to.be.null;62  });63});
after · tests/src/adminTransferAndBurn.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 {usingPlaygrounds, expect, itSub} from './util';1920describe('Integration Test: ownerCanTransfer allows admins to use only transferFrom/burnFrom:', () => {21  let alice: IKeyringPair;22  let bob: IKeyringPair;23  let charlie: IKeyringPair;2425  before(async () => {26    await usingPlaygrounds(async (helper, privateKey) => {27      const donor = await privateKey({filename: __filename});28      [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);29    });30  });3132  itSub('admin transfers other user\'s token', async ({helper}) => {33    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});34    await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});35    const limits = await helper.collection.getEffectiveLimits(collectionId);36    expect(limits.ownerCanTransfer).to.be.true;3738    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});39    await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address})).to.be.rejected;4041    await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address});42    const newTokenOwner = await helper.nft.getTokenOwner(collectionId, tokenId);43    expect(newTokenOwner.Substrate).to.be.equal(charlie.address);44  });4546  itSub('admin burns other user\'s token', async ({helper}) => {47    const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});4849    await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});50    const limits = await helper.collection.getEffectiveLimits(collectionId);51    expect(limits.ownerCanTransfer).to.be.true;5253    const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});5455    await expect(helper.nft.burnToken(alice, collectionId, tokenId)).to.be.rejected;5657    await helper.nft.burnToken(bob, collectionId, tokenId);58    const token = await helper.nft.getToken(collectionId, tokenId);59    expect(token).to.be.null;60  });61});