Bitcoin Core  22.99.0
P2P Digital Currency
fee_rate.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 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 <amount.h>
6 #include <policy/feerate.h>
8 #include <test/fuzz/fuzz.h>
9 #include <test/fuzz/util.h>
10 
11 #include <cstdint>
12 #include <limits>
13 #include <string>
14 #include <vector>
15 
16 FUZZ_TARGET(fee_rate)
17 {
18  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
19  const CAmount satoshis_per_k = ConsumeMoney(fuzzed_data_provider);
20  const CFeeRate fee_rate{satoshis_per_k};
21 
22  (void)fee_rate.GetFeePerK();
23  const auto bytes = fuzzed_data_provider.ConsumeIntegral<uint32_t>();
24  if (!MultiplicationOverflow(int64_t{bytes}, satoshis_per_k)) {
25  (void)fee_rate.GetFee(bytes);
26  }
27  (void)fee_rate.ToString();
28 
29  const CAmount another_satoshis_per_k = ConsumeMoney(fuzzed_data_provider);
30  CFeeRate larger_fee_rate{another_satoshis_per_k};
31  larger_fee_rate += fee_rate;
32  if (satoshis_per_k != 0 && another_satoshis_per_k != 0) {
33  assert(fee_rate < larger_fee_rate);
34  assert(!(fee_rate > larger_fee_rate));
35  assert(!(fee_rate == larger_fee_rate));
36  assert(fee_rate <= larger_fee_rate);
37  assert(!(fee_rate >= larger_fee_rate));
38  assert(fee_rate != larger_fee_rate);
39  }
40 }
feerate.h
assert
assert(!tx.IsCoinBase())
util.h
CFeeRate
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:29
MultiplicationOverflow
bool MultiplicationOverflow(const T i, const T j) noexcept
Definition: util.h:172
FuzzedDataProvider.h
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
FUZZ_TARGET
FUZZ_TARGET(fee_rate)
Definition: fee_rate.cpp:16
fuzz.h
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition: FuzzedDataProvider.h:194
CFeeRate::GetFeePerK
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:56
ConsumeMoney
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
Definition: util.cpp:221
amount.h