Migration to truffle 5 (and web3 1.0 (and BN)) (#1601)
* Now compiling using truffle 5.
* Migrated some test files, missing BN scientific notation usage.
* Now using BN time values.
* Migrate ERC20 tests.
* Migrate all ERC20 tests.
* Migrate utils, payment and ownership tests.
* All tests save ERC721 migrated.
* Migrated ERC721 tests.
* Fix lint errors.
* Delete old test helpers.
* Fix remaining crowdsale tests.
* Fix signature bouncer tests.
* Update how constants is used.
* Compile script pre-removes the build dir.
* Fix SafeMath tests.
* Revert "Compile script pre-removes the build dir."
This reverts commit 247e745113.
* Fix linter errors.
* Upgrade openzeppelin-test-helpers dependency.
* Update openzeppelin-test-helpers dependency.
* Define math constants globally.
* Remove unnecessary ether unit.
* Roll back reduced ether amounts in tests.
* Remove unnecessary toNumber conversions.
* Delete compile script.
* Fixed failing test.
This commit is contained in:
@ -1,60 +0,0 @@
|
||||
const { ethGetBlock } = require('./web3');
|
||||
const pify = require('pify');
|
||||
|
||||
function advanceBlock () {
|
||||
return pify(web3.currentProvider.sendAsync)({
|
||||
jsonrpc: '2.0',
|
||||
method: 'evm_mine',
|
||||
});
|
||||
}
|
||||
|
||||
// Returns the time of the last mined block in seconds
|
||||
async function latest () {
|
||||
const block = await ethGetBlock('latest');
|
||||
return block.timestamp;
|
||||
}
|
||||
|
||||
// Increases ganache time by the passed duration in seconds
|
||||
async function increase (duration) {
|
||||
if (duration < 0) throw Error(`Cannot increase time by a negative amount (${duration})`);
|
||||
|
||||
await pify(web3.currentProvider.sendAsync)({
|
||||
jsonrpc: '2.0',
|
||||
method: 'evm_increaseTime',
|
||||
params: [duration],
|
||||
});
|
||||
|
||||
await advanceBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Beware that due to the need of calling two separate ganache methods and rpc calls overhead
|
||||
* it's hard to increase time precisely to a target point so design your test to tolerate
|
||||
* small fluctuations from time to time.
|
||||
*
|
||||
* @param target time in seconds
|
||||
*/
|
||||
async function increaseTo (target) {
|
||||
const now = (await latest());
|
||||
|
||||
if (target < now) throw Error(`Cannot increase current time (${now}) to a moment in the past (${target})`);
|
||||
const diff = target - now;
|
||||
return increase(diff);
|
||||
}
|
||||
|
||||
const duration = {
|
||||
seconds: function (val) { return val; },
|
||||
minutes: function (val) { return val * this.seconds(60); },
|
||||
hours: function (val) { return val * this.minutes(60); },
|
||||
days: function (val) { return val * this.hours(24); },
|
||||
weeks: function (val) { return val * this.days(7); },
|
||||
years: function (val) { return val * this.days(365); },
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
advanceBlock,
|
||||
latest,
|
||||
increase,
|
||||
increaseTo,
|
||||
duration,
|
||||
};
|
||||
Reference in New Issue
Block a user