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 '19 at 2:34
  • Mocha has an enableTimeouts configuration flag, which you can set to false. BTW, no need for await on that assert. – goodvibration Jun 14 '19 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 '19 at 21:23

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);
| improve this answer | |

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.