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
--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -21,6 +21,7 @@
 contract 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
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
before · tests/src/eth/api/CollectionHelpers.sol
1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7interface Dummy {89}1011interface ERC165 is Dummy {12	function supportsInterface(bytes4 interfaceID) external view returns (bool);13}1415/// @dev inlined interface16interface CollectionHelpersEvents {17	event CollectionCreated(address indexed owner, address indexed collectionId);18	event CollectionDestroyed(address indexed collectionId);19}2021/// @title Contract, which allows users to operate with collections22/// @dev the ERC-165 identifier for this interface is 0xe65011aa23interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {24	/// Create an NFT collection25	/// @param name Name of the collection26	/// @param description Informative description of the collection27	/// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications28	/// @return address Address of the newly created collection29	/// @dev EVM selector for this function is: 0x844af658,30	///  or in textual repr: createNFTCollection(string,string,string)31	function createNFTCollection(32		string memory name,33		string memory description,34		string memory tokenPrefix35	) external payable returns (address);3637	// /// Create an NFT collection38	// /// @param name Name of the collection39	// /// @param description Informative description of the collection40	// /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications41	// /// @return address Address of the newly created collection42	// /// @dev EVM selector for this function is: 0xe34a6844,43	// ///  or in textual repr: createNonfungibleCollection(string,string,string)44	// function createNonfungibleCollection(string memory name, string memory description, string memory tokenPrefix) external payable returns (address);4546	/// @dev EVM selector for this function is: 0xab173450,47	///  or in textual repr: createRFTCollection(string,string,string)48	function createRFTCollection(49		string memory name,50		string memory description,51		string memory tokenPrefix52	) external payable returns (address);5354	/// @dev EVM selector for this function is: 0x7335b79f,55	///  or in textual repr: createFTCollection(string,uint8,string,string)56	function createFTCollection(57		string memory name,58		uint8 decimals,59		string memory description,60		string memory tokenPrefix61	) external payable returns (address);6263	/// @dev EVM selector for this function is: 0x85624258,64	///  or in textual repr: makeCollectionERC721MetadataCompatible(address,string)65	function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) external;6667	/// @dev EVM selector for this function is: 0x564e321f,68	///  or in textual repr: destroyCollection(address)69	function destroyCollection(address collectionAddress) external;7071	/// Check if a collection exists72	/// @param collectionAddress Address of the collection in question73	/// @return bool Does the collection exist?74	/// @dev EVM selector for this function is: 0xc3de1494,75	///  or in textual repr: isCollectionExist(address)76	function isCollectionExist(address collectionAddress) external view returns (bool);7778	/// @dev EVM selector for this function is: 0xd23a7ab1,79	///  or in textual repr: collectionCreationFee()80	function collectionCreationFee() external view returns (uint256);8182	/// Returns address of a collection.83	/// @param collectionId  - CollectionId  of the collection84	/// @return eth mirror address of the collection85	/// @dev EVM selector for this function is: 0x2e716683,86	///  or in textual repr: collectionAddress(uint32)87	function collectionAddress(uint32 collectionId) external view returns (address);8889	/// Returns collectionId of a collection.90	/// @param collectionAddress  - Eth address of the collection91	/// @return collectionId of the collection92	/// @dev EVM selector for this function is: 0xb5cb7498,93	///  or in textual repr: collectionId(address)94	function collectionId(address collectionAddress) external view returns (uint32);95}
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