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

difftreelog

path: Fix other broken tests.

Trubnikov Sergey2022-08-05parent: #1b2f0f9.patch.diff
in: master

2 files changed

modifiedtests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth
--- 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});
modifiedtests/src/eth/sponsoring.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {expect} from 'chai';17import {expect} from 'chai';
18import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, SponsoringMode, transferBalanceToEth} from './util/helpers';18import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, SponsoringMode} from './util/helpers';
1919
20describe('EVM sponsoring', () => {20describe('EVM sponsoring', () => {
21 itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3, privateKeyWrapper}) => {21 itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3, privateKeyWrapper}) => {
22 const alice = privateKeyWrapper('//Alice');22 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
23
24 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);23 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
25 const caller = createEthAccount(web3);24 const caller = createEthAccount(web3);
26 const originalCallerBalance = await web3.eth.getBalance(caller);25 const originalCallerBalance = await web3.eth.getBalance(caller);
27 expect(originalCallerBalance).to.be.equal('0');26 expect(originalCallerBalance).to.be.equal('0');
32 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});31 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
33 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});32 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
33
34 await helpers.methods.setSponsor(flipper.options.address, sponsor).send({from: owner});
35 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
3436
35 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;37 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
36 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});38 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
37 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});39 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
38 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;40 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
39
40 await transferBalanceToEth(api, alice, flipper.options.address);
4141
42 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);42 const originalSponsorBalance = await web3.eth.getBalance(sponsor);
43 expect(originalFlipperBalance).to.be.not.equal('0');43 expect(originalSponsorBalance).to.be.not.equal('0');
4444
45 await flipper.methods.flip().send({from: caller});45 await flipper.methods.flip().send({from: caller});
46 expect(await flipper.methods.getValue().call()).to.be.true;46 expect(await flipper.methods.getValue().call()).to.be.true;
4747
48 // Balance should be taken from flipper instead of caller48 // Balance should be taken from flipper instead of caller
49 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);49 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
50 expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance);50 expect(await web3.eth.getBalance(sponsor)).to.be.not.equals(originalSponsorBalance);
51 });51 });
52
52 itWeb3('...but this doesn\'t applies to payable value', async ({api, web3, privateKeyWrapper}) => {53 itWeb3('...but this doesn\'t applies to payable value', async ({api, web3, privateKeyWrapper}) => {
53 const alice = privateKeyWrapper('//Alice');54 const alice = privateKeyWrapper('//Alice');
5455
55 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);56 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
57 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
56 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);58 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
57 const originalCallerBalance = await web3.eth.getBalance(caller);59 const originalCallerBalance = await web3.eth.getBalance(caller);
58 expect(originalCallerBalance).to.be.not.equal('0');60 expect(originalCallerBalance).to.be.not.equal('0');
68 await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({from: owner});70 await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({from: owner});
69 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;71 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;
7072
71 await transferBalanceToEth(api, alice, collector.options.address);73 await helpers.methods.setSponsor(collector.options.address, sponsor).send({from: owner});
72
73 const originalCollectorBalance = await web3.eth.getBalance(collector.options.address);74 await helpers.methods.confirmSponsorship(collector.options.address).send({from: sponsor});
75
76 const originalSponsorBalance = await web3.eth.getBalance(sponsor);
74 expect(originalCollectorBalance).to.be.not.equal('0');77 expect(originalSponsorBalance).to.be.not.equal('0');
7578
76 await collector.methods.giveMoney().send({from: caller, value: '10000'});79 await collector.methods.giveMoney().send({from: caller, value: '10000'});
7780
78 // Balance will be taken from both caller (value) and from collector (fee)81 // Balance will be taken from both caller (value) and from collector (fee)
79 expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());82 expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());
80 expect(await web3.eth.getBalance(collector.options.address)).to.be.not.equals(originalCollectorBalance);83 expect(await web3.eth.getBalance(sponsor)).to.be.not.equals(originalSponsorBalance);
81 expect(await collector.methods.getCollected().call()).to.be.equal('10000');84 expect(await collector.methods.getCollected().call()).to.be.equal('10000');
82 });85 });
83});86});