Beem 0.19.52 - calculation error in vests_to_rshares

@flugschwein · 2018-08-10 08:22 · busy

Project Information

  • Repository: https://github.com/holgern/beem
  • Project Name: Beem
  • Publisher (if applicable): @holger80

Expected behavior

The vests_to_rshares function of the beem.steem module should return the number of rshares a vote by an account dependent on the vests and the voting power the account has, and the vote percentage that account uses for voting.

Actual behavior

Instead, that function returns the rshares that it should return, but 1e6 times smaller. This issue happens because the vests would need to be multiplied with 1e6 in order to be in the right scope for the calculation (relevant tutorial) This would need to be added here.

How to reproduce

  1. from beem.steem import Steem
  2. Get a Steem() instance. (e.g. stm = Steem())
  3. Run the vests_to_rshares function on any number of vests. (e.g. stm.vests_to_rshares(10000000))
  4. Transform the value point 2. returned to SBD using the rshares_to_sbd function. (e.g. stm.rshares_to_sbd(200000))
  5. Run the vests_to_sbd function on the same number of vests as before. (e.g. stm.vests_to_sbd(10000000))
  6. Compare the two values you got in point 3. and 4., and see that the one you got in point 3 is 1e6 times smaller than the other one.

It looks like this in a REPL:

>>> from beem.steem import Steem
>>> stm = Steem()
>>> stm.vests_to_rshares(10000000)
200000

^This is where the issue is. That should be 200000000000 instead

>>> stm.rshares_to_sbd(200000)
3.3005542087518333e-07
>>> stm.vests_to_sbd(10000000)
0.33005542087518336

After applying a fix, it would look like that:

>>> from beem.steem import Steem
>>> stm = Steem()
>>> stm.vests_to_rshares(10000000)
200000000000
>>> stm.rshares_to_sbd(200000000000)
0.33005542087518336
>>> stm.vests_to_sbd(10000000)
0.33005542087518336
  • beem version: 0.19.52
  • Operating system: Windows 10

I provided this issue on GitHub right here, and opened a pull request while opening the issue as well. My fix was merged, and is already live in version 0.19.53

GitHub Account

https://github.com/flugschwein

#utopian-io #bug-hunting #busy #beem #steemdev
Payout: 0.000 HBD
Votes: 71
More interactions (upvote, reblog, reply) coming soon.