diff options
| author | Oliver Gugger <[email protected]> | 2020-09-12 17:07:59 +0200 |
|---|---|---|
| committer | Oliver Gugger <[email protected]> | 2020-10-02 15:48:45 +0200 |
| commit | 64bc5efd39bad3212a1d57fd6234b544a14bb974 (patch) | |
| tree | 87b28867f03ab01159d9486ee75a067f01a637fd | |
| parent | Merge #19991: net: Use alternative port for incoming Tor connections (diff) | |
| download | discoin-64bc5efd39bad3212a1d57fd6234b544a14bb974.tar.xz discoin-64bc5efd39bad3212a1d57fd6234b544a14bb974.zip | |
test: Assert PSBT change type
Make sure the wallet's default change type is respected by default when
funding a PSBT but can be overwritten by the "change_type" option.
| -rwxr-xr-x | test/functional/rpc_psbt.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index 781a49dfa..c2e7fac7b 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -30,7 +30,7 @@ class PSBTTest(BitcoinTestFramework): self.num_nodes = 3 self.extra_args = [ ["-walletrbf=1"], - ["-walletrbf=0"], + ["-walletrbf=0", "-changetype=legacy"], [] ] self.supports_cli = False @@ -83,6 +83,14 @@ class PSBTTest(BitcoinTestFramework): connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 2) + def assert_change_type(self, psbtx, expected_type): + """Assert that the given PSBT has a change output with the given type.""" + + # The decodepsbt RPC is stateless and independent of any settings, we can always just call it on the first node + decoded_psbt = self.nodes[0].decodepsbt(psbtx["psbt"]) + changepos = psbtx["changepos"] + assert_equal(decoded_psbt["tx"]["vout"][changepos]["scriptPubKey"]["type"], expected_type) + def run_test(self): # Create and fund a raw tx for sending 10 BTC psbtx1 = self.nodes[0].walletcreatefundedpsbt([], {self.nodes[2].getnewaddress():10})['psbt'] @@ -301,6 +309,17 @@ class PSBTTest(BitcoinTestFramework): # when attempting BnB coin selection self.nodes[0].walletcreatefundedpsbt([], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], block_height+2, {"changeAddress":self.nodes[1].getnewaddress()}, False) + # Make sure the wallet's change type is respected by default + small_output = {self.nodes[0].getnewaddress():0.1} + psbtx_native = self.nodes[0].walletcreatefundedpsbt([], [small_output]) + self.assert_change_type(psbtx_native, "witness_v0_keyhash") + psbtx_legacy = self.nodes[1].walletcreatefundedpsbt([], [small_output]) + self.assert_change_type(psbtx_legacy, "pubkeyhash") + + # Make sure the change type of the wallet can also be overwritten + psbtx_np2wkh = self.nodes[1].walletcreatefundedpsbt([], [small_output], 0, {"change_type":"p2sh-segwit"}) + self.assert_change_type(psbtx_np2wkh, "scripthash") + # Regression test for 14473 (mishandling of already-signed witness transaction): psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], 0, {"add_inputs": True}) complete_psbt = self.nodes[0].walletprocesspsbt(psbtx_info["psbt"]) |