Changeset View
Changeset View
Standalone View
Standalone View
test/functional/example_test.py
Show All 13 Lines | |||||
from collections import defaultdict | from collections import defaultdict | ||||
# Avoid wildcard * imports if possible | # Avoid wildcard * imports if possible | ||||
from test_framework.blocktools import (create_block, create_coinbase) | from test_framework.blocktools import (create_block, create_coinbase) | ||||
from test_framework.messages import (CInv, msg_block, msg_getdata) | from test_framework.messages import (CInv, msg_block, msg_getdata) | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
P2PInterface, | P2PInterface, | ||||
mininode_lock, | mininode_lock, | ||||
network_thread_join, | |||||
network_thread_start, | |||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
connect_nodes, | connect_nodes, | ||||
wait_until, | wait_until, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | def custom_method(self): | ||||
self.log.info("Running custom_method") | self.log.info("Running custom_method") | ||||
def run_test(self): | def run_test(self): | ||||
"""Main test logic""" | """Main test logic""" | ||||
# Create P2P connections to two of the nodes | # Create P2P connections to two of the nodes | ||||
self.nodes[0].add_p2p_connection(BaseNode()) | self.nodes[0].add_p2p_connection(BaseNode()) | ||||
# Start up network handling in another thread. This needs to be called | |||||
# after the P2P connections have been created. | |||||
network_thread_start() | |||||
# wait_for_verack ensures that the P2P connection is fully up. | # wait_for_verack ensures that the P2P connection is fully up. | ||||
self.nodes[0].p2p.wait_for_verack() | self.nodes[0].p2p.wait_for_verack() | ||||
# Generating a block on one of the nodes will get us out of IBD | # Generating a block on one of the nodes will get us out of IBD | ||||
blocks = [int(self.nodes[0].generate(nblocks=1)[0], 16)] | blocks = [int(self.nodes[0].generate(nblocks=1)[0], 16)] | ||||
self.sync_all([self.nodes[0:1]]) | self.sync_all([self.nodes[0:1]]) | ||||
# Notice above how we called an RPC by calling a method with the same | # Notice above how we called an RPC by calling a method with the same | ||||
Show All 38 Lines | def run_test(self): | ||||
self.log.info( | self.log.info( | ||||
"Wait for node1 to reach current tip (height 11) using RPC") | "Wait for node1 to reach current tip (height 11) using RPC") | ||||
self.nodes[1].waitforblockheight(11) | self.nodes[1].waitforblockheight(11) | ||||
self.log.info("Connect node2 and node1") | self.log.info("Connect node2 and node1") | ||||
connect_nodes(self.nodes[1], self.nodes[2]) | connect_nodes(self.nodes[1], self.nodes[2]) | ||||
self.log.info("Add P2P connection to node2") | self.log.info("Add P2P connection to node2") | ||||
# We can't add additional P2P connections once the network thread has started. Disconnect the connection | |||||
# to node0, wait for the network thread to terminate, then connect to node2. This is specific to | |||||
# the current implementation of the network thread and may be improved in future. | |||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
network_thread_join() | |||||
self.nodes[2].add_p2p_connection(BaseNode()) | self.nodes[2].add_p2p_connection(BaseNode()) | ||||
network_thread_start() | |||||
self.nodes[2].p2p.wait_for_verack() | self.nodes[2].p2p.wait_for_verack() | ||||
self.log.info( | self.log.info( | ||||
"Wait for node2 reach current tip. Test that it has propagated all the blocks to us") | "Wait for node2 reach current tip. Test that it has propagated all the blocks to us") | ||||
getdata_request = msg_getdata() | getdata_request = msg_getdata() | ||||
for block in blocks: | for block in blocks: | ||||
getdata_request.inv.append(CInv(2, block)) | getdata_request.inv.append(CInv(2, block)) | ||||
Show All 18 Lines |