Changeset View
Changeset View
Standalone View
Standalone View
src/test/sighash_tests.cpp
Show First 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | for (int i = 0; i < nRandomTests; i++) { | ||||
CMutableTransaction txTo; | CMutableTransaction txTo; | ||||
RandomTransaction(txTo, (nHashType & 0x1f) == SIGHASH_SINGLE); | RandomTransaction(txTo, (nHashType & 0x1f) == SIGHASH_SINGLE); | ||||
CScript scriptCode; | CScript scriptCode; | ||||
RandomScript(scriptCode); | RandomScript(scriptCode); | ||||
int nIn = insecure_rand() % txTo.vin.size(); | int nIn = insecure_rand() % txTo.vin.size(); | ||||
uint256 sh, sho; | uint256 sh, sho; | ||||
sho = SignatureHashOld(scriptCode, txTo, nIn, nHashType); | sho = SignatureHashOld(scriptCode, txTo, nIn, nHashType); | ||||
sh = SignatureHash(scriptCode, txTo, nIn, nHashType, 0); | sh = SignatureHash(scriptCode, txTo, nIn, nHashType, Amount(0)); | ||||
#if defined(PRINT_SIGHASH_JSON) | #if defined(PRINT_SIGHASH_JSON) | ||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | ||||
ss << txTo; | ss << txTo; | ||||
std::cout << "\t[\""; | std::cout << "\t[\""; | ||||
std::cout << HexStr(ss.begin(), ss.end()) << "\", \""; | std::cout << HexStr(ss.begin(), ss.end()) << "\", \""; | ||||
std::cout << HexStr(scriptCode) << "\", "; | std::cout << HexStr(scriptCode) << "\", "; | ||||
std::cout << nIn << ", "; | std::cout << nIn << ", "; | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | for (unsigned int idx = 0; idx < tests.size(); idx++) { | ||||
std::vector<uint8_t> raw = ParseHex(raw_script); | std::vector<uint8_t> raw = ParseHex(raw_script); | ||||
scriptCode.insert(scriptCode.end(), raw.begin(), raw.end()); | scriptCode.insert(scriptCode.end(), raw.begin(), raw.end()); | ||||
} catch (...) { | } catch (...) { | ||||
BOOST_ERROR("Bad test, couldn't deserialize data: " << strTest); | BOOST_ERROR("Bad test, couldn't deserialize data: " << strTest); | ||||
continue; | continue; | ||||
} | } | ||||
sh = SignatureHash(scriptCode, *tx, nIn, nHashType, 0); | sh = SignatureHash(scriptCode, *tx, nIn, nHashType, Amount(0)); | ||||
BOOST_CHECK_MESSAGE(sh.GetHex() == sigHashHex, strTest); | BOOST_CHECK_MESSAGE(sh.GetHex() == sigHashHex, strTest); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |