difftreelog
CORE-386 Add admin tests
in: master
5 files changed
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -330,57 +330,7 @@
}
}
-// Selector: d74d154f
-contract ERC721UniqueExtensions is Dummy, ERC165 {
- // Selector: transfer(address,uint256) a9059cbb
- function transfer(address to, uint256 tokenId) public {
- require(false, stub_error);
- to;
- tokenId;
- dummy = 0;
- }
-
- // Selector: burnFrom(address,uint256) 79cc6790
- function burnFrom(address from, uint256 tokenId) public {
- require(false, stub_error);
- from;
- tokenId;
- dummy = 0;
- }
-
- // Selector: nextTokenId() 75794a3c
- function nextTokenId() public view returns (uint256) {
- require(false, stub_error);
- dummy;
- return 0;
- }
-
- // Selector: mintBulk(address,uint256[]) 44a9945e
- function mintBulk(address to, uint256[] memory tokenIds)
- public
- returns (bool)
- {
- require(false, stub_error);
- to;
- tokenIds;
- dummy = 0;
- return false;
- }
-
- // Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006
- function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)
- public
- returns (bool)
- {
- require(false, stub_error);
- to;
- tokens;
- dummy = 0;
- return false;
- }
-}
-
-// Selector: f56cd7fa
+// Selector: 7d9262e6
contract Collection is Dummy, ERC165 {
// Selector: setCollectionProperty(string,bytes) 2f073f66
function setCollectionProperty(string memory key, bytes memory value)
@@ -449,8 +399,22 @@
return 0x0000000000000000000000000000000000000000;
}
- // Selector: addAdmin(address) 70480275
- function addAdmin(address newAdmin) public view {
+ // Selector: addCollectionAdminSubstrate(uint256) 5730062b
+ function addCollectionAdminSubstrate(uint256 newAdmin) public view {
+ require(false, stub_error);
+ newAdmin;
+ dummy;
+ }
+
+ // Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
+ function removeCollectionAdminSubstrate(uint256 newAdmin) public view {
+ require(false, stub_error);
+ newAdmin;
+ dummy;
+ }
+
+ // Selector: addCollectionAdmin(address) 92e462c7
+ function addCollectionAdmin(address newAdmin) public view {
require(false, stub_error);
newAdmin;
dummy;
@@ -507,6 +471,56 @@
}
}
+// Selector: d74d154f
+contract ERC721UniqueExtensions is Dummy, ERC165 {
+ // Selector: transfer(address,uint256) a9059cbb
+ function transfer(address to, uint256 tokenId) public {
+ require(false, stub_error);
+ to;
+ tokenId;
+ dummy = 0;
+ }
+
+ // Selector: burnFrom(address,uint256) 79cc6790
+ function burnFrom(address from, uint256 tokenId) public {
+ require(false, stub_error);
+ from;
+ tokenId;
+ dummy = 0;
+ }
+
+ // Selector: nextTokenId() 75794a3c
+ function nextTokenId() public view returns (uint256) {
+ require(false, stub_error);
+ dummy;
+ return 0;
+ }
+
+ // Selector: mintBulk(address,uint256[]) 44a9945e
+ function mintBulk(address to, uint256[] memory tokenIds)
+ public
+ returns (bool)
+ {
+ require(false, stub_error);
+ to;
+ tokenIds;
+ dummy = 0;
+ return false;
+ }
+
+ // Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006
+ function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)
+ public
+ returns (bool)
+ {
+ require(false, stub_error);
+ to;
+ tokens;
+ dummy = 0;
+ return false;
+ }
+}
+
contract UniqueNFT is
Dummy,
ERC165,
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56// Anonymous struct7struct Tuple0 {8 uint256 field_0;9 string field_1;10}1112// Common stubs holder13interface Dummy {1415}1617interface ERC165 is Dummy {18 function supportsInterface(bytes4 interfaceID) external view returns (bool);19}2021// Inline22interface ERC721Events {23 event Transfer(24 address indexed from,25 address indexed to,26 uint256 indexed tokenId27 );28 event Approval(29 address indexed owner,30 address indexed approved,31 uint256 indexed tokenId32 );33 event ApprovalForAll(34 address indexed owner,35 address indexed operator,36 bool approved37 );38}3940// Inline41interface ERC721MintableEvents {42 event MintingFinished();43}4445// Selector: 4136937746interface TokenProperties is Dummy, ERC165 {47 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa48 function setTokenPropertyPermission(49 string memory key,50 bool isMutable,51 bool collectionAdmin,52 bool tokenOwner53 ) external;5455 // Selector: setProperty(uint256,string,bytes) 1752d67b56 function setProperty(57 uint256 tokenId,58 string memory key,59 bytes memory value60 ) external;6162 // Selector: deleteProperty(uint256,string) 066111d163 function deleteProperty(uint256 tokenId, string memory key) external;6465 // Throws error if key not found66 //67 // Selector: property(uint256,string) 7228c32768 function property(uint256 tokenId, string memory key)69 external70 view71 returns (bytes memory);72}7374// Selector: 42966c6875interface ERC721Burnable is Dummy, ERC165 {76 // Selector: burn(uint256) 42966c6877 function burn(uint256 tokenId) external;78}7980// Selector: 5880016181interface ERC721 is Dummy, ERC165, ERC721Events {82 // Selector: balanceOf(address) 70a0823183 function balanceOf(address owner) external view returns (uint256);8485 // Selector: ownerOf(uint256) 6352211e86 function ownerOf(uint256 tokenId) external view returns (address);8788 // Not implemented89 //90 // Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a1167291 function safeTransferFromWithData(92 address from,93 address to,94 uint256 tokenId,95 bytes memory data96 ) external;9798 // Not implemented99 //100 // Selector: safeTransferFrom(address,address,uint256) 42842e0e101 function safeTransferFrom(102 address from,103 address to,104 uint256 tokenId105 ) external;106107 // Selector: transferFrom(address,address,uint256) 23b872dd108 function transferFrom(109 address from,110 address to,111 uint256 tokenId112 ) external;113114 // Selector: approve(address,uint256) 095ea7b3115 function approve(address approved, uint256 tokenId) external;116117 // Not implemented118 //119 // Selector: setApprovalForAll(address,bool) a22cb465120 function setApprovalForAll(address operator, bool approved) external;121122 // Not implemented123 //124 // Selector: getApproved(uint256) 081812fc125 function getApproved(uint256 tokenId) external view returns (address);126127 // Not implemented128 //129 // Selector: isApprovedForAll(address,address) e985e9c5130 function isApprovedForAll(address owner, address operator)131 external132 view133 returns (address);134}135136// Selector: 5b5e139f137interface ERC721Metadata is Dummy, ERC165 {138 // Selector: name() 06fdde03139 function name() external view returns (string memory);140141 // Selector: symbol() 95d89b41142 function symbol() external view returns (string memory);143144 // Returns token's const_metadata145 //146 // Selector: tokenURI(uint256) c87b56dd147 function tokenURI(uint256 tokenId) external view returns (string memory);148}149150// Selector: 68ccfe89151interface ERC721Mintable is Dummy, ERC165, ERC721MintableEvents {152 // Selector: mintingFinished() 05d2035b153 function mintingFinished() external view returns (bool);154155 // `token_id` should be obtained with `next_token_id` method,156 // unlike standard, you can't specify it manually157 //158 // Selector: mint(address,uint256) 40c10f19159 function mint(address to, uint256 tokenId) external returns (bool);160161 // `token_id` should be obtained with `next_token_id` method,162 // unlike standard, you can't specify it manually163 //164 // Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f165 function mintWithTokenURI(166 address to,167 uint256 tokenId,168 string memory tokenUri169 ) external returns (bool);170171 // Not implemented172 //173 // Selector: finishMinting() 7d64bcb4174 function finishMinting() external returns (bool);175}176177// Selector: 780e9d63178interface ERC721Enumerable is Dummy, ERC165 {179 // Selector: tokenByIndex(uint256) 4f6ccce7180 function tokenByIndex(uint256 index) external view returns (uint256);181182 // Not implemented183 //184 // Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59185 function tokenOfOwnerByIndex(address owner, uint256 index)186 external187 view188 returns (uint256);189190 // Selector: totalSupply() 18160ddd191 function totalSupply() external view returns (uint256);192}193194// Selector: 7d9262e6195interface Collection is Dummy, ERC165 {196 // Selector: setCollectionProperty(string,bytes) 2f073f66197 function setCollectionProperty(string memory key, bytes memory value)198 external;199200 // Selector: deleteCollectionProperty(string) 7b7debce201 function deleteCollectionProperty(string memory key) external;202203 // Throws error if key not found204 //205 // Selector: collectionProperty(string) cf24fd6d206 function collectionProperty(string memory key)207 external208 view209 returns (bytes memory);210211 // Selector: setCollectionSponsor(address) 7623402e212 function setCollectionSponsor(address sponsor) external;213214 // Selector: confirmCollectionSponsorship() 3c50e97a215 function confirmCollectionSponsorship() external;216217 // Selector: setCollectionLimit(string,uint32) 6a3841db218 function setCollectionLimit(string memory limit, uint32 value) external;219220 // Selector: setCollectionLimit(string,bool) 993b7fba221 function setCollectionLimit(string memory limit, bool value) external;222223 // Selector: contractAddress() f6b4dfb4224 function contractAddress() external view returns (address);225226 // Selector: addCollectionAdminSubstrate(uint256) 5730062b227 function addCollectionAdminSubstrate(uint256 newAdmin) external view;228229 // Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9230 function removeCollectionAdminSubstrate(uint256 newAdmin) external view;231232 // Selector: addCollectionAdmin(address) 92e462c7233 function addCollectionAdmin(address newAdmin) external view;234235 // Selector: removeCollectionAdmin(address) fafd7b42236 function removeCollectionAdmin(address admin) external view;237238 // Selector: setCollectionNesting(bool) 112d4586239 function setCollectionNesting(bool enable) external;240241 // Selector: setCollectionNesting(bool,address[]) 64872396242 function setCollectionNesting(bool enable, address[] memory collections)243 external;244245 // Selector: setCollectionAccess(uint8) 41835d4c246 function setCollectionAccess(uint8 mode) external;247248 // Selector: addToCollectionAllowList(address) 67844fe6249 function addToCollectionAllowList(address user) external view;250251 // Selector: removeFromCollectionAllowList(address) 85c51acb252 function removeFromCollectionAllowList(address user) external view;253254 // Selector: setCollectionMintMode(bool) 00018e84255 function setCollectionMintMode(bool mode) external;256}257258// Selector: d74d154f259interface ERC721UniqueExtensions is Dummy, ERC165 {260 // Selector: transfer(address,uint256) a9059cbb261 function transfer(address to, uint256 tokenId) external;262263 // Selector: burnFrom(address,uint256) 79cc6790264 function burnFrom(address from, uint256 tokenId) external;265266 // Selector: nextTokenId() 75794a3c267 function nextTokenId() external view returns (uint256);268269 // Selector: mintBulk(address,uint256[]) 44a9945e270 function mintBulk(address to, uint256[] memory tokenIds)271 external272 returns (bool);273274 // Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006275 function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)276 external277 returns (bool);278}279280// Selector: f56cd7fa281interface Collection is Dummy, ERC165 {282 // Selector: setCollectionProperty(string,bytes) 2f073f66283 function setCollectionProperty(string memory key, bytes memory value)284 external;285286 // Selector: deleteCollectionProperty(string) 7b7debce287 function deleteCollectionProperty(string memory key) external;288289 // Throws error if key not found290 //291 // Selector: collectionProperty(string) cf24fd6d292 function collectionProperty(string memory key)293 external294 view295 returns (bytes memory);296297 // Selector: ethSetSponsor(address) 8f9af356298 function ethSetSponsor(address sponsor) external;299300 // Selector: ethConfirmSponsorship() a8580d1a301 function ethConfirmSponsorship() external;302303 // Selector: setLimit(string,uint32) 68db30ca304 function setLimit(string memory limit, uint32 value) external;305306 // Selector: setLimit(string,bool) ea67e4c2307 function setLimit(string memory limit, bool value) external;308309 // Selector: contractAddress() f6b4dfb4310 function contractAddress() external view returns (address);311312 // Selector: addAdmin(address) 70480275313 function addAdmin(address newAdmin) external view;314315 // Selector: removeAdmin(address) 1785f53c316 function removeAdmin(address admin) external view;317318 // Selector: setNesting(bool) e8fc50dd319 function setNesting(bool enable) external;320321 // Selector: setNesting(bool,address[]) 7df12a9a322 function setNesting(bool enable, address[] memory collections) external;323324 // Selector: setAccess(string) 488f56aa325 function setAccess(string memory mode) external;326327 // Selector: addToAllowList(address) 31f59102328 function addToAllowList(address user) external view;329330 // Selector: removeFromAllowList(address) eba8dabc331 function removeFromAllowList(address user) external view;332333 // Selector: setMintMode(bool) 5dea9bd5334 function setMintMode(bool mode) external;335}336337interface UniqueNFT is338 Dummy,339 ERC165,340 ERC721,341 ERC721Metadata,342 ERC721Enumerable,343 ERC721UniqueExtensions,344 ERC721Mintable,345 ERC721Burnable,346 Collection,347 TokenProperties348{}tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -0,0 +1,88 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+import {expect} from 'chai';
+import privateKey from '../substrate/privateKey';
+import {
+ createEthAccount,
+ createEthAccountWithBalance,
+ evmCollection,
+ evmCollectionHelpers,
+ getCollectionAddressFromResult,
+ itWeb3,
+} from './util/helpers';
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+describe.only('Add collection admins', () => {
+ itWeb3('Add admin by owner', async ({api, web3}) => {
+ const owner = await createEthAccountWithBalance(api, web3);
+ const collectionHelper = evmCollectionHelpers(web3, owner);
+
+ const result = await collectionHelper.methods
+ .createNonfungibleCollection('A', 'B', 'C')
+ .send();
+ const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+
+ const newAdmin = await createEthAccount(web3);
+ const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+ await collectionEvm.methods.addCollectionAdmin(newAdmin).send();
+ const adminList = await api.rpc.unique.adminlist(collectionId);
+ expect(adminList[0].asEthereum.toString().toLocaleLowerCase())
+ .to.be.eq(newAdmin.toLocaleLowerCase());
+ });
+
+ itWeb3('Add substrate admin by owner', async ({api, web3}) => {
+ const owner = await createEthAccountWithBalance(api, web3);
+ const collectionHelper = evmCollectionHelpers(web3, owner);
+
+ const result = await collectionHelper.methods
+ .createNonfungibleCollection('A', 'B', 'C')
+ .send();
+ const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+
+ const newAdmin = privateKey('//Alice');
+ const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+ await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();
+ const adminList = await api.rpc.unique.adminlist(collectionId);
+ expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())
+ .to.be.eq(newAdmin.address.toLocaleLowerCase());
+ });
+
+ itWeb3('(!negative tests!) Add admin by admin is not allowed', async ({api, web3}) => {
+ const owner = await createEthAccountWithBalance(api, web3);
+ const collectionHelper = evmCollectionHelpers(web3, owner);
+
+ const result = await collectionHelper.methods
+ .createNonfungibleCollection('A', 'B', 'C')
+ .send();
+ const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+
+ const admin = await createEthAccountWithBalance(api, web3);
+ const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+ await collectionEvm.methods.addCollectionAdmin(admin).send();
+ {
+ const adminList = await api.rpc.unique.adminlist(collectionId);
+ expect(adminList[0].asEthereum.toString().toLocaleLowerCase())
+ .to.be.eq(admin.toLocaleLowerCase());
+ }
+
+ const user = await createEthAccount(web3);
+ await collectionEvm.methods.addCollectionAdmin(user).send({from: admin});
+ const adminList = await api.rpc.unique.adminlist(collectionId);
+ expect(adminList[0].asEthereum.toString().toLocaleLowerCase())
+ .to.be.eq(admin.toLocaleLowerCase());
+ expect(adminList.length).to.be.eq(1);
+ });
+});
\ No newline at end of file
tests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -91,6 +91,15 @@
},
{
"inputs": [
+ { "internalType": "uint256", "name": "newAdmin", "type": "uint256" }
+ ],
+ "name": "addCollectionAdminSubstrate",
+ "outputs": [],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "address", "name": "user", "type": "address" }
],
"name": "addToAllowList",
@@ -300,6 +309,15 @@
},
{
"inputs": [
+ { "internalType": "uint256", "name": "newAdmin", "type": "uint256" }
+ ],
+ "name": "removeCollectionAdminSubstrate",
+ "outputs": [],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "address", "name": "user", "type": "address" }
],
"name": "removeFromAllowList",