aboutsummaryrefslogtreecommitdiff
path: root/src/test/rpc_tests.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-04-14 10:03:39 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-04-14 10:05:09 +0200
commitfa78590a8fffdfc7e98ddb1f81218f05b1935a0a (patch)
treec15c163234096e2688c5bc1e3ff391f1d0ac8b81 /src/test/rpc_tests.cpp
parentb8e5bbdf93e5b3b35557d3b0e57a426492d568c1 (diff)
test: Use mocktime to avoid intermittent failure
Diffstat (limited to 'src/test/rpc_tests.cpp')
-rw-r--r--src/test/rpc_tests.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index 3b6faf7bbb..a1ad33b866 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -275,7 +275,11 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
BOOST_CHECK_NO_THROW(CallRPC(std::string("clearbanned")));
+ auto now = 10'000s;
+ SetMockTime(now);
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("setban 127.0.0.0/24 add 200")));
+ SetMockTime(now += 2s);
+ const int64_t time_remaining_expected{198};
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned")));
ar = r.get_array();
o1 = ar[0].get_obj();
@@ -284,12 +288,10 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
const int64_t ban_created{find_value(o1, "ban_created").get_int64()};
const int64_t ban_duration{find_value(o1, "ban_duration").get_int64()};
const int64_t time_remaining{find_value(o1, "time_remaining").get_int64()};
- const int64_t now{GetTime()};
BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24");
- BOOST_CHECK(banned_until > now);
- BOOST_CHECK(banned_until - now <= 200);
+ BOOST_CHECK_EQUAL(banned_until, time_remaining_expected + now.count());
BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created);
- BOOST_CHECK_EQUAL(time_remaining, banned_until - now);
+ BOOST_CHECK_EQUAL(time_remaining, time_remaining_expected);
// must throw an exception because 127.0.0.1 is in already banned subnet range
BOOST_CHECK_THROW(r = CallRPC(std::string("setban 127.0.0.1 add")), std::runtime_error);
@@ -333,6 +335,7 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
o1 = ar[0].get_obj();
adr = find_value(o1, "address");
BOOST_CHECK_EQUAL(adr.get_str(), "2001:4d48:ac57:400:cacf:e9ff:fe1d:9c63/128");
+ SetMockTime(0s);
}
BOOST_AUTO_TEST_CASE(rpc_convert_values_generatetoaddress)