difftreelog
Missing contract sponsoring tests added
in: master
2 files changed
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth8import { 8import { 9 contractHelpers,9 contractHelpers,10 createEthAccountWithBalance,10 createEthAccountWithBalance,11 createEthAccount,12 transferBalanceToEth,11 transferBalanceToEth,13 deployFlipper,12 deployFlipper,14 usingWeb3Http,15 itWeb3 } from './util/helpers';13 itWeb3 } from './util/helpers';16import waitNewBlocks from '../substrate/wait-new-blocks';14import waitNewBlocks from '../substrate/wait-new-blocks';171518describe.only('Sponsoring EVM contracts', () => {16describe.only('Sponsoring EVM contracts', () => {19 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api}) => {17 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {20 await usingWeb3Http(async web3Http => {18 const owner = await createEthAccountWithBalance(api, web3);21 const owner = await createEthAccountWithBalance(api, web3Http);22 const flipper = await deployFlipper(web3Http, owner);19 const flipper = await deployFlipper(web3, owner);23 await waitNewBlocks(api, 1);20 await waitNewBlocks(api, 1);24 const helpers = contractHelpers(web3Http, owner);21 const helpers = contractHelpers(web3, owner);25 await waitNewBlocks(api, 1);22 await waitNewBlocks(api, 1);26 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;23 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;27 await waitNewBlocks(api, 1);24 await waitNewBlocks(api, 1);28 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});25 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});29 await waitNewBlocks(api, 1);26 await waitNewBlocks(api, 1);30 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;27 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;31 });32 });28 });332934 itWeb3('Sponsoring cannot be set by the address that did not deployed the contract', async ({api}) => {30 itWeb3('Sponsoring cannot be set by the address that did not deployed the contract', async ({api, web3}) => {35 await usingWeb3Http(async web3Http => {31 const owner = await createEthAccountWithBalance(api, web3);36 const owner = await createEthAccountWithBalance(api, web3Http);37 const notOwner = await createEthAccountWithBalance(api, web3Http);32 const notOwner = await createEthAccountWithBalance(api, web3);38 const flipper = await deployFlipper(web3Http, owner);33 const flipper = await deployFlipper(web3, owner);39 await waitNewBlocks(api, 1);34 await waitNewBlocks(api, 1);40 const helpers = contractHelpers(web3Http, owner);35 const helpers = contractHelpers(web3, owner);41 await waitNewBlocks(api, 1);36 await waitNewBlocks(api, 1);42 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;43 await waitNewBlocks(api, 1);38 await waitNewBlocks(api, 1);44 await expect(helpers.methods.toggleSponsoring(notOwner, true).send({from: notOwner})).to.rejected;39 await expect(helpers.methods.toggleSponsoring(notOwner, true).send({from: notOwner})).to.rejected;45 await waitNewBlocks(api, 1);40 await waitNewBlocks(api, 1);46 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;41 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;47 });48 });42 });494350 itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease', async ({api, web3}) => {44 itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (whitelisted)', async ({api, web3}) => {51 await usingWeb3Http(async web3Http => {52 const alice = privateKey('//Alice');45 const alice = privateKey('//Alice');534654 const owner = await createEthAccountWithBalance(api, web3Http);47 const owner = await createEthAccountWithBalance(api, web3);55 const caller = createEthAccount(web3Http);48 const caller = await createEthAccountWithBalance(api, web3);56 const originalCallerBalance = await web3.eth.getBalance(caller);57 expect(originalCallerBalance).to.be.equal('0');584959 const flipper = await deployFlipper(web3Http, owner);50 const flipper = await deployFlipper(web3, owner);60 await waitNewBlocks(api, 1);51 await waitNewBlocks(api, 1);61 52 62 const helpers = contractHelpers(web3Http, owner);53 const helpers = contractHelpers(web3, owner);63 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });54 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });64 await waitNewBlocks(api, 1);55 await waitNewBlocks(api, 1);65 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });56 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });66 await waitNewBlocks(api, 1);57 await waitNewBlocks(api, 1);675868 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;59 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;69 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});60 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});70 await waitNewBlocks(api, 1);61 await waitNewBlocks(api, 1);71 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});62 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});72 await waitNewBlocks(api, 1);63 await waitNewBlocks(api, 1);73 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;64 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;746575 await transferBalanceToEth(api, alice, flipper.options.address);66 await transferBalanceToEth(api, alice, flipper.options.address);76 await waitNewBlocks(api, 2);67 await waitNewBlocks(api, 2);776878 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);69 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);79 expect(originalFlipperBalance).to.be.not.equal('0');70 expect(originalFlipperBalance).to.be.not.equal('0');807181 await flipper.methods.flip().send({ from: caller });72 await flipper.methods.flip().send({ from: caller });82 await waitNewBlocks(api, 1);73 await waitNewBlocks(api, 1);83 expect(await flipper.methods.getValue().call()).to.be.true;74 expect(await flipper.methods.getValue().call()).to.be.true;847585 // Balance should be taken from flipper instead of caller76 // Balance should be taken from flipper instead of caller86 const balanceAfter = await web3.eth.getBalance(flipper.options.address);77 const balanceAfter = await web3.eth.getBalance(flipper.options.address);87 expect(+balanceAfter).to.be.lessThan(+originalFlipperBalance);78 expect(+balanceAfter).to.be.lessThan(+originalFlipperBalance);88 });89 });79 });908081 itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-whitelisted)', async ({api, web3}) => {82 const alice = privateKey('//Alice');8384 const owner = await createEthAccountWithBalance(api, web3);85 const caller = await createEthAccountWithBalance(api, web3);8687 const flipper = await deployFlipper(web3, owner);88 await waitNewBlocks(api, 1);89 90 const helpers = contractHelpers(web3, owner);9192 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;93 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});94 await waitNewBlocks(api, 1);95 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});96 await waitNewBlocks(api, 1);97 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;9899 await transferBalanceToEth(api, alice, flipper.options.address);100 await waitNewBlocks(api, 2);101102 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);103 expect(originalFlipperBalance).to.be.not.equal('0');104105 await flipper.methods.flip().send({ from: caller });106 await waitNewBlocks(api, 1);107 expect(await flipper.methods.getValue().call()).to.be.true;108109 // Balance should be taken from flipper instead of caller110 const balanceAfter = await web3.eth.getBalance(flipper.options.address);111 expect(+balanceAfter).to.be.equals(+originalFlipperBalance);112 });11391 itWeb3('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({api, web3}) => {114 itWeb3('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({api, web3}) => {92 await usingWeb3Http(async web3Http => {115 const alice = privateKey('//Alice');93 const alice = privateKey('//Alice');9411695 const owner = await createEthAccountWithBalance(api, web3Http);117 const owner = await createEthAccountWithBalance(api, web3);96 const caller = createEthAccount(web3Http);118 const caller = await createEthAccountWithBalance(api, web3);97 const originalCallerBalance = await web3.eth.getBalance(caller);119 const originalCallerBalance = await web3.eth.getBalance(caller);98 expect(originalCallerBalance).to.be.equal('0');99120100 const flipper = await deployFlipper(web3Http, owner);121 const flipper = await deployFlipper(web3, owner);101 await waitNewBlocks(api, 1);122 await waitNewBlocks(api, 1);102 123 103 const helpers = contractHelpers(web3Http, owner);124 const helpers = contractHelpers(web3, owner);104 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });125 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });105 await waitNewBlocks(api, 1);126 await waitNewBlocks(api, 1);106 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });127 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });107 await waitNewBlocks(api, 1);128 await waitNewBlocks(api, 1);108129109 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;130 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;110 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});131 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});111 await waitNewBlocks(api, 1);132 await waitNewBlocks(api, 1);112 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});133 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});113 await waitNewBlocks(api, 1);134 await waitNewBlocks(api, 1);114 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;135 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;115136116 await transferBalanceToEth(api, alice, flipper.options.address);137 await transferBalanceToEth(api, alice, flipper.options.address);117 await waitNewBlocks(api, 2);138 await waitNewBlocks(api, 2);118139119 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);140 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);120 expect(originalFlipperBalance).to.be.not.equal('0');141 expect(originalFlipperBalance).to.be.not.equal('0');121142122 await flipper.methods.flip().send({ from: caller });143 await flipper.methods.flip().send({ from: caller });123 await waitNewBlocks(api, 1);144 await waitNewBlocks(api, 1);124 expect(await flipper.methods.getValue().call()).to.be.true;145 expect(await flipper.methods.getValue().call()).to.be.true;125146126 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);147 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);127 });128 });148 });129149130 itWeb3('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({api, web3}) => {150 itWeb3('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({api, web3}) => {131 await usingWeb3Http(async web3Http => {151 const alice = privateKey('//Alice');132 const alice = privateKey('//Alice');133152134 const owner = await createEthAccountWithBalance(api, web3Http);153 const owner = await createEthAccountWithBalance(api, web3);135 const caller = await createEthAccountWithBalance(api, web3Http);154 const caller = await createEthAccountWithBalance(api, web3);136 const originalCallerBalance = await web3.eth.getBalance(caller);155 const originalCallerBalance = await web3.eth.getBalance(caller);137156138 const flipper = await deployFlipper(web3Http, owner);157 const flipper = await deployFlipper(web3, owner);139 await waitNewBlocks(api, 1);158 await waitNewBlocks(api, 1);140 159 141 const helpers = contractHelpers(web3Http, owner);160 const helpers = contractHelpers(web3, owner);142 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });161 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });143 await waitNewBlocks(api, 1);162 await waitNewBlocks(api, 1);144 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });163 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });145 await waitNewBlocks(api, 1);164 await waitNewBlocks(api, 1);146165147 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;166 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;148 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});167 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});149 await waitNewBlocks(api, 1);168 await waitNewBlocks(api, 1);150 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 10).send({from: owner});169 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 10).send({from: owner});151 await waitNewBlocks(api, 1);170 await waitNewBlocks(api, 1);152 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;171 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;153172154 await transferBalanceToEth(api, alice, flipper.options.address);173 await transferBalanceToEth(api, alice, flipper.options.address);155 await waitNewBlocks(api, 2);174 await waitNewBlocks(api, 2);156175157 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);176 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);158 expect(originalFlipperBalance).to.be.not.equal('0');177 expect(originalFlipperBalance).to.be.not.equal('0');159178160 await flipper.methods.flip().send({ from: caller });179 await flipper.methods.flip().send({ from: caller });161 await waitNewBlocks(api, 1);180 await waitNewBlocks(api, 1);162 expect(await flipper.methods.getValue().call()).to.be.true;181 expect(await flipper.methods.getValue().call()).to.be.true;163 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);182 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);164183165 await flipper.methods.flip().send({ from: caller });184 await flipper.methods.flip().send({ from: caller });166 await waitNewBlocks(api, 1);185 await waitNewBlocks(api, 1);167 expect(await web3.eth.getBalance(caller)).to.be.not.equals(originalCallerBalance);186 expect(await web3.eth.getBalance(caller)).to.be.not.equals(originalCallerBalance);168 });169 });187 });188189 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {190 const owner = await createEthAccountWithBalance(api, web3);191 const flipper = await deployFlipper(web3, owner);192 await waitNewBlocks(api, 1);193 const helpers = contractHelpers(web3, owner);194 await waitNewBlocks(api, 1);195 expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');196 });197198 itWeb3('If whitelist mode is off and sponsorship is on, sponsorship does not work', async ({api, web3}) => {199 const alice = privateKey('//Alice');200201 const owner = await createEthAccountWithBalance(api, web3);202 const caller = await createEthAccountWithBalance(api, web3);203204 const flipper = await deployFlipper(web3, owner);205 await waitNewBlocks(api, 1);206 207 const helpers = contractHelpers(web3, owner);208209 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;210 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});211 await waitNewBlocks(api, 1);212 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});213 await waitNewBlocks(api, 1);214 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;215216 await transferBalanceToEth(api, alice, flipper.options.address);217 await waitNewBlocks(api, 2);218219 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);220 expect(originalFlipperBalance).to.be.not.equal('0');221222 await flipper.methods.flip().send({ from: caller });223 await waitNewBlocks(api, 1);224 expect(await flipper.methods.getValue().call()).to.be.true;225226 // Balance should be taken from flipper instead of caller227 const balanceAfter = await web3.eth.getBalance(flipper.options.address);228 expect(+balanceAfter).to.be.equals(+originalFlipperBalance);229 });230170});231});171232tests/src/eth/util/contractHelpersAbi.jsondiffbeforeafterboth--- a/tests/src/eth/util/contractHelpersAbi.json
+++ b/tests/src/eth/util/contractHelpersAbi.json
@@ -3,11 +3,16 @@
"inputs": [
{
"internalType": "address",
- "name": "contract",
+ "name": "contractAddress",
"type": "address"
+ },
+ {
+ "internalType": "address",
+ "name": "user",
+ "type": "address"
}
],
- "name": "allowlistEnabled",
+ "name": "allowed",
"outputs": [
{
"internalType": "bool",
@@ -22,16 +27,11 @@
"inputs": [
{
"internalType": "address",
- "name": "target",
- "type": "address"
- },
- {
- "internalType": "address",
- "name": "caller",
+ "name": "contractAddress",
"type": "address"
}
],
- "name": "allowed",
+ "name": "allowlistEnabled",
"outputs": [
{
"internalType": "bool",
@@ -46,7 +46,7 @@
"inputs": [
{
"internalType": "address",
- "name": "target",
+ "name": "contractAddress",
"type": "address"
}
],
@@ -65,16 +65,16 @@
"inputs": [
{
"internalType": "address",
- "name": "target",
+ "name": "contractAddress",
"type": "address"
}
],
- "name": "sponsoringEnabled",
+ "name": "getSponsoringRateLimit",
"outputs": [
{
- "internalType": "bool",
+ "internalType": "uint32",
"name": "",
- "type": "bool"
+ "type": "uint32"
}
],
"stateMutability": "view",
@@ -84,39 +84,58 @@
"inputs": [
{
"internalType": "address",
- "name": "target",
+ "name": "contractAddress",
"type": "address"
},
{
+ "internalType": "uint32",
+ "name": "rateLimit",
+ "type": "uint32"
+ }
+ ],
+ "name": "setSponsoringRateLimit",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
"internalType": "address",
- "name": "user",
+ "name": "contractAddress",
"type": "address"
- },
+ }
+ ],
+ "name": "sponsoringEnabled",
+ "outputs": [
{
"internalType": "bool",
- "name": "isAllowed",
+ "name": "",
"type": "bool"
}
],
- "name": "toggleAllowed",
- "outputs": [],
- "stateMutability": "nonpayable",
+ "stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
- "name": "target",
+ "name": "contractAddress",
+ "type": "address"
+ },
+ {
+ "internalType": "address",
+ "name": "user",
"type": "address"
},
{
"internalType": "bool",
- "name": "enabled",
+ "name": "allowed",
"type": "bool"
}
],
- "name": "toggleAllowlist",
+ "name": "toggleAllowed",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
@@ -125,7 +144,7 @@
"inputs": [
{
"internalType": "address",
- "name": "target",
+ "name": "contractAddress",
"type": "address"
},
{
@@ -134,7 +153,7 @@
"type": "bool"
}
],
- "name": "toggleSponsoring",
+ "name": "toggleAllowlist",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
@@ -143,16 +162,16 @@
"inputs": [
{
"internalType": "address",
- "name": "target",
+ "name": "contractAddress",
"type": "address"
},
{
- "internalType": "uint32",
- "name": "limit",
- "type": "uint32"
+ "internalType": "bool",
+ "name": "enabled",
+ "type": "bool"
}
],
- "name": "setSponsoringRateLimit",
+ "name": "toggleSponsoring",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"