Node.js 是什么导致web3js测试代码中出现MaxListenerSexceedAwarning警告
我在以太坊测试合同的代码Node.js 是什么导致web3js测试代码中出现MaxListenerSexceedAwarning警告,node.js,mocha.js,ethereum,solidity,web3js,Node.js,Mocha.js,Ethereum,Solidity,Web3js,我在以太坊测试合同的代码 const assert = require("assert"); const ganache = require("ganache-cli"); const Web3 = require("web3"); const web3 = new Web3(ganache.provider()); const { abi, evm } = require("../compile"); let accounts; let inbox; beforeEach(async ()
const assert = require("assert");
const ganache = require("ganache-cli");
const Web3 = require("web3");
const web3 = new Web3(ganache.provider());
const { abi, evm } = require("../compile");
let accounts;
let inbox;
beforeEach(async () => {
// Get a list of all accounts
accounts = await web3.eth.getAccounts();
// Use one of those accounts to deploy the contract
inbox = await new web3.eth.Contract(abi)
.deploy({
data: evm.bytecode.object,
arguments: ["Hi there!"]
})
.send({ from: accounts[0], gas: "1000000" });
});
describe("Inbox", () => {
it("deploys a contract", () => {
console.log(accounts);
console.log(inbox);
assert.ok(inbox.options.address);
});
});
这显示了以下警告
(node:52888) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added. Use emitter.setMaxListeners() to increase limit
可能的原因是什么?如何解决?得到了答案。这是web3js版本1的发送功能中的一个问题 因此,要么使用
web3.currentProvider.setMaxListeners(300);
或者升级到v2^已修复