Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_unrequested_blocks.py
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | |||||
class AcceptBlockTest(BitcoinTestFramework): | class AcceptBlockTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-noparkdeepreorg"], | self.extra_args = [["-noparkdeepreorg"], | ||||
["-minimumchainwork=0x10"]] | ["-minimumchainwork=0x10"]] | ||||
def skip_test_if_missing_module(self): | |||||
self.skip_if_no_wallet() | |||||
def setup_network(self): | def setup_network(self): | ||||
# Node0 will be used to test behavior of processing unrequested blocks | # Node0 will be used to test behavior of processing unrequested blocks | ||||
# from peers which are not whitelisted, while Node1 will be used for | # from peers which are not whitelisted, while Node1 will be used for | ||||
# the whitelisted case. | # the whitelisted case. | ||||
# Node2 will be used for non-whitelisted peers to test the interaction | # Node2 will be used for non-whitelisted peers to test the interaction | ||||
# with nMinimumChainWork. | # with nMinimumChainWork. | ||||
self.setup_nodes() | self.setup_nodes() | ||||
def run_test(self): | def run_test(self): | ||||
# Setup the p2p connections | # Setup the p2p connections | ||||
# test_node connects to node0 (not whitelisted) | # test_node connects to node0 (not whitelisted) | ||||
test_node = self.nodes[0].add_p2p_connection(P2PInterface()) | test_node = self.nodes[0].add_p2p_connection(P2PInterface()) | ||||
# min_work_node connects to node1 (whitelisted) | # min_work_node connects to node1 (whitelisted) | ||||
min_work_node = self.nodes[1].add_p2p_connection(P2PInterface()) | min_work_node = self.nodes[1].add_p2p_connection(P2PInterface()) | ||||
# 1. Have nodes mine a block (leave IBD) | # 1. Have nodes mine a block (leave IBD) | ||||
[n.generate(1) for n in self.nodes] | [n.generatetoaddress(1, n.get_deterministic_priv_key().address) | ||||
for n in self.nodes] | |||||
tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes] | tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes] | ||||
# 2. Send one block that builds on each tip. | # 2. Send one block that builds on each tip. | ||||
# This should be accepted by node0 | # This should be accepted by node0 | ||||
blocks_h2 = [] # the height 2 blocks on each node's chain | blocks_h2 = [] # the height 2 blocks on each node's chain | ||||
block_time = int(time.time()) + 1 | block_time = int(time.time()) + 1 | ||||
for i in range(2): | for i in range(2): | ||||
blocks_h2.append(create_block( | blocks_h2.append(create_block( | ||||
▲ Show 20 Lines • Show All 245 Lines • Show Last 20 Lines |