Skip to content

Commit e75ecb9

Browse files
tests: Add fuzzing harness for various CTxOut related functions
1 parent ce93529 commit e75ecb9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/Makefile.test.include

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ FUZZ_TARGETS = \
4949
test/fuzz/transaction \
5050
test/fuzz/tx_in \
5151
test/fuzz/tx_in_deserialize \
52+
test/fuzz/tx_out \
5253
test/fuzz/txoutcompressor_deserialize \
5354
test/fuzz/txundo_deserialize
5455

@@ -504,6 +505,12 @@ test_fuzz_tx_in_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
504505
test_fuzz_tx_in_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
505506
test_fuzz_tx_in_LDADD = $(FUZZ_SUITE_LD_COMMON)
506507

508+
test_fuzz_tx_out_SOURCES = $(FUZZ_SUITE) test/fuzz/tx_out.cpp
509+
test_fuzz_tx_out_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
510+
test_fuzz_tx_out_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
511+
test_fuzz_tx_out_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
512+
test_fuzz_tx_out_LDADD = $(FUZZ_SUITE_LD_COMMON)
513+
507514
endif # ENABLE_FUZZ
508515

509516
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)

src/test/fuzz/tx_out.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <consensus/validation.h>
6+
#include <core_memusage.h>
7+
#include <policy/policy.h>
8+
#include <primitives/transaction.h>
9+
#include <streams.h>
10+
#include <test/fuzz/fuzz.h>
11+
#include <version.h>
12+
13+
void test_one_input(const std::vector<uint8_t>& buffer)
14+
{
15+
CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);
16+
CTxOut tx_out;
17+
try {
18+
int version;
19+
ds >> version;
20+
ds.SetVersion(version);
21+
ds >> tx_out;
22+
} catch (const std::ios_base::failure&) {
23+
return;
24+
}
25+
26+
const CFeeRate dust_relay_fee{DUST_RELAY_TX_FEE};
27+
(void)GetDustThreshold(tx_out, dust_relay_fee);
28+
(void)IsDust(tx_out, dust_relay_fee);
29+
(void)RecursiveDynamicUsage(tx_out);
30+
31+
(void)tx_out.ToString();
32+
(void)tx_out.IsNull();
33+
tx_out.SetNull();
34+
assert(tx_out.IsNull());
35+
}

0 commit comments

Comments
 (0)