Skip to content

Conversation

@nventuro
Copy link
Contributor

Part of #1078.

@nventuro nventuro added kind:improvement tests Test suite and helpers. labels Nov 27, 2018
@nventuro nventuro added this to the Test helpers milestone Nov 27, 2018
@nventuro nventuro requested a review from frangio November 27, 2018 21:14
await time.increase(time.duration.hours(1));

const end = this.start + time.duration.hours(1);
(await time.latest()).should.be.within(end - 20, end + 20); // +-20 sec tolerance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use closeTo. Can we define the tolerance in a file-wide constant?

Also, I'm curious, experimentally, what did you find the actual time increase to be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know about closeTo, thanks!

The time tolerance comes from the last block (and therefore the timestamp) being mined in the previous test, and the time between tests is variable (in particular, the time between ganache being set-up and the first test running may be very large).

I ended up making this more explicit by adding an advanceBlock call before calling latest(), but we should make sure the documentation explains this behavior properly.


describe('increaseTo', function () {
it('increases time to a time in the future', async function () {
await time.increaseTo(this.start + time.duration.hours(1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the end variable defined below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it seems I'm not very smart 😅

Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@nventuro nventuro merged commit 6407d78 into OpenZeppelin:master Nov 27, 2018
@nventuro nventuro deleted the time-tests branch November 27, 2018 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test suite and helpers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants