Starting to build the following test suite for a contract. It deploys fine on Remix.

I get the following error message.

1) "before each" hook for "deploys a contract": Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

I haven't had much of an issue doing this on other contracts with this setup. Not sure what's going on here. Am I missing something basic?

const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());

const json = require('../build/contracts/Contract.json');
let accounts, contract;

const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";

beforeEach( async () => {
  // Get a list of all accounts;
  accounts = await web3.eth.getAccounts();
  console.log('accounts', accounts);
  const interface = json["abi"];
  contract = await new web3.eth.Contract(interface)
  .deploy({ data: json["bytecode"] })
  .send({ from: accounts[0], gas: '3000000' })

  console.log('contract', contract);

describe("Contract", () => {

  describe("Smoke test", () => {
    it("deploys a contract", async () => {
      await assert.ok(contract.options.address);

  • What version of solc are you using? Check what is the content of json[bytecode].
    – Sanjay S B
    Jun 14, 2019 at 2:34
  • Mocha has an enableTimeouts configuration flag, which you can set to false. BTW, no need for await on that assert. Jun 14, 2019 at 8:32
  • It was 0.5.8 solc. Timeout was extended out to 20000 ms and it still timed out. And yeah, fair point on await, left over from hacking away :)
    – Tulun
    Jun 14, 2019 at 21:23

2 Answers 2


it looks like a mocha timeout action that does not allow to complete the deploy of the smart contract or await the end of execution. You need to extend the default setting of 20000ms, you can change it (eg. 60000ms) in 2 different ways:

  • if you use script on package.json add the --timeout option on command, eg.

    "scripts": { ... "run_test": "mocha '/*.js' --timeout 60000" ... }

  • otherwise directly on the function script, eg.

    beforeEach( async () => { // Get a list of all accounts; ... }).timeout(60000);

And you can add a try / catch paradigm to print the error in case there is one.


you are missing the OPTIONS on your web3! Try this:

const OPTIONS = {
    defaultBlock: "latest",
    transactionConfirmationBlocks: 1,
    transactionBlockTimeout: 5
const web3 = new Web3(ganache.provider(), null, OPTIONS);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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