v30.3-roots.1 · Commit 2: [PATCH 02/68] feat(runtime): preserve Roots operator controls on Core 30.3
src/test/getarg_tests.cpp
Before: src/test/getarg_tests.cpp · After: src/test/getarg_tests.cpp
File metadata
index 8734735fd5b0c04832a65a74b80c13e1225d4b9c..277497000086c7e546999ba9140da2288ae4bf77 100644
Download original patch · Release notes
Diff rows 1–61 of 61. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/test/getarg_tests.cpp
CHANGED
|
@@ -10,6 +10,8 @@
|
|
| 10 |
#include <util/strencodings.h>
|
| 11 |
|
| 12 |
#include <limits>
|
|
|
|
|
|
|
| 13 |
#include <string>
|
| 14 |
#include <utility>
|
| 15 |
#include <vector>
|
|
@@ -104,22 +106,22 @@ BOOST_AUTO_TEST_CASE(setting_args)
|
|
| 104 |
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "99");
|
| 105 |
BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "99");
|
| 106 |
BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 99);
|
| 107 |
-
BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
|
| 108 |
-
BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);
|
| 109 |
|
| 110 |
set_foo(3.25);
|
| 111 |
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "3.25");
|
| 112 |
BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "3.25");
|
| 113 |
BOOST_CHECK_THROW(args.GetIntArg("foo", 100), std::runtime_error);
|
| 114 |
-
BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
|
| 115 |
-
BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);
|
| 116 |
|
| 117 |
set_foo(0);
|
| 118 |
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "0");
|
| 119 |
BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "0");
|
| 120 |
BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 0);
|
| 121 |
-
BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
|
| 122 |
-
BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);
|
| 123 |
|
| 124 |
set_foo(true);
|
| 125 |
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "true");
|
|
@@ -454,4 +456,25 @@ BOOST_AUTO_TEST_CASE(logargs)
|
|
| 454 |
BOOST_CHECK(str.find("private42") == std::string::npos);
|
| 455 |
}
|
| 456 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|
| 10 |
#include <util/strencodings.h>
|
| 11 |
|
| 12 |
#include <limits>
|
| 13 |
+
#include <map>
|
| 14 |
+
#include <sstream>
|
| 15 |
#include <string>
|
| 16 |
#include <utility>
|
| 17 |
#include <vector>
|
|
|
|
| 106 |
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "99");
|
| 107 |
BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "99");
|
| 108 |
BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 99);
|
| 109 |
+
BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), true);
|
| 110 |
+
BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), true);
|
| 111 |
|
| 112 |
set_foo(3.25);
|
| 113 |
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "3.25");
|
| 114 |
BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "3.25");
|
| 115 |
BOOST_CHECK_THROW(args.GetIntArg("foo", 100), std::runtime_error);
|
| 116 |
+
BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), true);
|
| 117 |
+
BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), true);
|
| 118 |
|
| 119 |
set_foo(0);
|
| 120 |
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "0");
|
| 121 |
BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "0");
|
| 122 |
BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 0);
|
| 123 |
+
BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), false);
|
| 124 |
+
BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), false);
|
| 125 |
|
| 126 |
set_foo(true);
|
| 127 |
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "true");
|
|
|
|
| 456 |
BOOST_CHECK(str.find("private42") == std::string::npos);
|
| 457 |
}
|
| 458 |
|
| 459 |
+
BOOST_AUTO_TEST_CASE(fixed_point_settings)
|
| 460 |
+
{
|
| 461 |
+
BOOST_CHECK(!SettingToFixedPoint(UniValue{}, 3));
|
| 462 |
+
BOOST_CHECK_EQUAL(*SettingToFixedPoint(UniValue{"1.25"}, 3), 1250);
|
| 463 |
+
BOOST_CHECK_EQUAL(*SettingToFixedPoint(UniValue{UniValue::VNUM, "0.001"}, 3), 1);
|
| 464 |
+
BOOST_CHECK_THROW(SettingToFixedPoint(UniValue{"0.0001"}, 3), std::runtime_error);
|
| 465 |
+
BOOST_CHECK_THROW(SettingToFixedPoint(UniValue{"invalid"}, 3), std::runtime_error);
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
BOOST_AUTO_TEST_CASE(rw_config_stream)
|
| 469 |
+
{
|
| 470 |
+
std::istringstream input{"# operator settings\nprune=5\n[regtest]\nprune=1\n"};
|
| 471 |
+
std::ostringstream output;
|
| 472 |
+
ModifyRWConfigStream(input, output, {{"listen", "0"}, {"prune", "550"}});
|
| 473 |
+
BOOST_CHECK_EQUAL(output.str(), "# operator settings\nprune=550\nlisten=0\n[regtest]\nprune=1\n");
|
| 474 |
+
|
| 475 |
+
std::istringstream empty;
|
| 476 |
+
std::ostringstream rejected;
|
| 477 |
+
BOOST_CHECK_THROW(ModifyRWConfigStream(empty, rejected, {{"listen", "0\nprune=0"}}), std::invalid_argument);
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
BOOST_AUTO_TEST_SUITE_END()
|