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.

Safe transfer and not coverable assert() failure

See original GitHub issue

Not 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:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
areacommented, Nov 30, 2017

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!

2reactions
areacommented, Nov 9, 2017

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

If used properly, analysis tools can evaluate your contract to identify the conditions and function calls which will reach a failing assert. Properly functioning code should never reach a failing assert statement; if this happens there is a bug in your contract which you should fix.

And so… yes, if the assert is appropriate (rather than it should be a require), 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.

Read more comments on GitHub >

github_iconTop 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 >

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