|
13 | 13 | CTxIn, |
14 | 14 | CTxOut, |
15 | 15 | ) |
16 | | -from test_framework.mininode import P2PDataStore, network_thread_join |
| 16 | +from test_framework.mininode import P2PDataStore |
17 | 17 | from test_framework.script import ( |
18 | 18 | CScript, |
19 | 19 | OP_NOTIF, |
20 | 20 | OP_TRUE, |
| 21 | + OP_DROP |
21 | 22 | ) |
22 | 23 | from test_framework.test_framework import PivxTestFramework |
23 | 24 | from test_framework.util import ( |
@@ -47,15 +48,11 @@ def reconnect_p2p(self, **kwargs): |
47 | 48 | self.nodes[0].disconnect_p2ps() |
48 | 49 | self.bootstrap_p2p(**kwargs) |
49 | 50 |
|
50 | | - def new_spend_tx(self, prev_hash, prev_n, values): |
51 | | - """Create a CTransaction spending COutPoint(prev_hash, prev_n) |
52 | | -
|
53 | | - each amount specified in the 'values' list is sent to an |
54 | | - anyone-can-spend script""" |
| 51 | + def new_spend_tx(self, prev_hash, prev_n, tx_outs): |
| 52 | + """Create a CTransaction spending COutPoint(prev_hash, prev_n) to the CTxOut-list tx_outs.""" |
55 | 53 | tx = CTransaction() |
56 | 54 | tx.vin.append(CTxIn(outpoint=COutPoint(prev_hash, prev_n))) |
57 | | - for value in values: |
58 | | - tx.vout.append(CTxOut(nValue=value, scriptPubKey=CScript([OP_TRUE]))) |
| 55 | + tx.vout = tx_outs |
59 | 56 | tx.calc_sha256() |
60 | 57 | return tx |
61 | 58 |
|
@@ -93,21 +90,22 @@ def run_test(self): |
93 | 90 | self.reconnect_p2p(num_connections=2) |
94 | 91 |
|
95 | 92 | self.log.info('Test orphan transaction handling ... ') |
| 93 | + SCRIPT_PUB_KEY_OP_TRUE = CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]) |
96 | 94 | # Create a root transaction that we withhold until all dependend transactions |
97 | 95 | # are sent out and in the orphan cache |
98 | | - tx_withhold = self.new_spend_tx(block1.vtx[0].sha256, 0, [50 * COIN - 12000]) |
| 96 | + tx_withhold = self.new_spend_tx(block1.vtx[0].sha256, 0, [CTxOut(nValue=50 * COIN - 12000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)]) |
99 | 97 |
|
100 | 98 | # Our first orphan tx with 3 outputs to create further orphan txs |
101 | | - tx_orphan_1 = self.new_spend_tx(tx_withhold.sha256, 0, [10 * COIN] * 3) |
| 99 | + tx_orphan_1 = self.new_spend_tx(tx_withhold.sha256, 0, [CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 3) |
102 | 100 |
|
103 | 101 | # A valid transaction with low fee |
104 | | - tx_orphan_2_no_fee = self.new_spend_tx(tx_orphan_1.sha256, 0, [10 * COIN]) |
| 102 | + tx_orphan_2_no_fee = self.new_spend_tx(tx_orphan_1.sha256, 0, [CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)]) |
105 | 103 |
|
106 | 104 | # A valid transaction with sufficient fee |
107 | | - tx_orphan_2_valid = self.new_spend_tx(tx_orphan_1.sha256, 1, [10 * COIN - 12000]) |
| 105 | + tx_orphan_2_valid = self.new_spend_tx(tx_orphan_1.sha256, 1, [CTxOut(nValue=10 * COIN - 12000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)]) |
108 | 106 |
|
109 | 107 | # An invalid transaction with negative fee |
110 | | - tx_orphan_2_invalid = self.new_spend_tx(tx_orphan_1.sha256, 2, [11 * COIN]) |
| 108 | + tx_orphan_2_invalid = self.new_spend_tx(tx_orphan_1.sha256, 2, [CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)]) |
111 | 109 |
|
112 | 110 | self.log.info('Send the orphans ... ') |
113 | 111 | # Send valid orphan txs from p2ps[0] |
@@ -139,6 +137,22 @@ def run_test(self): |
139 | 137 | #wait_until(lambda: 1 == len(node.getpeerinfo()), timeout=12) # p2ps[1] is no longer connected |
140 | 138 | assert_equal(expected_mempool, set(node.getrawmempool())) |
141 | 139 |
|
| 140 | + self.log.info('Test orphan pool overflow') |
| 141 | + orphan_tx_pool = [CTransaction() for _ in range(101)] |
| 142 | + for i in range(len(orphan_tx_pool)): |
| 143 | + orphan_tx_pool[i].vin.append(CTxIn(outpoint=COutPoint(i, 333))) |
| 144 | + orphan_tx_pool[i].vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)) |
| 145 | + |
| 146 | + with node.assert_debug_log(['mapOrphan overflow, removed 1 tx']): |
| 147 | + node.p2p.send_txs_and_test(orphan_tx_pool, node, success=False) |
| 148 | + |
| 149 | + rejected_parent = CTransaction() |
| 150 | + rejected_parent.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_2_invalid.sha256, 0))) |
| 151 | + rejected_parent.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)) |
| 152 | + rejected_parent.rehash() |
| 153 | + with node.assert_debug_log(['not keeping orphan with rejected parents {}'.format(rejected_parent.hash)]): |
| 154 | + node.p2p.send_txs_and_test([rejected_parent], node, success=False) |
| 155 | + |
142 | 156 |
|
143 | 157 | if __name__ == '__main__': |
144 | 158 | InvalidTxRequestTest().main() |
0 commit comments