I'm writing tests for a smart contract, but I've run into an error.
Here's the code
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);
})
})
and the error
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)
What am I doing wrong?
The problem was that I set my initial constructor function for the contract to private; meaning that it wasn't initialized and so I had no bytecode deployed, hence null.