def test_blockchain(self): bts = self.bts b = Blockchain(dpay_instance=bts) num = b.get_current_block_num() self.assertTrue(num > 0) self.assertTrue(isinstance(num, int)) block = b.get_current_block() self.assertTrue(isinstance(block, Block)) self.assertTrue((num - block.identifier) < 3) block_time = b.block_time(block.identifier) self.assertEqual(block.time(), block_time) block_timestamp = b.block_timestamp(block.identifier) timestamp = int(time.mktime(block.time().timetuple())) self.assertEqual(block_timestamp, timestamp)
def test_estimate_block_num(self): bts = self.bts b = Blockchain(dpay_instance=bts) last_block = b.get_current_block() num = last_block.identifier old_block = Block(num - 60, dpay_instance=bts) date = old_block.time() est_block_num = b.get_estimated_block_num(date, accurate=False) self.assertTrue((est_block_num - (old_block.identifier)) < 10) est_block_num = b.get_estimated_block_num(date, accurate=True) self.assertTrue((est_block_num - (old_block.identifier)) < 2) est_block_num = b.get_estimated_block_num(date, estimateForwards=True, accurate=True) self.assertTrue((est_block_num - (old_block.identifier)) < 2) est_block_num = b.get_estimated_block_num(date, estimateForwards=True, accurate=False)
authorperm = construct_authorperm(vote_event["author"], vote_event["permlink"]) # print(authorperm) try: process_vote_content(Comment(authorperm)) except exceptions.ContentDoesNotExistsException: print("Could not find Comment: %s" % (authorperm)) al = list() if not vote_event["voter"] in self.looked_up: al.append(vote_event["voter"]) self.looked_up.add(vote_event["voter"]) if not vote_event["author"] in self.looked_up: al.append(vote_event["author"]) self.looked_up.add(vote_event["author"]) if len(al) > 0: lookup_accounts(al) if __name__ == "__main__": wtw = WatchingTheWatchers() tb = WatchingTheWatchersBot(wtw) blockchain = Blockchain() threading = True thread_num = 16 cur_block = blockchain.get_current_block() stop = cur_block.identifier startdate = cur_block.time() - timedelta(days=1) start = blockchain.get_estimated_block_num(startdate, accurate=True) for vote in blockchain.stream(opNames=["vote"], start=start, stop=stop, threading=threading, thread_num=thread_num): tb.vote(vote) wtw.report()
if useWallet: stm.wallet.addPrivateKey(owner_privkey) stm.wallet.addPrivateKey(active_privkey) stm.wallet.addPrivateKey(memo_privkey) stm.wallet.addPrivateKey(posting_privkey) else: stm = DPay(node=testnet_node, wif={ 'active': str(active_privkey), 'posting': str(posting_privkey), 'memo': str(memo_privkey) }) account = Account(username, dpay_instance=stm) if account["name"] == "dpaycli": account.disallow("dpaycli1", permission='posting') account.allow('dpaycli1', weight=1, permission='posting', account=None) account.follow("dpaycli1") elif account["name"] == "dpaycli5": account.allow('dpaycli4', weight=2, permission='active', account=None) if useWallet: stm.wallet.getAccountFromPrivateKey(str(active_privkey)) # stm.create_account("dpaycli1", creator=account, password=password1) account1 = Account("dpaycli1", dpay_instance=stm) b = Blockchain(dpay_instance=stm) blocknum = b.get_current_block().identifier account.transfer("dpaycli1", 1, "BBD", "test") b1 = Block(blocknum, dpay_instance=stm)
if __name__ == "__main__": node_setup = 1 threading = True thread_num = 8 timeout = 10 nodes = NodeList() nodes.update_nodes(weights={"block": 1}) node_list = nodes.get_nodes()[:5] vote_result = [] duration = [] stm = DPay(node=node_list, timeout=timeout) b = Blockchain(dpay_instance=stm) block = b.get_current_block() block.set_cache_auto_clean(False) opcount, total_duration = stream_votes(stm, threading, thread_num) print("Finished!") block.set_cache_auto_clean(True) cache_len = len(list(block._cache)) start_time = time.time() block.clear_cache_from_expired_items() clear_duration = time.time() - start_time time.sleep(5) cache_len_after = len(list(block._cache)) start_time = time.time() print(str(block._cache)) clear_duration2 = time.time() - start_time print("Results:") print("%d Threads with https duration: %.2f s - votes: %d" % (thread_num, total_duration, opcount))