Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
977 views
in Technique[技术] by (71.8m points)

node.js - I get TypeError: cannot read property 'send' of null for mocha test I'm writing for solidity

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...