Beispiel #1
0
 def test_stream_threading(self):
     bts = self.bts
     b = Blockchain(steem_instance=bts)
     ops_stream = []
     opNames = ["transfer", "vote"]
     for op in b.stream(opNames=opNames, start=self.start, stop=self.stop):
         ops_stream.append(op)
     self.assertTrue(len(ops_stream) > 0)
     op_stat = b.ops_statistics(start=self.start, stop=self.stop)
     ops_blocks = []
     for op in b.blocks(start=self.start,
                        stop=self.stop,
                        threading=True,
                        thread_num=8):
         ops_blocks.append(op)
     op_stat4 = {"transfer": 0, "vote": 0}
     self.assertTrue(len(ops_blocks) > 0)
     for block in ops_blocks:
         for tran in block["transactions"]:
             for op in tran['operations']:
                 if op[0] in opNames:
                     op_stat4[op[0]] += 1
         self.assertTrue(block.identifier >= self.start)
         self.assertTrue(block.identifier <= self.stop)
     self.assertEqual(op_stat["transfer"], op_stat4["transfer"])
     self.assertEqual(op_stat["vote"], op_stat4["vote"])
Beispiel #2
0
 def test_stream_batch(self):
     bts = self.bts
     b = Blockchain(steem_instance=bts)
     ops_stream = []
     opNames = ["transfer", "vote"]
     for op in b.stream(opNames=opNames, start=self.start, stop=self.stop, max_batch_size=self.max_batch_size, threading=False):
         ops_stream.append(op)
     self.assertTrue(ops_stream[0]["block_num"] >= self.start)
     self.assertTrue(ops_stream[-1]["block_num"] <= self.stop)
     op_stat = b.ops_statistics(start=self.start, stop=self.stop)
     self.assertEqual(op_stat["vote"] + op_stat["transfer"], len(ops_stream))
     ops_blocks = []
     for op in b.blocks(start=self.start, stop=self.stop, max_batch_size=self.max_batch_size, threading=False):
         ops_blocks.append(op)
     op_stat4 = {"transfer": 0, "vote": 0}
     self.assertTrue(len(ops_blocks) > 0)
     for block in ops_blocks:
         for tran in block["transactions"]:
             for op in tran['operations']:
                 if isinstance(op, dict) and "type" in op and "value" in op:
                     op_type = op["type"]
                     if len(op_type) > 10 and op_type[len(op_type) - 10:] == "_operation":
                         op_type = op_type[:-10]
                     if op_type in opNames:
                         op_stat4[op_type] += 1
                 elif op[0] in opNames:
                     op_stat4[op[0]] += 1
         self.assertTrue(block.identifier >= self.start)
         self.assertTrue(block.identifier <= self.stop)
     self.assertEqual(op_stat["transfer"], op_stat4["transfer"])
     self.assertEqual(op_stat["vote"], op_stat4["vote"])
Beispiel #3
0
    def test_stream(self, node_param):
        if node_param == "non_appbase":
            bts = self.bts
        else:
            bts = self.appbase
        b = Blockchain(steem_instance=bts)
        ops_stream = []
        opNames = ["transfer", "vote"]
        for op in b.stream(opNames=opNames, start=self.start, stop=self.stop):
            ops_stream.append(op)
        self.assertTrue(len(ops_stream) > 0)
        op_stat = b.ops_statistics(start=self.start, stop=self.stop)
        op_stat2 = {"transfer": 0, "vote": 0}
        for op in ops_stream:
            self.assertIn(op["type"], opNames)
            op_stat2[op["type"]] += 1
            self.assertTrue(op["block_num"] >= self.start)
            self.assertTrue(op["block_num"] <= self.stop)
        self.assertEqual(op_stat["transfer"], op_stat2["transfer"])
        self.assertEqual(op_stat["vote"], op_stat2["vote"])

        ops_ops = []
        for op in b.ops(start=self.start, stop=self.stop):
            ops_ops.append(op)
        self.assertTrue(len(ops_ops) > 0)
        op_stat3 = {"transfer": 0, "vote": 0}

        for op in ops_ops:
            if op["op"][0] in opNames:
                op_stat3[op["op"][0]] += 1
            self.assertTrue(op["block_num"] >= self.start)
            self.assertTrue(op["block_num"] <= self.stop)
        self.assertEqual(op_stat["transfer"], op_stat3["transfer"])
        self.assertEqual(op_stat["vote"], op_stat3["vote"])

        ops_blocks = []
        for op in b.blocks(start=self.start, stop=self.stop):
            ops_blocks.append(op)
        op_stat4 = {"transfer": 0, "vote": 0}
        self.assertTrue(len(ops_blocks) > 0)
        for block in ops_blocks:
            for tran in block["transactions"]:
                for op in tran['operations']:
                    if op[0] in opNames:
                        op_stat4[op[0]] += 1
            self.assertTrue(block.identifier >= self.start)
            self.assertTrue(block.identifier <= self.stop)
        self.assertEqual(op_stat["transfer"], op_stat4["transfer"])
        self.assertEqual(op_stat["vote"], op_stat4["vote"])

        ops_blocks = []
        for op in b.blocks():
            ops_blocks.append(op)
            break
        self.assertTrue(len(ops_blocks) == 1)
