Hello @abcoathup
I was trying to use the increaseTimeto function of Openzepplin test helpers.
I was importing from - openzeppelin-solidity/test/helpers/increaseTime
However I got an error which(I assume) is related to web3 breaking changes -
ERROR- “web3.currentProvider.sendAsync is not a function”
Because of this web3 error I am not being able to proceed with my time tests using Openzepplin.
How to solve this .?
Should I use any other upgraded version?
1 Like
Hi @zaryab2000,
Welcome to the community forum
Thanks for posting here.
It looks like you are using the test helpers from an older version of OpenZeppelin Contracts
I recommend using the latest version of OpenZeppelin Test Helpers which is a separate package.
npm install --save-dev @openzeppelin/test-helpers
You can then use time
functionality in your tests. See the documentation for details: https://docs.openzeppelin.com/test-helpers/0.5/api#time
A simple test example (based from the Learn guides: https://docs.openzeppelin.com/learn/writing-automated-tests#performing-complex-assertions)
// test/Box.test.js
// Load dependencies
const { expect } = require('chai');
// Import utilities from Test Helpers
const { BN, 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 });
await time.increase(10);
// Use large integer comparisons
expect(await this.box.retrieve()).to.be.bignumber.equal(value);
});
});
Testing Box.sol (from the Learn guides)
// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract Box {
uint256 private value;
// Emitted when the stored value changes
event ValueChanged(uint256 newValue);
// Stores a new value in the contract
function store(uint256 newValue) public {
value = newValue;
emit ValueChanged(newValue);
}
// Reads the last stored value
function retrieve() public view returns (uint256) {
return value;
}
}
Running the test:
$ npx truffle test
Compiling your contracts...
===========================
> Compiling ./contracts/Box.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /tmp/test--1751-QgwJ7hZSF9IO
> Compiled successfully using:
- solc: 0.6.12+commit.27d51765.Emscripten.clang
Contract: Box
✓ retrieve returns a value previously stored (100ms)
1 passing (182ms)