Changeset View
Changeset View
Standalone View
Standalone View
src/test/rpc_tests.cpp
Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | BOOST_CHECK_NO_THROW( | ||||
r = CallRPC(std::string("decoderawtransaction ") + rawtx)); | r = CallRPC(std::string("decoderawtransaction ") + rawtx)); | ||||
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "size").get_int(), 193); | BOOST_CHECK_EQUAL(find_value(r.get_obj(), "size").get_int(), 193); | ||||
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "version").get_int(), 1); | BOOST_CHECK_EQUAL(find_value(r.get_obj(), "version").get_int(), 1); | ||||
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "locktime").get_int(), 0); | BOOST_CHECK_EQUAL(find_value(r.get_obj(), "locktime").get_int(), 0); | ||||
BOOST_CHECK_THROW( | BOOST_CHECK_THROW( | ||||
r = CallRPC(std::string("decoderawtransaction ") + rawtx + " extra"), | r = CallRPC(std::string("decoderawtransaction ") + rawtx + " extra"), | ||||
std::runtime_error); | std::runtime_error); | ||||
BOOST_CHECK_THROW(CallRPC("signrawtransaction"), std::runtime_error); | |||||
BOOST_CHECK_THROW(CallRPC("signrawtransaction null"), std::runtime_error); | |||||
BOOST_CHECK_THROW(CallRPC("signrawtransaction ff00"), std::runtime_error); | |||||
BOOST_CHECK_NO_THROW(CallRPC(std::string("signrawtransaction ") + rawtx)); | |||||
BOOST_CHECK_NO_THROW(CallRPC(std::string("signrawtransaction ") + rawtx + | |||||
" null null NONE|FORKID|ANYONECANPAY")); | |||||
BOOST_CHECK_NO_THROW(CallRPC(std::string("signrawtransaction ") + rawtx + | |||||
" [] [] NONE|FORKID|ANYONECANPAY")); | |||||
BOOST_CHECK_THROW(CallRPC(std::string("signrawtransaction ") + rawtx + | |||||
" null null badenum"), | |||||
std::runtime_error); | |||||
// Only check failure cases for sendrawtransaction, there's no network to | // Only check failure cases for sendrawtransaction, there's no network to | ||||
// send to... | // send to... | ||||
BOOST_CHECK_THROW(CallRPC("sendrawtransaction"), std::runtime_error); | BOOST_CHECK_THROW(CallRPC("sendrawtransaction"), std::runtime_error); | ||||
BOOST_CHECK_THROW(CallRPC("sendrawtransaction null"), std::runtime_error); | BOOST_CHECK_THROW(CallRPC("sendrawtransaction null"), std::runtime_error); | ||||
BOOST_CHECK_THROW(CallRPC("sendrawtransaction DEADBEEF"), | BOOST_CHECK_THROW(CallRPC("sendrawtransaction DEADBEEF"), | ||||
std::runtime_error); | std::runtime_error); | ||||
BOOST_CHECK_THROW( | BOOST_CHECK_THROW( | ||||
CallRPC(std::string("sendrawtransaction ") + rawtx + " extra"), | CallRPC(std::string("sendrawtransaction ") + rawtx + " extra"), | ||||
Show All 36 Lines | std::string prevout = "[{\"txid\":" | ||||
"fca5b94d6df834e77e108f68e66f126044c052ae\"}]"; | "fca5b94d6df834e77e108f68e66f126044c052ae\"}]"; | ||||
r = CallRPC(std::string("createrawtransaction ") + prevout + " " + | r = CallRPC(std::string("createrawtransaction ") + prevout + " " + | ||||
"{\"3HqAe9LtNBjnsfM4CyYaWTnvCaUYT7v4oZ\":11}"); | "{\"3HqAe9LtNBjnsfM4CyYaWTnvCaUYT7v4oZ\":11}"); | ||||
std::string notsigned = r.get_str(); | std::string notsigned = r.get_str(); | ||||
std::string privkey1 = | std::string privkey1 = | ||||
"\"KzsXybp9jX64P5ekX1KUxRQ79Jht9uzW7LorgwE65i5rWACL6LQe\""; | "\"KzsXybp9jX64P5ekX1KUxRQ79Jht9uzW7LorgwE65i5rWACL6LQe\""; | ||||
std::string privkey2 = | std::string privkey2 = | ||||
"\"Kyhdf5LuKTRx4ge69ybABsiUAWjVRK4XGxAKk2FQLp2HjGMy87Z4\""; | "\"Kyhdf5LuKTRx4ge69ybABsiUAWjVRK4XGxAKk2FQLp2HjGMy87Z4\""; | ||||
r = CallRPC(std::string("signrawtransaction ") + notsigned + " " + prevout + | r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + " [] " + | ||||
" " + "[]"); | prevout); | ||||
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == false); | BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == false); | ||||
r = CallRPC(std::string("signrawtransaction ") + notsigned + " " + prevout + | r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + " [" + | ||||
" " + "[" + privkey1 + "," + privkey2 + "]"); | privkey1 + "," + privkey2 + "] " + prevout); | ||||
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == true); | BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == true); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(rpc_rawsign_missing_amount) { | BOOST_AUTO_TEST_CASE(rpc_rawsign_missing_amount) { | ||||
// Old format, missing amount parameter for prevout should generate | // Old format, missing amount parameter for prevout should generate | ||||
// an RPC error. This is because of new replay-protected tx's require | // an RPC error. This is because of new replay-protected tx's require | ||||
// nonzero amount present in signed tx. | // nonzero amount present in signed tx. | ||||
// See: https://github.com/Bitcoin-ABC/bitcoin-abc/issues/63 | // See: https://github.com/Bitcoin-ABC/bitcoin-abc/issues/63 | ||||
Show All 14 Lines | BOOST_AUTO_TEST_CASE(rpc_rawsign_missing_amount) { | ||||
std::string notsigned = r.get_str(); | std::string notsigned = r.get_str(); | ||||
std::string privkey1 = | std::string privkey1 = | ||||
"\"KzsXybp9jX64P5ekX1KUxRQ79Jht9uzW7LorgwE65i5rWACL6LQe\""; | "\"KzsXybp9jX64P5ekX1KUxRQ79Jht9uzW7LorgwE65i5rWACL6LQe\""; | ||||
std::string privkey2 = | std::string privkey2 = | ||||
"\"Kyhdf5LuKTRx4ge69ybABsiUAWjVRK4XGxAKk2FQLp2HjGMy87Z4\""; | "\"Kyhdf5LuKTRx4ge69ybABsiUAWjVRK4XGxAKk2FQLp2HjGMy87Z4\""; | ||||
bool exceptionThrownDueToMissingAmount = false, | bool exceptionThrownDueToMissingAmount = false, | ||||
errorWasMissingAmount = false; | errorWasMissingAmount = false; | ||||
try { | try { | ||||
r = CallRPC(std::string("signrawtransaction ") + notsigned + " " + | r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + | ||||
prevout + " " + "[" + privkey1 + "," + privkey2 + "]"); | " [" + privkey1 + "," + privkey2 + "] " + prevout); | ||||
} catch (const std::runtime_error &e) { | } catch (const std::runtime_error &e) { | ||||
exceptionThrownDueToMissingAmount = true; | exceptionThrownDueToMissingAmount = true; | ||||
if (std::string(e.what()).find("amount") != std::string::npos) { | if (std::string(e.what()).find("amount") != std::string::npos) { | ||||
errorWasMissingAmount = true; | errorWasMissingAmount = true; | ||||
} | } | ||||
} | } | ||||
BOOST_CHECK(exceptionThrownDueToMissingAmount == true); | BOOST_CHECK(exceptionThrownDueToMissingAmount == true); | ||||
BOOST_CHECK(errorWasMissingAmount == true); | BOOST_CHECK(errorWasMissingAmount == true); | ||||
▲ Show 20 Lines • Show All 327 Lines • Show Last 20 Lines |