Browse Source

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 247e7451135d33c056a126e9e5fd77a24348018d.

* 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.
Nicolás Venturo 6 years ago
parent
commit
3e82db2f6f
86 changed files with 827 additions and 2456 deletions
  1. 0 3
      .gitignore
  2. 145 640
      package-lock.json
  3. 3 4
      package.json
  4. 0 42
      scripts/compile.sh
  5. 2 4
      test/access/Roles.test.js
  6. 2 5
      test/access/roles/PublicRole.behavior.js
  7. 8 13
      test/crowdsale/AllowanceCrowdsale.test.js
  8. 8 11
      test/crowdsale/CappedCrowdsale.test.js
  9. 7 12
      test/crowdsale/Crowdsale.test.js
  10. 5 9
      test/crowdsale/FinalizableCrowdsale.test.js
  11. 23 27
      test/crowdsale/IncreasingPriceCrowdsale.test.js
  12. 9 12
      test/crowdsale/IndividuallyCappedCrowdsale.test.js
  13. 2 5
      test/crowdsale/MintedCrowdsale.behavior.js
  14. 3 6
      test/crowdsale/MintedCrowdsale.test.js
  15. 4 6
      test/crowdsale/PausableCrowdsale.test.js
  16. 9 13
      test/crowdsale/PostDeliveryCrowdsale.test.js
  17. 12 18
      test/crowdsale/RefundableCrowdsale.test.js
  18. 11 19
      test/crowdsale/RefundablePostDeliveryCrowdsale.test.js
  19. 9 13
      test/crowdsale/TimedCrowdsale.test.js
  20. 4 8
      test/crowdsale/WhitelistCrowdsale.test.js
  21. 8 10
      test/cryptography/ECDSA.test.js
  22. 2 2
      test/cryptography/MerkleProof.test.js
  23. 4 5
      test/drafts/Counter.test.js
  24. 2 2
      test/drafts/ERC1046/TokenMetadata.test.js
  25. 8 10
      test/drafts/ERC20Migrator.test.js
  26. 25 25
      test/drafts/SignatureBouncer.test.js
  27. 31 33
      test/drafts/SignedSafeMath.test.js
  28. 19 25
      test/drafts/TokenVesting.test.js
  29. 17 22
      test/examples/SampleCrowdsale.test.js
  30. 4 5
      test/examples/SimpleToken.test.js
  31. 0 12
      test/helpers/balanceDifference.js
  32. 0 8
      test/helpers/constants.js
  33. 0 7
      test/helpers/ether.js
  34. 0 57
      test/helpers/expectEvent.js
  35. 0 25
      test/helpers/makeInterfaceId.js
  36. 0 26
      test/helpers/send.js
  37. 0 9
      test/helpers/setup.js
  38. 0 36
      test/helpers/shouldFail.js
  39. 7 27
      test/helpers/sign.js
  40. 0 22
      test/helpers/test/balanceDifference.test.js
  41. 0 16
      test/helpers/test/ether.test.js
  42. 0 375
      test/helpers/test/expectEvent.test.js
  43. 0 20
      test/helpers/test/makeInterfaceId.test.js
  44. 0 70
      test/helpers/test/send.test.js
  45. 0 95
      test/helpers/test/shouldFail.test.js
  46. 0 77
      test/helpers/test/time.test.js
  47. 0 60
      test/helpers/time.js
  48. 0 10
      test/helpers/web3.js
  49. 2 7
      test/introspection/ERC165.test.js
  50. 2 2
      test/introspection/ERC165Checker.test.js
  51. 1 1
      test/introspection/SupportsInterface.behavior.js
  52. 6 9
      test/lifecycle/Pausable.test.js
  53. 11 11
      test/math/Math.test.js
  54. 41 43
      test/math/SafeMath.test.js
  55. 3 5
      test/ownership/Ownable.behavior.js
  56. 1 0
      test/ownership/Ownable.test.js
  57. 2 5
      test/ownership/Secondary.test.js
  58. 23 28
      test/payment/PaymentSplitter.test.js
  59. 8 11
      test/payment/PullPayment.test.js
  60. 2 6
      test/payment/escrow/ConditionalEscrow.test.js
  61. 12 18
      test/payment/escrow/Escrow.behavior.js
  62. 1 0
      test/payment/escrow/Escrow.test.js
  63. 7 12
      test/payment/escrow/RefundEscrow.test.js
  64. 119 123
      test/token/ERC20/ERC20.test.js
  65. 3 1
      test/token/ERC20/ERC20Burnable.test.js
  66. 3 4
      test/token/ERC20/ERC20Capped.test.js
  67. 2 2
      test/token/ERC20/ERC20Detailed.test.js
  68. 46 35
      test/token/ERC20/ERC20Pausable.test.js
  69. 1 3
      test/token/ERC20/SafeERC20.test.js
  70. 8 11
      test/token/ERC20/TokenTimelock.test.js
  71. 17 18
      test/token/ERC20/behaviors/ERC20Burnable.behavior.js
  72. 6 8
      test/token/ERC20/behaviors/ERC20Capped.behavior.js
  73. 4 7
      test/token/ERC20/behaviors/ERC20Mintable.behavior.js
  74. 21 26
      test/token/ERC721/ERC721.behavior.js
  75. 13 17
      test/token/ERC721/ERC721.test.js
  76. 2 2
      test/token/ERC721/ERC721Burnable.test.js
  77. 20 21
      test/token/ERC721/ERC721Full.test.js
  78. 3 3
      test/token/ERC721/ERC721Holder.test.js
  79. 8 10
      test/token/ERC721/ERC721MintBurn.behavior.js
  80. 2 5
      test/token/ERC721/ERC721Mintable.test.js
  81. 1 2
      test/token/ERC721/ERC721Pausable.test.js
  82. 8 19
      test/token/ERC721/ERC721PausedToken.behavior.js
  83. 2 2
      test/utils/Address.test.js
  84. 14 14
      test/utils/Arrays.test.js
  85. 3 4
      test/utils/ReentrancyGuard.test.js
  86. 6 0
      truffle-config.js

+ 0 - 3
.gitignore

@@ -37,6 +37,3 @@ build/
 
 # truffle
 .node-xmlhttprequest-*
-
-# Temporary directory for 0.5.x compilation
-solc-0.5

File diff suppressed because it is too large
+ 145 - 640
package-lock.json


+ 3 - 4
package.json

@@ -9,7 +9,7 @@
   ],
   "scripts": {
     "build": "scripts/build.sh",
-    "compile": "scripts/compile.sh",
+    "compile": "truffle compile",
     "console": "truffle console",
     "coverage": "scripts/coverage.sh",
     "lint": "npm run lint:js && npm run lint:sol",
@@ -41,7 +41,6 @@
   "homepage": "https://github.com/OpenZeppelin/zeppelin-solidity",
   "devDependencies": {
     "chai": "^4.1.2",
-    "chai-bignumber": "^2.0.2",
     "coveralls": "^3.0.1",
     "eslint": "^4.19.1",
     "eslint-config-standard": "^10.2.1",
@@ -53,11 +52,11 @@
     "ethereumjs-util": "^6.0.0",
     "ethjs-abi": "^0.2.1",
     "ganache-cli": "6.1.8",
+    "openzeppelin-test-helpers": "^0.1.1",
     "pify": "^4.0.1",
     "solhint": "^1.5.0",
     "solidity-coverage": "^0.5.4",
-    "truffle": "^4.1.13",
-    "web3-utils": "^1.0.0-beta.34"
+    "truffle": "^5.0.0"
   },
   "dependencies": {}
 }

+ 0 - 42
scripts/compile.sh

