Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Uncaught TypeError: Cannot read property 'constructor' of undefined #494

Closed
danielfebrero opened this issue Jul 12, 2017 · 13 comments
Closed

Comments

@danielfebrero
Copy link

danielfebrero commented Jul 12, 2017

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
@izqui
Copy link

izqui commented Jul 18, 2017

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

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

@danielfebrero
Copy link
Author

danielfebrero commented Jul 18, 2017 via email

@mikeshultz
Copy link

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

@tomasienrbc
Copy link

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.

davidyuk added a commit to aeternity/aepp-response that referenced this issue Oct 17, 2017
davidyuk added a commit to aeternity/aepp-response that referenced this issue Oct 17, 2017
davidyuk added a commit to aeternity/aepp-response that referenced this issue Oct 17, 2017
davidyuk added a commit to davidyuk/education-hackathon-2017 that referenced this issue Nov 8, 2017
davidyuk added a commit to aeternity/aepp-response-contracts that referenced this issue Nov 30, 2017
davidyuk added a commit to aeternity/aepp-response-contracts that referenced this issue Nov 30, 2017
@alexaltair
Copy link

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.

@roderik
Copy link
Contributor

roderik commented Feb 26, 2018

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

@ambiflextrous
Copy link

Adding the name worked for me too.

@bellaj
Copy link

bellaj commented Jul 1, 2018

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...)

@john-osullivan
Copy link

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

@stale
Copy link

stale bot commented Nov 8, 2018

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.

@stale stale bot added the stale label Nov 8, 2018
@stale
Copy link

stale bot commented Nov 15, 2018

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!

@stale stale bot closed this as completed Nov 15, 2018
@l-henri
Copy link

l-henri commented Nov 29, 2018

Same issue here

@adibas03
Copy link

adibas03 commented Dec 5, 2018

@l-henri check at the comment above
#494 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests