Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_block.py
Show All 24 Lines | |||||
class InvalidBlockRequestTest(BitcoinTestFramework): | class InvalidBlockRequestTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.extra_args = [["-whitelist=127.0.0.1"]] | self.extra_args = [["-whitelist=127.0.0.1"]] | ||||
def skip_test_if_missing_module(self): | |||||
self.skip_if_no_wallet() | |||||
def run_test(self): | def run_test(self): | ||||
# Add p2p connection to node0 | # Add p2p connection to node0 | ||||
node = self.nodes[0] # convenience reference to the node | node = self.nodes[0] # convenience reference to the node | ||||
node.add_p2p_connection(P2PDataStore()) | node.add_p2p_connection(P2PDataStore()) | ||||
best_block = node.getblock(node.getbestblockhash()) | best_block = node.getblock(node.getbestblockhash()) | ||||
tip = int(node.getbestblockhash(), 16) | tip = int(node.getbestblockhash(), 16) | ||||
height = best_block["height"] + 1 | height = best_block["height"] + 1 | ||||
block_time = best_block["time"] + 1 | block_time = best_block["time"] + 1 | ||||
self.log.info("Create a new block with an anyone-can-spend coinbase") | self.log.info("Create a new block with an anyone-can-spend coinbase") | ||||
height = 1 | height = 1 | ||||
block = create_block(tip, create_coinbase(height), block_time) | block = create_block(tip, create_coinbase(height), block_time) | ||||
block.solve() | block.solve() | ||||
# Save the coinbase for later | # Save the coinbase for later | ||||
block1 = block | block1 = block | ||||
tip = block.sha256 | tip = block.sha256 | ||||
node.p2p.send_blocks_and_test([block1], node, success=True) | node.p2p.send_blocks_and_test([block1], node, success=True) | ||||
self.log.info("Mature the block.") | self.log.info("Mature the block.") | ||||
node.generate(100) | node.generatetoaddress(100, node.get_deterministic_priv_key().address) | ||||
best_block = node.getblock(node.getbestblockhash()) | best_block = node.getblock(node.getbestblockhash()) | ||||
tip = int(node.getbestblockhash(), 16) | tip = int(node.getbestblockhash(), 16) | ||||
height = best_block["height"] + 1 | height = best_block["height"] + 1 | ||||
block_time = best_block["time"] + 1 | block_time = best_block["time"] + 1 | ||||
# Use merkle-root malleability to generate an invalid block with | # Use merkle-root malleability to generate an invalid block with | ||||
# same blockheader. | # same blockheader. | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |