tests: Add deserialization fuzzing harnesses

This commit is contained in:
practicalswift
2019-10-03 14:18:31 +00:00
parent 16f0a186dc
commit 897849d8c2
4 changed files with 359 additions and 108 deletions

View File

@@ -26,19 +26,31 @@ void test_one_input(const std::vector<uint8_t>& buffer)
int nVersion;
ds >> nVersion;
ds.SetVersion(nVersion);
} catch (const std::ios_base::failure& e) {
} catch (const std::ios_base::failure&) {
return;
}
bool valid = true;
bool valid_tx = true;
const CTransaction tx = [&] {
try {
return CTransaction(deserialize, ds);
} catch (const std::ios_base::failure& e) {
valid = false;
} catch (const std::ios_base::failure&) {
valid_tx = false;
return CTransaction();
}
}();
if (!valid) {
bool valid_mutable_tx = true;
CDataStream ds_mtx(buffer, SER_NETWORK, INIT_PROTO_VERSION);
CMutableTransaction mutable_tx;
try {
int nVersion;
ds_mtx >> nVersion;
ds_mtx.SetVersion(nVersion);
ds_mtx >> mutable_tx;
} catch (const std::ios_base::failure&) {
valid_mutable_tx = false;
}
assert(valid_tx == valid_mutable_tx);
if (!valid_tx) {
return;
}