aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/test/sighash_tests.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp
index 0cc9bc20b9..9985ad6928 100644
--- a/src/test/sighash_tests.cpp
+++ b/src/test/sighash_tests.cpp
@@ -114,11 +114,21 @@ void static RandomTransaction(CTransaction &tx, bool fSingle) {
}
BOOST_AUTO_TEST_SUITE(sighash_tests)
+
BOOST_AUTO_TEST_CASE(sighash_test)
{
seed_insecure_rand(false);
-
- for (int i=0; i<50000; i++) {
+
+ #if defined(PRINT_SIGHASH_JSON)
+ std::cout << "[\n";
+ std::cout << "\t[\"raw_transaction, script, input_index, hashType, signature_hash (result)\"],\n";
+ #endif
+ int nRandomTests = 50000;
+
+ #if defined(PRINT_SIGHASH_JSON)
+ nRandomTests = 500;
+ #endif
+ for (int i=0; i<nRandomTests; i++) {
int nHashType = insecure_rand();
CTransaction txTo;
RandomTransaction(txTo, (nHashType & 0x1f) == SIGHASH_SINGLE);
@@ -129,12 +139,29 @@ BOOST_AUTO_TEST_CASE(sighash_test)
uint256 sh, sho;
sho = SignatureHashOld(scriptCode, txTo, nIn, nHashType);
sh = SignatureHash(scriptCode, txTo, nIn, nHashType);
+ #if defined(PRINT_SIGHASH_JSON)
+ CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
+ ss << txTo;
+
+ std::cout << "\t[\"" ;
+ std::cout << HexStr(ss.begin(), ss.end()) << "\", \"";
+ std::cout << HexStr(scriptCode) << "\", ";
+ std::cout << nIn << ", ";
+ std::cout << nHashType << ", \"";
+ std::cout << sho.GetHex() << "\"]";
+ if (i+1 != nRandomTests) {
+ std::cout << ",";
+ }
+ std::cout << "\n";
+ #endif
BOOST_CHECK(sh == sho);
}
+ #if defined(PRINT_SIGHASH_JSON)
+ std::cout << "]\n";
+ #endif
}
// Goal: check that SignatureHash generates correct hash
-
BOOST_AUTO_TEST_CASE(sighash_from_data)
{
Array tests = read_json(std::string(json_tests::sighash, json_tests::sighash + sizeof(json_tests::sighash)));