git.delta.rocks / unique-network / refs/commits / 59683d4fb2c6

difftreelog

feat add evm event `CollectionChanged` for sub events : `CollectionPropertySet`, `CollectionPropertyDeleted`, `PropertyPermissionSet`

Trubnikov Sergey2022-12-06parent: #6c3810b.patch.diff
in: master

7 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -58,6 +58,12 @@
 		#[indexed]
 		collection_id: address,
 	},
+	/// The collection has been changed.
+	CollectionChanged {
+		/// Collection ID.
+		#[indexed]
+		collection_id: address,
+	},
 }
 
 /// Does not always represent a full collection, for RFT it is either
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1036,6 +1036,12 @@
 		.map_err(<Error<T>>::from)?;
 
 		Self::deposit_event(Event::CollectionPropertySet(collection.id, property.key));
+		<PalletEvm<T>>::deposit_log(
+			erc::CollectionHelpersEvents::CollectionChanged {
+				collection_id: eth::collection_id_to_address(collection.id),
+			}
+			.to_log(T::ContractAddress::get()),
+		);
 
 		Ok(())
 	}
@@ -1115,6 +1121,12 @@
 			collection.id,
 			property_key,
 		));
+		<PalletEvm<T>>::deposit_log(
+			erc::CollectionHelpersEvents::CollectionChanged {
+				collection_id: eth::collection_id_to_address(collection.id),
+			}
+			.to_log(T::ContractAddress::get()),
+		);
 
 		Ok(())
 	}
@@ -1209,6 +1221,12 @@
 			collection.id,
 			property_permission.key,
 		));
