Test Helpers: Unable to advance to a future block with advanceBlockTo


I am using openzepplin-test-helpers in my tests version 0.5.1
But using time.advanceBlockTo I get openzepplin-test-helpers does not have function advanceBlockTo

1 Like

Hello, we can’t help you if you don’t share your code with us.

1 Like

yeah @martriay

import { time } from “openzeppelin-test-helpers”;
block = await time.latestBlockTo(target)
I get an error latestBlockTo does not exist on openzeppelin-test-helpers

1 Like

I just want to be able to skip a few blocks somehow in my tests

1 Like

Hi @viraj124,

For this functionality you need to change from openzeppelin-test-helpers to @openzeppelin/test-helpers.

Installing openzeppelin-test-helpers gives a deprecation warning:

$ npm i openzeppelin-test-helpers
npm WARN deprecated openzeppelin-test-helpers@0.5.1: This package has been renamed to @openzeppelin/test-helpers. Please update your dependency, or you will no longer receive updates.

I used the setup from the Learn guides: https://docs.openzeppelin.com/learn/writing-automated-tests#performing-complex-assertions and installed @openzeppelin/test-helpers


// test/Box.test.js
// Load dependencies
const { expect } = require('chai');

// Import utilities from Test Helpers
const { BN, expectEvent, expectRevert, time } = require('@openzeppelin/test-helpers');

// Load compiled artifacts
const Box = artifacts.require('Box');

// Start test block
contract('Box', function ([ owner, other ]) {

  // Use large integers ('big numbers')
  const value = new BN('42');

  beforeEach(async function () {
    this.box = await Box.new({ from: owner });

  it('retrieve returns a value previously stored', async function () {
    await this.box.store(value, { from: owner });

    const latest = await time.latestBlock();
    console.log(`Current block: ${latest}`);

    await time.advanceBlockTo(parseInt(latest) + 5);

    const current = await time.latestBlock();
    console.log(`Current block: ${current}`);

    // Use large integer comparisons
    expect(await this.box.retrieve()).to.be.bignumber.equal(value);


Using Truffle develop

truffle(develop)> test

Compiling your contracts...
> Compiling ./contracts/Box.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /tmp/test--26130-yxIIrDfEcPM2
> Compiled successfully using:
   - solc: 0.6.12+commit.27d51765.Emscripten.clang

  Contract: Box
Current block: 4
Current block: 9
    âś“ retrieve returns a value previously stored (176ms)

  1 passing (260ms)

got it I didn’t know there were 2 different packages

1 Like

Hi @viraj124,

This changed in OpenZeppelin Test Helpers 0.5, see: OpenZeppelin Test Helpers 0.5.

@abcoathup I have a time out of 5 secs currently but I am advancing 7 blocks 3 times in the same test and I get this

@openzeppelin/test-helpers WARN advanceBlockTo: Advancing too many blocks is causing this test to be slow.

and I get an error what should be the right timeout duration?

1 Like

Hi @viraj124,

Unfortunately advancing too many blocks will make your test slow, which is why a warning is shown.

You could try increasing your timeout to 20 seconds.