0

I'm running a test using hardhat and chai. I keep getting this error:

Error: Timeout of 40000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/mnt/c/Users/hp/Documents/SolidityProj/general/test/faucetTest.js)

This is the test code:

const { loadFixture } = require("@nomicfoundation/hardhat-network-helpers");
const { expect } = require("chai");

describe("Faucet", function () {
  async function deployContractAndSetVariables() {
    const Faucet = await ethers.getContractFactory("Faucet");
    const faucet = await Faucet.deploy();

    const [owner] = await ethers.getSigners();

    console.log("Signer 1 address: ", owner.address);
    return { faucet, owner };
  }

  it("should deploy and set the owner correctly", async function () {
    const { faucet, owner } = await loadFixture(deployContractAndSetVariables);

    expect(await faucet.owner()).to.equal(owner.address);
  });
});

This is my hardhat.config file:

require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.17",
};

2 Answers 2

0

Add this to your hardhat.config file:

mocha: {
    timeout: 100000000,
  },

Like so:

module.exports = {
  solidity: "0.8.17",
  mocha: {
    timeout: 100000000,
  },
};
0

There are two ways of doing it

The first one is by changing the hardhat.config file

mocha: {
    timeout: 100000000,
  }

The Second one is by giving a timeout at the end of the function as follows

it("...", async function () {
...
}).timeout(100000);

Good Luck

Your Answer

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

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