Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_blockchain.py
Show First 20 Lines • Show All 348 Lines • ▼ Show 20 Lines | def _test_stopatheight(self): | ||||
self.log.debug('Node should stop at this height...') | self.log.debug('Node should stop at this height...') | ||||
self.nodes[0].wait_until_stopped() | self.nodes[0].wait_until_stopped() | ||||
self.start_node(0) | self.start_node(0) | ||||
assert_equal(self.nodes[0].getblockcount(), 207) | assert_equal(self.nodes[0].getblockcount(), 207) | ||||
def _test_waitforblockheight(self): | def _test_waitforblockheight(self): | ||||
self.log.info("Test waitforblockheight") | self.log.info("Test waitforblockheight") | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
node.add_p2p_connection(P2PInterface()) | peer = node.add_p2p_connection(P2PInterface()) | ||||
current_height = node.getblock(node.getbestblockhash())['height'] | current_height = node.getblock(node.getbestblockhash())['height'] | ||||
# Create a fork somewhere below our current height, invalidate the tip | # Create a fork somewhere below our current height, invalidate the tip | ||||
# of that fork, and then ensure that waitforblockheight still | # of that fork, and then ensure that waitforblockheight still | ||||
# works as expected. | # works as expected. | ||||
# | # | ||||
# (Previously this was broken based on setting | # (Previously this was broken based on setting | ||||
# `rpc/blockchain.cpp:latestblock` incorrectly.) | # `rpc/blockchain.cpp:latestblock` incorrectly.) | ||||
# | # | ||||
b20hash = node.getblockhash(20) | b20hash = node.getblockhash(20) | ||||
b20 = node.getblock(b20hash) | b20 = node.getblock(b20hash) | ||||
def solve_and_send_block(prevhash, height, time): | def solve_and_send_block(prevhash, height, time): | ||||
b = create_block(prevhash, create_coinbase(height), time) | b = create_block(prevhash, create_coinbase(height), time) | ||||
b.solve() | b.solve() | ||||
node.p2p.send_and_ping(msg_block(b)) | peer.send_and_ping(msg_block(b)) | ||||
return b | return b | ||||
b21f = solve_and_send_block(int(b20hash, 16), 21, b20['time'] + 1) | b21f = solve_and_send_block(int(b20hash, 16), 21, b20['time'] + 1) | ||||
b22f = solve_and_send_block(b21f.sha256, 22, b21f.nTime + 1) | b22f = solve_and_send_block(b21f.sha256, 22, b21f.nTime + 1) | ||||
node.invalidateblock(b22f.hash) | node.invalidateblock(b22f.hash) | ||||
def assert_waitforheight(height, timeout=2): | def assert_waitforheight(height, timeout=2): | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |