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

Never failing Solidity unit testing #745

Closed
1 task done
GNSPS opened this issue Jan 10, 2018 · 4 comments
Closed
1 task done

Never failing Solidity unit testing #745

GNSPS opened this issue Jan 10, 2018 · 4 comments

Comments

@GNSPS
Copy link

GNSPS commented Jan 10, 2018


Issue

Solidity unit testing in Truffle doesn't work (no tests fail) unless you invoke any method of Truffle's Assert library.

Found this while doing unit testing with an assertion library of my own which complies with Truffle's TestEvent firing.

Steps to Reproduce

Run the tests from this repo:

https://github.com/GNSPS/solidity-bytes-utils

But remove this line:

https://github.com/GNSPS/solidity-bytes-utils/blob/master/test/TestBytesLib1.sol#L45

Which is the fix for the affliction I mentioned.

Expected Behavior

For the test to run independent of calling a method from Assert.sol

Actual Results

All tests were passing irregardless of wether they were firing false TestEvents or not.

Environment

  • Operating System: macOS
  • Truffle version: 4.0.4
  • Ethereum client: ganache-cli
  • node version: 8.9.1
  • npm version: 5.6.0
@cgewecke
Copy link
Contributor

Hi @GNSPS. It seems like the underlying issue might be a quirk relating to libraries and events. Everything about the way AssertBytes mimics Truffle's Assert is correct and seems like it should work.

However, if the only defined TestEvent is located in a library, the transaction result that Truffle inspects for failing event logs always has an empty logs arrary. The events fire but they aren't decoded at the web3 level, which is what Truffle expects.

Jorge Izquierdo at Aragon has written a nice Medium post about libraries and says there:

as of right now, the contract ABI does not reflect the events that the libraries it uses may emit. This confuses clients such as web3, that won’t be able to decode what event was called or figure out how to decode its arguments.

There is a quick hack for this, defining the event both in the contract and the library will trick clients into thinking that it was actually the main contract who sent the event and not the library.

So one fix would be to additionally define TestEvent in the test suite contracts, which would allow you to remove the fake test. If that solution works for you, maybe we should rename this issue a little - it's an unexpected problem that other people might run into as well.

@cgewecke
Copy link
Contributor

cgewecke commented Jan 13, 2018

Looking at this more i wonder if linking the AssertBytes library and the test suite contracts in a deployment step is what really needs to be done here. The comment above has the glaring flaw that Assert is also a library, so . . . why does it work ok?

@cgewecke
Copy link
Contributor

@GNSPS This should be fixed in the latest release. Please re-open if continue to see this problem, or the patch doesn't work for any other reason. Thanks!

@GNSPS
Copy link
Author

GNSPS commented Jan 18, 2018

Thank you so much @cgewecke!! 🙌 And sorry for the delay! Appreciated very much your prompt response! 😄

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

No branches or pull requests

2 participants