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

difftreelog

CORE-386 Fix names and tests

Trubnikov Sergey2022-06-10parent: #84e2b3d.patch.diff
in: master

8 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -211,7 +211,7 @@
 		Ok(())
 	}
 
-	#[solidity(rename_selector = "setNesting")]
+	#[solidity(rename_selector = "setCollectionNesting")]
 	fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {
 		check_is_owner_or_admin(caller, self)?;
 		let permissions = CollectionPermissions {
@@ -231,7 +231,7 @@
 		save(self)
 	}
 
-	#[solidity(rename_selector = "setNesting")]
+	#[solidity(rename_selector = "setCollectionNesting")]
 	fn set_nesting(
 		&mut self,
 		caller: caller,
@@ -309,7 +309,7 @@
 		Ok(())
 	}
 
-	fn set_mint_mode(&mut self, caller: caller, mode: bool) -> Result<void> {
+	fn set_collection_mint_mode(&mut self, caller: caller, mode: bool) -> Result<void> {
 		check_is_owner_or_admin(caller, self)?;
 		let permissions = CollectionPermissions { mint_mode: Some(mode), .. Default::default() };
 		self.collection.permissions = <Pallet<T>>::clamp_permissions(
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -330,7 +330,7 @@
 	}
 }
 
-// Selector: c0de6be0
+// Selector: 7d9262e6
 contract Collection is Dummy, ERC165 {
 	// Selector: setCollectionProperty(string,bytes) 2f073f66
 	function setCollectionProperty(string memory key, bytes memory value)
@@ -427,15 +427,17 @@
 		dummy;
 	}
 
-	// Selector: setNesting(bool) e8fc50dd
-	function setNesting(bool enable) public {
+	// Selector: setCollectionNesting(bool) 112d4586
+	function setCollectionNesting(bool enable) public {
 		require(false, stub_error);
 		enable;
 		dummy = 0;
 	}
 
-	// Selector: setNesting(bool,address[]) 7df12a9a
-	function setNesting(bool enable, address[] memory collections) public {
+	// Selector: setCollectionNesting(bool,address[]) 64872396
+	function setCollectionNesting(bool enable, address[] memory collections)
+		public
+	{
 		require(false, stub_error);
 		enable;
 		collections;
@@ -463,8 +465,8 @@
 		dummy;
 	}
 
-	// Selector: setMintMode(bool) 5dea9bd5
-	function setMintMode(bool mode) public {
+	// Selector: setCollectionMintMode(bool) 00018e84
+	function setCollectionMintMode(bool mode) public {
 		require(false, stub_error);
 		mode;
 		dummy = 0;
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -191,7 +191,7 @@
 	function totalSupply() external view returns (uint256);
 }
 
-// Selector: c0de6be0
+// Selector: 7d9262e6
 interface Collection is Dummy, ERC165 {
 	// Selector: setCollectionProperty(string,bytes) 2f073f66
 	function setCollectionProperty(string memory key, bytes memory value)
@@ -235,11 +235,12 @@
 	// Selector: removeCollectionAdmin(address) fafd7b42
 	function removeCollectionAdmin(address admin) external view;
 
-	// Selector: setNesting(bool) e8fc50dd
-	function setNesting(bool enable) external;
+	// Selector: setCollectionNesting(bool) 112d4586
+	function setCollectionNesting(bool enable) external;
 
-	// Selector: setNesting(bool,address[]) 7df12a9a
-	function setNesting(bool enable, address[] memory collections) external;
+	// Selector: setCollectionNesting(bool,address[]) 64872396
+	function setCollectionNesting(bool enable, address[] memory collections)
+		external;
 
 	// Selector: setCollectionAccess(uint8) 41835d4c
 	function setCollectionAccess(uint8 mode) external;
@@ -250,8 +251,8 @@
 	// Selector: removeFromCollectionAllowList(address) 85c51acb
 	function removeFromCollectionAllowList(address user) external view;
 
-	// Selector: setMintMode(bool) 5dea9bd5
-	function setMintMode(bool mode) external;
+	// Selector: setCollectionMintMode(bool) 00018e84
+	function setCollectionMintMode(bool mode) external;
 }
 
 // Selector: d74d154f
modifiedtests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth
before · tests/src/eth/collectionAdmin.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.3// Unique Network is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7//8// Unique Network is distributed in the hope that it will be useful,9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the11// GNU General Public License for more details.1213// You should have received a copy of the GNU General Public License14// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1516import {expect} from 'chai';17import privateKey from '../substrate/privateKey';18import {19  createEthAccount,20  createEthAccountWithBalance, 21  evmCollection, 22  evmCollectionHelpers, 23  getCollectionAddressFromResult, 24  itWeb3,25} from './util/helpers';2627describe('Add collection admins', () => {28  itWeb3('Add admin by owner', async ({api, web3}) => {29    const owner = await createEthAccountWithBalance(api, web3);30    const collectionHelper = evmCollectionHelpers(web3, owner);31        32    const result = await collectionHelper.methods33      .createNonfungibleCollection('A', 'B', 'C')34      .send();35    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);3637    const newAdmin = await createEthAccount(web3);38    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);39    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();40    const adminList = await api.rpc.unique.adminlist(collectionId);41    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())42      .to.be.eq(newAdmin.toLocaleLowerCase());43  });4445  itWeb3('Add substrate admin by owner', async ({api, web3}) => {46    const owner = await createEthAccountWithBalance(api, web3);47    const collectionHelper = evmCollectionHelpers(web3, owner);48        49    const result = await collectionHelper.methods50      .createNonfungibleCollection('A', 'B', 'C')51      .send();52    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);5354    const newAdmin = privateKey('//Alice');55    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);56    await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();5758    const adminList = await api.rpc.unique.adminlist(collectionId);59    expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())60      .to.be.eq(newAdmin.address.toLocaleLowerCase());61  });6263  itWeb3('(!negative tests!) Add admin by ADMIN is not allowed', async ({api, web3}) => {64    const owner = await createEthAccountWithBalance(api, web3);65    const collectionHelper = evmCollectionHelpers(web3, owner);66        67    const result = await collectionHelper.methods68      .createNonfungibleCollection('A', 'B', 'C')69      .send();70    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);7172    const admin = await createEthAccountWithBalance(api, web3);73    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);74    await collectionEvm.methods.addCollectionAdmin(admin).send();75    76    const user = await createEthAccount(web3);77    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))78      .to.be.rejectedWith('NoPermission');7980    const adminList = await api.rpc.unique.adminlist(collectionId);81    expect(adminList.length).to.be.eq(1);82    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())83      .to.be.eq(admin.toLocaleLowerCase());84  });8586  itWeb3('(!negative tests!) Add admin by USER is not allowed', async ({api, web3}) => {87    const owner = await createEthAccountWithBalance(api, web3);88    const collectionHelper = evmCollectionHelpers(web3, owner);89        90    const result = await collectionHelper.methods91      .createNonfungibleCollection('A', 'B', 'C')92      .send();93    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);9495    const notAdmin = await createEthAccountWithBalance(api, web3);96    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);97    98    const user = await createEthAccount(web3);99    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))100      .to.be.rejectedWith('NoPermission');101102    const adminList = await api.rpc.unique.adminlist(collectionId);103    expect(adminList.length).to.be.eq(0);104  });105106  itWeb3('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({api, web3}) => {107    const owner = await createEthAccountWithBalance(api, web3);108    const collectionHelper = evmCollectionHelpers(web3, owner);109        110    const result = await collectionHelper.methods111      .createNonfungibleCollection('A', 'B', 'C')112      .send();113    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);114115    const admin = await createEthAccountWithBalance(api, web3);116    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);117    await collectionEvm.methods.addCollectionAdmin(admin).send();118119    const notAdmin = privateKey('//Alice');120    await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))121      .to.be.rejectedWith('NoPermission');122123    const adminList = await api.rpc.unique.adminlist(collectionId);124    expect(adminList.length).to.be.eq(1);125    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())126      .to.be.eq(admin.toLocaleLowerCase());127  });128  129  itWeb3('(!negative tests!) Add substrate admin by USER is not allowed', async ({api, web3}) => {130    const owner = await createEthAccountWithBalance(api, web3);131    const collectionHelper = evmCollectionHelpers(web3, owner);132        133    const result = await collectionHelper.methods134      .createNonfungibleCollection('A', 'B', 'C')135      .send();136    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);137138    const notAdmin0 = await createEthAccountWithBalance(api, web3);139    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);140    const notAdmin1 = privateKey('//Alice');141    await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))142      .to.be.rejectedWith('NoPermission');143144    const adminList = await api.rpc.unique.adminlist(collectionId);145    expect(adminList.length).to.be.eq(0);146  });147});148149describe('Remove collection admins', () => {150  itWeb3('Remove admin by owner', async ({api, web3}) => {151    const owner = await createEthAccountWithBalance(api, web3);152    const collectionHelper = evmCollectionHelpers(web3, owner);153        154    const result = await collectionHelper.methods155      .createNonfungibleCollection('A', 'B', 'C')156      .send();157    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);158159    const newAdmin = await createEthAccount(web3);160    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);161    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();162    {163      const adminList = await api.rpc.unique.adminlist(collectionId);164      expect(adminList.length).to.be.eq(1);165      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())166        .to.be.eq(newAdmin.toLocaleLowerCase());167    }168169    await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();170    const adminList = await api.rpc.unique.adminlist(collectionId);171    expect(adminList.length).to.be.eq(0);172  });173174  itWeb3('Remove substrate admin by owner', async ({api, web3}) => {175    const owner = await createEthAccountWithBalance(api, web3);176    const collectionHelper = evmCollectionHelpers(web3, owner);177        178    const result = await collectionHelper.methods179      .createNonfungibleCollection('A', 'B', 'C')180      .send();181    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);182183    const newAdmin = privateKey('//Alice');184    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);185    await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();186    {187      const adminList = await api.rpc.unique.adminlist(collectionId);188      expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())189        .to.be.eq(newAdmin.address.toLocaleLowerCase());190    }191    192    await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();193    const adminList = await api.rpc.unique.adminlist(collectionId);194    expect(adminList.length).to.be.eq(0);195  });196197  itWeb3('(!negative tests!) Remove admin by ADMIN is not allowed', async ({api, web3}) => {198    const owner = await createEthAccountWithBalance(api, web3);199    const collectionHelper = evmCollectionHelpers(web3, owner);200        201    const result = await collectionHelper.methods202      .createNonfungibleCollection('A', 'B', 'C')203      .send();204    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);205206    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);207208    const admin0 = await createEthAccountWithBalance(api, web3);209    await collectionEvm.methods.addCollectionAdmin(admin0).send();210    const admin1 = await createEthAccount(web3);211    await collectionEvm.methods.addCollectionAdmin(admin1).send();212213    await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))214      .to.be.rejectedWith('NoPermission');215    {216      const adminList = await api.rpc.unique.adminlist(collectionId);217      expect(adminList.length).to.be.eq(2);218      expect(adminList.toString().toLocaleLowerCase())219        .to.be.deep.contains(admin0.toLocaleLowerCase())220        .to.be.deep.contains(admin1.toLocaleLowerCase());221    }222  });223224  itWeb3('(!negative tests!) Remove admin by USER is not allowed', async ({api, web3}) => {225    const owner = await createEthAccountWithBalance(api, web3);226    const collectionHelper = evmCollectionHelpers(web3, owner);227        228    const result = await collectionHelper.methods229      .createNonfungibleCollection('A', 'B', 'C')230      .send();231    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);232233    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);234235    const admin = await createEthAccountWithBalance(api, web3);236    await collectionEvm.methods.addCollectionAdmin(admin).send();237    const notAdmin = await createEthAccount(web3);238239    await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))240      .to.be.rejectedWith('NoPermission');241    {242      const adminList = await api.rpc.unique.adminlist(collectionId);243      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())244        .to.be.eq(admin.toLocaleLowerCase());245      expect(adminList.length).to.be.eq(1);246    }247  });248249  itWeb3('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({api, web3}) => {250    const owner = await createEthAccountWithBalance(api, web3);251    const collectionHelper = evmCollectionHelpers(web3, owner);252        253    const result = await collectionHelper.methods254      .createNonfungibleCollection('A', 'B', 'C')255      .send();256    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);257258    const adminSub = privateKey('//Alice');259    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);260    await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();261    const adminEth = await createEthAccountWithBalance(api, web3);262    await collectionEvm.methods.addCollectionAdmin(adminEth).send();263264    await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))265      .to.be.rejectedWith('NoPermission');266267    const adminList = await api.rpc.unique.adminlist(collectionId);268    expect(adminList.length).to.be.eq(2);269    expect(adminList.toString().toLocaleLowerCase())270      .to.be.deep.contains(adminSub.address.toLocaleLowerCase())271      .to.be.deep.contains(adminEth.toLocaleLowerCase());272  });273274  itWeb3('(!negative tests!) Remove substrate admin by USER is not allowed', async ({api, web3}) => {275    const owner = await createEthAccountWithBalance(api, web3);276    const collectionHelper = evmCollectionHelpers(web3, owner);277        278    const result = await collectionHelper.methods279      .createNonfungibleCollection('A', 'B', 'C')280      .send();281    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);282283    const adminSub = privateKey('//Alice');284    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);285    await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();286    const notAdminEth = await createEthAccountWithBalance(api, web3);287288    await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))289      .to.be.rejectedWith('NoPermission');290291    const adminList = await api.rpc.unique.adminlist(collectionId);292    expect(adminList.length).to.be.eq(1);293    expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())294      .to.be.eq(adminSub.address.toLocaleLowerCase());295  });296});
modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -250,7 +250,7 @@
 
     await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});
     await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});
-    await collectionEvm.methods.setMintMode(true).send({from: owner});
+    await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});
 
     const newPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
     expect(newPermissions.mintMode).to.be.true;
modifiedtests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -386,27 +386,15 @@
     "type": "function"
   },
   {
-    "inputs": [
-      { "internalType": "string", "name": "key", "type": "string" },
-      { "internalType": "bytes", "name": "value", "type": "bytes" }
-    ],
-    "name": "setCollectionProperty",
-    "outputs": [],
-    "stateMutability": "nonpayable",
-    "type": "function"
-  },
-  {
-    "inputs": [
-      { "internalType": "address", "name": "sponsor", "type": "address" }
-    ],
-    "name": "setCollectionSponsor",
+    "inputs": [{ "internalType": "bool", "name": "mode", "type": "bool" }],
+    "name": "setCollectionMintMode",
     "outputs": [],
     "stateMutability": "nonpayable",
     "type": "function"
   },
   {
-    "inputs": [{ "internalType": "bool", "name": "mode", "type": "bool" }],
-    "name": "setMintMode",
+    "inputs": [{ "internalType": "bool", "name": "enable", "type": "bool" }],
+    "name": "setCollectionNesting",
     "outputs": [],
     "stateMutability": "nonpayable",
     "type": "function"
@@ -420,14 +408,26 @@
         "type": "address[]"
       }
     ],
-    "name": "setNesting",
+    "name": "setCollectionNesting",
     "outputs": [],
     "stateMutability": "nonpayable",
     "type": "function"
   },
   {
-    "inputs": [{ "internalType": "bool", "name": "enable", "type": "bool" }],
-    "name": "setNesting",
+    "inputs": [
+      { "internalType": "string", "name": "key", "type": "string" },
+      { "internalType": "bytes", "name": "value", "type": "bytes" }
+    ],
+    "name": "setCollectionProperty",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
+      { "internalType": "address", "name": "sponsor", "type": "address" }
+    ],
+    "name": "setCollectionSponsor",
     "outputs": [],
     "stateMutability": "nonpayable",
     "type": "function"
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -111,18 +111,24 @@
     });
   });
 
-  it('Admin can\'t remove collection admin.', async () => {
+  it.only('Admin can\'t remove collection admin.', async () => {
     await usingApi(async (api, privateKeyWrapper) => {
       const collectionId = await createCollectionExpectSuccess();
       const alice = privateKeyWrapper('//Alice');
       const bob = privateKeyWrapper('//Bob');
       const charlie = privateKeyWrapper('//Charlie');
 
+      const addBobAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
+      await submitTransactionAsync(alice, addBobAdminTx);
+      const addCharlieAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));
+      await submitTransactionAsync(alice, addCharlieAdminTx);
+
       const adminListAfterAddAdmin = await getAdminList(api, collectionId);
       expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
+      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(charlie.address));
 
       const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
-      await expect(submitTransactionAsync(charlie, removeAdminTx)).to.be.rejected;
+      await expect(submitTransactionExpectFailAsync(charlie, removeAdminTx)).to.be.rejected;
 
       const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);
       expect(adminListAfterRemoveAdmin).to.be.deep.contains(normalizeAccountId(bob.address));