Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_sendheaders.py
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | from test_framework.messages import ( | ||||
msg_getdata, | msg_getdata, | ||||
msg_getheaders, | msg_getheaders, | ||||
msg_headers, | msg_headers, | ||||
msg_inv, | msg_inv, | ||||
msg_sendheaders, | msg_sendheaders, | ||||
) | ) | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
mininode_lock, | mininode_lock, | ||||
network_thread_start, | |||||
P2PInterface, | P2PInterface, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal, sync_blocks, wait_until | from test_framework.util import assert_equal, sync_blocks, wait_until | ||||
DIRECT_FETCH_RESPONSE_TIME = 0.05 | DIRECT_FETCH_RESPONSE_TIME = 0.05 | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | def mine_reorg(self, length): | ||||
tip_height - (length - 1)) | tip_height - (length - 1)) | ||||
self.nodes[1].invalidateblock(hash_to_invalidate) | self.nodes[1].invalidateblock(hash_to_invalidate) | ||||
# Must be longer than the orig chain | # Must be longer than the orig chain | ||||
all_hashes = self.nodes[1].generate(length + 1) | all_hashes = self.nodes[1].generate(length + 1) | ||||
sync_blocks(self.nodes, wait=0.1) | sync_blocks(self.nodes, wait=0.1) | ||||
return [int(x, 16) for x in all_hashes] | return [int(x, 16) for x in all_hashes] | ||||
def run_test(self): | def run_test(self): | ||||
# Setup the p2p connections and start up the network thread. | # Setup the p2p connections | ||||
inv_node = self.nodes[0].add_p2p_connection(BaseNode()) | inv_node = self.nodes[0].add_p2p_connection(BaseNode()) | ||||
# Make sure NODE_NETWORK is not set for test_node, so no block download | # Make sure NODE_NETWORK is not set for test_node, so no block download | ||||
# will occur outside of direct fetching | # will occur outside of direct fetching | ||||
test_node = self.nodes[0].add_p2p_connection(BaseNode(), services=0) | test_node = self.nodes[0].add_p2p_connection(BaseNode(), services=0) | ||||
network_thread_start() | |||||
# Test logic begins here | |||||
inv_node.wait_for_verack() | inv_node.wait_for_verack() | ||||
test_node.wait_for_verack() | test_node.wait_for_verack() | ||||
# Ensure verack's have been processed by our peer | # Ensure verack's have been processed by our peer | ||||
inv_node.sync_with_ping() | inv_node.sync_with_ping() | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
self.test_null_locators(test_node, inv_node) | self.test_null_locators(test_node, inv_node) | ||||
▲ Show 20 Lines • Show All 380 Lines • Show Last 20 Lines |