Example #1
0
    def _test_case(self):
        self.log.warning("running _test_case()")

        # Generate simple transactions
        tx_amount = 10000
        self.log.info(
            "generate simple transactions on node0, amount {}".format(
                tx_amount))
        self.generate_simple_transaction(node_id=0, tx_amount=tx_amount)

        # Generate vbk_blocks
        vbk_blocks = 15000
        self.log.info(
            "generate vbk blocks on node0, amount {}".format(vbk_blocks))
        mine_vbk_blocks(self.nodes[0], self.apm, vbk_blocks)

        containingblockhash = self.nodes[0].generate(nblocks=1)[0]
        containingblock = self.nodes[0].getblock(containingblockhash)

        assert len(containingblock['tx']) > 1
        assert len(containingblock['tx']) < tx_amount + 1
        assert len(containingblock['pop']['data']['vbkblocks']) != 0
        assert len(containingblock['pop']['data']['vbkblocks']) < vbk_blocks

        self.log.info("sync nodes")
        self.sync_blocks(self.nodes, timeout=600)

        containingblock = self.nodes[1].getblock(containingblockhash)
        assert len(containingblock['tx']) > 1
        assert len(containingblock['tx']) < tx_amount + 1
        assert len(containingblock['pop']['data']['vbkblocks']) != 0
        assert len(containingblock['pop']['data']['vbkblocks']) < vbk_blocks

        self.log.warning("success! _test_case()")
    def _test_case_vbk(self, payloads_amount):
        self.log.info("running _test_case_vbk()")

        vbk_blocks = mine_vbk_blocks(self.nodes[0], self.apm, payloads_amount)

        # mine a block on node[1] with this pop tx
        containingblockhash = self.nodes[0].generate(nblocks=1)[0]
        containingblock = self.nodes[0].getblock(containingblockhash)

        assert len(containingblock['pop']['data']['vbkblocks']) == payloads_amount == len(vbk_blocks)

        self.log.info("success! _test_case_vbk()")
    def _test_mempool_reorg_case(self):
        self.log.info("running _test_mempool_reorg_case()")

        self.log.info("disconnect nodes 0 and 1")
        disconnect_nodes(self.nodes[0], 1)

        vbk_blocks_amount = 10
        self.log.info("generate {} vbk blocks".format(vbk_blocks_amount))
        vbk_blocks = mine_vbk_blocks(self.nodes[0], self.apm, vbk_blocks_amount)

        # mine a block on node[0] with these vbk blocks
        node0_tip_hash = self.nodes[0].generate(nblocks=1)[0]
        node0_tip = self.nodes[0].getblock(node0_tip_hash)

        assert len(node0_tip['pop']['data']['vbkblocks']) == vbk_blocks_amount == len(vbk_blocks)
        assert_equal(node0_tip, self.get_best_block(0))

        node1_tip = self.get_best_block(1)

        assert node1_tip['hash'] != node0_tip['hash']

        self.log.info("node 1 mine 10 blocks")
        node1_tip_hash = self.nodes[1].generate(nblocks=10)[9]
        node1_tip = self.nodes[1].getblock(node1_tip_hash)

        assert_equal(node1_tip, self.get_best_block(1))

        connect_nodes(self.nodes[0], 1)
        self.log.info("connect node 1 and node 0")

        self.sync_all(self.nodes, timeout=30)
        self.log.info("nodes[0,1] are in sync")

        assert_equal(self.get_best_block(1), self.get_best_block(0))

        # mine a block on node[1] with these vbk blocks
        tip_hash = self.nodes[1].generate(nblocks=1)[0]
        tip = self.nodes[1].getblock(tip_hash)

        assert len(tip['pop']['data']['vbkblocks']) == vbk_blocks_amount == len(vbk_blocks)

        self.log.info("success! _test_mempool_reorg_case()")