6#include <capnp/capability.h>
14#include <ipc/test/fuzz/ipc_fuzz.capnp.h>
15#include <ipc/test/fuzz/ipc_fuzz.capnp.proxy.h>
31 std::promise<std::unique_ptr<mp::ProxyClient<test::fuzz::messages::IpcFuzzInterface>>> client_promise;
32 auto client_future{client_promise.get_future()};
33 m_loop_thread = std::thread([&client_promise] {
34 mp::EventLoop loop(
"ipc-fuzz", [](mp::LogMessage message) {
37 auto pipe = loop.m_io_context.provider->newTwoWayPipe();
39 auto server_connection = std::make_unique<mp::Connection>(
42 [&](mp::Connection& connection) {
43 auto server_proxy = kj::heap<mp::ProxyServer<test::fuzz::messages::IpcFuzzInterface>>(
44 std::make_shared<IpcFuzzImplementation>(), connection);
45 return capnp::Capability::Client(kj::mv(server_proxy));
47 server_connection->onDisconnect([&] { server_connection.reset(); });
49 auto client_connection = std::make_unique<mp::Connection>(loop, kj::mv(pipe.ends[1]));
50 auto client_proxy = std::make_unique<mp::ProxyClient<test::fuzz::messages::IpcFuzzInterface>>(
51 client_connection->m_rpc_system->bootstrap(mp::ServerVatId().vat_id)
52 .castAs<test::fuzz::messages::IpcFuzzInterface>(),
53 client_connection.get(),
55 (void)client_connection.release();
57 client_promise.set_value(std::move(client_proxy));
60 m_client = client_future.get();
66 if (m_loop_thread.joinable()) m_loop_thread.join();
69 std::unique_ptr<mp::ProxyClient<test::fuzz::messages::IpcFuzzInterface>> m_client;
72 std::thread m_loop_thread;
75static IpcFuzzSetup* g_ipc;
77static void initialize_ipc()
87 thread_local static IpcFuzzSetup
ipc;
99 static constexpr int MIN_ADD{-1'000'000};
100 static constexpr int MAX_ADD{1'000'000};
101 const int a = fuzzed_data_provider.ConsumeIntegralInRange<
int>(MIN_ADD, MAX_ADD);
102 const int b = fuzzed_data_provider.ConsumeIntegralInRange<
int>(MIN_ADD, MAX_ADD);
103 assert(
ipc.m_client->add(a, b) == a + b);
107 fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
109 assert(
ipc.m_client->passOutPoint(outpoint) == expected);
113 std::vector<uint8_t> expected{value.rbegin(), value.rend()};
114 assert(
ipc.m_client->passVectorUint8(value) == expected);
124 if (!value.
read(fuzzed_data_provider.ConsumeRandomLengthString(512)))
return;
125 assert(
ipc.m_client->passUniValue(value).write() == value.
write());
129 if (mutable_tx.
vin.empty())
return;
131 assert(
ipc.m_client->passTransaction(tx)->Equals(*tx));
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
bool read(std::string_view json)
Parse JSON; set value to null on failure.
static transaction_identifier FromUint256(const uint256 &id)
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
ThreadContext & CurrentThread()
std::shared_ptr< const CTransaction > CTransactionRef
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
A mutable version of CTransaction.
Log level
The severity level of this message.
std::string message
Message to be logged.
CScript ConsumeScript(FuzzedDataProvider &fuzzed_data_provider, const bool maybe_p2wsh) noexcept
CMutableTransaction ConsumeTransaction(FuzzedDataProvider &fuzzed_data_provider, const std::optional< std::vector< Txid > > &prevout_txids, const int max_num_in, const int max_num_out) noexcept
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
std::vector< B > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept