2013-11-30 11:10:35 +01:00
|
|
|
#include "rpcserver.h"
|
|
|
|
#include "rpcclient.h"
|
|
|
|
|
|
|
|
#include "base58.h"
|
2014-01-23 20:18:26 +01:00
|
|
|
#include "wallet.h"
|
2013-11-30 11:10:35 +01:00
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace json_spirit;
|
|
|
|
|
|
|
|
extern Array createArgs(int nRequired, const char* address1=NULL, const char* address2=NULL);
|
|
|
|
extern Value CallRPC(string args);
|
|
|
|
|
2014-01-23 20:18:26 +01:00
|
|
|
extern CWallet* pwalletMain;
|
|
|
|
|
2013-11-30 11:10:35 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE(rpc_wallet_tests)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(rpc_addmultisig)
|
|
|
|
{
|
2014-01-23 20:18:26 +01:00
|
|
|
LOCK(pwalletMain->cs_wallet);
|
|
|
|
|
2013-11-30 11:10:35 +01:00
|
|
|
rpcfn_type addmultisig = tableRPC["addmultisigaddress"]->actor;
|
|
|
|
|
|
|
|
// old, 65-byte-long:
|
|
|
|
const char address1Hex[] = "0434e3e09f49ea168c5bbf53f877ff4206923858aab7c7e1df25bc263978107c95e35065a27ef6f1b27222db0ec97e0e895eaca603d3ee0d4c060ce3d8a00286c8";
|
|
|
|
// new, compressed:
|
|
|
|
const char address2Hex[] = "0388c2037017c62240b6b72ac1a2a5f94da790596ebd06177c8572752922165cb4";
|
|
|
|
|
|
|
|
Value v;
|
|
|
|
CBitcoinAddress address;
|
|
|
|
BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex), false));
|
|
|
|
address.SetString(v.get_str());
|
|
|
|
BOOST_CHECK(address.IsValid() && address.IsScript());
|
|
|
|
|
|
|
|
BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex, address2Hex), false));
|
|
|
|
address.SetString(v.get_str());
|
|
|
|
BOOST_CHECK(address.IsValid() && address.IsScript());
|
|
|
|
|
|
|
|
BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(2, address1Hex, address2Hex), false));
|
|
|
|
address.SetString(v.get_str());
|
|
|
|
BOOST_CHECK(address.IsValid() && address.IsScript());
|
|
|
|
|
|
|
|
BOOST_CHECK_THROW(addmultisig(createArgs(0), false), runtime_error);
|
|
|
|
BOOST_CHECK_THROW(addmultisig(createArgs(1), false), runtime_error);
|
|
|
|
BOOST_CHECK_THROW(addmultisig(createArgs(2, address1Hex), false), runtime_error);
|
|
|
|
|
|
|
|
BOOST_CHECK_THROW(addmultisig(createArgs(1, ""), false), runtime_error);
|
|
|
|
BOOST_CHECK_THROW(addmultisig(createArgs(1, "NotAValidPubkey"), false), runtime_error);
|
|
|
|
|
|
|
|
string short1(address1Hex, address1Hex+sizeof(address1Hex)-2); // last byte missing
|
|
|
|
BOOST_CHECK_THROW(addmultisig(createArgs(2, short1.c_str()), false), runtime_error);
|
|
|
|
|
|
|
|
string short2(address1Hex+1, address1Hex+sizeof(address1Hex)); // first byte missing
|
|
|
|
BOOST_CHECK_THROW(addmultisig(createArgs(2, short2.c_str()), false), runtime_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(rpc_wallet)
|
|
|
|
{
|
|
|
|
// Test RPC calls for various wallet statistics
|
|
|
|
Value r;
|
|
|
|
|
2014-01-23 20:18:26 +01:00
|
|
|
LOCK(pwalletMain->cs_wallet);
|
|
|
|
|
2013-11-30 11:10:35 +01:00
|
|
|
BOOST_CHECK_NO_THROW(CallRPC("listunspent"));
|
|
|
|
BOOST_CHECK_THROW(CallRPC("listunspent string"), runtime_error);
|
|
|
|
BOOST_CHECK_THROW(CallRPC("listunspent 0 string"), runtime_error);
|
|
|
|
BOOST_CHECK_THROW(CallRPC("listunspent 0 1 not_array"), runtime_error);
|
|
|
|
BOOST_CHECK_THROW(CallRPC("listunspent 0 1 [] extra"), runtime_error);
|
|
|
|
BOOST_CHECK_NO_THROW(r=CallRPC("listunspent 0 1 []"));
|
|
|
|
BOOST_CHECK(r.get_array().empty());
|
|
|
|
|
|
|
|
BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress"));
|
|
|
|
BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress 0"));
|
|
|
|
BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress not_int"), runtime_error);
|
|
|
|
BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress 0 not_bool"), runtime_error);
|
|
|
|
BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress 0 true"));
|
|
|
|
BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress 0 true extra"), runtime_error);
|
|
|
|
|
|
|
|
BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount"));
|
|
|
|
BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0"));
|
|
|
|
BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount not_int"), runtime_error);
|
|
|
|
BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 not_bool"), runtime_error);
|
|
|
|
BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0 true"));
|
|
|
|
BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 true extra"), runtime_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|