--- a/tests/src/eth/marketplace/marketplace.test.ts +++ b/tests/src/eth/marketplace/marketplace.test.ts @@ -39,6 +39,7 @@ describe('Matcher contract usage', () => { itWeb3('With UNQ', async ({api, web3, privateKeyWrapper}) => { const alice = privateKeyWrapper('//Alice'); + const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); const matcherOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, { from: matcherOwner, @@ -48,7 +49,9 @@ const helpers = contractHelpers(web3, matcherOwner); await helpers.methods.setSponsoringMode(matcher.options.address, SponsoringMode.Allowlisted).send({from: matcherOwner}); await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner}); - await transferBalanceToEth(api, alice, matcher.options.address); + + await helpers.methods.setSponsor(matcher.options.address, sponsor).send({from: matcherOwner}); + await helpers.methods.confirmSponsorship(matcher.options.address).send({from: sponsor}); const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorApproveTimeout: 1}); @@ -100,6 +103,7 @@ itWeb3('With escrow', async ({api, web3, privateKeyWrapper}) => { const alice = privateKeyWrapper('//Alice'); + const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); const matcherOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); const escrow = await createEthAccountWithBalance(api, web3, privateKeyWrapper); const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, { @@ -111,7 +115,9 @@ const helpers = contractHelpers(web3, matcherOwner); await helpers.methods.setSponsoringMode(matcher.options.address, SponsoringMode.Allowlisted).send({from: matcherOwner}); await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner}); - await transferBalanceToEth(api, alice, matcher.options.address); + + await helpers.methods.setSponsor(matcher.options.address, sponsor).send({from: matcherOwner}); + await helpers.methods.confirmSponsorship(matcher.options.address).send({from: sponsor}); const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorApproveTimeout: 1}); --- a/tests/src/eth/sponsoring.test.ts +++ b/tests/src/eth/sponsoring.test.ts @@ -15,13 +15,12 @@ // along with Unique Network. If not, see . import {expect} from 'chai'; -import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, SponsoringMode, transferBalanceToEth} from './util/helpers'; +import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, SponsoringMode} from './util/helpers'; describe('EVM sponsoring', () => { itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3, privateKeyWrapper}) => { - const alice = privateKeyWrapper('//Alice'); - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); const caller = createEthAccount(web3); const originalCallerBalance = await web3.eth.getBalance(caller); expect(originalCallerBalance).to.be.equal('0'); @@ -31,28 +30,31 @@ const helpers = contractHelpers(web3, owner); await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner}); await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner}); + + await helpers.methods.setSponsor(flipper.options.address, sponsor).send({from: owner}); + await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor}); expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false; await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner}); await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner}); expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true; - - await transferBalanceToEth(api, alice, flipper.options.address); - const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address); - expect(originalFlipperBalance).to.be.not.equal('0'); + const originalSponsorBalance = await web3.eth.getBalance(sponsor); + expect(originalSponsorBalance).to.be.not.equal('0'); await flipper.methods.flip().send({from: caller}); expect(await flipper.methods.getValue().call()).to.be.true; // Balance should be taken from flipper instead of caller expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance); - expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance); + expect(await web3.eth.getBalance(sponsor)).to.be.not.equals(originalSponsorBalance); }); + itWeb3('...but this doesn\'t applies to payable value', async ({api, web3, privateKeyWrapper}) => { const alice = privateKeyWrapper('//Alice'); const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); const originalCallerBalance = await web3.eth.getBalance(caller); expect(originalCallerBalance).to.be.not.equal('0'); @@ -68,16 +70,17 @@ await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({from: owner}); expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true; - await transferBalanceToEth(api, alice, collector.options.address); + await helpers.methods.setSponsor(collector.options.address, sponsor).send({from: owner}); + await helpers.methods.confirmSponsorship(collector.options.address).send({from: sponsor}); - const originalCollectorBalance = await web3.eth.getBalance(collector.options.address); - expect(originalCollectorBalance).to.be.not.equal('0'); + const originalSponsorBalance = await web3.eth.getBalance(sponsor); + expect(originalSponsorBalance).to.be.not.equal('0'); await collector.methods.giveMoney().send({from: caller, value: '10000'}); // Balance will be taken from both caller (value) and from collector (fee) expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString()); - expect(await web3.eth.getBalance(collector.options.address)).to.be.not.equals(originalCollectorBalance); + expect(await web3.eth.getBalance(sponsor)).to.be.not.equals(originalSponsorBalance); expect(await collector.methods.getCollected().call()).to.be.equal('10000'); }); });