当我尝试将合约发送到 Ganache 时出现超时错误。我的代码如下,
const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const {interface,bytecode} = require('../compile');
let accounts;
let inbox;
beforeEach(async() => {
accounts = await web3.eth.getAccounts();
inbox = await new web3.eth.Contract(JSON.parse(interface))
.deploy({data: bytecode,arguments:['Hi There !'] })
.send({from: accounts[0], gas:'1000000'});
});
describe("inbox", () => {
it('deploys a contract', () => {
console.log(inbox);
})
})
当我注释掉发送方法(在下面提供)时,程序运行没有任何问题。但是,将其添加回来会引入超时错误。无论我为 mocha 超时分配多少时间,我仍然会遇到相同的错误。
.send({from: accounts[0], gas:'1000000'});
下面列出了关于超时的类似帖子, Error: Timeout of 2000ms exceeded. For async tests and hooks. Unit test with mocha and chai
Unit test error with mocha and chai Timeout of 2000ms exceeded. For async tests and hooks
Mocha testing with promises: Error: Timeout of 2000ms exceeded
Mocha exceeding 2000ms timeout when returning a promise
以上解决方案都不适合我(主要是关于增加超时时间)。此外,我按照另一个论坛中的建议降级了 web3 库。但是,它也没有用。
您可以在 a different forum 找到其他人发布的确切问题.显然,这个问题也没有得到任何可能的答案。
最佳答案
我安装了 truffle v5.0.24 并开始使用解决了所有问题的 truffle 控制台。
关于mocha.js - mocha : Timeout of 20000ms exceeded 单元测试错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56616396/