(self)
| 28 | self.skip_if_no_wallet() |
| 29 | |
| 30 | def run_test(self): |
| 31 | # Add p2p connection to node0 |
| 32 | node = self.nodes[0] # convenience reference to the node |
| 33 | node.add_p2p_connection(P2PDataStore()) |
| 34 | |
| 35 | best_block = node.getblock(node.getbestblockhash()) |
| 36 | tip = int(node.getbestblockhash(), 16) |
| 37 | height = best_block["height"] + 1 |
| 38 | block_time = best_block["time"] + 1 |
| 39 | |
| 40 | self.log.info("Create a new block with an anyone-can-spend coinbase") |
| 41 | |
| 42 | height = 1 |
| 43 | block = create_block(tip, create_coinbase(height), block_time) |
| 44 | block.solve() |
| 45 | # Save the coinbase for later |
| 46 | block1 = block |
| 47 | tip = block.sha256 |
| 48 | node.p2p.send_blocks_and_test([block1], node, success=True) |
| 49 | |
| 50 | self.log.info("Mature the block.") |
| 51 | node.generate(100) |
| 52 | |
| 53 | best_block = node.getblock(node.getbestblockhash()) |
| 54 | tip = int(node.getbestblockhash(), 16) |
| 55 | height = best_block["height"] + 1 |
| 56 | block_time = best_block["time"] + 1 |
| 57 | |
| 58 | # Use merkle-root malleability to generate an invalid block with |
| 59 | # same blockheader. |
| 60 | # Manufacture a block with 3 transactions (coinbase, spend of prior |
| 61 | # coinbase, spend of that spend). Duplicate the 3rd transaction to |
| 62 | # leave merkle root and blockheader unchanged but invalidate the block. |
| 63 | self.log.info("Test merkle root malleability.") |
| 64 | |
| 65 | block2 = create_block(tip, create_coinbase(height), block_time) |
| 66 | block_time += 1 |
| 67 | |
| 68 | # b'0x51' is OP_TRUE |
| 69 | tx1 = create_tx_with_script(block1.vtx[0], 0, script_sig=b'\x51', amount=50 * COIN) |
| 70 | tx2 = create_tx_with_script(tx1, 0, script_sig=b'\x51', amount=50 * COIN) |
| 71 | |
| 72 | block2.vtx.extend([tx1, tx2]) |
| 73 | block2.hashMerkleRoot = block2.calc_merkle_root() |
| 74 | block2.rehash() |
| 75 | block2.solve() |
| 76 | orig_hash = block2.sha256 |
| 77 | block2_orig = copy.deepcopy(block2) |
| 78 | |
| 79 | # Mutate block 2 |
| 80 | block2.vtx.append(tx2) |
| 81 | assert_equal(block2.hashMerkleRoot, block2.calc_merkle_root()) |
| 82 | assert_equal(orig_hash, block2.rehash()) |
| 83 | assert block2_orig.vtx != block2.vtx |
| 84 | |
| 85 | node.p2p.send_blocks_and_test([block2], node, success=False, reject_code=16, reject_reason=b'bad-txns-duplicate') |
| 86 | |
| 87 | # Check transactions for duplicate inputs |
nothing calls this directly
no test coverage detected