Truffle: Uncaught TypeError: Cannot read property 'constructor' of undefined

Created on 12 Jul 2017  路  13Comments  路  Source: trufflesuite/truffle

Issue

Comparing a bool from a Structure return error when combined with an Event.

Cannot read property 'constructor' of undefined

when running Truffle test

Steps to Reproduce

Contract

Contract Bug {
    One demo;

    event Ramdom(String);

    struct One {
        bool active;
        address user;
    }

    function init() {
        demo = One({active: false, address: 0x0});
    }

    function isActive() returns (bool) {
        Ramdom("buggy");
        // Option 1
        if(demo.active == true){
            return true;
        }else { return false; }

        // Option 2
        if(demo.address == address(0)){
            return false;
        }else { return true; }
    }
}

Test:

it('is a demo test', () => {
        return Bug.init()
            .then(txObject => Bug.isActive())
      })

Expected Behavior

Return True or False when the Structure.bool is true or false.

Actual Results

When using Option 1, the bug happens;
When using Option 2, it works fine;

Environment

  • Operating System: macOs
  • Truffle version: 3.2.8
  • Ethereum client: testrpc
  • Solidity: 0.4.11
  • node version: 6.7.0
  • npm version: 4.0.3
needs reproduced stale

Most helpful comment

Naming the event parameter in solidity solved this issue for us.

Try replacing event Random(string) for event Random(string random)

All 13 comments

Naming the event parameter in solidity solved this issue for us.

Try replacing event Random(string) for event Random(string random)

Interesting, thank you, I will try it!

Just ran into this. This is a very odd bug. Is not naming event params technically a bad pattern in Solidity code?

Had this problem as well - I share Mike's question, what's the pressing need to name event attributes? I'll assume it's the right design decision going forward but I didn't know that.

I ran into this problem also. I defined an event and did not name the address parameter, which resulted in Uncaught TypeError: Cannot read property 'constructor' of undefined. If this issue hadn't come up in google I never would have figure it out.

Indeed, same issue for me. I like to use event Debug(bool, bool, bool) for example to debug values in my smart contracts. event Debug(bool a, bool b, bool c) works like a charm

Adding the name worked for me too.

I confirm i can reproduce the same error
and it's solved as stated by other developers by adding arguments names like following :
eventX(bool b, address a...)

Another confirmation for the pile -- saw the same bug, fixed it by naming the event params.

Thank you for raising this issue! It has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you would like to keep this issue open, please respond with information about the current state of this problem.

There has been no new activity on this issue since it was marked as stale 7 days ago, so it is being automatically closed. If you'd like help with this or a different problem, please open a new issue. Thanks!

Same issue here

@l-henri check at the comment above
https://github.com/trufflesuite/truffle/issues/494#issuecomment-316044753

Was this page helpful?
0 / 5 - 0 ratings