test: Small fixes to sighash test vector generation
Also tweaks the test that parses them to display errors
This commit is contained in:
parent
cfa7d6bf73
commit
59efe29a78
|
@ -117,7 +117,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle, uint32_t co
|
|||
tx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID;
|
||||
tx.nVersion = overwinter_version_dist(rng);
|
||||
}
|
||||
tx.nExpiryHeight = (insecure_rand() % 2) ? insecure_rand() : 0;
|
||||
tx.nExpiryHeight = (insecure_rand() % 2) ? insecure_rand() % TX_EXPIRY_HEIGHT_THRESHOLD : 0;
|
||||
} else {
|
||||
tx.nVersion = insecure_rand() & 0x7FFFFFFF;
|
||||
}
|
||||
|
@ -229,7 +229,8 @@ BOOST_AUTO_TEST_CASE(sighash_test)
|
|||
#endif
|
||||
for (int i=0; i<nRandomTests; i++) {
|
||||
int nHashType = insecure_rand();
|
||||
uint32_t consensusBranchId = NetworkUpgradeInfo[insecure_rand() % Consensus::MAX_NETWORK_UPGRADES].nBranchId;
|
||||
// Exclude ZFUTURE as its branch ID can't be represented as a JSON int32
|
||||
uint32_t consensusBranchId = NetworkUpgradeInfo[insecure_rand() % (Consensus::MAX_NETWORK_UPGRADES - 1)].nBranchId;
|
||||
CMutableTransaction txTo;
|
||||
RandomTransaction(txTo, (nHashType & 0x1f) == SIGHASH_SINGLE, consensusBranchId);
|
||||
CScript scriptCode;
|
||||
|
@ -292,7 +293,8 @@ BOOST_AUTO_TEST_CASE(sighash_from_data)
|
|||
raw_script = test[1].get_str();
|
||||
nIn = test[2].get_int();
|
||||
nHashType = test[3].get_int();
|
||||
consensusBranchId = test[4].get_int();
|
||||
// JSON integers are signed, so parse uint32 as int64
|
||||
consensusBranchId = test[4].get_int64();
|
||||
sigHashHex = test[5].get_str();
|
||||
|
||||
uint256 sh;
|
||||
|
@ -324,6 +326,9 @@ BOOST_AUTO_TEST_CASE(sighash_from_data)
|
|||
|
||||
std::vector<unsigned char> raw = ParseHex(raw_script);
|
||||
scriptCode.insert(scriptCode.end(), raw.begin(), raw.end());
|
||||
} catch (const std::exception& ex) {
|
||||
BOOST_ERROR("Bad test, couldn't deserialize data: " << strTest << ": " << ex.what());
|
||||
continue;
|
||||
} catch (...) {
|
||||
BOOST_ERROR("Bad test, couldn't deserialize data: " << strTest);
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue