Skip to content

Commit

Permalink
Fix unit tests and adapt mvest/vest relation for vests_to_rshares
Browse files Browse the repository at this point in the history
  • Loading branch information
holgern committed Aug 10, 2018
1 parent 0e23e1a commit 78281e7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Changelog
* bug fixed in allow and disallow for CLI
* Issue #52 closed thanks to crokkon
* Issue #64 fixed
* Issue #66 fixed thanks to flugschwein

0.19.52
-------
Expand Down
2 changes: 1 addition & 1 deletion beem/steem.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def sp_to_rshares(self, steem_power, voting_power=STEEM_100_PERCENT, vote_pct=ST
"""
# calculate our account voting shares (from vests)
vesting_shares = int(self.sp_to_vests(steem_power, use_stored_data=use_stored_data) * 1e6)
vesting_shares = int(self.sp_to_vests(steem_power, use_stored_data=use_stored_data))
return self.vests_to_rshares(vesting_shares, voting_power=voting_power, vote_pct=vote_pct, use_stored_data=use_stored_data)

def vests_to_rshares(self, vests, voting_power=STEEM_100_PERCENT, vote_pct=STEEM_100_PERCENT, use_stored_data=True):
Expand Down
16 changes: 13 additions & 3 deletions tests/beem/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pprint import pprint
from beem import Steem
from beem.blockchain import Blockchain
from beem.exceptions import BlockWaitTimeExceeded
from beem.block import Block
from beem.instance import set_shared_steem_instance
from beem.nodelist import NodeList
Expand Down Expand Up @@ -234,15 +235,24 @@ def test_wait_for_and_get_block(self, node_param):
bts = self.bts
else:
bts = self.appbase
b = Blockchain(steem_instance=bts, max_block_wait_repetition=6)
b = Blockchain(steem_instance=bts, max_block_wait_repetition=18)
start_num = b.get_current_block_num()
blocknum = start_num
last_fetched_block_num = None
for i in range(3):
block = b.wait_for_and_get_block(blocknum)
last_fetched_block_num = block.block_num
blocknum = last_fetched_block_num + 2
self.assertEqual(last_fetched_block_num, start_num + 4)
blocknum = last_fetched_block_num + 1
self.assertEqual(last_fetched_block_num, start_num + 2)

b2 = Blockchain(steem_instance=bts, max_block_wait_repetition=1)
with self.assertRaises(
BlockWaitTimeExceeded
):
for i in range(300):
block = b2.wait_for_and_get_block(blocknum)
last_fetched_block_num = block.block_num
blocknum = last_fetched_block_num + 2

def test_hash_op(self):
bts = self.bts
Expand Down
2 changes: 1 addition & 1 deletion tests/beem/test_nodelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUpClass(cls):
def test_get_nodes(self):
nodelist = NodeList()
all_nodes = nodelist.get_nodes(normal=True, appbase=True, dev=True, testnet=True, testnetdev=True)
self.assertEqual(len(nodelist) - 2, len(all_nodes))
self.assertEqual(len(nodelist) - 6, len(all_nodes))
https_nodes = nodelist.get_nodes(wss=False)
self.assertEqual(https_nodes[0][:5], 'https')

Expand Down
6 changes: 6 additions & 0 deletions tests/beem/test_steem.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,12 @@ def test_sp_to_rshares(self):
rshares = stm.sp_to_rshares(stm.vests_to_sp(1e6))
self.assertTrue(abs(rshares - 20000000000.0) < 2)

def test_rshares_to_vests(self):
stm = self.bts
rshares = stm.sp_to_rshares(stm.vests_to_sp(1e6))
rshares2 = stm.vests_to_rshares(1e6)
self.assertTrue(abs(rshares - rshares2) < 2)

def test_sp_to_sbd(self):
stm = self.bts
sp = 500
Expand Down

0 comments on commit 78281e7

Please sign in to comment.