diff --git a/silkworm/db/kv/grpc/client/remote_cursor_test.cpp b/silkworm/db/kv/grpc/client/remote_cursor_test.cpp index ca8f370376..d420091771 100644 --- a/silkworm/db/kv/grpc/client/remote_cursor_test.cpp +++ b/silkworm/db/kv/grpc/client/remote_cursor_test.cpp @@ -63,7 +63,7 @@ class RemoteCursorTest : public test_util::KVTestBase { // Execute the test preconditions: start a new Tx RPC and read first incoming message (tx_id) Task<::remote::Pair> start_and_read_tx_id() { - if (!co_await tx_rpc_.start(*stub)) { + if (!co_await tx_rpc_.start(*stub_)) { const auto status = co_await tx_rpc_.finish(); throw boost::system::system_error{rpc::to_system_code(status.error_code())}; } diff --git a/silkworm/db/kv/grpc/client/remote_transaction_test.cpp b/silkworm/db/kv/grpc/client/remote_transaction_test.cpp index 01aac25bfa..54cdd21daa 100644 --- a/silkworm/db/kv/grpc/client/remote_transaction_test.cpp +++ b/silkworm/db/kv/grpc/client/remote_transaction_test.cpp @@ -34,16 +34,16 @@ using testing::_; namespace proto = ::remote; namespace test = rpc::test; -struct RemoteTransactionTest : db::test_util::KVTestBase { - private: - api::CoherentStateCache state_cache_; - +class RemoteTransactionTest : public db::test_util::KVTestBase { public: - RemoteTransaction remote_tx{*stub, + RemoteTransaction remote_tx{*stub_, grpc_context_, &state_cache_, {}, {}}; + + private: + api::CoherentStateCache state_cache_; }; static remote::Pair make_fake_tx_created_pair() { @@ -446,7 +446,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::domain_get", "[db][k }; rpc::test::StrictMockAsyncResponseReader reader; - EXPECT_CALL(*stub, AsyncDomainGetRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncDomainGetRaw).WillOnce(testing::Return(&reader)); api::DomainPointResult result; @@ -489,7 +489,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::history_seek", "[db] }; rpc::test::StrictMockAsyncResponseReader reader; - EXPECT_CALL(*stub, AsyncHistorySeekRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncHistorySeekRaw).WillOnce(testing::Return(&reader)); api::HistoryPointResult result; @@ -541,7 +541,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::index_range", "[db][ SECTION("throw on error") { // Set the call expectations: // 1. remote::KV::StubInterface::AsyncIndexRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncIndexRangeRaw).WillOnce(Return(&reader)); + EXPECT_CALL(*stub_, AsyncIndexRangeRaw).WillOnce(Return(&reader)); // 2. AsyncResponseReader<>::Finish call fails EXPECT_CALL(reader, Finish).WillOnce(test::finish_error_aborted(grpc_context_, proto::IndexRangeReply{})); // Execute the test: trying to *use* index_range lazy result should throw @@ -550,7 +550,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::index_range", "[db][ SECTION("success: empty") { // Set the call expectations: // 1. remote::KV::StubInterface::AsyncIndexRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncIndexRangeRaw).WillRepeatedly(Return(&reader)); + EXPECT_CALL(*stub_, AsyncIndexRangeRaw).WillRepeatedly(Return(&reader)); // 2. AsyncResponseReader<>::Finish call succeeds 3 times EXPECT_CALL(reader, Finish) .WillOnce(test::finish_with(grpc_context_, make_index_range_reply({}, /*has_more*/ false))); @@ -561,7 +561,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::index_range", "[db][ SECTION("success: one page") { // Set the call expectations: // 1. remote::KV::StubInterface::AsyncIndexRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncIndexRangeRaw).WillRepeatedly(Return(&reader)); + EXPECT_CALL(*stub_, AsyncIndexRangeRaw).WillRepeatedly(Return(&reader)); // 2. AsyncResponseReader<>::Finish call succeeds EXPECT_CALL(reader, Finish) .WillOnce(test::finish_with(grpc_context_, make_index_range_reply({19}, /*has_more*/ false))); @@ -584,7 +584,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::index_range", "[db][ // 4. AsyncReaderWriter::Finish call succeeds w/ status OK EXPECT_CALL(reader_writer_, Finish).WillOnce(test::finish_streaming_ok(grpc_context_)); // 5. remote::KV::StubInterface::AsyncIndexRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncIndexRangeRaw).WillRepeatedly(Return(&reader)); + EXPECT_CALL(*stub_, AsyncIndexRangeRaw).WillRepeatedly(Return(&reader)); // 6. AsyncResponseReader<>::Finish call succeeds 3 times EXPECT_CALL(reader, Finish) .WillOnce(test::finish_with(grpc_context_, make_index_range_reply({1, 2, 3}, /*has_more*/ true))) @@ -637,7 +637,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::history_range", "[db SECTION("throw on error") { // Set the call expectations: // 1. remote::KV::StubInterface::AsyncHistoryRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncHistoryRangeRaw).WillOnce(Return(&reader)); + EXPECT_CALL(*stub_, AsyncHistoryRangeRaw).WillOnce(Return(&reader)); // 2. AsyncResponseReader<>::Finish call fails EXPECT_CALL(reader, Finish).WillOnce(test::finish_error_aborted(grpc_context_, proto::Pairs{})); // Execute the test: trying to *use* index_range lazy result should throw @@ -646,7 +646,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::history_range", "[db SECTION("success: empty") { // Set the call expectations: // 1. remote::KV::StubInterface::AsyncHistoryRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncHistoryRangeRaw).WillRepeatedly(Return(&reader)); + EXPECT_CALL(*stub_, AsyncHistoryRangeRaw).WillRepeatedly(Return(&reader)); // 2. AsyncResponseReader<>::Finish call succeeds 3 times EXPECT_CALL(reader, Finish) .WillOnce(test::finish_with(grpc_context_, make_key_value_range_reply({}, /*has_more*/ false))); @@ -657,7 +657,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::history_range", "[db SECTION("success: one page") { // Set the call expectations: // 1. remote::KV::StubInterface::AsyncHistoryRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncHistoryRangeRaw).WillRepeatedly(Return(&reader)); + EXPECT_CALL(*stub_, AsyncHistoryRangeRaw).WillRepeatedly(Return(&reader)); // 2. AsyncResponseReader<>::Finish call succeeds EXPECT_CALL(reader, Finish) .WillOnce(test::finish_with(grpc_context_, make_key_value_range_reply({kv1}, /*has_more*/ false))); @@ -680,7 +680,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::history_range", "[db // 4. AsyncReaderWriter::Finish call succeeds w/ status OK EXPECT_CALL(reader_writer_, Finish).WillOnce(test::finish_streaming_ok(grpc_context_)); // 5. remote::KV::StubInterface::AsyncHistoryRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncHistoryRangeRaw).WillRepeatedly(Return(&reader)); + EXPECT_CALL(*stub_, AsyncHistoryRangeRaw).WillRepeatedly(Return(&reader)); // 6. AsyncResponseReader<>::Finish call succeeds 3 times EXPECT_CALL(reader, Finish) .WillOnce(test::finish_with(grpc_context_, make_key_value_range_reply({kv1, kv2}, /*has_more*/ true))) @@ -723,7 +723,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::domain_range", "[db] SECTION("throw on error") { // Set the call expectations: // 1. remote::KV::StubInterface::AsyncDomainRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncDomainRangeRaw).WillOnce(Return(&reader)); + EXPECT_CALL(*stub_, AsyncDomainRangeRaw).WillOnce(Return(&reader)); // 2. AsyncResponseReader<>::Finish call fails EXPECT_CALL(reader, Finish).WillOnce(test::finish_error_aborted(grpc_context_, proto::Pairs{})); // Execute the test: trying to *use* index_range lazy result should throw @@ -732,7 +732,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::domain_range", "[db] SECTION("success: empty") { // Set the call expectations: // 1. remote::KV::StubInterface::AsyncDomainRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncDomainRangeRaw).WillRepeatedly(Return(&reader)); + EXPECT_CALL(*stub_, AsyncDomainRangeRaw).WillRepeatedly(Return(&reader)); // 2. AsyncResponseReader<>::Finish call succeeds 3 times EXPECT_CALL(reader, Finish) .WillOnce(test::finish_with(grpc_context_, make_key_value_range_reply({}, /*has_more*/ false))); @@ -743,7 +743,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::domain_range", "[db] SECTION("success: one page") { // Set the call expectations: // 1. remote::KV::StubInterface::AsyncDomainRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncDomainRangeRaw).WillRepeatedly(Return(&reader)); + EXPECT_CALL(*stub_, AsyncDomainRangeRaw).WillRepeatedly(Return(&reader)); // 2. AsyncResponseReader<>::Finish call succeeds EXPECT_CALL(reader, Finish) .WillOnce(test::finish_with(grpc_context_, make_key_value_range_reply({kv1}, /*has_more*/ false))); @@ -766,7 +766,7 @@ TEST_CASE_METHOD(RemoteTransactionTest, "RemoteTransaction::domain_range", "[db] // 4. AsyncReaderWriter::Finish call succeeds w/ status OK EXPECT_CALL(reader_writer_, Finish).WillOnce(test::finish_streaming_ok(grpc_context_)); // 5. remote::KV::StubInterface::AsyncDomainRangeRaw call succeeds - EXPECT_CALL(*stub, AsyncDomainRangeRaw).WillRepeatedly(Return(&reader)); + EXPECT_CALL(*stub_, AsyncDomainRangeRaw).WillRepeatedly(Return(&reader)); // 6. AsyncResponseReader<>::Finish call succeeds 3 times EXPECT_CALL(reader, Finish) .WillOnce(test::finish_with(grpc_context_, make_key_value_range_reply({kv1, kv2}, /*has_more*/ true))) diff --git a/silkworm/db/kv/state_changes_stream_test.cpp b/silkworm/db/kv/state_changes_stream_test.cpp index db24d1241b..98cede5343 100644 --- a/silkworm/db/kv/state_changes_stream_test.cpp +++ b/silkworm/db/kv/state_changes_stream_test.cpp @@ -113,7 +113,7 @@ TEST_CASE_METHOD(RemoteStateChangesStreamTest, "RemoteStateChangesStreamTest::op // 2. AsyncReader::Finish call succeeds w/ status cancelled EXPECT_CALL(*statechanges_reader_, Finish).WillOnce(test::finish_streaming_cancelled(grpc_context_)); // Execute the test: opening the stream should succeed until finishes - RemoteClient remote_client{make_remote_client(std::move(stub))}; + RemoteClient remote_client{make_remote_client(std::move(stub_))}; StateChangesStream stream{context_, remote_client}; std::future run_completed; CHECK_NOTHROW(run_completed = stream.open()); @@ -125,7 +125,7 @@ TEST_CASE_METHOD(RemoteStateChangesStreamTest, "RemoteStateChangesStreamTest::ru SECTION("stream closed-by-peer") { // Set the call expectations: // 1. remote::KV::StubInterface::PrepareAsyncStateChangesRaw calls succeed - EXPECT_CALL(*stub, PrepareAsyncStateChangesRaw) + EXPECT_CALL(*stub_, PrepareAsyncStateChangesRaw) .WillOnce(InvokeWithoutArgs([&]() { // 2. AsyncReader::StartCall call succeed EXPECT_CALL(*statechanges_reader_, StartCall) @@ -146,7 +146,7 @@ TEST_CASE_METHOD(RemoteStateChangesStreamTest, "RemoteStateChangesStreamTest::ru return statechanges_reader_ptr_.release(); })); - RemoteClient remote_client{make_remote_client(std::move(stub))}; + RemoteClient remote_client{make_remote_client(std::move(stub_))}; // remote_client.set_min_backoff_timeout(10ms); // remote_client.set_max_backoff_timeout(100ms); StateChangesStream stream{context_, remote_client}; @@ -163,7 +163,7 @@ TEST_CASE_METHOD(RemoteStateChangesStreamTest, "RemoteStateChangesStreamTest::ru // 3. AsyncReader::Finish call succeeds w/ status aborted EXPECT_CALL(*statechanges_reader_, Finish).WillOnce(test::finish_streaming_aborted(grpc_context_)); - RemoteClient remote_client{make_remote_client(std::move(stub))}; + RemoteClient remote_client{make_remote_client(std::move(stub_))}; StateChangesStream stream{context_, remote_client}; // Execute the test: running the stream should succeed until finishes @@ -180,7 +180,7 @@ TEST_CASE_METHOD(RemoteStateChangesStreamTest, "RemoteStateChangesStreamTest::ru // 3. AsyncReader::Finish call succeeds w/ status aborted EXPECT_CALL(*statechanges_reader_, Finish).WillOnce(test::finish_streaming_aborted(grpc_context_)); - RemoteClient remote_client{make_remote_client(std::move(stub))}; + RemoteClient remote_client{make_remote_client(std::move(stub_))}; StateChangesStream stream{context_, remote_client}; // Execute the test: running the stream should succeed until finishes @@ -194,7 +194,7 @@ TEST_CASE_METHOD(RemoteStateChangesStreamTest, "RemoteStateChangesStreamTest::cl SECTION("while requesting w/ error every 10ms") { // Set the call expectations: // 1. remote::KV::StubInterface::PrepareAsyncStateChangesRaw calls succeed - EXPECT_CALL(*stub, PrepareAsyncStateChangesRaw) + EXPECT_CALL(*stub_, PrepareAsyncStateChangesRaw) .WillRepeatedly(InvokeWithoutArgs([&]() { static int counter{0}; if (counter > 0) { @@ -216,7 +216,7 @@ TEST_CASE_METHOD(RemoteStateChangesStreamTest, "RemoteStateChangesStreamTest::cl return statechanges_reader_ptr_.release(); })); - RemoteClient remote_client{make_remote_client(std::move(stub))}; + RemoteClient remote_client{make_remote_client(std::move(stub_))}; remote_client.set_min_backoff_timeout(5ms); remote_client.set_max_backoff_timeout(10ms); StateChangesStream stream{context_, remote_client}; @@ -237,7 +237,7 @@ TEST_CASE_METHOD(RemoteStateChangesStreamTest, "RemoteStateChangesStreamTest::cl SECTION("while reading w/ error every 10ms") { // Set the call expectations: // 1. remote::KV::StubInterface::PrepareAsyncStateChangesRaw calls succeed - EXPECT_CALL(*stub, PrepareAsyncStateChangesRaw) + EXPECT_CALL(*stub_, PrepareAsyncStateChangesRaw) .WillRepeatedly(InvokeWithoutArgs([&]() { static int counter{0}; if (counter > 0) { @@ -263,7 +263,7 @@ TEST_CASE_METHOD(RemoteStateChangesStreamTest, "RemoteStateChangesStreamTest::cl return statechanges_reader_ptr_.release(); })); - RemoteClient remote_client{make_remote_client(std::move(stub))}; + RemoteClient remote_client{make_remote_client(std::move(stub_))}; remote_client.set_min_backoff_timeout(5ms); remote_client.set_max_backoff_timeout(10ms); StateChangesStream stream{context_, remote_client}; diff --git a/silkworm/db/test_util/kv_test_base.hpp b/silkworm/db/test_util/kv_test_base.hpp index 43d4a9798f..ee8ec05b3a 100644 --- a/silkworm/db/test_util/kv_test_base.hpp +++ b/silkworm/db/test_util/kv_test_base.hpp @@ -33,11 +33,11 @@ using testing::Return; class KVTestBase : public silkworm::test_util::ContextTestBase { public: testing::Expectation expect_request_async_tx(bool ok) { - return expect_request_async_tx(*stub, ok); + return expect_request_async_tx(*stub_, ok); } testing::Expectation expect_request_async_statechanges(bool ok) { - return expect_request_async_statechanges(*stub, ok); + return expect_request_async_statechanges(*stub_, ok); } testing::Expectation expect_request_async_tx(remote::MockKVStub& stb, bool ok) { @@ -58,10 +58,12 @@ class KVTestBase : public silkworm::test_util::ContextTestBase { using StrictMockKVTxAsyncReaderWriter = rpc::test::StrictMockAsyncReaderWriter; using StrictMockKVStateChangesAsyncReader = rpc::test::StrictMockAsyncReader; - //! Mocked stub of gRPC KV interface - std::unique_ptr stub{std::make_unique()}; + StrictMockKVStub& stub() { return *stub_; } protected: + //! Mocked stub of gRPC KV interface + std::unique_ptr stub_{std::make_unique()}; + //! Mocked reader/writer for Tx bidi streaming RPC of gRPC KV interface std::unique_ptr reader_writer_ptr_{ std::make_unique()}; diff --git a/silkworm/rpc/core/estimate_gas_oracle_test.cpp b/silkworm/rpc/core/estimate_gas_oracle_test.cpp index fa4e9340c6..d011408aa8 100644 --- a/silkworm/rpc/core/estimate_gas_oracle_test.cpp +++ b/silkworm/rpc/core/estimate_gas_oracle_test.cpp @@ -98,7 +98,7 @@ TEST_CASE("estimate gas") { const silkworm::ChainConfig& config{kMainnetConfig}; RemoteDatabaseTest remote_db_test; test::BackEndMock backend; - auto tx = std::make_unique(*remote_db_test.stub, + auto tx = std::make_unique(remote_db_test.stub(), remote_db_test.grpc_context(), &remote_db_test.state_cache, ethdb::kv::block_provider(&backend),