Skip to content
Bitcoin Roots

v31.1-roots.1 · Commit 11: [PATCH 11/17] fix(test): bound policy oracles and retain CI diagnostics

src/test/fuzz/policy_args.cpp

Before: src/test/fuzz/policy_args.cpp · After: src/test/fuzz/policy_args.cpp

File metadata
index eaa8af6199499f1d66326b6f362d1ff8c711f525..8ea7efa1a020b953f782588f2718e35a7f4121b5 100644

Download original patch · Release notes

Diff rows 1–39 of 39. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.

src/test/fuzz/policy_args.cpp CHANGED
@@ -8,6 +8,7 @@
8
8
  #include <node/mempool_args.h>
9
9
  #include <test/fuzz/FuzzedDataProvider.h>
10
10
  #include <test/fuzz/fuzz.h>
11
+ #include <test/util/roots_policy_oracles.h>
11
12
  #include <test/util/setup_common.h>
12
13
  #include <univalue.h>
13
14
  #include <util/check.h>
@@ -24,24 +25,6 @@ void InitializePolicyArgs()
24
25
  static const auto setup = MakeNoLogFileContext<const BasicTestingSetup>();
25
26
  }
26
27
 
27
- // Decimal accumulation with an explicit bound is independent of ToIntegral.
28
- bool ValidInteger(std::string_view value, uint64_t maximum)
29
- {
30
- bool negative{false};
31
- if (!value.empty() && (value.front() == '+' || value.front() == '-')) {
32
- negative = value.front() == '-';
33
- value.remove_prefix(1);
34
- }
35
- if (value.empty()) return false;
36
- uint64_t number{0};
37
- for (const unsigned char digit : value) {
38
- if (digit < '0' || digit > '9') return false;
39
- const auto numeric_digit{static_cast<uint64_t>(digit - '0')};
40
- if (number > maximum / 10 || (number == maximum / 10 && numeric_digit > maximum % 10)) return false;
41
- number = number * 10 + numeric_digit;
42
- }
43
- return !negative || number == 0;
44
- }
45
28
  } // namespace
46
29
 
47
30
  FUZZ_TARGET(policy_args, .init = InitializePolicyArgs)
@@ -63,7 +46,7 @@ FUZZ_TARGET(policy_args, .init = InitializePolicyArgs)
63
46
  {"-blockmaxsize", 4'000'000}, {"-blockprioritysize", INT64_MAX}}) {
64
47
  ArgsManager args;
65
48
  args.ForceSetArg(option, value);
66
- Assert(bool(ValidateRootsPolicyOptions(args)) == ValidInteger(value, maximum));
49
+ Assert(bool(ValidateRootsPolicyOptions(args)) == roots_test::ValidInteger(value, maximum));
67
50
  }
68
51
  for (const char* option : {"-datacarriercost", "-mempoolreplacement", "-mempooltruc", "-permitephemeral", "-spkreuse"}) {
69
52
  ArgsManager args;