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
42 ContractSponsorSet {42 ContractSponsorSet {
43 /// Contract address of the affected collection.43 /// Contract address of the affected collection.
44 #[indexed]44 #[indexed]
45 contract: address,45 contract_address: address,
46 /// New sponsor address.46 /// New sponsor address.
47 #[indexed]
48 sponsor: address,47 sponsor: address,
49 },48 },
5049
51 /// New sponsor was confirm.50 /// New sponsor was confirm.
52 ContractSponsorshipConfirmed {51 ContractSponsorshipConfirmed {
53 /// Contract address of the affected collection.52 /// Contract address of the affected collection.
54 #[indexed]53 #[indexed]
55 contract: address,54 contract_address: address,
56 /// New sponsor address.55 /// New sponsor address.
57 #[indexed]
58 sponsor: address,56 sponsor: address,
59 },57 },
6058
61 /// Collection sponsor was removed.59 /// Collection sponsor was removed.
62 ContractSponsorRemoved {60 ContractSponsorRemoved {
63 /// Contract address of the affected collection.61 /// Contract address of the affected collection.
64 #[indexed]62 #[indexed]
65 contract: address,63 contract_address: address,
66 },64 },
67}65}
6866
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
208 ));208 ));
209 <PalletEvm<T>>::deposit_log(209 <PalletEvm<T>>::deposit_log(
210 ContractHelpersEvents::ContractSponsorSet {210 ContractHelpersEvents::ContractSponsorSet {
211 contract,211 contract_address: contract,
212 sponsor: *sponsor.as_eth(),212 sponsor: *sponsor.as_eth(),
213 }213 }
214 .to_log(contract),214 .to_log(contract),
221 /// `sender` must be owner of contract.221 /// `sender` must be owner of contract.
222 pub fn force_set_sponsor(222 pub fn force_set_sponsor(
223 sender: &T::CrossAccountId,223 sender: &T::CrossAccountId,
224 contract: H160,224 contract_address: H160,
225 sponsor: &T::CrossAccountId,225 sponsor: &T::CrossAccountId,
226 ) -> DispatchResult {226 ) -> DispatchResult {
227 Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;227 Pallet::<T>::ensure_owner(contract_address, *sender.as_eth())?;
228 Sponsoring::<T>::insert(228 Sponsoring::<T>::insert(
229 contract,229 contract_address,
230 SponsorshipState::<T::CrossAccountId>::Confirmed(T::CrossAccountId::from_eth(230 SponsorshipState::<T::CrossAccountId>::Confirmed(T::CrossAccountId::from_eth(
231 contract,231 contract_address,
232 )),232 )),
233 );233 );
234234
235 let eth_sponsor = *sponsor.as_eth();235 let eth_sponsor = *sponsor.as_eth();
236 let sub_sponsor = sponsor.as_sub().clone();236 let sub_sponsor = sponsor.as_sub().clone();
237237
238 <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorSet(238 <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorSet(
239 contract,239 contract_address,
240 sub_sponsor.clone(),240 sub_sponsor.clone(),
241 ));241 ));
242 <PalletEvm<T>>::deposit_log(242 <PalletEvm<T>>::deposit_log(
243 ContractHelpersEvents::ContractSponsorSet {243 ContractHelpersEvents::ContractSponsorSet {
244 contract,244 contract_address,
245 sponsor: eth_sponsor,245 sponsor: eth_sponsor,
246 }246 }
247 .to_log(contract),247 .to_log(contract_address),
248 );248 );
249249
250 <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorshipConfirmed(250 <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorshipConfirmed(
251 contract,251 contract_address,
252 sub_sponsor,252 sub_sponsor,
253 ));253 ));
254 <PalletEvm<T>>::deposit_log(254 <PalletEvm<T>>::deposit_log(
255 ContractHelpersEvents::ContractSponsorshipConfirmed {255 ContractHelpersEvents::ContractSponsorshipConfirmed {
256 contract,256 contract_address,
257 sponsor: eth_sponsor,257 sponsor: eth_sponsor,
258 }258 }
259 .to_log(contract),259 .to_log(contract_address),
260 );260 );
261261
262 Ok(())262 Ok(())
265 /// Remove sponsor for `contract`.265 /// Remove sponsor for `contract`.
266 ///266 ///
267 /// `sender` must be owner of contract.267 /// `sender` must be owner of contract.
268 pub fn remove_sponsor(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {268 pub fn remove_sponsor(sender: &T::CrossAccountId, contract_address: H160) -> DispatchResult {
269 Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;269 Pallet::<T>::ensure_owner(contract_address, *sender.as_eth())?;
270 Sponsoring::<T>::remove(contract);270 Sponsoring::<T>::remove(contract_address);
271271
272 <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorRemoved(contract));272 <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorRemoved(contract_address));
273 <PalletEvm<T>>::deposit_log(273 <PalletEvm<T>>::deposit_log(
274 ContractHelpersEvents::ContractSponsorRemoved { contract }.to_log(contract),274 ContractHelpersEvents::ContractSponsorRemoved { contract_address }.to_log(contract_address),
275 );275 );
276276
277 Ok(())277 Ok(())
280 /// Confirm sponsorship.280 /// Confirm sponsorship.
281 ///281 ///
282 /// `sender` must be same that set via [`set_sponsor`].282 /// `sender` must be same that set via [`set_sponsor`].
283 pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {283 pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract_address: H160) -> DispatchResult {
284 match Sponsoring::<T>::get(contract) {284 match Sponsoring::<T>::get(contract_address) {
285 SponsorshipState::Unconfirmed(sponsor) => {285 SponsorshipState::Unconfirmed(sponsor) => {
286 ensure!(sponsor == *sender, Error::<T>::NoPermission);286 ensure!(sponsor == *sender, Error::<T>::NoPermission);
287 let eth_sponsor = *sponsor.as_eth();287 let eth_sponsor = *sponsor.as_eth();
288 let sub_sponsor = sponsor.as_sub().clone();288 let sub_sponsor = sponsor.as_sub().clone();
289 Sponsoring::<T>::insert(289 Sponsoring::<T>::insert(
290 contract,290 contract_address,
291 SponsorshipState::<T::CrossAccountId>::Confirmed(sponsor),291 SponsorshipState::<T::CrossAccountId>::Confirmed(sponsor),
292 );292 );
293293
294 <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorshipConfirmed(294 <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorshipConfirmed(
295 contract,295 contract_address,
296 sub_sponsor,296 sub_sponsor,
297 ));297 ));
298 <PalletEvm<T>>::deposit_log(298 <PalletEvm<T>>::deposit_log(
299 ContractHelpersEvents::ContractSponsorshipConfirmed {299 ContractHelpersEvents::ContractSponsorshipConfirmed {
300 contract,300 contract_address,
301 sponsor: eth_sponsor,301 sponsor: eth_sponsor,
302 }302 }
303 .to_log(contract),303 .to_log(contract_address),
304 );304 );
305305
306 Ok(())306 Ok(())
modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth
21 }21 }
22}22}
23
24/// @dev inlined interface
25contract ContractHelpersEvents {
26 event ContractSponsorSet(address indexed contractAddress, address sponsor);
27 event ContractSponsorshipConfirmed(
28 address indexed contractAddress,
29 address sponsor
30 );
31 event ContractSponsorRemoved(address indexed contractAddress);
32}
2333
24/// @title Magic contract, which allows users to reconfigure other contracts34/// @title Magic contract, which allows users to reconfigure other contracts
25/// @dev the ERC-165 identifier for this interface is 0xd77fab7035/// @dev the ERC-165 identifier for this interface is 0xd77fab70
26contract ContractHelpers is Dummy, ERC165 {36contract ContractHelpers is Dummy, ERC165, ContractHelpersEvents {
27 /// Get user, which deployed specified contract37 /// Get user, which deployed specified contract
28 /// @dev May return zero address in case if contract is deployed38 /// @dev May return zero address in case if contract is deployed
29 /// using uniquenetwork evm-migration pallet, or using other terms not39 /// using uniquenetwork evm-migration pallet, or using other terms not
modifiedtests/src/eth/api/ContractHelpers.soldiffbeforeafterboth
12 function supportsInterface(bytes4 interfaceID) external view returns (bool);12 function supportsInterface(bytes4 interfaceID) external view returns (bool);
13}13}
14
15/// @dev inlined interface
16interface ContractHelpersEvents {
17 event ContractSponsorSet(address indexed contractAddress, address sponsor);
18 event ContractSponsorshipConfirmed(
19 address indexed contractAddress,
20 address sponsor
21 );
22 event ContractSponsorRemoved(address indexed contractAddress);
23}
1424
15/// @title Magic contract, which allows users to reconfigure other contracts25/// @title Magic contract, which allows users to reconfigure other contracts
16/// @dev the ERC-165 identifier for this interface is 0xd77fab7026/// @dev the ERC-165 identifier for this interface is 0xd77fab70
17interface ContractHelpers is Dummy, ERC165 {27interface ContractHelpers is Dummy, ERC165, ContractHelpersEvents {
18 /// Get user, which deployed specified contract28 /// Get user, which deployed specified contract
19 /// @dev May return zero address in case if contract is deployed29 /// @dev May return zero address in case if contract is deployed
20 /// using uniquenetwork evm-migration pallet, or using other terms not30 /// 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
1[1[
2 {
3 "anonymous": false,
4 "inputs": [
5 {
6 "indexed": true,
7 "internalType": "address",
8 "name": "contractAddress",
9 "type": "address"
10 }
11 ],
12 "name": "ContractSponsorRemoved",
13 "type": "event"
14 },
15 {
16 "anonymous": false,
17 "inputs": [
18 {
19 "indexed": true,
20 "internalType": "address",
21 "name": "contractAddress",
22 "type": "address"
23 },
24 {
25 "indexed": false,
26 "internalType": "address",
27 "name": "sponsor",
28 "type": "address"
29 }
30 ],
31 "name": "ContractSponsorSet",
32 "type": "event"
33 },
34 {
35 "anonymous": false,
36 "inputs": [
37 {
38 "indexed": true,
39 "internalType": "address",
40 "name": "contractAddress",
41 "type": "address"
42 },
43 {
44 "indexed": false,
45 "internalType": "address",
46 "name": "sponsor",
47 "type": "address"
48 }
49 ],
50 "name": "ContractSponsorshipConfirmed",
51 "type": "event"
52 },
2 {53 {
3 "inputs": [54 "inputs": [
4 {55 {