@@ -1,42 +0,0 @@
-#!/usr/bin/env bash
-
-# Configure to exit script as soon as a command fails.
-set -o errexit
-
-SOLC_05_DIR=solc-0.5
-
-# Delete any previous build artifacts
-rm -rf build/
-
-# Create a subproject where 0.5.x compilation will take place
-mkdir -p "$SOLC_05_DIR"
-
-cd "$SOLC_05_DIR"
-echo '{ "private": true }' > package.json
-npm install --save-dev truffle@5.0.0
-
-rm -rf contracts
-ln --symbolic ../contracts contracts
-
-# Delete any previous build artifacts
-rm -rf build/
-
-# Compile
-echo "
-module.exports = {
-  compilers: {
-    solc: {
-      version: \"0.5.0\",
-    },
-  },
-};
-" > truffle-config.js
-
-npx truffle compile
-
-# Modify the paths in the artifacts to make it look as if they were built in the root
-sed --in-place --expression "s/\/$SOLC_05_DIR//g" build/contracts/*.json
-
-# Copy them back into the root
-cd ..
-cp --recursive "$SOLC_05_DIR"/build build

+ 2 - 4
test/access/Roles.test.js

@@ -1,10 +1,8 @@
-const shouldFail = require('../helpers/shouldFail');
-const { ZERO_ADDRESS } = require('../helpers/constants');
+const { shouldFail, constants } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 const RolesMock = artifacts.require('RolesMock');
 
-require('./../helpers/setup');
-
 contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
   beforeEach(async function () {
     this.roles = await RolesMock.new();

+ 2 - 5
test/access/roles/PublicRole.behavior.js

@@ -1,8 +1,5 @@
-const shouldFail = require('../../helpers/shouldFail');
-const { ZERO_ADDRESS } = require('../../helpers/constants');
-const expectEvent = require('../../helpers/expectEvent');
-
-require('../../helpers/setup');
+const { shouldFail, constants, expectEvent } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 function capitalize (str) {
   return str.replace(/\b\w/g, l => l.toUpperCase());

+ 8 - 13
test/crowdsale/AllowanceCrowdsale.test.js

@@ -1,19 +1,14 @@
-const expectEvent = require('../helpers/expectEvent');
-const { ether } = require('../helpers/ether');
-const shouldFail = require('../helpers/shouldFail');
-const { balanceDifference } = require('../helpers/balanceDifference');
-const { ZERO_ADDRESS } = require('../helpers/constants');
-
-const { BigNumber } = require('../helpers/setup');
+const { balance, BN, constants, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 const AllowanceCrowdsaleImpl = artifacts.require('AllowanceCrowdsaleImpl');
 const SimpleToken = artifacts.require('SimpleToken');
 
 contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenWallet]) {
-  const rate = new BigNumber(1);
-  const value = ether(0.42);
+  const rate = new BN('1');
+  const value = ether('0.42');
   const expectedTokenAmount = rate.mul(value);
-  const tokenAllowance = new BigNumber('1e22');
+  const tokenAllowance = new BN('10').pow(new BN('22'));
 
   beforeEach(async function () {
     this.token = await SimpleToken.new({ from: tokenWallet });
@@ -52,7 +47,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
     });
 
     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);
     });
@@ -60,7 +55,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);
     });
@@ -68,7 +63,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.plus(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 () {

+ 8 - 11
test/crowdsale/CappedCrowdsale.test.js

@@ -1,16 +1,13 @@
-const { ether } = require('../helpers/ether');
-const shouldFail = require('../helpers/shouldFail');
-
-const { BigNumber } = require('../helpers/setup');
+const { BN, ether, shouldFail } = require('openzeppelin-test-helpers');
 
 const CappedCrowdsaleImpl = artifacts.require('CappedCrowdsaleImpl');
 const SimpleToken = artifacts.require('SimpleToken');
 
 contract('CappedCrowdsale', function ([_, wallet]) {
-  const rate = new BigNumber(1);
-  const cap = ether(100);
-  const lessThanCap = ether(60);
-  const tokenSupply = new BigNumber('1e22');
+  const rate = new BN('1');
+  const cap = ether('100');
+  const lessThanCap = ether('60');
+  const tokenSupply = new BN('10').pow(new BN('22'));
 
   beforeEach(async function () {
     this.token = await SimpleToken.new();
@@ -28,7 +25,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
 
     describe('accepting payments', function () {
       it('should accept payments within cap', async function () {
-        await this.crowdsale.send(cap.minus(lessThanCap));
+        await this.crowdsale.send(cap.sub(lessThanCap));
         await this.crowdsale.send(lessThanCap);
       });
 
@@ -38,7 +35,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
       });
 
       it('should reject payments that exceed cap', async function () {
-        await shouldFail.reverting(this.crowdsale.send(cap.plus(1)));
+        await shouldFail.reverting(this.crowdsale.send(cap.addn(1)));
       });
     });
 
@@ -49,7 +46,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
       });
 
       it('should not reach cap if sent just under cap', async function () {
-        await this.crowdsale.send(cap.minus(1));
+        await this.crowdsale.send(cap.subn(1));
         (await this.crowdsale.capReached()).should.equal(false);
       });
 

+ 7 - 12
test/crowdsale/Crowdsale.test.js

@@ -1,18 +1,13 @@
-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 { ZERO_ADDRESS } = constants;
 
 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 +88,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 +111,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);
         });

+ 5 - 9
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(

+ 23 - 27
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,12 +61,12 @@ 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 () {
         await time.increaseTo(this.afterClosingTime);
-        (await this.crowdsale.getCurrentRate()).should.be.bignumber.equal(0);
+        (await this.crowdsale.getCurrentRate()).should.be.bignumber.equal('0');
       });
 
       it('at start', 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.addn(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));
       });

+ 9 - 12
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.addn(1) }));
+          await shouldFail.reverting(this.crowdsale.buyTokens(bob, { value: capBob.addn(1) }));
         });
 
         it('should manage independent caps', async function () {

+ 2 - 5
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);
       });

+ 3 - 6
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 () {

+ 4 - 6
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 () {

+ 9 - 13
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);
         });
 

+ 12 - 18
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,8 +88,8 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon
           });
 
           it('forwards funds to wallet', async function () {
-            const postWalletBalance = await ethGetBalance(wallet);
-            postWalletBalance.minus(this.preWalletBalance).should.be.bignumber.equal(goal);
+            const postWalletBalance = await balance.current(wallet);
+            postWalletBalance.sub(this.preWalletBalance).should.be.bignumber.equal(goal);
           });
         });
       });

+ 11 - 19
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);
         });
 

+ 9 - 13
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
     ));
   });
 

+ 4 - 8
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 });

+ 8 - 10
test/cryptography/ECDSA.test.js

@@ -1,12 +1,10 @@
+const { shouldFail } = require('openzeppelin-test-helpers');
 const { signMessage, toEthSignedMessageHash } = require('../helpers/sign');
-const shouldFail = require('../helpers/shouldFail');
 
 const ECDSAMock = artifacts.require('ECDSAMock');
 
-require('../helpers/setup');
-
-const TEST_MESSAGE = web3.sha3('OpenZeppelin');
-const WRONG_MESSAGE = web3.sha3('Nope');
+const TEST_MESSAGE = web3.utils.sha3('OpenZeppelin');
+const WRONG_MESSAGE = web3.utils.sha3('Nope');
 
 contract('ECDSA', function ([_, anyone]) {
   beforeEach(async function () {
@@ -16,7 +14,7 @@ contract('ECDSA', function ([_, anyone]) {
   context('recover with valid signature', function () {
     context('with v0 signature', function () {
       // Signature generated outside ganache with method web3.eth.sign(signer, message)
-      const signer = '0x2cc1166f6212628a0deef2b33befb2187d35b86c';
+      const signer = '0x2cc1166f6212628A0deEf2B33BEFB2187D35b86c';
       // eslint-disable-next-line max-len
       const signatureWithoutVersion = '0x5d99b6f7f6d1f73d1a26497f2b1c89b24c0993913f86e9a2d02cd69887d9c94f3c880358579d811b21dd1b7fd9bb01c1d81d10e69f0384e675c32b39643be892';
 
@@ -49,7 +47,7 @@ contract('ECDSA', function ([_, anyone]) {
     });
 
     context('with v1 signature', function () {
-      const signer = '0x1e318623ab09fe6de3c9b8672098464aeda9100e';
+      const signer = '0x1E318623aB09Fe6de3C9b8672098464Aeda9100E';
       // eslint-disable-next-line max-len
       const signatureWithoutVersion = '0x331fe75a821c982f9127538858900d87d3ec1f9f737338ad67cad133fa48feff48e6fa0c18abc62e42820f05943e47af3e9fbe306ce74d64094bdf1691ee53e0';
 
@@ -85,7 +83,7 @@ contract('ECDSA', function ([_, anyone]) {
       context('with correct signature', function () {
         it('returns signer address', async function () {
           // Create the signature
-          const signature = signMessage(anyone, TEST_MESSAGE);
+          const signature = await signMessage(anyone, TEST_MESSAGE);
 
           // Recover the signer address from the generated message and signature.
           (await this.ecdsa.recover(
@@ -98,7 +96,7 @@ contract('ECDSA', function ([_, anyone]) {
       context('with wrong signature', function () {
         it('does not return signer address', async function () {
           // Create the signature
-          const signature = signMessage(anyone, TEST_MESSAGE);
+          const signature = await signMessage(anyone, TEST_MESSAGE);
 
           // Recover the signer address from the generated message and wrong signature.
           (await this.ecdsa.recover(WRONG_MESSAGE, signature)).should.not.equal(anyone);
@@ -111,7 +109,7 @@ contract('ECDSA', function ([_, anyone]) {
     // @TODO - remove `skip` once we upgrade to solc^0.5
     it.skip('reverts', async function () {
       // Create the signature
-      const signature = signMessage(anyone, TEST_MESSAGE);
+      const signature = await signMessage(anyone, TEST_MESSAGE);
       await shouldFail.reverting(
         this.ecdsa.recover(TEST_MESSAGE.substring(2), signature)
       );

+ 2 - 2
test/cryptography/MerkleProof.test.js

@@ -1,10 +1,10 @@
+require('openzeppelin-test-helpers');
+
 const { MerkleTree } = require('../helpers/merkleTree.js');
 const { keccak256, bufferToHex } = require('ethereumjs-util');
 
 const MerkleProofWrapper = artifacts.require('MerkleProofWrapper');
 
-require('../helpers/setup');
-
 contract('MerkleProof', function () {
   beforeEach(async function () {
     this.merkleProof = await MerkleProofWrapper.new();

+ 4 - 5
test/drafts/Counter.test.js

@@ -1,11 +1,10 @@
+const { BN } = require('openzeppelin-test-helpers');
 
 const CounterImpl = artifacts.require('CounterImpl');
 
-require('../helpers/setup');
-
-const EXPECTED = [1, 2, 3, 4];
-const KEY1 = web3.sha3('key1');
-const KEY2 = web3.sha3('key2');
+const EXPECTED = [new BN(1), new BN(2), new BN(3), new BN(4)];
+const KEY1 = web3.utils.sha3('key1');
+const KEY2 = web3.utils.sha3('key2');
 
 contract('Counter', function ([_, owner]) {
   beforeEach(async function () {

+ 2 - 2
test/drafts/ERC1046/TokenMetadata.test.js

@@ -1,6 +1,6 @@
-const ERC20WithMetadataMock = artifacts.require('ERC20WithMetadataMock');
+require('openzeppelin-test-helpers');
 
-require('../../helpers/setup');
+const ERC20WithMetadataMock = artifacts.require('ERC20WithMetadataMock');
 
 const metadataURI = 'https://example.com';
 

+ 8 - 10
test/drafts/ERC20Migrator.test.js

@@ -1,14 +1,12 @@
-const shouldFail = require('../helpers/shouldFail');
-const { ZERO_ADDRESS } = require('../helpers/constants');
+const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 const ERC20Mock = artifacts.require('ERC20Mock');
 const ERC20Mintable = artifacts.require('ERC20Mintable');
 const ERC20Migrator = artifacts.require('ERC20Migrator');
 
-require('../helpers/setup');
-
 contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
-  const totalSupply = 200;
+  const totalSupply = new BN('200');
 
   it('reverts with a null legacy token address', async function () {
     await shouldFail.reverting(ERC20Migrator.new(ZERO_ADDRESS));
@@ -81,7 +79,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
             currentBurnedBalance.should.be.bignumber.equal(amount);
 
             const currentLegacyTokenBalance = await this.legacyToken.balanceOf(owner);
-            currentLegacyTokenBalance.should.be.bignumber.equal(0);
+            currentLegacyTokenBalance.should.be.bignumber.equal('0');
           });
 
           it('updates the total supply', async function () {
@@ -91,7 +89,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
         });
 
         describe('when the approved balance is lower than the owned balance', function () {
-          const amount = baseAmount - 1;
+          const amount = baseAmount.subn(1);
 
           beforeEach('approving part of the balance to the new contract', async function () {
             await this.legacyToken.approve(this.migrator.address, amount, { from: owner });
@@ -106,7 +104,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
       });
 
       describe('migrate', function () {
-        const baseAmount = 50;
+        const baseAmount = new BN(50);
 
         beforeEach('approving tokens to the new contract', async function () {
           await this.legacyToken.approve(this.migrator.address, baseAmount, { from: owner });
@@ -129,7 +127,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
             currentBurnedBalance.should.be.bignumber.equal(amount);
 
             const currentLegacyTokenBalance = await this.legacyToken.balanceOf(owner);
-            currentLegacyTokenBalance.should.be.bignumber.equal(totalSupply - amount);
+            currentLegacyTokenBalance.should.be.bignumber.equal(totalSupply.sub(amount));
           });
 
           it('updates the total supply', async function () {
@@ -139,7 +137,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
         });
 
         describe('when the given amount is higher than the one approved', function () {
-          const amount = baseAmount + 1;
+          const amount = baseAmount.addn(1);
 
           it('reverts', async function () {
             await shouldFail.reverting(this.migrator.migrate(owner, amount));

+ 25 - 25
test/drafts/SignatureBouncer.test.js

@@ -1,13 +1,11 @@
-const shouldFail = require('../helpers/shouldFail');
+const { shouldFail } = require('openzeppelin-test-helpers');
 const { getSignFor } = require('../helpers/sign');
 const { shouldBehaveLikePublicRole } = require('../access/roles/PublicRole.behavior');
 
 const SignatureBouncerMock = artifacts.require('SignatureBouncerMock');
 
-require('../helpers/setup');
-
 const UINT_VALUE = 23;
-const BYTES_VALUE = web3.toHex('test');
+const BYTES_VALUE = web3.utils.toHex('test');
 const INVALID_SIGNATURE = '0xabcd';
 
 contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authorizedUser, ...otherAccounts]) {
@@ -28,7 +26,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
   describe('modifiers', function () {
     context('plain signature', function () {
       it('allows valid signature for sender', async function () {
-        await this.sigBouncer.onlyWithValidSignature(this.signFor(authorizedUser), { from: authorizedUser });
+        await this.sigBouncer.onlyWithValidSignature(await this.signFor(authorizedUser), { from: authorizedUser });
       });
 
       it('does not allow invalid signature for sender', async function () {
@@ -39,13 +37,13 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
 
       it('does not allow valid signature for other sender', async function () {
         await shouldFail.reverting(
-          this.sigBouncer.onlyWithValidSignature(this.signFor(authorizedUser), { from: anyone })
+          this.sigBouncer.onlyWithValidSignature(await this.signFor(authorizedUser), { from: anyone })
         );
       });
 
       it('does not allow valid signature for method for sender', async function () {
         await shouldFail.reverting(
-          this.sigBouncer.onlyWithValidSignature(this.signFor(authorizedUser, 'onlyWithValidSignature'),
+          this.sigBouncer.onlyWithValidSignature(await this.signFor(authorizedUser, 'onlyWithValidSignature'),
             { from: authorizedUser })
         );
       });
@@ -54,7 +52,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
     context('method signature', function () {
       it('allows valid signature with correct method for sender', async function () {
         await this.sigBouncer.onlyWithValidSignatureAndMethod(
-          this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: authorizedUser }
+          await this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: authorizedUser }
         );
       });
 
@@ -67,21 +65,21 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
       it('does not allow valid signature with correct method for other sender', async function () {
         await shouldFail.reverting(
           this.sigBouncer.onlyWithValidSignatureAndMethod(
-            this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: anyone }
+            await this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: anyone }
           )
         );
       });
 
       it('does not allow valid method signature with incorrect method for sender', async function () {
         await shouldFail.reverting(
-          this.sigBouncer.onlyWithValidSignatureAndMethod(this.signFor(authorizedUser, 'theWrongMethod'),
+          this.sigBouncer.onlyWithValidSignatureAndMethod(await this.signFor(authorizedUser, 'theWrongMethod'),
             { from: authorizedUser })
         );
       });
 
       it('does not allow valid non-method signature method for sender', async function () {
         await shouldFail.reverting(
-          this.sigBouncer.onlyWithValidSignatureAndMethod(this.signFor(authorizedUser), { from: authorizedUser })
+          this.sigBouncer.onlyWithValidSignatureAndMethod(await this.signFor(authorizedUser), { from: authorizedUser })
         );
       });
     });
@@ -89,7 +87,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
     context('method and data signature', function () {
       it('allows valid signature with correct method and data for sender', async function () {
         await this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE,
-          this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]), { from: authorizedUser }
+          await this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]), { from: authorizedUser }
         );
       });
 
@@ -102,7 +100,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
       it('does not allow valid signature with correct method and incorrect data for sender', async function () {
         await shouldFail.reverting(
           this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE + 10,
-            this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]),
+            await this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]),
             { from: authorizedUser }
           )
         );
@@ -111,7 +109,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
       it('does not allow valid signature with correct method and data for other sender', async function () {
         await shouldFail.reverting(
           this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE,
-            this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]),
+            await this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]),
             { from: anyone }
           )
         );
@@ -120,7 +118,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
       it('does not allow valid non-method signature for sender', async function () {
         await shouldFail.reverting(
           this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE,
-            this.signFor(authorizedUser), { from: authorizedUser }
+            await this.signFor(authorizedUser), { from: authorizedUser }
           )
         );
       });
@@ -136,7 +134,8 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
   context('signature validation', function () {
     context('plain signature', function () {
       it('validates valid signature for valid user', async function () {
-        (await this.sigBouncer.checkValidSignature(authorizedUser, this.signFor(authorizedUser))).should.equal(true);
+        (await this.sigBouncer.checkValidSignature(authorizedUser, await this.signFor(authorizedUser)))
+          .should.equal(true);
       });
 
       it('does not validate invalid signature for valid user', async function () {
@@ -144,11 +143,12 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
       });
 
       it('does not validate valid signature for anyone', async function () {
-        (await this.sigBouncer.checkValidSignature(anyone, this.signFor(authorizedUser))).should.equal(false);
+        (await this.sigBouncer.checkValidSignature(anyone, await this.signFor(authorizedUser))).should.equal(false);
       });
 
       it('does not validate valid signature for method for valid user', async function () {
-        (await this.sigBouncer.checkValidSignature(authorizedUser, this.signFor(authorizedUser, 'checkValidSignature'))
+        (await this.sigBouncer.checkValidSignature(
+          authorizedUser, await this.signFor(authorizedUser, 'checkValidSignature'))
         ).should.equal(false);
       });
     });
@@ -156,7 +156,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
     context('method signature', function () {
       it('validates valid signature with correct method for valid user', async function () {
         (await this.sigBouncer.checkValidSignatureAndMethod(authorizedUser,
-          this.signFor(authorizedUser, 'checkValidSignatureAndMethod'))
+          await this.signFor(authorizedUser, 'checkValidSignatureAndMethod'))
         ).should.equal(true);
       });
 
@@ -166,12 +166,12 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
 
       it('does not validate valid signature with correct method for anyone', async function () {
         (await this.sigBouncer.checkValidSignatureAndMethod(anyone,
-          this.signFor(authorizedUser, 'checkValidSignatureAndMethod'))
+          await this.signFor(authorizedUser, 'checkValidSignatureAndMethod'))
         ).should.equal(false);
       });
 
       it('does not validate valid non-method signature with correct method for valid user', async function () {
-        (await this.sigBouncer.checkValidSignatureAndMethod(authorizedUser, this.signFor(authorizedUser))
+        (await this.sigBouncer.checkValidSignatureAndMethod(authorizedUser, await this.signFor(authorizedUser))
         ).should.equal(false);
       });
     });
@@ -179,7 +179,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
     context('method and data signature', function () {
       it('validates valid signature with correct method and data for valid user', async function () {
         (await this.sigBouncer.checkValidSignatureAndData(authorizedUser, BYTES_VALUE, UINT_VALUE,
-          this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
+          await this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
         ).should.equal(true);
       });
 
@@ -191,21 +191,21 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
       it('does not validate valid signature with correct method and incorrect data for valid user',
         async function () {
           (await this.sigBouncer.checkValidSignatureAndData(authorizedUser, BYTES_VALUE, UINT_VALUE + 10,
-            this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
+            await this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
           ).should.equal(false);
         }
       );
 
       it('does not validate valid signature with correct method and data for anyone', async function () {
         (await this.sigBouncer.checkValidSignatureAndData(anyone, BYTES_VALUE, UINT_VALUE,
-          this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
+          await this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
         ).should.equal(false);
       });
 
       it('does not validate valid non-method-data signature with correct method and data for valid user',
         async function () {
           (await this.sigBouncer.checkValidSignatureAndData(authorizedUser, BYTES_VALUE, UINT_VALUE,
-            this.signFor(authorizedUser, 'checkValidSignatureAndData'))
+            await this.signFor(authorizedUser, 'checkValidSignatureAndData'))
           ).should.equal(false);
         }
       );

+ 31 - 33
test/drafts/SignedSafeMath.test.js

@@ -1,10 +1,8 @@
-const shouldFail = require('../helpers/shouldFail');
-const { MIN_INT256, MAX_INT256 } = require('../helpers/constants');
+const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
+const { MAX_INT256, MIN_INT256 } = constants;
 
 const SignedSafeMathMock = artifacts.require('SignedSafeMathMock');
 
-const { BigNumber } = require('../helpers/setup');
-
 contract('SignedSafeMath', function () {
   beforeEach(async function () {
     this.safeMath = await SignedSafeMathMock.new();
@@ -12,10 +10,10 @@ 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.add(a, b)).should.be.bignumber.equal(a.add(b));
     });
 
     it('adds correctly if it does not overflow and the result is negative', async function () {
@@ -23,19 +21,19 @@ contract('SignedSafeMath', function () {
       const b = MIN_INT256;
 
       const result = await this.safeMath.add(a, b);
-      result.should.be.bignumber.equal(a.plus(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 b = new BN('1');
 
       await shouldFail.reverting(this.safeMath.add(a, b));
     });
 
     it('reverts on negative addition overflow', async function () {
       const a = MIN_INT256;
-      const b = new BigNumber(-1);
+      const b = new BN('-1');
 
       await shouldFail.reverting(this.safeMath.add(a, b));
     });
@@ -43,31 +41,31 @@ contract('SignedSafeMath', function () {
 
   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));
+      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));
+      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 b = new BN('-1');
 
       await shouldFail.reverting(this.safeMath.sub(a, b));
     });
 
     it('reverts on negative subtraction overflow', async function () {
       const a = MIN_INT256;
-      const b = new BigNumber(1);
+      const b = new BN('1');
 
       await shouldFail.reverting(this.safeMath.sub(a, b));
     });
@@ -75,37 +73,37 @@ contract('SignedSafeMath', function () {
 
   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));
+      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));
+      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 b = new BN('2');
 
       await shouldFail.reverting(this.safeMath.mul(a, b));
     });
 
     it('reverts when minimum integer is multiplied by -1', async function () {
       const a = MIN_INT256;
-      const b = new BigNumber(-1);
+      const b = new BN('-1');
 
       await shouldFail.reverting(this.safeMath.mul(a, b));
     });
 
     it('reverts when -1 is multiplied by minimum integer', async function () {
-      const a = new BigNumber(-1);
+      const a = new BN('-1');
       const b = MIN_INT256;
 
       await shouldFail.reverting(this.safeMath.mul(a, b));
@@ -114,23 +112,23 @@ contract('SignedSafeMath', 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');
 
       const result = await this.safeMath.div(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));
     });
 
     it('reverts on overflow, negative second', async function () {
-      const a = new BigNumber(MIN_INT256);
-      const b = new BigNumber(-1);
+      const a = new BN(MIN_INT256);
+      const b = new BN('-1');
 
       await shouldFail.reverting(this.safeMath.div(a, b));
     });

+ 19 - 25
test/drafts/TokenVesting.test.js

@@ -1,20 +1,15 @@
-const shouldFail = require('../helpers/shouldFail');
-const expectEvent = require('../helpers/expectEvent');
-const time = require('../helpers/time');
-const { ethGetBlock } = require('../helpers/web3');
-const { ZERO_ADDRESS } = require('../helpers/constants');
-
-const { BigNumber } = require('../helpers/setup');
+const { BN, constants, expectEvent, shouldFail, time } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 const ERC20Mintable = artifacts.require('ERC20Mintable');
 const TokenVesting = artifacts.require('TokenVesting');
 
 contract('TokenVesting', function ([_, owner, beneficiary]) {
-  const amount = new BigNumber(1000);
+  const amount = new BN('1000');
 
   beforeEach(async function () {
     // +1 minute so it starts after contract instantiation
-    this.start = (await time.latest()) + time.duration.minutes(1);
+    this.start = (await time.latest()).add(time.duration.minutes(1));
     this.cliffDuration = time.duration.years(1);
     this.duration = time.duration.years(2);
   });
@@ -23,7 +18,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
     const cliffDuration = this.duration;
     const duration = this.cliffDuration;
 
-    cliffDuration.should.be.gt(duration);
+    cliffDuration.should.be.bignumber.that.is.at.least(duration);
 
     await shouldFail.reverting(
       TokenVesting.new(beneficiary, this.start, cliffDuration, duration, true, { from: owner })
@@ -46,7 +41,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
   it('reverts if the end time is in the past', async function () {
     const now = await time.latest();
 
-    this.start = now - this.duration - time.duration.minutes(1);
+    this.start = now.sub(this.duration).sub(time.duration.minutes(1));
     await shouldFail.reverting(
       TokenVesting.new(beneficiary, this.start, this.cliffDuration, this.duration, true, { from: owner })
     );
@@ -63,7 +58,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
 
     it('can get state', async function () {
       (await this.vesting.beneficiary()).should.be.equal(beneficiary);
-      (await this.vesting.cliff()).should.be.bignumber.equal(this.start + this.cliffDuration);
+      (await this.vesting.cliff()).should.be.bignumber.equal(this.start.add(this.cliffDuration));
       (await this.vesting.start()).should.be.bignumber.equal(this.start);
       (await this.vesting.duration()).should.be.bignumber.equal(this.duration);
       (await this.vesting.revocable()).should.be.equal(true);
@@ -74,7 +69,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
     });
 
     it('can be released after cliff', async function () {
-      await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(1));
+      await time.increaseTo(this.start.add(this.cliffDuration).add(time.duration.weeks(1)));
       const { logs } = await this.vesting.release(this.token.address);
       expectEvent.inLogs(logs, 'TokensReleased', {
         token: this.token.address,
@@ -83,34 +78,33 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
     });
 
     it('should release proper amount after cliff', async function () {
-      await time.increaseTo(this.start + this.cliffDuration);
+      await time.increaseTo(this.start.add(this.cliffDuration));
 
-      const { receipt } = await this.vesting.release(this.token.address);
-      const block = await ethGetBlock(receipt.blockNumber);
-      const releaseTime = block.timestamp;
+      await this.vesting.release(this.token.address);
+      const releaseTime = await time.latest();
 
-      const releasedAmount = amount.mul(releaseTime - this.start).div(this.duration).floor();
+      const releasedAmount = amount.mul(releaseTime.sub(this.start)).div(this.duration);
       (await this.token.balanceOf(beneficiary)).should.bignumber.equal(releasedAmount);
       (await this.vesting.released(this.token.address)).should.bignumber.equal(releasedAmount);
     });
 
     it('should linearly release tokens during vesting period', async function () {
-      const vestingPeriod = this.duration - this.cliffDuration;
+      const vestingPeriod = this.duration.sub(this.cliffDuration);
       const checkpoints = 4;
 
       for (let i = 1; i <= checkpoints; i++) {
-        const now = this.start + this.cliffDuration + i * (vestingPeriod / checkpoints);
+        const now = this.start.add(this.cliffDuration).add((vestingPeriod.muln(i).divn(checkpoints)));
         await time.increaseTo(now);
 
         await this.vesting.release(this.token.address);
-        const expectedVesting = amount.mul(now - this.start).div(this.duration).floor();
+        const expectedVesting = amount.mul(now.sub(this.start)).div(this.duration);
         (await this.token.balanceOf(beneficiary)).should.bignumber.equal(expectedVesting);
         (await this.vesting.released(this.token.address)).should.bignumber.equal(expectedVesting);
       }
     });
 
     it('should have released all after end', async function () {
-      await time.increaseTo(this.start + this.duration);
+      await time.increaseTo(this.start.add(this.duration));
       await this.vesting.release(this.token.address);
       (await this.token.balanceOf(beneficiary)).should.bignumber.equal(amount);
       (await this.vesting.released(this.token.address)).should.bignumber.equal(amount);
@@ -131,7 +125,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
     });
 
     it('should return the non-vested tokens when revoked by owner', async function () {
-      await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
+      await time.increaseTo(this.start.add(this.cliffDuration).add(time.duration.weeks(12)));
 
       const vested = vestedAmount(amount, await time.latest(), this.start, this.cliffDuration, this.duration);
 
@@ -141,7 +135,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
     });
 
     it('should keep the vested tokens when revoked by owner', async function () {
-      await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
+      await time.increaseTo(this.start.add(this.cliffDuration).add(time.duration.weeks(12)));
 
       const vestedPre = vestedAmount(amount, await time.latest(), this.start, this.cliffDuration, this.duration);
 
@@ -158,7 +152,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
     });
 
     function vestedAmount (total, now, start, cliffDuration, duration) {
-      return (now < start + cliffDuration) ? 0 : Math.round(total * (now - start) / duration);
+      return (now.lt(start.add(cliffDuration))) ? new BN(0) : total.mul((now.sub(start))).div(duration);
     }
   });
 });

+ 17 - 22
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 () {
@@ -77,26 +72,26 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
     await time.increaseTo(this.openingTime);
     await this.crowdsale.send(GOAL);
 
-    (await balanceDifference(wallet, async () => {
+    (await balance.difference(wallet, async () => {
       await time.increaseTo(this.afterClosingTime);
       await this.crowdsale.finalize({ from: owner });
     })).should.be.bignumber.equal(GOAL);
   });
 
   it('should allow refunds if the goal is not reached', async function () {
-    (await balanceDifference(investor, async () => {
+    (await balance.difference(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(

+ 4 - 5
test/examples/SimpleToken.test.js

@@ -1,8 +1,7 @@
-const expectEvent = require('../helpers/expectEvent');
-const { ZERO_ADDRESS } = require('../helpers/constants');
-const SimpleToken = artifacts.require('SimpleToken');
+const { constants, expectEvent } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
-require('../helpers/setup');
+const SimpleToken = artifacts.require('SimpleToken');
 
 contract('SimpleToken', function ([_, creator]) {
   beforeEach(async function () {
@@ -18,7 +17,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 () {

+ 0 - 12
test/helpers/balanceDifference.js

@@ -1,12 +0,0 @@
-const { ethGetBalance } = require('./web3');
-
-async function balanceDifference (account, promiseFunc) {
-  const balanceBefore = await ethGetBalance(account);
-  await promiseFunc();
-  const balanceAfter = await ethGetBalance(account);
-  return balanceAfter.minus(balanceBefore);
-}
-
-module.exports = {
-  balanceDifference,
-};

+ 0 - 8
test/helpers/constants.js

@@ -1,8 +0,0 @@
-const BigNumber = web3.BigNumber;
-
-module.exports = {
-  ZERO_ADDRESS: '0x0000000000000000000000000000000000000000',
-  MAX_UINT256: new BigNumber(2).pow(256).minus(1),
-  MAX_INT256: new BigNumber(2).pow(255).minus(1),
-  MIN_INT256: new BigNumber(2).pow(255).times(-1),
-};

+ 0 - 7
test/helpers/ether.js

@@ -1,7 +0,0 @@
-function ether (n) {
-  return new web3.BigNumber(web3.toWei(n, 'ether'));
-}
-
-module.exports = {
-  ether,
-};

+ 0 - 57
test/helpers/expectEvent.js

@@ -1,57 +0,0 @@
-const { should, BigNumber } = require('./setup');
-
-const SolidityEvent = require('web3/lib/web3/event.js');
-const { ethGetTransactionReceipt } = require('./web3');
-
-function inLogs (logs, eventName, eventArgs = {}) {
-  const event = logs.find(function (e) {
-    if (e.event === eventName) {
-      for (const [k, v] of Object.entries(eventArgs)) {
-        contains(e.args, k, v);
-      }
-      return true;
-    }
-  });
-  should.exist(event);
-  return event;
-}
-
-async function inConstruction (contract, eventName, eventArgs = {}) {
-  return inTransaction(contract.transactionHash, contract.constructor, eventName, eventArgs);
-}
-
-async function inTransaction (txHash, emitter, eventName, eventArgs = {}) {
-  const receipt = await ethGetTransactionReceipt(txHash);
-  const logs = decodeLogs(receipt.logs, emitter.events);
-
-  return inLogs(logs, eventName, eventArgs);
-}
-
-function contains (args, key, value) {
-  if (isBigNumber(args[key])) {
-    args[key].should.be.bignumber.equal(value);
-  } else {
-    args[key].should.be.equal(value);
-  }
-}
-
-function isBigNumber (object) {
-  return object.isBigNumber ||
-    object instanceof BigNumber ||
-    (object.constructor && object.constructor.name === 'BigNumber');
-}
-
-function decodeLogs (logs, events) {
-  return Array.prototype.concat(...logs.map(log =>
-    log.topics.filter(topic => topic in events).map(topic => {
-      const event = new SolidityEvent(null, events[topic], 0);
-      return event.decode(log);
-    })
-  ));
-}
-
-module.exports = {
-  inLogs,
-  inConstruction,
-  inTransaction,
-};

+ 0 - 25
test/helpers/makeInterfaceId.js

@@ -1,25 +0,0 @@
-const { soliditySha3 } = require('web3-utils');
-
-const INTERFACE_ID_LENGTH = 4;
-
-function makeInterfaceId (interfaces = []) {
-  const interfaceIdBuffer = interfaces
-    .map(methodSignature => soliditySha3(methodSignature)) // keccak256
-    .map(h =>
-      Buffer
-        .from(h.substring(2), 'hex')
-        .slice(0, 4) // bytes4()
-    )
-    .reduce((memo, bytes) => {
-      for (let i = 0; i < INTERFACE_ID_LENGTH; i++) {
-        memo[i] = memo[i] ^ bytes[i]; // xor
-      }
-      return memo;
-    }, Buffer.alloc(INTERFACE_ID_LENGTH));
-
-  return `0x${interfaceIdBuffer.toString('hex')}`;
-}
-
-module.exports = {
-  makeInterfaceId,
-};

+ 0 - 26
test/helpers/send.js

@@ -1,26 +0,0 @@
-const ethjsABI = require('ethjs-abi');
-const { ethSendTransaction } = require('./web3');
-
-function findMethod (abi, name, args) {
-  for (let i = 0; i < abi.length; i++) {
-    const methodArgs = abi[i].inputs.map(input => input.type).join(',');
-    if ((abi[i].name === name) && (methodArgs === args)) {
-      return abi[i];
-    }
-  }
-}
-
-async function transaction (target, name, argsTypes, argsValues, opts) {
-  const abiMethod = findMethod(target.abi, name, argsTypes);
-  const encodedData = ethjsABI.encodeMethod(abiMethod, argsValues);
-  return target.sendTransaction(Object.assign({ data: encodedData }, opts));
-}
-
-function ether (from, to, value) {
-  return ethSendTransaction({ from, to, value, gasPrice: 0 });
-}
-
-module.exports = {
-  ether,
-  transaction,
-};

+ 0 - 9
test/helpers/setup.js

@@ -1,9 +0,0 @@
-const chai = require('chai');
-
-const BigNumber = web3.BigNumber;
-const should = chai.use(require('chai-bignumber')(BigNumber)).should();
-
-module.exports = {
-  BigNumber,
-  should,
-};

+ 0 - 36
test/helpers/shouldFail.js

@@ -1,36 +0,0 @@
-const { should } = require('./setup');
-
-async function shouldFailWithMessage (promise, message) {
-  try {
-    await promise;
-  } catch (error) {
-    if (message) {
-      error.message.should.include(message, `Wrong failure type, expected '${message}'`);
-    }
-    return;
-  }
-
-  should.fail('Expected failure not received');
-}
-
-async function reverting (promise) {
-  await shouldFailWithMessage(promise, 'revert');
-}
-
-async function throwing (promise) {
-  await shouldFailWithMessage(promise, 'invalid opcode');
-}
-
-async function outOfGas (promise) {
-  await shouldFailWithMessage(promise, 'out of gas');
-}
-
-async function shouldFail (promise) {
-  await shouldFailWithMessage(promise);
-}
-
-shouldFail.reverting = reverting;
-shouldFail.throwing = throwing;
-shouldFail.outOfGas = outOfGas;
-
-module.exports = shouldFail;

+ 7 - 27
test/helpers/sign.js

@@ -1,38 +1,22 @@
-const { sha3, soliditySha3 } = require('web3-utils');
-
 const REAL_SIGNATURE_SIZE = 2 * 65; // 65 bytes in hexadecimal string legnth
 const PADDED_SIGNATURE_SIZE = 2 * 96; // 96 bytes in hexadecimal string length
 
-const DUMMY_SIGNATURE = `0x${web3.padLeft('', REAL_SIGNATURE_SIZE)}`;
+const DUMMY_SIGNATURE = `0x${web3.utils.padLeft('', REAL_SIGNATURE_SIZE)}`;
 
-// messageHex = '0xdeadbeef'
 function toEthSignedMessageHash (messageHex) {
   const messageBuffer = Buffer.from(messageHex.substring(2), 'hex');
   const prefix = Buffer.from(`\u0019Ethereum Signed Message:\n${messageBuffer.length}`);
-  return sha3(Buffer.concat([prefix, messageBuffer]));
+  return web3.utils.sha3(Buffer.concat([prefix, messageBuffer]));
 }
 
 // signs message in node (ganache auto-applies "Ethereum Signed Message" prefix)
-// messageHex = '0xdeadbeef'
 const signMessage = (signer, messageHex = '0x') => {
-  return web3.eth.sign(signer, messageHex); // actually personal_sign
-};
-
-// @TODO - remove this when we migrate to web3-1.0.0
-const transformToFullName = function (json) {
-  if (json.name.indexOf('(') !== -1) {
-    return json.name;
-  }
-
-  const typeName = json.inputs.map(function (i) { return i.type; }).join();
-  return json.name + '(' + typeName + ')';
+  return web3.eth.sign(messageHex, signer);
 };
 
 /**
  * Create a signer between a contract and a signer for a voucher of method, args, and redeemer
  * Note that `method` is the web3 method, not the truffle-contract method
- * Well truffle is terrible, but luckily (?) so is web3 < 1.0, so we get to make our own method id
- *   fetcher because the method on the contract isn't actually the SolidityFunction object ಠ_ಠ
  * @param contract TruffleContract
  * @param signer address
  * @param redeemer address
@@ -49,21 +33,17 @@ const getSignFor = (contract, signer) => (redeemer, methodName, methodArgs = [])
   if (methodName) {
     if (methodArgs.length > 0) {
       parts.push(
-        contract.contract[methodName].getData(...methodArgs.concat([DUMMY_SIGNATURE])).slice(
-          0,
-          -1 * PADDED_SIGNATURE_SIZE
-        )
+        contract.contract.methods[methodName](...methodArgs.concat([DUMMY_SIGNATURE])).encodeABI()
+          .slice(0, -1 * PADDED_SIGNATURE_SIZE)
       );
     } else {
       const abi = contract.abi.find(abi => abi.name === methodName);
-      const name = transformToFullName(abi);
-      const signature = sha3(name).slice(0, 10);
-      parts.push(signature);
+      parts.push(abi.signature);
     }
   }
 
   // return the signature of the "Ethereum Signed Message" hash of the hash of `parts`
-  const messageHex = soliditySha3(...parts);
+  const messageHex = web3.utils.soliditySha3(...parts);
   return signMessage(signer, messageHex);
 };
 

+ 0 - 22
test/helpers/test/balanceDifference.test.js

@@ -1,22 +0,0 @@
-const { balanceDifference } = require('../balanceDifference');
-const send = require('../send');
-const { ether } = require('../ether');
-
-const BigNumber = web3.BigNumber;
-require('chai')
-  .use(require('chai-bignumber')(BigNumber))
-  .should();
-
-contract('balanceDifference', function ([sender, receiver]) {
-  it('returns balance increments', async function () {
-    (await balanceDifference(receiver, () =>
-      send.ether(sender, receiver, ether(1)))
-    ).should.be.bignumber.equal(ether(1));
-  });
-
-  it('returns balance decrements', async function () {
-    (await balanceDifference(sender, () =>
-      send.ether(sender, receiver, ether(1)))
-    ).should.be.bignumber.equal(ether(-1));
-  });
-});

+ 0 - 16
test/helpers/test/ether.test.js

@@ -1,16 +0,0 @@
-const { ether } = require('../ether');
-
-const BigNumber = web3.BigNumber;
-require('chai')
-  .use(require('chai-bignumber')(BigNumber))
-  .should();
-
-describe('ether', function () {
-  it('returns a BigNumber', function () {
-    ether(1, 'ether').should.be.bignumber.equal(new BigNumber(1000000000000000000));
-  });
-
-  it('works with negative amounts', function () {
-    ether(-1, 'ether').should.be.bignumber.equal(new BigNumber(-1000000000000000000));
-  });
-});

+ 0 - 375
test/helpers/test/expectEvent.test.js

@@ -1,375 +0,0 @@
-const expectEvent = require('../expectEvent');
-const shouldFail = require('../shouldFail');
-
-const EventEmitter = artifacts.require('EventEmitter');
-const IndirectEventEmitter = artifacts.require('IndirectEventEmitter');
-
-const { should, BigNumber } = require('../../helpers/setup');
-
-describe('expectEvent', function () {
-  beforeEach(async function () {
-    this.constructionValues = {
-      uint: 42,
-      boolean: true,
-      string: 'OpenZeppelin',
-    };
-
-    this.emitter = await EventEmitter.new(
-      this.constructionValues.uint,
-      this.constructionValues.boolean,
-      this.constructionValues.string
-    );
-  });
-
-  describe('inConstructor', function () {
-    context('short uint value', function () {
-      it('accepts emitted events with correct number', async function () {
-        await expectEvent.inConstruction(this.emitter, 'ShortUint',
-          { value: this.constructionValues.uint }
-        );
-      });
-
-      it('throws if an incorrect value is passed', async function () {
-        await shouldFail(expectEvent.inConstruction(this.emitter, 'ShortUint', { value: 23 }));
-      });
-    });
-
-    context('boolean value', function () {
-      it('accepts emitted events with correct value', async function () {
-        await expectEvent.inConstruction(this.emitter, 'Boolean', { value: this.constructionValues.boolean });
-      });
-
-      it('throws if an incorrect value is passed', async function () {
-        await shouldFail(expectEvent.inConstruction(this.emitter, 'Boolean',
-          { value: !this.constructionValues.boolean }
-        ));
-      });
-    });
-
-    context('string value', function () {
-      it('accepts emitted events with correct string', async function () {
-        await expectEvent.inConstruction(this.emitter, 'String', { value: this.constructionValues.string });
-      });
-
-      it('throws if an incorrect string is passed', async function () {
-        await shouldFail(expectEvent.inConstruction(this.emitter, 'String', { value: 'ClosedZeppelin' }));
-      });
-    });
-
-    it('throws if an unemitted event is requested', async function () {
-      await shouldFail(expectEvent.inConstruction(this.emitter, 'UnemittedEvent'));
-    });
-  });
-
-  describe('inLogs', function () {
-    describe('with no arguments', function () {
-      beforeEach(async function () {
-        ({ logs: this.logs } = await this.emitter.emitArgumentless());
-      });
-
-      it('accepts emitted events', function () {
-        expectEvent.inLogs(this.logs, 'Argumentless');
-      });
-
-      it('throws if an unemitted event is requested', function () {
-        should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent'));
-      });
-    });
-
-    describe('with single argument', function () {
-      context('short uint value', function () {
-        beforeEach(async function () {
-          this.value = 42;
-          ({ logs: this.logs } = await this.emitter.emitShortUint(this.value));
-        });
-
-        it('accepts emitted events with correct JavaScript number', function () {
-          expectEvent.inLogs(this.logs, 'ShortUint', { value: this.value });
-        });
-
-        it('accepts emitted events with correct BigNumber', function () {
-          expectEvent.inLogs(this.logs, 'ShortUint', { value: new BigNumber(this.value) });
-        });
-
-        it('throws if an unemitted event is requested', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value }));
-        });
-
-        it('throws if an incorrect value is passed', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'ShortUint', { value: 23 }));
-        });
-      });
-
-      context('short int value', function () {
-        beforeEach(async function () {
-          this.value = -42;
-          ({ logs: this.logs } = await this.emitter.emitShortInt(this.value));
-        });
-
-        it('accepts emitted events with correct JavaScript number', function () {
-          expectEvent.inLogs(this.logs, 'ShortInt', { value: this.value });
-        });
-
-        it('accepts emitted events with correct BigNumber', function () {
-          expectEvent.inLogs(this.logs, 'ShortInt', { value: new BigNumber(this.value) });
-        });
-
-        it('throws if an unemitted event is requested', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value }));
-        });
-
-        it('throws if an incorrect value is passed', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'ShortInt', { value: -23 }));
-        });
-      });
-
-      context('long uint value', function () {
-        beforeEach(async function () {
-          this.bigNumValue = new BigNumber('123456789012345678901234567890');
-          ({ logs: this.logs } = await this.emitter.emitLongUint(this.bigNumValue));
-        });
-
-        it('accepts emitted events with correct BigNumber', function () {
-          expectEvent.inLogs(this.logs, 'LongUint', { value: this.bigNumValue });
-        });
-
-        it('throws if an unemitted event is requested', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.bigNumValue }));
-        });
-
-        it('throws if an incorrect value is passed', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'LongUint', { value: 2300 }));
-        });
-      });
-
-      context('long int value', function () {
-        beforeEach(async function () {
-          this.bigNumValue = new BigNumber('-123456789012345678901234567890');
-          ({ logs: this.logs } = await this.emitter.emitLongInt(this.bigNumValue));
-        });
-
-        it('accepts emitted events with correct BigNumber', function () {
-          expectEvent.inLogs(this.logs, 'LongInt', { value: this.bigNumValue });
-        });
-
-        it('throws if an unemitted event is requested', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.bigNumValue }));
-        });
-
-        it('throws if an incorrect value is passed', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'LongInt', { value: -2300 }));
-        });
-      });
-
-      context('address value', function () {
-        beforeEach(async function () {
-          this.value = '0x811412068e9fbf25dc300a29e5e316f7122b282c';
-          ({ logs: this.logs } = await this.emitter.emitAddress(this.value));
-        });
-
-        it('accepts emitted events with correct address', function () {
-          expectEvent.inLogs(this.logs, 'Address', { value: this.value });
-        });
-
-        it('throws if an unemitted event is requested', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value }));
-        });
-
-        it('throws if an incorrect value is passed', function () {
-          should.Throw(() =>
-            expectEvent.inLogs(this.logs, 'Address', { value: '0x21d04e022e0b52b5d5bcf90b7f1aabf406be002d' })
-          );
-        });
-      });
-
-      context('boolean value', function () {
-        beforeEach(async function () {
-          this.value = true;
-          ({ logs: this.logs } = await this.emitter.emitBoolean(this.value));
-        });
-
-        it('accepts emitted events with correct address', function () {
-          expectEvent.inLogs(this.logs, 'Boolean', { value: this.value });
-        });
-
-        it('throws if an unemitted event is requested', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value }));
-        });
-
-        it('throws if an incorrect value is passed', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'Boolean', { value: false }));
-        });
-      });
-
-      context('string value', function () {
-        beforeEach(async function () {
-          this.value = 'OpenZeppelin';
-          ({ logs: this.logs } = await this.emitter.emitString(this.value));
-        });
-
-        it('accepts emitted events with correct string', function () {
-          expectEvent.inLogs(this.logs, 'String', { value: this.value });
-        });
-
-        it('throws if an unemitted event is requested', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value }));
-        });
-
-        it('throws if an incorrect value is passed', function () {
-          should.Throw(() => expectEvent.inLogs(this.logs, 'String', { value: 'ClosedZeppelin' }));
-        });
-      });
-    });
-
-    describe('with multiple arguments', function () {
-      beforeEach(async function () {
-        this.uintValue = new BigNumber('123456789012345678901234567890');
-        this.booleanValue = true;
-        this.stringValue = 'OpenZeppelin';
-        ({ logs: this.logs } =
-          await this.emitter.emitLongUintBooleanString(this.uintValue, this.booleanValue, this.stringValue));
-      });
-
-      it('accepts correct values', function () {
-        expectEvent.inLogs(this.logs, 'LongUintBooleanString', {
-          uintValue: this.uintValue, booleanValue: this.booleanValue, stringValue: this.stringValue,
-        });
-      });
-
-      it('throws with correct values assigned to wrong arguments', function () {
-        should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', {
-          uintValue: this.booleanValue, booleanValue: this.uintValue, stringValue: this.stringValue,
-        }));
-      });
-
-      it('throws when any of the values is incorrect', function () {
-        should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', {
-          uintValue: 23, booleanValue: this.booleanValue, stringValue: this.stringValue,
-        }));
-
-        should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', {
-          uintValue: this.uintValue, booleanValue: false, stringValue: this.stringValue,
-        }));
-
-        should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', {
-          uintValue: this.uintValue, booleanValue: this.booleanValue, stringValue: 'ClosedZeppelin',
-        }));
-      });
-    });
-
-    describe('with multiple events', function () {
-      beforeEach(async function () {
-        this.uintValue = 42;
-        this.booleanValue = true;
-        ({ logs: this.logs } = await this.emitter.emitLongUintAndBoolean(this.uintValue, this.booleanValue));
-      });
-
-      it('accepts all emitted events with correct values', function () {
-        expectEvent.inLogs(this.logs, 'LongUint', { value: this.uintValue });
-        expectEvent.inLogs(this.logs, 'Boolean', { value: this.booleanValue });
-      });
-
-      it('throws if an unemitted event is requested', function () {
-        should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.uintValue }));
-      });
-
-      it('throws if incorrect values are passed', function () {
-        should.Throw(() => expectEvent.inLogs(this.logs, 'LongUint', { value: 23 }));
-        should.Throw(() => expectEvent.inLogs(this.logs, 'Boolean', { value: false }));
-      });
-    });
-
-    describe('with events emitted by an indirectly called contract', function () {
-      beforeEach(async function () {
-        this.secondEmitter = await IndirectEventEmitter.new();
-
-        this.value = 'OpenZeppelin';
-        ({ logs: this.logs } = await this.emitter.emitStringAndEmitIndirectly(this.value, this.secondEmitter.address));
-      });
-
-      it('accepts events emitted by the directly called contract', function () {
-        expectEvent.inLogs(this.logs, 'String', { value: this.value });
-      });
-
-      it('throws when passing events emitted by the indirectly called contract', function () {
-        should.Throw(() => expectEvent.inLogs(this.logs, 'IndirectString', { value: this.value }));
-      });
-    });
-  });
-
-  describe('inTransaction', function () {
-    describe('when emitting from called contract and indirect calls', function () {
-      context('string value', function () {
-        beforeEach(async function () {
-          this.secondEmitter = await IndirectEventEmitter.new();
-
-          this.value = 'OpenZeppelin';
-          const receipt = await this.emitter.emitStringAndEmitIndirectly(this.value, this.secondEmitter.address);
-          this.txHash = receipt.tx;
-        });
-
-        context('with directly called contract', function () {
-          it('accepts emitted events with correct string', async function () {
-            await expectEvent.inTransaction(this.txHash, EventEmitter, 'String', { value: this.value });
-          });
-
-          it('throws if an unemitted event is requested', async function () {
-            await shouldFail(expectEvent.inTransaction(this.txHash, EventEmitter, 'UnemittedEvent',
-              { value: this.value }
-            ));
-          });
-
-          it('throws if an incorrect string is passed', async function () {
-            await shouldFail(expectEvent.inTransaction(this.txHash, EventEmitter, 'String',
-              { value: 'ClosedZeppelin' }
-            ));
-          });
-
-          it('throws if an event emitted from other contract is passed', async function () {
-            await shouldFail(expectEvent.inTransaction(this.txHash, EventEmitter, 'IndirectString',
-              { value: this.value }
-            ));
-          });
-
-          it('throws if an incorrect emitter is passed', async function () {
-            await shouldFail(expectEvent.inTransaction(this.txHash, IndirectEventEmitter, 'String',
-              { value: this.value }
-            ));
-          });
-        });
-
-        context('with indirectly called contract', function () {
-          it('accepts events emitted from other contracts', async function () {
-            await expectEvent.inTransaction(this.txHash, IndirectEventEmitter, 'IndirectString',
-              { value: this.value }
-            );
-          });
-
-          it('throws if an unemitted event is requested', async function () {
-            await shouldFail(expectEvent.inTransaction(this.txHash, IndirectEventEmitter, 'UnemittedEvent',
-              { value: this.value }
-            ));
-          });
-
-          it('throws if an incorrect string is passed', async function () {
-            await shouldFail(expectEvent.inTransaction(this.txHash, IndirectEventEmitter, 'IndirectString',
-              { value: 'ClosedZeppelin' }
-            ));
-          });
-
-          it('throws if an event emitted from other contract is passed', async function () {
-            await shouldFail(expectEvent.inTransaction(this.txHash, IndirectEventEmitter, 'String',
-              { value: this.value }
-            ));
-          });
-
-          it('throws if an incorrect emitter is passed', async function () {
-            await shouldFail(expectEvent.inTransaction(this.txHash, EventEmitter, 'IndirectString',
-              { value: this.value }
-            ));
-          });
-        });
-      });
-    });
-  });
-});

+ 0 - 20
test/helpers/test/makeInterfaceId.test.js

@@ -1,20 +0,0 @@
-const { makeInterfaceId } = require('../makeInterfaceId');
-
-const OwnableInterfaceId = artifacts.require('OwnableInterfaceId');
-
-require('chai')
-  .should();
-
-describe('makeInterfaceId', function () {
-  it('calculates the EIP165 interface id from function signatures', async function () {
-    const calculator = await OwnableInterfaceId.new();
-    const ownableId = await calculator.getInterfaceId();
-
-    makeInterfaceId([
-      'owner()',
-      'isOwner()',
-      'renounceOwnership()',
-      'transferOwnership(address)',
-    ]).should.equal(ownableId);
-  });
-});

+ 0 - 70
test/helpers/test/send.test.js

@@ -1,70 +0,0 @@
-const send = require('../send');
-const shouldFail = require('../shouldFail');
-const expectEvent = require('../expectEvent');
-const { ether } = require('../ether');
-const { ethGetBalance } = require('../web3');
-
-const Acknowledger = artifacts.require('Acknowledger');
-
-const BigNumber = web3.BigNumber;
-require('chai')
-  .use(require('chai-bignumber')(BigNumber))
-  .should();
-
-contract('send', function ([sender, receiver]) {
-  describe('ether', function () {
-    it('sends ether with no gas cost', async function () {
-      const value = ether(1);
-
-      const initialSenderBalance = await ethGetBalance(sender);
-      const initialReceiverBalance = await ethGetBalance(receiver);
-
-      await send.ether(sender, receiver, value);
-
-      const finalSenderBalance = await ethGetBalance(sender);
-      const finalReceiverBalance = await ethGetBalance(receiver);
-
-      finalSenderBalance.sub(initialSenderBalance).should.be.bignumber.equal(-value);
-      finalReceiverBalance.sub(initialReceiverBalance).should.be.bignumber.equal(value);
-    });
-
-    it('throws if the sender balance is insufficient', async function () {
-      const value = (await ethGetBalance(sender)).plus(1);
-
-      await shouldFail(send.ether(sender, receiver, value));
-    });
-  });
-
-  describe('transaction', function () {
-    beforeEach(async function () {
-      this.acknowledger = await Acknowledger.new();
-    });
-
-    it('calls a function from its signature ', async function () {
-      const { logs } = await send.transaction(this.acknowledger, 'foo', 'uint256', [3]);
-      expectEvent.inLogs(logs, 'AcknowledgeFoo', { a: 3 });
-    });
-
-    it('calls overloaded functions with less arguments', async function () {
-      const { logs } = await send.transaction(this.acknowledger, 'bar', 'uint256', [3]);
-      expectEvent.inLogs(logs, 'AcknowledgeBarSingle', { a: 3 });
-    });
-
-    it('calls overloaded functions with more arguments', async function () {
-      const { logs } = await send.transaction(this.acknowledger, 'bar', 'uint256,uint256', [3, 5]);
-      expectEvent.inLogs(logs, 'AcknowledgeBarDouble', { a: 3, b: 5 });
-    });
-
-    it('throws if the number of arguments does not match', async function () {
-      await shouldFail(send.transaction(this.acknowledger, 'foo', 'uint256, uint256', [3, 5]));
-    });
-
-    it('throws if the method does not exist', async function () {
-      await shouldFail(send.transaction(this.acknowledger, 'baz', 'uint256', [3]));
-    });
-
-    it('throws if there is a mismatch in the number of types and values', async function () {
-      await shouldFail(send.transaction(this.acknowledger, 'foo', 'uint256', [3, 3]));
-    });
-  });
-});

+ 0 - 95
test/helpers/test/shouldFail.test.js

@@ -1,95 +0,0 @@
-const shouldFail = require('../shouldFail');
-
-const BigNumber = web3.BigNumber;
-const should = require('chai')
-  .use(require('chai-bignumber')(BigNumber))
-  .should();
-
-const Failer = artifacts.require('Failer');
-
-async function assertFailure (promise) {
-  try {
-    await promise;
-  } catch (error) {
-    return;
-  }
-  should.fail();
-}
-
-describe('shouldFail', function () {
-  beforeEach(async function () {
-    this.failer = await Failer.new();
-  });
-
-  describe('shouldFail', function () {
-    it('rejects if no failure occurs', async function () {
-      await assertFailure(shouldFail(this.failer.dontFail()));
-    });
-
-    it('accepts a revert', async function () {
-      await shouldFail(this.failer.failWithRevert());
-    });
-
-    it('accepts a throw', async function () {
-      await shouldFail(this.failer.failWithThrow());
-    });
-
-    it('accepts an out of gas', async function () {
-      await shouldFail(this.failer.failWithOutOfGas({ gas: 2000000 }));
-    });
-  });
-
-  describe('reverting', function () {
-    it('rejects if no failure occurs', async function () {
-      await assertFailure(shouldFail.reverting(this.failer.dontFail()));
-    });
-
-    it('accepts a revert', async function () {
-      await shouldFail.reverting(this.failer.failWithRevert());
-    });
-
-    it('rejects a throw', async function () {
-      await assertFailure(shouldFail.reverting(this.failer.failWithThrow()));
-    });
-
-    it('rejects an outOfGas', async function () {
-      await assertFailure(shouldFail.reverting(this.failer.failWithOutOfGas({ gas: 2000000 })));
-    });
-  });
-
-  describe('throwing', function () {
-    it('rejects if no failure occurs', async function () {
-      await assertFailure(shouldFail.throwing(this.failer.dontFail()));
-    });
-
-    it('accepts a throw', async function () {
-      await shouldFail.throwing(this.failer.failWithThrow());
-    });
-
-    it('rejects a throw', async function () {
-      await assertFailure(shouldFail.throwing(this.failer.failWithRevert()));
-    });
-
-    it('rejects an outOfGas', async function () {
-      await assertFailure(shouldFail.throwing(this.failer.failWithOutOfGas({ gas: 2000000 })));
-    });
-  });
-
-  describe('outOfGas', function () {
-    it('rejects if no failure occurs', async function () {
-      await assertFailure(shouldFail.outOfGas(this.failer.dontFail()));
-    });
-
-    it('accepts an out of gas', async function () {
-      await shouldFail.outOfGas(this.failer.failWithOutOfGas({ gas: 2000000 }));
-    });
-
-    it('rejects a revert', async function () {
-      await assertFailure(shouldFail.outOfGas(this.failer.failWithRevert()));
-    });
-
-    it('rejects a throw', async function () {
-      await assertFailure(shouldFail.outOfGas(this.failer.failWithThrow()));
-    });
-  });
-});

+ 0 - 77
test/helpers/test/time.test.js

@@ -1,77 +0,0 @@
-const time = require('../time');
-const shouldFail = require('../shouldFail');
-
-const BigNumber = web3.BigNumber;
-require('chai')
-  .use(require('chai-bignumber')(BigNumber))
-  .should();
-
-describe('time', function () {
-  const TOLERANCE_SECONDS = 1;
-
-  describe('duration', function () {
-    it('converts seconds to seconds', function () {
-      time.duration.seconds(1).should.equal(1);
-    });
-
-    it('converts minutes to seconds', function () {
-      time.duration.minutes(1).should.equal(60);
-    });
-
-    it('converts hours to seconds', function () {
-      time.duration.hours(1).should.equal(60 * 60);
-    });
-
-    it('converts days to seconds', function () {
-      time.duration.days(1).should.equal(60 * 60 * 24);
-    });
-
-    it('converts weeks to seconds', function () {
-      time.duration.weeks(1).should.equal(60 * 60 * 24 * 7);
-    });
-
-    it('converts years to seconds', function () {
-      time.duration.years(1).should.equal(60 * 60 * 24 * 365);
-    });
-  });
-
-  describe('advanceBlock', function () {
-    it('increases the block number by one', async function () {
-      const startingBlock = web3.eth.blockNumber;
-      await time.advanceBlock();
-      web3.eth.blockNumber.should.be.bignumber.equal(startingBlock + 1);
-    });
-  });
-
-  context('with starting time', function () {
-    beforeEach(async function () {
-      await time.advanceBlock();
-      this.start = await time.latest();
-    });
-
-    describe('increase', function () {
-      it('increases time by a duration', async function () {
-        await time.increase(time.duration.hours(1));
-
-        const end = this.start + time.duration.hours(1);
-        (await time.latest()).should.be.closeTo(end, TOLERANCE_SECONDS);
-      });
-
-      it('throws with negative durations', async function () {
-        await shouldFail(time.increase(-1));
-      });
-    });
-
-    describe('increaseTo', function () {
-      it('increases time to a time in the future', async function () {
-        const end = this.start + time.duration.hours(1);
-        await time.increaseTo(end);
-        (await time.latest()).should.be.closeTo(end, TOLERANCE_SECONDS);
-      });
-
-      it('throws with a time in the past', async function () {
-        await shouldFail(time.increaseTo(this.start - 30));
-      });
-    });
-  });
-});

+ 0 - 60
test/helpers/time.js

@@ -1,60 +0,0 @@
-const { ethGetBlock } = require('./web3');
-const pify = require('pify');
-
-function advanceBlock () {
-  return pify(web3.currentProvider.sendAsync)({
-    jsonrpc: '2.0',
-    method: 'evm_mine',
-  });
-}
-
-// Returns the time of the last mined block in seconds
-async function latest () {
-  const block = await ethGetBlock('latest');
-  return block.timestamp;
-}
-
-// Increases ganache time by the passed duration in seconds
-async function increase (duration) {
-  if (duration < 0) throw Error(`Cannot increase time by a negative amount (${duration})`);
-
-  await pify(web3.currentProvider.sendAsync)({
-    jsonrpc: '2.0',
-    method: 'evm_increaseTime',
-    params: [duration],
-  });
-
-  await advanceBlock();
-}
-
-/**
- * Beware that due to the need of calling two separate ganache methods and rpc calls overhead
- * it's hard to increase time precisely to a target point so design your test to tolerate
- * small fluctuations from time to time.
- *
- * @param target time in seconds
- */
-async function increaseTo (target) {
-  const now = (await latest());
-
-  if (target < now) throw Error(`Cannot increase current time (${now}) to a moment in the past (${target})`);
-  const diff = target - now;
-  return increase(diff);
-}
-
-const duration = {
-  seconds: function (val) { return val; },
-  minutes: function (val) { return val * this.seconds(60); },
-  hours: function (val) { return val * this.minutes(60); },
-  days: function (val) { return val * this.hours(24); },
-  weeks: function (val) { return val * this.days(7); },
-  years: function (val) { return val * this.days(365); },
-};
-
-module.exports = {
-  advanceBlock,
-  latest,
-  increase,
-  increaseTo,
-  duration,
-};

