MCPcopy Create free account
hub / github.com/ElementsProject/elements / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/sighash_tests.cpp:120–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118BOOST_FIXTURE_TEST_SUITE(sighash_tests, BasicTestingSetup)
119
120BOOST_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
164BOOST_AUTO_TEST_CASE(sighash_from_data)

Callers

nothing calls this directly

Calls 15

InsecureRand32Function · 0.85
RandomTransactionFunction · 0.85
RandomScriptFunction · 0.85
InsecureRandRangeFunction · 0.85
SignatureHashOldFunction · 0.85
read_jsonFunction · 0.85
ParseHexFunction · 0.85
CheckTransactionFunction · 0.85
CConfidentialValueClass · 0.85
get_intMethod · 0.80
rand32Method · 0.80
StoreMethod · 0.80

Tested by

no test coverage detected