mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
tests: rpc_fundrawtx lock to UTXO types
For some of the tests within rpc_fundrawtx, there is the expectation that two independent calls to coin selection RPCs will use the same type of UTXO. This is not necessarily guaranteed, so to make sure it is, use lockunspent prior to those tests.
This commit is contained in:
parent
d2dd1697ce
commit
df765a484d
1 changed files with 45 additions and 0 deletions
|
@ -47,7 +47,40 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
self.connect_nodes(0, 2)
|
||||
self.connect_nodes(0, 3)
|
||||
|
||||
def lock_outputs_type(self, wallet, outputtype):
|
||||
"""
|
||||
Only allow UTXOs of the given type
|
||||
"""
|
||||
if outputtype in ["legacy", "p2pkh", "pkh"]:
|
||||
prefixes = ["pkh(", "sh(multi("]
|
||||
elif outputtype in ["p2sh-segwit", "sh_wpkh"]:
|
||||
prefixes = ["sh(wpkh(", "sh(wsh("]
|
||||
elif outputtype in ["bech32", "wpkh"]:
|
||||
prefixes = ["wpkh(", "wsh("]
|
||||
else:
|
||||
assert False, f"Unknown output type {outputtype}"
|
||||
|
||||
to_lock = []
|
||||
for utxo in wallet.listunspent():
|
||||
if "desc" in utxo:
|
||||
for prefix in prefixes:
|
||||
if utxo["desc"].startswith(prefix):
|
||||
to_lock.append({"txid": utxo["txid"], "vout": utxo["vout"]})
|
||||
wallet.lockunspent(False, to_lock)
|
||||
|
||||
def unlock_utxos(self, wallet):
|
||||
"""
|
||||
Unlock all UTXOs except the watchonly one
|
||||
"""
|
||||
to_keep = []
|
||||
if self.watchonly_txid is not None and self.watchonly_vout is not None:
|
||||
to_keep.append({"txid": self.watchonly_txid, "vout": self.watchonly_vout})
|
||||
wallet.lockunspent(True)
|
||||
wallet.lockunspent(False, to_keep)
|
||||
|
||||
def run_test(self):
|
||||
self.watchonly_txid = None
|
||||
self.watchonly_vout = None
|
||||
self.log.info("Connect nodes, set fees, generate blocks, and sync")
|
||||
self.min_relay_tx_fee = self.nodes[0].getnetworkinfo()['relayfee']
|
||||
# This test is not meant to test fee estimation and we'd like
|
||||
|
@ -373,6 +406,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
def test_fee_p2pkh(self):
|
||||
"""Compare fee of a standard pubkeyhash transaction."""
|
||||
self.log.info("Test fundrawtxn p2pkh fee")
|
||||
self.lock_outputs_type(self.nodes[0], "p2pkh")
|
||||
inputs = []
|
||||
outputs = {self.nodes[1].getnewaddress():1.1}
|
||||
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
|
||||
|
@ -386,9 +420,12 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
|
||||
assert feeDelta >= 0 and feeDelta <= self.fee_tolerance
|
||||
|
||||
self.unlock_utxos(self.nodes[0])
|
||||
|
||||
def test_fee_p2pkh_multi_out(self):
|
||||
"""Compare fee of a standard pubkeyhash transaction with multiple outputs."""
|
||||
self.log.info("Test fundrawtxn p2pkh fee with multiple outputs")
|
||||
self.lock_outputs_type(self.nodes[0], "p2pkh")
|
||||
inputs = []
|
||||
outputs = {
|
||||
self.nodes[1].getnewaddress():1.1,
|
||||
|
@ -409,8 +446,11 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
|
||||
assert feeDelta >= 0 and feeDelta <= self.fee_tolerance
|
||||
|
||||
self.unlock_utxos(self.nodes[0])
|
||||
|
||||
def test_fee_p2sh(self):
|
||||
"""Compare fee of a 2-of-2 multisig p2sh transaction."""
|
||||
self.lock_outputs_type(self.nodes[0], "p2pkh")
|
||||
# Create 2-of-2 addr.
|
||||
addr1 = self.nodes[1].getnewaddress()
|
||||
addr2 = self.nodes[1].getnewaddress()
|
||||
|
@ -433,9 +473,12 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
|
||||
assert feeDelta >= 0 and feeDelta <= self.fee_tolerance
|
||||
|
||||
self.unlock_utxos(self.nodes[0])
|
||||
|
||||
def test_fee_4of5(self):
|
||||
"""Compare fee of a standard pubkeyhash transaction."""
|
||||
self.log.info("Test fundrawtxn fee with 4-of-5 addresses")
|
||||
self.lock_outputs_type(self.nodes[0], "p2pkh")
|
||||
|
||||
# Create 4-of-5 addr.
|
||||
addr1 = self.nodes[1].getnewaddress()
|
||||
|
@ -474,6 +517,8 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
|
||||
assert feeDelta >= 0 and feeDelta <= self.fee_tolerance
|
||||
|
||||
self.unlock_utxos(self.nodes[0])
|
||||
|
||||
def test_spend_2of2(self):
|
||||
"""Spend a 2-of-2 multisig transaction over fundraw."""
|
||||
self.log.info("Test fundpsbt spending 2-of-2 multisig")
|
||||
|
|
Loading…
Add table
Reference in a new issue