[Beem-0.20.6] DivisionByZero Error in RC manabar lookup

in #utopian-io6 years ago

Project Information

A GitHub issue was created and could be fixed with a PR.

Expected behavior

Account.get_rc_manabar() should return the current RC mana state of an Account

Actual behavior

Account.get_rc_manabar() may raise a ZeroDivisionError exception if the corresponding account has a max_rc bandwidth of 0.

How to reproduce

from beem.account import Account
a = Account('a-pile-of-steem')
print(a.get_rc_manabar())
Traceback (most recent call last):
  File "bug_rc.py", line 3, in <module>
    print(a.get_rc_manabar())
  File "/usr/local/lib/python3.6/site-packages/beem/account.py", line 241, in get_rc_manabar
    current_pct = current_mana / max_mana * 100
ZeroDivisionError: division by zero

Environment

# beempy --version
beempy, version 0.20.6
# python --version
Python 3.6.6

Fix

The division by zero error was triggered in the calculation of the relative RC balance as the current value over its maximum. The given account has a maximum RC balance of 0. By checking for non-zero divisors before the division, the error could be avoided. This has been implemented with PR #100 together with further division-by-zero preventions at other locations in the code. The issue is fixed in beem master and will be rolled out with beem-0.20.7.

GitHub Account

https://github.com/crokkon

Sort:  

Hi @stmdev, thanks for making this contribution.

Thanks also, for proposing a fix and making a pull request to fix the issue.

  1. The post title was succinctly informative, providing any reader a glimpse of the error experienced.
  2. The expected and actual behavior were properly explained with code inputs.
  3. The steps you provided in form of a sample input code was very clear to understand to follow.
  4. I see you provided a simple analysis of the bug experienced, proposed a fix and also made a pull request to that effect. Your efforts are deeply appreciated,

Thanks again for this contribution. I look forward to your future reports

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator].

Thank you for your review, @fego!

So far this week you've reviewed 3 contributions. Keep up the good work!

Hi @stmdev!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @stmdev!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.034
BTC 66499.54
ETH 3203.31
USDT 1.00
SBD 4.14