aboutsummaryrefslogtreecommitdiff
path: root/src/test/rpc_tests.cpp
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-04-06 19:36:10 +0200
committerJarol Rodriguez <jarolrod@tutanota.com>2021-04-07 01:57:26 -0400
commit60290d3f5ec8e7e3b8cb1ebae02d5d72f6005184 (patch)
tree71dffe7dcd70c09fe09180066a82eba59be801ce /src/test/rpc_tests.cpp
parent3e978d1a5dbd43f85bd03e759984ab1f209d6e34 (diff)
downloadbitcoin-60290d3f5ec8e7e3b8cb1ebae02d5d72f6005184.tar.xz
test: increase listbanned unit test coverage
Add test coverage for the new ban_duration and time_remaining fields. While here, some code improvements.
Diffstat (limited to 'src/test/rpc_tests.cpp')
-rw-r--r--src/test/rpc_tests.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index 67e70b3bc3..1e1b0518a7 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -269,9 +269,9 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
ar = r.get_array();
o1 = ar[0].get_obj();
adr = find_value(o1, "address");
- UniValue banned_until = find_value(o1, "banned_until");
+ int64_t banned_until{find_value(o1, "banned_until").get_int64()};
BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24");
- BOOST_CHECK_EQUAL(banned_until.get_int64(), 9907731200); // absolute time check
+ BOOST_CHECK_EQUAL(banned_until, 9907731200); // absolute time check
BOOST_CHECK_NO_THROW(CallRPC(std::string("clearbanned")));
@@ -280,11 +280,16 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
ar = r.get_array();
o1 = ar[0].get_obj();
adr = find_value(o1, "address");
- banned_until = find_value(o1, "banned_until");
+ banned_until = find_value(o1, "banned_until").get_int64();
+ 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");
- int64_t now = GetTime();
- BOOST_CHECK(banned_until.get_int64() > now);
- BOOST_CHECK(banned_until.get_int64()-now <= 200);
+ BOOST_CHECK(banned_until > now);
+ BOOST_CHECK(banned_until - now <= 200);
+ BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created);
+ BOOST_CHECK_EQUAL(time_remaining, banned_until - now);
// 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);