8
8
from decimal import Decimal
9
9
from test_framework .test_framework import BitcoinTestFramework
10
10
from test_framework .util import (
11
+ assert_approx ,
11
12
assert_equal ,
12
13
assert_greater_than ,
13
14
assert_raises_rpc_error ,
@@ -80,6 +81,13 @@ def run_test(self):
80
81
# Create and fund a raw tx for sending 10 BTC
81
82
psbtx1 = self .nodes [0 ].walletcreatefundedpsbt ([], {self .nodes [2 ].getnewaddress ():10 })['psbt' ]
82
83
84
+ # If inputs are specified, do not automatically add more:
85
+ utxo1 = self .nodes [0 ].listunspent ()[0 ]
86
+ assert_raises_rpc_error (- 4 , "Insufficient funds" , self .nodes [0 ].walletcreatefundedpsbt , [{"txid" : utxo1 ['txid' ], "vout" : utxo1 ['vout' ]}], {self .nodes [2 ].getnewaddress ():90 })
87
+
88
+ psbtx1 = self .nodes [0 ].walletcreatefundedpsbt ([{"txid" : utxo1 ['txid' ], "vout" : utxo1 ['vout' ]}], {self .nodes [2 ].getnewaddress ():90 }, 0 , {"add_inputs" : True })['psbt' ]
89
+ assert_equal (len (self .nodes [0 ].decodepsbt (psbtx1 )['tx' ]['vin' ]), 2 )
90
+
83
91
# Node 1 should not be able to add anything to it but still return the psbtx same as before
84
92
psbtx = self .nodes [1 ].walletprocesspsbt (psbtx1 )['psbt' ]
85
93
assert_equal (psbtx1 , psbtx )
@@ -137,13 +145,13 @@ def run_test(self):
137
145
self .nodes [1 ].sendrawtransaction (self .nodes [1 ].finalizepsbt (walletprocesspsbt_out ['psbt' ])['hex' ])
138
146
139
147
# feeRate of 0.1 BTC / KB produces a total fee slightly below -maxtxfee (~0.05280000):
140
- res = self .nodes [1 ].walletcreatefundedpsbt ([{"txid" :txid ,"vout" :p2wpkh_pos },{"txid" :txid ,"vout" :p2sh_p2wpkh_pos },{"txid" :txid ,"vout" :p2pkh_pos }], {self .nodes [1 ].getnewaddress ():29.99 }, 0 , {"feeRate" : 0.1 })
141
- assert_greater_than (res ["fee" ], 0.05 )
142
- assert_greater_than (0.06 , res ["fee" ])
148
+ res = self .nodes [1 ].walletcreatefundedpsbt ([{"txid" :txid ,"vout" :p2wpkh_pos },{"txid" :txid ,"vout" :p2sh_p2wpkh_pos },{"txid" :txid ,"vout" :p2pkh_pos }], {self .nodes [1 ].getnewaddress ():29.99 }, 0 , {"feeRate" : 0.1 , "add_inputs" : True })
149
+ assert_approx (res ["fee" ], 0.055 , 0.005 )
143
150
144
151
# feeRate of 10 BTC / KB produces a total fee well above -maxtxfee
145
152
# previously this was silently capped at -maxtxfee
146
- assert_raises_rpc_error (- 4 , "Fee exceeds maximum configured by -maxtxfee" , self .nodes [1 ].walletcreatefundedpsbt , [{"txid" :txid ,"vout" :p2wpkh_pos },{"txid" :txid ,"vout" :p2sh_p2wpkh_pos },{"txid" :txid ,"vout" :p2pkh_pos }], {self .nodes [1 ].getnewaddress ():29.99 }, 0 , {"feeRate" : 10 })
153
+ assert_raises_rpc_error (- 4 , "Fee exceeds maximum configured by -maxtxfee" , self .nodes [1 ].walletcreatefundedpsbt , [{"txid" :txid ,"vout" :p2wpkh_pos },{"txid" :txid ,"vout" :p2sh_p2wpkh_pos },{"txid" :txid ,"vout" :p2pkh_pos }], {self .nodes [1 ].getnewaddress ():29.99 }, 0 , {"feeRate" : 10 , "add_inputs" : True })
154
+ assert_raises_rpc_error (- 4 , "Fee exceeds maximum configured by -maxtxfee" , self .nodes [1 ].walletcreatefundedpsbt , [{"txid" :txid ,"vout" :p2wpkh_pos },{"txid" :txid ,"vout" :p2sh_p2wpkh_pos },{"txid" :txid ,"vout" :p2pkh_pos }], {self .nodes [1 ].getnewaddress ():1 }, 0 , {"feeRate" : 10 , "add_inputs" : False })
147
155
148
156
# partially sign multisig things with node 1
149
157
psbtx = self .nodes [1 ].walletcreatefundedpsbt ([{"txid" :txid ,"vout" :p2wsh_pos },{"txid" :txid ,"vout" :p2sh_pos },{"txid" :txid ,"vout" :p2sh_p2wsh_pos }], {self .nodes [1 ].getnewaddress ():29.99 })['psbt' ]
@@ -221,23 +229,23 @@ def run_test(self):
221
229
# replaceable arg
222
230
block_height = self .nodes [0 ].getblockcount ()
223
231
unspent = self .nodes [0 ].listunspent ()[0 ]
224
- psbtx_info = self .nodes [0 ].walletcreatefundedpsbt ([{"txid" :unspent ["txid" ], "vout" :unspent ["vout" ]}], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }], block_height + 2 , {"replaceable" : False }, False )
232
+ psbtx_info = self .nodes [0 ].walletcreatefundedpsbt ([{"txid" :unspent ["txid" ], "vout" :unspent ["vout" ]}], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }], block_height + 2 , {"replaceable" : False , "add_inputs" : True }, False )
225
233
decoded_psbt = self .nodes [0 ].decodepsbt (psbtx_info ["psbt" ])
226
234
for tx_in , psbt_in in zip (decoded_psbt ["tx" ]["vin" ], decoded_psbt ["inputs" ]):
227
235
assert_greater_than (tx_in ["sequence" ], MAX_BIP125_RBF_SEQUENCE )
228
236
assert "bip32_derivs" not in psbt_in
229
237
assert_equal (decoded_psbt ["tx" ]["locktime" ], block_height + 2 )
230
238
231
239
# Same construction with only locktime set and RBF explicitly enabled
232
- psbtx_info = self .nodes [0 ].walletcreatefundedpsbt ([{"txid" :unspent ["txid" ], "vout" :unspent ["vout" ]}], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }], block_height , {"replaceable" : True }, True )
240
+ psbtx_info = self .nodes [0 ].walletcreatefundedpsbt ([{"txid" :unspent ["txid" ], "vout" :unspent ["vout" ]}], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }], block_height , {"replaceable" : True , "add_inputs" : True }, True )
233
241
decoded_psbt = self .nodes [0 ].decodepsbt (psbtx_info ["psbt" ])
234
242
for tx_in , psbt_in in zip (decoded_psbt ["tx" ]["vin" ], decoded_psbt ["inputs" ]):
235
243
assert_equal (tx_in ["sequence" ], MAX_BIP125_RBF_SEQUENCE )
236
244
assert "bip32_derivs" in psbt_in
237
245
assert_equal (decoded_psbt ["tx" ]["locktime" ], block_height )
238
246
239
247
# Same construction without optional arguments
240
- psbtx_info = self .nodes [0 ].walletcreatefundedpsbt ([{ "txid" : unspent [ "txid" ], "vout" : unspent [ "vout" ]} ], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }])
248
+ psbtx_info = self .nodes [0 ].walletcreatefundedpsbt ([], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }])
241
249
decoded_psbt = self .nodes [0 ].decodepsbt (psbtx_info ["psbt" ])
242
250
for tx_in , psbt_in in zip (decoded_psbt ["tx" ]["vin" ], decoded_psbt ["inputs" ]):
243
251
assert_equal (tx_in ["sequence" ], MAX_BIP125_RBF_SEQUENCE )
@@ -246,7 +254,7 @@ def run_test(self):
246
254
247
255
# Same construction without optional arguments, for a node with -walletrbf=0
248
256
unspent1 = self .nodes [1 ].listunspent ()[0 ]
249
- psbtx_info = self .nodes [1 ].walletcreatefundedpsbt ([{"txid" :unspent1 ["txid" ], "vout" :unspent1 ["vout" ]}], [{self .nodes [2 ].getnewaddress ():unspent1 ["amount" ]+ 1 }], block_height )
257
+ psbtx_info = self .nodes [1 ].walletcreatefundedpsbt ([{"txid" :unspent1 ["txid" ], "vout" :unspent1 ["vout" ]}], [{self .nodes [2 ].getnewaddress ():unspent1 ["amount" ]+ 1 }], block_height , { "add_inputs" : True } )
250
258
decoded_psbt = self .nodes [1 ].decodepsbt (psbtx_info ["psbt" ])
251
259
for tx_in , psbt_in in zip (decoded_psbt ["tx" ]["vin" ], decoded_psbt ["inputs" ]):
252
260
assert_greater_than (tx_in ["sequence" ], MAX_BIP125_RBF_SEQUENCE )
@@ -257,7 +265,7 @@ def run_test(self):
257
265
self .nodes [0 ].walletcreatefundedpsbt ([], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }], block_height + 2 , {"changeAddress" :self .nodes [1 ].getnewaddress ()}, False )
258
266
259
267
# Regression test for 14473 (mishandling of already-signed witness transaction):
260
- psbtx_info = self .nodes [0 ].walletcreatefundedpsbt ([{"txid" :unspent ["txid" ], "vout" :unspent ["vout" ]}], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }])
268
+ psbtx_info = self .nodes [0 ].walletcreatefundedpsbt ([{"txid" :unspent ["txid" ], "vout" :unspent ["vout" ]}], [{self .nodes [2 ].getnewaddress ():unspent ["amount" ]+ 1 }], 0 , { "add_inputs" : True } )
261
269
complete_psbt = self .nodes [0 ].walletprocesspsbt (psbtx_info ["psbt" ])
262
270
double_processed_psbt = self .nodes [0 ].walletprocesspsbt (complete_psbt ["psbt" ])
263
271
assert_equal (complete_psbt , double_processed_psbt )
0 commit comments