mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
test: MiniWallet: add send_self_transfer_chain
to create chain of txns
With this new method, a chain of transactions can be created. This method is introduced to further simplify the mempool_package_limits.py tests.
This commit is contained in:
parent
1d6b438ef0
commit
f2f6068b69
2 changed files with 35 additions and 45 deletions
|
@ -45,17 +45,12 @@ class MempoolPackageLimitsTest(BitcoinTestFramework):
|
||||||
assert_equal(0, node.getmempoolinfo()["size"])
|
assert_equal(0, node.getmempoolinfo()["size"])
|
||||||
chain_hex = []
|
chain_hex = []
|
||||||
|
|
||||||
chaintip_utxo = None
|
chaintip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=mempool_count)
|
||||||
for i in range(mempool_count + package_count):
|
# in-package transactions
|
||||||
|
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)
|
||||||
chaintip_utxo = tx["new_utxo"]
|
chaintip_utxo = tx["new_utxo"]
|
||||||
if i < mempool_count:
|
chain_hex.append(tx["hex"])
|
||||||
# in-mempool transactions
|
|
||||||
txid = self.wallet.sendrawtransaction(from_node=node, tx_hex=tx["hex"])
|
|
||||||
assert_equal(node.getmempoolentry(txid)["ancestorcount"], i + 1)
|
|
||||||
else:
|
|
||||||
# in-package transactions
|
|
||||||
chain_hex.append(tx["hex"])
|
|
||||||
testres_too_long = node.testmempoolaccept(rawtxs=chain_hex)
|
testres_too_long = node.testmempoolaccept(rawtxs=chain_hex)
|
||||||
for txres in testres_too_long:
|
for txres in testres_too_long:
|
||||||
assert_equal(txres["package-error"], "package-mempool-limits")
|
assert_equal(txres["package-error"], "package-mempool-limits")
|
||||||
|
@ -104,25 +99,17 @@ 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']
|
||||||
|
|
||||||
package_hex = []
|
package_hex = []
|
||||||
# Chain A
|
# Chain A (M2a... M12a)
|
||||||
chain_a_utxo = 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])
|
||||||
for i in range(12):
|
# Pa
|
||||||
tx = self.wallet.create_self_transfer(utxo_to_spend=chain_a_utxo)
|
pa_hex = self.wallet.create_self_transfer(utxo_to_spend=chain_a_tip_utxo)["hex"]
|
||||||
chain_a_utxo = tx["new_utxo"]
|
package_hex.append(pa_hex)
|
||||||
if i < 11: # M2a... M12a
|
|
||||||
self.wallet.sendrawtransaction(from_node=node, tx_hex=tx["hex"])
|
|
||||||
else: # Pa
|
|
||||||
package_hex.append(tx["hex"])
|
|
||||||
|
|
||||||
# Chain B
|
# Chain B (M2b... M13b)
|
||||||
chain_b_utxo = 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])
|
||||||
for i in range(13):
|
# Pb
|
||||||
tx = self.wallet.create_self_transfer(utxo_to_spend=chain_b_utxo)
|
pb_hex = self.wallet.create_self_transfer(utxo_to_spend=chain_b_tip_utxo)["hex"]
|
||||||
chain_b_utxo = tx["new_utxo"]
|
package_hex.append(pb_hex)
|
||||||
if i < 12: # M3b... M13b
|
|
||||||
self.wallet.sendrawtransaction(from_node=node, tx_hex=tx["hex"])
|
|
||||||
else: # Pb
|
|
||||||
package_hex.append(tx["hex"])
|
|
||||||
|
|
||||||
assert_equal(24, node.getmempoolinfo()["size"])
|
assert_equal(24, node.getmempoolinfo()["size"])
|
||||||
assert_equal(2, len(package_hex))
|
assert_equal(2, len(package_hex))
|
||||||
|
@ -158,9 +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
|
||||||
chain_utxo = m1_utxos[0]
|
self.wallet.send_self_transfer_chain(from_node=node, chain_length=23, utxo_to_spend=m1_utxos[0])
|
||||||
for _ in range(23): # M2...M24
|
|
||||||
chain_utxo = self.wallet.send_self_transfer(from_node=node, utxo_to_spend=chain_utxo)["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])
|
||||||
|
@ -206,15 +191,11 @@ class MempoolPackageLimitsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# Two chains of 13 transactions each
|
# Two chains of 13 transactions each
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
chaintip_utxo = None
|
chain_tip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12)
|
||||||
for i in range(13):
|
# Save the 13th transaction for the package
|
||||||
tx = self.wallet.create_self_transfer(utxo_to_spend=chaintip_utxo)
|
tx = self.wallet.create_self_transfer(utxo_to_spend=chain_tip_utxo)
|
||||||
chaintip_utxo = tx["new_utxo"]
|
package_hex.append(tx["hex"])
|
||||||
if i < 12:
|
pc_parent_utxos.append(tx["new_utxo"])
|
||||||
self.wallet.sendrawtransaction(from_node=node, tx_hex=tx["hex"])
|
|
||||||
else: # Save the 13th transaction for the package
|
|
||||||
package_hex.append(tx["hex"])
|
|
||||||
pc_parent_utxos.append(chaintip_utxo)
|
|
||||||
|
|
||||||
# Child Pc
|
# Child Pc
|
||||||
pc_hex = self.wallet.create_self_transfer_multi(utxos_to_spend=pc_parent_utxos)["hex"]
|
pc_hex = self.wallet.create_self_transfer_multi(utxos_to_spend=pc_parent_utxos)["hex"]
|
||||||
|
@ -253,12 +234,9 @@ 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 = None
|
chaintip_utxo = self.wallet.send_self_transfer_chain(from_node=node, chain_length=12)
|
||||||
for i in range(12):
|
# last 2 transactions will be the parents of Pc
|
||||||
chaintip_utxo = self.wallet.send_self_transfer(from_node=node, utxo_to_spend=chaintip_utxo)["new_utxo"]
|
pc_parent_utxos.append(chaintip_utxo)
|
||||||
if i == 11:
|
|
||||||
# last 2 transactions will be the parents of Pc
|
|
||||||
pc_parent_utxos.append(chaintip_utxo)
|
|
||||||
|
|
||||||
# Child Pc
|
# Child Pc
|
||||||
pc_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=pc_parent_utxos)
|
pc_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=pc_parent_utxos)
|
||||||
|
|
|
@ -335,6 +335,18 @@ class MiniWallet:
|
||||||
self.scan_tx(from_node.decoderawtransaction(tx_hex))
|
self.scan_tx(from_node.decoderawtransaction(tx_hex))
|
||||||
return txid
|
return txid
|
||||||
|
|
||||||
|
def send_self_transfer_chain(self, *, from_node, chain_length, utxo_to_spend=None):
|
||||||
|
"""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.
|
||||||
|
|
||||||
|
Returns the chaintip (nth) utxo
|
||||||
|
"""
|
||||||
|
chaintip_utxo = utxo_to_spend or self.get_utxo()
|
||||||
|
for _ in range(chain_length):
|
||||||
|
chaintip_utxo = self.send_self_transfer(utxo_to_spend=chaintip_utxo, from_node=from_node)["new_utxo"]
|
||||||
|
return chaintip_utxo
|
||||||
|
|
||||||
|
|
||||||
def getnewdestination(address_type='bech32m'):
|
def getnewdestination(address_type='bech32m'):
|
||||||
"""Generate a random destination of the specified type and return the
|
"""Generate a random destination of the specified type and return the
|
||||||
corresponding public key, scriptPubKey and address. Supported types are
|
corresponding public key, scriptPubKey and address. Supported types are
|
||||||
|
|
Loading…
Add table
Reference in a new issue