I get TypeError: cannot read property 'send' of null for mocha test I'm writing for solidity
I get TypeError: cannot read property 'send' of null for mocha test I'm writing for solidity
我正在为智能合约编写测试,但 运行 出错了。
这是代码
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(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hello'] })
.send({from: accounts[0], gas: '1000000'});
});
describe("Inbox", () => {
it('deploys a contract',() => {
console.log(inbox);
})
})
和错误
Inbox
1) "before each" hook for "deploys a contract"
1) "before each" hook for "deploys a contract":
TypeError: Cannot read property 'send' of null
at Context.beforeEach (test/Inbox.test.js:63:9)
at process._tickCallback (internal/process/next_tick.js:68:7)
我做错了什么?
问题是我将合约的初始构造函数设置为私有;这意味着它没有被初始化,所以我没有部署字节码,因此为 null。
我正在为智能合约编写测试,但 运行 出错了。
这是代码
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(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hello'] })
.send({from: accounts[0], gas: '1000000'});
});
describe("Inbox", () => {
it('deploys a contract',() => {
console.log(inbox);
})
})
和错误
Inbox
1) "before each" hook for "deploys a contract"
1) "before each" hook for "deploys a contract":
TypeError: Cannot read property 'send' of null
at Context.beforeEach (test/Inbox.test.js:63:9)
at process._tickCallback (internal/process/next_tick.js:68:7)
我做错了什么?
问题是我将合约的初始构造函数设置为私有;这意味着它没有被初始化,所以我没有部署字节码,因此为 null。