Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_block.py
Show First 20 Lines • Show All 1,264 Lines • ▼ Show 20 Lines | def update_block(self, block_number, new_transactions, reorder=True): | ||||
del self.block_heights[old_sha256] | del self.block_heights[old_sha256] | ||||
self.blocks[block_number] = block | self.blocks[block_number] = block | ||||
return block | return block | ||||
def bootstrap_p2p(self, timeout=10): | def bootstrap_p2p(self, timeout=10): | ||||
"""Add a P2P connection to the node. | """Add a P2P connection to the node. | ||||
Helper to connect and wait for version handshake.""" | Helper to connect and wait for version handshake.""" | ||||
self.nodes[0].add_p2p_connection(P2PDataStore()) | self.helper_peer = self.nodes[0].add_p2p_connection(P2PDataStore()) | ||||
# We need to wait for the initial getheaders from the peer before we | # We need to wait for the initial getheaders from the peer before we | ||||
# start populating our blockstore. If we don't, then we may run ahead | # start populating our blockstore. If we don't, then we may run ahead | ||||
# to the next subtest before we receive the getheaders. We'd then send | # to the next subtest before we receive the getheaders. We'd then send | ||||
# an INV for the next block and receive two getheaders - one for the | # an INV for the next block and receive two getheaders - one for the | ||||
# IBD and one for the INV. We'd respond to both and could get | # IBD and one for the INV. We'd respond to both and could get | ||||
# unexpectedly disconnected if the DoS score for that error is 50. | # unexpectedly disconnected if the DoS score for that error is 50. | ||||
self.nodes[0].p2p.wait_for_getheaders(timeout=timeout) | self.helper_peer.wait_for_getheaders(timeout=timeout) | ||||
def reconnect_p2p(self, timeout=60): | def reconnect_p2p(self, timeout=60): | ||||
"""Tear down and bootstrap the P2P connection to the node. | """Tear down and bootstrap the P2P connection to the node. | ||||
The node gets disconnected several times in this test. This helper | The node gets disconnected several times in this test. This helper | ||||
method reconnects the p2p and restarts the network thread.""" | method reconnects the p2p and restarts the network thread.""" | ||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
self.bootstrap_p2p(timeout=timeout) | self.bootstrap_p2p(timeout=timeout) | ||||
def send_blocks(self, blocks, success=True, reject_reason=None, | def send_blocks(self, blocks, success=True, reject_reason=None, | ||||
force_send=False, reconnect=False, timeout=60): | force_send=False, reconnect=False, timeout=60): | ||||
"""Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block. | """Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block. | ||||
Call with success = False if the tip shouldn't advance to the most recent block.""" | Call with success = False if the tip shouldn't advance to the most recent block.""" | ||||
self.nodes[0].p2p.send_blocks_and_test(blocks, self.nodes[0], success=success, | self.helper_peer.send_blocks_and_test(blocks, self.nodes[0], success=success, | ||||
reject_reason=reject_reason, force_send=force_send, timeout=timeout, expect_disconnect=reconnect) | reject_reason=reject_reason, force_send=force_send, timeout=timeout, expect_disconnect=reconnect) | ||||
if reconnect: | if reconnect: | ||||
self.reconnect_p2p(timeout=timeout) | self.reconnect_p2p(timeout=timeout) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
FullBlockTest().main() | FullBlockTest().main() |