Skip to content

Commit

Permalink
uncomts tests for remote_storage_test
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 committed Oct 24, 2024
1 parent 943460d commit ff68c54
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions silkworm/db/chain/remote_chain_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@
#include <silkworm/db/tables.hpp>
#include <silkworm/db/test_util/mock_transaction.hpp>
#include <silkworm/infra/test_util/context_test_base.hpp>
#include <silkworm/rpc/ethdb/kv/backend_providers.hpp>
#include <silkworm/rpc/test_util/mock_back_end.hpp>

namespace silkworm::db::chain {

#ifdef notdef

using Catch::Matchers::Message;
using testing::_;
using testing::InvokeWithoutArgs;
Expand All @@ -53,23 +49,22 @@ static Bytes kChainConfig{*from_hex(
"30302c22697374616e62756c426c6f636b223a393036393030302c226c6f6e646f6e426c6f636b223a31323936353030302c226d75697"
"2476c6163696572426c6f636b223a393230303030302c2270657465727362757267426c6f636b223a373238303030307d")};

chain::BlockProvider block_provider{
[](BlockNum, HashAsSpan, bool, Block&) -> Task<bool> { co_return false; }};
chain::BlockNumberFromTxnHashProvider block_number_from_txn_hash_provider{
[](HashAsSpan) -> Task<BlockNum> { co_return 0; }};
chain::BlockNumberFromBlockHashProvider block_number_from_block_hash_provider{
[](HashAsSpan) -> Task<BlockNum> { co_return 0; }};
chain::CanonicalBlockHashFromNumberProvider canonical_block_hash_from_number_provider{
[](BlockNum) -> Task<evmc::bytes32> { co_return kBlockHash; }};

struct RemoteChainStorageTest : public silkworm::test_util::ContextTestBase {
test_util::MockTransaction transaction;
RemoteChainStorage storage{transaction, Providers{}};
rpc::test::BackEndMock backend;
// RemoteChainStorage storage{transaction, rpc::ethdb::kv::make_backend_providers(&backend)};
RemoteChainStorage storage{transaction, {block_provider, block_number_from_txn_hash_provider, block_number_from_block_hash_provider, canonical_block_hash_from_number_provider}};
};

TEST_CASE_METHOD(RemoteChainStorageTest, "read_chain_config") {
SECTION("empty chain data") {
EXPECT_CALL(backend, get_block_hash_from_block_number(_))
.WillOnce(InvokeWithoutArgs([]() -> Task<evmc::bytes32> {
co_return kBlockHash;
}));

EXPECT_CALL(transaction, get_one(table::kCanonicalHashesName, _)).WillOnce(InvokeWithoutArgs([]() -> Task<Bytes> {
co_return kBlockHash;
}));
EXPECT_CALL(transaction, get_one(table::kConfigName, _)).WillOnce(InvokeWithoutArgs([]() -> Task<Bytes> {
co_return Bytes{};
}));
Expand All @@ -81,21 +76,13 @@ TEST_CASE_METHOD(RemoteChainStorageTest, "read_chain_config") {
}

SECTION("invalid JSON chain data") {
EXPECT_CALL(backend, get_block_hash_from_block_number(_))
.WillOnce(InvokeWithoutArgs([]() -> Task<evmc::bytes32> {
co_return kBlockHash;
}));
EXPECT_CALL(transaction, get_one(table::kConfigName, _)).WillOnce(InvokeWithoutArgs([]() -> Task<Bytes> {
co_return kInvalidJsonChainConfig;
}));
CHECK_THROWS_AS(spawn_and_wait(storage.read_chain_config()), nlohmann::json::parse_error);
}

SECTION("valid JSON chain data") {
EXPECT_CALL(backend, get_block_hash_from_block_number(_))
.WillOnce(InvokeWithoutArgs([]() -> Task<evmc::bytes32> {
co_return kBlockHash;
}));
EXPECT_CALL(transaction, get_one(table::kConfigName, _)).WillOnce(InvokeWithoutArgs([]() -> Task<Bytes> {
co_return kChainConfig;
}));
Expand All @@ -119,6 +106,5 @@ TEST_CASE_METHOD(RemoteChainStorageTest, "read_chain_config") {
})"_json);
}
}
#endif

} // namespace silkworm::db::chain

0 comments on commit ff68c54

Please sign in to comment.