6#include <ipc/capnp/mining.capnp.h>
10#include <ipc/test/ipc_test.capnp.h>
11#include <ipc/test/ipc_test.capnp.proxy.h>
18#include <validation.h>
27#include <boost/test/unit_test.hpp>
30static_assert(ipc::capnp::messages::MAX_DOUBLE == std::numeric_limits<double>::max());
42static std::string
TempPath(std::string_view pattern)
46 int fd{mkstemp(temp.data())};
47 BOOST_CHECK_GE(fd, 0);
49 temp.resize(temp.size() - 1);
65 std::promise<std::unique_ptr<mp::ProxyClient<gen::FooInterface>>> foo_promise;
67 mp::EventLoop loop(
"IpcPipeTest", [](
bool raise,
const std::string& log) {
LogInfo(
"LOG%i: %s", raise, log); });
70 auto connection_client = std::make_unique<mp::Connection>(loop, kj::mv(pipe.ends[0]));
71 auto foo_client = std::make_unique<mp::ProxyClient<gen::FooInterface>>(
72 connection_client->m_rpc_system->bootstrap(
mp::ServerVatId().vat_id).castAs<gen::FooInterface>(),
73 connection_client.get(),
true);
74 (void)connection_client.release();
75 foo_promise.set_value(std::move(foo_client));
77 auto connection_server = std::make_unique<mp::Connection>(loop, kj::mv(pipe.ends[1]), [&](
mp::Connection& connection) {
78 auto foo_server = kj::heap<mp::ProxyServer<gen::FooInterface>>(std::make_shared<FooImplementation>(), connection);
79 return capnp::Capability::Client(kj::mv(foo_server));
81 connection_server->onDisconnect([&] { connection_server.reset(); });
84 std::unique_ptr<mp::ProxyClient<gen::FooInterface>> foo{foo_promise.get_future().get()};
90 COutPoint txout2{foo->passOutPoint(txout1)};
95 uni1.pushKV(
"s",
"two");
96 UniValue uni2{foo->passUniValue(uni1)};
102 mtx.
vin.emplace_back(txout1);
108 std::vector<CTransactionRef> txs1;
110 txs1.push_back(
nullptr);
111 std::vector<CTransactionRef> txs2(foo->passTransactions(txs1));
116 std::vector<char> vec1{
'H',
'e',
'l',
'l',
'o'};
117 std::vector<char> vec2{foo->passVectorChar(vec1)};
118 BOOST_CHECK_EQUAL(std::string_view(vec1.begin(), vec1.end()), std::string_view(vec2.begin(), vec2.end()));
121 auto script2{foo->passScript(script1)};
132 std::unique_ptr<interfaces::Init>
init{std::make_unique<TestInit>()};
135 std::promise<void> promise;
137 protocol->serve(*
init, [&] {
139 client_stream = protocol->makeStream(pair[0]);
141 return protocol->makeStream(pair[1]);
144 promise.get_future().wait();
145 std::unique_ptr<interfaces::Init> remote_init{protocol->connect(std::move(client_stream))};
146 std::unique_ptr<interfaces::Echo> remote_echo{remote_init->makeEcho()};
156 std::unique_ptr<interfaces::Init>
init{std::make_unique<TestInit>()};
160 std::string invalid_bind{
"invalid:"};
161 BOOST_CHECK_THROW(process->bind(datadir,
"test_bitcoin", invalid_bind), std::invalid_argument);
162 BOOST_CHECK_THROW(process->connect(datadir,
"test_bitcoin", invalid_bind), std::invalid_argument);
164 auto bind_and_listen{[&](
const std::string& bind_address) {
165 std::string address{bind_address};
166 mp::SocketId serve_fd = process->bind(datadir,
"test_bitcoin", address);
169 protocol->listen(serve_fd, *
init);
172 auto connect_and_test{[&](
const std::string& connect_address) {
173 std::string address{connect_address};
174 mp::SocketId connect_fd{process->connect(datadir,
"test_bitcoin", address)};
176 std::unique_ptr<interfaces::Init> remote_init{protocol->connect(protocol->makeStream(connect_fd))};
177 std::unique_ptr<interfaces::Echo> remote_echo{remote_init->makeEcho()};
185 std::vector<std::string> addresses{
191 for (
const auto& address : addresses) {
192 bind_and_listen(address);
196 for (
int i : {0, 1, 0, 0, 1}) {
197 connect_and_test(addresses[i]);
213 fs::path datadir{
"/var/empty/notexist"};
214 auto check_notexist{[](
const std::system_error& e) {
return e.code() == std::errc::no_such_file_or_directory; }};
215 auto check_address{[&](std::string address, std::string expect_address, std::string expect_error) {
216 if (expect_error.empty()) {
217 BOOST_CHECK_EXCEPTION(process->connect(datadir,
"test_bitcoin", address), std::system_error, check_notexist);
224 check_address(
"unix",
"unix:" +
prefix +
"test_bitcoin.sock",
"");
225 check_address(
"unix:",
"unix:" +
prefix +
"test_bitcoin.sock",
"");
226 check_address(
"unix:path.sock",
"unix:" +
prefix +
"path.sock",
"");
227 check_address(
"unix:0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock",
228 "unix:" +
prefix +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock",
229 "Unix address path \"" +
prefix +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.sock\" exceeded maximum socket path length");
230 check_address(
"invalid",
"invalid",
"Unrecognized address 'invalid'");
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
static 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
Initial interface created when a process is first started, and used to give and get access to other i...
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_EQUAL(headers.FindFirst("key"), "value")
BOOST_CHECK_EXCEPTION(HTTPHeaders{}.Read(reader), std::runtime_error, HasReason{"Empty HTTP header name"})
BOOST_AUTO_TEST_CASE(ipc_tests)
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.
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)
std::unique_ptr< Process > MakeProcess()
Constructor for Process interface.
std::array< SocketId, 2 > SocketPair()
constexpr SocketId SocketError
#define BOOST_CHECK_THROW(stmt, excMatch)
#define BOOST_CHECK(expr)
static constexpr unsigned int DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIGOPS
Default sigops cost to reserve for coinbase transaction outputs when creating block templates.
static 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.
std::vector< CTxOut > vout
Vat id for server side of connection.