+		<PalletEvm<T>>::deposit_log(
+			erc::CollectionHelpersEvents::CollectionChanged {
+				collection_id: eth::collection_id_to_address(collection.id),
+			}
+			.to_log(T::ContractAddress::get()),
+		);
 
 		Ok(())
 	}
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth
before · pallets/unique/src/eth/stubs/CollectionHelpers.sol
1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7contract Dummy {8	uint8 dummy;9	string stub_error = "this contract is implemented in native";10}1112contract ERC165 is Dummy {13	function supportsInterface(bytes4 interfaceID) external view returns (bool) {14		require(false, stub_error);15		interfaceID;16		return true;17	}18}1920/// @dev inlined interface21contract CollectionHelpersEvents {22	event CollectionCreated(address indexed owner, address indexed collectionId);23	event CollectionDestroyed(address indexed collectionId);24}2526/// @title Contract, which allows users to operate with collections27/// @dev the ERC-165 identifier for this interface is 0xe65011aa28contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {29	/// Create an NFT collection30	/// @param name Name of the collection31	/// @param description Informative description of the collection32	/// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications33	/// @return address Address of the newly created collection34	/// @dev EVM selector for this function is: 0x844af658,35	///  or in textual repr: createNFTCollection(string,string,string)36	function createNFTCollection(37		string memory name,38		string memory description,39		string memory tokenPrefix40	) public payable returns (address) {41		require(false, stub_error);42		name;43		description;44		tokenPrefix;45		dummy = 0;46		return 0x0000000000000000000000000000000000000000;47	}4849	// /// Create an NFT collection50	// /// @param name Name of the collection51	// /// @param description Informative description of the collection52	// /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications53	// /// @return address Address of the newly created collection54	// /// @dev EVM selector for this function is: 0xe34a6844,55	// ///  or in textual repr: createNonfungibleCollection(string,string,string)56	// function createNonfungibleCollection(string memory name, string memory description, string memory tokenPrefix) public payable returns (address) {57	// 	require(false, stub_error);58	// 	name;59	// 	description;60	// 	tokenPrefix;61	// 	dummy = 0;62	// 	return 0x0000000000000000000000000000000000000000;63	// }6465	/// @dev EVM selector for this function is: 0xab173450,66	///  or in textual repr: createRFTCollection(string,string,string)67	function createRFTCollection(68		string memory name,69		string memory description,70		string memory tokenPrefix71	) public payable returns (address) {72		require(false, stub_error);73		name;74		description;75		tokenPrefix;76		dummy = 0;77		return 0x0000000000000000000000000000000000000000;78	}7980	/// @dev EVM selector for this function is: 0x7335b79f,81	///  or in textual repr: createFTCollection(string,uint8,string,string)82	function createFTCollection(83		string memory name,84		uint8 decimals,85		string memory description,86		string memory tokenPrefix87	) public payable returns (address) {88		require(false, stub_error);89		name;90		decimals;91		description;92		tokenPrefix;93		dummy = 0;94		return 0x0000000000000000000000000000000000000000;95	}9697	/// @dev EVM selector for this function is: 0x85624258,98	///  or in textual repr: makeCollectionERC721MetadataCompatible(address,string)99	function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) public {100		require(false, stub_error);101		collection;102		baseUri;103		dummy = 0;104	}105106	/// @dev EVM selector for this function is: 0x564e321f,107	///  or in textual repr: destroyCollection(address)108	function destroyCollection(address collectionAddress) public {109		require(false, stub_error);110		collectionAddress;111		dummy = 0;112	}113114	/// Check if a collection exists115	/// @param collectionAddress Address of the collection in question116	/// @return bool Does the collection exist?117	/// @dev EVM selector for this function is: 0xc3de1494,118	///  or in textual repr: isCollectionExist(address)119	function isCollectionExist(address collectionAddress) public view returns (bool) {120		require(false, stub_error);121		collectionAddress;122		dummy;123		return false;124	}125126	/// @dev EVM selector for this function is: 0xd23a7ab1,127	///  or in textual repr: collectionCreationFee()128	function collectionCreationFee() public view returns (uint256) {129		require(false, stub_error);130		dummy;131		return 0;132	}133134	/// Returns address of a collection.135	/// @param collectionId  - CollectionId  of the collection136	/// @return eth mirror address of the collection137	/// @dev EVM selector for this function is: 0x2e716683,138	///  or in textual repr: collectionAddress(uint32)139	function collectionAddress(uint32 collectionId) public view returns (address) {140		require(false, stub_error);141		collectionId;142		dummy;143		return 0x0000000000000000000000000000000000000000;144	}145146	/// Returns collectionId of a collection.147	/// @param collectionAddress  - Eth address of the collection148	/// @return collectionId of the collection149	/// @dev EVM selector for this function is: 0xb5cb7498,150	///  or in textual repr: collectionId(address)151	function collectionId(address collectionAddress) public view returns (uint32) {152		require(false, stub_error);153		collectionAddress;154		dummy;155		return 0;156	}157}
after · pallets/unique/src/eth/stubs/CollectionHelpers.sol
1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7contract Dummy {8	uint8 dummy;9	string stub_error = "this contract is implemented in native";10}1112contract ERC165 is Dummy {13	function supportsInterface(bytes4 interfaceID) external view returns (bool) {14		require(false, stub_error);15		interfaceID;16		return true;17	}18}1920/// @dev inlined interface21contract CollectionHelpersEvents {22	event CollectionCreated(address indexed owner, address indexed collectionId);23	event CollectionDestroyed(address indexed collectionId);24	event CollectionChanged(address indexed collectionId);25}2627/// @title Contract, which allows users to operate with collections28/// @dev the ERC-165 identifier for this interface is 0xe65011aa29contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {30	/// Create an NFT collection31	/// @param name Name of the collection32	/// @param description Informative description of the collection33	/// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications34	/// @return address Address of the newly created collection35	/// @dev EVM selector for this function is: 0x844af658,36	///  or in textual repr: createNFTCollection(string,string,string)37	function createNFTCollection(38		string memory name,39		string memory description,40		string memory tokenPrefix41	) public payable returns (address) {42		require(false, stub_error);43		name;44		description;45		tokenPrefix;46		dummy = 0;47		return 0x0000000000000000000000000000000000000000;48	}4950	// /// Create an NFT collection51	// /// @param name Name of the collection52	// /// @param description Informative description of the collection53	// /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications54	// /// @return address Address of the newly created collection55	// /// @dev EVM selector for this function is: 0xe34a6844,56	// ///  or in textual repr: createNonfungibleCollection(string,string,string)57	// function createNonfungibleCollection(string memory name, string memory description, string memory tokenPrefix) public payable returns (address) {58	// 	require(false, stub_error);59	// 	name;60	// 	description;61	// 	tokenPrefix;62	// 	dummy = 0;63	// 	return 0x0000000000000000000000000000000000000000;64	// }6566	/// @dev EVM selector for this function is: 0xab173450,67	///  or in textual repr: createRFTCollection(string,string,string)68	function createRFTCollection(69		string memory name,70		string memory description,71		string memory tokenPrefix72	) public payable returns (address) {73		require(false, stub_error);74		name;75		description;76		tokenPrefix;77		dummy = 0;78		return 0x0000000000000000000000000000000000000000;79	}8081	/// @dev EVM selector for this function is: 0x7335b79f,82	///  or in textual repr: createFTCollection(string,uint8,string,string)83	function createFTCollection(84		string memory name,85		uint8 decimals,86		string memory description,87		string memory tokenPrefix88	) public payable returns (address) {89		require(false, stub_error);90		name;91		decimals;92		description;93		tokenPrefix;94		dummy = 0;95		return 0x0000000000000000000000000000000000000000;96	}9798	/// @dev EVM selector for this function is: 0x85624258,99	///  or in textual repr: makeCollectionERC721MetadataCompatible(address,string)100	function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) public {101		require(false, stub_error);102		collection;103		baseUri;104		dummy = 0;105	}106107	/// @dev EVM selector for this function is: 0x564e321f,108	///  or in textual repr: destroyCollection(address)109	function destroyCollection(address collectionAddress) public {110		require(false, stub_error);111		collectionAddress;112		dummy = 0;113	}114115	/// Check if a collection exists116	/// @param collectionAddress Address of the collection in question117	/// @return bool Does the collection exist?118	/// @dev EVM selector for this function is: 0xc3de1494,119	///  or in textual repr: isCollectionExist(address)120	function isCollectionExist(address collectionAddress) public view returns (bool) {121		require(false, stub_error);122		collectionAddress;123		dummy;124		return false;125	}126127	/// @dev EVM selector for this function is: 0xd23a7ab1,128	///  or in textual repr: collectionCreationFee()129	function collectionCreationFee() public view returns (uint256) {130		require(false, stub_error);131		dummy;132		return 0;133	}134135	/// Returns address of a collection.136	/// @param collectionId  - CollectionId  of the collection137	/// @return eth mirror address of the collection138	/// @dev EVM selector for this function is: 0x2e716683,139	///  or in textual repr: collectionAddress(uint32)140	function collectionAddress(uint32 collectionId) public view returns (address) {141		require(false, stub_error);142		collectionId;143		dummy;144		return 0x0000000000000000000000000000000000000000;145	}146147	/// Returns collectionId of a collection.148	/// @param collectionAddress  - Eth address of the collection149	/// @return collectionId of the collection150	/// @dev EVM selector for this function is: 0xb5cb7498,151	///  or in textual repr: collectionId(address)152	function collectionId(address collectionAddress) public view returns (uint32) {153		require(false, stub_error);154		collectionAddress;155		dummy;156		return 0;157	}158}
modifiedtests/src/eth/abi/collectionHelpers.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/collectionHelpers.json
+++ b/tests/src/eth/abi/collectionHelpers.json
@@ -5,6 +5,19 @@
       {
         "indexed": true,
         "internalType": "address",
+        "name": "collectionId",
+        "type": "address"
+      }
+    ],
+    "name": "CollectionChanged",
+    "type": "event"
+  },
+  {
+    "anonymous": false,
+    "inputs": [
+      {
+        "indexed": true,
+        "internalType": "address",
         "name": "owner",
         "type": "address"
       },
modifiedtests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth
--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -16,6 +16,7 @@
 interface CollectionHelpersEvents {
 	event CollectionCreated(address indexed owner, address indexed collectionId);
 	event CollectionDestroyed(address indexed collectionId);
+	event CollectionChanged(address indexed collectionId);
 }
 
 /// @title Contract, which allows users to operate with collections
addedtests/src/eth/events.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/events.test.ts
@@ -0,0 +1,139 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// 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/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import { expect } from 'chai';
+import { itEth, usingEthPlaygrounds } from './util';
+
+describe.only('NFT events', () => {
+    let donor: IKeyringPair;
+  
+    before(async function () {
+      await usingEthPlaygrounds(async (_helper, privateKey) => {
+        donor = await privateKey({filename: __filename});
+      });
+    });
+
+    itEth('Create event', async ({helper}) => {
+        const owner = await helper.eth.createAccountWithBalance(donor);
+        const {collectionAddress, events} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+        expect(events).to.be.like([
+            {
+                event: 'CollectionCreated',
+                args: {
+                    owner: owner,
+                    collectionId: collectionAddress
+                }
+            }
+        ]);
+    });
+
+    itEth('Destroy event', async ({helper}) => {
+        const owner = await helper.eth.createAccountWithBalance(donor);
+        const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+        const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+        let resutl = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});
+        expect(resutl.events).to.be.like({
+            CollectionDestroyed: {
+                returnValues: {
+                    collectionId: collectionAddress
+                }
+            }
+        });
+    });
+    
+    itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => {
+        const owner = await helper.eth.createAccountWithBalance(donor);
+        const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+        const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+        const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+        
+        {
+            const events: any = [];
+            collectionHelper.events.allEvents((_: any, event: any) => {
+                events.push(event);
+            });
+            await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});
+            expect(events).to.be.like([
+                {
+                    event: 'CollectionChanged',
+                    returnValues: {
+                        collectionId: collectionAddress
+                    }
+                }
+            ]);
+        }
+        {
+            const events: any = [];
+            collectionHelper.events.allEvents((_: any, event: any) => {
+                events.push(event);
+            });
+            await collection.methods.deleteCollectionProperties(['A']).send({from:owner});
+            expect(events).to.be.like([
+                {
+                    event: 'CollectionChanged',
+                    returnValues: {
+                        collectionId: collectionAddress
+                    }
+                }
+            ]);
+        }
+
+    });
+    
+    itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => {
+        const owner = await helper.eth.createAccountWithBalance(donor);
+        const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+        const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+        const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+        const events: any = [];
+        collectionHelper.events.allEvents((_: any, event: any) => {
+            events.push(event);
+        });
+        await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});
+        expect(events).to.be.like([
+            {
+                event: 'CollectionChanged',
+                returnValues: {
+                    collectionId: collectionAddress
+                }
+            }
+        ]);
+    });
+    
+    // itEth('CollectionChanged event for AllowListAddressAdded', async ({helper}) => {
+    //     const owner = await helper.eth.createAccountWithBalance(donor);
+    //     const user = await helper.eth.createAccount();
+    //     const userCross = helper.ethCrossAccount.fromAddress(user);
+    //     const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+    //   // allow list does not need to be enabled to add someone in advance
+    //     const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+    //     const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+    //     const events: any = [];
+    //     collectionHelper.events.allEvents((_: any, event: any) => {
+    //         events.push(event);
+    //     });
+    //     await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
+    //     expect(events).to.be.like([
+    //         {
+    //             event: 'CollectionChanged',
+    //             returnValues: {
+    //                 collectionId: collectionAddress
+    //             }
+    //         }
+    //     ]);
+    // });
+});
\ No newline at end of file