def send_blocks_and_test(self, blocks, rpc, success=True, request_block=True, reject_code=None, reject_reason=None, timeout=60):
    "Send blocks to test node and test whether the tip advances.\n\n         - add all blocks to our block_store\n         - send a headers message for the final block\n         - the on_getheaders handler will ensure that any getheaders are responded to\n         - if request_block is True: wait for getdata for each of the blocks. The on_getdata handler will\n           ensure that any getdata messages are responded to\n         - if success is True: assert that the node's tip advances to the most recent block\n         - if success is False: assert that the node's tip doesn't advance\n         - if reject_code and reject_reason are set: assert that the correct reject message is received"
    with mininode_lock:
        self.reject_code_received = None
        self.reject_reason_received = None
        for block in blocks:
            self.block_store[block.sha256] = block
            self.last_block_hash = block.sha256
    self.send_message(msg_headers([CBlockHeader(blocks[(- 1)])]))
    if request_block:
        wait_until((lambda : (blocks[(- 1)].sha256 in self.getdata_requests)), timeout=timeout, lock=mininode_lock)
    if success:
        wait_until((lambda : (rpc.getbestblockhash() == blocks[(- 1)].hash)), timeout=timeout)
    else:
        assert (rpc.getbestblockhash() != blocks[(- 1)].hash)
    if (reject_code is not None):
        wait_until((lambda : (self.reject_code_received == reject_code)), lock=mininode_lock)
    if (reject_reason is not None):
        wait_until((lambda : (self.reject_reason_received == reject_reason)), lock=mininode_lock)
Send blocks to test node and test whether the tip advances.

- add all blocks to our block_store
- send a headers message for the final block
- the on_getheaders handler will ensure that any getheaders are responded to
- if request_block is True: wait for getdata for each of the blocks. The on_getdata handler will
  ensure that any getdata messages are responded to
- if success is True: assert that the node's tip advances to the most recent block
- if success is False: assert that the node's tip doesn't advance
- if reject_code and reject_reason are set: assert that the correct reject message is received
def send_blocks_and_test(self, blocks, rpc, success=True, request_block=True, reject_code=None, reject_reason=None, timeout=60):
    "Send blocks to test node and test whether the tip advances.\n\n         - add all blocks to our block_store\n         - send a headers message for the final block\n         - the on_getheaders handler will ensure that any getheaders are responded to\n         - if request_block is True: wait for getdata for each of the blocks. The on_getdata handler will\n           ensure that any getdata messages are responded to\n         - if success is True: assert that the node's tip advances to the most recent block\n         - if success is False: assert that the node's tip doesn't advance\n         - if reject_code and reject_reason are set: assert that the correct reject message is received"
    with mininode_lock:
        self.reject_code_received = None
        self.reject_reason_received = None
        for block in blocks:
            self.block_store[block.sha256] = block
            self.last_block_hash = block.sha256
    self.send_message(msg_headers([CBlockHeader(blocks[(- 1)])]))
    if request_block:
        wait_until((lambda : (blocks[(- 1)].sha256 in self.getdata_requests)), timeout=timeout, lock=mininode_lock)
    if success:
        wait_until((lambda : (rpc.getbestblockhash() == blocks[(- 1)].hash)), timeout=timeout)
    else:
        assert (rpc.getbestblockhash() != blocks[(- 1)].hash)
    if (reject_code is not None):
        wait_until((lambda : (self.reject_code_received == reject_code)), lock=mininode_lock)
    if (reject_reason is not None):
        wait_until((lambda : (self.reject_reason_received == reject_reason)), lock=mininode_lock)