Exemple #1
0
    def _give_nodes_spendable_coins(self, threadpool):
        nodes = list(self._context.nodes.values())
        cbs = []
        for i, node in enumerate(nodes):
            cbs.append(
                threadpool.apply_async(
                    node_utils.start_node,
                    args=(node, (str(node.ip)
                                 for node in nodes[max(0, i - 5):i]))))
        for cb in cbs:
            cb.get()

        threadpool.map(node_utils.check_startup_node, nodes)

        amount_of_tx_chains = _calc_number_of_tx_chains(
            self._context.args.txs_per_tick,
            self._context.args.blocks_per_tick, len(nodes))
        logging.info(
            'Each node receives {} tx-chains'.format(amount_of_tx_chains))

        for i, node in enumerate(nodes):
            node_utils.wait_until_height_reached(node, i * amount_of_tx_chains)
            node.execute_rpc('generate', amount_of_tx_chains)
            logging.info(
                'Generated {} blocks for node={} for their tx-chains'.format(
                    amount_of_tx_chains, node.name))

        node_utils.wait_until_height_reached(nodes[0],
                                             amount_of_tx_chains * len(nodes))
        nodes[0].generate_blocks(
            config.blocks_needed_to_make_coinbase_spendable)
        current_height = config.blocks_needed_to_make_coinbase_spendable + amount_of_tx_chains * len(
            nodes)

        threadpool.starmap(node_utils.wait_until_height_reached,
                           zip(nodes, itertools.repeat(current_height)))

        # TODO fix coinbase behaviour where [Example1](#AppendixA) does not occur
        # self._pool.map(node_utils.transfer_coinbase_tx_to_normal_tx, nodes)

        for i, node in enumerate(nodes):
            node_utils.wait_until_height_reached(node, current_height + i)
            node.execute_rpc('generate', 1)

        current_height += len(nodes)
        # TODO fix
        self._context.first_block_height = 0  # current_height

        threadpool.starmap(node_utils.wait_until_height_reached,
                           zip(nodes, itertools.repeat(current_height)))

        threadpool.map(node_utils.rm_peers_file, nodes)
        node_utils.graceful_rm(threadpool, nodes)
Exemple #2
0
    def _give_nodes_spendable_coins(self):
        # At start no node will have coins,
        # assign them manually to make for smooth run
        # We do this before the RPC is ready, making it perfect fit
        nodes = list(self._context.nodes.values())
        cbs = []
        for i, node in enumerate(nodes):
            cbs.append(
                self._pool.apply_async(
                    node_utils.start_node,
                    args=(node, (str(node.ip)
                                 for node in nodes[max(0, i - 5):i]))))
        for cb in cbs:
            cb.get()

        self._pool.map(node_utils.check_startup_node, nodes)

        amount_of_tx_chains = _calc_number_of_tx_chains(
            self._context.args.txs_per_tick,
            self._context.args.blocks_per_tick, len(nodes))
        logging.info('Each node got {} tx-chains'.format(amount_of_tx_chains))

        for i, node in enumerate(nodes):
            node_utils.wait_until_height_reached(node, i * amount_of_tx_chains)
            node.execute_rpc('generate', amount_of_tx_chains)
            logging.info(
                'Generated {} blocks for node'.format(amount_of_tx_chains))

        node_utils.wait_until_height_reached(nodes[0],
                                             amount_of_tx_chains * len(nodes))
        nodes[0].generate_blocks(
            config.blocks_needed_to_make_coinbase_spendable)
        current_height = config.blocks_needed_to_make_coinbase_spendable + amount_of_tx_chains * len(
            nodes)

        self._pool.starmap(node_utils.wait_until_height_reached,
                           zip(nodes, itertools.repeat(current_height)))

        self._pool.map(node_utils.transfer_coinbase_tx_to_normal_tx, nodes)

        for i, node in enumerate(nodes):
            node_utils.wait_until_height_reached(node, current_height + i)
            node.execute_rpc('generate', 1)

        current_height += len(nodes)
        self._context.first_block_height = current_height

        self._pool.starmap(node_utils.wait_until_height_reached,
                           zip(nodes, itertools.repeat(current_height)))

        self._pool.map(node_utils.rm_peers_file, nodes)
        node_utils.graceful_rm(self._pool, nodes)
Exemple #3
0
def test_wait_until_height_reached_already_reached(m_sleep):
    node = MagicMock()
    node.execute_rpc.return_value = '10'
    node_utils.wait_until_height_reached(node, 10)

    assert m_sleep.called is False
Exemple #4
0
def test_wait_until_height_reached(m_sleep):
    node = MagicMock()
    node.execute_rpc.side_effect = ['0', '9', '10']
    node_utils.wait_until_height_reached(node, 10)

    assert m_sleep.call_count == 2