From 950f8ffdb67903359ab9f66a3062aecc3288e71f Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 11 Oct 2016 14:01:39 -0700 Subject: [PATCH 1/3] Fixes #1491 by updating help message for rpc call z_importkey --- src/wallet/rpcdump.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 61aa4da50..9db1a2fab 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -532,9 +532,9 @@ Value z_importkey(const Array& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return Value::null; - if (fHelp || params.size() < 1 || params.size() > 3) + if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "z_importkey \"zkey\" ( \"label\" rescan )\n" + "z_importkey \"zkey\" ( rescan )\n" "\nAdds a zkey (as returned by z_exportkey) to your wallet.\n" "\nArguments:\n" "1. \"zkey\" (string, required) The zkey (see z_exportkey)\n" @@ -545,10 +545,8 @@ Value z_importkey(const Array& params, bool fHelp) + HelpExampleCli("z_exportkey", "\"myaddress\"") + "\nImport the zkey with rescan\n" + HelpExampleCli("z_importkey", "\"mykey\"") + - "\nImport using a label and without rescan\n" - + HelpExampleCli("z_importkey", "\"mykey\" \"testing\" false") + "\nAs a JSON-RPC call\n" - + HelpExampleRpc("z_importkey", "\"mykey\", \"testing\", false") + + HelpExampleRpc("z_importkey", "\"mykey\", false") ); LOCK2(cs_main, pwalletMain->cs_wallet); From 49e591eb89aba9f8735379fce3b95a36c934d09c Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 12 Oct 2016 10:14:32 -0700 Subject: [PATCH 2/3] Fix incorrect check of number of parameters for z_getnewaddress. --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 33a62e98d..747682136 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2792,7 +2792,7 @@ Value z_getnewaddress(const Array& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return Value::null; - if (fHelp || params.size() > 1) + if (fHelp || params.size() > 0) throw runtime_error( "z_getnewaddress\n" "\nReturns a new zaddr for receiving payments.\n" From e346a0b3f884ca970b5b15ac0a73912befe28958 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 12 Oct 2016 10:15:12 -0700 Subject: [PATCH 3/3] Add tests to verify that all z_* rpc calls return an error if there are too many input parameters. --- src/test/rpc_wallet_tests.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp index 8395d982e..1da7c4781 100644 --- a/src/test/rpc_wallet_tests.cpp +++ b/src/test/rpc_wallet_tests.cpp @@ -312,7 +312,9 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_exportwallet) BOOST_CHECK(addrs.size()==1); BOOST_CHECK_THROW(CallRPC("z_exportwallet"), runtime_error); - + + BOOST_CHECK_THROW(CallRPC("z_exportwallet toomany args"), runtime_error); + boost::filesystem::path temp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); @@ -362,6 +364,9 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importwallet) // error if no args BOOST_CHECK_THROW(CallRPC("z_importwallet"), runtime_error); + // error if too many args + BOOST_CHECK_THROW(CallRPC("z_importwallet toomany args"), runtime_error); + // create a random key locally auto testSpendingKey = libzcash::SpendingKey::random(); auto testPaymentAddress = testSpendingKey.address(); @@ -430,6 +435,10 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importexport) BOOST_CHECK_THROW(CallRPC("z_importkey"), runtime_error); BOOST_CHECK_THROW(CallRPC("z_exportkey"), runtime_error); + // error if too many args + BOOST_CHECK_THROW(CallRPC("z_importkey too many args"), runtime_error); + BOOST_CHECK_THROW(CallRPC("z_exportkey toomany args"), runtime_error); + // wallet should currently be empty std::set addrs; pwalletMain->GetPaymentAddresses(addrs); @@ -490,6 +499,9 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importexport) CZCPaymentAddress pa(newaddress); auto newAddr = pa.Get(); BOOST_CHECK(pwalletMain->HaveSpendingKey(newAddr)); + + // Check if too many args + BOOST_CHECK_THROW(CallRPC("z_getnewaddress toomanyargs"), runtime_error); } @@ -709,6 +721,9 @@ BOOST_AUTO_TEST_CASE(rpc_z_getoperations) std::this_thread::sleep_for(std::chrono::milliseconds(1000)); BOOST_CHECK(q->getOperationCount() == 0); + // Check if too many args + BOOST_CHECK_THROW(CallRPC("z_listoperationids toomany args"), runtime_error); + Value retValue; BOOST_CHECK_NO_THROW(retValue = CallRPC("z_listoperationids")); BOOST_CHECK(retValue.get_array().size() == 2);