+ 0 - 10
test/helpers/web3.js

@@ -1,10 +0,0 @@
-const pify = require('pify');
-
-const ethAsync = pify(web3.eth);
-
-module.exports = {
-  ethGetBalance: ethAsync.getBalance,
-  ethGetBlock: ethAsync.getBlock,
-  ethGetTransactionReceipt: ethAsync.getTransactionReceipt,
-  ethSendTransaction: ethAsync.sendTransaction,
-};

+ 2 - 7
test/introspection/ERC165.test.js

@@ -1,20 +1,15 @@
+const { 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([

+ 2 - 2
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();

+ 1 - 1
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([

+ 6 - 9
test/lifecycle/Pausable.test.js

@@ -1,10 +1,7 @@
-const shouldFail = require('../helpers/shouldFail');
-const expectEvent = require('../helpers/expectEvent');
-
-const PausableMock = artifacts.require('PausableMock');
+const { expectEvent, shouldFail } = require('openzeppelin-test-helpers');
 const { shouldBehaveLikePublicRole } = require('../access/roles/PublicRole.behavior');
 
-require('../helpers/setup');
+const PausableMock = artifacts.require('PausableMock');
 
 contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts]) {
   beforeEach(async function () {
@@ -26,10 +23,10 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts
     });
 
     it('can perform normal process in non-pause', async function () {
-      (await this.pausable.count()).should.be.bignumber.equal(0);
+      (await this.pausable.count()).should.be.bignumber.equal('0');
 
       await this.pausable.normalProcess({ from: anyone });
-      (await this.pausable.count()).should.be.bignumber.equal(1);
+      (await this.pausable.count()).should.be.bignumber.equal('1');
     });
 
     it('cannot take drastic measure in non-pause', async function () {
@@ -89,9 +86,9 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts
             });
 
             it('should resume allowing normal process', async function () {
-              (await this.pausable.count()).should.be.bignumber.equal(0);
+              (await this.pausable.count()).should.be.bignumber.equal('0');
               await this.pausable.normalProcess({ from: anyone });
-              (await this.pausable.count()).should.be.bignumber.equal(1);
+              (await this.pausable.count()).should.be.bignumber.equal('1');
             });
 
             it('should prevent drastic measure', async function () {

+ 11 - 11
test/math/Math.test.js

@@ -1,10 +1,10 @@
-const MathMock = artifacts.require('MathMock');
+const { BN } = require('openzeppelin-test-helpers');
 
-const { BigNumber } = require('../helpers/setup');
+const MathMock = artifacts.require('MathMock');
 
 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));
     });
   });

+ 41 - 43
test/math/SafeMath.test.js

@@ -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));
     });

+ 3 - 5
test/ownership/Ownable.behavior.js

@@ -1,7 +1,5 @@
-const shouldFail = require('../helpers/shouldFail');
-const expectEvent = require('../helpers/expectEvent');
-const { ZERO_ADDRESS } = require('../helpers/constants');
-require('./../helpers/setup');
+const { constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 function shouldBehaveLikeOwnable (owner, [anyone]) {
   describe('as an ownable', function () {
@@ -23,7 +21,7 @@ function shouldBehaveLikeOwnable (owner, [anyone]) {
     });
 
     it('should guard ownership against stuck state', async function () {
-      await shouldFail.reverting(this.ownable.transferOwnership(null, { from: owner }));
+      await shouldFail.reverting(this.ownable.transferOwnership(ZERO_ADDRESS, { from: owner }));
     });
 
     it('loses owner after renouncement', async function () {

+ 1 - 0
test/ownership/Ownable.test.js

@@ -1,3 +1,4 @@
+require('openzeppelin-test-helpers');
 const { shouldBehaveLikeOwnable } = require('./Ownable.behavior');
 
 const Ownable = artifacts.require('OwnableMock');

+ 2 - 5
test/ownership/Secondary.test.js

@@ -1,11 +1,8 @@
-const shouldFail = require('../helpers/shouldFail');
-const expectEvent = require('../helpers/expectEvent');
-const { ZERO_ADDRESS } = require('../helpers/constants');
+const { constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 const SecondaryMock = artifacts.require('SecondaryMock');
 
-require('../helpers/setup');
-
 contract('Secondary', function ([_, primary, newPrimary, anyone]) {
   beforeEach(async function () {
     this.secondary = await SecondaryMock.new({ from: primary });

+ 23 - 28
test/payment/PaymentSplitter.test.js

@@ -1,16 +1,10 @@
-const { ethGetBalance } = require('../helpers/web3');
-const expectEvent = require('../helpers/expectEvent');
-const send = require('./../helpers/send');
-const { ether } = require('../helpers/ether');
-const { ZERO_ADDRESS } = require('./../helpers/constants');
+const { balance, constants, ether, expectEvent, send, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
-require('../helpers/setup');
-
-const shouldFail = require('../helpers/shouldFail');
 const PaymentSplitter = artifacts.require('PaymentSplitter');
 
 contract('PaymentSplitter', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) {
-  const amount = ether(1.0);
+  const amount = ether('1');
 
   it('rejects an empty set of payees', async function () {
     await shouldFail.reverting(PaymentSplitter.new([], []));
@@ -45,28 +39,28 @@ contract('PaymentSplitter', function ([_, owner, payee1, payee2, payee3, nonpaye
     });
 
     it('should have total shares', async function () {
-      (await this.contract.totalShares()).should.be.bignumber.equal(20 + 10 + 70);
+      (await this.contract.totalShares()).should.be.bignumber.equal('100');
     });
 
     it('should have payees', async function () {
       await Promise.all(this.payees.map(async (payee, index) => {
         (await this.contract.payee(index)).should.be.equal(payee);
-        (await this.contract.released(payee)).should.be.bignumber.equal(0);
+        (await this.contract.released(payee)).should.be.bignumber.equal('0');
       }));
     });
 
     it('should accept payments', async function () {
       await send.ether(owner, this.contract.address, amount);
 
-      (await ethGetBalance(this.contract.address)).should.be.bignumber.equal(amount);
+      (await balance.current(this.contract.address)).should.be.bignumber.equal(amount);
     });
 
     it('should store shares if address is payee', async function () {
-      (await this.contract.shares(payee1)).should.be.bignumber.not.equal(0);
+      (await this.contract.shares(payee1)).should.be.bignumber.not.equal('0');
     });
 
     it('should not store shares if address is not payee', async function () {
-      (await this.contract.shares(nonpayee1)).should.be.bignumber.equal(0);
+      (await this.contract.shares(nonpayee1)).should.be.bignumber.equal('0');
     });
 
     it('should throw if no funds to claim', async function () {
@@ -82,30 +76,31 @@ contract('PaymentSplitter', function ([_, owner, payee1, payee2, payee3, nonpaye
       await send.ether(payer1, this.contract.address, amount);
 
       // receive funds
-      const initBalance = await ethGetBalance(this.contract.address);
+      const initBalance = await balance.current(this.contract.address);
       initBalance.should.be.bignumber.equal(amount);
 
       // distribute to payees
-      const initAmount1 = await ethGetBalance(payee1);
-      const { logs: logs1 } = await this.contract.release(payee1);
-      const profit1 = (await ethGetBalance(payee1)).sub(initAmount1);
-      profit1.sub(web3.toWei(0.20, 'ether')).abs().should.be.bignumber.lt(1e16);
+
+      const initAmount1 = await balance.current(payee1);
+      const { logs: logs1 } = await this.contract.release(payee1, { gasPrice: 0 });
+      const profit1 = (await balance.current(payee1)).sub(initAmount1);
+      profit1.should.be.bignumber.equal(ether('0.20', 'ether'));
       expectEvent.inLogs(logs1, 'PaymentReleased', { to: payee1, amount: profit1 });
 
-      const initAmount2 = await ethGetBalance(payee2);
-      const { logs: logs2 } = await this.contract.release(payee2);
-      const profit2 = (await ethGetBalance(payee2)).sub(initAmount2);
-      profit2.sub(web3.toWei(0.10, 'ether')).abs().should.be.bignumber.lt(1e16);
+      const initAmount2 = await balance.current(payee2);
+      const { logs: logs2 } = await this.contract.release(payee2, { gasPrice: 0 });
+      const profit2 = (await balance.current(payee2)).sub(initAmount2);
+      profit2.should.be.bignumber.equal(ether('0.10', 'ether'));
       expectEvent.inLogs(logs2, 'PaymentReleased', { to: payee2, amount: profit2 });
 
-      const initAmount3 = await ethGetBalance(payee3);
-      const { logs: logs3 } = await this.contract.release(payee3);
-      const profit3 = (await ethGetBalance(payee3)).sub(initAmount3);
-      profit3.sub(web3.toWei(0.70, 'ether')).abs().should.be.bignumber.lt(1e16);
+      const initAmount3 = await balance.current(payee3);
+      const { logs: logs3 } = await this.contract.release(payee3, { gasPrice: 0 });
+      const profit3 = (await balance.current(payee3)).sub(initAmount3);
+      profit3.should.be.bignumber.equal(ether('0.70', 'ether'));
       expectEvent.inLogs(logs3, 'PaymentReleased', { to: payee3, amount: profit3 });
 
       // end balance should be zero
-      (await ethGetBalance(this.contract.address)).should.be.bignumber.equal(0);
+      (await balance.current(this.contract.address)).should.be.bignumber.equal('0');
 
       // check correct funds released accounting
       (await this.contract.totalReleased()).should.be.bignumber.equal(initBalance);

+ 8 - 11
test/payment/PullPayment.test.js

@@ -1,12 +1,9 @@
-const { balanceDifference } = require('../helpers/balanceDifference');
-const { ether } = require('../helpers/ether');
-
-require('../helpers/setup');
+const { balance, ether } = require('openzeppelin-test-helpers');
 
 const PullPaymentMock = artifacts.require('PullPaymentMock');
 
 contract('PullPayment', function ([_, payer, payee1, payee2]) {
-  const amount = ether(17.0);
+  const amount = ether('17');
 
   beforeEach(async function () {
     this.contract = await PullPaymentMock.new({ value: amount });
@@ -14,32 +11,32 @@ contract('PullPayment', function ([_, payer, payee1, payee2]) {
 
   it('can record an async payment correctly', async function () {
     await this.contract.callTransfer(payee1, 100, { from: payer });
-    (await this.contract.payments(payee1)).should.be.bignumber.equal(100);
+    (await this.contract.payments(payee1)).should.be.bignumber.equal('100');
   });
 
   it('can add multiple balances on one account', async function () {
     await this.contract.callTransfer(payee1, 200, { from: payer });
     await this.contract.callTransfer(payee1, 300, { from: payer });
-    (await this.contract.payments(payee1)).should.be.bignumber.equal(500);
+    (await this.contract.payments(payee1)).should.be.bignumber.equal('500');
   });
 
   it('can add balances on multiple accounts', async function () {
     await this.contract.callTransfer(payee1, 200, { from: payer });
     await this.contract.callTransfer(payee2, 300, { from: payer });
 
-    (await this.contract.payments(payee1)).should.be.bignumber.equal(200);
+    (await this.contract.payments(payee1)).should.be.bignumber.equal('200');
 
-    (await this.contract.payments(payee2)).should.be.bignumber.equal(300);
+    (await this.contract.payments(payee2)).should.be.bignumber.equal('300');
   });
 
   it('can withdraw payment', async function () {
-    (await balanceDifference(payee1, async () => {
+    (await balance.difference(payee1, async () => {
       await this.contract.callTransfer(payee1, amount, { from: payer });
       (await this.contract.payments(payee1)).should.be.bignumber.equal(amount);
 
       await this.contract.withdrawPayments(payee1);
     })).should.be.bignumber.equal(amount);
 
-    (await this.contract.payments(payee1)).should.be.bignumber.equal(0);
+    (await this.contract.payments(payee1)).should.be.bignumber.equal('0');
   });
 });

+ 2 - 6
test/payment/escrow/ConditionalEscrow.test.js

@@ -1,10 +1,6 @@
+const { ether, shouldFail } = require('openzeppelin-test-helpers');
 const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
 
-const shouldFail = require('../../helpers/shouldFail');
-const { ether } = require('../../helpers/ether');
-
-require('../../helpers/setup');
-
 const ConditionalEscrowMock = artifacts.require('ConditionalEscrowMock');
 
 contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
@@ -21,7 +17,7 @@ contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
   });
 
   context('when withdrawal is disallowed', function () {
-    const amount = ether(23.0);
+    const amount = ether('23');
 
     beforeEach(async function () {
       await this.escrow.setAllowed(payee, false);

+ 12 - 18
test/payment/escrow/Escrow.behavior.js

@@ -1,20 +1,14 @@
-const expectEvent = require('../../helpers/expectEvent');
-const shouldFail = require('../../helpers/shouldFail');
-const { ethGetBalance } = require('../../helpers/web3');
-const { balanceDifference } = require('../../helpers/balanceDifference');
-const { ether } = require('../../helpers/ether');
-
-require('../../helpers/setup');
+const { balance, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
 
 function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
-  const amount = ether(42.0);
+  const amount = ether('42');
 
   describe('as an escrow', function () {
     describe('deposits', function () {
       it('can accept a single deposit', async function () {
         await this.escrow.deposit(payee1, { from: primary, value: amount });
 
-        (await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(amount);
+        (await balance.current(this.escrow.address)).should.be.bignumber.equal(amount);
 
         (await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount);
       });
@@ -37,34 +31,34 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
 
       it('can add multiple deposits on a single account', async function () {
         await this.escrow.deposit(payee1, { from: primary, value: amount });
-        await this.escrow.deposit(payee1, { from: primary, value: amount * 2 });
+        await this.escrow.deposit(payee1, { from: primary, value: amount.muln(2) });
 
-        (await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(amount * 3);
+        (await balance.current(this.escrow.address)).should.be.bignumber.equal(amount.muln(3));
 
-        (await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount * 3);
+        (await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount.muln(3));
       });
 
       it('can track deposits to multiple accounts', async function () {
         await this.escrow.deposit(payee1, { from: primary, value: amount });
-        await this.escrow.deposit(payee2, { from: primary, value: amount * 2 });
+        await this.escrow.deposit(payee2, { from: primary, value: amount.muln(2) });
 
-        (await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(amount * 3);
+        (await balance.current(this.escrow.address)).should.be.bignumber.equal(amount.muln(3));
 
         (await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount);
 
-        (await this.escrow.depositsOf(payee2)).should.be.bignumber.equal(amount * 2);
+        (await this.escrow.depositsOf(payee2)).should.be.bignumber.equal(amount.muln(2));
       });
     });
 
     describe('withdrawals', async function () {
       it('can withdraw payments', async function () {
-        (await balanceDifference(payee1, async () => {
+        (await balance.difference(payee1, async () => {
           await this.escrow.deposit(payee1, { from: primary, value: amount });
           await this.escrow.withdraw(payee1, { from: primary });
         })).should.be.bignumber.equal(amount);
 
-        (await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(0);
-        (await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(0);
+        (await balance.current(this.escrow.address)).should.be.bignumber.equal('0');
+        (await this.escrow.depositsOf(payee1)).should.be.bignumber.equal('0');
       });
 
       it('can do an empty withdrawal', async function () {

+ 1 - 0
test/payment/escrow/Escrow.test.js

@@ -1,3 +1,4 @@
+require('openzeppelin-test-helpers');
 const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
 
 const Escrow = artifacts.require('Escrow');

+ 7 - 12
test/payment/escrow/RefundEscrow.test.js

@@ -1,15 +1,10 @@
-const shouldFail = require('../../helpers/shouldFail');
-const expectEvent = require('../../helpers/expectEvent');
-const { balanceDifference } = require('../../helpers/balanceDifference');
-const { ether } = require('../../helpers/ether');
-const { ZERO_ADDRESS } = require('../../helpers/constants');
-
-require('../../helpers/setup');
+const { balance, constants, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 const RefundEscrow = artifacts.require('RefundEscrow');
 
 contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee2]) {
-  const amount = ether(54.0);
+  const amount = ether('54');
   const refundees = [refundee1, refundee2];
 
   it('requires a non-null beneficiary', async function () {
@@ -26,7 +21,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
     context('active state', function () {
       it('has beneficiary and state', async function () {
         (await this.escrow.beneficiary()).should.be.equal(beneficiary);
-        (await this.escrow.state()).should.be.bignumber.equal(0);
+        (await this.escrow.state()).should.be.bignumber.equal('0');
       });
 
       it('accepts deposits', async function () {
@@ -69,9 +64,9 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
       });
 
       it('allows beneficiary withdrawal', async function () {
-        (await balanceDifference(beneficiary, () =>
+        (await balance.difference(beneficiary, () =>
           this.escrow.beneficiaryWithdraw()
-        )).should.be.bignumber.equal(amount * refundees.length);
+        )).should.be.bignumber.equal(amount.muln(refundees.length));
       });
 
       it('prevents entering the refund state', async function () {
@@ -103,7 +98,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
 
       it('refunds refundees', async function () {
         for (const refundee of [refundee1, refundee2]) {
-          (await balanceDifference(refundee, () =>
+          (await balance.difference(refundee, () =>
             this.escrow.withdraw(refundee, { from: primary }))
           ).should.be.bignumber.equal(amount);
         }

+ 119 - 123
test/token/ERC20/ERC20.test.js

@@ -1,32 +1,30 @@
-const shouldFail = require('../../helpers/shouldFail');
-const expectEvent = require('../../helpers/expectEvent');
-const { ZERO_ADDRESS } = require('../../helpers/constants');
+const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 const ERC20Mock = artifacts.require('ERC20Mock');
 
-const { BigNumber } = require('../../helpers/setup');
-
-contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
+contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
+  const initialSupply = new BN(100);
   beforeEach(async function () {
-    this.token = await ERC20Mock.new(owner, 100);
+    this.token = await ERC20Mock.new(initialHolder, initialSupply);
   });
 
   describe('total supply', function () {
     it('returns the total amount of tokens', async function () {
-      (await this.token.totalSupply()).should.be.bignumber.equal(100);
+      (await this.token.totalSupply()).should.be.bignumber.equal(initialSupply);
     });
   });
 
   describe('balanceOf', function () {
     describe('when the requested account has no tokens', function () {
       it('returns zero', async function () {
-        (await this.token.balanceOf(anotherAccount)).should.be.bignumber.equal(0);
+        (await this.token.balanceOf(anotherAccount)).should.be.bignumber.equal('0');
       });
     });
 
     describe('when the requested account has some tokens', function () {
       it('returns the total amount of tokens', async function () {
-        (await this.token.balanceOf(owner)).should.be.bignumber.equal(100);
+        (await this.token.balanceOf(initialHolder)).should.be.bignumber.equal(initialSupply);
       });
     });
   });
@@ -36,29 +34,29 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
       const to = recipient;
 
       describe('when the sender does not have enough balance', function () {
-        const amount = 101;
+        const amount = initialSupply.addn(1);
 
         it('reverts', async function () {
-          await shouldFail.reverting(this.token.transfer(to, amount, { from: owner }));
+          await shouldFail.reverting(this.token.transfer(to, amount, { from: initialHolder }));
         });
       });
 
       describe('when the sender has enough balance', function () {
-        const amount = 100;
+        const amount = initialSupply;
 
         it('transfers the requested amount', async function () {
-          await this.token.transfer(to, amount, { from: owner });
+          await this.token.transfer(to, amount, { from: initialHolder });
 
-          (await this.token.balanceOf(owner)).should.be.bignumber.equal(0);
+          (await this.token.balanceOf(initialHolder)).should.be.bignumber.equal('0');
 
           (await this.token.balanceOf(to)).should.be.bignumber.equal(amount);
         });
 
         it('emits a transfer event', async function () {
-          const { logs } = await this.token.transfer(to, amount, { from: owner });
+          const { logs } = await this.token.transfer(to, amount, { from: initialHolder });
 
           expectEvent.inLogs(logs, 'Transfer', {
-            from: owner,
+            from: initialHolder,
             to: to,
             value: amount,
           });
@@ -70,7 +68,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
       const to = ZERO_ADDRESS;
 
       it('reverts', async function () {
-        await shouldFail.reverting(this.token.transfer(to, 100, { from: owner }));
+        await shouldFail.reverting(this.token.transfer(to, initialSupply, { from: initialHolder }));
       });
     });
   });
@@ -80,13 +78,13 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
       const spender = recipient;
 
       describe('when the sender has enough balance', function () {
-        const amount = 100;
+        const amount = initialSupply;
 
         it('emits an approval event', async function () {
-          const { logs } = await this.token.approve(spender, amount, { from: owner });
+          const { logs } = await this.token.approve(spender, amount, { from: initialHolder });
 
           expectEvent.inLogs(logs, 'Approval', {
-            owner: owner,
+            owner: initialHolder,
             spender: spender,
             value: amount,
           });
@@ -94,33 +92,33 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
 
         describe('when there was no approved amount before', function () {
           it('approves the requested amount', async function () {
-            await this.token.approve(spender, amount, { from: owner });
+            await this.token.approve(spender, amount, { from: initialHolder });
 
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
           });
         });
 
         describe('when the spender had an approved amount', function () {
           beforeEach(async function () {
-            await this.token.approve(spender, 1, { from: owner });
+            await this.token.approve(spender, new BN(1), { from: initialHolder });
           });
 
           it('approves the requested amount and replaces the previous one', async function () {
-            await this.token.approve(spender, amount, { from: owner });
+            await this.token.approve(spender, amount, { from: initialHolder });
 
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
           });
         });
       });
 
       describe('when the sender does not have enough balance', function () {
-        const amount = 101;
+        const amount = initialSupply.addn(1);
 
         it('emits an approval event', async function () {
-          const { logs } = await this.token.approve(spender, amount, { from: owner });
+          const { logs } = await this.token.approve(spender, amount, { from: initialHolder });
 
           expectEvent.inLogs(logs, 'Approval', {
-            owner: owner,
+            owner: initialHolder,
             spender: spender,
             value: amount,
           });
@@ -128,32 +126,32 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
 
         describe('when there was no approved amount before', function () {
           it('approves the requested amount', async function () {
-            await this.token.approve(spender, amount, { from: owner });
+            await this.token.approve(spender, amount, { from: initialHolder });
 
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
           });
         });
 
         describe('when the spender had an approved amount', function () {
           beforeEach(async function () {
-            await this.token.approve(spender, 1, { from: owner });
+            await this.token.approve(spender, new BN(1), { from: initialHolder });
           });
 
           it('approves the requested amount and replaces the previous one', async function () {
-            await this.token.approve(spender, amount, { from: owner });
+            await this.token.approve(spender, amount, { from: initialHolder });
 
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
           });
         });
       });
     });
 
     describe('when the spender is the zero address', function () {
-      const amount = 100;
+      const amount = initialSupply;
       const spender = ZERO_ADDRESS;
 
       it('reverts', async function () {
-        await shouldFail.reverting(this.token.approve(spender, amount, { from: owner }));
+        await shouldFail.reverting(this.token.approve(spender, amount, { from: initialHolder }));
       });
     });
   });
@@ -166,89 +164,89 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
 
       describe('when the spender has enough approved balance', function () {
         beforeEach(async function () {
-          await this.token.approve(spender, 100, { from: owner });
+          await this.token.approve(spender, initialSupply, { from: initialHolder });
         });
 
-        describe('when the owner has enough balance', function () {
-          const amount = 100;
+        describe('when the initial holder has enough balance', function () {
+          const amount = initialSupply;
 
           it('transfers the requested amount', async function () {
-            await this.token.transferFrom(owner, to, amount, { from: spender });
+            await this.token.transferFrom(initialHolder, to, amount, { from: spender });
 
-            (await this.token.balanceOf(owner)).should.be.bignumber.equal(0);
+            (await this.token.balanceOf(initialHolder)).should.be.bignumber.equal('0');
 
             (await this.token.balanceOf(to)).should.be.bignumber.equal(amount);
           });
 
           it('decreases the spender allowance', async function () {
-            await this.token.transferFrom(owner, to, amount, { from: spender });
+            await this.token.transferFrom(initialHolder, to, amount, { from: spender });
 
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(0);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal('0');
           });
 
           it('emits a transfer event', async function () {
-            const { logs } = await this.token.transferFrom(owner, to, amount, { from: spender });
+            const { logs } = await this.token.transferFrom(initialHolder, to, amount, { from: spender });
 
             expectEvent.inLogs(logs, 'Transfer', {
-              from: owner,
+              from: initialHolder,
               to: to,
               value: amount,
             });
           });
 
           it('emits an approval event', async function () {
-            const { logs } = await this.token.transferFrom(owner, to, amount, { from: spender });
+            const { logs } = await this.token.transferFrom(initialHolder, to, amount, { from: spender });
 
             expectEvent.inLogs(logs, 'Approval', {
-              owner: owner,
+              owner: initialHolder,
               spender: spender,
-              value: await this.token.allowance(owner, spender),
+              value: await this.token.allowance(initialHolder, spender),
             });
           });
         });
 
-        describe('when the owner does not have enough balance', function () {
-          const amount = 101;
+        describe('when the initial holder does not have enough balance', function () {
+          const amount = initialSupply.addn(1);
 
           it('reverts', async function () {
-            await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender }));
+            await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
           });
         });
       });
 
       describe('when the spender does not have enough approved balance', function () {
         beforeEach(async function () {
-          await this.token.approve(spender, 99, { from: owner });
+          await this.token.approve(spender, initialSupply.subn(1), { from: initialHolder });
         });
 
-        describe('when the owner has enough balance', function () {
-          const amount = 100;
+        describe('when the initial holder has enough balance', function () {
+          const amount = initialSupply;
 
           it('reverts', async function () {
-            await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender }));
+            await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
           });
         });
 
-        describe('when the owner does not have enough balance', function () {
-          const amount = 101;
+        describe('when the initial holder does not have enough balance', function () {
+          const amount = initialSupply.addn(1);
 
           it('reverts', async function () {
-            await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender }));
+            await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
           });
         });
       });
     });
 
     describe('when the recipient is the zero address', function () {
-      const amount = 100;
+      const amount = initialSupply;
       const to = ZERO_ADDRESS;
 
       beforeEach(async function () {
-        await this.token.approve(spender, amount, { from: owner });
+        await this.token.approve(spender, amount, { from: initialHolder });
       });
 
       it('reverts', async function () {
-        await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender }));
+        await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
       });
     });
   });
@@ -260,7 +258,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
       function shouldDecreaseApproval (amount) {
         describe('when there was no approved amount before', function () {
           it('reverts', async function () {
-            await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: owner }));
+            await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: initialHolder }));
           });
         });
 
@@ -268,71 +266,73 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
           const approvedAmount = amount;
 
           beforeEach(async function () {
-            ({ logs: this.logs } = await this.token.approve(spender, approvedAmount, { from: owner }));
+            ({ logs: this.logs } = await this.token.approve(spender, approvedAmount, { from: initialHolder }));
           });
 
           it('emits an approval event', async function () {
-            const { logs } = await this.token.decreaseAllowance(spender, approvedAmount, { from: owner });
+            const { logs } = await this.token.decreaseAllowance(spender, approvedAmount, { from: initialHolder });
 
             expectEvent.inLogs(logs, 'Approval', {
-              owner: owner,
+              owner: initialHolder,
               spender: spender,
-              value: 0,
+              value: new BN(0),
             });
           });
 
           it('decreases the spender allowance subtracting the requested amount', async function () {
-            await this.token.decreaseAllowance(spender, approvedAmount - 1, { from: owner });
+            await this.token.decreaseAllowance(spender, approvedAmount.subn(1), { from: initialHolder });
 
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(1);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal('1');
           });
 
           it('sets the allowance to zero when all allowance is removed', async function () {
-            await this.token.decreaseAllowance(spender, approvedAmount, { from: owner });
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(0);
+            await this.token.decreaseAllowance(spender, approvedAmount, { from: initialHolder });
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal('0');
           });
 
           it('reverts when more than the full allowance is removed', async function () {
-            await shouldFail.reverting(this.token.decreaseAllowance(spender, approvedAmount + 1, { from: owner }));
+            await shouldFail.reverting(
+              this.token.decreaseAllowance(spender, approvedAmount.addn(1), { from: initialHolder })
+            );
           });
         });
       }
 
       describe('when the sender has enough balance', function () {
-        const amount = 100;
+        const amount = initialSupply;
 
         shouldDecreaseApproval(amount);
       });
 
       describe('when the sender does not have enough balance', function () {
-        const amount = 101;
+        const amount = initialSupply.addn(1);
 
         shouldDecreaseApproval(amount);
       });
     });
 
     describe('when the spender is the zero address', function () {
-      const amount = 100;
+      const amount = initialSupply;
       const spender = ZERO_ADDRESS;
 
       it('reverts', async function () {
-        await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: owner }));
+        await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: initialHolder }));
       });
     });
   });
 
   describe('increase allowance', function () {
-    const amount = 100;
+    const amount = initialSupply;
 
     describe('when the spender is not the zero address', function () {
       const spender = recipient;
 
       describe('when the sender has enough balance', function () {
         it('emits an approval event', async function () {
-          const { logs } = await this.token.increaseAllowance(spender, amount, { from: owner });
+          const { logs } = await this.token.increaseAllowance(spender, amount, { from: initialHolder });
 
           expectEvent.inLogs(logs, 'Approval', {
-            owner: owner,
+            owner: initialHolder,
             spender: spender,
             value: amount,
           });
@@ -340,33 +340,33 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
 
         describe('when there was no approved amount before', function () {
           it('approves the requested amount', async function () {
-            await this.token.increaseAllowance(spender, amount, { from: owner });
+            await this.token.increaseAllowance(spender, amount, { from: initialHolder });
 
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
           });
         });
 
         describe('when the spender had an approved amount', function () {
           beforeEach(async function () {
-            await this.token.approve(spender, 1, { from: owner });
+            await this.token.approve(spender, new BN(1), { from: initialHolder });
           });
 
           it('increases the spender allowance adding the requested amount', async function () {
-            await this.token.increaseAllowance(spender, amount, { from: owner });
+            await this.token.increaseAllowance(spender, amount, { from: initialHolder });
 
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount + 1);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount.addn(1));
           });
         });
       });
 
       describe('when the sender does not have enough balance', function () {
-        const amount = 101;
+        const amount = initialSupply.addn(1);
 
         it('emits an approval event', async function () {
-          const { logs } = await this.token.increaseAllowance(spender, amount, { from: owner });
+          const { logs } = await this.token.increaseAllowance(spender, amount, { from: initialHolder });
 
           expectEvent.inLogs(logs, 'Approval', {
-            owner: owner,
+            owner: initialHolder,
             spender: spender,
             value: amount,
           });
@@ -374,21 +374,21 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
 
         describe('when there was no approved amount before', function () {
           it('approves the requested amount', async function () {
-            await this.token.increaseAllowance(spender, amount, { from: owner });
+            await this.token.increaseAllowance(spender, amount, { from: initialHolder });
 
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
           });
         });
 
         describe('when the spender had an approved amount', function () {
           beforeEach(async function () {
-            await this.token.approve(spender, 1, { from: owner });
+            await this.token.approve(spender, new BN(1), { from: initialHolder });
           });
 
           it('increases the spender allowance adding the requested amount', async function () {
-            await this.token.increaseAllowance(spender, amount, { from: owner });
+            await this.token.increaseAllowance(spender, amount, { from: initialHolder });
 
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount + 1);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount.addn(1));
           });
         });
       });
@@ -398,14 +398,13 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
       const spender = ZERO_ADDRESS;
 
       it('reverts', async function () {
-        await shouldFail.reverting(this.token.increaseAllowance(spender, amount, { from: owner }));
+        await shouldFail.reverting(this.token.increaseAllowance(spender, amount, { from: initialHolder }));
       });
     });
   });
 
   describe('_mint', function () {
-    const initialSupply = new BigNumber(100);
-    const amount = new BigNumber(50);
+    const amount = new BN(50);
 
     it('rejects a null account', async function () {
       await shouldFail.reverting(this.token.mint(ZERO_ADDRESS, amount));
@@ -418,7 +417,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
       });
 
       it('increments totalSupply', async function () {
-        const expectedSupply = initialSupply.plus(amount);
+        const expectedSupply = initialSupply.add(amount);
         (await this.token.totalSupply()).should.be.bignumber.equal(expectedSupply);
       });
 
@@ -438,37 +437,35 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
   });
 
   describe('_burn', function () {
-    const initialSupply = new BigNumber(100);
-
     it('rejects a null account', async function () {
-      await shouldFail.reverting(this.token.burn(ZERO_ADDRESS, 1));
+      await shouldFail.reverting(this.token.burn(ZERO_ADDRESS, new BN(1)));
     });
 
     describe('for a non null account', function () {
       it('rejects burning more than balance', async function () {
-        await shouldFail.reverting(this.token.burn(owner, initialSupply.plus(1)));
+        await shouldFail.reverting(this.token.burn(initialHolder, initialSupply.addn(1)));
       });
 
       const describeBurn = function (description, amount) {
         describe(description, function () {
           beforeEach('burning', async function () {
-            const { logs } = await this.token.burn(owner, amount);
+            const { logs } = await this.token.burn(initialHolder, amount);
             this.logs = logs;
           });
 
           it('decrements totalSupply', async function () {
-            const expectedSupply = initialSupply.minus(amount);
+            const expectedSupply = initialSupply.sub(amount);
             (await this.token.totalSupply()).should.be.bignumber.equal(expectedSupply);
           });
 
-          it('decrements owner balance', async function () {
-            const expectedBalance = initialSupply.minus(amount);
-            (await this.token.balanceOf(owner)).should.be.bignumber.equal(expectedBalance);
+          it('decrements initialHolder balance', async function () {
+            const expectedBalance = initialSupply.sub(amount);
+            (await this.token.balanceOf(initialHolder)).should.be.bignumber.equal(expectedBalance);
           });
 
           it('emits Transfer event', async function () {
             const event = expectEvent.inLogs(this.logs, 'Transfer', {
-              from: owner,
+              from: initialHolder,
               to: ZERO_ADDRESS,
             });
 
@@ -478,58 +475,57 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
       };
 
       describeBurn('for entire balance', initialSupply);
-      describeBurn('for less amount than balance', initialSupply.sub(1));
+      describeBurn('for less amount than balance', initialSupply.subn(1));
     });
   });
 
   describe('_burnFrom', function () {
-    const initialSupply = new BigNumber(100);
-    const allowance = new BigNumber(70);
+    const allowance = new BN(70);
 
     const spender = anotherAccount;
 
     beforeEach('approving', async function () {
-      await this.token.approve(spender, allowance, { from: owner });
+      await this.token.approve(spender, allowance, { from: initialHolder });
     });
 
     it('rejects a null account', async function () {
-      await shouldFail.reverting(this.token.burnFrom(ZERO_ADDRESS, 1));
+      await shouldFail.reverting(this.token.burnFrom(ZERO_ADDRESS, new BN(1)));
     });
 
     describe('for a non null account', function () {
       it('rejects burning more than allowance', async function () {
-        await shouldFail.reverting(this.token.burnFrom(owner, allowance.plus(1)));
+        await shouldFail.reverting(this.token.burnFrom(initialHolder, allowance.addn(1)));
       });
 
       it('rejects burning more than balance', async function () {
-        await shouldFail.reverting(this.token.burnFrom(owner, initialSupply.plus(1)));
+        await shouldFail.reverting(this.token.burnFrom(initialHolder, initialSupply.addn(1)));
       });
 
       const describeBurnFrom = function (description, amount) {
         describe(description, function () {
           beforeEach('burning', async function () {
-            const { logs } = await this.token.burnFrom(owner, amount, { from: spender });
+            const { logs } = await this.token.burnFrom(initialHolder, amount, { from: spender });
             this.logs = logs;
           });
 
           it('decrements totalSupply', async function () {
-            const expectedSupply = initialSupply.minus(amount);
+            const expectedSupply = initialSupply.sub(amount);
             (await this.token.totalSupply()).should.be.bignumber.equal(expectedSupply);
           });
 
-          it('decrements owner balance', async function () {
-            const expectedBalance = initialSupply.minus(amount);
-            (await this.token.balanceOf(owner)).should.be.bignumber.equal(expectedBalance);
+          it('decrements initialHolder balance', async function () {
+            const expectedBalance = initialSupply.sub(amount);
+            (await this.token.balanceOf(initialHolder)).should.be.bignumber.equal(expectedBalance);
           });
 
           it('decrements spender allowance', async function () {
-            const expectedAllowance = allowance.minus(amount);
-            (await this.token.allowance(owner, spender)).should.be.bignumber.equal(expectedAllowance);
+            const expectedAllowance = allowance.sub(amount);
+            (await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(expectedAllowance);
           });
 
           it('emits a Transfer event', async function () {
             const event = expectEvent.inLogs(this.logs, 'Transfer', {
-              from: owner,
+              from: initialHolder,
               to: ZERO_ADDRESS,
             });
 
@@ -538,16 +534,16 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
 
           it('emits an Approval event', async function () {
             expectEvent.inLogs(this.logs, 'Approval', {
-              owner: owner,
+              owner: initialHolder,
               spender: spender,
-              value: await this.token.allowance(owner, spender),
+              value: await this.token.allowance(initialHolder, spender),
             });
           });
         });
       };
 
       describeBurnFrom('for entire allowance', allowance);
-      describeBurnFrom('for less amount than allowance', allowance.sub(1));
+      describeBurnFrom('for less amount than allowance', allowance.subn(1));
     });
   });
 });

+ 3 - 1
test/token/ERC20/ERC20Burnable.test.js

@@ -1,8 +1,10 @@
+const { BN } = require('openzeppelin-test-helpers');
+
 const { shouldBehaveLikeERC20Burnable } = require('./behaviors/ERC20Burnable.behavior');
 const ERC20BurnableMock = artifacts.require('ERC20BurnableMock');
 
 contract('ERC20Burnable', function ([_, owner, ...otherAccounts]) {
-  const initialBalance = 1000;
+  const initialBalance = new BN(1000);
 
   beforeEach(async function () {
     this.token = await ERC20BurnableMock.new(owner, initialBalance, { from: owner });

+ 3 - 4
test/token/ERC20/ERC20Capped.test.js

@@ -1,16 +1,15 @@
-const shouldFail = require('../../helpers/shouldFail');
-const { ether } = require('../../helpers/ether');
+const { BN, ether, shouldFail } = require('openzeppelin-test-helpers');
 const { shouldBehaveLikeERC20Mintable } = require('./behaviors/ERC20Mintable.behavior');
 const { shouldBehaveLikeERC20Capped } = require('./behaviors/ERC20Capped.behavior');
 
 const ERC20Capped = artifacts.require('ERC20Capped');
 
 contract('ERC20Capped', function ([_, minter, ...otherAccounts]) {
-  const cap = ether(1000);
+  const cap = ether('1000');
 
   it('requires a non-zero cap', async function () {
     await shouldFail.reverting(
-      ERC20Capped.new(0, { from: minter })
+      ERC20Capped.new(new BN(0), { from: minter })
     );
   });
 

+ 2 - 2
test/token/ERC20/ERC20Detailed.test.js

@@ -1,11 +1,11 @@
-require('../../helpers/setup');
+const { BN } = require('openzeppelin-test-helpers');
 
 const ERC20DetailedMock = artifacts.require('ERC20DetailedMock');
 
 contract('ERC20Detailed', function () {
   const _name = 'My Detailed ERC20';
   const _symbol = 'MDT';
-  const _decimals = 18;
+  const _decimals = new BN(18);
 
   beforeEach(async function () {
     this.detailedERC20 = await ERC20DetailedMock.new(_name, _symbol, _decimals);

+ 46 - 35
test/token/ERC20/ERC20Pausable.test.js

@@ -1,12 +1,13 @@
-const expectEvent = require('../../helpers/expectEvent');
-const shouldFail = require('../../helpers/shouldFail');
+const { BN, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
 
 const ERC20PausableMock = artifacts.require('ERC20PausableMock');
 const { shouldBehaveLikePublicRole } = require('../../access/roles/PublicRole.behavior');
 
 contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherAccount, ...otherAccounts]) {
+  const initialSupply = new BN(100);
+
   beforeEach(async function () {
-    this.token = await ERC20PausableMock.new(pauser, 100, { from: pauser });
+    this.token = await ERC20PausableMock.new(pauser, initialSupply, { from: pauser });
   });
 
   describe('pauser role', function () {
@@ -114,132 +115,142 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA
 
     describe('transfer', function () {
       it('allows to transfer when unpaused', async function () {
-        await this.token.transfer(recipient, 100, { from: pauser });
+        await this.token.transfer(recipient, initialSupply, { from: pauser });
 
-        (await this.token.balanceOf(pauser)).should.be.bignumber.equal(0);
-        (await this.token.balanceOf(recipient)).should.be.bignumber.equal(100);
+        (await this.token.balanceOf(pauser)).should.be.bignumber.equal('0');
+        (await this.token.balanceOf(recipient)).should.be.bignumber.equal(initialSupply);
       });
 
       it('allows to transfer when paused and then unpaused', async function () {
         await this.token.pause({ from: pauser });
         await this.token.unpause({ from: pauser });
 
-        await this.token.transfer(recipient, 100, { from: pauser });
+        await this.token.transfer(recipient, initialSupply, { from: pauser });
 
-        (await this.token.balanceOf(pauser)).should.be.bignumber.equal(0);
-        (await this.token.balanceOf(recipient)).should.be.bignumber.equal(100);
+        (await this.token.balanceOf(pauser)).should.be.bignumber.equal('0');
+        (await this.token.balanceOf(recipient)).should.be.bignumber.equal(initialSupply);
       });
 
       it('reverts when trying to transfer when paused', async function () {
         await this.token.pause({ from: pauser });
 
-        await shouldFail.reverting(this.token.transfer(recipient, 100, { from: pauser }));
+        await shouldFail.reverting(this.token.transfer(recipient, initialSupply, { from: pauser }));
       });
     });
 
     describe('approve', function () {
+      const allowance = new BN(40);
+
       it('allows to approve when unpaused', async function () {
-        await this.token.approve(anotherAccount, 40, { from: pauser });
+        await this.token.approve(anotherAccount, allowance, { from: pauser });
 
-        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(40);
+        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance);
       });
 
       it('allows to approve when paused and then unpaused', async function () {
         await this.token.pause({ from: pauser });
         await this.token.unpause({ from: pauser });
 
-        await this.token.approve(anotherAccount, 40, { from: pauser });
+        await this.token.approve(anotherAccount, allowance, { from: pauser });
 
-        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(40);
+        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance);
       });
 
       it('reverts when trying to approve when paused', async function () {
         await this.token.pause({ from: pauser });
 
-        await shouldFail.reverting(this.token.approve(anotherAccount, 40, { from: pauser }));
+        await shouldFail.reverting(this.token.approve(anotherAccount, allowance, { from: pauser }));
       });
     });
 
     describe('transfer from', function () {
+      const allowance = new BN(40);
+
       beforeEach(async function () {
-        await this.token.approve(anotherAccount, 50, { from: pauser });
+        await this.token.approve(anotherAccount, allowance, { from: pauser });
       });
 
       it('allows to transfer from when unpaused', async function () {
-        await this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount });
+        await this.token.transferFrom(pauser, recipient, allowance, { from: anotherAccount });
 
-        (await this.token.balanceOf(pauser)).should.be.bignumber.equal(60);
-        (await this.token.balanceOf(recipient)).should.be.bignumber.equal(40);
+        (await this.token.balanceOf(recipient)).should.be.bignumber.equal(allowance);
+        (await this.token.balanceOf(pauser)).should.be.bignumber.equal(initialSupply.sub(allowance));
       });
 
       it('allows to transfer when paused and then unpaused', async function () {
         await this.token.pause({ from: pauser });
         await this.token.unpause({ from: pauser });
 
-        await this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount });
+        await this.token.transferFrom(pauser, recipient, allowance, { from: anotherAccount });
 
-        (await this.token.balanceOf(pauser)).should.be.bignumber.equal(60);
-        (await this.token.balanceOf(recipient)).should.be.bignumber.equal(40);
+        (await this.token.balanceOf(recipient)).should.be.bignumber.equal(allowance);
+        (await this.token.balanceOf(pauser)).should.be.bignumber.equal(initialSupply.sub(allowance));
       });
 
       it('reverts when trying to transfer from when paused', async function () {
         await this.token.pause({ from: pauser });
 
-        await shouldFail.reverting(this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount }));
+        await shouldFail.reverting(this.token.transferFrom(pauser, recipient, allowance, { from: anotherAccount }));
       });
     });
 
     describe('decrease approval', function () {
+      const allowance = new BN(40);
+      const decrement = new BN(10);
+
       beforeEach(async function () {
-        await this.token.approve(anotherAccount, 100, { from: pauser });
+        await this.token.approve(anotherAccount, allowance, { from: pauser });
       });
 
       it('allows to decrease approval when unpaused', async function () {
-        await this.token.decreaseAllowance(anotherAccount, 40, { from: pauser });
+        await this.token.decreaseAllowance(anotherAccount, decrement, { from: pauser });
 
-        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(60);
+        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.sub(decrement));
       });
 
       it('allows to decrease approval when paused and then unpaused', async function () {
         await this.token.pause({ from: pauser });
         await this.token.unpause({ from: pauser });
 
-        await this.token.decreaseAllowance(anotherAccount, 40, { from: pauser });
+        await this.token.decreaseAllowance(anotherAccount, decrement, { from: pauser });
 
-        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(60);
+        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.sub(decrement));
       });
 
       it('reverts when trying to transfer when paused', async function () {
         await this.token.pause({ from: pauser });
 
-        await shouldFail.reverting(this.token.decreaseAllowance(anotherAccount, 40, { from: pauser }));
+        await shouldFail.reverting(this.token.decreaseAllowance(anotherAccount, decrement, { from: pauser }));
       });
     });
 
     describe('increase approval', function () {
+      const allowance = new BN(40);
+      const increment = new BN(30);
+
       beforeEach(async function () {
-        await this.token.approve(anotherAccount, 100, { from: pauser });
+        await this.token.approve(anotherAccount, allowance, { from: pauser });
       });
 
       it('allows to increase approval when unpaused', async function () {
-        await this.token.increaseAllowance(anotherAccount, 40, { from: pauser });
+        await this.token.increaseAllowance(anotherAccount, increment, { from: pauser });
 
-        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(140);
+        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.add(increment));
       });
 
       it('allows to increase approval when paused and then unpaused', async function () {
         await this.token.pause({ from: pauser });
         await this.token.unpause({ from: pauser });
 
-        await this.token.increaseAllowance(anotherAccount, 40, { from: pauser });
+        await this.token.increaseAllowance(anotherAccount, increment, { from: pauser });
 
-        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(140);
+        (await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.add(increment));
       });
 
       it('reverts when trying to increase approval when paused', async function () {
         await this.token.pause({ from: pauser });
 
-        await shouldFail.reverting(this.token.increaseAllowance(anotherAccount, 40, { from: pauser }));
+        await shouldFail.reverting(this.token.increaseAllowance(anotherAccount, increment, { from: pauser }));
       });
     });
   });

+ 1 - 3
test/token/ERC20/SafeERC20.test.js

@@ -1,6 +1,4 @@
-const shouldFail = require('../../helpers/shouldFail');
-
-require('../../helpers/setup');
+const { shouldFail } = require('openzeppelin-test-helpers');
 
 const SafeERC20Helper = artifacts.require('SafeERC20Helper');
 

+ 8 - 11
test/token/ERC20/TokenTimelock.test.js

@@ -1,13 +1,10 @@
-const shouldFail = require('../../helpers/shouldFail');
-const time = require('../../helpers/time');
-
-const { BigNumber } = require('../../helpers/setup');
+const { BN, shouldFail, time } = require('openzeppelin-test-helpers');
 
 const ERC20Mintable = artifacts.require('ERC20Mintable');
 const TokenTimelock = artifacts.require('TokenTimelock');
 
 contract('TokenTimelock', function ([_, minter, beneficiary]) {
-  const amount = new BigNumber(100);
+  const amount = new BN(100);
 
   context('with token', function () {
     beforeEach(async function () {
@@ -15,7 +12,7 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) {
     });
 
     it('rejects a release time in the past', async function () {
-      const pastReleaseTime = (await time.latest()) - time.duration.years(1);
+      const pastReleaseTime = (await time.latest()).sub(time.duration.years(1));
       await shouldFail.reverting(
         TokenTimelock.new(this.token.address, beneficiary, pastReleaseTime)
       );
@@ -23,7 +20,7 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) {
 
     context('once deployed', function () {
       beforeEach(async function () {
-        this.releaseTime = (await time.latest()) + time.duration.years(1);
+        this.releaseTime = (await time.latest()).add(time.duration.years(1));
         this.timelock = await TokenTimelock.new(this.token.address, beneficiary, this.releaseTime);
         await this.token.mint(this.timelock.address, amount, { from: minter });
       });
@@ -39,24 +36,24 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) {
       });
 
       it('cannot be released just before time limit', async function () {
-        await time.increaseTo(this.releaseTime - time.duration.seconds(3));
+        await time.increaseTo(this.releaseTime.sub(time.duration.seconds(3)));
         await shouldFail.reverting(this.timelock.release());
       });
 
       it('can be released just after limit', async function () {
-        await time.increaseTo(this.releaseTime + time.duration.seconds(1));
+        await time.increaseTo(this.releaseTime.add(time.duration.seconds(1)));
         await this.timelock.release();
         (await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
       });
 
       it('can be released after time limit', async function () {
-        await time.increaseTo(this.releaseTime + time.duration.years(1));
+        await time.increaseTo(this.releaseTime.add(time.duration.years(1)));
         await this.timelock.release();
         (await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
       });
 
       it('cannot be released twice', async function () {
-        await time.increaseTo(this.releaseTime + time.duration.years(1));
+        await time.increaseTo(this.releaseTime.add(time.duration.years(1)));
         await this.timelock.release();
         await shouldFail.reverting(this.timelock.release());
         (await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);

+ 17 - 18
test/token/ERC20/behaviors/ERC20Burnable.behavior.js

@@ -1,18 +1,15 @@
-const shouldFail = require('../../../helpers/shouldFail');
-const expectEvent = require('../../../helpers/expectEvent');
-const { ZERO_ADDRESS } = require('../../../helpers/constants');
-
-require('../../../helpers/setup');
+const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
   describe('burn', function () {
     describe('when the given amount is not greater than balance of the sender', function () {
       context('for a zero amount', function () {
-        shouldBurn(0);
+        shouldBurn(new BN(0));
       });
 
       context('for a non-zero amount', function () {
-        shouldBurn(100);
+        shouldBurn(new BN(100));
       });
 
       function shouldBurn (amount) {
@@ -21,7 +18,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
         });
 
         it('burns the requested amount', async function () {
-          (await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance - amount);
+          (await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance.sub(amount));
         });
 
         it('emits a transfer event', async function () {
@@ -35,7 +32,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
     });
 
     describe('when the given amount is greater than the balance of the sender', function () {
-      const amount = initialBalance + 1;
+      const amount = initialBalance.addn(1);
 
       it('reverts', async function () {
         await shouldFail.reverting(this.token.burn(amount, { from: owner }));
@@ -46,15 +43,15 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
   describe('burnFrom', function () {
     describe('on success', function () {
       context('for a zero amount', function () {
-        shouldBurnFrom(0);
+        shouldBurnFrom(new BN(0));
       });
 
       context('for a non-zero amount', function () {
-        shouldBurnFrom(100);
+        shouldBurnFrom(new BN(100));
       });
 
       function shouldBurnFrom (amount) {
-        const originalAllowance = amount * 3;
+        const originalAllowance = amount.muln(3);
 
         beforeEach(async function () {
           await this.token.approve(burner, originalAllowance, { from: owner });
@@ -63,11 +60,11 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
         });
 
         it('burns the requested amount', async function () {
-          (await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance - amount);
+          (await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance.sub(amount));
         });
 
         it('decrements allowance', async function () {
-          (await this.token.allowance(owner, burner)).should.be.bignumber.equal(originalAllowance - amount);
+          (await this.token.allowance(owner, burner)).should.be.bignumber.equal(originalAllowance.sub(amount));
         });
 
         it('emits a transfer event', async function () {
@@ -81,7 +78,8 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
     });
 
     describe('when the given amount is greater than the balance of the sender', function () {
-      const amount = initialBalance + 1;
+      const amount = initialBalance.addn(1);
+
       it('reverts', async function () {
         await this.token.approve(burner, amount, { from: owner });
         await shouldFail.reverting(this.token.burnFrom(owner, amount, { from: burner }));
@@ -89,10 +87,11 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
     });
 
     describe('when the given amount is greater than the allowance', function () {
-      const amount = 100;
+      const allowance = new BN(100);
+
       it('reverts', async function () {
-        await this.token.approve(burner, amount - 1, { from: owner });
-        await shouldFail.reverting(this.token.burnFrom(owner, amount, { from: burner }));
+        await this.token.approve(burner, allowance, { from: owner });
+        await shouldFail.reverting(this.token.burnFrom(owner, allowance.addn(1), { from: burner }));
       });
     });
   });

+ 6 - 8
test/token/ERC20/behaviors/ERC20Capped.behavior.js

@@ -1,6 +1,4 @@
-const shouldFail = require('../../../helpers/shouldFail');
-
-require('../../../helpers/setup');
+const { shouldFail } = require('openzeppelin-test-helpers');
 
 function shouldBehaveLikeERC20Capped (minter, [anyone], cap) {
   describe('capped token', function () {
@@ -11,13 +9,13 @@ function shouldBehaveLikeERC20Capped (minter, [anyone], cap) {
     });
 
     it('should mint when amount is less than cap', async function () {
-      await this.token.mint(anyone, cap.sub(1), { from });
-      (await this.token.totalSupply()).should.be.bignumber.equal(cap.sub(1));
+      await this.token.mint(anyone, cap.subn(1), { from });
+      (await this.token.totalSupply()).should.be.bignumber.equal(cap.subn(1));
     });
 
-    it('should fail to mint if the ammount exceeds the cap', async function () {
-      await this.token.mint(anyone, cap.sub(1), { from });
-      await shouldFail.reverting(this.token.mint(anyone, 100, { from }));
+    it('should fail to mint if the amount exceeds the cap', async function () {
+      await this.token.mint(anyone, cap.subn(1), { from });
+      await shouldFail.reverting(this.token.mint(anyone, 2, { from }));
     });
 
     it('should fail to mint after cap is reached', async function () {

+ 4 - 7
test/token/ERC20/behaviors/ERC20Mintable.behavior.js

@@ -1,19 +1,16 @@
-const shouldFail = require('../../../helpers/shouldFail');
-const expectEvent = require('../../../helpers/expectEvent');
-const { ZERO_ADDRESS } = require('../../../helpers/constants');
-
-require('../../../helpers/setup');
+const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
   describe('as a mintable token', function () {
     describe('mint', function () {
-      const amount = 100;
+      const amount = new BN(100);
 
       context('when the sender has minting permission', function () {
         const from = minter;
 
         context('for a zero amount', function () {
-          shouldMint(0);
+          shouldMint(new BN(0));
         });
 
         context('for a non-zero amount', function () {

+ 21 - 26
test/token/ERC721/ERC721.behavior.js

@@ -1,20 +1,17 @@
-const expectEvent = require('../../helpers/expectEvent');
+const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior');
-const shouldFail = require('../../helpers/shouldFail');
-const { ZERO_ADDRESS } = require('../../helpers/constants');
-const send = require('../../helpers/send');
 
 const ERC721ReceiverMock = artifacts.require('ERC721ReceiverMock.sol');
-require('../../helpers/setup');
 
 function shouldBehaveLikeERC721 (
   creator,
   minter,
   [owner, approved, anotherApproved, operator, anyone]
 ) {
-  const firstTokenId = 1;
-  const secondTokenId = 2;
-  const unknownTokenId = 3;
+  const firstTokenId = new BN(1);
+  const secondTokenId = new BN(2);
+  const unknownTokenId = new BN(3);
   const RECEIVER_MAGIC_VALUE = '0x150b7a02';
 
   describe('like an ERC721', function () {
@@ -27,19 +24,19 @@ function shouldBehaveLikeERC721 (
     describe('balanceOf', function () {
       context('when the given address owns some tokens', function () {
         it('returns the amount of tokens owned by the given address', async function () {
-          (await this.token.balanceOf(owner)).should.be.bignumber.equal(2);
+          (await this.token.balanceOf(owner)).should.be.bignumber.equal('2');
         });
       });
 
       context('when the given address does not own any tokens', function () {
         it('returns 0', async function () {
-          (await this.token.balanceOf(anyone)).should.be.bignumber.equal(0);
+          (await this.token.balanceOf(anyone)).should.be.bignumber.equal('0');
         });
       });
 
       context('when querying the zero address', function () {
         it('throws', async function () {
-          await shouldFail.reverting(this.token.balanceOf(0));
+          await shouldFail.reverting(this.token.balanceOf(ZERO_ADDRESS));
         });
       });
     });
@@ -101,15 +98,15 @@ function shouldBehaveLikeERC721 (
         }
 
         it('adjusts owners balances', async function () {
-          (await this.token.balanceOf(owner)).should.be.bignumber.equal(1);
+          (await this.token.balanceOf(owner)).should.be.bignumber.equal('1');
         });
 
         it('adjusts owners tokens by index', async function () {
           if (!this.token.tokenOfOwnerByIndex) return;
 
-          (await this.token.tokenOfOwnerByIndex(this.toWhom, 0)).toNumber().should.be.equal(tokenId);
+          (await this.token.tokenOfOwnerByIndex(this.toWhom, 0)).should.be.bignumber.equal(tokenId);
 
-          (await this.token.tokenOfOwnerByIndex(owner, 0)).toNumber().should.not.be.equal(tokenId);
+          (await this.token.tokenOfOwnerByIndex(owner, 0)).should.be.bignumber.not.equal(tokenId);
         });
       };
 
@@ -165,7 +162,7 @@ function shouldBehaveLikeERC721 (
           });
 
           it('keeps the owner balance', async function () {
-            (await this.token.balanceOf(owner)).should.be.bignumber.equal(2);
+            (await this.token.balanceOf(owner)).should.be.bignumber.equal('2');
           });
 
           it('keeps same tokens by index', async function () {
@@ -173,7 +170,9 @@ function shouldBehaveLikeERC721 (
             const tokensListed = await Promise.all(
               [0, 1].map(i => this.token.tokenOfOwnerByIndex(owner, i))
             );
-            tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId, secondTokenId]);
+            tokensListed.map(t => t.toNumber()).should.have.members(
+              [firstTokenId.toNumber(), secondTokenId.toNumber()]
+            );
           });
         });
 
@@ -200,7 +199,9 @@ function shouldBehaveLikeERC721 (
 
         context('when the address to transfer the token to is the zero address', function () {
           it('reverts', async function () {
-            await shouldFail.reverting(transferFunction.call(this, owner, ZERO_ADDRESS, tokenId, { from: owner }));
+            await shouldFail.reverting(
+              transferFunction.call(this, owner, ZERO_ADDRESS, tokenId, { from: owner })
+            );
           });
         });
       };
@@ -213,17 +214,11 @@ function shouldBehaveLikeERC721 (
 
       describe('via safeTransferFrom', function () {
         const safeTransferFromWithData = function (from, to, tokenId, opts) {
-          return send.transaction(
-            this.token,
-            'safeTransferFrom',
-            'address,address,uint256,bytes',
-            [from, to, tokenId, data],
-            opts
-          );
+          return this.token.methods['safeTransferFrom(address,address,uint256,bytes)'](from, to, tokenId, data, opts);
         };
 
         const safeTransferFromWithoutData = function (from, to, tokenId, opts) {
-          return this.token.safeTransferFrom(from, to, tokenId, opts);
+          return this.token.methods['safeTransferFrom(address,address,uint256)'](from, to, tokenId, opts);
         };
 
         const shouldTransferSafely = function (transferFun, data) {
@@ -282,7 +277,7 @@ function shouldBehaveLikeERC721 (
         });
 
         describe('without data', function () {
-          shouldTransferSafely(safeTransferFromWithoutData, '0x');
+          shouldTransferSafely(safeTransferFromWithoutData, null);
         });
 
         describe('to a receiver contract returning unexpected value', function () {

+ 13 - 17
test/token/ERC721/ERC721.test.js

@@ -1,8 +1,5 @@
-require('../../helpers/setup');
-const { ZERO_ADDRESS } = require('../../helpers/constants');
-const expectEvent = require('../../helpers/expectEvent');
-const send = require('../../helpers/send');
-const shouldFail = require('../../helpers/shouldFail');
+const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
 const ERC721Mock = artifacts.require('ERC721Mock.sol');
@@ -15,7 +12,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
   shouldBehaveLikeERC721(creator, creator, accounts);
 
   describe('internal functions', function () {
-    const tokenId = 5042;
+    const tokenId = new BN('5042');
 
     describe('_mint(address, uint256)', function () {
       it('reverts with a null destination address', async function () {
@@ -32,7 +29,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
         });
 
         it('creates the token', async function () {
-          (await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal(1);
+          (await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal('1');
           (await this.token.ownerOf(tokenId)).should.equal(tokenOwner);
         });
 
@@ -44,7 +41,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
 
     describe('_burn(address, uint256)', function () {
       it('reverts when burning a non-existent token id', async function () {
-        await shouldFail.reverting(send.transaction(this.token, 'burn', 'address,uint256', [tokenOwner, tokenId]));
+        await shouldFail.reverting(this.token.methods['burn(address,uint256)'](tokenOwner, tokenId));
       });
 
       context('with minted token', function () {
@@ -53,13 +50,12 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
         });
 
         it('reverts when the account is not the owner', async function () {
-          await shouldFail.reverting(send.transaction(this.token, 'burn', 'address,uint256', [anyone, tokenId]));
+          await shouldFail.reverting(this.token.methods['burn(address,uint256)'](anyone, tokenId));
         });
 
         context('with burnt token', function () {
           beforeEach(async function () {
-            ({ logs: this.logs } =
-              await send.transaction(this.token, 'burn', 'address,uint256', [tokenOwner, tokenId]));
+            ({ logs: this.logs } = await this.token.methods['burn(address,uint256)'](tokenOwner, tokenId));
           });
 
           it('emits a Transfer event', function () {
@@ -67,12 +63,12 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
           });
 
           it('deletes the token', async function () {
-            (await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal(0);
+            (await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal('0');
             await shouldFail.reverting(this.token.ownerOf(tokenId));
           });
 
           it('reverts when burning a token id that has been deleted', async function () {
-            await shouldFail.reverting(send.transaction(this.token, 'burn', 'address,uint256', [tokenOwner, tokenId]));
+            await shouldFail.reverting(this.token.methods['burn(address,uint256)'](tokenOwner, tokenId));
           });
         });
       });
@@ -80,7 +76,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
 
     describe('_burn(uint256)', function () {
       it('reverts when burning a non-existent token id', async function () {
-        await shouldFail.reverting(send.transaction(this.token, 'burn', 'uint256', [tokenId]));
+        await shouldFail.reverting(this.token.methods['burn(uint256)'](tokenId));
       });
 
       context('with minted token', function () {
@@ -90,7 +86,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
 
         context('with burnt token', function () {
           beforeEach(async function () {
-            ({ logs: this.logs } = await send.transaction(this.token, 'burn', 'uint256', [tokenId]));
+            ({ logs: this.logs } = await this.token.methods['burn(uint256)'](tokenId));
           });
 
           it('emits a Transfer event', function () {
@@ -98,12 +94,12 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
           });
 
           it('deletes the token', async function () {
-            (await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal(0);
+            (await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal('0');
             await shouldFail.reverting(this.token.ownerOf(tokenId));
           });
 
           it('reverts when burning a token id that has been deleted', async function () {
-            await shouldFail.reverting(send.transaction(this.token, 'burn', 'uint256', [tokenId]));
+            await shouldFail.reverting(this.token.methods['burn(uint256)'](tokenId));
           });
         });
       });

+ 2 - 2
test/token/ERC721/ERC721Burnable.test.js

@@ -1,3 +1,5 @@
+require('openzeppelin-test-helpers');
+
 const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
 const {
   shouldBehaveLikeMintAndBurnERC721,
@@ -5,8 +7,6 @@ const {
 
 const ERC721BurnableImpl = artifacts.require('ERC721MintableBurnableImpl.sol');
 
-require('../../helpers/setup');
-
 contract('ERC721Burnable', function ([_, creator, ...accounts]) {
   const minter = creator;
 

+ 20 - 21
test/token/ERC721/ERC721Full.test.js

@@ -1,21 +1,20 @@
-const shouldFail = require('../../helpers/shouldFail');
+const { BN, shouldFail } = require('openzeppelin-test-helpers');
+
 const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
 const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior');
 
 const ERC721FullMock = artifacts.require('ERC721FullMock.sol');
 
-require('../../helpers/setup');
-
 contract('ERC721Full', function ([
   creator,
   ...accounts
 ]) {
   const name = 'Non Fungible Token';
   const symbol = 'NFT';
-  const firstTokenId = 100;
-  const secondTokenId = 200;
-  const thirdTokenId = 300;
-  const nonExistentTokenId = 999;
+  const firstTokenId = new BN(100);
+  const secondTokenId = new BN(200);
+  const thirdTokenId = new BN(300);
+  const nonExistentTokenId = new BN(999);
 
   const minter = creator;
 
@@ -41,11 +40,11 @@ contract('ERC721Full', function ([
       });
 
       it('adjusts owner tokens by index', async function () {
-        (await this.token.tokenOfOwnerByIndex(newOwner, 0)).toNumber().should.be.equal(thirdTokenId);
+        (await this.token.tokenOfOwnerByIndex(newOwner, 0)).should.be.bignumber.equal(thirdTokenId);
       });
 
       it('adjusts all tokens list', async function () {
-        (await this.token.tokenByIndex(2)).toNumber().should.be.equal(thirdTokenId);
+        (await this.token.tokenByIndex(2)).should.be.bignumber.equal(thirdTokenId);
       });
     });
 
@@ -55,16 +54,16 @@ contract('ERC721Full', function ([
       });
 
       it('removes that token from the token list of the owner', async function () {
-        (await this.token.tokenOfOwnerByIndex(owner, 0)).toNumber().should.be.equal(secondTokenId);
+        (await this.token.tokenOfOwnerByIndex(owner, 0)).should.be.bignumber.equal(secondTokenId);
       });
 
       it('adjusts all tokens list', async function () {
-        (await this.token.tokenByIndex(0)).toNumber().should.be.equal(secondTokenId);
+        (await this.token.tokenByIndex(0)).should.be.bignumber.equal(secondTokenId);
       });
 
       it('burns all tokens', async function () {
         await this.token.burn(secondTokenId, { from: owner });
-        (await this.token.totalSupply()).toNumber().should.be.equal(0);
+        (await this.token.totalSupply()).should.be.bignumber.equal('0');
         await shouldFail.reverting(this.token.tokenByIndex(0));
       });
     });
@@ -115,7 +114,7 @@ contract('ERC721Full', function ([
 
     describe('totalSupply', function () {
       it('returns total token supply', async function () {
-        (await this.token.totalSupply()).should.be.bignumber.equal(2);
+        (await this.token.totalSupply()).should.be.bignumber.equal('2');
       });
     });
 
@@ -145,15 +144,15 @@ contract('ERC721Full', function ([
         });
 
         it('returns correct token IDs for target', async function () {
-          (await this.token.balanceOf(another)).toNumber().should.be.equal(2);
+          (await this.token.balanceOf(another)).should.be.bignumber.equal('2');
           const tokensListed = await Promise.all(
             [0, 1].map(i => this.token.tokenOfOwnerByIndex(another, i))
           );
-          tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId, secondTokenId]);
+          tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId.toNumber(), secondTokenId.toNumber()]);
         });
 
         it('returns empty collection for original owner', async function () {
-          (await this.token.balanceOf(owner)).toNumber().should.be.equal(0);
+          (await this.token.balanceOf(owner)).should.be.bignumber.equal('0');
           await shouldFail.reverting(this.token.tokenOfOwnerByIndex(owner, 0));
         });
       });
@@ -164,7 +163,7 @@ contract('ERC721Full', function ([
         const tokensListed = await Promise.all(
           [0, 1].map(i => this.token.tokenByIndex(i))
         );
-        tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId, secondTokenId]);
+        tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId.toNumber(), secondTokenId.toNumber()]);
       });
 
       it('should revert if index is greater than supply', async function () {
@@ -173,14 +172,14 @@ contract('ERC721Full', function ([
 
       [firstTokenId, secondTokenId].forEach(function (tokenId) {
         it(`should return all tokens after burning token ${tokenId} and minting new tokens`, async function () {
-          const newTokenId = 300;
-          const anotherNewTokenId = 400;
+          const newTokenId = new BN(300);
+          const anotherNewTokenId = new BN(400);
 
           await this.token.burn(tokenId, { from: owner });
           await this.token.mint(newOwner, newTokenId, { from: minter });
           await this.token.mint(newOwner, anotherNewTokenId, { from: minter });
 
-          (await this.token.totalSupply()).toNumber().should.be.equal(3);
+          (await this.token.totalSupply()).should.be.bignumber.equal('3');
 
           const tokensListed = await Promise.all(
             [0, 1, 2].map(i => this.token.tokenByIndex(i))
@@ -188,7 +187,7 @@ contract('ERC721Full', function ([
           const expectedTokens = [firstTokenId, secondTokenId, newTokenId, anotherNewTokenId].filter(
             x => (x !== tokenId)
           );
-          tokensListed.map(t => t.toNumber()).should.have.members(expectedTokens);
+          tokensListed.map(t => t.toNumber()).should.have.members(expectedTokens.map(t => t.toNumber()));
         });
       });
     });

+ 3 - 3
test/token/ERC721/ERC721Holder.test.js

@@ -1,12 +1,12 @@
+const { BN } = require('openzeppelin-test-helpers');
+
 const ERC721Holder = artifacts.require('ERC721Holder.sol');
 const ERC721Mintable = artifacts.require('ERC721MintableBurnableImpl.sol');
 
-require('../../helpers/setup');
-
 contract('ERC721Holder', function ([creator]) {
   it('receives an ERC721 token', async function () {
     const token = await ERC721Mintable.new({ from: creator });
-    const tokenId = 1;
+    const tokenId = new BN(1);
     await token.mint(creator, tokenId, { from: creator });
 
     const receiver = await ERC721Holder.new();

+ 8 - 10
test/token/ERC721/ERC721MintBurn.behavior.js

@@ -1,17 +1,15 @@
-const shouldFail = require('../../helpers/shouldFail');
-const expectEvent = require('../../helpers/expectEvent');
-const { ZERO_ADDRESS } = require('../../helpers/constants');
-require('../../helpers/setup');
+const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 function shouldBehaveLikeMintAndBurnERC721 (
   creator,
   minter,
   [owner, newOwner, approved, anyone]
 ) {
-  const firstTokenId = 1;
-  const secondTokenId = 2;
-  const thirdTokenId = 3;
-  const unknownTokenId = 4;
+  const firstTokenId = new BN(1);
+  const secondTokenId = new BN(2);
+  const thirdTokenId = new BN(3);
+  const unknownTokenId = new BN(4);
   const MOCK_URI = 'https://example.com';
 
   describe('like a mintable and burnable ERC721', function () {
@@ -34,7 +32,7 @@ function shouldBehaveLikeMintAndBurnERC721 (
         });
 
         it('increases the balance of its owner', async function () {
-          (await this.token.balanceOf(newOwner)).should.be.bignumber.equal(1);
+          (await this.token.balanceOf(newOwner)).should.be.bignumber.equal('1');
         });
 
         it('emits a transfer and minted event', async function () {
@@ -79,7 +77,7 @@ function shouldBehaveLikeMintAndBurnERC721 (
 
         it('burns the given token ID and adjusts the balance of the owner', async function () {
           await shouldFail.reverting(this.token.ownerOf(tokenId));
-          (await this.token.balanceOf(owner)).should.be.bignumber.equal(1);
+          (await this.token.balanceOf(owner)).should.be.bignumber.equal('1');
         });
 
         it('emits a burn event', async function () {

+ 2 - 5
test/token/ERC721/ERC721Mintable.test.js

@@ -1,12 +1,9 @@
+require('openzeppelin-test-helpers');
 const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
-const {
-  shouldBehaveLikeMintAndBurnERC721,
-} = require('./ERC721MintBurn.behavior');
+const { shouldBehaveLikeMintAndBurnERC721 } = require('./ERC721MintBurn.behavior');
 
 const ERC721MintableImpl = artifacts.require('ERC721MintableBurnableImpl.sol');
 
-require('../../helpers/setup');
-
 contract('ERC721Mintable', function ([_, creator, ...accounts]) {
   const minter = creator;
 

+ 1 - 2
test/token/ERC721/ERC721Pausable.test.js

@@ -1,11 +1,10 @@
+require('openzeppelin-test-helpers');
 const { shouldBehaveLikeERC721PausedToken } = require('./ERC721PausedToken.behavior');
 const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
 const { shouldBehaveLikePublicRole } = require('../../access/roles/PublicRole.behavior');
 
 const ERC721PausableMock = artifacts.require('ERC721PausableMock.sol');
 
-require('../../helpers/setup');
-
 contract('ERC721Pausable', function ([
   _,
   creator,

+ 8 - 19
test/token/ERC721/ERC721PausedToken.behavior.js

@@ -1,12 +1,9 @@
-const shouldFail = require('../../helpers/shouldFail');
-const send = require('../../helpers/send');
-const { ZERO_ADDRESS } = require('../../helpers/constants');
-
-require('../../helpers/setup');
+const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
+const { ZERO_ADDRESS } = constants;
 
 function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
-  const firstTokenId = 1;
-  const mintedTokens = 1;
+  const firstTokenId = new BN(1);
+  const mintedTokens = new BN(1);
   const mockData = '0x42';
 
   describe('like a paused ERC721', function () {
@@ -31,14 +28,8 @@ function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
     });
 
     it('reverts when trying to safeTransferFrom with data', async function () {
-      await shouldFail.reverting(
-        send.transaction(
-          this.token,
-          'safeTransferFrom',
-          'address,address,uint256,bytes',
-          [owner, recipient, firstTokenId, mockData],
-          { from: owner }
-        )
+      await shouldFail.reverting(this.token.methods['safeTransferFrom(address,address,uint256,bytes)'](
+        owner, recipient, firstTokenId, mockData, { from: owner })
       );
     });
 
@@ -65,15 +56,13 @@ function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
 
     describe('exists', function () {
       it('should return token existance', async function () {
-        const result = await this.token.exists(firstTokenId);
-        result.should.eq(true);
+        (await this.token.exists(firstTokenId)).should.equal(true);
       });
     });
 
     describe('isApprovedForAll', function () {
       it('returns the approval of the operator', async function () {
-        const isApproved = await this.token.isApprovedForAll(owner, operator);
-        isApproved.should.eq(false);
+        (await this.token.isApprovedForAll(owner, operator)).should.equal(false);
       });
     });
   });

+ 2 - 2
test/utils/Address.test.js

@@ -1,8 +1,8 @@
+require('openzeppelin-test-helpers');
+
 const AddressImpl = artifacts.require('AddressImpl');
 const SimpleToken = artifacts.require('SimpleToken');
 
-require('../helpers/setup');
-
 contract('Address', function ([_, anyone]) {
   beforeEach(async function () {
     this.mock = await AddressImpl.new();

+ 14 - 14
test/utils/Arrays.test.js

@@ -1,6 +1,6 @@
-const ArraysImpl = artifacts.require('ArraysImpl');
+require('openzeppelin-test-helpers');
 
-require('../helpers/setup');
+const ArraysImpl = artifacts.require('ArraysImpl');
 
 contract('Arrays', function () {
   context('Even number of elements', function () {
@@ -11,23 +11,23 @@ contract('Arrays', function () {
     });
 
     it('should return correct index for the basic case', async function () {
-      (await this.arrays.findUpperBound(16)).should.be.bignumber.equal(5);
+      (await this.arrays.findUpperBound(16)).should.be.bignumber.equal('5');
     });
 
     it('should return 0 for the first element', async function () {
-      (await this.arrays.findUpperBound(11)).should.be.bignumber.equal(0);
+      (await this.arrays.findUpperBound(11)).should.be.bignumber.equal('0');
     });
 
     it('should return index of the last element', async function () {
-      (await this.arrays.findUpperBound(20)).should.be.bignumber.equal(9);
+      (await this.arrays.findUpperBound(20)).should.be.bignumber.equal('9');
     });
 
     it('should return first index after last element if searched value is over the upper boundary', async function () {
-      (await this.arrays.findUpperBound(32)).should.be.bignumber.equal(10);
+      (await this.arrays.findUpperBound(32)).should.be.bignumber.equal('10');
     });
 
     it('should return 0 for the element under the lower boundary', async function () {
-      (await this.arrays.findUpperBound(2)).should.be.bignumber.equal(0);
+      (await this.arrays.findUpperBound(2)).should.be.bignumber.equal('0');
     });
   });
 
@@ -39,23 +39,23 @@ contract('Arrays', function () {
     });
 
     it('should return correct index for the basic case', async function () {
-      (await this.arrays.findUpperBound(16)).should.be.bignumber.equal(5);
+      (await this.arrays.findUpperBound(16)).should.be.bignumber.equal('5');
     });
 
     it('should return 0 for the first element', async function () {
-      (await this.arrays.findUpperBound(11)).should.be.bignumber.equal(0);
+      (await this.arrays.findUpperBound(11)).should.be.bignumber.equal('0');
     });
 
     it('should return index of the last element', async function () {
-      (await this.arrays.findUpperBound(21)).should.be.bignumber.equal(10);
+      (await this.arrays.findUpperBound(21)).should.be.bignumber.equal('10');
     });
 
     it('should return first index after last element if searched value is over the upper boundary', async function () {
-      (await this.arrays.findUpperBound(32)).should.be.bignumber.equal(11);
+      (await this.arrays.findUpperBound(32)).should.be.bignumber.equal('11');
     });
 
     it('should return 0 for the element under the lower boundary', async function () {
-      (await this.arrays.findUpperBound(2)).should.be.bignumber.equal(0);
+      (await this.arrays.findUpperBound(2)).should.be.bignumber.equal('0');
     });
   });
 
@@ -67,7 +67,7 @@ contract('Arrays', function () {
     });
 
     it('should return index of first element in next filled range', async function () {
-      (await this.arrays.findUpperBound(17)).should.be.bignumber.equal(5);
+      (await this.arrays.findUpperBound(17)).should.be.bignumber.equal('5');
     });
   });
 
@@ -77,7 +77,7 @@ contract('Arrays', function () {
     });
 
     it('should always return 0 for empty array', async function () {
-      (await this.arrays.findUpperBound(10)).should.be.bignumber.equal(0);
+      (await this.arrays.findUpperBound(10)).should.be.bignumber.equal('0');
     });
   });
 });

+ 3 - 4
test/utils/ReentrancyGuard.test.js

@@ -1,13 +1,12 @@
-const shouldFail = require('../helpers/shouldFail');
+const { shouldFail } = require('openzeppelin-test-helpers');
+
 const ReentrancyMock = artifacts.require('ReentrancyMock');
 const ReentrancyAttack = artifacts.require('ReentrancyAttack');
 
-require('../helpers/setup');
-
 contract('ReentrancyGuard', function () {
   beforeEach(async function () {
     this.reentrancyMock = await ReentrancyMock.new();
-    (await this.reentrancyMock.counter()).should.be.bignumber.equal(0);
+    (await this.reentrancyMock.counter()).should.be.bignumber.equal('0');
   });
 
   it('should not allow remote callback', async function () {

+ 6 - 0
truffle-config.js

@@ -13,4 +13,10 @@ module.exports = {
       gasPrice: 0x01,
     },
   },
+
+  compilers: {
+    solc: {
+      version: '0.5.0',
+    },
+  },
 };

Some files were not shown because too many files changed in this diff