Ethereum Asked by Tulun on January 26, 2021
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);
});
})
});
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.
Answered by chetta on January 26, 2021
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);
Answered by João Quintanilha on January 26, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP