@@ -114,11 +114,21 @@ void static RandomTransaction(CTransaction &tx, bool fSingle) {
114
114
}
115
115
116
116
BOOST_AUTO_TEST_SUITE (sighash_tests)
117
+
117
118
BOOST_AUTO_TEST_CASE(sighash_test)
118
119
{
119
120
seed_insecure_rand (false );
120
-
121
- for (int i=0 ; i<50000 ; i++) {
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
+ #endif
126
+ int nRandomTests = 50000 ;
127
+
128
+ #if defined(PRINT_SIGHASH_JSON)
129
+ nRandomTests = 500 ;
130
+ #endif
131
+ for (int i=0 ; i<nRandomTests; i++) {
122
132
int nHashType = insecure_rand ();
123
133
CTransaction txTo;
124
134
RandomTransaction (txTo, (nHashType & 0x1f ) == SIGHASH_SINGLE);
@@ -129,12 +139,29 @@ BOOST_AUTO_TEST_CASE(sighash_test)
129
139
uint256 sh, sho;
130
140
sho = SignatureHashOld (scriptCode, txTo, nIn, nHashType);
131
141
sh = SignatureHash (scriptCode, txTo, nIn, nHashType);
142
+ #if defined(PRINT_SIGHASH_JSON)
143
+ CDataStream ss (SER_NETWORK, PROTOCOL_VERSION);
144
+ ss << txTo;
145
+
146
+ std::cout << " \t [\" " ;
147
+ std::cout << HexStr (ss.begin (), ss.end ()) << " \" , \" " ;
148
+ std::cout << HexStr (scriptCode) << " \" , " ;
149
+ std::cout << nIn << " , " ;
150
+ std::cout << nHashType << " , \" " ;
151
+ std::cout << sho.GetHex () << " \" ]" ;
152
+ if (i+1 != nRandomTests) {
153
+ std::cout << " ," ;
154
+ }
155
+ std::cout << " \n " ;
156
+ #endif
132
157
BOOST_CHECK (sh == sho);
133
158
}
159
+ #if defined(PRINT_SIGHASH_JSON)
160
+ std::cout << " ]\n " ;
161
+ #endif
134
162
}
135
163
136
164
// Goal: check that SignatureHash generates correct hash
137
-
138
165
BOOST_AUTO_TEST_CASE (sighash_from_data)
139
166
{
140
167
Array tests = read_json (std::string (json_tests::sighash, json_tests::sighash + sizeof (json_tests::sighash)));
0 commit comments