Esempio n. 1
0
 def test_estimate_virtual_op_num(self):
     stm = self.bts
     account = Account("gtg", dpay_instance=stm)
     block_num = 21248120
     block = Block(block_num, dpay_instance=stm)
     op_num1 = account.estimate_virtual_op_num(block.time(), stop_diff=1, max_count=100)
     op_num2 = account.estimate_virtual_op_num(block_num, stop_diff=1, max_count=100)
     op_num3 = account.estimate_virtual_op_num(block_num, stop_diff=100, max_count=100)
     op_num4 = account.estimate_virtual_op_num(block_num, stop_diff=0.00001, max_count=100)
     self.assertTrue(abs(op_num1 - op_num2) < 2)
     self.assertTrue(abs(op_num1 - op_num4) < 2)
     self.assertTrue(abs(op_num1 - op_num3) < 200)
     block_diff1 = 0
     block_diff2 = 0
     for h in account.get_account_history(op_num4 - 1, 0):
         block_diff1 = (block_num - h["block"])
     for h in account.get_account_history(op_num4 + 1, 0):
         block_diff2 = (block_num - h["block"])
     self.assertTrue(block_diff1 > 0)
     self.assertTrue(block_diff2 <= 0)
Esempio n. 2
0
 def test_history_block_num(self, node_param):
     if node_param == "non_appbase":
         stm = self.bts
         zero_element = 0
     else:
         stm = self.appbase
         zero_element = 0  # bug in dpay
     account = Account("fullnodeupdate", dpay_instance=stm)
     h_all_raw = []
     for h in account.history_reverse(raw_output=True):
         h_all_raw.append(h)
     h_list = []
     for h in account.history(start=h_all_raw[-1][1]["block"], stop=h_all_raw[-11 + zero_element][1]["block"], use_block_num=True, batch_size=10, raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], zero_element)
     self.assertEqual(h_list[-1][0], 10)
     self.assertEqual(h_list[0][1]['block'], h_all_raw[-1][1]['block'])
     self.assertEqual(h_list[-1][1]['block'], h_all_raw[-11 + zero_element][1]['block'])
     h_list = []
     for h in account.history_reverse(start=h_all_raw[-11 + zero_element][1]["block"], stop=h_all_raw[-1][1]["block"], use_block_num=True, batch_size=10, raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 10)
     self.assertEqual(h_list[-1][0], zero_element)
     self.assertEqual(h_list[0][1]['block'], h_all_raw[-11 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'], h_all_raw[-1][1]['block'])
     h_list = []
     for h in account.get_account_history(10, 10, use_block_num=True, start=h_all_raw[-2 + zero_element][1]["block"], stop=h_all_raw[-10 + zero_element][1]["block"], order=1, raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 1)
     self.assertEqual(h_list[-1][0], 9)
     self.assertEqual(h_list[0][1]['block'], h_all_raw[-2 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'], h_all_raw[-10 + zero_element][1]['block'])
     h_list = []
     for h in account.get_account_history(10, 10, use_block_num=True, start=h_all_raw[-10 + zero_element][1]["block"], stop=h_all_raw[-2 + zero_element][1]["block"], order=-1, raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 9)
     self.assertEqual(h_list[-1][0], 1)
     self.assertEqual(h_list[0][1]['block'], h_all_raw[-10 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'], h_all_raw[-2 + zero_element][1]['block'])