| 118 | BOOST_FIXTURE_TEST_SUITE(sighash_tests, BasicTestingSetup) |
| 119 | |
| 120 | BOOST_AUTO_TEST_CASE(sighash_test) |
| 121 | { |
| 122 | #if defined(PRINT_SIGHASH_JSON) |
| 123 | std::cout << "[\n"; |
| 124 | std::cout << "\t[\"raw_transaction, script, input_index, hashType, signature_hash (result)\"],\n"; |
| 125 | int nRandomTests = 500; |
| 126 | #else |
| 127 | int nRandomTests = 50000; |
| 128 | #endif |
| 129 | for (int i=0; i<nRandomTests; i++) { |
| 130 | // In randomized test, we disable SIGHASH_RANGEPROOF. |
| 131 | int nHashType{int(InsecureRand32()) & ~SIGHASH_RANGEPROOF}; |
| 132 | CMutableTransaction txTo; |
| 133 | RandomTransaction(txTo, (nHashType & 0x1f) == SIGHASH_SINGLE); |
| 134 | CScript scriptCode; |
| 135 | RandomScript(scriptCode); |
| 136 | int nIn = InsecureRandRange(txTo.vin.size()); |
| 137 | |
| 138 | uint256 sh, sho; |
| 139 | sho = SignatureHashOld(scriptCode, CTransaction(txTo), nIn, nHashType); |
| 140 | sh = SignatureHash(scriptCode, txTo, nIn, nHashType, 0, SigVersion::BASE, SCRIPT_SIGHASH_RANGEPROOF); |
| 141 | #if defined(PRINT_SIGHASH_JSON) |
| 142 | CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); |
| 143 | ss << txTo; |
| 144 | |
| 145 | std::cout << "\t[\"" ; |
| 146 | std::cout << HexStr(ss) << "\", \""; |
| 147 | std::cout << HexStr(scriptCode) << "\", "; |
| 148 | std::cout << nIn << ", "; |
| 149 | std::cout << nHashType << ", \""; |
| 150 | std::cout << sho.GetHex() << "\"]"; |
| 151 | if (i+1 != nRandomTests) { |
| 152 | std::cout << ","; |
| 153 | } |
| 154 | std::cout << "\n"; |
| 155 | #endif |
| 156 | BOOST_CHECK(sh == sho); |
| 157 | } |
| 158 | #if defined(PRINT_SIGHASH_JSON) |
| 159 | std::cout << "]\n"; |
| 160 | #endif |
| 161 | } |
| 162 | |
| 163 | // Goal: check that SignatureHash generates correct hash |
| 164 | BOOST_AUTO_TEST_CASE(sighash_from_data) |
nothing calls this directly
no test coverage detected