mocha 的单元测试错误:超过 20000 毫秒的超时

Unit test error with mocha: Timeout of 20000ms exceeded

当我尝试将合约发送到 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

None 以上解决方案对我有用(主要是关于增加超时)。此外,我按照另一个论坛中的建议降级了 web3 库。但是,它也没有用。

您可以在 a different forum 找到其他人发布的确切问题。显然,这个问题也没有得到任何可能的答案。

我安装了 truffle v5.0.24 并开始使用解决了所有问题的 truffle 控制台。