My tests calls start failing whenever I use evm_increaseTime found this deleted question using google chache, since the question was accidentally deleted.
My situation is quite similar, and it would be awesome if @itinance could elaborate on his solution.
2 Likes
Hi @ccolorado
there is already a library for that thanks to OpenZepplin.
Have a look at my tests: https://github.com/itinance/ncd-token/blob/master/test/NCDTokenSaleTeamTokens.js#L66 , there are plenty examples.
While it is possible to increase to a specific timestamp, I recommend to not use fixed dates because ganache-cli can never roll back. So I constantely increase the time by some delta values into the future.
3 Likes
Welcome to the community @ccolorado
OpenZeppelin Test Helpers are awesome, the README has lots of information on how to use. If you have any questions please ask.
# OpenZeppelin Test Helpers
[![NPM Package](https://img.shields.io/npm/v/openzeppelin-test-helpers.svg)](https://www.npmjs.org/package/openzeppelin-test-helpers)
[![Build Status](https://travis-ci.com/OpenZeppelin/openzeppelin-test-helpers.svg?branch=master)](https://travis-ci.com/OpenZeppelin/openzeppelin-test-helpers)
**JavaScript testing helpers for Ethereum smart contract development.** These are specially suited for [Truffle 5](https://truffleframework.com/truffle) (using [web3 1.0](https://github.com/ethereum/web3.js/)). [Chai](http://chaijs.com/) [bn.js](https://github.com/indutny/bn.js) assertions using [chai-bn](https://github.com/ZeppelinSolutions/chai-bn) are also included.
## Installation
```bash
npm install --save-dev openzeppelin-test-helpers chai
```
## Usage
```javascript
// Import all required modules from openzeppelin-test-helpers
const { BN, constants, expectEvent, expectRevert } = require('openzeppelin-test-helpers');
// Import preferred chai flavor: both expect and should are supported
This file has been truncated. show original
OpenZeppelin tests are great examples of using the Test Helpers. For time
have a look at TimedCrowdsale.test.js
const { BN, ether, expectEvent, expectRevert, time } = require('openzeppelin-test-helpers');
const TimedCrowdsaleImpl = artifacts.require('TimedCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BN(1);
const value = ether('42');
const tokenSupply = new BN('10').pow(new BN('22'));
before(async function () {
// Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache
await time.advanceBlock();
});
beforeEach(async function () {
this.openingTime = (await time.latest()).add(time.duration.weeks(1));
this.closingTime = this.openingTime.add(time.duration.weeks(1));
this.afterClosingTime = this.closingTime.add(time.duration.seconds(1));
this.token = await SimpleToken.new();
This file has been truncated. show original
I undeleted @itinance original topic , so for future people they can find it. Well done on finding the community through that.
1 Like
abcoathup
Split this topic
November 1, 2019, 1:17am
4
A post was split to a new topic: Simulate a date in the future