6#include <ipc/capnp/mining.capnp.h>
11#include <ipc/test/ipc_test.capnp.h>
12#include <ipc/test/ipc_test.capnp.proxy.h>
21#include <validation.h>
31#include <boost/test/unit_test.hpp>
33static_assert(ipc::capnp::messages::MAX_MONEY ==
MAX_MONEY);
34static_assert(ipc::capnp::messages::MAX_DOUBLE == std::numeric_limits<double>::max());
69 std::promise<std::unique_ptr<mp::ProxyClient<gen::FooInterface>>>
foo_promise;
71 mp::EventLoop loop(
"IpcPipeTest", [](
bool raise,
const std::string& log) {
LogInfo(
"LOG%i: %s", raise, log); });
75 auto foo_client = std::make_unique<mp::ProxyClient<gen::FooInterface>>(
82 auto foo_server = kj::heap<mp::ProxyServer<gen::FooInterface>>(std::make_shared<FooImplementation>(), connection);
83 return capnp::Capability::Client(kj::mv(foo_server));
88 std::unique_ptr<mp::ProxyClient<gen::FooInterface>>
foo{
foo_promise.get_future().get()};
99 uni1.pushKV(
"s",
"two");
112 std::vector<CTransactionRef>
txs1;
114 txs1.push_back(
nullptr);
115 std::vector<CTransactionRef>
txs2(
foo->passTransactions(
txs1));
120 std::vector<char>
vec1{
'H',
'e',
'l',
'l',
'o'};
136 std::unique_ptr<interfaces::Init>
init{std::make_unique<TestInit>()};
140 std::thread
thread([&]() {
160 std::unique_ptr<interfaces::Init>
init{std::make_unique<TestInit>()};
200 for (
int i : {0, 1, 0, 0, 1}) {
208 std::unique_ptr<interfaces::Init>
init{std::make_unique<TestInit>()};
212 std::string address{
strprintf(
"unix:%s",
TempPath(
"bitcoin_sock_limit_XXXXXX"))};
220 return std::make_pair(fd, addr);
229 auto second_call = std::async(std::launch::async, [&] {
230 std::string addr{address};
234 return std::make_pair(
remote_echo->echo(
"echo test 2"), addr);
261 fs::path datadir{
"/var/empty/notexist"};
262 auto check_notexist{[](
const std::system_error&
e) {
return e.code() == std::errc::no_such_file_or_directory; }};
275 check_address(
"unix:0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock",
276 "unix:" +
prefix +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock",
277 "Unix address path \"" +
prefix +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock\" exceeded maximum socket path length");
278 check_address(
"invalid",
"invalid",
"Unrecognized address 'invalid'");
297 check_listen_address(
"unix:path.sock,max-connections=8,unknown=1",
"", 0,
"Unknown socket option 'unknown'");
300 check_listen_address(
"unix:,max-connections=8,,max-connections=8",
"", 0,
"Empty socket option");
303 check_listen_address(
"unix:,max-connections=-9223372036854775808",
"", 0,
"max-connections must be at least 1");
304 check_listen_address(
"unix:,max-connections=257",
"", 0,
"max-connections must be at most 256");
305 check_listen_address(
"unix:,max-connections=9223372036854775808",
"", 0,
"Invalid max-connections value '9223372036854775808'");
306 check_listen_address(
"unix:,max-connections=",
"", 0,
"Missing value for max-connections option");
309 check_listen_address(
"unix:path%2Cbackup.sock=1,max-connections=8",
"unix:path,backup.sock=1", 8);
310 check_listen_address(
"unix:,max-connections",
"", 0,
"Missing value for max-connections option");
318 char arg0[]{
"bitcoin-node"};
constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
constexpr CAmount COIN
The amount of satoshis in one BTC.
#define Assert(val)
Identity function.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
std::unique_ptr< interfaces::Echo > makeEcho() override
void pushKV(std::string key, UniValue val)
Initial interface created when a process is first started, and used to give and get access to other i...
static util::Result< ipc::ListenAddress > parseListenAddress(std::string address)
Parse an IPC listening address and its per-listener options.
Object holding network & rpc state associated with either an incoming server connection,...
Event loop implementation.
kj::AsyncIoContext m_io_context
Capnp IO context.
static transaction_identifier FromUint256(const uint256 &id)
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
static std::string PathToString(const path &path)
Convert path object to a byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
BOOST_CHECK_EXCEPTION(HTTPHeaders{}.Read(reader), std::runtime_error, HasReason{"Empty HTTP header name"})
is a home for public enum and struct type definitions that are used internally by ipc code,...
BOOST_AUTO_TEST_CASE(ipc_tests)
void IpcSocketMaxConnectionsTest(const fs::path &datadir)
Test ipc::Protocol listen() local connection limiting over a unix socket.
static std::string TempPath(std::string_view pattern)
Generate a temporary path with temp_directory_path and mkstemp.
void IpcSocketTest(const fs::path &datadir)
Test ipc::Process bind() and connect() methods connecting over a unix socket.
void IpcPipeTest()
Unit test that tests execution of IPC calls without actually creating a separate process.
void IpcSocketPairTest()
Test ipc::Protocol connect() and serve() methods connecting over a socketpair.
static const std::string addr1
static const std::string addr2
std::thread thread
Thread variable should be after other struct members so the thread does not start until the other mem...
std::unique_ptr< Echo > MakeEcho()
Return implementation of Echo interface.
std::unique_ptr< Protocol > MakeCapnpProtocol(const char *exe_name)
constexpr size_t MAX_CONNECTIONS
Maximum accepted client connection limit for an IPC listening socket.
std::unique_ptr< Process > MakeProcess()
Constructor for Process interface.
constexpr size_t DEFAULT_MAX_CONNECTIONS
Default accepted client connection limit for each IPC listening socket.
std::array< SocketId, 2 > SocketPair()
constexpr SocketId SocketError
bilingual_str ErrorString(const Result< T > &result)
#define BOOST_CHECK_THROW(stmt, excMatch)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
constexpr unsigned int DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIGOPS
Default sigops cost to reserve for coinbase transaction outputs when creating block templates.
constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT
Default for -blockreservedweight.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
A mutable version of CTransaction.
Vat id for server side of connection.
BOOST_CHECK_NE(OneL.ToString(), ArrayToString(ZeroArray, 32))
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.