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
194 match Sponsoring::<T>::get(contract) {194 match Sponsoring::<T>::get(contract) {
195 SponsorshipState::Unconfirmed(sponsor) => {195 SponsorshipState::Unconfirmed(sponsor) => {
196 ensure!(sponsor == *sender, Error::<T>::NoPermission);196 ensure!(sponsor == *sender, Error::<T>::NoPermission);
197 Sponsoring::<T>::mutate_exists(contract, |state| {197 Sponsoring::<T>::insert(
198 contract,
198 *state = Some(SponsorshipState::<T::CrossAccountId>::Confirmed(199 SponsorshipState::<T::CrossAccountId>::Confirmed(sponsor),
199 sponsor.clone(),
200 ))
201 });200 );
202 Ok(())201 Ok(())
203 }202 }
204 SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => {203 SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => {
modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -110,6 +110,16 @@
     expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
   });
 
+  itWeb3('Sponsorship can not be confirmed by the address that not set as sponsor', async ({api, web3, privateKeyWrapper}) => {
+    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    const flipper = await deployFlipper(web3, owner);
+    const helpers = contractHelpers(web3, owner);
+    expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
+    await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor');
+    expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
+  });
+
   itWeb3('Get self sponsored sponsor', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const flipper = await deployFlipper(web3, owner);