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

difftreelog

Merge pull request #292 from UniqueNetwork/test/fix-sponsoring-tests

kozyrevdev2022-02-18parents: #f663e99 #1703581.patch.diff
in: master
Fix sponsoring tests

2 files changed

modifiedtests/src/eth/allowlist.test.tsdiffbeforeafterboth
before · tests/src/eth/allowlist.test.ts
1import {expect} from 'chai';2import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3} from './util/helpers';34describe('EVM allowlist', () => {5  itWeb3('Contract allowlist can be toggled', async ({api, web3}) => {6    const owner = await createEthAccountWithBalance(api, web3);7    const flipper = await deployFlipper(web3, owner);8    const randomUser = createEthAccount(web3);910    const helpers = contractHelpers(web3, owner);1112    // Any user is allowed by default13    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;14    expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;1516    // Enable17    await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});18    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;19    expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.false;2021    // Disable22    await helpers.methods.toggleAllowlist(flipper.options.address, false).send({from: owner});23    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;24    expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;25  });2627  itWeb3('Non-allowlisted user can\'t call contract with allowlist enabled', async ({api, web3}) => {28    const owner = await createEthAccountWithBalance(api, web3);29    const flipper = await deployFlipper(web3, owner);30    const caller = await createEthAccountWithBalance(api, web3);3132    const helpers = contractHelpers(web3, owner);3334    // User can flip with allowlist disabled35    await flipper.methods.flip().send({from: caller});36    expect(await flipper.methods.getValue().call()).to.be.true;3738    // Tx will be reverted if user is not in allowlist39    await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});40    await expect(flipper.methods.flip().send({from: caller})).to.rejected;41    expect(await flipper.methods.getValue().call()).to.be.true;4243    // Adding caller to allowlist will make contract callable again44    await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});45    await flipper.methods.flip().send({from: caller});46    expect(await flipper.methods.getValue().call()).to.be.false;47  });48});
after · tests/src/eth/allowlist.test.ts
1import {expect} from 'chai';2import {contractHelpers, createEthAccountWithBalance, deployFlipper, itWeb3} from './util/helpers';34describe('EVM allowlist', () => {5  itWeb3('Contract allowlist can be toggled', async ({api, web3}) => {6    const owner = await createEthAccountWithBalance(api, web3);7    const flipper = await deployFlipper(web3, owner);89    const helpers = contractHelpers(web3, owner);1011    // Any user is allowed by default12    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;1314    // Enable15    await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});16    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;1718    // Disable19    await helpers.methods.toggleAllowlist(flipper.options.address, false).send({from: owner});20    expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;21  });2223  itWeb3('Non-allowlisted user can\'t call contract with allowlist enabled', async ({api, web3}) => {24    const owner = await createEthAccountWithBalance(api, web3);25    const flipper = await deployFlipper(web3, owner);26    const caller = await createEthAccountWithBalance(api, web3);2728    const helpers = contractHelpers(web3, owner);2930    // User can flip with allowlist disabled31    await flipper.methods.flip().send({from: caller});32    expect(await flipper.methods.getValue().call()).to.be.true;3334    // Tx will be reverted if user is not in allowlist35    await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});36    await expect(flipper.methods.flip().send({from: caller})).to.rejected;37    expect(await flipper.methods.getValue().call()).to.be.true;3839    // Adding caller to allowlist will make contract callable again40    await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});41    await flipper.methods.flip().send({from: caller});42    expect(await flipper.methods.getValue().call()).to.be.false;43  });44});
modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -113,8 +113,8 @@
     const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
     expect(originalFlipperBalance).to.be.not.equal('0');
 
-    await flipper.methods.flip().send({from: caller});
-    expect(await flipper.methods.getValue().call()).to.be.true;
+    await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/InvalidTransaction::Payment/);
+    expect(await flipper.methods.getValue().call()).to.be.false;
 
     // Balance should be taken from flipper instead of caller
     const balanceAfter = await web3.eth.getBalance(flipper.options.address);