13
13
)
14
14
from test_framework .wallet import MiniWallet
15
15
16
+ # Decorator to
17
+ # 1) check that mempool is empty at the start of a subtest
18
+ # 2) run the subtest, which may submit some transaction(s) to the mempool and
19
+ # create a list of hex transactions
20
+ # 3) testmempoolaccept the package hex and check that it fails with the error
21
+ # "package-mempool-limits" for each tx
22
+ # 4) after mining a block, clearing the pre-submitted transactions from mempool,
23
+ # check that submitting the created package succeeds
24
+ def check_package_limits (func ):
25
+ def func_wrapper (self , * args , ** kwargs ):
26
+ node = self .nodes [0 ]
27
+ assert_equal (0 , node .getmempoolinfo ()["size" ])
28
+ package_hex = func (self , * args , ** kwargs )
29
+ testres_error_expected = node .testmempoolaccept (rawtxs = package_hex )
30
+ assert_equal (len (testres_error_expected ), len (package_hex ))
31
+ for txres in testres_error_expected :
32
+ assert_equal (txres ["package-error" ], "package-mempool-limits" )
33
+
34
+ # Clear mempool and check that the package passes now
35
+ self .generate (node , 1 )
36
+ assert all ([res ["allowed" ] for res in node .testmempoolaccept (rawtxs = package_hex )])
37
+
38
+ return func_wrapper
39
+
16
40
17
41
class MempoolPackageLimitsTest (BitcoinTestFramework ):
18
42
def set_test_params (self ):
@@ -37,9 +61,9 @@ def run_test(self):
37
61
self .test_anc_size_limits ()
38
62
self .test_desc_size_limits ()
39
63
64
+ @check_package_limits
40
65
def test_chain_limits_helper (self , mempool_count , package_count ):
41
66
node = self .nodes [0 ]
42
- assert_equal (0 , node .getmempoolinfo ()["size" ])
43
67
chain_hex = []
44
68
45
69
chaintip_utxo = self .wallet .send_self_transfer_chain (from_node = node , chain_length = mempool_count )[- 1 ]["new_utxo" ]
@@ -48,13 +72,7 @@ def test_chain_limits_helper(self, mempool_count, package_count):
48
72
tx = self .wallet .create_self_transfer (utxo_to_spend = chaintip_utxo )
49
73
chaintip_utxo = tx ["new_utxo" ]
50
74
chain_hex .append (tx ["hex" ])
51
- testres_too_long = node .testmempoolaccept (rawtxs = chain_hex )
52
- for txres in testres_too_long :
53
- assert_equal (txres ["package-error" ], "package-mempool-limits" )
54
-
55
- # Clear mempool and check that the package passes now
56
- self .generate (node , 1 )
57
- assert all ([res ["allowed" ] for res in node .testmempoolaccept (rawtxs = chain_hex )])
75
+ return chain_hex
58
76
59
77
def test_chain_limits (self ):
60
78
"""Create chains from mempool and package transactions that are longer than 25,
@@ -73,6 +91,7 @@ def test_chain_limits(self):
73
91
# 13 transactions in the mempool and 13 in the package.
74
92
self .test_chain_limits_helper (13 , 13 )
75
93
94
+ @check_package_limits
76
95
def test_desc_count_limits (self ):
77
96
"""Create an 'A' shaped package with 24 transactions in the mempool and 2 in the package:
78
97
M1
@@ -90,7 +109,6 @@ def test_desc_count_limits(self):
90
109
package transactions).
91
110
"""
92
111
node = self .nodes [0 ]
93
- assert_equal (0 , node .getmempoolinfo ()["size" ])
94
112
self .log .info ("Check that in-mempool and in-package descendants are calculated properly in packages" )
95
113
# Top parent in mempool, M1
96
114
m1_utxos = self .wallet .send_self_transfer_multi (from_node = node , num_outputs = 2 )['new_utxos' ]
@@ -110,14 +128,9 @@ def test_desc_count_limits(self):
110
128
111
129
assert_equal (24 , node .getmempoolinfo ()["size" ])
112
130
assert_equal (2 , len (package_hex ))
113
- testres_too_long = node .testmempoolaccept (rawtxs = package_hex )
114
- for txres in testres_too_long :
115
- assert_equal (txres ["package-error" ], "package-mempool-limits" )
116
-
117
- # Clear mempool and check that the package passes now
118
- self .generate (node , 1 )
119
- assert all ([res ["allowed" ] for res in node .testmempoolaccept (rawtxs = package_hex )])
131
+ return package_hex
120
132
133
+ @check_package_limits
121
134
def test_desc_count_limits_2 (self ):
122
135
"""Create a Package with 24 transaction in mempool and 2 transaction in package:
123
136
M1
@@ -154,15 +167,9 @@ def test_desc_count_limits_2(self):
154
167
155
168
assert_equal (24 , node .getmempoolinfo ()["size" ])
156
169
assert_equal (2 , len (package_hex ))
157
- testres = node .testmempoolaccept (rawtxs = package_hex )
158
- assert_equal (len (testres ), len (package_hex ))
159
- for txres in testres :
160
- assert_equal (txres ["package-error" ], "package-mempool-limits" )
161
-
162
- # Clear mempool and check that the package passes now
163
- self .generate (node , 1 )
164
- assert all ([res ["allowed" ] for res in node .testmempoolaccept (rawtxs = package_hex )])
170
+ return package_hex
165
171
172
+ @check_package_limits
166
173
def test_anc_count_limits (self ):
167
174
"""Create a 'V' shaped chain with 24 transactions in the mempool and 3 in the package:
168
175
M1a M1b
@@ -180,7 +187,6 @@ def test_anc_count_limits(self):
180
187
and in-package ancestors are all considered together.
181
188
"""
182
189
node = self .nodes [0 ]
183
- assert_equal (0 , node .getmempoolinfo ()["size" ])
184
190
package_hex = []
185
191
pc_parent_utxos = []
186
192
@@ -200,14 +206,9 @@ def test_anc_count_limits(self):
200
206
201
207
assert_equal (24 , node .getmempoolinfo ()["size" ])
202
208
assert_equal (3 , len (package_hex ))
203
- testres_too_long = node .testmempoolaccept (rawtxs = package_hex )
204
- for txres in testres_too_long :
205
- assert_equal (txres ["package-error" ], "package-mempool-limits" )
206
-
207
- # Clear mempool and check that the package passes now
208
- self .generate (node , 1 )
209
- assert all ([res ["allowed" ] for res in node .testmempoolaccept (rawtxs = package_hex )])
209
+ return package_hex
210
210
211
+ @check_package_limits
211
212
def test_anc_count_limits_2 (self ):
212
213
"""Create a 'Y' shaped chain with 24 transactions in the mempool and 2 in the package:
213
214
M1a M1b
@@ -225,7 +226,6 @@ def test_anc_count_limits_2(self):
225
226
and in-package ancestors are all considered together.
226
227
"""
227
228
node = self .nodes [0 ]
228
- assert_equal (0 , node .getmempoolinfo ()["size" ])
229
229
pc_parent_utxos = []
230
230
231
231
self .log .info ("Check that in-mempool and in-package ancestors are calculated properly in packages" )
@@ -242,14 +242,9 @@ def test_anc_count_limits_2(self):
242
242
pd_tx = self .wallet .create_self_transfer (utxo_to_spend = pc_tx ["new_utxos" ][0 ])
243
243
244
244
assert_equal (24 , node .getmempoolinfo ()["size" ])
245
- testres_too_long = node .testmempoolaccept (rawtxs = [pc_tx ["hex" ], pd_tx ["hex" ]])
246
- for txres in testres_too_long :
247
- assert_equal (txres ["package-error" ], "package-mempool-limits" )
248
-
249
- # Clear mempool and check that the package passes now
250
- self .generate (node , 1 )
251
- assert all ([res ["allowed" ] for res in node .testmempoolaccept (rawtxs = [pc_tx ["hex" ], pd_tx ["hex" ]])])
245
+ return [pc_tx ["hex" ], pd_tx ["hex" ]]
252
246
247
+ @check_package_limits
253
248
def test_anc_count_limits_bushy (self ):
254
249
"""Create a tree with 20 transactions in the mempool and 6 in the package:
255
250
M1...M4 M5...M8 M9...M12 M13...M16 M17...M20
@@ -262,7 +257,6 @@ def test_anc_count_limits_bushy(self):
262
257
combined, PC has 25 in-mempool and in-package parents.
263
258
"""
264
259
node = self .nodes [0 ]
265
- assert_equal (0 , node .getmempoolinfo ()["size" ])
266
260
package_hex = []
267
261
pc_parent_utxos = []
268
262
for _ in range (5 ): # Make package transactions P0 ... P4
@@ -279,14 +273,9 @@ def test_anc_count_limits_bushy(self):
279
273
280
274
assert_equal (20 , node .getmempoolinfo ()["size" ])
281
275
assert_equal (6 , len (package_hex ))
282
- testres = node .testmempoolaccept (rawtxs = package_hex )
283
- for txres in testres :
284
- assert_equal (txres ["package-error" ], "package-mempool-limits" )
285
-
286
- # Clear mempool and check that the package passes now
287
- self .generate (node , 1 )
288
- assert all ([res ["allowed" ] for res in node .testmempoolaccept (rawtxs = package_hex )])
276
+ return package_hex
289
277
278
+ @check_package_limits
290
279
def test_anc_size_limits (self ):
291
280
"""Test Case with 2 independent transactions in the mempool and a parent + child in the
292
281
package, where the package parent is the child of both mempool transactions (30KvB each):
@@ -299,7 +288,6 @@ def test_anc_size_limits(self):
299
288
and in-package ancestors are all considered together.
300
289
"""
301
290
node = self .nodes [0 ]
302
- assert_equal (0 , node .getmempoolinfo ()["size" ])
303
291
parent_utxos = []
304
292
target_vsize = 30_000
305
293
high_fee = 10 * target_vsize # 10 sats/vB
@@ -318,14 +306,9 @@ def test_anc_size_limits(self):
318
306
pd_tx = self .wallet .create_self_transfer (utxo_to_spend = pc_tx ["new_utxos" ][0 ], target_weight = target_weight )
319
307
320
308
assert_equal (2 , node .getmempoolinfo ()["size" ])
321
- testres_too_heavy = node .testmempoolaccept (rawtxs = [pc_tx ["hex" ], pd_tx ["hex" ]])
322
- for txres in testres_too_heavy :
323
- assert_equal (txres ["package-error" ], "package-mempool-limits" )
324
-
325
- # Clear mempool and check that the package passes now
326
- self .generate (node , 1 )
327
- assert all ([res ["allowed" ] for res in node .testmempoolaccept (rawtxs = [pc_tx ["hex" ], pd_tx ["hex" ]])])
309
+ return [pc_tx ["hex" ], pd_tx ["hex" ]]
328
310
311
+ @check_package_limits
329
312
def test_desc_size_limits (self ):
330
313
"""Create 3 mempool transactions and 2 package transactions (21KvB each):
331
314
Ma
@@ -337,7 +320,6 @@ def test_desc_size_limits(self):
337
320
and in-package descendants are all considered together.
338
321
"""
339
322
node = self .nodes [0 ]
340
- assert_equal (0 , node .getmempoolinfo ()["size" ])
341
323
target_vsize = 21_000
342
324
high_fee = 10 * target_vsize # 10 sats/vB
343
325
target_weight = target_vsize * WITNESS_SCALE_FACTOR
@@ -358,13 +340,7 @@ def test_desc_size_limits(self):
358
340
359
341
assert_equal (3 , node .getmempoolinfo ()["size" ])
360
342
assert_equal (2 , len (package_hex ))
361
- testres_too_heavy = node .testmempoolaccept (rawtxs = package_hex )
362
- for txres in testres_too_heavy :
363
- assert_equal (txres ["package-error" ], "package-mempool-limits" )
364
-
365
- # Clear mempool and check that the package passes now
366
- self .generate (node , 1 )
367
- assert all ([res ["allowed" ] for res in node .testmempoolaccept (rawtxs = package_hex )])
343
+ return package_hex
368
344
369
345
370
346
if __name__ == "__main__" :
0 commit comments