Beispiel #4
0
 def test_stream_batch2(self):
     bts = self.bts
     b = Blockchain(steem_instance=bts)
     ops_stream = []
     start_block = 25097000
     stop_block = 25097100
     opNames = ["account_create", "custom_json"]
     for op in b.stream(start=int(start_block), stop=int(stop_block), opNames=opNames, max_batch_size=50, threading=False, thread_num=8):
         ops_stream.append(op)
     self.assertTrue(ops_stream[0]["block_num"] >= start_block)
     self.assertTrue(ops_stream[-1]["block_num"] <= stop_block)
     op_stat = b.ops_statistics(start=start_block, stop=stop_block)
     self.assertEqual(op_stat["account_create"] + op_stat["custom_json"], len(ops_stream))
Beispiel #5
0
    def test_stream(self):
        bts = self.bts
        start = self.start
        stop = self.stop
        b = Blockchain(steem_instance=bts)
        ops_stream = []
        opNames = ["transfer", "vote"]
        for op in b.stream(opNames=opNames, start=start, stop=stop):
            ops_stream.append(op)
        self.assertTrue(len(ops_stream) > 0)

        ops_raw_stream = []
        opNames = ["transfer", "vote"]
        for op in b.stream(opNames=opNames,
                           raw_ops=True,
                           start=start,
                           stop=stop):
            ops_raw_stream.append(op)
        self.assertTrue(len(ops_raw_stream) > 0)

        only_ops_stream = []
        opNames = ["transfer", "vote"]
        for op in b.stream(opNames=opNames,
                           start=start,
                           stop=stop,
                           only_ops=True):
            only_ops_stream.append(op)
        self.assertTrue(len(only_ops_stream) > 0)

        only_ops_raw_stream = []
        opNames = ["transfer", "vote"]
        for op in b.stream(opNames=opNames,
                           raw_ops=True,
                           start=start,
                           stop=stop,
                           only_ops=True):
            only_ops_raw_stream.append(op)
        self.assertTrue(len(only_ops_raw_stream) > 0)

        op_stat = b.ops_statistics(start=start, stop=stop)
        op_stat2 = {"transfer": 0, "vote": 0}
        for op in ops_stream:
            self.assertIn(op["type"], opNames)
            op_stat2[op["type"]] += 1
            self.assertTrue(op["block_num"] >= start)
            self.assertTrue(op["block_num"] <= stop)
        self.assertEqual(op_stat["transfer"], op_stat2["transfer"])
        self.assertEqual(op_stat["vote"], op_stat2["vote"])

        op_stat3 = {"transfer": 0, "vote": 0}
        for op in ops_raw_stream:
            self.assertIn(op["op"][0], opNames)
            op_stat3[op["op"][0]] += 1
            self.assertTrue(op["block_num"] >= start)
            self.assertTrue(op["block_num"] <= stop)
        self.assertEqual(op_stat["transfer"], op_stat3["transfer"])
        self.assertEqual(op_stat["vote"], op_stat3["vote"])

        op_stat5 = {"transfer": 0, "vote": 0}
        for op in only_ops_stream:
            self.assertIn(op["type"], opNames)
            op_stat5[op["type"]] += 1
            self.assertTrue(op["block_num"] >= start)
            self.assertTrue(op["block_num"] <= stop)
        self.assertEqual(op_stat["transfer"], op_stat5["transfer"])
        self.assertEqual(op_stat["vote"], op_stat5["vote"])

        op_stat6 = {"transfer": 0, "vote": 0}
        for op in only_ops_raw_stream:
            self.assertIn(op["op"][0], opNames)
            op_stat6[op["op"][0]] += 1
            self.assertTrue(op["block_num"] >= start)
            self.assertTrue(op["block_num"] <= stop)
        self.assertEqual(op_stat["transfer"], op_stat6["transfer"])
        self.assertEqual(op_stat["vote"], op_stat6["vote"])

        ops_blocks = []
        for op in b.blocks(start=start, stop=stop):
            ops_blocks.append(op)
        op_stat4 = {"transfer": 0, "vote": 0}
        self.assertTrue(len(ops_blocks) > 0)
        for block in ops_blocks:
            for tran in block["transactions"]:
                for op in tran['operations']:
                    if isinstance(op, list) and op[0] in opNames:
                        op_stat4[op[0]] += 1
                    elif isinstance(op, dict):
                        op_type = op["type"]
                        if len(op_type) > 10 and op_type[len(op_type) -
                                                         10:] == "_operation":
                            op_type = op_type[:-10]
                        if op_type in opNames:
                            op_stat4[op_type] += 1
            self.assertTrue(block.identifier >= start)
            self.assertTrue(block.identifier <= stop)
        self.assertEqual(op_stat["transfer"], op_stat4["transfer"])
        self.assertEqual(op_stat["vote"], op_stat4["vote"])

        ops_blocks = []
        for op in b.blocks():
            ops_blocks.append(op)
            break
        self.assertTrue(len(ops_blocks) == 1)