(self)
| 45 | self.bootstrap_p2p(**kwargs) |
| 46 | |
| 47 | def run_test(self): |
| 48 | node = self.nodes[0] # convenience reference to the node |
| 49 | |
| 50 | self.bootstrap_p2p() # Add one p2p connection to the node |
| 51 | |
| 52 | best_block = self.nodes[0].getbestblockhash() |
| 53 | tip = int(best_block, 16) |
| 54 | best_block_time = self.nodes[0].getblock(best_block)['time'] |
| 55 | block_time = best_block_time + 1 |
| 56 | |
| 57 | self.log.info("Create a new block with an anyone-can-spend coinbase.") |
| 58 | height = 1 |
| 59 | block = create_block(tip, create_coinbase(height), block_time) |
| 60 | block.solve() |
| 61 | # Save the coinbase for later |
| 62 | block1 = block |
| 63 | tip = block.sha256 |
| 64 | node.p2p.send_blocks_and_test([block], node, success=True) |
| 65 | |
| 66 | self.log.info("Mature the block.") |
| 67 | self.nodes[0].generate(100) |
| 68 | |
| 69 | # b'\x64' is OP_NOTIF |
| 70 | # Transaction will be rejected with code 16 (REJECT_INVALID) |
| 71 | # and we get disconnected immediately |
| 72 | self.log.info('Test a transaction that is rejected') |
| 73 | tx1 = create_tx_with_script(block1.vtx[0], 0, script_sig=b'\x64' * 35, amount=50 * COIN - 12000) |
| 74 | node.p2p.send_txs_and_test([tx1], node, success=False, expect_disconnect=True) |
| 75 | |
| 76 | # Make two p2p connections to provide the node with orphans |
| 77 | # * p2ps[0] will send valid orphan txs (one with low fee) |
| 78 | # * p2ps[1] will send an invalid orphan tx (and is later disconnected for that) |
| 79 | self.reconnect_p2p(num_connections=2) |
| 80 | |
| 81 | self.log.info('Test orphan transaction handling ... ') |
| 82 | # Create a root transaction that we withhold until all dependend transactions |
| 83 | # are sent out and in the orphan cache |
| 84 | SCRIPT_PUB_KEY_OP_TRUE = b'\x51\x75' * 15 + b'\x51' |
| 85 | tx_withhold = CTransaction() |
| 86 | tx_withhold.vin.append(CTxIn(outpoint=COutPoint(block1.vtx[0].sha256, 0))) |
| 87 | tx_withhold.vout.append(CTxOut(nValue=50 * COIN - 12000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)) |
| 88 | tx_withhold.calc_sha256() |
| 89 | |
| 90 | # Our first orphan tx with some outputs to create further orphan txs |
| 91 | tx_orphan_1 = CTransaction() |
| 92 | tx_orphan_1.vin.append(CTxIn(outpoint=COutPoint(tx_withhold.sha256, 0))) |
| 93 | tx_orphan_1.vout = [CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 3 |
| 94 | tx_orphan_1.calc_sha256() |
| 95 | |
| 96 | # A valid transaction with low fee |
| 97 | tx_orphan_2_no_fee = CTransaction() |
| 98 | tx_orphan_2_no_fee.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 0))) |
| 99 | tx_orphan_2_no_fee.vout.append(CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)) |
| 100 | |
| 101 | # A valid transaction with sufficient fee |
| 102 | tx_orphan_2_valid = CTransaction() |
| 103 | tx_orphan_2_valid.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 1))) |
| 104 | tx_orphan_2_valid.vout.append(CTxOut(nValue=10 * COIN - 12000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)) |
nothing calls this directly
no test coverage detected