mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-23 07:13:33 +02:00
test: Return chain of MiniWallet txs from MiniWallet chain method
This commit is contained in:
parent
faa12d4ccd
commit
faec09f240
@ -45,7 +45,7 @@ class MempoolPackageLimitsTest(BitcoinTestFramework):
|
|||||||
assert_equal(0, node.getmempoolinfo()["size"])
|
assert_equal(0, node.getmempoolinfo()["size"])
|
||||||
chain_hex = []
|
chain_hex = []
|
||||||
|
|
||||||
chaintip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=mempool_count)
|
chaintip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=mempool_count)[-1]["new_utxo"]
|
||||||
# in-package transactions
|
# in-package transactions
|
||||||
for _ in range(package_count):
|
for _ in range(package_count):
|
||||||
tx = self.wallet.create_self_transfer(utxo_to_spend=chaintip_utxo)
|
tx = self.wallet.create_self_transfer(utxo_to_spend=chaintip_utxo)
|
||||||
@ -100,13 +100,13 @@ class MempoolPackageLimitsTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
package_hex = []
|
package_hex = []
|
||||||
# Chain A (M2a... M12a)
|
# Chain A (M2a... M12a)
|
||||||
chain_a_tip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=11, utxo_to_spend=m1_utxos[0])
|
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"]
|
||||||
# Pa
|
# Pa
|
||||||
pa_hex = self.wallet.create_self_transfer(utxo_to_spend=chain_a_tip_utxo)["hex"]
|
pa_hex = self.wallet.create_self_transfer(utxo_to_spend=chain_a_tip_utxo)["hex"]
|
||||||
package_hex.append(pa_hex)
|
package_hex.append(pa_hex)
|
||||||
|
|
||||||
# Chain B (M2b... M13b)
|
# Chain B (M2b... M13b)
|
||||||
chain_b_tip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12, utxo_to_spend=m1_utxos[1])
|
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"]
|
||||||
# Pb
|
# Pb
|
||||||
pb_hex = self.wallet.create_self_transfer(utxo_to_spend=chain_b_tip_utxo)["hex"]
|
pb_hex = self.wallet.create_self_transfer(utxo_to_spend=chain_b_tip_utxo)["hex"]
|
||||||
package_hex.append(pb_hex)
|
package_hex.append(pb_hex)
|
||||||
@ -145,7 +145,7 @@ class MempoolPackageLimitsTest(BitcoinTestFramework):
|
|||||||
m1_utxos = self.wallet.send_self_transfer_multi(from_node=node, num_outputs=2)['new_utxos']
|
m1_utxos = self.wallet.send_self_transfer_multi(from_node=node, num_outputs=2)['new_utxos']
|
||||||
|
|
||||||
# Chain M2...M24
|
# Chain M2...M24
|
||||||
self.wallet.send_self_transfer_chain(from_node=node, chain_length=23, utxo_to_spend=m1_utxos[0])
|
self.wallet.send_self_transfer_chain(from_node=node, chain_length=23, utxo_to_spend=m1_utxos[0])[-1]["new_utxo"]
|
||||||
|
|
||||||
# P1
|
# P1
|
||||||
p1_tx = self.wallet.create_self_transfer(utxo_to_spend=m1_utxos[1])
|
p1_tx = self.wallet.create_self_transfer(utxo_to_spend=m1_utxos[1])
|
||||||
@ -191,7 +191,7 @@ class MempoolPackageLimitsTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
# Two chains of 13 transactions each
|
# Two chains of 13 transactions each
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
chain_tip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12)
|
chain_tip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12)[-1]["new_utxo"]
|
||||||
# Save the 13th transaction for the package
|
# Save the 13th transaction for the package
|
||||||
tx = self.wallet.create_self_transfer(utxo_to_spend=chain_tip_utxo)
|
tx = self.wallet.create_self_transfer(utxo_to_spend=chain_tip_utxo)
|
||||||
package_hex.append(tx["hex"])
|
package_hex.append(tx["hex"])
|
||||||
@ -234,7 +234,7 @@ class MempoolPackageLimitsTest(BitcoinTestFramework):
|
|||||||
self.log.info("Check that in-mempool and in-package ancestors are calculated properly in packages")
|
self.log.info("Check that in-mempool and in-package ancestors are calculated properly in packages")
|
||||||
# Two chains of 12 transactions each
|
# Two chains of 12 transactions each
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
chaintip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12)
|
chaintip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12)[-1]["new_utxo"]
|
||||||
# last 2 transactions will be the parents of Pc
|
# last 2 transactions will be the parents of Pc
|
||||||
pc_parent_utxos.append(chaintip_utxo)
|
pc_parent_utxos.append(chaintip_utxo)
|
||||||
|
|
||||||
|
@ -128,8 +128,8 @@ class RPCPackagesTest(BitcoinTestFramework):
|
|||||||
node = self.nodes[0]
|
node = self.nodes[0]
|
||||||
|
|
||||||
chain = self.wallet.create_self_transfer_chain(chain_length=25)
|
chain = self.wallet.create_self_transfer_chain(chain_length=25)
|
||||||
chain_hex = chain["chain_hex"]
|
chain_hex = [t["hex"] for t in chain]
|
||||||
chain_txns = chain["chain_txns"]
|
chain_txns = [t["tx"] for t in chain]
|
||||||
|
|
||||||
self.log.info("Check that testmempoolaccept requires packages to be sorted by dependency")
|
self.log.info("Check that testmempoolaccept requires packages to be sorted by dependency")
|
||||||
assert_equal(node.testmempoolaccept(rawtxs=chain_hex[::-1]),
|
assert_equal(node.testmempoolaccept(rawtxs=chain_hex[::-1]),
|
||||||
@ -374,7 +374,7 @@ class RPCPackagesTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
self.log.info("Submitpackage only allows packages of 1 child with its parents")
|
self.log.info("Submitpackage only allows packages of 1 child with its parents")
|
||||||
# Chain of 3 transactions has too many generations
|
# Chain of 3 transactions has too many generations
|
||||||
chain_hex = self.wallet.create_self_transfer_chain(chain_length=25)["chain_hex"]
|
chain_hex = [t["hex"] for t in self.wallet.create_self_transfer_chain(chain_length=25)]
|
||||||
assert_raises_rpc_error(-25, "not-child-with-parents", node.submitpackage, chain_hex)
|
assert_raises_rpc_error(-25, "not-child-with-parents", node.submitpackage, chain_hex)
|
||||||
|
|
||||||
|
|
||||||
|
@ -354,38 +354,31 @@ class MiniWallet:
|
|||||||
self.scan_tx(from_node.decoderawtransaction(tx_hex))
|
self.scan_tx(from_node.decoderawtransaction(tx_hex))
|
||||||
return txid
|
return txid
|
||||||
|
|
||||||
def create_self_transfer_chain(self, *, chain_length):
|
def create_self_transfer_chain(self, *, chain_length, utxo_to_spend=None):
|
||||||
"""
|
"""
|
||||||
Create a "chain" of chain_length transactions. The nth transaction in
|
Create a "chain" of chain_length transactions. The nth transaction in
|
||||||
the chain is a child of the n-1th transaction and parent of the n+1th transaction.
|
the chain is a child of the n-1th transaction and parent of the n+1th transaction.
|
||||||
|
|
||||||
Returns a dic {"chain_hex": chain_hex, "chain_txns" : chain_txns}
|
|
||||||
|
|
||||||
"chain_hex" is a list representing the chain's transactions in hexadecimal.
|
|
||||||
"chain_txns" is a list representing the chain's transactions in the CTransaction object.
|
|
||||||
"""
|
"""
|
||||||
chaintip_utxo = self.get_utxo()
|
chaintip_utxo = utxo_to_spend or self.get_utxo()
|
||||||
chain_hex = []
|
chain = []
|
||||||
chain_txns = []
|
|
||||||
|
|
||||||
for _ in range(chain_length):
|
for _ in range(chain_length):
|
||||||
tx = self.create_self_transfer(utxo_to_spend=chaintip_utxo)
|
tx = self.create_self_transfer(utxo_to_spend=chaintip_utxo)
|
||||||
chaintip_utxo = tx["new_utxo"]
|
chaintip_utxo = tx["new_utxo"]
|
||||||
chain_hex.append(tx["hex"])
|
chain.append(tx)
|
||||||
chain_txns.append(tx["tx"])
|
|
||||||
|
|
||||||
return {"chain_hex": chain_hex, "chain_txns" : chain_txns}
|
return chain
|
||||||
|
|
||||||
def send_self_transfer_chain(self, *, from_node, chain_length, utxo_to_spend=None):
|
def send_self_transfer_chain(self, *, from_node, **kwargs):
|
||||||
"""Create and send a "chain" of chain_length transactions. The nth transaction in
|
"""Create and send a "chain" of chain_length transactions. The nth transaction in
|
||||||
the chain is a child of the n-1th transaction and parent of the n+1th transaction.
|
the chain is a child of the n-1th transaction and parent of the n+1th transaction.
|
||||||
|
|
||||||
Returns the chaintip (nth) utxo
|
Returns a list of objects for each tx (see create_self_transfer_multi).
|
||||||
"""
|
"""
|
||||||
chaintip_utxo = utxo_to_spend or self.get_utxo()
|
chain = self.create_self_transfer_chain(**kwargs)
|
||||||
for _ in range(chain_length):
|
for t in chain:
|
||||||
chaintip_utxo = self.send_self_transfer(utxo_to_spend=chaintip_utxo, from_node=from_node)["new_utxo"]
|
self.sendrawtransaction(from_node=from_node, tx_hex=t["hex"])
|
||||||
return chaintip_utxo
|
return chain
|
||||||
|
|
||||||
|
|
||||||
def getnewdestination(address_type='bech32m'):
|
def getnewdestination(address_type='bech32m'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user