From cea2a85a429f70b0a3891614bcb62f1b1f99de5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Wed, 18 Jul 2018 19:37:16 -0300 Subject: [PATCH] Remove Babel (#1074) * Test helpers no longer rely on Babel. * Behaviours are no longer imported. * Removed Babel dependency. * Fixed linter errors. --- package-lock.json | 31 ------------------- package.json | 5 --- test/Bounty.test.js | 7 +++-- test/Heritable.test.js | 6 ++-- test/LimitBalance.test.js | 4 +-- test/ReentrancyGuard.test.js | 3 +- test/SimpleSavingsWallet.test.js | 5 ++- test/access/SignatureBouncer.test.js | 11 +++---- test/crowdsale/AllowanceCrowdsale.test.js | 7 ++--- test/crowdsale/CappedCrowdsale.test.js | 4 +-- test/crowdsale/Crowdsale.test.js | 4 +-- test/crowdsale/FinalizableCrowdsale.test.js | 8 ++--- .../IncreasingPriceCrowdsale.test.js | 8 ++--- .../IndividuallyCappedCrowdsale.test.js | 4 +-- test/crowdsale/MintedCrowdsale.behaviour.js | 8 +++-- test/crowdsale/MintedCrowdsale.test.js | 4 +-- test/crowdsale/PostDeliveryCrowdsale.test.js | 10 +++--- test/crowdsale/RefundableCrowdsale.test.js | 12 +++---- test/crowdsale/TimedCrowdsale.test.js | 10 +++--- test/crowdsale/WhitelistedCrowdsale.test.js | 2 +- test/examples/SampleCrowdsale.test.js | 14 ++++----- test/examples/SimpleToken.test.js | 2 +- test/helpers/EVMRevert.js | 6 +++- test/helpers/EVMThrow.js | 6 +++- test/helpers/advanceToBlock.js | 9 ++++-- test/helpers/assertJump.js | 6 +++- test/helpers/assertRevert.js | 6 +++- test/helpers/decodeLogs.js | 6 +++- test/helpers/ether.js | 6 +++- test/helpers/expectEvent.js | 8 ++--- test/helpers/expectThrow.js | 6 +++- test/helpers/increaseTime.js | 15 ++++++--- test/helpers/latestTime.js | 8 +++-- test/helpers/makeInterfaceId.js | 8 +++-- test/helpers/merkleTree.js | 8 +++-- test/helpers/sendTransaction.js | 9 ++++-- test/helpers/sign.js | 18 +++++++---- test/helpers/transactionMined.js | 11 +++++-- test/helpers/web3.js | 8 +++-- .../SupportsInterface.behavior.js | 8 +++-- .../SupportsInterfaceWithLookup.test.js | 4 +-- test/library/ECRecovery.test.js | 7 ++--- test/library/MerkleProof.test.js | 5 ++- test/lifecycle/Destructible.test.js | 6 ++-- test/lifecycle/Pausable.test.js | 3 +- test/lifecycle/TokenDestructible.test.js | 3 +- test/math/SafeMath.test.js | 2 +- test/ownership/CanReclaimToken.test.js | 3 +- test/ownership/Claimable.test.js | 3 +- test/ownership/Contactable.test.js | 1 - test/ownership/DelayedClaimable.test.js | 2 +- test/ownership/HasNoContracts.test.js | 3 +- test/ownership/HasNoEther.test.js | 4 +-- test/ownership/HasNoTokens.test.js | 3 +- test/ownership/Ownable.behaviour.js | 8 +++-- test/ownership/Ownable.test.js | 2 +- test/ownership/Superuser.test.js | 6 ++-- test/ownership/Whitelist.test.js | 4 +-- test/ownership/rbac/RBAC.test.js | 4 +-- test/payment/ConditionalEscrow.test.js | 4 +-- test/payment/Escrow.behaviour.js | 12 ++++--- test/payment/Escrow.test.js | 2 +- test/payment/PullPayment.test.js | 2 +- test/payment/RefundEscrow.test.js | 6 ++-- test/payment/SplitPayment.test.js | 2 +- test/token/ERC20/BasicToken.test.js | 2 +- test/token/ERC20/BurnableToken.behaviour.js | 10 ++++-- test/token/ERC20/BurnableToken.test.js | 2 +- test/token/ERC20/CappedToken.behaviour.js | 12 ++++--- test/token/ERC20/CappedToken.test.js | 8 ++--- test/token/ERC20/MintableToken.behaviour.js | 8 +++-- test/token/ERC20/MintableToken.test.js | 2 +- test/token/ERC20/PausableToken.test.js | 2 +- test/token/ERC20/RBACCappedToken.test.js | 8 ++--- .../ERC20/RBACMintableToken.behaviour.js | 10 ++++-- test/token/ERC20/RBACMintableToken.test.js | 4 +-- test/token/ERC20/SafeERC20.test.js | 2 +- .../token/ERC20/StandardBurnableToken.test.js | 8 ++--- test/token/ERC20/StandardToken.test.js | 2 +- test/token/ERC20/TokenTimelock.test.js | 4 +-- test/token/ERC20/TokenVesting.test.js | 8 ++--- .../ERC721/ERC721BasicToken.behaviour.js | 16 ++++++---- test/token/ERC721/ERC721BasicToken.test.js | 6 ++-- test/token/ERC721/ERC721MintBurn.behaviour.js | 10 ++++-- test/token/ERC721/ERC721Token.test.js | 12 +++---- truffle-config.js | 2 -- 86 files changed, 308 insertions(+), 252 deletions(-) diff --git a/package-lock.json b/package-lock.json index b5953cf82..acfa71115 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1246,37 +1246,6 @@ "babel-types": "^6.24.1" } }, - "babel-polyfill": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", - "integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=", - "dev": true, - "requires": { - "babel-runtime": "^6.26.0", - "core-js": "^2.5.0", - "regenerator-runtime": "^0.10.5" - }, - "dependencies": { - "babel-runtime": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", - "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", - "dev": true, - "requires": { - "core-js": "^2.4.0", - "regenerator-runtime": "^0.11.0" - }, - "dependencies": { - "regenerator-runtime": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==", - "dev": true - } - } - } - } - }, "babel-preset-env": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/babel-preset-env/-/babel-preset-env-1.7.0.tgz", diff --git a/package.json b/package.json index 1ffb2b084..293d36905 100644 --- a/package.json +++ b/package.json @@ -37,11 +37,6 @@ }, "homepage": "https://github.com/OpenZeppelin/zeppelin-solidity", "devDependencies": { - "babel-polyfill": "^6.26.0", - "babel-preset-es2015": "^6.18.0", - "babel-preset-stage-2": "^6.18.0", - "babel-preset-stage-3": "^6.17.0", - "babel-register": "^6.26.0", "chai": "^4.1.2", "chai-as-promised": "^7.0.0", "chai-bignumber": "^2.0.2", diff --git a/test/Bounty.test.js b/test/Bounty.test.js index 0fd768be4..35756caf1 100644 --- a/test/Bounty.test.js +++ b/test/Bounty.test.js @@ -1,10 +1,11 @@ -import { ethGetBalance, ethSendTransaction } from './helpers/web3'; +const { ethGetBalance, ethSendTransaction } = require('./helpers/web3'); + +var SecureTargetBounty = artifacts.require('SecureTargetBounty'); +var InsecureTargetBounty = artifacts.require('InsecureTargetBounty'); const sendReward = async (from, to, value) => ethSendTransaction({ from, to, value, }); -var SecureTargetBounty = artifacts.require('SecureTargetBounty'); -var InsecureTargetBounty = artifacts.require('InsecureTargetBounty'); function awaitEvent (event, handler) { return new Promise((resolve, reject) => { diff --git a/test/Heritable.test.js b/test/Heritable.test.js index 2124a5279..8a703bbd6 100644 --- a/test/Heritable.test.js +++ b/test/Heritable.test.js @@ -1,6 +1,6 @@ -import increaseTime from './helpers/increaseTime'; -import expectThrow from './helpers/expectThrow'; -import assertRevert from './helpers/assertRevert'; +const { increaseTime } = require('./helpers/increaseTime'); +const { expectThrow } = require('./helpers/expectThrow'); +const { assertRevert } = require('./helpers/assertRevert'); const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'; diff --git a/test/LimitBalance.test.js b/test/LimitBalance.test.js index 6c91f7555..4659090c8 100644 --- a/test/LimitBalance.test.js +++ b/test/LimitBalance.test.js @@ -1,5 +1,5 @@ -import assertRevert from './helpers/assertRevert'; -import { ethGetBalance } from './helpers/web3'; +const { assertRevert } = require('./helpers/assertRevert'); +const { ethGetBalance } = require('./helpers/web3'); var LimitBalanceMock = artifacts.require('LimitBalanceMock'); diff --git a/test/ReentrancyGuard.test.js b/test/ReentrancyGuard.test.js index 0e32cf369..a99dcff72 100644 --- a/test/ReentrancyGuard.test.js +++ b/test/ReentrancyGuard.test.js @@ -1,5 +1,4 @@ - -import expectThrow from './helpers/expectThrow'; +const { expectThrow } = require('./helpers/expectThrow'); const ReentrancyMock = artifacts.require('ReentrancyMock'); const ReentrancyAttack = artifacts.require('ReentrancyAttack'); diff --git a/test/SimpleSavingsWallet.test.js b/test/SimpleSavingsWallet.test.js index 20a6a4cae..4409e2861 100644 --- a/test/SimpleSavingsWallet.test.js +++ b/test/SimpleSavingsWallet.test.js @@ -1,6 +1,5 @@ - -import expectThrow from './helpers/expectThrow'; -import { ethGetBalance, ethSendTransaction } from './helpers/web3'; +const { expectThrow } = require('./helpers/expectThrow'); +const { ethGetBalance, ethSendTransaction } = require('./helpers/web3'); const SimpleSavingsWallet = artifacts.require('SimpleSavingsWallet'); diff --git a/test/access/SignatureBouncer.test.js b/test/access/SignatureBouncer.test.js index 48832032b..2db5044c7 100644 --- a/test/access/SignatureBouncer.test.js +++ b/test/access/SignatureBouncer.test.js @@ -1,6 +1,5 @@ - -import assertRevert from '../helpers/assertRevert'; -import { signHex } from '../helpers/sign'; +const { assertRevert } = require('../helpers/assertRevert'); +const { signHex } = require('../helpers/sign'); const Bouncer = artifacts.require('SignatureBouncerMock'); @@ -8,19 +7,19 @@ require('chai') .use(require('chai-as-promised')) .should(); -export const getSigner = (contract, signer, data = '') => (addr) => { +const getSigner = (contract, signer, data = '') => (addr) => { // via: https://github.com/OpenZeppelin/zeppelin-solidity/pull/812/files const message = contract.address.substr(2) + addr.substr(2) + data; // ^ substr to remove `0x` because in solidity the address is a set of byes, not a string `0xabcd` return signHex(signer, message); }; -export const getMethodId = (methodName, ...paramTypes) => { +const getMethodId = (methodName, ...paramTypes) => { // methodId is a sha3 of the first 4 bytes after 0x of 'method(paramType1,...)' return web3.sha3(`${methodName}(${paramTypes.join(',')})`).substr(2, 8); }; -export const stripAndPadHexValue = (hexVal, sizeInBytes, start = true) => { +const stripAndPadHexValue = (hexVal, sizeInBytes, start = true) => { // strip 0x from the font and pad with 0's for const strippedHexVal = hexVal.substr(2); return start ? strippedHexVal.padStart(sizeInBytes * 2, 0) : strippedHexVal.padEnd(sizeInBytes * 2, 0); diff --git a/test/crowdsale/AllowanceCrowdsale.test.js b/test/crowdsale/AllowanceCrowdsale.test.js index e785b2ca5..8f1e2267d 100644 --- a/test/crowdsale/AllowanceCrowdsale.test.js +++ b/test/crowdsale/AllowanceCrowdsale.test.js @@ -1,7 +1,6 @@ - -import ether from '../helpers/ether'; -import assertRevert from '../helpers/assertRevert'; -import { ethGetBalance } from '../helpers/web3'; +const { ether } = require('../helpers/ether'); +const { assertRevert } = require('../helpers/assertRevert'); +const { ethGetBalance } = require('../helpers/web3'); const BigNumber = web3.BigNumber; diff --git a/test/crowdsale/CappedCrowdsale.test.js b/test/crowdsale/CappedCrowdsale.test.js index a3dd9660f..7781e81d9 100644 --- a/test/crowdsale/CappedCrowdsale.test.js +++ b/test/crowdsale/CappedCrowdsale.test.js @@ -1,5 +1,5 @@ -import ether from '../helpers/ether'; -import EVMRevert from '../helpers/EVMRevert'; +const { ether } = require('../helpers/ether'); +const { EVMRevert } = require('../helpers/EVMRevert'); const BigNumber = web3.BigNumber; diff --git a/test/crowdsale/Crowdsale.test.js b/test/crowdsale/Crowdsale.test.js index d2b3af46b..34d8ec27f 100644 --- a/test/crowdsale/Crowdsale.test.js +++ b/test/crowdsale/Crowdsale.test.js @@ -1,5 +1,5 @@ -import ether from '../helpers/ether'; -import { ethGetBalance } from '../helpers/web3'; +const { ether } = require('../helpers/ether'); +const { ethGetBalance } = require('../helpers/web3'); const BigNumber = web3.BigNumber; diff --git a/test/crowdsale/FinalizableCrowdsale.test.js b/test/crowdsale/FinalizableCrowdsale.test.js index 1a8b058a6..dcd4e9945 100644 --- a/test/crowdsale/FinalizableCrowdsale.test.js +++ b/test/crowdsale/FinalizableCrowdsale.test.js @@ -1,7 +1,7 @@ -import { advanceBlock } from '../helpers/advanceToBlock'; -import { increaseTimeTo, duration } from '../helpers/increaseTime'; -import latestTime from '../helpers/latestTime'; -import EVMRevert from '../helpers/EVMRevert'; +const { advanceBlock } = require('../helpers/advanceToBlock'); +const { increaseTimeTo, duration } = require('../helpers/increaseTime'); +const { latestTime } = require('../helpers/latestTime'); +const { EVMRevert } = require('../helpers/EVMRevert'); const BigNumber = web3.BigNumber; diff --git a/test/crowdsale/IncreasingPriceCrowdsale.test.js b/test/crowdsale/IncreasingPriceCrowdsale.test.js index 680564b50..ba2a3a1cc 100644 --- a/test/crowdsale/IncreasingPriceCrowdsale.test.js +++ b/test/crowdsale/IncreasingPriceCrowdsale.test.js @@ -1,7 +1,7 @@ -import ether from '../helpers/ether'; -import { advanceBlock } from '../helpers/advanceToBlock'; -import { increaseTimeTo, duration } from '../helpers/increaseTime'; -import latestTime from '../helpers/latestTime'; +const { ether } = require('../helpers/ether'); +const { advanceBlock } = require('../helpers/advanceToBlock'); +const { increaseTimeTo, duration } = require('../helpers/increaseTime'); +const { latestTime } = require('../helpers/latestTime'); const BigNumber = web3.BigNumber; diff --git a/test/crowdsale/IndividuallyCappedCrowdsale.test.js b/test/crowdsale/IndividuallyCappedCrowdsale.test.js index e8585ad6d..c0695242a 100644 --- a/test/crowdsale/IndividuallyCappedCrowdsale.test.js +++ b/test/crowdsale/IndividuallyCappedCrowdsale.test.js @@ -1,5 +1,5 @@ -import ether from '../helpers/ether'; -import EVMRevert from '../helpers/EVMRevert'; +const { ether } = require('../helpers/ether'); +const { EVMRevert } = require('../helpers/EVMRevert'); const BigNumber = web3.BigNumber; diff --git a/test/crowdsale/MintedCrowdsale.behaviour.js b/test/crowdsale/MintedCrowdsale.behaviour.js index 42bd95417..06624e930 100644 --- a/test/crowdsale/MintedCrowdsale.behaviour.js +++ b/test/crowdsale/MintedCrowdsale.behaviour.js @@ -1,4 +1,4 @@ -import { ethGetBalance } from '../helpers/web3'; +const { ethGetBalance } = require('../helpers/web3'); const BigNumber = web3.BigNumber; @@ -7,7 +7,7 @@ const should = require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -export default function ([_, investor, wallet, purchaser], rate, value) { +function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate, value) { const expectedTokenAmount = rate.mul(value); describe('as a minted crowdsale', function () { @@ -44,3 +44,7 @@ export default function ([_, investor, wallet, purchaser], rate, value) { }); }); } + +module.exports = { + shouldBehaveLikeMintedCrowdsale, +}; diff --git a/test/crowdsale/MintedCrowdsale.test.js b/test/crowdsale/MintedCrowdsale.test.js index 1baf04ee0..b07f52f7f 100644 --- a/test/crowdsale/MintedCrowdsale.test.js +++ b/test/crowdsale/MintedCrowdsale.test.js @@ -1,5 +1,5 @@ -import shouldBehaveLikeMintedCrowdsale from './MintedCrowdsale.behaviour'; -import ether from '../helpers/ether'; +const { shouldBehaveLikeMintedCrowdsale } = require('./MintedCrowdsale.behaviour'); +const { ether } = require('../helpers/ether'); const BigNumber = web3.BigNumber; diff --git a/test/crowdsale/PostDeliveryCrowdsale.test.js b/test/crowdsale/PostDeliveryCrowdsale.test.js index c0d5a5436..e3049e886 100644 --- a/test/crowdsale/PostDeliveryCrowdsale.test.js +++ b/test/crowdsale/PostDeliveryCrowdsale.test.js @@ -1,8 +1,8 @@ -import { advanceBlock } from '../helpers/advanceToBlock'; -import { increaseTimeTo, duration } from '../helpers/increaseTime'; -import latestTime from '../helpers/latestTime'; -import EVMRevert from '../helpers/EVMRevert'; -import ether from '../helpers/ether'; +const { advanceBlock } = require('../helpers/advanceToBlock'); +const { increaseTimeTo, duration } = require('../helpers/increaseTime'); +const { latestTime } = require('../helpers/latestTime'); +const { EVMRevert } = require('../helpers/EVMRevert'); +const { ether } = require('../helpers/ether'); const BigNumber = web3.BigNumber; diff --git a/test/crowdsale/RefundableCrowdsale.test.js b/test/crowdsale/RefundableCrowdsale.test.js index 6b0f5855d..303bfb717 100644 --- a/test/crowdsale/RefundableCrowdsale.test.js +++ b/test/crowdsale/RefundableCrowdsale.test.js @@ -1,9 +1,9 @@ -import ether from '../helpers/ether'; -import { advanceBlock } from '../helpers/advanceToBlock'; -import { increaseTimeTo, duration } from '../helpers/increaseTime'; -import latestTime from '../helpers/latestTime'; -import EVMRevert from '../helpers/EVMRevert'; -import { ethGetBalance } from '../helpers/web3'; +const { ether } = require('../helpers/ether'); +const { advanceBlock } = require('../helpers/advanceToBlock'); +const { increaseTimeTo, duration } = require('../helpers/increaseTime'); +const { latestTime } = require('../helpers/latestTime'); +const { EVMRevert } = require('../helpers/EVMRevert'); +const { ethGetBalance } = require('../helpers/web3'); const BigNumber = web3.BigNumber; diff --git a/test/crowdsale/TimedCrowdsale.test.js b/test/crowdsale/TimedCrowdsale.test.js index c3062a73b..aaebe75bf 100644 --- a/test/crowdsale/TimedCrowdsale.test.js +++ b/test/crowdsale/TimedCrowdsale.test.js @@ -1,8 +1,8 @@ -import ether from '../helpers/ether'; -import { advanceBlock } from '../helpers/advanceToBlock'; -import { increaseTimeTo, duration } from '../helpers/increaseTime'; -import latestTime from '../helpers/latestTime'; -import EVMRevert from '../helpers/EVMRevert'; +const { ether } = require('../helpers/ether'); +const { advanceBlock } = require('../helpers/advanceToBlock'); +const { increaseTimeTo, duration } = require('../helpers/increaseTime'); +const { latestTime } = require('../helpers/latestTime'); +const { EVMRevert } = require('../helpers/EVMRevert'); const BigNumber = web3.BigNumber; diff --git a/test/crowdsale/WhitelistedCrowdsale.test.js b/test/crowdsale/WhitelistedCrowdsale.test.js index 0097b046d..c6c470769 100644 --- a/test/crowdsale/WhitelistedCrowdsale.test.js +++ b/test/crowdsale/WhitelistedCrowdsale.test.js @@ -1,4 +1,4 @@ -import ether from '../helpers/ether'; +const { ether } = require('../helpers/ether'); const BigNumber = web3.BigNumber; diff --git a/test/examples/SampleCrowdsale.test.js b/test/examples/SampleCrowdsale.test.js index 2e56f07b5..851c5eb68 100644 --- a/test/examples/SampleCrowdsale.test.js +++ b/test/examples/SampleCrowdsale.test.js @@ -1,10 +1,10 @@ -import ether from '../helpers/ether'; -import { advanceBlock } from '../helpers/advanceToBlock'; -import { increaseTimeTo, duration } from '../helpers/increaseTime'; -import latestTime from '../helpers/latestTime'; -import EVMRevert from '../helpers/EVMRevert'; -import assertRevert from '../helpers/assertRevert'; -import { ethGetBalance } from '../helpers/web3'; +const { ether } = require('../helpers/ether'); +const { advanceBlock } = require('../helpers/advanceToBlock'); +const { increaseTimeTo, duration } = require('../helpers/increaseTime'); +const { latestTime } = require('../helpers/latestTime'); +const { EVMRevert } = require('../helpers/EVMRevert'); +const { assertRevert } = require('../helpers/assertRevert'); +const { ethGetBalance } = require('../helpers/web3'); const BigNumber = web3.BigNumber; diff --git a/test/examples/SimpleToken.test.js b/test/examples/SimpleToken.test.js index 7f81c438a..193ca4303 100644 --- a/test/examples/SimpleToken.test.js +++ b/test/examples/SimpleToken.test.js @@ -1,4 +1,4 @@ -import decodeLogs from '../helpers/decodeLogs'; +const { decodeLogs } = require('../helpers/decodeLogs'); const SimpleToken = artifacts.require('SimpleToken'); contract('SimpleToken', accounts => { diff --git a/test/helpers/EVMRevert.js b/test/helpers/EVMRevert.js index 9edcc9d54..cb0c8e02e 100644 --- a/test/helpers/EVMRevert.js +++ b/test/helpers/EVMRevert.js @@ -1 +1,5 @@ -export default 'revert'; +const EVMRevert = 'revert'; + +module.exports = { + EVMRevert, +}; diff --git a/test/helpers/EVMThrow.js b/test/helpers/EVMThrow.js index abdbd4ef3..afe21d277 100644 --- a/test/helpers/EVMThrow.js +++ b/test/helpers/EVMThrow.js @@ -1 +1,5 @@ -export default 'invalid opcode'; +const EVMThrow = 'invalid opcode'; + +module.exports = { + EVMThrow, +}; diff --git a/test/helpers/advanceToBlock.js b/test/helpers/advanceToBlock.js index a11dc92b9..22e5467cc 100644 --- a/test/helpers/advanceToBlock.js +++ b/test/helpers/advanceToBlock.js @@ -1,4 +1,4 @@ -export function advanceBlock () { +function advanceBlock () { return new Promise((resolve, reject) => { web3.currentProvider.sendAsync({ jsonrpc: '2.0', @@ -11,7 +11,7 @@ export function advanceBlock () { } // Advances the block number so that the last mined block is `number`. -export default async function advanceToBlock (number) { +async function advanceToBlock (number) { if (web3.eth.blockNumber > number) { throw Error(`block number ${number} is in the past (current is ${web3.eth.blockNumber})`); } @@ -20,3 +20,8 @@ export default async function advanceToBlock (number) { await advanceBlock(); } } + +module.exports = { + advanceBlock, + advanceToBlock, +}; diff --git a/test/helpers/assertJump.js b/test/helpers/assertJump.js index 5b4e2778a..09db3622b 100644 --- a/test/helpers/assertJump.js +++ b/test/helpers/assertJump.js @@ -1,4 +1,4 @@ -export default async promise => { +async function assertJump (promise) { try { await promise; assert.fail('Expected invalid opcode not received'); @@ -6,4 +6,8 @@ export default async promise => { const invalidOpcodeReceived = error.message.search('invalid opcode') >= 0; assert(invalidOpcodeReceived, `Expected "invalid opcode", got ${error} instead`); } +} + +module.exports = { + assertJump, }; diff --git a/test/helpers/assertRevert.js b/test/helpers/assertRevert.js index 866e211d9..b82e0f195 100644 --- a/test/helpers/assertRevert.js +++ b/test/helpers/assertRevert.js @@ -1,4 +1,4 @@ -export default async promise => { +async function assertRevert (promise) { try { await promise; assert.fail('Expected revert not received'); @@ -6,4 +6,8 @@ export default async promise => { const revertFound = error.message.search('revert') >= 0; assert(revertFound, `Expected "revert", got ${error} instead`); } +} + +module.exports = { + assertRevert, }; diff --git a/test/helpers/decodeLogs.js b/test/helpers/decodeLogs.js index c990eedcb..1f1bc946c 100644 --- a/test/helpers/decodeLogs.js +++ b/test/helpers/decodeLogs.js @@ -1,8 +1,12 @@ const SolidityEvent = require('web3/lib/web3/event.js'); -export default function decodeLogs (logs, contract, address) { +function decodeLogs (logs, contract, address) { return logs.map(log => { const event = new SolidityEvent(null, contract.events[log.topics[0]], address); return event.decode(log); }); } + +module.exports = { + decodeLogs, +}; diff --git a/test/helpers/ether.js b/test/helpers/ether.js index 3b5d13f7d..6e11a112a 100644 --- a/test/helpers/ether.js +++ b/test/helpers/ether.js @@ -1,3 +1,7 @@ -export default function ether (n) { +function ether (n) { return new web3.BigNumber(web3.toWei(n, 'ether')); } + +module.exports = { + ether, +}; diff --git a/test/helpers/expectEvent.js b/test/helpers/expectEvent.js index ab1d6751b..168434401 100644 --- a/test/helpers/expectEvent.js +++ b/test/helpers/expectEvent.js @@ -1,6 +1,6 @@ const should = require('chai').should(); -const inLogs = async (logs, eventName, eventArgs = {}) => { +async function inLogs (logs, eventName, eventArgs = {}) { const event = logs.find(e => e.event === eventName); should.exist(event); for (const [k, v] of Object.entries(eventArgs)) { @@ -8,12 +8,12 @@ const inLogs = async (logs, eventName, eventArgs = {}) => { event.args[k].should.eq(v); } return event; -}; +} -const inTransaction = async (tx, eventName, eventArgs = {}) => { +async function inTransaction (tx, eventName, eventArgs = {}) { const { logs } = await tx; return inLogs(logs, eventName, eventArgs); -}; +} module.exports = { inLogs, diff --git a/test/helpers/expectThrow.js b/test/helpers/expectThrow.js index 948f2c69c..7be652a01 100644 --- a/test/helpers/expectThrow.js +++ b/test/helpers/expectThrow.js @@ -1,4 +1,4 @@ -export default async promise => { +async function expectThrow (promise) { try { await promise; } catch (error) { @@ -18,4 +18,8 @@ export default async promise => { return; } assert.fail('Expected throw not received'); +} + +module.exports = { + expectThrow, }; diff --git a/test/helpers/increaseTime.js b/test/helpers/increaseTime.js index 8eb39459a..a8cfc6007 100644 --- a/test/helpers/increaseTime.js +++ b/test/helpers/increaseTime.js @@ -1,7 +1,7 @@ -import latestTime from './latestTime'; +const { latestTime } = require('./latestTime'); // Increases ganache time by the passed duration in seconds -export default function increaseTime (duration) { +function increaseTime (duration) { const id = Date.now(); return new Promise((resolve, reject) => { @@ -31,14 +31,15 @@ export default function increaseTime (duration) { * * @param target time in seconds */ -export async function increaseTimeTo (target) { +async function increaseTimeTo (target) { let now = (await latestTime()); + if (target < now) throw Error(`Cannot increase current time(${now}) to a moment in the past(${target})`); let diff = target - now; return increaseTime(diff); } -export const duration = { +const duration = { seconds: function (val) { return val; }, minutes: function (val) { return val * this.seconds(60); }, hours: function (val) { return val * this.minutes(60); }, @@ -46,3 +47,9 @@ export const duration = { weeks: function (val) { return val * this.days(7); }, years: function (val) { return val * this.days(365); }, }; + +module.exports = { + increaseTime, + increaseTimeTo, + duration, +}; diff --git a/test/helpers/latestTime.js b/test/helpers/latestTime.js index 1b975f9ce..fee9521d6 100644 --- a/test/helpers/latestTime.js +++ b/test/helpers/latestTime.js @@ -1,7 +1,11 @@ -import { ethGetBlock } from './web3'; +const { ethGetBlock } = require('./web3'); // Returns the time of the last mined block in seconds -export default async function latestTime () { +async function latestTime () { const block = await ethGetBlock('latest'); return block.timestamp; } + +module.exports = { + latestTime, +}; diff --git a/test/helpers/makeInterfaceId.js b/test/helpers/makeInterfaceId.js index e87db67b9..c9963468a 100644 --- a/test/helpers/makeInterfaceId.js +++ b/test/helpers/makeInterfaceId.js @@ -1,8 +1,8 @@ -import { soliditySha3 } from 'web3-utils'; +const { soliditySha3 } = require('web3-utils'); const INTERFACE_ID_LENGTH = 4; -export default (interfaces = []) => { +function makeInterfaceId (interfaces = []) { const interfaceIdBuffer = interfaces .map(methodSignature => soliditySha3(methodSignature)) // keccak256 .map(h => @@ -18,4 +18,8 @@ export default (interfaces = []) => { }, Buffer.alloc(INTERFACE_ID_LENGTH)); return `0x${interfaceIdBuffer.toString('hex')}`; +} + +module.exports = { + makeInterfaceId, }; diff --git a/test/helpers/merkleTree.js b/test/helpers/merkleTree.js index 22c51b6da..8afa32511 100644 --- a/test/helpers/merkleTree.js +++ b/test/helpers/merkleTree.js @@ -1,6 +1,6 @@ -import { sha3, bufferToHex } from 'ethereumjs-util'; +const { sha3, bufferToHex } = require('ethereumjs-util'); -export default class MerkleTree { +class MerkleTree { constructor (elements) { // Filter empty strings and hash elements this.elements = elements.filter(el => el).map(el => sha3(el)); @@ -129,3 +129,7 @@ export default class MerkleTree { return Buffer.concat([...args].sort(Buffer.compare)); } } + +module.exports = { + MerkleTree, +}; diff --git a/test/helpers/sendTransaction.js b/test/helpers/sendTransaction.js index 3d2811746..647474115 100644 --- a/test/helpers/sendTransaction.js +++ b/test/helpers/sendTransaction.js @@ -1,7 +1,7 @@ const _ = require('lodash'); const ethjsABI = require('ethjs-abi'); -export function findMethod (abi, name, args) { +function findMethod (abi, name, args) { for (var i = 0; i < abi.length; i++) { const methodArgs = _.map(abi[i].inputs, 'type').join(','); if ((abi[i].name === name) && (methodArgs === args)) { @@ -10,8 +10,13 @@ export function findMethod (abi, name, args) { } } -export default function sendTransaction (target, name, argsTypes, argsValues, opts) { +function sendTransaction (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)); } + +module.exports = { + findMethod, + sendTransaction, +}; diff --git a/test/helpers/sign.js b/test/helpers/sign.js index 30e894334..bfa711b38 100644 --- a/test/helpers/sign.js +++ b/test/helpers/sign.js @@ -1,22 +1,28 @@ -import utils from 'ethereumjs-util'; +const utils = require('ethereumjs-util'); /** * Hash and add same prefix to the hash that ganache use. * @param {string} message the plaintext/ascii/original message * @return {string} the hash of the message, prefixed, and then hashed again */ -export const hashMessage = (message) => { +function hashMessage (message) { const messageHex = Buffer.from(utils.sha3(message).toString('hex'), 'hex'); const prefix = utils.toBuffer('\u0019Ethereum Signed Message:\n' + messageHex.length.toString()); return utils.bufferToHex(utils.sha3(Buffer.concat([prefix, messageHex]))); -}; +} // signs message using web3 (auto-applies prefix) -export const signMessage = (signer, message = '', options = {}) => { +function signMessage (signer, message = '', options = {}) { return web3.eth.sign(signer, web3.sha3(message, options)); -}; +} // signs hex string using web3 (auto-applies prefix) -export const signHex = (signer, message = '') => { +function signHex (signer, message = '') { return signMessage(signer, message, { encoding: 'hex' }); +} + +module.exports = { + hashMessage, + signMessage, + signHex, }; diff --git a/test/helpers/transactionMined.js b/test/helpers/transactionMined.js index 45fadfbd3..d98b225ed 100644 --- a/test/helpers/transactionMined.js +++ b/test/helpers/transactionMined.js @@ -1,6 +1,5 @@ - -// from https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6 -module.export = web3.eth.transactionMined = function (txnHash, interval) { +// From https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6 +function transactionMined (txnHash, interval) { var transactionReceiptAsync; interval = interval || 500; transactionReceiptAsync = function (txnHash, resolve, reject) { @@ -30,4 +29,10 @@ module.export = web3.eth.transactionMined = function (txnHash, interval) { transactionReceiptAsync(txnHash, resolve, reject); }); } +} + +web3.eth.transactionMined = transactionMined; + +module.exports = { + transactionMined, }; diff --git a/test/helpers/web3.js b/test/helpers/web3.js index b98f94817..b4fd87199 100644 --- a/test/helpers/web3.js +++ b/test/helpers/web3.js @@ -2,6 +2,8 @@ const pify = require('pify'); const ethAsync = pify(web3.eth); -export const ethGetBalance = ethAsync.getBalance; -export const ethSendTransaction = ethAsync.sendTransaction; -export const ethGetBlock = ethAsync.getBlock; +module.exports = { + ethGetBalance: ethAsync.getBalance, + ethSendTransaction: ethAsync.sendTransaction, + ethGetBlock: ethAsync.getBlock, +}; diff --git a/test/introspection/SupportsInterface.behavior.js b/test/introspection/SupportsInterface.behavior.js index 6e49456db..429281f1f 100644 --- a/test/introspection/SupportsInterface.behavior.js +++ b/test/introspection/SupportsInterface.behavior.js @@ -1,4 +1,4 @@ -import makeInterfaceId from '../helpers/makeInterfaceId'; +const { makeInterfaceId } = require('../helpers/makeInterfaceId'); const INTERFACE_IDS = { ERC165: makeInterfaceId([ @@ -30,7 +30,7 @@ const INTERFACE_IDS = { ]), }; -export default function (interfaces = []) { +function shouldSupportInterfaces (interfaces = []) { describe('ERC165\'s supportsInterface(bytes4)', function () { beforeEach(function () { this.thing = this.mock || this.token; @@ -52,3 +52,7 @@ export default function (interfaces = []) { } }); } + +module.exports = { + shouldSupportInterfaces, +}; diff --git a/test/introspection/SupportsInterfaceWithLookup.test.js b/test/introspection/SupportsInterfaceWithLookup.test.js index be017a0c2..ddd727c9c 100644 --- a/test/introspection/SupportsInterfaceWithLookup.test.js +++ b/test/introspection/SupportsInterfaceWithLookup.test.js @@ -1,5 +1,5 @@ -import shouldSupportInterfaces from './SupportsInterface.behavior'; -import assertRevert from '../helpers/assertRevert'; +const { shouldSupportInterfaces } = require('./SupportsInterface.behavior'); +const { assertRevert } = require('../helpers/assertRevert'); const SupportsInterfaceWithLookup = artifacts.require('SupportsInterfaceWithLookupMock'); diff --git a/test/library/ECRecovery.test.js b/test/library/ECRecovery.test.js index 83c4fd23f..f4ab54294 100644 --- a/test/library/ECRecovery.test.js +++ b/test/library/ECRecovery.test.js @@ -1,9 +1,6 @@ +const { hashMessage, signMessage } = require('../helpers/sign'); +const { expectThrow } = require('../helpers/expectThrow'); -import { - hashMessage, - signMessage, -} from '../helpers/sign'; -import expectThrow from '../helpers/expectThrow'; const ECRecoveryMock = artifacts.require('ECRecoveryMock'); require('chai') diff --git a/test/library/MerkleProof.test.js b/test/library/MerkleProof.test.js index 1e8da3c8f..633c9fd8d 100644 --- a/test/library/MerkleProof.test.js +++ b/test/library/MerkleProof.test.js @@ -1,6 +1,5 @@ - -import MerkleTree from '../helpers/merkleTree.js'; -import { sha3, bufferToHex } from 'ethereumjs-util'; +const { MerkleTree } = require('../helpers/merkleTree.js'); +const { sha3, bufferToHex } = require('ethereumjs-util'); var MerkleProofWrapper = artifacts.require('MerkleProofWrapper'); diff --git a/test/lifecycle/Destructible.test.js b/test/lifecycle/Destructible.test.js index c70bf0094..be716b40a 100644 --- a/test/lifecycle/Destructible.test.js +++ b/test/lifecycle/Destructible.test.js @@ -1,7 +1,5 @@ -import { ethGetBalance } from '../helpers/web3'; - -const Destructible = artifacts.require('Destructible'); -require('../helpers/transactionMined.js'); +var Destructible = artifacts.require('Destructible'); +const { ethGetBalance } = require('../helpers/web3'); contract('Destructible', function (accounts) { it('should send balance to owner after destruction', async function () { diff --git a/test/lifecycle/Pausable.test.js b/test/lifecycle/Pausable.test.js index aaf11000e..e8e2df708 100644 --- a/test/lifecycle/Pausable.test.js +++ b/test/lifecycle/Pausable.test.js @@ -1,5 +1,4 @@ - -import assertRevert from '../helpers/assertRevert'; +const { assertRevert } = require('../helpers/assertRevert'); const PausableMock = artifacts.require('PausableMock'); contract('Pausable', function (accounts) { diff --git a/test/lifecycle/TokenDestructible.test.js b/test/lifecycle/TokenDestructible.test.js index 509c06c09..f7f354ee9 100644 --- a/test/lifecycle/TokenDestructible.test.js +++ b/test/lifecycle/TokenDestructible.test.js @@ -1,8 +1,7 @@ -import { ethGetBalance } from '../helpers/web3'; +const { ethGetBalance } = require('../helpers/web3'); var TokenDestructible = artifacts.require('TokenDestructible'); var StandardTokenMock = artifacts.require('StandardTokenMock'); -require('../helpers/transactionMined.js'); contract('TokenDestructible', function (accounts) { let destructible; diff --git a/test/math/SafeMath.test.js b/test/math/SafeMath.test.js index 8b7efba1f..ab5ab46ef 100644 --- a/test/math/SafeMath.test.js +++ b/test/math/SafeMath.test.js @@ -1,4 +1,4 @@ -import assertJump from '../helpers/assertJump'; +const { assertJump } = require('../helpers/assertJump'); const BigNumber = web3.BigNumber; const SafeMathMock = artifacts.require('SafeMathMock'); diff --git a/test/ownership/CanReclaimToken.test.js b/test/ownership/CanReclaimToken.test.js index 6f0f2c671..a50c05f9f 100644 --- a/test/ownership/CanReclaimToken.test.js +++ b/test/ownership/CanReclaimToken.test.js @@ -1,5 +1,4 @@ - -import expectThrow from '../helpers/expectThrow'; +const { expectThrow } = require('../helpers/expectThrow'); const CanReclaimToken = artifacts.require('CanReclaimToken'); const BasicTokenMock = artifacts.require('BasicTokenMock'); diff --git a/test/ownership/Claimable.test.js b/test/ownership/Claimable.test.js index 52340fb94..e0b394a07 100644 --- a/test/ownership/Claimable.test.js +++ b/test/ownership/Claimable.test.js @@ -1,5 +1,4 @@ - -import assertRevert from '../helpers/assertRevert'; +const { assertRevert } = require('../helpers/assertRevert'); var Claimable = artifacts.require('Claimable'); diff --git a/test/ownership/Contactable.test.js b/test/ownership/Contactable.test.js index 901ba4824..11a8f2999 100644 --- a/test/ownership/Contactable.test.js +++ b/test/ownership/Contactable.test.js @@ -1,4 +1,3 @@ - var Contactable = artifacts.require('Contactable'); contract('Contactable', function (accounts) { diff --git a/test/ownership/DelayedClaimable.test.js b/test/ownership/DelayedClaimable.test.js index 90be7fbc9..193a9c3d8 100644 --- a/test/ownership/DelayedClaimable.test.js +++ b/test/ownership/DelayedClaimable.test.js @@ -1,4 +1,4 @@ -import assertRevert from '../helpers/assertRevert'; +const { assertRevert } = require('../helpers/assertRevert'); var DelayedClaimable = artifacts.require('DelayedClaimable'); diff --git a/test/ownership/HasNoContracts.test.js b/test/ownership/HasNoContracts.test.js index f2020a173..cc56a46e7 100644 --- a/test/ownership/HasNoContracts.test.js +++ b/test/ownership/HasNoContracts.test.js @@ -1,5 +1,4 @@ - -import expectThrow from '../helpers/expectThrow'; +const { expectThrow } = require('../helpers/expectThrow'); const Ownable = artifacts.require('Ownable'); const HasNoContracts = artifacts.require('HasNoContracts'); diff --git a/test/ownership/HasNoEther.test.js b/test/ownership/HasNoEther.test.js index a586051d7..2068fe864 100644 --- a/test/ownership/HasNoEther.test.js +++ b/test/ownership/HasNoEther.test.js @@ -1,5 +1,5 @@ -import { ethSendTransaction, ethGetBalance } from '../helpers/web3'; -import expectThrow from '../helpers/expectThrow'; +const { expectThrow } = require('../helpers/expectThrow'); +const { ethSendTransaction, ethGetBalance } = require('../helpers/web3'); const HasNoEtherTest = artifacts.require('HasNoEtherTest'); const ForceEther = artifacts.require('ForceEther'); diff --git a/test/ownership/HasNoTokens.test.js b/test/ownership/HasNoTokens.test.js index e9c14a7f5..5dd499fe2 100644 --- a/test/ownership/HasNoTokens.test.js +++ b/test/ownership/HasNoTokens.test.js @@ -1,5 +1,4 @@ - -import expectThrow from '../helpers/expectThrow'; +const { expectThrow } = require('../helpers/expectThrow'); const HasNoTokens = artifacts.require('HasNoTokens'); const ERC223TokenMock = artifacts.require('ERC223TokenMock'); diff --git a/test/ownership/Ownable.behaviour.js b/test/ownership/Ownable.behaviour.js index bd0a1f4b7..4d9ba7ebb 100644 --- a/test/ownership/Ownable.behaviour.js +++ b/test/ownership/Ownable.behaviour.js @@ -1,4 +1,4 @@ -import EVMRevert from '../helpers/EVMRevert'; +const { EVMRevert } = require('../helpers/EVMRevert'); const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; @@ -6,7 +6,7 @@ require('chai') .use(require('chai-as-promised')) .should(); -export default function (accounts) { +function shouldBehaveLikeOwnable (accounts) { describe('as an ownable', function () { it('should have an owner', async function () { let owner = await this.ownable.owner(); @@ -47,4 +47,8 @@ export default function (accounts) { await this.ownable.renounceOwnership({ from: other }).should.be.rejectedWith(EVMRevert); }); }); +} + +module.exports = { + shouldBehaveLikeOwnable, }; diff --git a/test/ownership/Ownable.test.js b/test/ownership/Ownable.test.js index 88d6e750a..fea51b77a 100644 --- a/test/ownership/Ownable.test.js +++ b/test/ownership/Ownable.test.js @@ -1,4 +1,4 @@ -import shouldBehaveLikeOwnable from './Ownable.behaviour'; +const { shouldBehaveLikeOwnable } = require('./Ownable.behaviour'); const Ownable = artifacts.require('Ownable'); diff --git a/test/ownership/Superuser.test.js b/test/ownership/Superuser.test.js index 3eb85f846..e0e5a6497 100644 --- a/test/ownership/Superuser.test.js +++ b/test/ownership/Superuser.test.js @@ -1,5 +1,5 @@ -import expectThrow from '../helpers/expectThrow'; -import expectEvent from '../helpers/expectEvent'; +const { expectThrow } = require('../helpers/expectThrow'); +const expectEvent = require('../helpers/expectEvent'); const Superuser = artifacts.require('Superuser'); @@ -27,7 +27,7 @@ contract('Superuser', function (accounts) { it('should change superuser after transferring', async function () { await this.superuser.transferSuperuser(newSuperuser, { from: firstOwner }); - + const ownerIsSuperuser = await this.superuser.isSuperuser(firstOwner); ownerIsSuperuser.should.be.equal(false); diff --git a/test/ownership/Whitelist.test.js b/test/ownership/Whitelist.test.js index 15e083c55..57ccac4d9 100644 --- a/test/ownership/Whitelist.test.js +++ b/test/ownership/Whitelist.test.js @@ -1,5 +1,5 @@ -import expectThrow from '../helpers/expectThrow'; -import expectEvent from '../helpers/expectEvent'; +const { expectThrow } = require('../helpers/expectThrow'); +const expectEvent = require('../helpers/expectEvent'); const WhitelistMock = artifacts.require('WhitelistMock'); diff --git a/test/ownership/rbac/RBAC.test.js b/test/ownership/rbac/RBAC.test.js index e748efba5..5a2543307 100644 --- a/test/ownership/rbac/RBAC.test.js +++ b/test/ownership/rbac/RBAC.test.js @@ -1,5 +1,5 @@ -import expectThrow from '../../helpers/expectThrow'; -import expectEvent from '../../helpers/expectEvent'; +const { expectThrow } = require('../../helpers/expectThrow'); +const expectEvent = require('../../helpers/expectEvent'); const RBACMock = artifacts.require('RBACMock'); diff --git a/test/payment/ConditionalEscrow.test.js b/test/payment/ConditionalEscrow.test.js index 3d8dfccfc..792752f24 100644 --- a/test/payment/ConditionalEscrow.test.js +++ b/test/payment/ConditionalEscrow.test.js @@ -1,5 +1,5 @@ -import shouldBehaveLikeEscrow from './Escrow.behaviour'; -import EVMRevert from '../helpers/EVMRevert'; +const { shouldBehaveLikeEscrow } = require('./Escrow.behaviour'); +const { EVMRevert } = require('../helpers/EVMRevert'); const BigNumber = web3.BigNumber; diff --git a/test/payment/Escrow.behaviour.js b/test/payment/Escrow.behaviour.js index eb9d11909..652a1fe86 100644 --- a/test/payment/Escrow.behaviour.js +++ b/test/payment/Escrow.behaviour.js @@ -1,6 +1,6 @@ -import expectEvent from '../helpers/expectEvent'; -import EVMRevert from '../helpers/EVMRevert'; -import { ethGetBalance } from '../helpers/web3'; +const expectEvent = require('../helpers/expectEvent'); +const { EVMRevert } = require('../helpers/EVMRevert'); +const { ethGetBalance } = require('../helpers/web3'); const BigNumber = web3.BigNumber; @@ -8,7 +8,7 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -export default function (owner, [payee1, payee2]) { +function shouldBehaveLikeEscrow (owner, [payee1, payee2]) { const amount = web3.toWei(42.0, 'ether'); describe('as an escrow', function () { @@ -96,4 +96,8 @@ export default function (owner, [payee1, payee2]) { }); }); }); +} + +module.exports = { + shouldBehaveLikeEscrow, }; diff --git a/test/payment/Escrow.test.js b/test/payment/Escrow.test.js index 0b2319efc..7047cfd9c 100644 --- a/test/payment/Escrow.test.js +++ b/test/payment/Escrow.test.js @@ -1,4 +1,4 @@ -import shouldBehaveLikeEscrow from './Escrow.behaviour'; +const { shouldBehaveLikeEscrow } = require('./Escrow.behaviour'); const Escrow = artifacts.require('Escrow'); diff --git a/test/payment/PullPayment.test.js b/test/payment/PullPayment.test.js index c2dc421d7..9609fd459 100644 --- a/test/payment/PullPayment.test.js +++ b/test/payment/PullPayment.test.js @@ -1,4 +1,4 @@ -import { ethGetBalance } from '../helpers/web3'; +const { ethGetBalance } = require('../helpers/web3'); const BigNumber = web3.BigNumber; diff --git a/test/payment/RefundEscrow.test.js b/test/payment/RefundEscrow.test.js index 34971dfa3..58d1ec787 100644 --- a/test/payment/RefundEscrow.test.js +++ b/test/payment/RefundEscrow.test.js @@ -1,6 +1,6 @@ -import EVMRevert from '../helpers/EVMRevert'; -import expectEvent from '../helpers/expectEvent'; -import { ethGetBalance } from '../helpers/web3'; +const { EVMRevert } = require('../helpers/EVMRevert'); +const expectEvent = require('../helpers/expectEvent'); +const { ethGetBalance } = require('../helpers/web3'); const BigNumber = web3.BigNumber; diff --git a/test/payment/SplitPayment.test.js b/test/payment/SplitPayment.test.js index 92b682aa9..dcb52ae66 100644 --- a/test/payment/SplitPayment.test.js +++ b/test/payment/SplitPayment.test.js @@ -1,4 +1,4 @@ -import { ethGetBalance, ethSendTransaction } from '../helpers/web3'; +const { ethGetBalance, ethSendTransaction } = require('../helpers/web3'); const BigNumber = web3.BigNumber; diff --git a/test/token/ERC20/BasicToken.test.js b/test/token/ERC20/BasicToken.test.js index 3e8170465..4a2d3bdc1 100644 --- a/test/token/ERC20/BasicToken.test.js +++ b/test/token/ERC20/BasicToken.test.js @@ -1,4 +1,4 @@ -import assertRevert from '../../helpers/assertRevert'; +const { assertRevert } = require('../../helpers/assertRevert'); const BasicToken = artifacts.require('BasicTokenMock'); contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { diff --git a/test/token/ERC20/BurnableToken.behaviour.js b/test/token/ERC20/BurnableToken.behaviour.js index c3793bc1a..a793d0472 100644 --- a/test/token/ERC20/BurnableToken.behaviour.js +++ b/test/token/ERC20/BurnableToken.behaviour.js @@ -1,5 +1,5 @@ -import assertRevert from '../../helpers/assertRevert'; -import { inLogs } from '../../helpers/expectEvent'; +const { assertRevert } = require('../../helpers/assertRevert'); +const { inLogs } = require('../../helpers/expectEvent'); const BigNumber = web3.BigNumber; const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; @@ -9,7 +9,7 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -export default function ([owner], initialBalance) { +function shouldBehaveLikeBurnableToken ([owner], initialBalance) { describe('as a basic burnable token', function () { const from = owner; @@ -47,4 +47,8 @@ export default function ([owner], initialBalance) { }); }); }); +} + +module.exports = { + shouldBehaveLikeBurnableToken, }; diff --git a/test/token/ERC20/BurnableToken.test.js b/test/token/ERC20/BurnableToken.test.js index 1b0c7bb30..4e1f3fa0c 100644 --- a/test/token/ERC20/BurnableToken.test.js +++ b/test/token/ERC20/BurnableToken.test.js @@ -1,4 +1,4 @@ -import shouldBehaveLikeBurnableToken from './BurnableToken.behaviour'; +const { shouldBehaveLikeBurnableToken } = require('./BurnableToken.behaviour'); const BurnableTokenMock = artifacts.require('BurnableTokenMock'); contract('BurnableToken', function ([owner]) { diff --git a/test/token/ERC20/CappedToken.behaviour.js b/test/token/ERC20/CappedToken.behaviour.js index 9dadc40f2..d2586929d 100644 --- a/test/token/ERC20/CappedToken.behaviour.js +++ b/test/token/ERC20/CappedToken.behaviour.js @@ -1,7 +1,7 @@ -import expectThrow from '../../helpers/expectThrow'; +const { expectThrow } = require('../../helpers/expectThrow'); -export default function ([owner, anotherAccount, minter, cap]) { - describe('capped token', function () { +function shouldBehaveLikeCappedToken ([owner, anotherAccount, minter, cap]) { + describe('capped token', function () { const from = minter; it('should start with the correct cap', async function () { @@ -25,4 +25,8 @@ export default function ([owner, anotherAccount, minter, cap]) { await expectThrow(this.token.mint(owner, 1, { from })); }); }); -} +} + +module.exports = { + shouldBehaveLikeCappedToken, +}; diff --git a/test/token/ERC20/CappedToken.test.js b/test/token/ERC20/CappedToken.test.js index 4eae4b800..cc27f2edd 100644 --- a/test/token/ERC20/CappedToken.test.js +++ b/test/token/ERC20/CappedToken.test.js @@ -1,12 +1,12 @@ -import ether from '../../helpers/ether'; -import shouldBehaveLikeMintableToken from './MintableToken.behaviour'; -import shouldBehaveLikeCappedToken from './CappedToken.behaviour'; +const { ether } = require('../../helpers/ether'); +const { shouldBehaveLikeMintableToken } = require('./MintableToken.behaviour'); +const { shouldBehaveLikeCappedToken } = require('./CappedToken.behaviour'); var CappedToken = artifacts.require('CappedToken'); contract('Capped', function ([owner, anotherAccount]) { const _cap = ether(1000); - + beforeEach(async function () { this.token = await CappedToken.new(_cap, { from: owner }); }); diff --git a/test/token/ERC20/MintableToken.behaviour.js b/test/token/ERC20/MintableToken.behaviour.js index 639bef7cc..88e7eeae7 100644 --- a/test/token/ERC20/MintableToken.behaviour.js +++ b/test/token/ERC20/MintableToken.behaviour.js @@ -1,4 +1,4 @@ -import assertRevert from '../../helpers/assertRevert'; +const { assertRevert } = require('../../helpers/assertRevert'); const BigNumber = web3.BigNumber; @@ -7,7 +7,7 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -export default function ([owner, anotherAccount, minter]) { +function shouldBehaveLikeMintableToken ([owner, anotherAccount, minter]) { describe('as a basic mintable token', function () { describe('after token creation', function () { it('sender should be token owner', async function () { @@ -145,4 +145,8 @@ export default function ([owner, anotherAccount, minter]) { }); }); }); +} + +module.exports = { + shouldBehaveLikeMintableToken, }; diff --git a/test/token/ERC20/MintableToken.test.js b/test/token/ERC20/MintableToken.test.js index 8a7331d7a..faf3c64d2 100644 --- a/test/token/ERC20/MintableToken.test.js +++ b/test/token/ERC20/MintableToken.test.js @@ -1,4 +1,4 @@ -import shouldBehaveLikeMintableToken from './MintableToken.behaviour'; +const { shouldBehaveLikeMintableToken } = require('./MintableToken.behaviour'); const MintableToken = artifacts.require('MintableToken'); contract('MintableToken', function ([owner, anotherAccount]) { diff --git a/test/token/ERC20/PausableToken.test.js b/test/token/ERC20/PausableToken.test.js index 46e30ee33..b138fcc04 100644 --- a/test/token/ERC20/PausableToken.test.js +++ b/test/token/ERC20/PausableToken.test.js @@ -1,4 +1,4 @@ -import assertRevert from '../../helpers/assertRevert'; +const { assertRevert } = require('../../helpers/assertRevert'); const PausableToken = artifacts.require('PausableTokenMock'); contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { diff --git a/test/token/ERC20/RBACCappedToken.test.js b/test/token/ERC20/RBACCappedToken.test.js index 2bf915714..cb457c979 100644 --- a/test/token/ERC20/RBACCappedToken.test.js +++ b/test/token/ERC20/RBACCappedToken.test.js @@ -1,7 +1,7 @@ -import ether from '../../helpers/ether'; -import shouldBehaveLikeRBACMintableToken from './RBACMintableToken.behaviour'; -import shouldBehaveLikeMintableToken from './MintableToken.behaviour'; -import shouldBehaveLikeCappedToken from './CappedToken.behaviour'; +const { ether } = require('../../helpers/ether'); +const { shouldBehaveLikeRBACMintableToken } = require('./RBACMintableToken.behaviour'); +const { shouldBehaveLikeMintableToken } = require('./MintableToken.behaviour'); +const { shouldBehaveLikeCappedToken } = require('./CappedToken.behaviour'); const RBACCappedTokenMock = artifacts.require('RBACCappedTokenMock'); diff --git a/test/token/ERC20/RBACMintableToken.behaviour.js b/test/token/ERC20/RBACMintableToken.behaviour.js index 006e2e06b..7ca3cc3ca 100644 --- a/test/token/ERC20/RBACMintableToken.behaviour.js +++ b/test/token/ERC20/RBACMintableToken.behaviour.js @@ -1,8 +1,8 @@ -import expectThrow from '../../helpers/expectThrow'; +const { expectThrow } = require('../../helpers/expectThrow'); const ROLE_MINTER = 'minter'; -export default function ([owner, anotherAccount]) { +function shouldBehaveLikeRBACMintableToken ([owner, anotherAccount]) { describe('handle roles', function () { it('owner can add and remove a minter role', async function () { await this.token.addMinter(anotherAccount, { from: owner }); @@ -24,5 +24,9 @@ export default function ([owner, anotherAccount]) { this.token.removeMinter(anotherAccount, { from: anotherAccount }) ); }); - }); + }); +} + +module.exports = { + shouldBehaveLikeRBACMintableToken, }; diff --git a/test/token/ERC20/RBACMintableToken.test.js b/test/token/ERC20/RBACMintableToken.test.js index ff95b4a5a..2617bfb61 100644 --- a/test/token/ERC20/RBACMintableToken.test.js +++ b/test/token/ERC20/RBACMintableToken.test.js @@ -1,5 +1,5 @@ -import shouldBehaveLikeRBACMintableToken from './RBACMintableToken.behaviour'; -import shouldBehaveLikeMintableToken from './MintableToken.behaviour'; +const { shouldBehaveLikeRBACMintableToken } = require('./RBACMintableToken.behaviour'); +const { shouldBehaveLikeMintableToken } = require('./MintableToken.behaviour'); const RBACMintableToken = artifacts.require('RBACMintableToken'); diff --git a/test/token/ERC20/SafeERC20.test.js b/test/token/ERC20/SafeERC20.test.js index 03ec3fee8..4b5d7f7f9 100644 --- a/test/token/ERC20/SafeERC20.test.js +++ b/test/token/ERC20/SafeERC20.test.js @@ -1,4 +1,4 @@ -import EVMRevert from '../../helpers/EVMRevert'; +const { EVMRevert } = require('../../helpers/EVMRevert'); require('chai') .use(require('chai-as-promised')) diff --git a/test/token/ERC20/StandardBurnableToken.test.js b/test/token/ERC20/StandardBurnableToken.test.js index f51438fcf..40dc10562 100644 --- a/test/token/ERC20/StandardBurnableToken.test.js +++ b/test/token/ERC20/StandardBurnableToken.test.js @@ -1,6 +1,6 @@ -import assertRevert from '../../helpers/assertRevert'; -import { inLogs } from '../../helpers/expectEvent'; -import shouldBehaveLikeBurnableToken from './BurnableToken.behaviour'; +const { assertRevert } = require('../../helpers/assertRevert'); +const { inLogs } = require('../../helpers/expectEvent'); +const { shouldBehaveLikeBurnableToken } = require('./BurnableToken.behaviour'); const StandardBurnableTokenMock = artifacts.require('StandardBurnableTokenMock'); const BigNumber = web3.BigNumber; @@ -13,7 +13,7 @@ require('chai') contract('StandardBurnableToken', function ([owner, burner]) { const initialBalance = 1000; - + beforeEach(async function () { this.token = await StandardBurnableTokenMock.new(owner, initialBalance); }); diff --git a/test/token/ERC20/StandardToken.test.js b/test/token/ERC20/StandardToken.test.js index 4d27b9dba..18239f2a4 100644 --- a/test/token/ERC20/StandardToken.test.js +++ b/test/token/ERC20/StandardToken.test.js @@ -1,4 +1,4 @@ -import assertRevert from '../../helpers/assertRevert'; +const { assertRevert } = require('../../helpers/assertRevert'); const StandardTokenMock = artifacts.require('StandardTokenMock'); contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { diff --git a/test/token/ERC20/TokenTimelock.test.js b/test/token/ERC20/TokenTimelock.test.js index 0c5ad744b..cb65fd421 100644 --- a/test/token/ERC20/TokenTimelock.test.js +++ b/test/token/ERC20/TokenTimelock.test.js @@ -1,5 +1,5 @@ -import latestTime from '../../helpers/latestTime'; -import { increaseTimeTo, duration } from '../../helpers/increaseTime'; +const { latestTime } = require('../../helpers/latestTime'); +const { increaseTimeTo, duration } = require('../../helpers/increaseTime'); const BigNumber = web3.BigNumber; diff --git a/test/token/ERC20/TokenVesting.test.js b/test/token/ERC20/TokenVesting.test.js index 8c33250ae..42659cee8 100644 --- a/test/token/ERC20/TokenVesting.test.js +++ b/test/token/ERC20/TokenVesting.test.js @@ -1,7 +1,7 @@ -import EVMRevert from '../../helpers/EVMRevert'; -import latestTime from '../../helpers/latestTime'; -import { increaseTimeTo, duration } from '../../helpers/increaseTime'; -import { ethGetBlock } from '../../helpers/web3'; +const { EVMRevert } = require('../../helpers/EVMRevert'); +const { latestTime } = require('../../helpers/latestTime'); +const { increaseTimeTo, duration } = require('../../helpers/increaseTime'); +const { ethGetBlock } = require('../../helpers/web3'); const BigNumber = web3.BigNumber; diff --git a/test/token/ERC721/ERC721BasicToken.behaviour.js b/test/token/ERC721/ERC721BasicToken.behaviour.js index 35f04af76..bf14a573a 100644 --- a/test/token/ERC721/ERC721BasicToken.behaviour.js +++ b/test/token/ERC721/ERC721BasicToken.behaviour.js @@ -1,8 +1,8 @@ -import shouldSupportInterfaces from '../../introspection/SupportsInterface.behavior'; -import assertRevert from '../../helpers/assertRevert'; -import decodeLogs from '../../helpers/decodeLogs'; -import sendTransaction from '../../helpers/sendTransaction'; -import _ from 'lodash'; +const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior'); +const { assertRevert } = require('../../helpers/assertRevert'); +const { decodeLogs } = require('../../helpers/decodeLogs'); +const { sendTransaction } = require('../../helpers/sendTransaction'); +const _ = require('lodash'); const ERC721Receiver = artifacts.require('ERC721ReceiverMock.sol'); const BigNumber = web3.BigNumber; @@ -12,7 +12,7 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -export default function shouldBehaveLikeERC721BasicToken (accounts) { +function shouldBehaveLikeERC721BasicToken (accounts) { const firstTokenId = 1; const secondTokenId = 2; const unknownTokenId = 3; @@ -558,4 +558,8 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) { 'ERC721Exists', ]); }); +} + +module.exports = { + shouldBehaveLikeERC721BasicToken, }; diff --git a/test/token/ERC721/ERC721BasicToken.test.js b/test/token/ERC721/ERC721BasicToken.test.js index 05666f5aa..65aeb12d5 100644 --- a/test/token/ERC721/ERC721BasicToken.test.js +++ b/test/token/ERC721/ERC721BasicToken.test.js @@ -1,5 +1,5 @@ -import shouldBehaveLikeERC721BasicToken from './ERC721BasicToken.behaviour'; -import shouldMintAndBurnERC721Token from './ERC721MintBurn.behaviour'; +const { shouldBehaveLikeERC721BasicToken } = require('./ERC721BasicToken.behaviour'); +const { shouldBehaveLikeMintAndBurnERC721Token } = require('./ERC721MintBurn.behaviour'); const BigNumber = web3.BigNumber; const ERC721BasicToken = artifacts.require('ERC721BasicTokenMock.sol'); @@ -15,5 +15,5 @@ contract('ERC721BasicToken', function (accounts) { }); shouldBehaveLikeERC721BasicToken(accounts); - shouldMintAndBurnERC721Token(accounts); + shouldBehaveLikeMintAndBurnERC721Token(accounts); }); diff --git a/test/token/ERC721/ERC721MintBurn.behaviour.js b/test/token/ERC721/ERC721MintBurn.behaviour.js index b2ab6a988..01e4c2ff1 100644 --- a/test/token/ERC721/ERC721MintBurn.behaviour.js +++ b/test/token/ERC721/ERC721MintBurn.behaviour.js @@ -1,4 +1,4 @@ -import assertRevert from '../../helpers/assertRevert'; +const { assertRevert } = require('../../helpers/assertRevert'); const BigNumber = web3.BigNumber; require('chai') @@ -6,7 +6,7 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -export default function shouldMintAndBurnERC721Token (accounts) { +function shouldBehaveLikeMintAndBurnERC721Token (accounts) { const firstTokenId = 1; const secondTokenId = 2; const unknownTokenId = 3; @@ -23,7 +23,7 @@ export default function shouldMintAndBurnERC721Token (accounts) { const to = accounts[1]; const tokenId = unknownTokenId; let logs = null; - + describe('when successful', function () { beforeEach(async function () { const result = await this.token.mint(to, tokenId); @@ -108,4 +108,8 @@ export default function shouldMintAndBurnERC721Token (accounts) { }); }); }); +} + +module.exports = { + shouldBehaveLikeMintAndBurnERC721Token, }; diff --git a/test/token/ERC721/ERC721Token.test.js b/test/token/ERC721/ERC721Token.test.js index 0f50d90e0..ae2c9d859 100644 --- a/test/token/ERC721/ERC721Token.test.js +++ b/test/token/ERC721/ERC721Token.test.js @@ -1,8 +1,8 @@ -import assertRevert from '../../helpers/assertRevert'; -import shouldBehaveLikeERC721BasicToken from './ERC721BasicToken.behaviour'; -import shouldMintAndBurnERC721Token from './ERC721MintBurn.behaviour'; -import shouldSupportInterfaces from '../../introspection/SupportsInterface.behavior'; -import _ from 'lodash'; +const { assertRevert } = require('../../helpers/assertRevert'); +const { shouldBehaveLikeERC721BasicToken } = require('./ERC721BasicToken.behaviour'); +const { shouldBehaveLikeMintAndBurnERC721Token } = require('./ERC721MintBurn.behaviour'); +const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior'); +const _ = require('lodash'); const BigNumber = web3.BigNumber; const ERC721Token = artifacts.require('ERC721TokenMock.sol'); @@ -24,7 +24,7 @@ contract('ERC721Token', function (accounts) { }); shouldBehaveLikeERC721BasicToken(accounts); - shouldMintAndBurnERC721Token(accounts); + shouldBehaveLikeMintAndBurnERC721Token(accounts); describe('like a full ERC721', function () { beforeEach(async function () { diff --git a/truffle-config.js b/truffle-config.js index a5ca2558e..52708daa9 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -1,6 +1,4 @@ require('dotenv').config(); -require('babel-register'); -require('babel-polyfill'); const HDWalletProvider = require('truffle-hdwallet-provider');