2

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 include mocha: { 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, run truffle build|deploy|test.)

Any hint on what to do to get my very basic test working would be highly appreciated.

5
  • You could add mocha: {enableTimeouts: false} in your Truffle configuration file (truffle.js or truffle-config.js), but the problem is probably in one of your migration scripts (located under migrations). You'd wanna check those, and possibly "disable" them when network == "development" (or fix them in a different manner). Aug 12, 2019 at 11:43
  • Try to create them in the test itself, so to begin with, your problem should then occur in the it and not in some "mysterious" before. BTW, contract takes a regular function, so you can (and should) remove that async in there. Aug 12, 2019 at 11:50
  • Which version of Truffle are you using? Aug 12, 2019 at 12:46
  • I have version 5.0.31 Aug 12, 2019 at 12:55
  • I recommend trying 4.1.15. Aug 12, 2019 at 12:58

2 Answers 2

6

There is an issue in a way you use HDWalletProvider when configuring development network in truffle-config.js.

You should add it like:

provider: () => new HDWalletProvider('your mnemonic', 'http://127.0.0.1:7545')

For me, it helped. Additional info can be found here.

3
  • 1
    I've updated my answer, since I could solve the problem on my computer. Try it, @JackO'neill Aug 13, 2019 at 15:28
  • That was it, it works now. Thanks a lot for your help! Aug 14, 2019 at 8:16
  • 1
    A bit of explanation. Why it's related to timeout. Testing seems to use a lot of connections now and previous Truffle provider setting was reaching the limit of the provider. Then requests were not successful and test was waiting for an answer that was not going to arrive, hence the timeout. New way to define provider enables more parallel connections (up to some point I guess). Sep 10, 2019 at 12:50
0

npm uninstall -g truffle

npm install -g [email protected] (always got me back on track)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.