difftreelog
patch: Refactor confirm sponsorship. Add test for confrim sponsorship.
in: master
2 files changed
pallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth194 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(_) => {tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth110 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 });112113 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 });112122113 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);