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
before · tests/src/eth/abi/collectionHelpers.json
1[2  {3    "anonymous": false,4    "inputs": [5      {6        "indexed": true,7        "internalType": "address",8        "name": "owner",9        "type": "address"10      },11      {12        "indexed": true,13        "internalType": "address",14        "name": "collectionId",15        "type": "address"16      }17    ],18    "name": "CollectionCreated",19    "type": "event"20  },21  {22    "anonymous": false,23    "inputs": [24      {25        "indexed": true,26        "internalType": "address",27        "name": "collectionId",28        "type": "address"29      }30    ],31    "name": "CollectionDestroyed",32    "type": "event"33  },34  {35    "inputs": [36      { "internalType": "uint32", "name": "collectionId", "type": "uint32" }37    ],38    "name": "collectionAddress",39    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],40    "stateMutability": "view",41    "type": "function"42  },43  {44    "inputs": [],45    "name": "collectionCreationFee",46    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],47    "stateMutability": "view",48    "type": "function"49  },50  {51    "inputs": [52      {53        "internalType": "address",54        "name": "collectionAddress",55        "type": "address"56      }57    ],58    "name": "collectionId",59    "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],60    "stateMutability": "view",61    "type": "function"62  },63  {64    "inputs": [65      { "internalType": "string", "name": "name", "type": "string" },66      { "internalType": "uint8", "name": "decimals", "type": "uint8" },67      { "internalType": "string", "name": "description", "type": "string" },68      { "internalType": "string", "name": "tokenPrefix", "type": "string" }69    ],70    "name": "createFTCollection",71    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],72    "stateMutability": "payable",73    "type": "function"74  },75  {76    "inputs": [77      { "internalType": "string", "name": "name", "type": "string" },78      { "internalType": "string", "name": "description", "type": "string" },79      { "internalType": "string", "name": "tokenPrefix", "type": "string" }80    ],81    "name": "createNFTCollection",82    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],83    "stateMutability": "payable",84    "type": "function"85  },86  {87    "inputs": [88      { "internalType": "string", "name": "name", "type": "string" },89      { "internalType": "string", "name": "description", "type": "string" },90      { "internalType": "string", "name": "tokenPrefix", "type": "string" }91    ],92    "name": "createRFTCollection",93    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],94    "stateMutability": "payable",95    "type": "function"96  },97  {98    "inputs": [99      {100        "internalType": "address",101        "name": "collectionAddress",102        "type": "address"103      }104    ],105    "name": "destroyCollection",106    "outputs": [],107    "stateMutability": "nonpayable",108    "type": "function"109  },110  {111    "inputs": [112      {113        "internalType": "address",114        "name": "collectionAddress",115        "type": "address"116      }117    ],118    "name": "isCollectionExist",119    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],120    "stateMutability": "view",121    "type": "function"122  },123  {124    "inputs": [125      { "internalType": "address", "name": "collection", "type": "address" },126      { "internalType": "string", "name": "baseUri", "type": "string" }127    ],128    "name": "makeCollectionERC721MetadataCompatible",129    "outputs": [],130    "stateMutability": "nonpayable",131    "type": "function"132  },133  {134    "inputs": [135      { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }136    ],137    "name": "supportsInterface",138    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],139    "stateMutability": "view",140    "type": "function"141  }142]
after · tests/src/eth/abi/collectionHelpers.json
1[2  {3    "anonymous": false,4    "inputs": [5      {6        "indexed": true,7        "internalType": "address",8        "name": "collectionId",9        "type": "address"10      }11    ],12    "name": "CollectionChanged",13    "type": "event"14  },15  {16    "anonymous": false,17    "inputs": [18      {19        "indexed": true,20        "internalType": "address",21        "name": "owner",22        "type": "address"23      },24      {25        "indexed": true,26        "internalType": "address",27        "name": "collectionId",28        "type": "address"29      }30    ],31    "name": "CollectionCreated",32    "type": "event"33  },34  {35    "anonymous": false,36    "inputs": [37      {38        "indexed": true,39        "internalType": "address",40        "name": "collectionId",41        "type": "address"42      }43    ],44    "name": "CollectionDestroyed",45    "type": "event"46  },47  {48    "inputs": [49      { "internalType": "uint32", "name": "collectionId", "type": "uint32" }50    ],51    "name": "collectionAddress",52    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],53    "stateMutability": "view",54    "type": "function"55  },56  {57    "inputs": [],58    "name": "collectionCreationFee",59    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],60    "stateMutability": "view",61    "type": "function"62  },63  {64    "inputs": [65      {66        "internalType": "address",67        "name": "collectionAddress",68        "type": "address"69      }70    ],71    "name": "collectionId",72    "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],73    "stateMutability": "view",74    "type": "function"75  },76  {77    "inputs": [78      { "internalType": "string", "name": "name", "type": "string" },79      { "internalType": "uint8", "name": "decimals", "type": "uint8" },80      { "internalType": "string", "name": "description", "type": "string" },81      { "internalType": "string", "name": "tokenPrefix", "type": "string" }82    ],83    "name": "createFTCollection",84    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],85    "stateMutability": "payable",86    "type": "function"87  },88  {89    "inputs": [90      { "internalType": "string", "name": "name", "type": "string" },91      { "internalType": "string", "name": "description", "type": "string" },92      { "internalType": "string", "name": "tokenPrefix", "type": "string" }93    ],94    "name": "createNFTCollection",95    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],96    "stateMutability": "payable",97    "type": "function"98  },99  {100    "inputs": [101      { "internalType": "string", "name": "name", "type": "string" },102      { "internalType": "string", "name": "description", "type": "string" },103      { "internalType": "string", "name": "tokenPrefix", "type": "string" }104    ],105    "name": "createRFTCollection",106    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],107    "stateMutability": "payable",108    "type": "function"109  },110  {111    "inputs": [112      {113        "internalType": "address",114        "name": "collectionAddress",115        "type": "address"116      }117    ],118    "name": "destroyCollection",119    "outputs": [],120    "stateMutability": "nonpayable",121    "type": "function"122  },123  {124    "inputs": [125      {126        "internalType": "address",127        "name": "collectionAddress",128        "type": "address"129      }130    ],131    "name": "isCollectionExist",132    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],133    "stateMutability": "view",134    "type": "function"135  },136  {137    "inputs": [138      { "internalType": "address", "name": "collection", "type": "address" },139      { "internalType": "string", "name": "baseUri", "type": "string" }140    ],141    "name": "makeCollectionERC721MetadataCompatible",142    "outputs": [],143    "stateMutability": "nonpayable",144    "type": "function"145  },146  {147    "inputs": [148      { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }149    ],150    "name": "supportsInterface",151    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],152    "stateMutability": "view",153    "type": "function"154  }155]
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