Browse Source

Add send_await_disconnect() method to p2p-compactblocks.py

p2p-compactblocks was incorrectly using sync_with_ping() when sending in
invalid block. The node would disconnect us and never respond to the
ping, so the sync_with_ping would just time out after 30 seconds and
continue with the test.

This commit adds a send_await_disconnect() method that sends the
message, and then waits for the node to disconnect us. In this commit
I've added the method to p2p-compactblocks.py, but a future commit could
move it to mininode since it could be useful more generally.

This commit reduces the p2p-compactblock runtime by 30 seconds.
0.15
John Newbery 8 years ago
parent
commit
6426716a99
  1. 23
      test/functional/p2p-compactblocks.py

23
test/functional/p2p-compactblocks.py

@ -32,6 +32,13 @@ class TestNode(NodeConnCB): @@ -32,6 +32,13 @@ class TestNode(NodeConnCB):
# This is for synchronizing the p2p message traffic,
# so we can eg wait until a particular block is announced.
self.set_announced_blockhashes = set()
self.connected = False
def on_open(self, conn):
self.connected = True
def on_close(self, conn):
self.connected = False
def on_sendcmpct(self, conn, message):
self.last_sendcmpct.append(message)
@ -107,6 +114,18 @@ class TestNode(NodeConnCB): @@ -107,6 +114,18 @@ class TestNode(NodeConnCB):
return (block_hash in self.set_announced_blockhashes)
return wait_until(received_hash, timeout=timeout)
def send_await_disconnect(self, message, timeout=30):
"""Sends a message to the node and wait for disconnect.
This is used when we want to send a message into the node that we expect
will get us disconnected, eg an invalid block."""
self.send_message(message)
success = wait_until(lambda: not self.connected, timeout=timeout)
if not success:
logger.error("send_await_disconnect failed!")
raise AssertionError("send_await_disconnect failed!")
return success
class CompactBlocksTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
@ -274,8 +293,8 @@ class CompactBlocksTest(BitcoinTestFramework): @@ -274,8 +293,8 @@ class CompactBlocksTest(BitcoinTestFramework):
# This index will be too high
prefilled_txn = PrefilledTransaction(1, block.vtx[0])
cmpct_block.prefilled_txn = [prefilled_txn]
self.test_node.send_and_ping(msg_cmpctblock(cmpct_block))
assert(int(self.nodes[0].getbestblockhash(), 16) == block.hashPrevBlock)
self.test_node.send_await_disconnect(msg_cmpctblock(cmpct_block))
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.hashPrevBlock)
# Compare the generated shortids to what we expect based on BIP 152, given
# bitcoind's choice of nonce.

Loading…
Cancel
Save