Repository navigation
Expand file tree
/
Copy pathexcessiveblock_tests.cpp
More file actions
68 lines (53 loc) · 2.88 KB
/
Copy pathexcessiveblock_tests.cpp
File metadata and controls
68 lines (53 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2017-2020 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <consensus/consensus.h>
#include <rpc/server.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <limits>
#include <string>
extern UniValue CallRPC(const std::string &strMethod, bool multithreaded = false);
BOOST_FIXTURE_TEST_SUITE(excessiveblock_tests, TestingSetup)
BOOST_AUTO_TEST_CASE(excessiveblock_rpc) {
BOOST_CHECK_NO_THROW(CallRPC("getexcessiveblock"));
BOOST_CHECK_THROW(CallRPC("setexcessiveblock"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("setexcessiveblock not_uint"),
std::runtime_error);
BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1000000 not_uint"),
std::runtime_error);
BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1000000 1"),
std::runtime_error);
BOOST_CHECK_THROW(CallRPC("setexcessiveblock -1"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("setexcessiveblock 0"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1000"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC(std::string("setexcessiveblock ") +
std::to_string(ONE_MEGABYTE - 1)),
std::runtime_error);
BOOST_CHECK_THROW(CallRPC(std::string("setexcessiveblock ") +
std::to_string(ONE_MEGABYTE)),
std::runtime_error);
BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") +
std::to_string(ONE_MEGABYTE + 1)));
BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") +
std::to_string(ONE_MEGABYTE + 10)));
// Default can be higher than 1MB in future - test it too
BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") +
std::to_string(DEFAULT_EXCESSIVE_BLOCK_SIZE)));
// Setting excessive block size outside MAX_EXCESSIVE_BLOCK_SIZE is not allowed
BOOST_CHECK_THROW(CallRPC(std::string("setexcessiveblock ") + std::to_string(MAX_EXCESSIVE_BLOCK_SIZE + 1)),
std::runtime_error);
// However, setting it at the limit should be ok
BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") + std::to_string(MAX_EXCESSIVE_BLOCK_SIZE)));
BOOST_CHECK_THROW(
CallRPC(
std::string("setexcessiveblock ") +
std::to_string(uint64_t(std::numeric_limits<int64_t>::max()) + 1)),
std::runtime_error);
BOOST_CHECK_THROW(
CallRPC(std::string("setexcessiveblock ") +
std::to_string(std::numeric_limits<uint64_t>::max())),
std::runtime_error);
}
BOOST_AUTO_TEST_SUITE_END()