I want to write some tests using mocha and ganache-cli for my contract. I tried to deploy a compiled contract like so:
//ZombieFactory.test.js
const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const compiledZombieFactory = require('../ethereum/build/ZombieFactory.json');
let accounts;
let factory;
beforeEach(async () => {
accounts = await web3.eth.getAccounts();
factory = await new web3.eth.Contract(compiledZombieFactory.abi)
.deploy({data: '0x' + compiledZombieFactory.evm.bytecode.object})
.send({from: accounts[0], gas: '3000000'});
});
describe('ZombieFactory', () => {
it('deploys the zombie factory', () => {
assert.ok(factory.options.address);
})
});
When I run this using npm run test
, I get the following error:
ZombieFactory
1) "before each" hook for "deploys the zombie factory"
0 passing (2s)
1 failing
1) "before each" hook for "deploys the zombie factory":
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
I did some research and I suppose this error occurs because the code fails to deploy the contract successfully. I would like to know if this issue is due to the deploy code or something else.