Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_block.py
Show All 10 Lines | |||||
re-requested. | re-requested. | ||||
""" | """ | ||||
import copy | import copy | ||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_block, | create_block, | ||||
create_coinbase, | create_coinbase, | ||||
create_transaction, | create_tx_with_script, | ||||
) | ) | ||||
from test_framework.messages import COIN | from test_framework.messages import COIN | ||||
from test_framework.mininode import P2PDataStore | from test_framework.mininode import P2PDataStore | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal | from test_framework.util import assert_equal | ||||
class InvalidBlockRequestTest(BitcoinTestFramework): | class InvalidBlockRequestTest(BitcoinTestFramework): | ||||
Show All 36 Lines | def run_test(self): | ||||
# coinbase, spend of that spend). Duplicate the 3rd transaction to | # coinbase, spend of that spend). Duplicate the 3rd transaction to | ||||
# leave merkle root and blockheader unchanged but invalidate the block. | # leave merkle root and blockheader unchanged but invalidate the block. | ||||
self.log.info("Test merkle root malleability.") | self.log.info("Test merkle root malleability.") | ||||
block2 = create_block(tip, create_coinbase(height), block_time) | block2 = create_block(tip, create_coinbase(height), block_time) | ||||
block_time += 1 | block_time += 1 | ||||
# b'0x51' is OP_TRUE | # b'0x51' is OP_TRUE | ||||
tx1 = create_transaction(block1.vtx[0], 0, b'', 50 * COIN) | tx1 = create_tx_with_script( | ||||
tx2 = create_transaction(tx1, 0, b'\x51', 50 * COIN) | block1.vtx[0], 0, script_sig=b'', amount=50 * COIN) | ||||
tx2 = create_tx_with_script( | |||||
tx1, 0, script_sig=b'\x51', amount=50 * COIN) | |||||
block2.vtx.extend([tx1, tx2]) | block2.vtx.extend([tx1, tx2]) | ||||
block2.vtx = [block2.vtx[0]] + \ | block2.vtx = [block2.vtx[0]] + \ | ||||
sorted(block2.vtx[1:], key=lambda tx: tx.get_id()) | sorted(block2.vtx[1:], key=lambda tx: tx.get_id()) | ||||
block2.hashMerkleRoot = block2.calc_merkle_root() | block2.hashMerkleRoot = block2.calc_merkle_root() | ||||
block2.rehash() | block2.rehash() | ||||
block2.solve() | block2.solve() | ||||
orig_hash = block2.sha256 | orig_hash = block2.sha256 | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |