From 7b79275eba8a9e6bd51c8ab396633cf4a24899c0 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 7 Sep 2016 11:51:29 -0700 Subject: [PATCH] Add tests to try and improve coverage of perform_joinsplit. --- src/test/rpc_wallet_tests.cpp | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp index 091f404a9..bcbdd5086 100644 --- a/src/test/rpc_wallet_tests.cpp +++ b/src/test/rpc_wallet_tests.cpp @@ -18,6 +18,7 @@ #include "asyncrpcoperation.h" #include "wallet/asyncrpcoperation_sendmany.h" #include "rpcprotocol.h" +#include "init.h" #include #include @@ -930,6 +931,61 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals) // No taddr inputs, so signed tx is the same as unsigned. BOOST_CHECK_NO_THROW( proxy.sign_send_raw_transaction(obj) ); } + + + // Test the perform_joinsplit methods. + { + // Dummy input so the operation object can be instantiated. + std::vector recipients = { SendManyRecipient(zaddr1, 0.0005, "ABCD") }; + + std::shared_ptr operation( new AsyncRPCOperation_sendmany(zaddr1, {}, recipients, 1) ); + std::shared_ptr ptr = std::dynamic_pointer_cast (operation); + TEST_FRIEND_AsyncRPCOperation_sendmany proxy(ptr); + + // Enable test mode so tx is not sent and proofs are not generated + static_cast(operation.get())->testmode = true; + + AsyncJoinSplitInfo info; + std::vector> witnesses; + uint256 anchor; + try { + proxy.perform_joinsplit(info, witnesses, anchor); + } catch (const std::runtime_error & e) { + BOOST_CHECK( string(e.what()).find("anchor is null")!= string::npos); + } + + try { + std::vector v; + proxy.perform_joinsplit(info, v); + } catch (const std::runtime_error & e) { + BOOST_CHECK( string(e.what()).find("anchor is null")!= string::npos); + } + + info.notes.push_back(Note()); + try { + proxy.perform_joinsplit(info); + } catch (const std::runtime_error & e) { + BOOST_CHECK( string(e.what()).find("number of notes")!= string::npos); + } + + info.notes.clear(); + info.vjsin.push_back(JSInput()); + info.vjsin.push_back(JSInput()); + info.vjsin.push_back(JSInput()); + try { + proxy.perform_joinsplit(info); + } catch (const std::runtime_error & e) { + BOOST_CHECK( string(e.what()).find("unsupported joinsplit input")!= string::npos); + } + + info.vjsin.clear(); + try { + proxy.perform_joinsplit(info); + } catch (const std::runtime_error & e) { + BOOST_CHECK( string(e.what()).find("JoinSplit verifying key not loaded")!= string::npos); + } + } + }