def __enter__(self): self._steemd_lock.acquire() # Setup temp directory to use as the data directory for this self._temp_data_dir = TemporaryDirectory() for child in self._data_dir.iterdir(): if (child.is_dir()): copytree(str(child), str(self._temp_data_dir.name) + '/' + child.name) db_version = Path(self._data_dir.name) / 'db_version' if (db_version.exists() and not db_version.is_dir()): copy2(str(db_version), str(self._temp_data_dir.name) + '/db_version') config = Path(self._temp_data_dir.name) / 'config.ini' config.touch() config.write_text(self._get_config()) steemd = [ str(self._steemd_bin), '--data-dir=' + str(self._temp_data_dir.name) ] steemd.extend(self._args) self._steemd_process = Popen(steemd, stdout=self.steemd_out, stderr=self.steemd_err) self._steemd_process.poll() sleep(5) if (not self._steemd_process.returncode): self._rpc = GolosNodeRPC('ws://127.0.0.1:8095', '', '') else: raise Exception("golosd did not start properly...")
def run_steemd_tests(debug_node): from steemapi.steemnoderpc import GolosNodeRPC try: print('Replaying blocks...', ) sys.stdout.flush() total_blocks = 0 while (total_blocks % 100000 == 0): total_blocks += debug_node.debug_push_blocks( 100000, skip_validate_invariants=True) print('Blocks Replayed: ' + str(total_blocks)) sys.stdout.flush() print("Triggering payouts") sys.stdout.flush() debug_node.debug_generate_blocks_until(1467590400 - 3) rpc = GolosNodeRPC('ws://127.0.0.1:8095', '', '') ret = rpc.lookup_accounts('', str(0xFFFFFFFF)) debug_node.debug_generate_blocks(1) print("Generating blocks to verify nothing broke") assert (debug_node.debug_generate_blocks(10) == 10) account_rewards = {} vote_count = {} for acc_name in ret: acc = rpc.get_accounts([acc_name]) #print( acc_name + ',' + acc[0][ 'curation_rewards' ] ) account_rewards[acc_name] = float( acc[0]['curation_rewards'].split(' ')[0]) vote_count[acc_name] = int(acc[0]['lifetime_vote_count']) ''' print( "Done!" ) print( "Getting comment dump:" ) sys.stdout.flush() ret = rpc.get_discussions_by_cashout_time( '', '', str( 0xFFFFFFFF ) ); print( 'author, url, total_payout_value, abs_rshares, num_active_votes' ) for comment in ret: print( comment[ 'author' ] + ', ' + comment[ 'url' ] + ', ' + comment[ 'total_payout_value' ] + ', ' + comment[ 'cashout_time' ] ) ''' print("Printing account reward dump:") sorted_rewards = sorted(account_rewards.items(), key=operator.itemgetter(1)) print("account, curation_steem") for rew in sorted_rewards: print(rew[0] + ', ' + str(rew[1]) + ', ' + str(vote_count[rew[0]])) except ValueError as val_err: print(str(val_err))