我已经在以太坊中测试了合约的代码
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
可能的原因是什么?如何解决?
答案 0 :(得分:1)
得到答案。这是web3js中具有版本1的发送功能的一个问题。
因此可以使用设置最大监听器
web3.currentProvider.setMaxListeners(300);
或升级到v2 ^,它已固定为there。