mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-24 22:45:41 +01:00
multiprocess: Add serialization code for BlockValidationState
Co-authored-by: TheCharlatan <seb.kung@gmail.com>
This commit is contained in:
@@ -9,7 +9,9 @@ $Cxx.namespace("gen");
|
||||
|
||||
using Proxy = import "/mp/proxy.capnp";
|
||||
$Proxy.include("test/ipc_test.h");
|
||||
$Proxy.includeTypes("ipc/capnp/common-types.h");
|
||||
$Proxy.includeTypes("test/ipc_test_types.h");
|
||||
|
||||
using Mining = import "../ipc/capnp/mining.capnp";
|
||||
|
||||
interface FooInterface $Proxy.wrap("FooImplementation") {
|
||||
add @0 (a :Int32, b :Int32) -> (result :Int32);
|
||||
@@ -17,4 +19,5 @@ interface FooInterface $Proxy.wrap("FooImplementation") {
|
||||
passUniValue @2 (arg :Text) -> (result :Text);
|
||||
passTransaction @3 (arg :Data) -> (result :Data);
|
||||
passVectorChar @4 (arg :Data) -> (result :Data);
|
||||
passBlockState @5 (arg :Mining.BlockValidationState) -> (result :Mining.BlockValidationState);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <test/ipc_test.capnp.proxy.h>
|
||||
#include <test/ipc_test.h>
|
||||
#include <tinyformat.h>
|
||||
#include <validation.h>
|
||||
|
||||
#include <future>
|
||||
#include <thread>
|
||||
@@ -101,6 +102,25 @@ void IpcPipeTest()
|
||||
std::vector<char> vec2{foo->passVectorChar(vec1)};
|
||||
BOOST_CHECK_EQUAL(std::string_view(vec1.begin(), vec1.end()), std::string_view(vec2.begin(), vec2.end()));
|
||||
|
||||
BlockValidationState bs1;
|
||||
bs1.Invalid(BlockValidationResult::BLOCK_CHECKPOINT, "reject reason", "debug message");
|
||||
BlockValidationState bs2{foo->passBlockState(bs1)};
|
||||
BOOST_CHECK_EQUAL(bs1.IsValid(), bs2.IsValid());
|
||||
BOOST_CHECK_EQUAL(bs1.IsError(), bs2.IsError());
|
||||
BOOST_CHECK_EQUAL(bs1.IsInvalid(), bs2.IsInvalid());
|
||||
BOOST_CHECK_EQUAL(static_cast<int>(bs1.GetResult()), static_cast<int>(bs2.GetResult()));
|
||||
BOOST_CHECK_EQUAL(bs1.GetRejectReason(), bs2.GetRejectReason());
|
||||
BOOST_CHECK_EQUAL(bs1.GetDebugMessage(), bs2.GetDebugMessage());
|
||||
|
||||
BlockValidationState bs3;
|
||||
BlockValidationState bs4{foo->passBlockState(bs3)};
|
||||
BOOST_CHECK_EQUAL(bs3.IsValid(), bs4.IsValid());
|
||||
BOOST_CHECK_EQUAL(bs3.IsError(), bs4.IsError());
|
||||
BOOST_CHECK_EQUAL(bs3.IsInvalid(), bs4.IsInvalid());
|
||||
BOOST_CHECK_EQUAL(static_cast<int>(bs3.GetResult()), static_cast<int>(bs4.GetResult()));
|
||||
BOOST_CHECK_EQUAL(bs3.GetRejectReason(), bs4.GetRejectReason());
|
||||
BOOST_CHECK_EQUAL(bs3.GetDebugMessage(), bs4.GetDebugMessage());
|
||||
|
||||
// Test cleanup: disconnect pipe and join thread
|
||||
disconnect_client();
|
||||
thread.join();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <primitives/transaction.h>
|
||||
#include <univalue.h>
|
||||
#include <util/fs.h>
|
||||
#include <validation.h>
|
||||
|
||||
class FooImplementation
|
||||
{
|
||||
@@ -17,6 +18,7 @@ public:
|
||||
UniValue passUniValue(UniValue v) { return v; }
|
||||
CTransactionRef passTransaction(CTransactionRef t) { return t; }
|
||||
std::vector<char> passVectorChar(std::vector<char> v) { return v; }
|
||||
BlockValidationState passBlockState(BlockValidationState s) { return s; }
|
||||
};
|
||||
|
||||
void IpcPipeTest();
|
||||
|
||||
12
src/test/ipc_test_types.h
Normal file
12
src/test/ipc_test_types.h
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2024 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_TEST_IPC_TEST_TYPES_H
|
||||
#define BITCOIN_TEST_IPC_TEST_TYPES_H
|
||||
|
||||
#include <ipc/capnp/common-types.h>
|
||||
#include <ipc/capnp/mining-types.h>
|
||||
#include <test/ipc_test.capnp.h>
|
||||
|
||||
#endif // BITCOIN_TEST_IPC_TEST_TYPES_H
|
||||
Reference in New Issue
Block a user