git.delta.rocks / unique-network / refs/commits / 3903c8aaf16e

difftreelog

CORE-386 Add admin tests

Trubnikov Sergey2022-06-07parent: #b484237.patch.diff
in: master

5 files changed

modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
330 }330 }
331}331}
332
333// Selector: 7d9262e6
334contract Collection is Dummy, ERC165 {
335 // Selector: setCollectionProperty(string,bytes) 2f073f66
336 function setCollectionProperty(string memory key, bytes memory value)
337 public
338 {
339 require(false, stub_error);
340 key;
341 value;
342 dummy = 0;
343 }
344
345 // Selector: deleteCollectionProperty(string) 7b7debce
346 function deleteCollectionProperty(string memory key) public {
347 require(false, stub_error);
348 key;
349 dummy = 0;
350 }
351
352 // Throws error if key not found
353 //
354 // Selector: collectionProperty(string) cf24fd6d
355 function collectionProperty(string memory key)
356 public
357 view
358 returns (bytes memory)
359 {
360 require(false, stub_error);
361 key;
362 dummy;
363 return hex"";
364 }
365
366 // Selector: ethSetSponsor(address) 8f9af356
367 function ethSetSponsor(address sponsor) public {
368 require(false, stub_error);
369 sponsor;
370 dummy = 0;
371 }
372
373 // Selector: ethConfirmSponsorship() a8580d1a
374 function ethConfirmSponsorship() public {
375 require(false, stub_error);
376 dummy = 0;
377 }
378
379 // Selector: setLimit(string,uint32) 68db30ca
380 function setLimit(string memory limit, uint32 value) public {
381 require(false, stub_error);
382 limit;
383 value;
384 dummy = 0;
385 }
386
387 // Selector: setLimit(string,bool) ea67e4c2
388 function setLimit(string memory limit, bool value) public {
389 require(false, stub_error);
390 limit;
391 value;
392 dummy = 0;
393 }
394
395 // Selector: contractAddress() f6b4dfb4
396 function contractAddress() public view returns (address) {
397 require(false, stub_error);
398 dummy;
399 return 0x0000000000000000000000000000000000000000;
400 }
401
402 // Selector: addCollectionAdminSubstrate(uint256) 5730062b
403 function addCollectionAdminSubstrate(uint256 newAdmin) public view {
404 require(false, stub_error);
405 newAdmin;
406 dummy;
407 }
408
409 // Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
410 function removeCollectionAdminSubstrate(uint256 newAdmin) public view {
411 require(false, stub_error);
412 newAdmin;
413 dummy;
414 }
415
416 // Selector: addCollectionAdmin(address) 92e462c7
417 function addCollectionAdmin(address newAdmin) public view {
418 require(false, stub_error);
419 newAdmin;
420 dummy;
421 }
422
423 // Selector: removeAdmin(address) 1785f53c
424 function removeAdmin(address admin) public view {
425 require(false, stub_error);
426 admin;
427 dummy;
428 }
429
430 // Selector: setNesting(bool) e8fc50dd
431 function setNesting(bool enable) public {
432 require(false, stub_error);
433 enable;
434 dummy = 0;
435 }
436
437 // Selector: setNesting(bool,address[]) 7df12a9a
438 function setNesting(bool enable, address[] memory collections) public {
439 require(false, stub_error);
440 enable;
441 collections;
442 dummy = 0;
443 }
444
445 // Selector: setAccess(string) 488f56aa
446 function setAccess(string memory mode) public {
447 require(false, stub_error);
448 mode;
449 dummy = 0;
450 }
451
452 // Selector: addToAllowList(address) 31f59102
453 function addToAllowList(address user) public view {
454 require(false, stub_error);
455 user;
456 dummy;
457 }
458
459 // Selector: removeFromAllowList(address) eba8dabc
460 function removeFromAllowList(address user) public view {
461 require(false, stub_error);
462 user;
463 dummy;
464 }
465
466 // Selector: setMintMode(bool) 5dea9bd5
467 function setMintMode(bool mode) public {
468 require(false, stub_error);
469 mode;
470 dummy = 0;
471 }
472}
332473
333// Selector: d74d154f474// Selector: d74d154f
334contract ERC721UniqueExtensions is Dummy, ERC165 {475contract ERC721UniqueExtensions is Dummy, ERC165 {
380 }521 }
381}522}
382
383// Selector: f56cd7fa
384contract Collection is Dummy, ERC165 {
385 // Selector: setCollectionProperty(string,bytes) 2f073f66
386 function setCollectionProperty(string memory key, bytes memory value)
387 public
388 {
389 require(false, stub_error);
390 key;
391 value;
392 dummy = 0;
393 }
394
395 // Selector: deleteCollectionProperty(string) 7b7debce
396 function deleteCollectionProperty(string memory key) public {
397 require(false, stub_error);
398 key;
399 dummy = 0;
400 }
401
402 // Throws error if key not found
403 //
404 // Selector: collectionProperty(string) cf24fd6d
405 function collectionProperty(string memory key)
406 public
407 view
408 returns (bytes memory)
409 {
410 require(false, stub_error);
411 key;
412 dummy;
413 return hex"";
414 }
415
416 // Selector: ethSetSponsor(address) 8f9af356
417 function ethSetSponsor(address sponsor) public {
418 require(false, stub_error);
419 sponsor;
420 dummy = 0;
421 }
422
423 // Selector: ethConfirmSponsorship() a8580d1a
424 function ethConfirmSponsorship() public {
425 require(false, stub_error);
426 dummy = 0;
427 }
428
429 // Selector: setLimit(string,uint32) 68db30ca
430 function setLimit(string memory limit, uint32 value) public {
431 require(false, stub_error);
432 limit;
433 value;
434 dummy = 0;
435 }
436
437 // Selector: setLimit(string,bool) ea67e4c2
438 function setLimit(string memory limit, bool value) public {
439 require(false, stub_error);
440 limit;
441 value;
442 dummy = 0;
443 }
444
445 // Selector: contractAddress() f6b4dfb4
446 function contractAddress() public view returns (address) {
447 require(false, stub_error);
448 dummy;
449 return 0x0000000000000000000000000000000000000000;
450 }
451
452 // Selector: addAdmin(address) 70480275
453 function addAdmin(address newAdmin) public view {
454 require(false, stub_error);
455 newAdmin;
456 dummy;
457 }
458
459 // Selector: removeAdmin(address) 1785f53c
460 function removeAdmin(address admin) public view {
461 require(false, stub_error);
462 admin;
463 dummy;
464 }
465
466 // Selector: setNesting(bool) e8fc50dd
467 function setNesting(bool enable) public {
468 require(false, stub_error);
469 enable;
470 dummy = 0;
471 }
472
473 // Selector: setNesting(bool,address[]) 7df12a9a
474 function setNesting(bool enable, address[] memory collections) public {
475 require(false, stub_error);
476 enable;
477 collections;
478 dummy = 0;
479 }
480
481 // Selector: setAccess(string) 488f56aa
482 function setAccess(string memory mode) public {
483 require(false, stub_error);
484 mode;
485 dummy = 0;
486 }
487
488 // Selector: addToAllowList(address) 31f59102
489 function addToAllowList(address user) public view {
490 require(false, stub_error);
491 user;
492 dummy;
493 }
494
495 // Selector: removeFromAllowList(address) eba8dabc
496 function removeFromAllowList(address user) public view {
497 require(false, stub_error);
498 user;
499 dummy;
500 }
501
502 // Selector: setMintMode(bool) 5dea9bd5
503 function setMintMode(bool mode) public {
504 require(false, stub_error);
505 mode;
506 dummy = 0;
507 }
508}
509523
510contract UniqueNFT is524contract UniqueNFT is
511 Dummy,525 Dummy,
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -191,6 +191,70 @@
 	function totalSupply() external view returns (uint256);
 }
 
