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/roots_policy_oracle_tests.cpp

Before: /dev/null · After: src/test/roots_policy_oracle_tests.cpp

File metadata
new file mode 100644
index 0000000000000000000000000000000000000000..dca078eedcc0c35819c03d80aec0997e7cf80f05

Download original patch · Release notes

Diff rows 1–59 of 59. 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/roots_policy_oracle_tests.cpp ADDED
@@ -0,0 +1,59 @@
1
+ // Copyright (c) 2026 The Bitcoin Roots 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 <test/util/roots_policy_oracles.h>
6
+
7
+ #include <boost/multiprecision/cpp_int.hpp>
8
+ #include <boost/test/unit_test.hpp>
9
+
10
+ #include <cstdint>
11
+ #include <limits>
12
+ #include <string>
13
+
14
+ BOOST_AUTO_TEST_SUITE(roots_policy_oracle_tests)
15
+
16
+ BOOST_AUTO_TEST_CASE(signed_reference_boundaries)
17
+ {
18
+ using Wide = boost::multiprecision::int128_t;
19
+ constexpr auto minimum{std::numeric_limits<int64_t>::min()};
20
+ constexpr auto maximum{std::numeric_limits<int64_t>::max()};
21
+ for (const int64_t expected : {minimum, minimum + 1, int64_t{-1}, int64_t{0}, int64_t{1}, maximum - 1, maximum}) {
22
+ BOOST_CHECK_EQUAL(roots_test::BoundedSignedReference(Wide{expected}), expected);
23
+ }
24
+ BOOST_CHECK_EQUAL(roots_test::BoundedSignedReference(Wide{minimum} - 1), minimum);
25
+ BOOST_CHECK_EQUAL(roots_test::BoundedSignedReference(Wide{maximum} + 1), maximum);
26
+ BOOST_CHECK_EQUAL(roots_test::BoundedSignedReference(Wide{minimum} * 1000), minimum);
27
+ BOOST_CHECK_EQUAL(roots_test::BoundedSignedReference(Wide{maximum} * 1000), maximum);
28
+ // Negative division rounds down in the independent fee-rate oracle.
29
+ const Wide product{-1000};
30
+ Wide quotient{product / 3};
31
+ if (product < 0 && product % 3 != 0) --quotient;
32
+ BOOST_CHECK_EQUAL(roots_test::BoundedSignedReference(quotient), -334);
33
+ }
34
+
35
+ BOOST_AUTO_TEST_CASE(decimal_reference_grammar_and_bytes)
36
+ {
37
+ constexpr auto maximum{std::numeric_limits<uint64_t>::max()};
38
+ for (const std::string value : {"0", "1", "+1", "01", "-0", "-000", "18446744073709551615"}) {
39
+ BOOST_CHECK(roots_test::ValidInteger(value, maximum));
40
+ }
41
+ for (const std::string value : {"", "+", "-", "-1", "+-0", " 1", "1 ", "1.0", "18446744073709551616"}) {
42
+ BOOST_CHECK(!roots_test::ValidInteger(value, maximum));
43
+ }
44
+ BOOST_CHECK(roots_test::ValidInteger("0", 0));
45
+ BOOST_CHECK(!roots_test::ValidInteger("1", 0));
46
+ BOOST_CHECK(roots_test::ValidInteger("10", 10));
47
+ BOOST_CHECK(!roots_test::ValidInteger("11", 10));
48
+ // Exercise every byte, including embedded NULs and high-bit values, using
49
+ // the same char representation that std::string_view exposes to the oracle.
50
+ for (unsigned int byte{0}; byte <= 255; ++byte) {
51
+ const char character{static_cast<char>(static_cast<unsigned char>(byte))};
52
+ const std::string value(1, character);
53
+ const bool digit{byte >= '0' && byte <= '9'};
54
+ BOOST_CHECK_EQUAL(roots_test::ValidInteger(value, maximum), digit);
55
+ BOOST_CHECK_EQUAL(roots_test::ValidInteger("1" + value, maximum), digit);
56
+ }
57
+ }
58
+
59
+ BOOST_AUTO_TEST_SUITE_END()