I'm trying to write my first tests for truffle, but I run in a timeout each time I want to execute the tests.
Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Contract deployment with truffle deploy
to ganache and a parity node works fine, but when I run truffle test
, truffle hangs for 2min and then runs into a timeout:
C:\Development\solidity>truffle test
Using network 'development'.
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Contract: MyContract
1) "before all" hook: prepare suite
0 passing (2m)
1 failing
1) Contract: MyContract
"before all" hook: prepare suite:
Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Development\solidity\test\first-tests.js)
truffle test
run fine without any tests (0 passing (1ms)
), but as soon as I create a test-file with a contract() as described in the docs truffle does not respond for 2 minutes, then runs into the timeout error shown above.
My test file in test/my_test.js
:
const MyContract = artifacts.require("MyContract")
contract("MyContract", async () => {
it("count should be zero after deployment", async () => {
MyContract.deployed().then(instance => {
assert.equal(0, 0)
})
})
})
My truffle-config.js
:
const HDWalletProvider = require("truffle-hdwallet-provider")
module.exports = {
networks: {
development: {
provider: new HDWalletProvider('aa bb cc .. xx yy zz', 'http://127.0.0.1:7545'),
network_id: 5777,
},
},
mocha: { enableTimeouts: false },
compilers: { solc: {} },
}
Am I missing some important configuration used for running the tests? or why does it run into a timeout? If there's another error causing this timeout, is there a way to debug this in more detail to get a better error description?
The post I found here addresses problems with contract deployments that took too long, but my contract is deploy within 10 seconds, so that doesn't seem to be the same problem here.
Things I tried:
- Updating my
truffle-config.js
to includemocha: { enableTimeouts: false }
as suggested didn't change anything, still same behaviour. - Create an empty project and start from scratch. Same Behaviour.
( I did
truffle init
, write contract, add to migrations, add truffle-config, add test-file, runtruffle build|deploy|test
.)
Any hint on what to do to get my very basic test working would be highly appreciated.
mocha: {enableTimeouts: false}
in your Truffle configuration file (truffle.js
ortruffle-config.js
), but the problem is probably in one of your migration scripts (located undermigrations
). You'd wanna check those, and possibly "disable" them whennetwork == "development"
(or fix them in a different manner).it
and not in some "mysterious"before
. BTW,contract
takes a regular function, so you can (and should) remove thatasync
in there.