Require constant, view, and pure methods be invoked by `.call`
See original GitHub issueWith 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 ofconstant
andview
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:
- Created 6 years ago
- Comments:21 (18 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 asconstant
,pure
, orview
. We then compile the contracts with all of those modifiers stripped, as before, and set theconstant
parameter in the ABI totrue
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
They appear to time out.
Other issues with the branch that should be discussed:
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 usingsolidity-coverage
withouttruffle
?payable
andstateMutability
. 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.
@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. 😕