(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.p2ps[0].send_blocks_and_test([block], node, success=True) |
| 65 | |
| 66 | self.log.info("Mature the block.") |
| 67 | self.generatetoaddress(self.nodes[0], 100, self.nodes[0].get_deterministic_priv_key().address) |
| 68 | |
| 69 | # Iterate through a list of known invalid transaction types, ensuring each is |
| 70 | # rejected. Some are consensus invalid and some just violate policy. |
| 71 | for BadTxTemplate in invalid_txs.iter_all_templates(): |
| 72 | self.log.info("Testing invalid transaction: %s", BadTxTemplate.__name__) |
| 73 | template = BadTxTemplate(spend_block=block1) |
| 74 | tx = template.get_tx() |
| 75 | node.p2ps[0].send_txs_and_test( |
| 76 | [tx], node, success=False, |
| 77 | reject_reason=template.reject_reason, |
| 78 | ) |
| 79 | |
| 80 | # Make two p2p connections to provide the node with orphans |
| 81 | # * p2ps[0] will send valid orphan txs (one with low fee) |
| 82 | # * p2ps[1] will send an invalid orphan tx (and is later disconnected for that) |
| 83 | self.reconnect_p2p(num_connections=2) |
| 84 | |
| 85 | self.log.info('Test orphan transaction handling ... ') |
| 86 | # Create a root transaction that we withhold until all dependent transactions |
| 87 | # are sent out and in the orphan cache |
| 88 | SCRIPT_PUB_KEY_OP_TRUE = b'\x51\x75' * 15 + b'\x51' |
| 89 | tx_withhold = CTransaction() |
| 90 | tx_withhold.vin.append(CTxIn(outpoint=COutPoint(block1.vtx[0].sha256, 0))) |
| 91 | tx_withhold.vout.append(CTxOut(nValue=50 * COIN - 12000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)) |
| 92 | tx_withhold.vout.append(CTxOut(12000)) # fee |
| 93 | tx_withhold.calc_sha256() |
| 94 | |
| 95 | # Our first orphan tx with some outputs to create further orphan txs |
| 96 | tx_orphan_1 = CTransaction() |
| 97 | tx_orphan_1.vin.append(CTxIn(outpoint=COutPoint(tx_withhold.sha256, 0))) |
| 98 | tx_orphan_1.vout = [CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 3 |
| 99 | tx_orphan_1.vout.append(CTxOut(20 * COIN - 12000)) # fee |
| 100 | tx_orphan_1.calc_sha256() |
| 101 | |
| 102 | # A valid transaction with low fee |
| 103 | tx_orphan_2_no_fee = CTransaction() |
| 104 | tx_orphan_2_no_fee.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 0))) |
nothing calls this directly
no test coverage detected