@@ -177,27 +177,36 @@ BOOST_AUTO_TEST_CASE(sighash_from_data)
177
177
}
178
178
if (test.size () == 1 ) continue ; // comment
179
179
180
- std::string raw_tx = test[0 ].get_str ();
181
- std::string raw_script = test[1 ].get_str ();
182
- int nIn = test[2 ].get_int ();
183
- int nHashType = test[3 ].get_int ();
184
- std::string sigHashHex = test[4 ].get_str ();
185
-
180
+ std::string raw_tx, raw_script, sigHashHex;
181
+ int nIn, nHashType;
186
182
uint256 sh;
187
- CDataStream stream (ParseHex (raw_tx), SER_NETWORK, PROTOCOL_VERSION);
188
183
CTransaction tx;
189
- stream >> tx;
190
-
191
- CValidationState state;
192
- BOOST_CHECK_MESSAGE (CheckTransaction (tx, state), strTest);
193
- BOOST_CHECK (state.IsValid ());
194
-
195
184
CScript scriptCode = CScript ();
196
- std::vector<unsigned char > raw = ParseHex (raw_script);
197
- scriptCode.insert (scriptCode.end (), raw.begin (), raw.end ());
198
185
186
+ try {
187
+ // deserialize test data
188
+ raw_tx = test[0 ].get_str ();
189
+ raw_script = test[1 ].get_str ();
190
+ nIn = test[2 ].get_int ();
191
+ nHashType = test[3 ].get_int ();
192
+ sigHashHex = test[4 ].get_str ();
193
+
194
+ uint256 sh;
195
+ CDataStream stream (ParseHex (raw_tx), SER_NETWORK, PROTOCOL_VERSION);
196
+ stream >> tx;
197
+
198
+ CValidationState state;
199
+ BOOST_CHECK_MESSAGE (CheckTransaction (tx, state), strTest);
200
+ BOOST_CHECK (state.IsValid ());
201
+
202
+ std::vector<unsigned char > raw = ParseHex (raw_script);
203
+ scriptCode.insert (scriptCode.end (), raw.begin (), raw.end ());
204
+ } catch (...) {
205
+ BOOST_ERROR (" Bad test, couldn't deserialize data: " << strTest);
206
+ continue ;
207
+ }
208
+
199
209
sh = SignatureHash (scriptCode, tx, nIn, nHashType);
200
-
201
210
BOOST_CHECK_MESSAGE (sh.GetHex () == sigHashHex, strTest);
202
211
}
203
212
}
0 commit comments