diff options
author | Manuel Araoz <manuelaraoz@gmail.com> | 2014-03-31 12:39:32 -0300 |
---|---|---|
committer | Manuel Araoz <manuelaraoz@gmail.com> | 2014-03-31 12:39:32 -0300 |
commit | 232aa9e034d4d48f4d16dfdc6bc0d56c9274cfd3 (patch) | |
tree | 82f90605a24d0f2dd2b8ddde06f6efd803b3a347 | |
parent | 43cb41859e910797510ef1117644fa2cd3c96fc9 (diff) |
Add code generating data/sighash.json test data
-rw-r--r-- | src/test/sighash_tests.cpp | 33 |
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))); |