@@ -45,17 +45,12 @@ def test_chain_limits_helper(self, mempool_count, package_count):
4545 assert_equal (0 , node .getmempoolinfo ()["size" ])
4646 chain_hex = []
4747
48- chaintip_utxo = None
49- for i in range (mempool_count + package_count ):
48+ chaintip_utxo = self .wallet .send_self_transfer_chain (from_node = node , chain_length = mempool_count )
49+ # in-package transactions
50+ for _ in range (package_count ):
5051 tx = self .wallet .create_self_transfer (utxo_to_spend = chaintip_utxo )
5152 chaintip_utxo = tx ["new_utxo" ]
52- if i < mempool_count :
53- # in-mempool transactions
54- txid = self .wallet .sendrawtransaction (from_node = node , tx_hex = tx ["hex" ])
55- assert_equal (node .getmempoolentry (txid )["ancestorcount" ], i + 1 )
56- else :
57- # in-package transactions
58- chain_hex .append (tx ["hex" ])
53+ chain_hex .append (tx ["hex" ])
5954 testres_too_long = node .testmempoolaccept (rawtxs = chain_hex )
6055 for txres in testres_too_long :
6156 assert_equal (txres ["package-error" ], "package-mempool-limits" )
@@ -104,25 +99,17 @@ def test_desc_count_limits(self):
10499 m1_utxos = self .wallet .send_self_transfer_multi (from_node = node , num_outputs = 2 )['new_utxos' ]
105100
106101 package_hex = []
107- # Chain A
108- chain_a_utxo = m1_utxos [0 ]
109- for i in range (12 ):
110- tx = self .wallet .create_self_transfer (utxo_to_spend = chain_a_utxo )
111- chain_a_utxo = tx ["new_utxo" ]
112- if i < 11 : # M2a... M12a
113- self .wallet .sendrawtransaction (from_node = node , tx_hex = tx ["hex" ])
114- else : # Pa
115- package_hex .append (tx ["hex" ])
116-
117- # Chain B
118- chain_b_utxo = m1_utxos [1 ]
119- for i in range (13 ):
120- tx = self .wallet .create_self_transfer (utxo_to_spend = chain_b_utxo )
121- chain_b_utxo = tx ["new_utxo" ]
122- if i < 12 : # M3b... M13b
123- self .wallet .sendrawtransaction (from_node = node , tx_hex = tx ["hex" ])
124- else : # Pb
125- package_hex .append (tx ["hex" ])
102+ # Chain A (M2a... M12a)
103+ chain_a_tip_utxo = self .wallet .send_self_transfer_chain (from_node = node , chain_length = 11 , utxo_to_spend = m1_utxos [0 ])
104+ # Pa
105+ pa_hex = self .wallet .create_self_transfer (utxo_to_spend = chain_a_tip_utxo )["hex" ]
106+ package_hex .append (pa_hex )
107+
108+ # Chain B (M2b... M13b)
109+ chain_b_tip_utxo = self .wallet .send_self_transfer_chain (from_node = node , chain_length = 12 , utxo_to_spend = m1_utxos [1 ])
110+ # Pb
111+ pb_hex = self .wallet .create_self_transfer (utxo_to_spend = chain_b_tip_utxo )["hex" ]
112+ package_hex .append (pb_hex )
126113
127114 assert_equal (24 , node .getmempoolinfo ()["size" ])
128115 assert_equal (2 , len (package_hex ))
@@ -158,9 +145,7 @@ def test_desc_count_limits_2(self):
158145 m1_utxos = self .wallet .send_self_transfer_multi (from_node = node , num_outputs = 2 )['new_utxos' ]
159146
160147 # Chain M2...M24
161- chain_utxo = m1_utxos [0 ]
162- for _ in range (23 ): # M2...M24
163- chain_utxo = self .wallet .send_self_transfer (from_node = node , utxo_to_spend = chain_utxo )["new_utxo" ]
148+ self .wallet .send_self_transfer_chain (from_node = node , chain_length = 23 , utxo_to_spend = m1_utxos [0 ])
164149
165150 # P1
166151 p1_tx = self .wallet .create_self_transfer (utxo_to_spend = m1_utxos [1 ])
@@ -206,15 +191,11 @@ def test_anc_count_limits(self):
206191
207192 # Two chains of 13 transactions each
208193 for _ in range (2 ):
209- chaintip_utxo = None
210- for i in range (13 ):
211- tx = self .wallet .create_self_transfer (utxo_to_spend = chaintip_utxo )
212- chaintip_utxo = tx ["new_utxo" ]
213- if i < 12 :
214- self .wallet .sendrawtransaction (from_node = node , tx_hex = tx ["hex" ])
215- else : # Save the 13th transaction for the package
216- package_hex .append (tx ["hex" ])
217- pc_parent_utxos .append (chaintip_utxo )
194+ chain_tip_utxo = self .wallet .send_self_transfer_chain (from_node = node , chain_length = 12 )
195+ # Save the 13th transaction for the package
196+ tx = self .wallet .create_self_transfer (utxo_to_spend = chain_tip_utxo )
197+ package_hex .append (tx ["hex" ])
198+ pc_parent_utxos .append (tx ["new_utxo" ])
218199
219200 # Child Pc
220201 pc_hex = self .wallet .create_self_transfer_multi (utxos_to_spend = pc_parent_utxos )["hex" ]
@@ -253,12 +234,9 @@ def test_anc_count_limits_2(self):
253234 self .log .info ("Check that in-mempool and in-package ancestors are calculated properly in packages" )
254235 # Two chains of 12 transactions each
255236 for _ in range (2 ):
256- chaintip_utxo = None
257- for i in range (12 ):
258- chaintip_utxo = self .wallet .send_self_transfer (from_node = node , utxo_to_spend = chaintip_utxo )["new_utxo" ]
259- if i == 11 :
260- # last 2 transactions will be the parents of Pc
261- pc_parent_utxos .append (chaintip_utxo )
237+ chaintip_utxo = self .wallet .send_self_transfer_chain (from_node = node , chain_length = 12 )
238+ # last 2 transactions will be the parents of Pc
239+ pc_parent_utxos .append (chaintip_utxo )
262240
263241 # Child Pc
264242 pc_tx = self .wallet .create_self_transfer_multi (utxos_to_spend = pc_parent_utxos )
0 commit comments