Changeset View
Changeset View
Standalone View
Standalone View
src/test/rpc_tests.cpp
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 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\""; | ||||
InitInterfaces interfaces; | NodeContext node; | ||||
interfaces.chain = interfaces::MakeChain(); | node.chain = interfaces::MakeChain(); | ||||
g_rpc_interfaces = &interfaces; | g_rpc_node = &node; | ||||
r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + " [] " + | r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + " [] " + | ||||
prevout); | 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("signrawtransactionwithkey ") + notsigned + " [" + | r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + " [" + | ||||
privkey1 + "," + privkey2 + "] " + prevout); | 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); | ||||
g_rpc_interfaces = nullptr; | g_rpc_node = nullptr; | ||||
} | } | ||||
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 | ||||
// (We will re-use the tx + keys from the above rpc_rawsign test for | // (We will re-use the tx + keys from the above rpc_rawsign test for | ||||
Show All 14 Lines | BOOST_AUTO_TEST_CASE(rpc_rawsign_missing_amount) { | ||||
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; | ||||
InitInterfaces interfaces; | NodeContext node; | ||||
interfaces.chain = interfaces::MakeChain(); | node.chain = interfaces::MakeChain(); | ||||
g_rpc_interfaces = &interfaces; | g_rpc_node = &node; | ||||
try { | try { | ||||
r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + | r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + | ||||
" [" + privkey1 + "," + privkey2 + "] " + prevout); | " [" + 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); | ||||
g_rpc_interfaces = nullptr; | g_rpc_node = nullptr; | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(rpc_createraw_op_return) { | BOOST_AUTO_TEST_CASE(rpc_createraw_op_return) { | ||||
BOOST_CHECK_NO_THROW( | BOOST_CHECK_NO_THROW( | ||||
CallRPC("createrawtransaction " | CallRPC("createrawtransaction " | ||||
"[{\"txid\":" | "[{\"txid\":" | ||||
"\"a3b807410df0b60fcb9736768df5823938b2f838694939ba45f3c0a1bff1" | "\"a3b807410df0b60fcb9736768df5823938b2f838694939ba45f3c0a1bff1" | ||||
"50ed\",\"vout\":0}] {\"data\":\"68656c6c6f776f726c64\"}")); | "50ed\",\"vout\":0}] {\"data\":\"68656c6c6f776f726c64\"}")); | ||||
▲ Show 20 Lines • Show All 320 Lines • Show Last 20 Lines |