difftreelog
feat add evm event `CollectionChanged` for sub events : `CollectionPropertySet`, `CollectionPropertyDeleted`, `PropertyPermissionSet`
in: master
7 files changed
pallets/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
pallets/common/src/lib.rsdiffbeforeafterboth1036 .map_err(<Error<T>>::from)?;1036 .map_err(<Error<T>>::from)?;103710371038 Self::deposit_event(Event::CollectionPropertySet(collection.id, property.key));1038 Self::deposit_event(Event::CollectionPropertySet(collection.id, property.key));1039 <PalletEvm<T>>::deposit_log(1040 erc::CollectionHelpersEvents::CollectionChanged {1041 collection_id: eth::collection_id_to_address(collection.id),1042 }1043 .to_log(T::ContractAddress::get()),1044 );103910451040 Ok(())1046 Ok(())1041 }1047 }1115 collection.id,1121 collection.id,1116 property_key,1122 property_key,1117 ));1123 ));1124 <PalletEvm<T>>::deposit_log(1125 erc::CollectionHelpersEvents::CollectionChanged {1126 collection_id: eth::collection_id_to_address(collection.id),1127 }1128 .to_log(T::ContractAddress::get()),1129 );111811301119 Ok(())1131 Ok(())1120 }1132 }1209 collection.id,1221 collection.id,1210 property_permission.key,1222 property_permission.key,1211 ));1223 ));1224 <PalletEvm<T>>::deposit_log(1225 erc::CollectionHelpersEvents::CollectionChanged {1226 collection_id: eth::collection_id_to_address(collection.id),1227 }1228 .to_log(T::ContractAddress::get()),1229 );121212301213 Ok(())1231 Ok(())1214 }1232 }pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/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
tests/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"
},
tests/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
tests/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