I’m trying to use Test Environment’s fork functionality for the first time in order to use the Uniswap factory and exchange contracts as well as the DAI token contract on Ropsten. I’m getting this error for some reason when I run my tests, Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Here’s what my test-environment.config.js
file looks like:
module.exports = {
accounts: {
amount: 20, // Number of unlocked accounts
ether: 1e6,
},
node: {
fork: `https://ropsten.infura.io/v3/${process.env.INFURA_API_KEY}`,
unlocked_accounts: ['0x9c83dCE8CA20E9aAF9D3efc003b2ea62aBC08351', '0xaD6D458402F60fD3Bd25163575031ACDce07538D'],
},
};
Here’s how it is being imported into the tests file:
const { accounts, contract } = require('@openzeppelin/test-environment');
To run the tests I simply run npm test
Any thoughts?
Environment
@openzeppelin/test-environment": “^0.1.4”
Truffle v5.1.22 (core: 5.1.22)
Solidity - ^0.6.0 (solc-js)
Node v13.7.0
Web3.js v1.2.1
2 Likes
Hi @dougiebuckets,
Mocha has a default timeout of 2000ms.
I suspect that the issue is the Ganache startup time can trigger the default mocha timeout as per open Issue: OpenZeppelin/openzeppelin-test-environment#48
A work around is to increase the mocha timeout.
2 Likes
@abcoathup That did the trick. Appreciate your help.
2 Likes
Hi @dougiebuckets,
Glad to help. I tried it out and was able to use a timeout of 5000
ms.
npx mocha --exit --recursive --timeout 5000
2 Likes
@abcoathup It looks like I’m still having the issue on my end. I’ve bumped the timeout up to 10000, but some of my tests will still timeout.
The strange part is that it’s not always the same tests that timeout and the first tests in the mocha test suites aren’t the ones that are timing out per this thread.
Also, my tests run very slowly now that I’m using the fork. Definitely slower than forking with Truffle. Think I’m doing something wrong on my end or is that to be expected given it’s new functionality?
Appreciate your help!
2 Likes
Hi @dougiebuckets,
Are you able to share a repository as it would be good to see what is happening.
Also what environment are you running on? I use WSL2 which can be slower, so I have used a higher timeout of 20000 ms.
1 Like
@abcoathup We’re running on zsh. I’ll DM you re: code.
2 Likes
Hi @dougiebuckets,
Posting here for the community. Thanks for providing access to your code repository.
It appears to be a timeout issue.
Unfortunately fork
is slow via Infura. Data is downloaded dynamically.
Setting Mocha timeout to 100000 should work.
I tried a simple test between OpenZeppelin Test Environment and Truffle Test using fork and the Box contract from the learn guides to see if there were timing differences between Truffle and OpenZeppelin Test Environment but got fairly similar times.
$ npm run test
> box@1.0.0 test /home/abcoathup/projects/forum/box
> mocha --exit --recursive test --timeout 100000
Box
✓ retrieve returns a value previously stored (1043ms)
✓ store emits an event (921ms)
✓ non owner cannot store a value (168ms)
3 passing (12s)
$ npx truffle test
Compiling your contracts...
===========================
> Compiling ./contracts/Box.sol
> Compiling ./contracts/Migrations.sol
> Compiling @openzeppelin/contracts/GSN/Context.sol
> Compiling @openzeppelin/contracts/access/Ownable.sol
> Artifacts written to /tmp/test-2020526-857-3q4p87.pzifh
> Compiled successfully using:
- solc: 0.6.10+commit.00c0fcaf.Emscripten.clang
Contract: Box
✓ retrieve returns a value previously stored (977ms)
✓ store emits an event (956ms)
✓ non owner cannot store a value (175ms)
3 passing (8s)