+// Selector: 7d9262e6
+interface Collection is Dummy, ERC165 {
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		external;
+
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) external;
+
+	// Throws error if key not found
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		external
+		view
+		returns (bytes memory);
+
+	// Selector: setCollectionSponsor(address) 7623402e
+	function setCollectionSponsor(address sponsor) external;
+
+	// Selector: confirmCollectionSponsorship() 3c50e97a
+	function confirmCollectionSponsorship() external;
+
+	// Selector: setCollectionLimit(string,uint32) 6a3841db
+	function setCollectionLimit(string memory limit, uint32 value) external;
+
+	// Selector: setCollectionLimit(string,bool) 993b7fba
+	function setCollectionLimit(string memory limit, bool value) external;
+
+	// Selector: contractAddress() f6b4dfb4
+	function contractAddress() external view returns (address);
+
+	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
+	function addCollectionAdminSubstrate(uint256 newAdmin) external view;
+
+	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
+	function removeCollectionAdminSubstrate(uint256 newAdmin) external view;
+
+	// Selector: addCollectionAdmin(address) 92e462c7
+	function addCollectionAdmin(address newAdmin) external view;
+
+	// Selector: removeCollectionAdmin(address) fafd7b42
+	function removeCollectionAdmin(address admin) external view;
+
+	// Selector: setCollectionNesting(bool) 112d4586
+	function setCollectionNesting(bool enable) external;
+
+	// Selector: setCollectionNesting(bool,address[]) 64872396
+	function setCollectionNesting(bool enable, address[] memory collections)
+		external;
+
+	// Selector: setCollectionAccess(uint8) 41835d4c
+	function setCollectionAccess(uint8 mode) external;
+
+	// Selector: addToCollectionAllowList(address) 67844fe6
+	function addToCollectionAllowList(address user) external view;
+
+	// Selector: removeFromCollectionAllowList(address) 85c51acb
+	function removeFromCollectionAllowList(address user) external view;
+
+	// Selector: setCollectionMintMode(bool) 00018e84
+	function setCollectionMintMode(bool mode) external;
+}
+
 // Selector: d74d154f
 interface ERC721UniqueExtensions is Dummy, ERC165 {
 	// Selector: transfer(address,uint256) a9059cbb
addedtests/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
modifiedtests/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",