Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solidity contracts (UINT value) - testing problem #214

Open
val3ri opened this issue Aug 11, 2017 · 1 comment
Open

Solidity contracts (UINT value) - testing problem #214

val3ri opened this issue Aug 11, 2017 · 1 comment

Comments

@val3ri
Copy link

val3ri commented Aug 11, 2017

Hi guys, I need some help. I am not sure, that here is the right place for this question, but I can't find any useful information in internet (google and stackexchange/overflow) and that's why I am writing to you.

I am using mocha/chai/chai-as-promised to test some blockchain smart contracts - classic Promises: should.eventually.equal() and so on. Until now everything was perfect but I am trying to check one UINT (solidity integer value) with instance.getValue().should.eventually.equal(4) (getValue() is getter from the solidity code) but I am receiving this error the result is: expected { Object (s, e, ...) } to equal 4. When I try to compare the values like this: assert.equal(instance.getMemberCount() == 4) - it works.

Can someone explain me - what is the difference between these two ways of testing the same thing? In the both ways should be a transformation of the Promise object, but in the first one - there is not...

@sorccu
Copy link

sorccu commented Oct 14, 2017

This is not a bug. It works as it should.

The reason why your first example doesn't work is that .equal() in chai is a strict equality check, i.e. ===. getValue() resolves with a web3.BigNumber, not a Number, so they'll never be equivalent.

The reason why the 2nd example works is that you're not doing a strict equality check. The non-strict equality check internally ends up calling .valueOf() on the BigNumber which returns a String value of '4'. Now, even though it returned a String, you're doing a non-strict check against the Number 4, which returns true.

% node
> function Foo() {}
undefined
> Foo.prototype.valueOf = () => { console.log('valueOf called'); return '4' }
[Function]
> new Foo() == 4
valueOf called
true
> new Foo() === 4
false
>

This issue can be closed.

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

No branches or pull requests

2 participants