Skip to content

Commit 6e1ea42

Browse files
committed
test: refactor for walletcreatefundedpsbt fee rate coverage
1 parent 3ac7b0c commit 6e1ea42

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

test/functional/rpc_psbt.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,11 @@ def run_test(self):
174174
elif out['scriptPubKey']['addresses'][0] == p2pkh:
175175
p2pkh_pos = out['n']
176176

177+
inputs = [{"txid": txid, "vout": p2wpkh_pos}, {"txid": txid, "vout": p2sh_p2wpkh_pos}, {"txid": txid, "vout": p2pkh_pos}]
178+
outputs = [{self.nodes[1].getnewaddress(): 29.99}]
179+
177180
# spend single key from node 1
178-
created_psbt = 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})
181+
created_psbt = self.nodes[1].walletcreatefundedpsbt(inputs, outputs)
179182
walletprocesspsbt_out = self.nodes[1].walletprocesspsbt(created_psbt['psbt'])
180183
# Make sure it has both types of UTXOs
181184
decoded = self.nodes[1].decodepsbt(walletprocesspsbt_out['psbt'])
@@ -186,15 +189,17 @@ def run_test(self):
186189
assert_equal(walletprocesspsbt_out['complete'], True)
187190
self.nodes[1].sendrawtransaction(self.nodes[1].finalizepsbt(walletprocesspsbt_out['psbt'])['hex'])
188191

189-
# feeRate of 0.1 BTC / KB produces a total fee slightly below -maxtxfee (~0.05280000):
190-
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})
192+
self.log.info("Test walletcreatefundedpsbt feeRate of 0.1 BTC/kB produces a total fee at or slightly below -maxtxfee (~0.05290000)")
193+
res = self.nodes[1].walletcreatefundedpsbt(inputs, outputs, 0, {"feeRate": 0.1, "add_inputs": True})
191194
assert_approx(res["fee"], 0.055, 0.005)
192195

193-
# feeRate of 10 BTC / KB produces a total fee well above -maxtxfee
196+
self.log.info("Test walletcreatefundedpsbt feeRate of 10 BTC/KB produces total fee well above -maxtxfee and raises RPC error")
194197
# previously this was silently capped at -maxtxfee
195-
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)", 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})
196-
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)", 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})
198+
for bool_add, outputs_array in {True: outputs, False: [{self.nodes[1].getnewaddress(): 1}]}.items():
199+
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)",
200+
self.nodes[1].walletcreatefundedpsbt, inputs, outputs_array, 0, {"feeRate": 10, "add_inputs": bool_add})
197201

202+
self.log.info("Test various PSBT operations")
198203
# partially sign multisig things with node 1
199204
psbtx = wmulti.walletcreatefundedpsbt(inputs=[{"txid":txid,"vout":p2wsh_pos},{"txid":txid,"vout":p2sh_pos},{"txid":txid,"vout":p2sh_p2wsh_pos}], outputs={self.nodes[1].getnewaddress():29.99}, options={'changeAddress': self.nodes[1].getrawchangeaddress()})['psbt']
200205
walletprocesspsbt_out = self.nodes[1].walletprocesspsbt(psbtx)

0 commit comments

Comments
 (0)