diff --git a/silkworm/rpc/core/estimate_gas_oracle_test.cpp b/silkworm/rpc/core/estimate_gas_oracle_test.cpp index d011408aa8..c0572ee2dd 100644 --- a/silkworm/rpc/core/estimate_gas_oracle_test.cpp +++ b/silkworm/rpc/core/estimate_gas_oracle_test.cpp @@ -44,7 +44,6 @@ namespace silkworm::rpc { class RemoteDatabaseTest : public db::test_util::KVTestBase { public: db::kv::api::CoherentStateCache state_cache; - test::BackEndMock backend; }; using testing::_; diff --git a/silkworm/rpc/ethbackend/remote_backend_test.cpp b/silkworm/rpc/ethbackend/remote_backend_test.cpp index fe6b385a64..8c2d8c839b 100644 --- a/silkworm/rpc/ethbackend/remote_backend_test.cpp +++ b/silkworm/rpc/ethbackend/remote_backend_test.cpp @@ -64,7 +64,7 @@ using EthBackendTest = test_util::GrpcApiTestBase reader; - EXPECT_CALL(*stub, AsyncEtherbaseRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncEtherbaseRaw).WillOnce(testing::Return(&reader)); SECTION("call etherbase and get address") { ::remote::EtherbaseReply response; @@ -88,7 +88,7 @@ TEST_CASE_METHOD(EthBackendTest, "BackEnd::etherbase", "[silkworm][rpc][ethbacke TEST_CASE_METHOD(EthBackendTest, "BackEnd::protocol_version", "[silkworm][rpc][ethbackend][backend]") { test::StrictMockAsyncResponseReader<::remote::ProtocolVersionReply> reader; - EXPECT_CALL(*stub, AsyncProtocolVersionRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncProtocolVersionRaw).WillOnce(testing::Return(&reader)); SECTION("call protocol_version and get version") { ::remote::ProtocolVersionReply response; @@ -112,7 +112,7 @@ TEST_CASE_METHOD(EthBackendTest, "BackEnd::protocol_version", "[silkworm][rpc][e TEST_CASE_METHOD(EthBackendTest, "BackEnd::net_version", "[silkworm][rpc][ethbackend][backend]") { test::StrictMockAsyncResponseReader<::remote::NetVersionReply> reader; - EXPECT_CALL(*stub, AsyncNetVersionRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncNetVersionRaw).WillOnce(testing::Return(&reader)); SECTION("call net_version and get version") { ::remote::NetVersionReply response; @@ -136,7 +136,7 @@ TEST_CASE_METHOD(EthBackendTest, "BackEnd::net_version", "[silkworm][rpc][ethbac TEST_CASE_METHOD(EthBackendTest, "BackEnd::client_version", "[silkworm][rpc][ethbackend][backend]") { test::StrictMockAsyncResponseReader<::remote::ClientVersionReply> reader; - EXPECT_CALL(*stub, AsyncClientVersionRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncClientVersionRaw).WillOnce(testing::Return(&reader)); SECTION("call client_version and get version") { ::remote::ClientVersionReply response; @@ -161,7 +161,7 @@ TEST_CASE_METHOD(EthBackendTest, "BackEnd::client_version", "[silkworm][rpc][eth TEST_CASE_METHOD(EthBackendTest, "BackEnd::get_block_number_from_txn_hash", "[silkworm][rpc][ethbackend][backend]") { test::StrictMockAsyncResponseReader<::remote::TxnLookupReply> reader; const Hash hash; - EXPECT_CALL(*stub, AsyncTxnLookupRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncTxnLookupRaw).WillOnce(testing::Return(&reader)); SECTION("call get_block_number_from_txn_hash and get number") { ::remote::TxnLookupReply response; @@ -185,7 +185,7 @@ TEST_CASE_METHOD(EthBackendTest, "BackEnd::get_block_number_from_txn_hash", "[si TEST_CASE_METHOD(EthBackendTest, "BackEnd::net_peer_count", "[silkworm][rpc][ethbackend][backend]") { test::StrictMockAsyncResponseReader<::remote::NetPeerCountReply> reader; - EXPECT_CALL(*stub, AsyncNetPeerCountRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncNetPeerCountRaw).WillOnce(testing::Return(&reader)); SECTION("call net_peer_count and get count") { ::remote::NetPeerCountReply response; @@ -209,7 +209,7 @@ TEST_CASE_METHOD(EthBackendTest, "BackEnd::net_peer_count", "[silkworm][rpc][eth TEST_CASE_METHOD(EthBackendTest, "BackEnd::node_info", "[silkworm][rpc][ethbackend][backend]") { test::StrictMockAsyncResponseReader<::remote::NodesInfoReply> reader; - EXPECT_CALL(*stub, AsyncNodeInfoRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncNodeInfoRaw).WillOnce(testing::Return(&reader)); SECTION("call node_info") { ::remote::NodesInfoReply response; @@ -465,7 +465,7 @@ TEST_CASE_METHOD(EthBackendTest, "BackEnd::engine_forkchoice_updated", "[silkwor TEST_CASE_METHOD(EthBackendTest, "BackEnd::peers", "[silkworm][rpc][ethbackend][backend]") { test::StrictMockAsyncResponseReader<::remote::PeersReply> reader; - EXPECT_CALL(*stub, AsyncPeersRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncPeersRaw).WillOnce(testing::Return(&reader)); SECTION("call peers") { ::remote::PeersReply response; diff --git a/silkworm/rpc/test_util/api_test_base.hpp b/silkworm/rpc/test_util/api_test_base.hpp index 431d6fe686..c4ab6358ef 100644 --- a/silkworm/rpc/test_util/api_test_base.hpp +++ b/silkworm/rpc/test_util/api_test_base.hpp @@ -34,31 +34,17 @@ class JsonApiTestBase : public ServiceContextTestBase { } }; -template -class JsonApiWithWorkersTestBase : public ServiceContextTestBase { - public: - explicit JsonApiWithWorkersTestBase() : ServiceContextTestBase(), workers_{1} {} - - template - auto run(Args&&... args) { - JsonApi api{io_context_, workers_}; - return spawn_and_wait((api.*method)(std::forward(args)...)); - } - - private: - WorkerPool workers_; -}; - template class GrpcApiTestBase : public ServiceContextTestBase { public: template auto run(Args&&... args) { - GrpcApi api{io_context_.get_executor(), std::move(stub), grpc_context_}; + GrpcApi api{io_context_.get_executor(), std::move(stub_), grpc_context_}; return spawn_and_wait((api.*method)(std::forward(args)...)); } - std::unique_ptr stub{std::make_unique()}; + protected: + std::unique_ptr stub_{std::make_unique()}; }; } // namespace silkworm::rpc::test_util diff --git a/silkworm/rpc/txpool/miner_test.cpp b/silkworm/rpc/txpool/miner_test.cpp index 54853eb162..6d63e3a2c8 100644 --- a/silkworm/rpc/txpool/miner_test.cpp +++ b/silkworm/rpc/txpool/miner_test.cpp @@ -42,7 +42,7 @@ using MinerTest = test_util::GrpcApiTestBase; #ifndef SILKWORM_SANITIZE TEST_CASE_METHOD(MinerTest, "Miner::get_work", "[rpc][txpool][miner]") { test::StrictMockAsyncResponseReader<::txpool::GetWorkReply> reader; - EXPECT_CALL(*stub, AsyncGetWorkRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncGetWorkRaw).WillOnce(testing::Return(&reader)); SECTION("call get_work and get result") { ::txpool::GetWorkReply response; @@ -75,7 +75,7 @@ TEST_CASE_METHOD(MinerTest, "Miner::get_work", "[rpc][txpool][miner]") { TEST_CASE_METHOD(MinerTest, "Miner::get_hashrate", "[rpc][txpool][miner]") { test::StrictMockAsyncResponseReader<::txpool::HashRateReply> reader; - EXPECT_CALL(*stub, AsyncHashRateRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncHashRateRaw).WillOnce(testing::Return(&reader)); SECTION("call get_hashrate and get result") { ::txpool::HashRateReply response; @@ -99,7 +99,7 @@ TEST_CASE_METHOD(MinerTest, "Miner::get_hashrate", "[rpc][txpool][miner]") { TEST_CASE_METHOD(MinerTest, "Miner::get_mining", "[rpc][txpool][miner]") { test::StrictMockAsyncResponseReader<::txpool::MiningReply> reader; - EXPECT_CALL(*stub, AsyncMiningRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncMiningRaw).WillOnce(testing::Return(&reader)); const std::pair enabled_running_pairs[] = { {false, false}, @@ -134,7 +134,7 @@ TEST_CASE_METHOD(MinerTest, "Miner::get_mining", "[rpc][txpool][miner]") { TEST_CASE_METHOD(MinerTest, "Miner::submit_work", "[rpc][txpool][miner]") { test::StrictMockAsyncResponseReader<::txpool::SubmitWorkReply> reader; - EXPECT_CALL(*stub, AsyncSubmitWorkRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncSubmitWorkRaw).WillOnce(testing::Return(&reader)); SECTION("call submit_work and get result") { ::txpool::SubmitWorkReply response; @@ -167,7 +167,7 @@ TEST_CASE_METHOD(MinerTest, "Miner::submit_work", "[rpc][txpool][miner]") { TEST_CASE_METHOD(MinerTest, "Miner::submit_hash_rate", "[rpc][txpool][miner]") { test::StrictMockAsyncResponseReader<::txpool::SubmitHashRateReply> reader; - EXPECT_CALL(*stub, AsyncSubmitHashRateRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncSubmitHashRateRaw).WillOnce(testing::Return(&reader)); SECTION("call submit_hash_rate and get result") { ::txpool::SubmitHashRateReply response; diff --git a/silkworm/rpc/txpool/transaction_pool_test.cpp b/silkworm/rpc/txpool/transaction_pool_test.cpp index a4ee46590c..fa7def7998 100644 --- a/silkworm/rpc/txpool/transaction_pool_test.cpp +++ b/silkworm/rpc/txpool/transaction_pool_test.cpp @@ -75,7 +75,7 @@ using TransactionPoolTest = test_util::GrpcApiTestBase reader; - EXPECT_CALL(*stub, AsyncAddRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncAddRaw).WillOnce(testing::Return(&reader)); const silkworm::Bytes tx_rlp{0x00, 0x01}; SECTION("call add_transaction and check import success") { @@ -117,7 +117,7 @@ TEST_CASE_METHOD(TransactionPoolTest, "TransactionPool::add_transaction", "[rpc] TEST_CASE_METHOD(TransactionPoolTest, "TransactionPool::get_transaction", "[rpc][txpool][transaction_pool]") { test::StrictMockAsyncResponseReader<::txpool::TransactionsReply> reader; - EXPECT_CALL(*stub, AsyncTransactionsRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncTransactionsRaw).WillOnce(testing::Return(&reader)); const auto tx_hash{0x3763e4f6e4198413383534c763f3f5dac5c5e939f0a81724e3beb96d6e2ad0d5_bytes32}; SECTION("call get_transaction and check success") { @@ -154,7 +154,7 @@ TEST_CASE_METHOD(TransactionPoolTest, "TransactionPool::get_transaction", "[rpc] TEST_CASE_METHOD(TransactionPoolTest, "TransactionPool::nonce", "[rpc][txpool][transaction_pool]") { test::StrictMockAsyncResponseReader<::txpool::NonceReply> reader; - EXPECT_CALL(*stub, AsyncNonceRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncNonceRaw).WillOnce(testing::Return(&reader)); const auto account{0x99f9b87991262f6ba471f09758cde1c0fc1de734_address}; SECTION("call nonce and check success") { @@ -191,7 +191,7 @@ TEST_CASE_METHOD(TransactionPoolTest, "TransactionPool::nonce", "[rpc][txpool][t TEST_CASE_METHOD(TransactionPoolTest, "TransactionPool::get_status", "[rpc][txpool][transaction_pool]") { test::StrictMockAsyncResponseReader<::txpool::StatusReply> reader; - EXPECT_CALL(*stub, AsyncStatusRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncStatusRaw).WillOnce(testing::Return(&reader)); SECTION("call get_status and check success") { ::txpool::StatusReply response; @@ -221,7 +221,7 @@ TEST_CASE_METHOD(TransactionPoolTest, "TransactionPool::get_status", "[rpc][txpo TEST_CASE_METHOD(TransactionPoolTest, "TransactionPool::get_transactions", "[rpc][txpool][transaction_pool]") { test::StrictMockAsyncResponseReader<::txpool::AllReply> reader; - EXPECT_CALL(*stub, AsyncAllRaw).WillOnce(testing::Return(&reader)); + EXPECT_CALL(*stub_, AsyncAllRaw).WillOnce(testing::Return(&reader)); SECTION("call get_transactions and check success [one tx]") { ::txpool::AllReply response;