diff --git a/test/BreakInvariantBounty.test.js b/test/BreakInvariantBounty.test.js index 4c1f8b06c4e..ff8e0f7bd03 100644 --- a/test/BreakInvariantBounty.test.js +++ b/test/BreakInvariantBounty.test.js @@ -1,5 +1,6 @@ const { ethGetBalance, ethSendTransaction } = require('./helpers/web3'); const { sendEther } = require('./helpers/sendTransaction'); +const { balanceDifference } = require('./helpers/balanceDiff'); const expectEvent = require('./helpers/expectEvent'); const { assertRevert } = require('./helpers/assertRevert'); @@ -72,12 +73,8 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar it('sends the reward to the researcher', async function () { await this.bounty.claim(this.target.address, { from: anyone }); - - const researcherPreBalance = await ethGetBalance(researcher); - await this.bounty.withdrawPayments(researcher); - const researcherPostBalance = await ethGetBalance(researcher); - - researcherPostBalance.sub(researcherPreBalance).should.be.bignumber.equal(reward); + (await balanceDifference(researcher, () => this.bounty.withdrawPayments(researcher))) + .should.be.bignumber.equal(reward); (await ethGetBalance(this.bounty.address)).should.be.bignumber.equal(0); }); diff --git a/test/helpers/balanceDiff.js b/test/helpers/balanceDiff.js new file mode 100644 index 00000000000..8f88ba40045 --- /dev/null +++ b/test/helpers/balanceDiff.js @@ -0,0 +1,10 @@ +async function balanceDifference (account, promise) { + const balanceBefore = web3.eth.getBalance(account); + await promise(); + const balanceAfter = web3.eth.getBalance(account); + return balanceAfter.minus(balanceBefore); +} + +module.exports = { + balanceDifference, +};