question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Require constant, view, and pure methods be invoked by `.call`

See original GitHub issue

With 0.3.5 we’ve begun using a testrpc that implements the Byzantium fork. Unfortunately we’re also pushing up against the limits of solidity-coverage’s current design and there were some new bugs discovered while doing the upgrade:

  • highest working pragma is 0.4.18. Above that you will get compilation errors complaining that the non-state-changing nature of constant and view methods has been violated.
  • pure modifier compiles but returns a transaction object rather than a value. If your tests check / use that value they will fail.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
areacommented, Nov 24, 2017

The branch fix/callNotRequired contains my swing at fixing this ‘properly’. During the original parsing of the contracts done to get the source mapping, we record which functions are marked as constant, pure, or view. We then compile the contracts with all of those modifiers stripped, as before, and set the constant parameter in the ABI to true for the functions we recorded as constant.

Two tests fail to pass on that branch, and I can’t spot why. I’m hoping @cgewecke can come to my rescue, there. They are

  1) app config with test command options string: should run test
  2) app config racing test command: should run test after testrpc has started

They appear to time out.

Other issues with the branch that should be discussed:

  • This integrates us even more closely with Truffle. I have included a compileCommand option, but it looks for the JSON files corresponding to the contracts in the ./build/contracts/ directory, which is obviously Truffle specific. Even potentially more problematic, the JSON files generated by truffle are do not contain just the ABI, but the abi is just one property in the object. Do we know of anyone using solidity-coverage without truffle?
  • Other related properties in the ABI are ignored currently, specifically payable and stateMutability. We should change these too to guard against changes to Truffle’s behavior in the future, but I’m unsure currently what the valid combinations are. The Solidity Documentation has what we need, though.

I have not opened a PR yet, but if you want to move discussion there, I’m happy to do that too.

1reaction
frangiocommented, Nov 22, 2017

@cgewecke We’re actually about to upgrade to the latest Truffle with Solidity 0.4.18. We’re considering removing coverage temporarily (OpenZeppelin/zeppelin-solidity#573), but 4 weeks until it’s fixed might be too long. 😕

Read more comments on GitHub >

github_iconTop Results From Across the Web

solidity - When to use "View" and "Pure" in place of "Constant"
To execute/call these pure or view functions from outside, no transaction is needed. Just a call is enough since the state of the...
Read more >
Solidity – Pure and View Modifiers – Blog - Avantrio
17, Furthermore, this release finally checks the modifiers view (used to be named constant) and pure on functions. As a rule of thumb,...
Read more >
Pure and View in Solidity smart contracts - Crypto Market Pool
Pure, view and payable dictate a Solidity functions behavior. If the behavior of a function is not specified by default it will read...
Read more >
Using pure functions in a constant declaration - Stack Overflow
Rune, integer, floating-point, and complex constants are collectively called numeric constants. Using var : var str1 = PureFunction(0) var str1 ...
Read more >
Contracts — Solidity 0.8.17 documentation
A contract and its functions need to be called for anything to happen. ... public pure returns (bool ok) { // Check an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found