55"""Test the send RPC command."""
66
77from decimal import Decimal , getcontext
8+ from itertools import product
9+
810from test_framework .authproxy import JSONRPCException
911from test_framework .test_framework import BitcoinTestFramework
1012from test_framework .util import (
1113 assert_equal ,
1214 assert_fee_amount ,
1315 assert_greater_than ,
14- assert_raises_rpc_error
16+ assert_raises_rpc_error ,
1517)
1618
1719class WalletSendTest (BitcoinTestFramework ):
@@ -271,8 +273,9 @@ def run_test(self):
271273 fee = self .nodes [1 ].decodepsbt (res ["psbt" ])["fee" ]
272274 assert_fee_amount (fee , Decimal (len (res ["hex" ]) / 2 ), Decimal ("0.00003" ))
273275
274- # TODO: This test should pass with all modes, e.g. with the next line uncommented, for consistency with the other explicit feerate RPCs.
275- # for mode in ["unset", "economical", "conservative", "btc/kb", "sat/b"]:
276+ for target , mode in product ([- 1 , 0 , 1009 ], ["economical" , "conservative" ]):
277+ self .test_send (from_wallet = w0 , to_wallet = w1 , amount = 1 , conf_target = target , estimate_mode = mode ,
278+ expect_error = (- 8 , "Invalid conf_target, must be between 1 and 1008" ))
276279 for mode in ["btc/kb" , "sat/b" ]:
277280 self .test_send (from_wallet = w0 , to_wallet = w1 , amount = 1 , conf_target = - 1 , estimate_mode = mode ,
278281 expect_error = (- 3 , "Amount out of range" ))
@@ -282,17 +285,15 @@ def run_test(self):
282285 for mode in ["foo" , Decimal ("3.141592" )]:
283286 self .test_send (from_wallet = w0 , to_wallet = w1 , amount = 1 , conf_target = 0.1 , estimate_mode = mode ,
284287 expect_error = (- 8 , "Invalid estimate_mode parameter" ))
285- # TODO: these 2 equivalent sends with an invalid estimate_mode arg should both fail, but they do not...why?
286- # self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_conf_target=0.1, arg_estimate_mode=mode,
287- # expect_error=(-8, "Invalid estimate_mode parameter"))
288- # assert_raises_rpc_error(-8, "Invalid estimate_mode parameter", lambda: w0.send({w1.getnewaddress(): 1}, 0.1, mode))
289-
290- # TODO: These tests should pass for consistency with the other explicit feerate RPCs, but they do not.
291- # for mode in ["unset", "economical", "conservative", "btc/kb", "sat/b"]:
292- # self.log.debug("{}".format(mode))
293- # for k, v in {"string": "", "object": {"foo": "bar"}}.items():
294- # self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=v, estimate_mode=mode,
295- # expect_error=(-3, "Expected type number for conf_target, got {}".format(k)))
288+ self .test_send (from_wallet = w0 , to_wallet = w1 , amount = 1 , arg_conf_target = 0.1 , arg_estimate_mode = mode ,
289+ expect_error = (- 8 , "Invalid estimate_mode parameter" ))
290+ assert_raises_rpc_error (- 8 , "Invalid estimate_mode parameter" , lambda : w0 .send ({w1 .getnewaddress (): 1 }, 0.1 , mode ))
291+
292+ for mode in ["economical" , "conservative" , "btc/kb" , "sat/b" ]:
293+ self .log .debug ("{}" .format (mode ))
294+ for k , v in {"string" : "true" , "object" : {"foo" : "bar" }}.items ():
295+ self .test_send (from_wallet = w0 , to_wallet = w1 , amount = 1 , conf_target = v , estimate_mode = mode ,
296+ expect_error = (- 3 , "Expected type number for conf_target, got {}" .format (k )))
296297
297298 # TODO: error should use sat/B instead of BTC/kB if sat/B is selected.
298299 # Test setting explicit fee rate just below the minimum.
0 commit comments