git.delta.rocks / unique-network / refs/commits / b87343e4913b

difftreelog

patch: Refactor confirm sponsorship. Add test for confrim sponsorship.

Trubnikov Sergey2022-08-05parent: #9252b2e.patch.diff
in: master

2 files changed

modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/lib.rs
+++ b/pallets/evm-contract-helpers/src/lib.rs
@@ -194,11 +194,10 @@
 			match Sponsoring::<T>::get(contract) {
 				SponsorshipState::Unconfirmed(sponsor) => {
 					ensure!(sponsor == *sender, Error::<T>::NoPermission);
-					Sponsoring::<T>::mutate_exists(contract, |state| {
-						*state = Some(SponsorshipState::<T::CrossAccountId>::Confirmed(
-							sponsor.clone(),
-						))
-					});
+					Sponsoring::<T>::insert(
+						contract,
+						SponsorshipState::<T::CrossAccountId>::Confirmed(sponsor),
+					);
 					Ok(())
 				}
 				SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => {
modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
110 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;110 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
111 });111 });
112
113 itWeb3('Sponsorship can not be confirmed by the address that not set as sponsor', async ({api, web3, privateKeyWrapper}) => {
114 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
115 const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
116 const flipper = await deployFlipper(web3, owner);
117 const helpers = contractHelpers(web3, owner);
118 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
119 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor');
120 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
121 });
112122
113 itWeb3('Get self sponsored sponsor', async ({api, web3, privateKeyWrapper}) => {123 itWeb3('Get self sponsored sponsor', async ({api, web3, privateKeyWrapper}) => {
114 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);124 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);