Safe transfer and not coverable assert() failure
See original GitHub issueNot really an issue but I’d like to know how to manage error case for these kind of lines :
assert(token.transfer(msg.sender, token.balanceOf(this)));
I added an assert to add extra security if something goes wrong.
But in my tests I can’t make this fail. So I can’t get 100% on branch coverage. It’s an example but I have some extra asserts for cases we can’t reproduce in the test environnement.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Understanding assertions – Hacking with Swift+
Use assertionFailure() if there's somewhere your code shouldn't reach, but it's not a disaster if it happens. Use precondition() anywhere that important checks ......
Read more >The dangers of assert in Python - Snyk
This article explores how to use asserts safely and what causes them to be unsafe. By the end of this article, you'll know...
Read more >Assertions, Exceptions and Errors
One case that is not easily covered by the assert statement is asserting Exception raises. This is easily done with slash.assert_raises() :.
Read more >TS Playground - An online editor for exploring TypeScript and ...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Read more >Wire Transfer FAQs: What is a Wire Transfer? - Bank of America
How do I assert an error with my Remittance Transfer?
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
I’ll also just say for people finding this later: code coverage is just a tool. 100% code coverage doesn’t mean that your code is flawless, and less than 100% doesn’t necessarily mean that your code (or tests) are bad. Striving for 100% coverage might be a waste of developer time. If you understand why you’re failing to reach 100% coverage, and it doesn’t imply poor code (as in this instance), then it’s perfectly okay!
I think the assert is in the Solidity code, not the javascript test. The rest of this comment assumes that to be true.
From the Solidity docs
And so… yes, if the
assert
is appropriate (rather than it should be arequire
), then you should not be able to to make it fail. It’s not clear to me if solidity-coverage should take that in to account, however, when reporting coverage.