aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/integer.cpp
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2020-01-13 15:08:52 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2020-01-22 13:06:52 +0000
commit4a7fd7a7124f84e010b01d0769ef0572bf031ee8 (patch)
treee6d725412348cee076f9aa9ddaaa4f6eb6d3316c /src/test/fuzz/integer.cpp
parenta51aa2880d123fc0bcbc0ccd930dbf98e4d29863 (diff)
downloadbitcoin-4a7fd7a7124f84e010b01d0769ef0572bf031ee8.tar.xz
tests: Add amount compression/decompression fuzzing to existing fuzzing harness: test compression round-trip
Diffstat (limited to 'src/test/fuzz/integer.cpp')
-rw-r--r--src/test/fuzz/integer.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/test/fuzz/integer.cpp b/src/test/fuzz/integer.cpp
index 723938bcdb..b496ab5341 100644
--- a/src/test/fuzz/integer.cpp
+++ b/src/test/fuzz/integer.cpp
@@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <amount.h>
#include <arith_uint256.h>
#include <compressor.h>
#include <consensus/merkle.h>
@@ -56,7 +57,14 @@ void test_one_input(const std::vector<uint8_t>& buffer)
const Consensus::Params& consensus_params = Params().GetConsensus();
(void)CheckProofOfWork(u256, u32, consensus_params);
- (void)CompressAmount(u64);
+ if (u64 <= MAX_MONEY) {
+ const uint64_t compressed_money_amount = CompressAmount(u64);
+ assert(u64 == DecompressAmount(compressed_money_amount));
+ static const uint64_t compressed_money_amount_max = CompressAmount(MAX_MONEY - 1);
+ assert(compressed_money_amount <= compressed_money_amount_max);
+ } else {
+ (void)CompressAmount(u64);
+ }
static const uint256 u256_min(uint256S("0000000000000000000000000000000000000000000000000000000000000000"));
static const uint256 u256_max(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
const std::vector<uint256> v256{u256, u256_min, u256_max};