Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_assumevalid.py
Show First 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
block = create_block( | block = create_block( | ||||
self.tip, create_coinbase(height), self.block_time) | self.tip, create_coinbase(height), self.block_time) | ||||
block.solve() | block.solve() | ||||
self.blocks.append(block) | self.blocks.append(block) | ||||
self.tip = block.sha256 | self.tip = block.sha256 | ||||
self.block_time += 1 | self.block_time += 1 | ||||
height += 1 | height += 1 | ||||
# Create a transaction spending the coinbase output with an invalid (null) signature | # Create a transaction spending the coinbase output with an invalid | ||||
# (null) signature | |||||
tx = CTransaction() | tx = CTransaction() | ||||
tx.vin.append( | tx.vin.append( | ||||
CTxIn(COutPoint(self.block1.vtx[0].sha256, 0), scriptSig=b"")) | CTxIn(COutPoint(self.block1.vtx[0].sha256, 0), scriptSig=b"")) | ||||
tx.vout.append(CTxOut(49 * 100000000, CScript([OP_TRUE]))) | tx.vout.append(CTxOut(49 * 100000000, CScript([OP_TRUE]))) | ||||
pad_tx(tx) | pad_tx(tx) | ||||
tx.calc_sha256() | tx.calc_sha256() | ||||
block102 = create_block( | block102 = create_block( | ||||
Show All 16 Lines | def run_test(self): | ||||
block.solve() | block.solve() | ||||
self.blocks.append(block) | self.blocks.append(block) | ||||
self.tip = block.sha256 | self.tip = block.sha256 | ||||
self.block_time += 1 | self.block_time += 1 | ||||
height += 1 | height += 1 | ||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
# Start node1 and node2 with assumevalid so they accept a block with a bad signature. | # Start node1 and node2 with assumevalid so they accept a block with a | ||||
# bad signature. | |||||
self.start_node(1, extra_args=["-assumevalid=" + hex(block102.sha256)]) | self.start_node(1, extra_args=["-assumevalid=" + hex(block102.sha256)]) | ||||
self.start_node(2, extra_args=["-assumevalid=" + hex(block102.sha256)]) | self.start_node(2, extra_args=["-assumevalid=" + hex(block102.sha256)]) | ||||
p2p0 = self.nodes[0].add_p2p_connection(BaseNode()) | p2p0 = self.nodes[0].add_p2p_connection(BaseNode()) | ||||
p2p1 = self.nodes[1].add_p2p_connection(BaseNode()) | p2p1 = self.nodes[1].add_p2p_connection(BaseNode()) | ||||
p2p2 = self.nodes[2].add_p2p_connection(BaseNode()) | p2p2 = self.nodes[2].add_p2p_connection(BaseNode()) | ||||
# send header lists to all three nodes | # send header lists to all three nodes | ||||
p2p0.send_header_for_blocks(self.blocks[0:2000]) | p2p0.send_header_for_blocks(self.blocks[0:2000]) | ||||
p2p0.send_header_for_blocks(self.blocks[2000:]) | p2p0.send_header_for_blocks(self.blocks[2000:]) | ||||
p2p1.send_header_for_blocks(self.blocks[0:2000]) | p2p1.send_header_for_blocks(self.blocks[0:2000]) | ||||
p2p1.send_header_for_blocks(self.blocks[2000:]) | p2p1.send_header_for_blocks(self.blocks[2000:]) | ||||
p2p2.send_header_for_blocks(self.blocks[0:200]) | p2p2.send_header_for_blocks(self.blocks[0:200]) | ||||
# Send blocks to node0. Block 102 will be rejected. | # Send blocks to node0. Block 102 will be rejected. | ||||
self.send_blocks_until_disconnected(p2p0) | self.send_blocks_until_disconnected(p2p0) | ||||
self.assert_blockchain_height(self.nodes[0], 101) | self.assert_blockchain_height(self.nodes[0], 101) | ||||
# Send all blocks to node1. All blocks will be accepted. | # Send all blocks to node1. All blocks will be accepted. | ||||
for i in range(2202): | for i in range(2202): | ||||
p2p1.send_message(msg_block(self.blocks[i])) | p2p1.send_message(msg_block(self.blocks[i])) | ||||
# Syncing 2200 blocks can take a while on slow systems. Give it plenty of time to sync. | # Syncing 2200 blocks can take a while on slow systems. Give it plenty | ||||
# of time to sync. | |||||
p2p1.sync_with_ping(960) | p2p1.sync_with_ping(960) | ||||
assert_equal(self.nodes[1].getblock( | assert_equal(self.nodes[1].getblock( | ||||
self.nodes[1].getbestblockhash())['height'], 2202) | self.nodes[1].getbestblockhash())['height'], 2202) | ||||
# Send blocks to node2. Block 102 will be rejected. | # Send blocks to node2. Block 102 will be rejected. | ||||
self.send_blocks_until_disconnected(p2p2) | self.send_blocks_until_disconnected(p2p2) | ||||
self.assert_blockchain_height(self.nodes[2], 101) | self.assert_blockchain_height(self.nodes[2], 101) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
AssumeValidTest().main() | AssumeValidTest().main() |