def update_in_vote(self, timestamp, weight, op): v = Vote(op) try: v.refresh() self.in_vote_timestamp.append(timestamp) self.in_vote_weight.append(weight) self.in_vote_rep.append(int(v["reputation"])) self.in_vote_rshares.append(int(v["rshares"])) except: print("Could not found: %s" % v) return
def test_vote(self): bts = self.bts vote = Vote(self.authorpermvoter, hive_instance=bts) self.assertEqual(self.voter, vote["voter"]) self.assertEqual(self.author, vote["author"]) self.assertEqual(self.permlink, vote["permlink"]) vote = Vote(self.voter, authorperm=self.authorperm, hive_instance=bts) self.assertEqual(self.voter, vote["voter"]) self.assertEqual(self.author, vote["author"]) self.assertEqual(self.permlink, vote["permlink"]) vote_json = vote.json() self.assertEqual(self.voter, vote_json["voter"]) self.assertEqual(self.voter, vote.voter) self.assertTrue(vote.weight >= 0) self.assertTrue(vote.hbd >= 0) self.assertTrue(vote.rshares >= 0) self.assertTrue(vote.percent >= 0) self.assertTrue(vote.reputation is not None) self.assertTrue(vote.rep is not None) self.assertTrue(vote.time is not None) vote.refresh() self.assertEqual(self.voter, vote["voter"]) self.assertEqual(self.author, vote["author"]) self.assertEqual(self.permlink, vote["permlink"]) vote_json = vote.json() self.assertEqual(self.voter, vote_json["voter"]) self.assertEqual(self.voter, vote.voter) self.assertTrue(vote.weight >= 0) self.assertTrue(vote.hbd >= 0) self.assertTrue(vote.rshares >= 0) self.assertTrue(vote.percent >= 0) self.assertTrue(vote.reputation is not None) self.assertTrue(vote.rep is not None) self.assertTrue(vote.time is not None)
def test_keyerror(self): bts = self.bts with self.assertRaises(exceptions.VoteDoesNotExistsException): Vote(construct_authorpermvoter(self.author, self.permlink, "asdfsldfjlasd"), hive_instance=bts) with self.assertRaises(exceptions.VoteDoesNotExistsException): Vote(construct_authorpermvoter(self.author, "sdlfjd", "asdfsldfjlasd"), hive_instance=bts) with self.assertRaises(exceptions.VoteDoesNotExistsException): Vote(construct_authorpermvoter("sdalfj", "dsfa", "asdfsldfjlasd"), hive_instance=bts)
def test_vote(self, node_param): if node_param == "instance": set_shared_hive_instance(self.bts) o = Vote(self.authorpermvoter) self.assertIn(o.hive.rpc.url, self.urls) with self.assertRaises(RPCConnection): Vote(self.authorpermvoter, hive_instance=Hive(node="https://abc.d", autoconnect=False, num_retries=1)) else: set_shared_hive_instance( Hive(node="https://abc.d", autoconnect=False, num_retries=1)) hv = self.bts o = Vote(self.authorpermvoter, hive_instance=hv) self.assertIn(o.hive.rpc.url, self.urls) with self.assertRaises(RPCConnection): Vote(self.authorpermvoter)
def benchmark_node(node, how_many_minutes=10, how_many_seconds=30): block_count = 0 history_count = 0 access_time = 0 follow_time = 0 blockchain_version = u'0.0.0' successful = True error_msg = None start_total = timer() max_batch_size = None threading = False thread_num = 16 authorpermvoter = u"@gtg/hive-pressure-4-need-for-speed|gandalf" [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter) authorperm = construct_authorperm(author, permlink) last_block_id = 19273700 try: hv = Hive(node=node, num_retries=3, num_retries_call=3, timeout=30) blockchain = Blockchain(hive_instance=hv) blockchain_version = hv.get_blockchain_version() last_block = Block(last_block_id, hive_instance=hv) stopTime = last_block.time() + timedelta(seconds=how_many_minutes * 60) total_transaction = 0 start = timer() for entry in blockchain.blocks(start=last_block_id, max_batch_size=max_batch_size, threading=threading, thread_num=thread_num): block_no = entry.identifier block_count += 1 if "block" in entry: trxs = entry["block"]["transactions"] else: trxs = entry["transactions"] for tx in trxs: for op in tx["operations"]: total_transaction += 1 if "block" in entry: block_time = parse_time(entry["block"]["timestamp"]) else: block_time = parse_time(entry["timestamp"]) if block_time > stopTime: last_block_id = block_no break if timer() - start > how_many_seconds or quit_thread: break except NumRetriesReached: error_msg = 'NumRetriesReached' block_count = -1 except KeyboardInterrupt: error_msg = 'KeyboardInterrupt' # quit = True except Exception as e: error_msg = str(e) block_count = -1 try: hv = Hive(node=node, num_retries=3, num_retries_call=3, timeout=30) account = Account("gtg", hive_instance=hv) blockchain_version = hv.get_blockchain_version() start = timer() for acc_op in account.history_reverse(batch_size=100): history_count += 1 if timer() - start > how_many_seconds or quit_thread: break except NumRetriesReached: error_msg = 'NumRetriesReached' history_count = -1 successful = False except KeyboardInterrupt: error_msg = 'KeyboardInterrupt' history_count = -1 successful = False # quit = True except Exception as e: error_msg = str(e) history_count = -1 successful = False try: hv = Hive(node=node, num_retries=3, num_retries_call=3, timeout=30) account = Account("gtg", hive_instance=hv) blockchain_version = hv.get_blockchain_version() start = timer() Vote(authorpermvoter, hive_instance=hv) stop = timer() vote_time = stop - start start = timer() Comment(authorperm, hive_instance=hv) stop = timer() comment_time = stop - start start = timer() Account(author, hive_instance=hv) stop = timer() account_time = stop - start start = timer() account.get_followers() stop = timer() follow_time = stop - start access_time = (vote_time + comment_time + account_time + follow_time) / 4.0 except NumRetriesReached: error_msg = 'NumRetriesReached' access_time = -1 except KeyboardInterrupt: error_msg = 'KeyboardInterrupt' # quit = True except Exception as e: error_msg = str(e) access_time = -1 return {'successful': successful, 'node': node, 'error': error_msg, 'total_duration': timer() - start_total, 'block_count': block_count, 'history_count': history_count, 'access_time': access_time, 'follow_time': follow_time, 'version': blockchain_version}