aboutsummaryrefslogtreecommitdiff
path: root/src/test/rpc_tests.cpp
diff options
context:
space:
mode:
authorJonas Schnelli <jonas.schnelli@include7.ch>2015-06-12 18:31:47 +0200
committerJonas Schnelli <jonas.schnelli@include7.ch>2015-06-17 21:40:55 +0200
commit4e36e9bcc7d071bba4c45fd89c0cfd2e2361ffe3 (patch)
tree2703eacb4f5dd62e6d6bb95193412cbcbf0e8ad5 /src/test/rpc_tests.cpp
parent3de24d7647db2b9167cee25549c3c603582e19e6 (diff)
setban: rewrite to UniValue, allow absolute bantime
Diffstat (limited to 'src/test/rpc_tests.cpp')
-rw-r--r--src/test/rpc_tests.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index 26588a43ed..e60281949e 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -181,25 +181,40 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
{
BOOST_CHECK_NO_THROW(CallRPC(string("clearbanned")));
- Value r;
+ UniValue r;
BOOST_CHECK_NO_THROW(r = CallRPC(string("setban 127.0.0.0 add")));
BOOST_CHECK_THROW(r = CallRPC(string("setban 127.0.0.0:8334")), runtime_error); //portnumber for setban not allowed
BOOST_CHECK_NO_THROW(r = CallRPC(string("listbanned")));
- Array ar = r.get_array();
- Object o1 = ar[0].get_obj();
- Value adr = find_value(o1, "address");
+ UniValue ar = r.get_array();
+ UniValue o1 = ar[0].get_obj();
+ UniValue adr = find_value(o1, "address");
BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/255.255.255.255");
BOOST_CHECK_NO_THROW(CallRPC(string("setban 127.0.0.0 remove")));;
BOOST_CHECK_NO_THROW(r = CallRPC(string("listbanned")));
ar = r.get_array();
BOOST_CHECK_EQUAL(ar.size(), 0);
- BOOST_CHECK_NO_THROW(r = CallRPC(string("setban 127.0.0.0/24 add")));
+ BOOST_CHECK_NO_THROW(r = CallRPC(string("setban 127.0.0.0/24 add 1607731200 true")));
+ BOOST_CHECK_NO_THROW(r = CallRPC(string("listbanned")));
+ ar = r.get_array();
+ o1 = ar[0].get_obj();
+ adr = find_value(o1, "address");
+ UniValue banned_until = find_value(o1, "banned_untill");
+ BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/255.255.255.0");
+ BOOST_CHECK_EQUAL(banned_until.get_int64(), 1607731200); // absolute time check
+
+ BOOST_CHECK_NO_THROW(CallRPC(string("clearbanned")));
+
+ BOOST_CHECK_NO_THROW(r = CallRPC(string("setban 127.0.0.0/24 add 200")));
BOOST_CHECK_NO_THROW(r = CallRPC(string("listbanned")));
ar = r.get_array();
o1 = ar[0].get_obj();
adr = find_value(o1, "address");
+ banned_until = find_value(o1, "banned_untill");
BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/255.255.255.0");
+ int64_t now = GetTime();
+ BOOST_CHECK(banned_until.get_int64() > now);
+ BOOST_CHECK(banned_until.get_int64()-now <= 200);
// must throw an exception because 127.0.0.1 is in already banned suubnet range
BOOST_CHECK_THROW(r = CallRPC(string("setban 127.0.0.1 add")), runtime_error);