Merge pull request #4985
bc470c4
Changed mixed indentation to four spaces (Eric Shaw)31d6390
Fixed setaccount accepting foreign address (Eric Shaw)
This commit is contained in:
commit
20a4b69360
2 changed files with 82 additions and 74 deletions
|
@ -230,6 +230,9 @@ Value setaccount(const Array& params, bool fHelp)
|
||||||
if (params.size() > 1)
|
if (params.size() > 1)
|
||||||
strAccount = AccountFromValue(params[1]);
|
strAccount = AccountFromValue(params[1]);
|
||||||
|
|
||||||
|
// Only add the account if the address is yours.
|
||||||
|
if (IsMine(*pwalletMain, address.Get()))
|
||||||
|
{
|
||||||
// Detect when changing the account of an address that is the 'unused current key' of another account:
|
// Detect when changing the account of an address that is the 'unused current key' of another account:
|
||||||
if (pwalletMain->mapAddressBook.count(address.Get()))
|
if (pwalletMain->mapAddressBook.count(address.Get()))
|
||||||
{
|
{
|
||||||
|
@ -237,8 +240,10 @@ Value setaccount(const Array& params, bool fHelp)
|
||||||
if (address == GetAccountAddress(strOldAccount))
|
if (address == GetAccountAddress(strOldAccount))
|
||||||
GetAccountAddress(strOldAccount, true);
|
GetAccountAddress(strOldAccount, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
pwalletMain->SetAddressBook(address.Get(), strAccount, "receive");
|
pwalletMain->SetAddressBook(address.Get(), strAccount, "receive");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw JSONRPCError(RPC_MISC_ERROR, "setaccount can only be used with own address");
|
||||||
|
|
||||||
return Value::null;
|
return Value::null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace json_spirit;
|
using namespace json_spirit;
|
||||||
|
|
||||||
extern Array createArgs(int nRequired, const char* address1=NULL, const char* address2=NULL);
|
extern Array createArgs(int nRequired, const char* address1 = NULL, const char* address2 = NULL);
|
||||||
extern Value CallRPC(string args);
|
extern Value CallRPC(string args);
|
||||||
|
|
||||||
extern CWallet* pwalletMain;
|
extern CWallet* pwalletMain;
|
||||||
|
@ -53,10 +53,10 @@ BOOST_AUTO_TEST_CASE(rpc_addmultisig)
|
||||||
BOOST_CHECK_THROW(addmultisig(createArgs(1, ""), false), runtime_error);
|
BOOST_CHECK_THROW(addmultisig(createArgs(1, ""), false), runtime_error);
|
||||||
BOOST_CHECK_THROW(addmultisig(createArgs(1, "NotAValidPubkey"), false), runtime_error);
|
BOOST_CHECK_THROW(addmultisig(createArgs(1, "NotAValidPubkey"), false), runtime_error);
|
||||||
|
|
||||||
string short1(address1Hex, address1Hex+sizeof(address1Hex)-2); // last byte missing
|
string short1(address1Hex, address1Hex + sizeof(address1Hex) - 2); // last byte missing
|
||||||
BOOST_CHECK_THROW(addmultisig(createArgs(2, short1.c_str()), false), runtime_error);
|
BOOST_CHECK_THROW(addmultisig(createArgs(2, short1.c_str()), false), runtime_error);
|
||||||
|
|
||||||
string short2(address1Hex+1, address1Hex+sizeof(address1Hex)); // first byte missing
|
string short2(address1Hex + 1, address1Hex + sizeof(address1Hex)); // first byte missing
|
||||||
BOOST_CHECK_THROW(addmultisig(createArgs(2, short2.c_str()), false), runtime_error);
|
BOOST_CHECK_THROW(addmultisig(createArgs(2, short2.c_str()), false), runtime_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,11 +80,15 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
|
||||||
walletdb.WriteAccount(strAccount, account);
|
walletdb.WriteAccount(strAccount, account);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CPubKey setaccountDemoPubkey = pwalletMain->GenerateNewKey();
|
||||||
|
CBitcoinAddress setaccountDemoAddress = CBitcoinAddress(CTxDestination(setaccountDemoPubkey.GetID()));
|
||||||
|
|
||||||
/*********************************
|
/*********************************
|
||||||
* setaccount
|
* setaccount
|
||||||
*********************************/
|
*********************************/
|
||||||
BOOST_CHECK_NO_THROW(CallRPC("setaccount 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ nullaccount"));
|
BOOST_CHECK_NO_THROW(CallRPC("setaccount " + setaccountDemoAddress.ToString() + " nullaccount"));
|
||||||
|
/* 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ is not owned by the test wallet. */
|
||||||
|
BOOST_CHECK_THROW(CallRPC("setaccount 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ nullaccount"), runtime_error);
|
||||||
BOOST_CHECK_THROW(CallRPC("setaccount"), runtime_error);
|
BOOST_CHECK_THROW(CallRPC("setaccount"), runtime_error);
|
||||||
/* 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4X (33 chars) is an illegal address (should be 34 chars) */
|
/* 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4X (33 chars) is an illegal address (should be 34 chars) */
|
||||||
BOOST_CHECK_THROW(CallRPC("setaccount 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4X nullaccount"), runtime_error);
|
BOOST_CHECK_THROW(CallRPC("setaccount 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4X nullaccount"), runtime_error);
|
||||||
|
@ -97,7 +101,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
|
||||||
BOOST_CHECK_THROW(CallRPC("listunspent 0 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 not_array"), runtime_error);
|
||||||
BOOST_CHECK_THROW(CallRPC("listunspent 0 1 [] extra"), runtime_error);
|
BOOST_CHECK_THROW(CallRPC("listunspent 0 1 [] extra"), runtime_error);
|
||||||
BOOST_CHECK_NO_THROW(r=CallRPC("listunspent 0 1 []"));
|
BOOST_CHECK_NO_THROW(r = CallRPC("listunspent 0 1 []"));
|
||||||
BOOST_CHECK(r.get_array().empty());
|
BOOST_CHECK(r.get_array().empty());
|
||||||
|
|
||||||
/*********************************
|
/*********************************
|
||||||
|
@ -154,16 +158,16 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
|
||||||
BOOST_CHECK_THROW(CallRPC("signmessage 1QFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ mymessage"), runtime_error);
|
BOOST_CHECK_THROW(CallRPC("signmessage 1QFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ mymessage"), runtime_error);
|
||||||
|
|
||||||
/* missing arguments */
|
/* missing arguments */
|
||||||
BOOST_CHECK_THROW(CallRPC("verifymessage "+ demoAddress.ToString()), runtime_error);
|
BOOST_CHECK_THROW(CallRPC("verifymessage " + demoAddress.ToString()), runtime_error);
|
||||||
BOOST_CHECK_THROW(CallRPC("verifymessage "+ demoAddress.ToString() + " " + retValue.get_str()), runtime_error);
|
BOOST_CHECK_THROW(CallRPC("verifymessage " + demoAddress.ToString() + " " + retValue.get_str()), runtime_error);
|
||||||
/* Illegal address */
|
/* Illegal address */
|
||||||
BOOST_CHECK_THROW(CallRPC("verifymessage 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4X " + retValue.get_str() + " mymessage"), runtime_error);
|
BOOST_CHECK_THROW(CallRPC("verifymessage 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4X " + retValue.get_str() + " mymessage"), runtime_error);
|
||||||
/* wrong address */
|
/* wrong address */
|
||||||
BOOST_CHECK(CallRPC("verifymessage 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ " + retValue.get_str() + " mymessage").get_bool() == false);
|
BOOST_CHECK(CallRPC("verifymessage 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ " + retValue.get_str() + " mymessage").get_bool() == false);
|
||||||
/* Correct address and signature but wrong message */
|
/* Correct address and signature but wrong message */
|
||||||
BOOST_CHECK(CallRPC("verifymessage "+ demoAddress.ToString() + " " + retValue.get_str() + " wrongmessage").get_bool() == false);
|
BOOST_CHECK(CallRPC("verifymessage " + demoAddress.ToString() + " " + retValue.get_str() + " wrongmessage").get_bool() == false);
|
||||||
/* Correct address, message and signature*/
|
/* Correct address, message and signature*/
|
||||||
BOOST_CHECK(CallRPC("verifymessage "+ demoAddress.ToString() + " " + retValue.get_str() + " mymessage").get_bool() == true);
|
BOOST_CHECK(CallRPC("verifymessage " + demoAddress.ToString() + " " + retValue.get_str() + " mymessage").get_bool() == true);
|
||||||
|
|
||||||
/*********************************
|
/*********************************
|
||||||
* getaddressesbyaccount
|
* getaddressesbyaccount
|
||||||
|
@ -173,7 +177,6 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
|
||||||
Array arr = retValue.get_array();
|
Array arr = retValue.get_array();
|
||||||
BOOST_CHECK(arr.size() > 0);
|
BOOST_CHECK(arr.size() > 0);
|
||||||
BOOST_CHECK(CBitcoinAddress(arr[0].get_str()).Get() == demoAddress.Get());
|
BOOST_CHECK(CBitcoinAddress(arr[0].get_str()).Get() == demoAddress.Get());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue