Migration to truffle 5 (and web3 1.0 (and BN)) (#1601)
* Now compiling using truffle 5.
* Migrated some test files, missing BN scientific notation usage.
* Now using BN time values.
* Migrate ERC20 tests.
* Migrate all ERC20 tests.
* Migrate utils, payment and ownership tests.
* All tests save ERC721 migrated.
* Migrated ERC721 tests.
* Fix lint errors.
* Delete old test helpers.
* Fix remaining crowdsale tests.
* Fix signature bouncer tests.
* Update how constants is used.
* Compile script pre-removes the build dir.
* Fix SafeMath tests.
* Revert "Compile script pre-removes the build dir."
This reverts commit 247e745113.
* Fix linter errors.
* Upgrade openzeppelin-test-helpers dependency.
* Update openzeppelin-test-helpers dependency.
* Define math constants globally.
* Remove unnecessary ether unit.
* Roll back reduced ether amounts in tests.
* Remove unnecessary toNumber conversions.
* Delete compile script.
* Fixed failing test.
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
const shouldFail = require('../helpers/shouldFail');
|
||||
const { MAX_UINT256 } = require('../helpers/constants');
|
||||
const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
|
||||
const { MAX_UINT256 } = constants;
|
||||
|
||||
const SafeMathMock = artifacts.require('SafeMathMock');
|
||||
|
||||
const { BigNumber } = require('../helpers/setup');
|
||||
|
||||
contract('SafeMath', function () {
|
||||
beforeEach(async function () {
|
||||
this.safeMath = await SafeMathMock.new();
|
||||
@ -12,15 +10,15 @@ 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.add(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 b = new BN('1');
|
||||
|
||||
await shouldFail.reverting(this.safeMath.add(a, b));
|
||||
});
|
||||
@ -28,15 +26,15 @@ contract('SafeMath', function () {
|
||||
|
||||
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.sub(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));
|
||||
});
|
||||
@ -44,29 +42,29 @@ contract('SafeMath', function () {
|
||||
|
||||
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.mul(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.mul(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.mul(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 b = new BN('2');
|
||||
|
||||
await shouldFail.reverting(this.safeMath.mul(a, b));
|
||||
});
|
||||
@ -74,29 +72,29 @@ contract('SafeMath', function () {
|
||||
|
||||
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));
|
||||
});
|
||||
|
||||
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.div(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.div(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));
|
||||
});
|
||||
@ -105,37 +103,37 @@ contract('SafeMath', function () {
|
||||
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));
|
||||
});
|
||||
|
||||
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));
|
||||
});
|
||||
|
||||
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));
|
||||
});
|
||||
|
||||
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));
|
||||
});
|
||||
});
|
||||
|
||||
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));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user