From f420b6356b6f886638282a6aa9309b9982768775 Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Wed, 16 Apr 2025 12:39:02 -0400 Subject: [PATCH] test: skip subtests that check for wrong types with cli The error messages returned for wrong type differ betwen using rpc or cli - skip these subtests where they happen. --- test/functional/rpc_estimatefee.py | 18 +++++++++--------- test/functional/rpc_generate.py | 9 +++++---- test/functional/rpc_getblockfrompeer.py | 7 +++++-- test/functional/rpc_getdescriptorinfo.py | 4 +++- test/functional/rpc_help.py | 4 ++-- test/functional/rpc_invalid_address_message.py | 10 ++++++---- test/functional/wallet_bumpfee.py | 12 +++++++----- 7 files changed, 37 insertions(+), 27 deletions(-) diff --git a/test/functional/rpc_estimatefee.py b/test/functional/rpc_estimatefee.py index 05ceafbe4e0..2b8772269ed 100755 --- a/test/functional/rpc_estimatefee.py +++ b/test/functional/rpc_estimatefee.py @@ -21,17 +21,17 @@ class EstimateFeeTest(BitcoinTestFramework): assert_raises_rpc_error(-1, "estimatesmartfee", self.nodes[0].estimatesmartfee) assert_raises_rpc_error(-1, "estimaterawfee", self.nodes[0].estimaterawfee) - # wrong type for conf_target - assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimatesmartfee, 'foo') - assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimaterawfee, 'foo') + # cli handles wrong types differently + if not self.options.usecli: + # wrong type for conf_target + assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimatesmartfee, 'foo') + assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimaterawfee, 'foo') + # wrong type for estimatesmartfee(estimate_mode) + assert_raises_rpc_error(-3, "JSON value of type number is not of expected type string", self.nodes[0].estimatesmartfee, 1, 1) + # wrong type for estimaterawfee(threshold) + assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimaterawfee, 1, 'foo') - # wrong type for estimatesmartfee(estimate_mode) - assert_raises_rpc_error(-3, "JSON value of type number is not of expected type string", self.nodes[0].estimatesmartfee, 1, 1) assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"', self.nodes[0].estimatesmartfee, 1, 'foo') - - # wrong type for estimaterawfee(threshold) - assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].estimaterawfee, 1, 'foo') - # extra params assert_raises_rpc_error(-1, "estimatesmartfee", self.nodes[0].estimatesmartfee, 1, 'ECONOMICAL', 1) assert_raises_rpc_error(-1, "estimaterawfee", self.nodes[0].estimaterawfee, 1, 1, 1) diff --git a/test/functional/rpc_generate.py b/test/functional/rpc_generate.py index 5f9dfdab173..a68d9c32247 100755 --- a/test/functional/rpc_generate.py +++ b/test/functional/rpc_generate.py @@ -124,11 +124,12 @@ class RPCGenerateTest(BitcoinTestFramework): "cli option. Refer to -help for more information.\n" ) - self.log.info("Test rpc generate raises with message to use cli option") - assert_raises_rpc_error(-32601, message, self.nodes[0]._rpc.generate) + if not self.options.usecli: + self.log.info("Test rpc generate raises with message to use cli option") + assert_raises_rpc_error(-32601, message, self.nodes[0]._rpc.generate) - self.log.info("Test rpc generate help prints message to use cli option") - assert_equal(message, self.nodes[0].help("generate")) + self.log.info("Test rpc generate help prints message to use cli option") + assert_equal(message, self.nodes[0].help("generate")) self.log.info("Test rpc generate is a hidden command not discoverable in general help") assert message not in self.nodes[0].help() diff --git a/test/functional/rpc_getblockfrompeer.py b/test/functional/rpc_getblockfrompeer.py index 05fe7699e0a..a417ffcb313 100755 --- a/test/functional/rpc_getblockfrompeer.py +++ b/test/functional/rpc_getblockfrompeer.py @@ -67,8 +67,11 @@ class GetBlockFromPeerTest(BitcoinTestFramework): self.log.info("Arguments must be valid") assert_raises_rpc_error(-8, "hash must be of length 64 (not 4, for '1234')", self.nodes[0].getblockfrompeer, "1234", peer_0_peer_1_id) - assert_raises_rpc_error(-3, "JSON value of type number is not of expected type string", self.nodes[0].getblockfrompeer, 1234, peer_0_peer_1_id) - assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].getblockfrompeer, short_tip, "0") + + # cli handles wrong types differently + if not self.options.usecli: + assert_raises_rpc_error(-3, "JSON value of type number is not of expected type string", self.nodes[0].getblockfrompeer, 1234, peer_0_peer_1_id) + assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", self.nodes[0].getblockfrompeer, short_tip, "0") self.log.info("We must already have the header") assert_raises_rpc_error(-1, "Block header missing", self.nodes[0].getblockfrompeer, "00" * 32, 0) diff --git a/test/functional/rpc_getdescriptorinfo.py b/test/functional/rpc_getdescriptorinfo.py index 65aa6dd47c8..56a8faaff98 100755 --- a/test/functional/rpc_getdescriptorinfo.py +++ b/test/functional/rpc_getdescriptorinfo.py @@ -35,7 +35,9 @@ class DescriptorTest(BitcoinTestFramework): def run_test(self): assert_raises_rpc_error(-1, 'getdescriptorinfo', self.nodes[0].getdescriptorinfo) - assert_raises_rpc_error(-3, 'JSON value of type number is not of expected type string', self.nodes[0].getdescriptorinfo, 1) + # cli handles wrong types differently + if not self.options.usecli: + assert_raises_rpc_error(-3, 'JSON value of type number is not of expected type string', self.nodes[0].getdescriptorinfo, 1) assert_raises_rpc_error(-5, "'' is not a valid descriptor function", self.nodes[0].getdescriptorinfo, "") assert_raises_rpc_error(-5, "pk(): Key ' 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798' is invalid due to whitespace", self.nodes[0].getdescriptorinfo, "pk( 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)") assert_raises_rpc_error(-5, "pk(): Key '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 ' is invalid due to whitespace", self.nodes[0].getdescriptorinfo, "pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 )") diff --git a/test/functional/rpc_help.py b/test/functional/rpc_help.py index 01a633a83d1..802a55492f2 100755 --- a/test/functional/rpc_help.py +++ b/test/functional/rpc_help.py @@ -45,7 +45,6 @@ def process_mapping(fname): class HelpRpcTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 - self.supports_cli = False self.uses_wallet = None def run_test(self): @@ -93,7 +92,8 @@ class HelpRpcTest(BitcoinTestFramework): assert_raises_rpc_error(-1, 'help', node.help, 'foo', 'bar') # invalid argument - assert_raises_rpc_error(-3, "JSON value of type number is not of expected type string", node.help, 0) + if not self.options.usecli: + assert_raises_rpc_error(-3, "JSON value of type number is not of expected type string", node.help, 0) # help of unknown command assert_equal(node.help('foo'), 'help: unknown command: foo') diff --git a/test/functional/rpc_invalid_address_message.py b/test/functional/rpc_invalid_address_message.py index bbd6955b563..25d8a68a1aa 100755 --- a/test/functional/rpc_invalid_address_message.py +++ b/test/functional/rpc_invalid_address_message.py @@ -97,10 +97,12 @@ class InvalidAddressErrorMessageTest(BitcoinTestFramework): node = self.nodes[0] - # Missing arg returns the help text - assert_raises_rpc_error(-1, "Return information about the given bitcoin address.", node.validateaddress) - # Explicit None is not allowed for required parameters - assert_raises_rpc_error(-3, "JSON value of type null is not of expected type string", node.validateaddress, None) + + if not self.options.usecli: + # Missing arg returns the help text + assert_raises_rpc_error(-1, "Return information about the given bitcoin address.", node.validateaddress) + # Explicit None is not allowed for required parameters + assert_raises_rpc_error(-3, "JSON value of type null is not of expected type string", node.validateaddress, None) def test_getaddressinfo(self): node = self.nodes[0] diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py index 00ce40b4475..05965caacd3 100755 --- a/test/functional/wallet_bumpfee.py +++ b/test/functional/wallet_bumpfee.py @@ -139,8 +139,9 @@ class BumpFeeTest(BitcoinTestFramework): assert_raises_rpc_error(-8, msg, rbf_node.bumpfee, rbfid, fee_rate=zero_value) msg = "Invalid amount" # Test fee_rate values that don't pass fixed-point parsing checks. - for invalid_value in ["", 0.000000001, 1e-09, 1.111111111, 1111111111111111, "31.999999999999999999999"]: - assert_raises_rpc_error(-3, msg, rbf_node.bumpfee, rbfid, fee_rate=invalid_value) + if not self.options.usecli: + for invalid_value in ["", 0.000000001, 1e-09, 1.111111111, 1111111111111111, "31.999999999999999999999"]: + assert_raises_rpc_error(-3, msg, rbf_node.bumpfee, rbfid, fee_rate=invalid_value) # Test fee_rate values that cannot be represented in sat/vB. for invalid_value in [0.0001, 0.00000001, 0.00099999, 31.99999999]: assert_raises_rpc_error(-3, msg, rbf_node.bumpfee, rbfid, fee_rate=invalid_value) @@ -164,9 +165,10 @@ class BumpFeeTest(BitcoinTestFramework): rbf_node.bumpfee, rbfid, {"confTarget": 123, "conf_target": 456}) self.log.info("Test invalid estimate_mode settings") - for k, v in {"number": 42, "object": {"foo": "bar"}}.items(): - assert_raises_rpc_error(-3, f"JSON value of type {k} for field estimate_mode is not of expected type string", - rbf_node.bumpfee, rbfid, estimate_mode=v) + if not self.options.usecli: + for k, v in {"number": 42, "object": {"foo": "bar"}}.items(): + assert_raises_rpc_error(-3, f"JSON value of type {k} for field estimate_mode is not of expected type string", + rbf_node.bumpfee, rbfid, estimate_mode=v) for mode in ["foo", Decimal("3.1415"), "sat/B", "BTC/kB"]: assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"', rbf_node.bumpfee, rbfid, estimate_mode=mode)