Skip to content

Commit 875e1cc

Browse files
author
MarcoFalke
committed
Merge #19947: Test: Cover "change_type" option of "walletcreatefundedpsbt" RPC
a56e9f5 test: Assert exclusive PSBT funding options (Oliver Gugger) 64bc5ef test: Assert PSBT change type (Oliver Gugger) Pull request description: Increases test coverage of the `walletcreatefundedpsbt` RPC. Tests the following combinations: - Make sure the global option `-changetype` is used as the default value for the `change_type` option if not specified. - Make sure the global option `-changetype` can be overwritten by explicitly setting the `change_type` option of the `walletcreatefundedpsbt` RPC call. - Make sure the options `change_type` and `changeAddress` are mutually exclusive. ACKs for top commit: achow101: ACK a56e9f5 Tree-SHA512: bf0fb20c890887b7228ad9277fdb32f367ba772eed6efbe2b4f471f808d4d435110256601e8ebd9bea57026d9f22f3cc3c26a009b017e3da6d8fc6896313def5
2 parents dde1049 + a56e9f5 commit 875e1cc

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/functional/rpc_psbt.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def set_test_params(self):
3030
self.num_nodes = 3
3131
self.extra_args = [
3232
["-walletrbf=1"],
33-
["-walletrbf=0"],
33+
["-walletrbf=0", "-changetype=legacy"],
3434
[]
3535
]
3636
self.supports_cli = False
@@ -83,6 +83,14 @@ def test_utxo_conversion(self):
8383
connect_nodes(self.nodes[0], 1)
8484
connect_nodes(self.nodes[0], 2)
8585

86+
def assert_change_type(self, psbtx, expected_type):
87+
"""Assert that the given PSBT has a change output with the given type."""
88+
89+
# The decodepsbt RPC is stateless and independent of any settings, we can always just call it on the first node
90+
decoded_psbt = self.nodes[0].decodepsbt(psbtx["psbt"])
91+
changepos = psbtx["changepos"]
92+
assert_equal(decoded_psbt["tx"]["vout"][changepos]["scriptPubKey"]["type"], expected_type)
93+
8694
def run_test(self):
8795
# Create and fund a raw tx for sending 10 BTC
8896
psbtx1 = self.nodes[0].walletcreatefundedpsbt([], {self.nodes[2].getnewaddress():10})['psbt']
@@ -301,6 +309,21 @@ def run_test(self):
301309
# when attempting BnB coin selection
302310
self.nodes[0].walletcreatefundedpsbt([], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], block_height+2, {"changeAddress":self.nodes[1].getnewaddress()}, False)
303311

312+
# Make sure the wallet's change type is respected by default
313+
small_output = {self.nodes[0].getnewaddress():0.1}
314+
psbtx_native = self.nodes[0].walletcreatefundedpsbt([], [small_output])
315+
self.assert_change_type(psbtx_native, "witness_v0_keyhash")
316+
psbtx_legacy = self.nodes[1].walletcreatefundedpsbt([], [small_output])
317+
self.assert_change_type(psbtx_legacy, "pubkeyhash")
318+
319+
# Make sure the change type of the wallet can also be overwritten
320+
psbtx_np2wkh = self.nodes[1].walletcreatefundedpsbt([], [small_output], 0, {"change_type":"p2sh-segwit"})
321+
self.assert_change_type(psbtx_np2wkh, "scripthash")
322+
323+
# Make sure the change type cannot be specified if a change address is given
324+
invalid_options = {"change_type":"legacy","changeAddress":self.nodes[0].getnewaddress()}
325+
assert_raises_rpc_error(-8, "both change address and address type options", self.nodes[0].walletcreatefundedpsbt, [], [small_output], 0, invalid_options)
326+
304327
# Regression test for 14473 (mishandling of already-signed witness transaction):
305328
psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], 0, {"add_inputs": True})
306329
complete_psbt = self.nodes[0].walletprocesspsbt(psbtx_info["psbt"])

0 commit comments

Comments
 (0)