git.delta.rocks / unique-network / refs/commits / 837c29c459b6

difftreelog

fix Rename event field name. test: Add eth test for contract sponsor events.

Trubnikov Sergey2022-09-05parent: #ec123de.patch.diff
in: master

7 files changed

modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -42,9 +42,8 @@
 	ContractSponsorSet {
 		/// Contract address of the affected collection.
 		#[indexed]
-		contract: address,
+		contract_address: address,
 		/// New sponsor address.
-		#[indexed]
 		sponsor: address,
 	},
 
@@ -52,9 +51,8 @@
 	ContractSponsorshipConfirmed {
 		/// Contract address of the affected collection.
 		#[indexed]
-		contract: address,
+		contract_address: address,
 		/// New sponsor address.
-		#[indexed]
 		sponsor: address,
 	},
 
@@ -62,7 +60,7 @@
 	ContractSponsorRemoved {
 		/// Contract address of the affected collection.
 		#[indexed]
-		contract: address,
+		contract_address: address,
 	},
 }
 
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/lib.rs
+++ b/pallets/evm-contract-helpers/src/lib.rs
@@ -208,7 +208,7 @@
 			));
 			<PalletEvm<T>>::deposit_log(
 				ContractHelpersEvents::ContractSponsorSet {
-					contract,
+					contract_address: contract,
 					sponsor: *sponsor.as_eth(),
 				}
 				.to_log(contract),
@@ -221,14 +221,14 @@
 		/// `sender` must be owner of contract.
 		pub fn force_set_sponsor(
 			sender: &T::CrossAccountId,
-			contract: H160,
+			contract_address: H160,
 			sponsor: &T::CrossAccountId,
 		) -> DispatchResult {
-			Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;
+			Pallet::<T>::ensure_owner(contract_address, *sender.as_eth())?;
 			Sponsoring::<T>::insert(
-				contract,
+				contract_address,
 				SponsorshipState::<T::CrossAccountId>::Confirmed(T::CrossAccountId::from_eth(
-					contract,
+					contract_address,
 				)),
 			);
 
@@ -236,27 +236,27 @@
 			let sub_sponsor = sponsor.as_sub().clone();
 
 			<Pallet<T>>::deposit_event(Event::<T>::ContractSponsorSet(
-				contract,
+				contract_address,
 				sub_sponsor.clone(),
 			));
 			<PalletEvm<T>>::deposit_log(
 				ContractHelpersEvents::ContractSponsorSet {
-					contract,
+					contract_address,
 					sponsor: eth_sponsor,
 				}
-				.to_log(contract),
+				.to_log(contract_address),
 			);
 
 			<Pallet<T>>::deposit_event(Event::<T>::ContractSponsorshipConfirmed(
-				contract,
+				contract_address,
 				sub_sponsor,
 			));
 			<PalletEvm<T>>::deposit_log(
 				ContractHelpersEvents::ContractSponsorshipConfirmed {
-					contract,
+					contract_address,
 					sponsor: eth_sponsor,
 				}
-				.to_log(contract),
+				.to_log(contract_address),
 			);
 
 			Ok(())
@@ -265,13 +265,13 @@
 		/// Remove sponsor for `contract`.
 		///
 		/// `sender` must be owner of contract.
-		pub fn remove_sponsor(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
-			Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;
-			Sponsoring::<T>::remove(contract);
+		pub fn remove_sponsor(sender: &T::CrossAccountId, contract_address: H160) -> DispatchResult {
+			Pallet::<T>::ensure_owner(contract_address, *sender.as_eth())?;
+			Sponsoring::<T>::remove(contract_address);
 
-			<Pallet<T>>::deposit_event(Event::<T>::ContractSponsorRemoved(contract));
+			<Pallet<T>>::deposit_event(Event::<T>::ContractSponsorRemoved(contract_address));
 			<PalletEvm<T>>::deposit_log(
-				ContractHelpersEvents::ContractSponsorRemoved { contract }.to_log(contract),
+				ContractHelpersEvents::ContractSponsorRemoved { contract_address }.to_log(contract_address),
 			);
 
 			Ok(())
@@ -280,27 +280,27 @@
 		/// Confirm sponsorship.
 		///
 		/// `sender` must be same that set via [`set_sponsor`].
-		pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
-			match Sponsoring::<T>::get(contract) {
+		pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract_address: H160) -> DispatchResult {
+			match Sponsoring::<T>::get(contract_address) {
 				SponsorshipState::Unconfirmed(sponsor) => {
 					ensure!(sponsor == *sender, Error::<T>::NoPermission);
 					let eth_sponsor = *sponsor.as_eth();
 					let sub_sponsor = sponsor.as_sub().clone();
 					Sponsoring::<T>::insert(
-						contract,
+						contract_address,
 						SponsorshipState::<T::CrossAccountId>::Confirmed(sponsor),
 					);
 
 					<Pallet<T>>::deposit_event(Event::<T>::ContractSponsorshipConfirmed(
-						contract,
+						contract_address,
 						sub_sponsor,
 					));
 					<PalletEvm<T>>::deposit_log(
 						ContractHelpersEvents::ContractSponsorshipConfirmed {
-							contract,
+							contract_address,
 							sponsor: eth_sponsor,
 						}
-						.to_log(contract),
+						.to_log(contract_address),
 					);
 
 					Ok(())
modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
+++ b/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
@@ -21,9 +21,19 @@
 	}
 }
 
+/// @dev inlined interface
+contract ContractHelpersEvents {
+	event ContractSponsorSet(address indexed contractAddress, address sponsor);
+	event ContractSponsorshipConfirmed(
+		address indexed contractAddress,
+		address sponsor
+	);
+	event ContractSponsorRemoved(address indexed contractAddress);
+}
+
 /// @title Magic contract, which allows users to reconfigure other contracts
 /// @dev the ERC-165 identifier for this interface is 0xd77fab70
-contract ContractHelpers is Dummy, ERC165 {
+contract ContractHelpers is Dummy, ERC165, ContractHelpersEvents {
 	/// Get user, which deployed specified contract
 	/// @dev May return zero address in case if contract is deployed
 	///  using uniquenetwork evm-migration pallet, or using other terms not
modifiedtests/src/eth/api/ContractHelpers.soldiffbeforeafterboth
--- a/tests/src/eth/api/ContractHelpers.sol
+++ b/tests/src/eth/api/ContractHelpers.sol
@@ -12,9 +12,19 @@
 	function supportsInterface(bytes4 interfaceID) external view returns (bool);
 }
 
+/// @dev inlined interface
+interface ContractHelpersEvents {
+	event ContractSponsorSet(address indexed contractAddress, address sponsor);
+	event ContractSponsorshipConfirmed(
+		address indexed contractAddress,
+		address sponsor
+	);
+	event ContractSponsorRemoved(address indexed contractAddress);
+}
+
 /// @title Magic contract, which allows users to reconfigure other contracts
 /// @dev the ERC-165 identifier for this interface is 0xd77fab70
-interface ContractHelpers is Dummy, ERC165 {
+interface ContractHelpers is Dummy, ERC165, ContractHelpersEvents {
 	/// Get user, which deployed specified contract
 	/// @dev May return zero address in case if contract is deployed
 	///  using uniquenetwork evm-migration pallet, or using other terms not
modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
24 SponsoringMode,24 SponsoringMode,
25 createEthAccount,25 createEthAccount,
26 ethBalanceViaSub,26 ethBalanceViaSub,
27 normalizeEvents,
27} from './util/helpers';28} from './util/helpers';
2829
29describe('Sponsoring EVM contracts', () => {30describe('Sponsoring EVM contracts', () => {
36 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;37 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
37 });38 });
39
40 itWeb3.only('Set self sponsored events', async ({api, web3, privateKeyWrapper}) => {
41 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
42 const flipper = await deployFlipper(web3, owner);
43 const helpers = contractHelpers(web3, owner);
44
45 const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send();
46 const events = normalizeEvents(result.events);
47 expect(events).to.be.deep.equal([
48 {
49 address: flipper.options.address,
50 event: 'ContractSponsorSet',
51 args: {
52 contractAddress: flipper.options.address,
53 sponsor: flipper.options.address,
54 },
55 },
56 {
57 address: flipper.options.address,
58 event: 'ContractSponsorshipConfirmed',
59 args: {
60 contractAddress: flipper.options.address,
61 sponsor: flipper.options.address,
62 },
63 },
64 ]);
65 });
3866
39 itWeb3('Self sponsored can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {67 itWeb3('Self sponsored can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {
40 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);68 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
75 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;103 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;
76 });104 });
77 105
106 itWeb3('Set sponsor event', async ({api, web3, privateKeyWrapper}) => {
107 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
108 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
109 const flipper = await deployFlipper(web3, owner);
110 const helpers = contractHelpers(web3, owner);
111
112 const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
113 const events = normalizeEvents(result.events);
114 expect(events).to.be.deep.equal([
115 {
116 address: flipper.options.address,
117 event: 'ContractSponsorSet',
118 args: {
119 contractAddress: flipper.options.address,
120 sponsor: sponsor,
121 },
122 },
123 ]);
124 });
125
78 itWeb3('Sponsor can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {126 itWeb3('Sponsor can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {
79 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);127 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
97 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;145 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
98 });146 });
147
148 itWeb3('Confirm sponsorship event', async ({api, web3, privateKeyWrapper}) => {
149 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
150 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
151 const flipper = await deployFlipper(web3, owner);
152 const helpers = contractHelpers(web3, owner);
153 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;
154 const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
155 const events = normalizeEvents(result.events);
156 expect(events).to.be.deep.equal([
157 {
158 address: flipper.options.address,
159 event: 'ContractSponsorshipConfirmed',
160 args: {
161 contractAddress: flipper.options.address,
162 sponsor: sponsor,
163 },
164 },
165 ]);
166 });
99167
100 itWeb3('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({api, web3, privateKeyWrapper}) => {168 itWeb3('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({api, web3, privateKeyWrapper}) => {
101 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);169 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
160 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;228 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
161 });229 });
230
231 itWeb3('Remove sponsor event', async ({api, web3, privateKeyWrapper}) => {
232 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
233 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
234 const flipper = await deployFlipper(web3, owner);
235 const helpers = contractHelpers(web3, owner);
236
237 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
238 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
239
240 const result = await helpers.methods.removeSponsor(flipper.options.address).send();
241 const events = normalizeEvents(result.events);
242 expect(events).to.be.deep.equal([
243 {
244 address: flipper.options.address,
245 event: 'ContractSponsorRemoved',
246 args: {
247 contractAddress: flipper.options.address,
248 },
249 },
250 ]);
251 });
162252
163 itWeb3('Sponsor can not be removed by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {253 itWeb3('Sponsor can not be removed by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {
164 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);254 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
modifiedtests/src/eth/util/contractHelpersAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/util/contractHelpersAbi.json
+++ b/tests/src/eth/util/contractHelpersAbi.json
@@ -1,5 +1,56 @@
 [
   {
+    "anonymous": false,
+    "inputs": [
+      {
+        "indexed": true,
+        "internalType": "address",
+        "name": "contractAddress",
+        "type": "address"
+      }
+    ],
+    "name": "ContractSponsorRemoved",
+    "type": "event"
+  },
+  {
+    "anonymous": false,
+    "inputs": [
+      {
+        "indexed": true,
+        "internalType": "address",
+        "name": "contractAddress",
+        "type": "address"
+      },
+      {
+        "indexed": false,
+        "internalType": "address",
+        "name": "sponsor",
+        "type": "address"
+      }
+    ],
+    "name": "ContractSponsorSet",
+    "type": "event"
+  },
+  {
+    "anonymous": false,
+    "inputs": [
+      {
+        "indexed": true,
+        "internalType": "address",
+        "name": "contractAddress",
+        "type": "address"
+      },
+      {
+        "indexed": false,
+        "internalType": "address",
+        "name": "sponsor",
+        "type": "address"
+      }
+    ],
+    "name": "ContractSponsorshipConfirmed",
+    "type": "event"
+  },
+  {
     "inputs": [
       {
         "internalType": "address",