Skip to content

Commit faec09f

Browse files
author
MarcoFalke
committed
test: Return chain of MiniWallet txs from MiniWallet chain method
1 parent faa12d4 commit faec09f

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

test/functional/mempool_package_limits.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_chain_limits_helper(self, mempool_count, package_count):
4545
assert_equal(0, node.getmempoolinfo()["size"])
4646
chain_hex = []
4747

48-
chaintip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=mempool_count)
48+
chaintip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=mempool_count)[-1]["new_utxo"]
4949
# in-package transactions
5050
for _ in range(package_count):
5151
tx = self.wallet.create_self_transfer(utxo_to_spend=chaintip_utxo)
@@ -100,13 +100,13 @@ def test_desc_count_limits(self):
100100

101101
package_hex = []
102102
# 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])
103+
chain_a_tip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=11, utxo_to_spend=m1_utxos[0])[-1]["new_utxo"]
104104
# Pa
105105
pa_hex = self.wallet.create_self_transfer(utxo_to_spend=chain_a_tip_utxo)["hex"]
106106
package_hex.append(pa_hex)
107107

108108
# 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])
109+
chain_b_tip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12, utxo_to_spend=m1_utxos[1])[-1]["new_utxo"]
110110
# Pb
111111
pb_hex = self.wallet.create_self_transfer(utxo_to_spend=chain_b_tip_utxo)["hex"]
112112
package_hex.append(pb_hex)
@@ -145,7 +145,7 @@ def test_desc_count_limits_2(self):
145145
m1_utxos = self.wallet.send_self_transfer_multi(from_node=node, num_outputs=2)['new_utxos']
146146

147147
# Chain M2...M24
148-
self.wallet.send_self_transfer_chain(from_node=node, chain_length=23, utxo_to_spend=m1_utxos[0])
148+
self.wallet.send_self_transfer_chain(from_node=node, chain_length=23, utxo_to_spend=m1_utxos[0])[-1]["new_utxo"]
149149

150150
# P1
151151
p1_tx = self.wallet.create_self_transfer(utxo_to_spend=m1_utxos[1])
@@ -191,7 +191,7 @@ def test_anc_count_limits(self):
191191

192192
# Two chains of 13 transactions each
193193
for _ in range(2):
194-
chain_tip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12)
194+
chain_tip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12)[-1]["new_utxo"]
195195
# Save the 13th transaction for the package
196196
tx = self.wallet.create_self_transfer(utxo_to_spend=chain_tip_utxo)
197197
package_hex.append(tx["hex"])
@@ -234,7 +234,7 @@ def test_anc_count_limits_2(self):
234234
self.log.info("Check that in-mempool and in-package ancestors are calculated properly in packages")
235235
# Two chains of 12 transactions each
236236
for _ in range(2):
237-
chaintip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12)
237+
chaintip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12)[-1]["new_utxo"]
238238
# last 2 transactions will be the parents of Pc
239239
pc_parent_utxos.append(chaintip_utxo)
240240

test/functional/rpc_packages.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ def test_chain(self):
128128
node = self.nodes[0]
129129

130130
chain = self.wallet.create_self_transfer_chain(chain_length=25)
131-
chain_hex = chain["chain_hex"]
132-
chain_txns = chain["chain_txns"]
131+
chain_hex = [t["hex"] for t in chain]
132+
chain_txns = [t["tx"] for t in chain]
133133

134134
self.log.info("Check that testmempoolaccept requires packages to be sorted by dependency")
135135
assert_equal(node.testmempoolaccept(rawtxs=chain_hex[::-1]),
@@ -374,7 +374,7 @@ def test_submitpackage(self):
374374

375375
self.log.info("Submitpackage only allows packages of 1 child with its parents")
376376
# Chain of 3 transactions has too many generations
377-
chain_hex = self.wallet.create_self_transfer_chain(chain_length=25)["chain_hex"]
377+
chain_hex = [t["hex"] for t in self.wallet.create_self_transfer_chain(chain_length=25)]
378378
assert_raises_rpc_error(-25, "not-child-with-parents", node.submitpackage, chain_hex)
379379

380380

test/functional/test_framework/wallet.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -354,38 +354,31 @@ def sendrawtransaction(self, *, from_node, tx_hex, maxfeerate=0, **kwargs):
354354
self.scan_tx(from_node.decoderawtransaction(tx_hex))
355355
return txid
356356

357-
def create_self_transfer_chain(self, *, chain_length):
357+
def create_self_transfer_chain(self, *, chain_length, utxo_to_spend=None):
358358
"""
359359
Create a "chain" of chain_length transactions. The nth transaction in
360360
the chain is a child of the n-1th transaction and parent of the n+1th transaction.
361-
362-
Returns a dic {"chain_hex": chain_hex, "chain_txns" : chain_txns}
363-
364-
"chain_hex" is a list representing the chain's transactions in hexadecimal.
365-
"chain_txns" is a list representing the chain's transactions in the CTransaction object.
366361
"""
367-
chaintip_utxo = self.get_utxo()
368-
chain_hex = []
369-
chain_txns = []
362+
chaintip_utxo = utxo_to_spend or self.get_utxo()
363+
chain = []
370364

371365
for _ in range(chain_length):
372366
tx = self.create_self_transfer(utxo_to_spend=chaintip_utxo)
373367
chaintip_utxo = tx["new_utxo"]
374-
chain_hex.append(tx["hex"])
375-
chain_txns.append(tx["tx"])
368+
chain.append(tx)
376369

377-
return {"chain_hex": chain_hex, "chain_txns" : chain_txns}
370+
return chain
378371

379-
def send_self_transfer_chain(self, *, from_node, chain_length, utxo_to_spend=None):
372+
def send_self_transfer_chain(self, *, from_node, **kwargs):
380373
"""Create and send a "chain" of chain_length transactions. The nth transaction in
381374
the chain is a child of the n-1th transaction and parent of the n+1th transaction.
382375
383-
Returns the chaintip (nth) utxo
376+
Returns a list of objects for each tx (see create_self_transfer_multi).
384377
"""
385-
chaintip_utxo = utxo_to_spend or self.get_utxo()
386-
for _ in range(chain_length):
387-
chaintip_utxo = self.send_self_transfer(utxo_to_spend=chaintip_utxo, from_node=from_node)["new_utxo"]
388-
return chaintip_utxo
378+
chain = self.create_self_transfer_chain(**kwargs)
379+
for t in chain:
380+
self.sendrawtransaction(from_node=from_node, tx_hex=t["hex"])
381+
return chain
389382

390383

391384
def getnewdestination(address_type='bech32m'):

0 commit comments

Comments
 (0)