diff --git a/package-lock.json b/package-lock.json index a28d3f836..2d457d11e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5796,9 +5796,9 @@ } }, "openzeppelin-test-helpers": { - "version": "0.1.0-beta.2", - "resolved": "https://registry.npmjs.org/openzeppelin-test-helpers/-/openzeppelin-test-helpers-0.1.0-beta.2.tgz", - "integrity": "sha512-xX1s8GZvQvC5QyuG8C0UpWBY4nLdIE5lg348wFCV8d4p/dUO9dGhB8RS+rxyjJ7jHDMzpRLKgCmVuQgetQhYWw==", + "version": "0.1.0-beta.3", + "resolved": "https://registry.npmjs.org/openzeppelin-test-helpers/-/openzeppelin-test-helpers-0.1.0-beta.3.tgz", + "integrity": "sha512-vAt9BQTA7qmShhQ5k5u6OovSqlAbRnSQL6liHpqVUheOIVItoI9n5J2+O6e4OHPsR3L+vmbTMJELhoFepVt2Fg==", "dev": true, "requires": { "chai": "^4.2.0", diff --git a/package.json b/package.json index d2c2d5aec..9c4255371 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "ethereumjs-util": "^6.0.0", "ethjs-abi": "^0.2.1", "ganache-cli": "6.1.8", - "openzeppelin-test-helpers": "0.1.0-beta.2", + "openzeppelin-test-helpers": "0.1.0-beta.3", "pify": "^4.0.1", "solhint": "^1.5.0", "solidity-coverage": "^0.5.4", diff --git a/test/crowdsale/AllowanceCrowdsale.test.js b/test/crowdsale/AllowanceCrowdsale.test.js index 887a4c69a..9a1e9b0e1 100644 --- a/test/crowdsale/AllowanceCrowdsale.test.js +++ b/test/crowdsale/AllowanceCrowdsale.test.js @@ -7,7 +7,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW const rate = new BN('1'); const value = ether('0.42'); const expectedTokenAmount = rate.mul(value); - const tokenAllowance = new BN('1e22'); + const tokenAllowance = new BN('10').pow(new BN('22')); beforeEach(async function () { this.token = await SimpleToken.new({ from: tokenWallet }); @@ -54,7 +54,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW describe('check remaining allowance', function () { it('should report correct allowace left', async function () { - const remainingAllowance = tokenAllowance - expectedTokenAmount; + const remainingAllowance = tokenAllowance.sub(expectedTokenAmount); await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }); (await this.crowdsale.remainingTokens()).should.be.bignumber.equal(remainingAllowance); }); @@ -62,7 +62,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW context('when the allowance is larger than the token amount', function () { beforeEach(async function () { const amount = await this.token.balanceOf(tokenWallet); - await this.token.approve(this.crowdsale.address, amount.add(new BN(1)), { from: tokenWallet }); + await this.token.approve(this.crowdsale.address, amount.addn(1), { from: tokenWallet }); }); it('should report the amount instead of the allowance', async function () { diff --git a/test/crowdsale/CappedCrowdsale.test.js b/test/crowdsale/CappedCrowdsale.test.js index f829f3033..eb3a24457 100644 --- a/test/crowdsale/CappedCrowdsale.test.js +++ b/test/crowdsale/CappedCrowdsale.test.js @@ -7,7 +7,7 @@ contract('CappedCrowdsale', function ([_, wallet]) { const rate = new BN('1'); const cap = ether('100'); const lessThanCap = ether('60'); - const tokenSupply = new BN('1e22'); + const tokenSupply = new BN('10').pow(new BN('22')); beforeEach(async function () { this.token = await SimpleToken.new(); @@ -35,7 +35,7 @@ contract('CappedCrowdsale', function ([_, wallet]) { }); it('should reject payments that exceed cap', async function () { - await shouldFail.reverting(this.crowdsale.send(cap.add(new BN(1)))); + await shouldFail.reverting(this.crowdsale.send(cap.addn(1))); }); }); diff --git a/test/crowdsale/Crowdsale.test.js b/test/crowdsale/Crowdsale.test.js index dbd33f1aa..dfcff4a96 100644 --- a/test/crowdsale/Crowdsale.test.js +++ b/test/crowdsale/Crowdsale.test.js @@ -1,18 +1,12 @@ -const expectEvent = require('../helpers/expectEvent'); -const shouldFail = require('../helpers/shouldFail'); -const { balanceDifference } = require('../helpers/balanceDifference'); -const { ether } = require('../helpers/ether'); -const { ZERO_ADDRESS } = require('../helpers/constants'); - -const { BigNumber } = require('../helpers/setup'); +const { balance, BN, constants, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers'); const Crowdsale = artifacts.require('CrowdsaleMock'); const SimpleToken = artifacts.require('SimpleToken'); contract('Crowdsale', function ([_, investor, wallet, purchaser]) { - const rate = new BigNumber(1); - const value = ether(42); - const tokenSupply = new BigNumber('1e22'); + const rate = new BN(1); + const value = ether('42'); + const tokenSupply = new BN('10').pow(new BN('22')); const expectedTokenAmount = rate.mul(value); it('requires a non-null token', async function () { @@ -93,7 +87,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { }); it('should forward funds to wallet', async function () { - (await balanceDifference(wallet, () => + (await balance.difference(wallet, () => this.crowdsale.sendTransaction({ value, from: investor })) ).should.be.bignumber.equal(value); }); @@ -116,7 +110,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { }); it('should forward funds to wallet', async function () { - (await balanceDifference(wallet, () => + (await balance.difference(wallet, () => this.crowdsale.buyTokens(investor, { value, from: purchaser })) ).should.be.bignumber.equal(value); }); diff --git a/test/crowdsale/FinalizableCrowdsale.test.js b/test/crowdsale/FinalizableCrowdsale.test.js index 778dbcb98..8a0786bc4 100644 --- a/test/crowdsale/FinalizableCrowdsale.test.js +++ b/test/crowdsale/FinalizableCrowdsale.test.js @@ -1,14 +1,10 @@ -const expectEvent = require('../helpers/expectEvent'); -const time = require('../helpers/time'); -const shouldFail = require('../helpers/shouldFail'); - -const { BigNumber } = require('../helpers/setup'); +const { BN, expectEvent, shouldFail, time } = require('openzeppelin-test-helpers'); const FinalizableCrowdsaleImpl = artifacts.require('FinalizableCrowdsaleImpl'); const ERC20 = artifacts.require('ERC20'); contract('FinalizableCrowdsale', function ([_, wallet, anyone]) { - const rate = new BigNumber(1000); + const rate = new BN('1000'); before(async function () { // Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache @@ -16,9 +12,9 @@ contract('FinalizableCrowdsale', function ([_, wallet, anyone]) { }); beforeEach(async function () { - this.openingTime = (await time.latest()) + time.duration.weeks(1); - this.closingTime = this.openingTime + time.duration.weeks(1); - this.afterClosingTime = this.closingTime + time.duration.seconds(1); + this.openingTime = (await time.latest()).add(time.duration.weeks(1)); + this.closingTime = this.openingTime.add(time.duration.weeks(1)); + this.afterClosingTime = this.closingTime.add(time.duration.seconds(1)); this.token = await ERC20.new(); this.crowdsale = await FinalizableCrowdsaleImpl.new( diff --git a/test/crowdsale/IncreasingPriceCrowdsale.test.js b/test/crowdsale/IncreasingPriceCrowdsale.test.js index c9ba167ea..d28a9534b 100644 --- a/test/crowdsale/IncreasingPriceCrowdsale.test.js +++ b/test/crowdsale/IncreasingPriceCrowdsale.test.js @@ -1,37 +1,33 @@ -const { ether } = require('../helpers/ether'); -const time = require('../helpers/time'); -const shouldFail = require('../helpers/shouldFail'); - -const { BigNumber } = require('../helpers/setup'); +const { BN, ether, shouldFail, time } = require('openzeppelin-test-helpers'); const IncreasingPriceCrowdsaleImpl = artifacts.require('IncreasingPriceCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser]) { - const value = ether(1); - const tokenSupply = new BigNumber('1e22'); + const value = ether('1'); + const tokenSupply = new BN('10').pow(new BN('22')); describe('rate during crowdsale should change at a fixed step every block', async function () { - const initialRate = new BigNumber(9166); - const finalRate = new BigNumber(5500); - const rateAtTime150 = new BigNumber(9166); - const rateAtTime300 = new BigNumber(9165); - const rateAtTime1500 = new BigNumber(9157); - const rateAtTime30 = new BigNumber(9166); - const rateAtTime150000 = new BigNumber(8257); - const rateAtTime450000 = new BigNumber(6439); + const initialRate = new BN('9166'); + const finalRate = new BN('5500'); + const rateAtTime150 = new BN('9166'); + const rateAtTime300 = new BN('9165'); + const rateAtTime1500 = new BN('9157'); + const rateAtTime30 = new BN('9166'); + const rateAtTime150000 = new BN('8257'); + const rateAtTime450000 = new BN('6439'); beforeEach(async function () { await time.advanceBlock(); - this.startTime = (await time.latest()) + time.duration.weeks(1); - this.closingTime = this.startTime + time.duration.weeks(1); - this.afterClosingTime = this.closingTime + time.duration.seconds(1); + this.startTime = (await time.latest()).add(time).duration.weeks(1); + this.closingTime = this.startTime.add(time).duration.weeks(1); + this.afterClosingTime = this.closingTime.add(time).duration.seconds(1); this.token = await SimpleToken.new(); }); it('reverts with a final rate larger than the initial rate', async function () { await shouldFail.reverting(IncreasingPriceCrowdsaleImpl.new( - this.startTime, this.closingTime, wallet, this.token.address, initialRate, initialRate.plus(1) + this.startTime, this.closingTime, wallet, this.token.address, initialRate, initialRate.addn(1) )); }); @@ -65,7 +61,7 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser]) }); it('returns a rate of 0 before the crowdsale starts', async function () { - (await this.crowdsale.getCurrentRate()).should.be.bignumber.equal(0); + (await this.crowdsale.getCurrentRate()).should.be.bignumber.equal('0'); }); it('returns a rate of 0 after the crowdsale ends', async function () { @@ -80,37 +76,37 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser]) }); it('at time 150', async function () { - await time.increaseTo(this.startTime + 150); + await time.increaseTo(this.startTime.addn(150)); await this.crowdsale.buyTokens(investor, { value, from: purchaser }); (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150)); }); it('at time 300', async function () { - await time.increaseTo(this.startTime + 300); + await time.increaseTo(this.startTime.add(300)); await this.crowdsale.buyTokens(investor, { value, from: purchaser }); (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime300)); }); it('at time 1500', async function () { - await time.increaseTo(this.startTime + 1500); + await time.increaseTo(this.startTime.addn(1500)); await this.crowdsale.buyTokens(investor, { value, from: purchaser }); (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime1500)); }); it('at time 30', async function () { - await time.increaseTo(this.startTime + 30); + await time.increaseTo(this.startTime.addn(30)); await this.crowdsale.buyTokens(investor, { value, from: purchaser }); (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime30)); }); it('at time 150000', async function () { - await time.increaseTo(this.startTime + 150000); + await time.increaseTo(this.startTime.addn(150000)); await this.crowdsale.buyTokens(investor, { value, from: purchaser }); (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150000)); }); it('at time 450000', async function () { - await time.increaseTo(this.startTime + 450000); + await time.increaseTo(this.startTime.addn(450000)); await this.crowdsale.buyTokens(investor, { value, from: purchaser }); (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime450000)); }); diff --git a/test/crowdsale/IndividuallyCappedCrowdsale.test.js b/test/crowdsale/IndividuallyCappedCrowdsale.test.js index 36de85f04..6bdf09de6 100644 --- a/test/crowdsale/IndividuallyCappedCrowdsale.test.js +++ b/test/crowdsale/IndividuallyCappedCrowdsale.test.js @@ -1,7 +1,4 @@ -const { ether } = require('../helpers/ether'); -const shouldFail = require('../helpers/shouldFail'); - -const { BigNumber } = require('../helpers/setup'); +const { BN, ether, shouldFail } = require('openzeppelin-test-helpers'); const IndividuallyCappedCrowdsaleImpl = artifacts.require('IndividuallyCappedCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); @@ -9,12 +6,12 @@ const { shouldBehaveLikePublicRole } = require('../access/roles/PublicRole.behav contract('IndividuallyCappedCrowdsale', function ( [_, capper, otherCapper, wallet, alice, bob, charlie, anyone, ...otherAccounts]) { - const rate = new BigNumber(1); - const capAlice = ether(10); - const capBob = ether(2); - const lessThanCapAlice = ether(6); - const lessThanCapBoth = ether(1); - const tokenSupply = new BigNumber('1e22'); + const rate = new BN(1); + const capAlice = ether('10'); + const capBob = ether('2'); + const lessThanCapAlice = ether('6'); + const lessThanCapBoth = ether('1'); + const tokenSupply = new BN('10').pow(new BN('22')); beforeEach(async function () { this.token = await SimpleToken.new(); @@ -59,8 +56,8 @@ contract('IndividuallyCappedCrowdsale', function ( }); it('should reject payments that exceed cap', async function () { - await shouldFail.reverting(this.crowdsale.buyTokens(alice, { value: capAlice.plus(1) })); - await shouldFail.reverting(this.crowdsale.buyTokens(bob, { value: capBob.plus(1) })); + await shouldFail.reverting(this.crowdsale.buyTokens(alice, { value: capAlice.add(1) })); + await shouldFail.reverting(this.crowdsale.buyTokens(bob, { value: capBob.add(1) })); }); it('should manage independent caps', async function () { diff --git a/test/crowdsale/MintedCrowdsale.behavior.js b/test/crowdsale/MintedCrowdsale.behavior.js index ec41e4948..75bceb3f5 100644 --- a/test/crowdsale/MintedCrowdsale.behavior.js +++ b/test/crowdsale/MintedCrowdsale.behavior.js @@ -1,7 +1,4 @@ -const expectEvent = require('../helpers/expectEvent'); -const { balanceDifference } = require('../helpers/balanceDifference'); - -require('../helpers/setup'); +const { balance, expectEvent } = require('openzeppelin-test-helpers'); function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate, value) { const expectedTokenAmount = rate.mul(value); @@ -31,7 +28,7 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate }); it('should forward funds to wallet', async function () { - (await balanceDifference(wallet, () => + (await balance.difference(wallet, () => this.crowdsale.sendTransaction({ value, from: investor })) ).should.be.bignumber.equal(value); }); diff --git a/test/crowdsale/MintedCrowdsale.test.js b/test/crowdsale/MintedCrowdsale.test.js index 98e54646d..2928f0142 100644 --- a/test/crowdsale/MintedCrowdsale.test.js +++ b/test/crowdsale/MintedCrowdsale.test.js @@ -1,16 +1,13 @@ +const { BN, ether, shouldFail } = require('openzeppelin-test-helpers'); const { shouldBehaveLikeMintedCrowdsale } = require('./MintedCrowdsale.behavior'); -const { ether } = require('../helpers/ether'); -const shouldFail = require('../helpers/shouldFail'); - -const { BigNumber } = require('../helpers/setup'); const MintedCrowdsaleImpl = artifacts.require('MintedCrowdsaleImpl'); const ERC20Mintable = artifacts.require('ERC20Mintable'); const ERC20 = artifacts.require('ERC20'); contract('MintedCrowdsale', function ([_, deployer, investor, wallet, purchaser]) { - const rate = new BigNumber(1000); - const value = ether(5); + const rate = new BN('1000'); + const value = ether('5'); describe('using ERC20Mintable', function () { beforeEach(async function () { diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index 2d0d0513d..d1e797e1e 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -1,20 +1,18 @@ -const shouldFail = require('../helpers/shouldFail'); +const { BN, shouldFail } = require('openzeppelin-test-helpers'); const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); -require('../helpers/setup'); - contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { - const rate = 1; - const value = 1; + const rate = new BN(1); + const value = new BN(1); beforeEach(async function () { const from = pauser; this.token = await SimpleToken.new({ from }); this.crowdsale = await PausableCrowdsale.new(rate, wallet, this.token.address, { from }); - await this.token.transfer(this.crowdsale.address, 2 * value, { from }); + await this.token.transfer(this.crowdsale.address, value.muln(2), { from }); }); it('purchases work', async function () { diff --git a/test/crowdsale/PostDeliveryCrowdsale.test.js b/test/crowdsale/PostDeliveryCrowdsale.test.js index e1e3b40a5..1417a1c76 100644 --- a/test/crowdsale/PostDeliveryCrowdsale.test.js +++ b/test/crowdsale/PostDeliveryCrowdsale.test.js @@ -1,15 +1,11 @@ -const time = require('../helpers/time'); -const shouldFail = require('../helpers/shouldFail'); -const { ether } = require('../helpers/ether'); - -const { BigNumber } = require('../helpers/setup'); +const { BN, ether, shouldFail, time } = require('openzeppelin-test-helpers'); const PostDeliveryCrowdsaleImpl = artifacts.require('PostDeliveryCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) { - const rate = new BigNumber(1); - const tokenSupply = new BigNumber('1e22'); + const rate = new BN(1); + const tokenSupply = new BN('10').pow(new BN('22')); before(async function () { // Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache @@ -17,9 +13,9 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) { }); beforeEach(async function () { - this.openingTime = (await time.latest()) + time.duration.weeks(1); - this.closingTime = this.openingTime + time.duration.weeks(1); - this.afterClosingTime = this.closingTime + time.duration.seconds(1); + this.openingTime = (await time.latest()).add(time.duration.weeks(1)); + this.closingTime = this.openingTime.add(time.duration.weeks(1)); + this.afterClosingTime = this.closingTime.add(time.duration.seconds(1)); this.token = await SimpleToken.new(); this.crowdsale = await PostDeliveryCrowdsaleImpl.new( this.openingTime, this.closingTime, rate, wallet, this.token.address @@ -33,7 +29,7 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) { }); context('with bought tokens', function () { - const value = ether(42); + const value = ether('42'); beforeEach(async function () { await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }); @@ -41,7 +37,7 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) { it('does not immediately assign tokens to beneficiaries', async function () { (await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal(value); - (await this.token.balanceOf(investor)).should.be.bignumber.equal(0); + (await this.token.balanceOf(investor)).should.be.bignumber.equal('0'); }); it('does not allow beneficiaries to withdraw tokens before crowdsale ends', async function () { @@ -55,7 +51,7 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) { it('allows beneficiaries to withdraw tokens', async function () { await this.crowdsale.withdrawTokens(investor); - (await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal(0); + (await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal('0'); (await this.token.balanceOf(investor)).should.be.bignumber.equal(value); }); diff --git a/test/crowdsale/RefundableCrowdsale.test.js b/test/crowdsale/RefundableCrowdsale.test.js index 9c8d01c72..be2acf38f 100644 --- a/test/crowdsale/RefundableCrowdsale.test.js +++ b/test/crowdsale/RefundableCrowdsale.test.js @@ -1,19 +1,13 @@ -const { ether } = require('../helpers/ether'); -const { balanceDifference } = require('../helpers/balanceDifference'); -const shouldFail = require('../helpers/shouldFail'); -const time = require('../helpers/time'); -const { ethGetBalance } = require('../helpers/web3'); - -const { BigNumber } = require('../helpers/setup'); +const { balance, BN, ether, shouldFail, time } = require('openzeppelin-test-helpers'); const RefundableCrowdsaleImpl = artifacts.require('RefundableCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyone]) { - const rate = new BigNumber(1); - const goal = ether(50); - const lessThanGoal = ether(45); - const tokenSupply = new BigNumber('1e22'); + const rate = new BN(1); + const goal = ether('50'); + const lessThanGoal = ether('45'); + const tokenSupply = new BN('10').pow(new BN('22')); before(async function () { // Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache @@ -21,10 +15,10 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon }); beforeEach(async function () { - this.openingTime = (await time.latest()) + time.duration.weeks(1); - this.closingTime = this.openingTime + time.duration.weeks(1); - this.afterClosingTime = this.closingTime + time.duration.seconds(1); - this.preWalletBalance = await ethGetBalance(wallet); + this.openingTime = (await time.latest()).add(time.duration.weeks(1)); + this.closingTime = this.openingTime.add(time.duration.weeks(1)); + this.afterClosingTime = this.closingTime.add(time.duration.seconds(1)); + this.preWalletBalance = await balance.current(wallet); this.token = await SimpleToken.new(); }); @@ -71,7 +65,7 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon }); it('refunds', async function () { - (await balanceDifference(investor, () => + (await balance.difference(investor, () => this.crowdsale.claimRefund(investor, { gasPrice: 0 })) ).should.be.bignumber.equal(lessThanGoal); }); @@ -94,7 +88,7 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon }); it('forwards funds to wallet', async function () { - const postWalletBalance = await ethGetBalance(wallet); + const postWalletBalance = await balance.current(wallet); postWalletBalance.minus(this.preWalletBalance).should.be.bignumber.equal(goal); }); }); diff --git a/test/crowdsale/RefundablePostDeliveryCrowdsale.test.js b/test/crowdsale/RefundablePostDeliveryCrowdsale.test.js index 088c73161..775bcc0a8 100644 --- a/test/crowdsale/RefundablePostDeliveryCrowdsale.test.js +++ b/test/crowdsale/RefundablePostDeliveryCrowdsale.test.js @@ -1,20 +1,12 @@ -const time = require('../helpers/time'); -const shouldFail = require('../helpers/shouldFail'); -const { ether } = require('../helpers/ether'); - -const BigNumber = web3.BigNumber; - -require('chai') - .use(require('chai-bignumber')(BigNumber)) - .should(); +const { BN, ether, shouldFail, time } = require('openzeppelin-test-helpers'); const RefundablePostDeliveryCrowdsaleImpl = artifacts.require('RefundablePostDeliveryCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) { - const rate = new BigNumber(1); - const tokenSupply = new BigNumber('1e22'); - const goal = ether(100); + const rate = new BN(1); + const tokenSupply = new BN('10').pow(new BN('22')); + const goal = ether('100'); before(async function () { // Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache @@ -22,9 +14,9 @@ contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purc }); beforeEach(async function () { - this.openingTime = (await time.latest()) + time.duration.weeks(1); - this.closingTime = this.openingTime + time.duration.weeks(1); - this.afterClosingTime = this.closingTime + time.duration.seconds(1); + this.openingTime = (await time.latest()).add(time.duration.weeks(1)); + this.closingTime = this.openingTime.add(time.duration.weeks(1)); + this.afterClosingTime = this.closingTime.add(time.duration.seconds(1)); this.token = await SimpleToken.new(); this.crowdsale = await RefundablePostDeliveryCrowdsaleImpl.new( this.openingTime, this.closingTime, rate, wallet, this.token.address, goal @@ -38,7 +30,7 @@ contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purc }); context('with bought tokens below the goal', function () { - const value = goal.sub(1); + const value = goal.subn(1); beforeEach(async function () { await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }); @@ -46,7 +38,7 @@ contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purc it('does not immediately deliver tokens to beneficiaries', async function () { (await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal(value); - (await this.token.balanceOf(investor)).should.be.bignumber.equal(0); + (await this.token.balanceOf(investor)).should.be.bignumber.equal('0'); }); it('does not allow beneficiaries to withdraw tokens before crowdsale ends', async function () { @@ -74,7 +66,7 @@ contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purc it('does not immediately deliver tokens to beneficiaries', async function () { (await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal(value); - (await this.token.balanceOf(investor)).should.be.bignumber.equal(0); + (await this.token.balanceOf(investor)).should.be.bignumber.equal('0'); }); it('does not allow beneficiaries to withdraw tokens before crowdsale ends', async function () { @@ -89,7 +81,7 @@ contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purc it('allows beneficiaries to withdraw tokens', async function () { await this.crowdsale.withdrawTokens(investor); - (await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal(0); + (await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal('0'); (await this.token.balanceOf(investor)).should.be.bignumber.equal(value); }); diff --git a/test/crowdsale/TimedCrowdsale.test.js b/test/crowdsale/TimedCrowdsale.test.js index 2f6e3e15c..b68ea3e8b 100644 --- a/test/crowdsale/TimedCrowdsale.test.js +++ b/test/crowdsale/TimedCrowdsale.test.js @@ -1,16 +1,12 @@ -const { ether } = require('../helpers/ether'); -const shouldFail = require('../helpers/shouldFail'); -const time = require('../helpers/time'); - -const { BigNumber } = require('../helpers/setup'); +const { BN, ether, shouldFail, time } = require('openzeppelin-test-helpers'); const TimedCrowdsaleImpl = artifacts.require('TimedCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) { - const rate = new BigNumber(1); - const value = ether(42); - const tokenSupply = new BigNumber('1e22'); + const rate = new BN(1); + const value = ether('42'); + const tokenSupply = new BN('10').pow(new BN('22')); before(async function () { // Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache @@ -18,21 +14,21 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) { }); beforeEach(async function () { - this.openingTime = (await time.latest()) + time.duration.weeks(1); - this.closingTime = this.openingTime + time.duration.weeks(1); - this.afterClosingTime = this.closingTime + time.duration.seconds(1); + this.openingTime = (await time.latest()).add(time.duration.weeks(1)); + this.closingTime = this.openingTime.add(time.duration.weeks(1)); + this.afterClosingTime = this.closingTime.add(time.duration.seconds(1)); this.token = await SimpleToken.new(); }); it('reverts if the opening time is in the past', async function () { await shouldFail.reverting(TimedCrowdsaleImpl.new( - (await time.latest()) - time.duration.days(1), this.closingTime, rate, wallet, this.token.address + (await time.latest()).sub(time.duration.days(1)), this.closingTime, rate, wallet, this.token.address )); }); it('reverts if the closing time is before the opening time', async function () { await shouldFail.reverting(TimedCrowdsaleImpl.new( - this.openingTime, this.openingTime - time.duration.seconds(1), rate, wallet, this.token.address + this.openingTime, this.openingTime.sub(time.duration.seconds(1)), rate, wallet, this.token.address )); }); diff --git a/test/crowdsale/WhitelistCrowdsale.test.js b/test/crowdsale/WhitelistCrowdsale.test.js index 713de675e..ffd79ea2b 100644 --- a/test/crowdsale/WhitelistCrowdsale.test.js +++ b/test/crowdsale/WhitelistCrowdsale.test.js @@ -1,16 +1,12 @@ -require('../helpers/setup'); -const { ether } = require('../helpers/ether'); -const shouldFail = require('../helpers/shouldFail'); - -const BigNumber = web3.BigNumber; +const { BN, ether, shouldFail } = require('openzeppelin-test-helpers'); const WhitelistCrowdsale = artifacts.require('WhitelistCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); contract('WhitelistCrowdsale', function ([_, wallet, whitelister, whitelisted, otherWhitelisted, anyone]) { - const rate = 1; - const value = ether(42); - const tokenSupply = new BigNumber('1e22'); + const rate = new BN(1); + const value = ether('42'); + const tokenSupply = new BN('10').pow(new BN('22')); beforeEach(async function () { this.token = await SimpleToken.new({ from: whitelister }); diff --git a/test/drafts/SignedSafeMath.test.js b/test/drafts/SignedSafeMath.test.js index e144d39f6..aca3155ce 100644 --- a/test/drafts/SignedSafeMath.test.js +++ b/test/drafts/SignedSafeMath.test.js @@ -1,10 +1,7 @@ -const shouldFail = require('../helpers/shouldFail'); -const { MIN_INT256, MAX_INT256 } = require('../helpers/constants'); +const { BN, constants, shouldFail } = require('openzeppelin-test-helpers'); const SignedSafeMathMock = artifacts.require('SignedSafeMathMock'); -const { BigNumber } = require('../helpers/setup'); - contract('SignedSafeMath', function () { beforeEach(async function () { this.safeMath = await SignedSafeMathMock.new(); @@ -12,127 +9,127 @@ contract('SignedSafeMath', function () { describe('add', function () { it('adds correctly if it does not overflow and the result is positve', async function () { - const a = new BigNumber(1234); - const b = new BigNumber(5678); + const a = new BN('1234'); + const b = new BN('5678'); - (await this.safeMath.add(a, b)).should.be.bignumber.equal(a.plus(b)); + (await this.safeMath.addUints(a, b)).should.be.bignumber.equal(a.add(b)); }); it('adds correctly if it does not overflow and the result is negative', async function () { - const a = MAX_INT256; - const b = MIN_INT256; + const a = constants.MAX_INT256; + const b = constants.MIN_INT256; - const result = await this.safeMath.add(a, b); - result.should.be.bignumber.equal(a.plus(b)); + const result = await this.safeMath.addInts(a, b); + result.should.be.bignumber.equal(a.add(b)); }); it('reverts on positive addition overflow', async function () { - const a = MAX_INT256; - const b = new BigNumber(1); + const a = constants.MAX_INT256; + const b = new BN('1'); - await shouldFail.reverting(this.safeMath.add(a, b)); + await shouldFail.reverting(this.safeMath.addInts(a, b)); }); it('reverts on negative addition overflow', async function () { - const a = MIN_INT256; - const b = new BigNumber(-1); + const a = constants.MIN_INT256; + const b = new BN('-1'); - await shouldFail.reverting(this.safeMath.add(a, b)); + await shouldFail.reverting(this.safeMath.addInts(a, b)); }); }); describe('sub', function () { it('subtracts correctly if it does not overflow and the result is positive', async function () { - const a = new BigNumber(5678); - const b = new BigNumber(1234); + const a = new BN('5678'); + const b = new BN('1234'); - const result = await this.safeMath.sub(a, b); - result.should.be.bignumber.equal(a.minus(b)); + const result = await this.safeMath.subInts(a, b); + result.should.be.bignumber.equal(a.sub(b)); }); it('subtracts correctly if it does not overflow and the result is negative', async function () { - const a = new BigNumber(1234); - const b = new BigNumber(5678); + const a = new BN('1234'); + const b = new BN('5678'); - const result = await this.safeMath.sub(a, b); - result.should.be.bignumber.equal(a.minus(b)); + const result = await this.safeMath.subInts(a, b); + result.should.be.bignumber.equal(a.sub(b)); }); it('reverts on positive subtraction overflow', async function () { - const a = MAX_INT256; - const b = new BigNumber(-1); + const a = constants.MAX_INT256; + const b = new BN('-1'); - await shouldFail.reverting(this.safeMath.sub(a, b)); + await shouldFail.reverting(this.safeMath.subInts(a, b)); }); it('reverts on negative subtraction overflow', async function () { - const a = MIN_INT256; - const b = new BigNumber(1); + const a = constants.MIN_INT256; + const b = new BN('1'); - await shouldFail.reverting(this.safeMath.sub(a, b)); + await shouldFail.reverting(this.safeMath.subInts(a, b)); }); }); describe('mul', function () { it('multiplies correctly', async function () { - const a = new BigNumber(5678); - const b = new BigNumber(-1234); + const a = new BN('5678'); + const b = new BN('-1234'); - const result = await this.safeMath.mul(a, b); - result.should.be.bignumber.equal(a.times(b)); + const result = await this.safeMath.mulInts(a, b); + result.should.be.bignumber.equal(a.mul(b)); }); it('handles a zero product correctly', async function () { - const a = new BigNumber(0); - const b = new BigNumber(5678); + const a = new BN('0'); + const b = new BN('5678'); - const result = await this.safeMath.mul(a, b); - result.should.be.bignumber.equal(a.times(b)); + const result = await this.safeMath.mulInts(a, b); + result.should.be.bignumber.equal(a.mul(b)); }); it('reverts on multiplication overflow, positive operands', async function () { - const a = MAX_INT256; - const b = new BigNumber(2); + const a = constants.MAX_INT256; + const b = new BN('2'); - await shouldFail.reverting(this.safeMath.mul(a, b)); + await shouldFail.reverting(this.safeMath.mulInts(a, b)); }); it('reverts when minimum integer is multiplied by -1', async function () { - const a = MIN_INT256; - const b = new BigNumber(-1); + const a = constants.MIN_INT256; + const b = new BN('-1'); - await shouldFail.reverting(this.safeMath.mul(a, b)); + await shouldFail.reverting(this.safeMath.mulInts(a, b)); }); it('reverts when -1 is multiplied by minimum integer', async function () { - const a = new BigNumber(-1); - const b = MIN_INT256; + const a = new BN('-1'); + const b = constants.MIN_INT256; - await shouldFail.reverting(this.safeMath.mul(a, b)); + await shouldFail.reverting(this.safeMath.mulInts(a, b)); }); }); describe('div', function () { it('divides correctly', async function () { - const a = new BigNumber(-5678); - const b = new BigNumber(5678); + const a = new BN('-5678'); + const b = new BN('5678'); - const result = await this.safeMath.div(a, b); + const result = await this.safeMath.divInts(a, b); result.should.be.bignumber.equal(a.div(b)); }); it('reverts on zero division', async function () { - const a = new BigNumber(-5678); - const b = new BigNumber(0); + const a = new BN('-5678'); + const b = new BN('0'); - await shouldFail.reverting(this.safeMath.div(a, b)); + await shouldFail.reverting(this.safeMath.divInts(a, b)); }); it('reverts on overflow, negative second', async function () { - const a = new BigNumber(MIN_INT256); - const b = new BigNumber(-1); + const a = new BN(constants.MIN_INT256); + const b = new BN('-1'); - await shouldFail.reverting(this.safeMath.div(a, b)); + await shouldFail.reverting(this.safeMath.divInts(a, b)); }); }); }); diff --git a/test/examples/SampleCrowdsale.test.js b/test/examples/SampleCrowdsale.test.js index e768265b4..437158fce 100644 --- a/test/examples/SampleCrowdsale.test.js +++ b/test/examples/SampleCrowdsale.test.js @@ -1,17 +1,12 @@ -const { ether } = require('../helpers/ether'); -const shouldFail = require('../helpers/shouldFail'); -const time = require('../helpers/time'); -const { balanceDifference } = require('../helpers/balanceDifference'); - -const { should, BigNumber } = require('../helpers/setup'); +const { BN, balance, ether, should, shouldFail, time } = require('openzeppelin-test-helpers');; const SampleCrowdsale = artifacts.require('SampleCrowdsale'); const SampleCrowdsaleToken = artifacts.require('SampleCrowdsaleToken'); contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) { - const RATE = new BigNumber(10); - const GOAL = ether(10); - const CAP = ether(20); + const RATE = new BN(10); + const GOAL = ether('10'); + const CAP = ether('20'); before(async function () { // Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache @@ -19,9 +14,9 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) { }); beforeEach(async function () { - this.openingTime = (await time.latest()) + time.duration.weeks(1); - this.closingTime = this.openingTime + time.duration.weeks(1); - this.afterClosingTime = this.closingTime + time.duration.seconds(1); + this.openingTime = (await time.latest()).add(time.duration.weeks(1)); + this.closingTime = this.openingTime.add(time.duration.weeks(1)); + this.afterClosingTime = this.closingTime.add(time.duration.seconds(1)); this.token = await SampleCrowdsaleToken.new({ from: deployer }); this.crowdsale = await SampleCrowdsale.new( @@ -46,12 +41,12 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) { }); it('should not accept payments before start', async function () { - await shouldFail.reverting(this.crowdsale.send(ether(1))); - await shouldFail.reverting(this.crowdsale.buyTokens(investor, { from: investor, value: ether(1) })); + await shouldFail.reverting(this.crowdsale.send(ether('1'))); + await shouldFail.reverting(this.crowdsale.buyTokens(investor, { from: investor, value: ether('1') })); }); it('should accept payments during the sale', async function () { - const investmentAmount = ether(1); + const investmentAmount = ether('1'); const expectedTokenAmount = RATE.mul(investmentAmount); await time.increaseTo(this.openingTime); @@ -63,8 +58,8 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) { it('should reject payments after end', async function () { await time.increaseTo(this.afterClosingTime); - await shouldFail.reverting(this.crowdsale.send(ether(1))); - await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: ether(1), from: investor })); + await shouldFail.reverting(this.crowdsale.send(ether('1'))); + await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: ether('1'), from: investor })); }); it('should reject payments over cap', async function () { @@ -86,17 +81,17 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) { it('should allow refunds if the goal is not reached', async function () { (await balanceDifference(investor, async () => { await time.increaseTo(this.openingTime); - await this.crowdsale.sendTransaction({ value: ether(1), from: investor, gasPrice: 0 }); + await this.crowdsale.sendTransaction({ value: ether('1'), from: investor, gasPrice: 0 }); await time.increaseTo(this.afterClosingTime); await this.crowdsale.finalize({ from: owner }); await this.crowdsale.claimRefund(investor, { gasPrice: 0 }); - })).should.be.bignumber.equal(0); + })).should.be.bignumber.equal('0'); }); describe('when goal > cap', function () { // goal > cap - const HIGH_GOAL = ether(30); + const HIGH_GOAL = ether('30'); it('creation reverts', async function () { await shouldFail.reverting(SampleCrowdsale.new( diff --git a/test/examples/SimpleToken.test.js b/test/examples/SimpleToken.test.js index 540ce4ae0..307a25eb7 100644 --- a/test/examples/SimpleToken.test.js +++ b/test/examples/SimpleToken.test.js @@ -1,8 +1,6 @@ -const expectEvent = require('../helpers/expectEvent'); -const { ZERO_ADDRESS } = require('../helpers/constants'); -const SimpleToken = artifacts.require('SimpleToken'); +const { constants, expectEvent } = require('openzeppelin-test-helpers');; -require('../helpers/setup'); +const SimpleToken = artifacts.require('SimpleToken'); contract('SimpleToken', function ([_, creator]) { beforeEach(async function () { @@ -18,7 +16,7 @@ contract('SimpleToken', function ([_, creator]) { }); it('has 18 decimals', async function () { - (await this.token.decimals()).should.be.bignumber.equal(18); + (await this.token.decimals()).should.be.bignumber.equal('18'); }); it('assigns the initial total supply to the creator', async function () { @@ -28,7 +26,7 @@ contract('SimpleToken', function ([_, creator]) { creatorBalance.should.be.bignumber.equal(totalSupply); await expectEvent.inConstruction(this.token, 'Transfer', { - from: ZERO_ADDRESS, + from: constants.ZERO_ADDRESS, to: creator, value: totalSupply, }); diff --git a/test/introspection/ERC165.test.js b/test/introspection/ERC165.test.js index 0dc2f8471..8fa606aa9 100644 --- a/test/introspection/ERC165.test.js +++ b/test/introspection/ERC165.test.js @@ -1,20 +1,15 @@ +const { BN, shouldFail } = require('openzeppelin-test-helpers'); const { shouldSupportInterfaces } = require('./SupportsInterface.behavior'); -const shouldFail = require('../helpers/shouldFail'); const ERC165Mock = artifacts.require('ERC165Mock'); -require('chai') - .should(); - contract('ERC165', function () { beforeEach(async function () { this.mock = await ERC165Mock.new(); }); it('does not allow 0xffffffff', async function () { - await shouldFail.reverting( - this.mock.registerInterface(0xffffffff) - ); + await shouldFail.reverting(this.mock.registerInterface('0xffffffff')); }); shouldSupportInterfaces([ diff --git a/test/introspection/ERC165Checker.test.js b/test/introspection/ERC165Checker.test.js index c339c78ab..881d19dcf 100644 --- a/test/introspection/ERC165Checker.test.js +++ b/test/introspection/ERC165Checker.test.js @@ -1,3 +1,5 @@ +require('openzeppelin-test-helpers'); + const ERC165CheckerMock = artifacts.require('ERC165CheckerMock'); const ERC165NotSupported = artifacts.require('ERC165NotSupported'); const ERC165InterfacesSupported = artifacts.require('ERC165InterfacesSupported'); @@ -9,8 +11,6 @@ const DUMMY_UNSUPPORTED_ID = '0xbaddcafe'; const DUMMY_UNSUPPORTED_ID_2 = '0xbaadcafe'; const DUMMY_ACCOUNT = '0x1111111111111111111111111111111111111111'; -require('../helpers/setup'); - contract('ERC165Checker', function () { beforeEach(async function () { this.mock = await ERC165CheckerMock.new(); diff --git a/test/introspection/SupportsInterface.behavior.js b/test/introspection/SupportsInterface.behavior.js index 838787f72..fde7f5cc6 100644 --- a/test/introspection/SupportsInterface.behavior.js +++ b/test/introspection/SupportsInterface.behavior.js @@ -1,4 +1,4 @@ -const { makeInterfaceId } = require('../helpers/makeInterfaceId'); +const { makeInterfaceId } = require('openzeppelin-test-helpers'); const INTERFACE_IDS = { ERC165: makeInterfaceId([ diff --git a/test/lifecycle/Pausable.test.js b/test/lifecycle/Pausable.test.js index 89d3a7352..0b5fe3126 100644 --- a/test/lifecycle/Pausable.test.js +++ b/test/lifecycle/Pausable.test.js @@ -1,7 +1,7 @@ const { expectEvent, shouldFail } = require('openzeppelin-test-helpers'); +const { shouldBehaveLikePublicRole } = require('../access/roles/PublicRole.behavior'); const PausableMock = artifacts.require('PausableMock'); -const { shouldBehaveLikePublicRole } = require('../access/roles/PublicRole.behavior'); contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts]) { beforeEach(async function () { diff --git a/test/math/Math.test.js b/test/math/Math.test.js index 99ab04531..c9f4aa73c 100644 --- a/test/math/Math.test.js +++ b/test/math/Math.test.js @@ -1,10 +1,10 @@ +const { BN } = require('openzeppelin-test-helpers');; + const MathMock = artifacts.require('MathMock'); -const { BigNumber } = require('../helpers/setup'); - contract('Math', function () { - const min = 1234; - const max = 5678; + const min = new BN('1234'); + const max = new BN('5678'); beforeEach(async function () { this.math = await MathMock.new(); @@ -32,24 +32,24 @@ contract('Math', function () { describe('average', function () { function bnAverage (a, b) { - return a.plus(b).div(2).truncated(); + return a.add(b).divn(2); } it('is correctly calculated with two odd numbers', async function () { - const a = new BigNumber(57417); - const b = new BigNumber(95431); + const a = new BN('57417'); + const b = new BN('95431'); (await this.math.average(a, b)).should.be.bignumber.equal(bnAverage(a, b)); }); it('is correctly calculated with two even numbers', async function () { - const a = new BigNumber(42304); - const b = new BigNumber(84346); + const a = new BN('42304'); + const b = new BN('84346'); (await this.math.average(a, b)).should.be.bignumber.equal(bnAverage(a, b)); }); it('is correctly calculated with one even and one odd number', async function () { - const a = new BigNumber(57417); - const b = new BigNumber(84346); + const a = new BN('57417'); + const b = new BN('84346'); (await this.math.average(a, b)).should.be.bignumber.equal(bnAverage(a, b)); }); }); diff --git a/test/math/SafeMath.test.js b/test/math/SafeMath.test.js index 221c998ff..a0d69aae1 100644 --- a/test/math/SafeMath.test.js +++ b/test/math/SafeMath.test.js @@ -1,10 +1,7 @@ -const shouldFail = require('../helpers/shouldFail'); -const { MAX_UINT256 } = require('../helpers/constants'); +const { BN, constants, shouldFail } = require('openzeppelin-test-helpers'); const SafeMathMock = artifacts.require('SafeMathMock'); -const { BigNumber } = require('../helpers/setup'); - contract('SafeMath', function () { beforeEach(async function () { this.safeMath = await SafeMathMock.new(); @@ -12,132 +9,132 @@ contract('SafeMath', function () { describe('add', function () { it('adds correctly', async function () { - const a = new BigNumber(5678); - const b = new BigNumber(1234); + const a = new BN('5678'); + const b = new BN('1234'); - (await this.safeMath.add(a, b)).should.be.bignumber.equal(a.plus(b)); + (await this.safeMath.addUints(a, b)).should.be.bignumber.equal(a.add(b)); }); it('reverts on addition overflow', async function () { - const a = MAX_UINT256; - const b = new BigNumber(1); + const a = constants.MAX_UINT256; + const b = new BN('1'); - await shouldFail.reverting(this.safeMath.add(a, b)); + await shouldFail.reverting(this.safeMath.addUints(a, b)); }); }); describe('sub', function () { it('subtracts correctly', async function () { - const a = new BigNumber(5678); - const b = new BigNumber(1234); + const a = new BN('5678'); + const b = new BN('1234'); - (await this.safeMath.sub(a, b)).should.be.bignumber.equal(a.minus(b)); + (await this.safeMath.subUints(a, b)).should.be.bignumber.equal(a.sub(b)); }); it('reverts if subtraction result would be negative', async function () { - const a = new BigNumber(1234); - const b = new BigNumber(5678); + const a = new BN('1234'); + const b = new BN('5678'); - await shouldFail.reverting(this.safeMath.sub(a, b)); + await shouldFail.reverting(this.safeMath.subUints(a, b)); }); }); describe('mul', function () { it('multiplies correctly', async function () { - const a = new BigNumber(1234); - const b = new BigNumber(5678); + const a = new BN('1234'); + const b = new BN('5678'); - (await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.times(b)); + (await this.safeMath.mulUints(a, b)).should.be.bignumber.equal(a.mul(b)); }); it('handles a zero product correctly (first number as zero)', async function () { - const a = new BigNumber(0); - const b = new BigNumber(5678); + const a = new BN('0'); + const b = new BN('5678'); - (await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.times(b)); + (await this.safeMath.mulUints(a, b)).should.be.bignumber.equal(a.mul(b)); }); it('handles a zero product correctly (second number as zero)', async function () { - const a = new BigNumber(5678); - const b = new BigNumber(0); + const a = new BN('5678'); + const b = new BN('0'); - (await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.times(b)); + (await this.safeMath.mulUints(a, b)).should.be.bignumber.equal(a.mul(b)); }); it('reverts on multiplication overflow', async function () { - const a = MAX_UINT256; - const b = new BigNumber(2); + const a = constants.MAX_UINT256; + const b = new BN('2'); - await shouldFail.reverting(this.safeMath.mul(a, b)); + await shouldFail.reverting(this.safeMath.mulUints(a, b)); }); }); describe('div', function () { it('divides correctly', async function () { - const a = new BigNumber(5678); - const b = new BigNumber(5678); + const a = new BN('5678'); + const b = new BN('5678'); - (await this.safeMath.div(a, b)).should.be.bignumber.equal(a.div(b)); + (await this.safeMath.divUints(a, b)).should.be.bignumber.equal(a.div(b)); }); it('divides zero correctly', async function () { - const a = new BigNumber(0); - const b = new BigNumber(5678); + const a = new BN('0'); + const b = new BN('5678'); - (await this.safeMath.div(a, b)).should.be.bignumber.equal(0); + (await this.safeMath.divUints(a, b)).should.be.bignumber.equal('0'); }); it('returns complete number result on non-even division', async function () { - const a = new BigNumber(7000); - const b = new BigNumber(5678); + const a = new BN('7000'); + const b = new BN('5678'); - (await this.safeMath.div(a, b)).should.be.bignumber.equal(1); + (await this.safeMath.divUints(a, b)).should.be.bignumber.equal('1'); }); it('reverts on zero division', async function () { - const a = new BigNumber(5678); - const b = new BigNumber(0); + const a = new BN('5678'); + const b = new BN('0'); - await shouldFail.reverting(this.safeMath.div(a, b)); + await shouldFail.reverting(this.safeMath.divUints(a, b)); }); }); describe('mod', function () { describe('modulos correctly', async function () { it('when the dividend is smaller than the divisor', async function () { - const a = new BigNumber(284); - const b = new BigNumber(5678); + const a = new BN('284'); + const b = new BN('5678'); - (await this.safeMath.mod(a, b)).should.be.bignumber.equal(a.mod(b)); + (await this.safeMath.modUints(a, b)).should.be.bignumber.equal(a.mod(b)); }); it('when the dividend is equal to the divisor', async function () { - const a = new BigNumber(5678); - const b = new BigNumber(5678); + const a = new BN('5678'); + const b = new BN('5678'); - (await this.safeMath.mod(a, b)).should.be.bignumber.equal(a.mod(b)); + (await this.safeMath.modUints(a, b)).should.be.bignumber.equal(a.mod(b)); }); it('when the dividend is larger than the divisor', async function () { - const a = new BigNumber(7000); - const b = new BigNumber(5678); + const a = new BN('7000'); + const b = new BN('5678'); - (await this.safeMath.mod(a, b)).should.be.bignumber.equal(a.mod(b)); + (await this.safeMath.modUints(a, b)).should.be.bignumber.equal(a.mod(b)); }); it('when the dividend is a multiple of the divisor', async function () { - const a = new BigNumber(17034); // 17034 == 5678 * 3 - const b = new BigNumber(5678); + const a = new BN('17034'); // 17034 == 5678 * 3 + const b = new BN('5678'); - (await this.safeMath.mod(a, b)).should.be.bignumber.equal(a.mod(b)); + (await this.safeMath.modUints(a, b)).should.be.bignumber.equal(a.mod(b)); }); }); it('reverts with a 0 divisor', async function () { - const a = new BigNumber(5678); - const b = new BigNumber(0); + const a = new BN('5678'); + const b = new BN('0'); - await shouldFail.reverting(this.safeMath.mod(a, b)); + await shouldFail.reverting(this.safeMath.modUints(a, b)); }); }); });