def _test_waitforblockheight(self):
    self.log.info('Test waitforblockheight')
    node = self.nodes[0]
    node.add_p2p_connection(P2PInterface())
    network_thread_start()
    node.p2p.wait_for_verack()
    current_height = node.getblock(node.getbestblockhash())['height']
    b20hash = node.getblockhash(20)
    b20 = node.getblock(b20hash)

    def solve_and_send_block(prevhash, height, time):
        b = create_block(prevhash, create_coinbase(height), time)
        b.solve()
        node.p2p.send_message(msg_block(b))
        node.p2p.sync_with_ping()
        return b
    b21f = solve_and_send_block(int(b20hash, 16), 21, (b20['time'] + 1))
    b22f = solve_and_send_block(b21f.sha256, 22, (b21f.nTime + 1))
    node.invalidateblock(b22f.hash)

    def assert_waitforheight(height, timeout=2):
        assert_equal(node.waitforblockheight(height, timeout)['height'], current_height)
    assert_waitforheight(0)
    assert_waitforheight((current_height - 1))
    assert_waitforheight(current_height)
    assert_waitforheight((current_height + 1))
def _test_waitforblockheight(self):
    self.log.info('Test waitforblockheight')
    node = self.nodes[0]
    node.add_p2p_connection(P2PInterface())
    network_thread_start()
    node.p2p.wait_for_verack()
    current_height = node.getblock(node.getbestblockhash())['height']
    b20hash = node.getblockhash(20)
    b20 = node.getblock(b20hash)

    def solve_and_send_block(prevhash, height, time):
        b = create_block(prevhash, create_coinbase(height), time)
        b.solve()
        node.p2p.send_message(msg_block(b))
        node.p2p.sync_with_ping()
        return b
    b21f = solve_and_send_block(int(b20hash, 16), 21, (b20['time'] + 1))
    b22f = solve_and_send_block(b21f.sha256, 22, (b21f.nTime + 1))
    node.invalidateblock(b22f.hash)

    def assert_waitforheight(height, timeout=2):
        assert_equal(node.waitforblockheight(height, timeout)['height'], current_height)
    assert_waitforheight(0)
    assert_waitforheight((current_height - 1))
    assert_waitforheight(current_height)
    assert_waitforheight((current_height + 1))