aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/transaction.cpp
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2019-10-03 14:18:31 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2019-11-21 17:53:06 +0000
commit897849d8c225045f0dd3a2fe99b5d69bdf84b4e2 (patch)
treeffa08860acf6adb50699991166315cc23623eab2 /src/test/fuzz/transaction.cpp
parent16f0a186dcee563bb1000e1ffc51da87e7623bc6 (diff)
tests: Add deserialization fuzzing harnesses
Diffstat (limited to 'src/test/fuzz/transaction.cpp')
-rw-r--r--src/test/fuzz/transaction.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/test/fuzz/transaction.cpp b/src/test/fuzz/transaction.cpp
index 76b230ef3c..fefafda36b 100644
--- a/src/test/fuzz/transaction.cpp
+++ b/src/test/fuzz/transaction.cpp
@@ -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;
}