Remove Babel (#1074)

* Test helpers no longer rely on Babel.

* Behaviours are no longer imported.

* Removed Babel dependency.

* Fixed linter errors.
pull/1023/head
Nicolás Venturo 7 years ago committed by GitHub
parent 99e4b081dc
commit cea2a85a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      package-lock.json
  2. 5
      package.json
  3. 7
      test/Bounty.test.js
  4. 6
      test/Heritable.test.js
  5. 4
      test/LimitBalance.test.js
  6. 3
      test/ReentrancyGuard.test.js
  7. 5
      test/SimpleSavingsWallet.test.js
  8. 11
      test/access/SignatureBouncer.test.js
  9. 7
      test/crowdsale/AllowanceCrowdsale.test.js
  10. 4
      test/crowdsale/CappedCrowdsale.test.js
  11. 4
      test/crowdsale/Crowdsale.test.js
  12. 8
      test/crowdsale/FinalizableCrowdsale.test.js
  13. 8
      test/crowdsale/IncreasingPriceCrowdsale.test.js
  14. 4
      test/crowdsale/IndividuallyCappedCrowdsale.test.js
  15. 8
      test/crowdsale/MintedCrowdsale.behaviour.js
  16. 4
      test/crowdsale/MintedCrowdsale.test.js
  17. 10
      test/crowdsale/PostDeliveryCrowdsale.test.js
  18. 12
      test/crowdsale/RefundableCrowdsale.test.js
  19. 10
      test/crowdsale/TimedCrowdsale.test.js
  20. 2
      test/crowdsale/WhitelistedCrowdsale.test.js
  21. 14
      test/examples/SampleCrowdsale.test.js
  22. 2
      test/examples/SimpleToken.test.js
  23. 6
      test/helpers/EVMRevert.js
  24. 6
      test/helpers/EVMThrow.js
  25. 9
      test/helpers/advanceToBlock.js
  26. 6
      test/helpers/assertJump.js
  27. 6
      test/helpers/assertRevert.js
  28. 6
      test/helpers/decodeLogs.js
  29. 6
      test/helpers/ether.js
  30. 8
      test/helpers/expectEvent.js
  31. 6
      test/helpers/expectThrow.js
  32. 15
      test/helpers/increaseTime.js
  33. 8
      test/helpers/latestTime.js
  34. 8
      test/helpers/makeInterfaceId.js
  35. 8
      test/helpers/merkleTree.js
  36. 9
      test/helpers/sendTransaction.js
  37. 18
      test/helpers/sign.js
  38. 11
      test/helpers/transactionMined.js
  39. 8
      test/helpers/web3.js
  40. 8
      test/introspection/SupportsInterface.behavior.js
  41. 4
      test/introspection/SupportsInterfaceWithLookup.test.js
  42. 7
      test/library/ECRecovery.test.js
  43. 5
      test/library/MerkleProof.test.js
  44. 6
      test/lifecycle/Destructible.test.js
  45. 3
      test/lifecycle/Pausable.test.js
  46. 3
      test/lifecycle/TokenDestructible.test.js
  47. 2
      test/math/SafeMath.test.js
  48. 3
      test/ownership/CanReclaimToken.test.js
  49. 3
      test/ownership/Claimable.test.js
  50. 1
      test/ownership/Contactable.test.js
  51. 2
      test/ownership/DelayedClaimable.test.js
  52. 3
      test/ownership/HasNoContracts.test.js
  53. 4
      test/ownership/HasNoEther.test.js
  54. 3
      test/ownership/HasNoTokens.test.js
  55. 8
      test/ownership/Ownable.behaviour.js
  56. 2
      test/ownership/Ownable.test.js
  57. 6
      test/ownership/Superuser.test.js
  58. 4
      test/ownership/Whitelist.test.js
  59. 4
      test/ownership/rbac/RBAC.test.js
  60. 4
      test/payment/ConditionalEscrow.test.js
  61. 12
      test/payment/Escrow.behaviour.js
  62. 2
      test/payment/Escrow.test.js
  63. 2
      test/payment/PullPayment.test.js
  64. 6
      test/payment/RefundEscrow.test.js
  65. 2
      test/payment/SplitPayment.test.js
  66. 2
      test/token/ERC20/BasicToken.test.js
  67. 10
      test/token/ERC20/BurnableToken.behaviour.js
  68. 2
      test/token/ERC20/BurnableToken.test.js
  69. 12
      test/token/ERC20/CappedToken.behaviour.js
  70. 8
      test/token/ERC20/CappedToken.test.js
  71. 8
      test/token/ERC20/MintableToken.behaviour.js
  72. 2
      test/token/ERC20/MintableToken.test.js
  73. 2
      test/token/ERC20/PausableToken.test.js
  74. 8
      test/token/ERC20/RBACCappedToken.test.js
  75. 10
      test/token/ERC20/RBACMintableToken.behaviour.js
  76. 4
      test/token/ERC20/RBACMintableToken.test.js
  77. 2
      test/token/ERC20/SafeERC20.test.js
  78. 8
      test/token/ERC20/StandardBurnableToken.test.js
  79. 2
      test/token/ERC20/StandardToken.test.js
  80. 4
      test/token/ERC20/TokenTimelock.test.js
  81. 8
      test/token/ERC20/TokenVesting.test.js
  82. 16
      test/token/ERC721/ERC721BasicToken.behaviour.js
  83. 6
      test/token/ERC721/ERC721BasicToken.test.js
  84. 10
      test/token/ERC721/ERC721MintBurn.behaviour.js
  85. 12
      test/token/ERC721/ERC721Token.test.js
  86. 2
      truffle-config.js

31
package-lock.json generated

@ -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",

@ -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",

@ -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) => {

@ -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';

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

@ -1,5 +1,4 @@
import expectThrow from './helpers/expectThrow';
const { expectThrow } = require('./helpers/expectThrow');
const ReentrancyMock = artifacts.require('ReentrancyMock');
const ReentrancyAttack = artifacts.require('ReentrancyAttack');

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -1,4 +1,4 @@
import ether from '../helpers/ether';
const { ether } = require('../helpers/ether');
const BigNumber = web3.BigNumber;

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

@ -1,4 +1,4 @@
import decodeLogs from '../helpers/decodeLogs';
const { decodeLogs } = require('../helpers/decodeLogs');
const SimpleToken = artifacts.require('SimpleToken');
contract('SimpleToken', accounts => {

@ -1 +1,5 @@
export default 'revert';
const EVMRevert = 'revert';
module.exports = {
EVMRevert,
};

@ -1 +1,5 @@
export default 'invalid opcode';
const EVMThrow = 'invalid opcode';
module.exports = {
EVMThrow,
};

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

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

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

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

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

@ -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,

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

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

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

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

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

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

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

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

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

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

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

@ -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')

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

@ -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 () {

@ -1,5 +1,4 @@
import assertRevert from '../helpers/assertRevert';
const { assertRevert } = require('../helpers/assertRevert');
const PausableMock = artifacts.require('PausableMock');
contract('Pausable', function (accounts) {

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

@ -1,4 +1,4 @@
import assertJump from '../helpers/assertJump';
const { assertJump } = require('../helpers/assertJump');
const BigNumber = web3.BigNumber;
const SafeMathMock = artifacts.require('SafeMathMock');

@ -1,5 +1,4 @@
import expectThrow from '../helpers/expectThrow';
const { expectThrow } = require('../helpers/expectThrow');
const CanReclaimToken = artifacts.require('CanReclaimToken');
const BasicTokenMock = artifacts.require('BasicTokenMock');

@ -1,5 +1,4 @@
import assertRevert from '../helpers/assertRevert';
const { assertRevert } = require('../helpers/assertRevert');
var Claimable = artifacts.require('Claimable');

@ -1,4 +1,3 @@
var Contactable = artifacts.require('Contactable');
contract('Contactable', function (accounts) {

@ -1,4 +1,4 @@
import assertRevert from '../helpers/assertRevert';
const { assertRevert } = require('../helpers/assertRevert');
var DelayedClaimable = artifacts.require('DelayedClaimable');

@ -1,5 +1,4 @@
import expectThrow from '../helpers/expectThrow';
const { expectThrow } = require('../helpers/expectThrow');
const Ownable = artifacts.require('Ownable');
const HasNoContracts = artifacts.require('HasNoContracts');

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

@ -1,5 +1,4 @@
import expectThrow from '../helpers/expectThrow';
const { expectThrow } = require('../helpers/expectThrow');
const HasNoTokens = artifacts.require('HasNoTokens');
const ERC223TokenMock = artifacts.require('ERC223TokenMock');

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

@ -1,4 +1,4 @@
import shouldBehaveLikeOwnable from './Ownable.behaviour';
const { shouldBehaveLikeOwnable } = require('./Ownable.behaviour');
const Ownable = artifacts.require('Ownable');

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

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

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

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

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

@ -1,4 +1,4 @@
import shouldBehaveLikeEscrow from './Escrow.behaviour';
const { shouldBehaveLikeEscrow } = require('./Escrow.behaviour');
const Escrow = artifacts.require('Escrow');

@ -1,4 +1,4 @@
import { ethGetBalance } from '../helpers/web3';
const { ethGetBalance } = require('../helpers/web3');
const BigNumber = web3.BigNumber;

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

@ -1,4 +1,4 @@
import { ethGetBalance, ethSendTransaction } from '../helpers/web3';
const { ethGetBalance, ethSendTransaction } = require('../helpers/web3');
const BigNumber = web3.BigNumber;

@ -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]) {

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

@ -1,4 +1,4 @@
import shouldBehaveLikeBurnableToken from './BurnableToken.behaviour';
const { shouldBehaveLikeBurnableToken } = require('./BurnableToken.behaviour');
const BurnableTokenMock = artifacts.require('BurnableTokenMock');
contract('BurnableToken', function ([owner]) {

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

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

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

@ -1,4 +1,4 @@
import shouldBehaveLikeMintableToken from './MintableToken.behaviour';
const { shouldBehaveLikeMintableToken } = require('./MintableToken.behaviour');
const MintableToken = artifacts.require('MintableToken');
contract('MintableToken', function ([owner, anotherAccount]) {

@ -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]) {

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

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

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

@ -1,4 +1,4 @@
import EVMRevert from '../../helpers/EVMRevert';
const { EVMRevert } = require('../../helpers/EVMRevert');
require('chai')
.use(require('chai-as-promised'))

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

@ -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]) {

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

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

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

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

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

@ -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 () {

@ -1,6 +1,4 @@
require('dotenv').config();
require('babel-register');
require('babel-polyfill');
const HDWalletProvider = require('truffle-hdwallet-provider');

Loading…
Cancel
Save