node.js - 是什么导致 web3js 测试代码中的 MaxListenersExceededWarning 警告
问题描述
我已经测试了以太坊合约的代码
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
造成这种情况的可能原因是什么以及如何解决?
解决方案
得到了答案。这是带有版本 1 的发送功能的 web3js 中的一个问题。
所以要么设置最大听众使用
web3.currentProvider.setMaxListeners(300);
或者升级到 v2^ 它已经固定在那里。
推荐阅读
- clang - clang 命令选项 -lm 是什么意思?
- mysql - Laravel 5.6 - 急切负载取决于父表中的值
- scala - 为什么如果 V <: Seq[Int] 当 V 是 Seq 后代映射并且 zip 操作返回 Seq[Int]
- python - 如何在 Python 中矢量化这个峰值查找 for 循环?
- c# - 从 ViewModel (MVVM) 添加到 XAML WPF
- python - 尝试解决 Python 3.5 中“图像”对象没有属性“名称”的问题
- java - Java - 使用getter从arraylist添加特定索引
- python - tensorflow.train.AdamOptimizer 的损失是否必须为正?
- swift - 如何在运行时确定泛型变量的值?
- javascript - Electron - 在其他 HTML 文件中包含 HTML 文件