From 84e5b83c6f4fb327baabaa1b3f9781ff236eff38 Mon Sep 17 00:00:00 2001 From: kayan Date: Wed, 7 Jun 2023 15:40:40 +0800 Subject: [PATCH] fix unittests --- silkrpc/commands/engine_api.cpp | 2 +- silkrpc/core/rawdb/util_test.cpp | 16 ++++++++-------- silkrpc/core/state_reader_test.cpp | 6 +++--- silkrpc/json/types_test.cpp | 20 ++++++++++---------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/silkrpc/commands/engine_api.cpp b/silkrpc/commands/engine_api.cpp index 6e28538a..9e9f3170 100644 --- a/silkrpc/commands/engine_api.cpp +++ b/silkrpc/commands/engine_api.cpp @@ -103,7 +103,7 @@ boost::asio::awaitable EngineRpcApi::handle_engine_forkchoice_updated_v1(c #ifndef BUILD_COVERAGE try { #endif - auto zero_hash = 0_bytes32; + auto zero_hash = 00_bytes32; const ForkchoiceState forkchoice_state = params[0].get(); if (forkchoice_state.safe_block_hash == zero_hash) { diff --git a/silkrpc/core/rawdb/util_test.cpp b/silkrpc/core/rawdb/util_test.cpp index 0fb4fdcc..ece53c14 100644 --- a/silkrpc/core/rawdb/util_test.cpp +++ b/silkrpc/core/rawdb/util_test.cpp @@ -25,8 +25,8 @@ namespace silkrpc { using evmc::literals::operator""_address, evmc::literals::operator""_bytes32; TEST_CASE("all-zero composite key", "[silkrpc][core][rawdb][util]") { - auto zero_address = 0_address; - auto zero_hash = 0_bytes32; + auto zero_address = 00_address; + auto zero_hash = 00_bytes32; const auto ckey{composite_storage_key(zero_address, 0, zero_hash.bytes)}; CHECK(ckey == silkworm::Bytes(60, '\0')); @@ -34,7 +34,7 @@ TEST_CASE("all-zero composite key", "[silkrpc][core][rawdb][util]") { TEST_CASE("non-zero address composite key", "[silkrpc][core][rawdb][util]") { constexpr auto address = 0x79a4d418f7887dd4d5123a41b6c8c186686ae8cb_address; - auto zero_hash = 0_bytes32; + auto zero_hash = 00_bytes32; const auto ckey{composite_storage_key(address, 0, zero_hash.bytes)}; CHECK(ckey == silkworm::from_hex( @@ -45,8 +45,8 @@ TEST_CASE("non-zero address composite key", "[silkrpc][core][rawdb][util]") { } TEST_CASE("non-zero incarnation composite key", "[silkrpc][core][rawdb][util]") { - auto zero_address = 0_address; - auto zero_hash = 0_bytes32; + auto zero_address = 00_address; + auto zero_hash = 00_bytes32; const auto ckey{composite_storage_key(zero_address, 37, zero_hash.bytes)}; CHECK(ckey == silkworm::from_hex( @@ -57,7 +57,7 @@ TEST_CASE("non-zero incarnation composite key", "[silkrpc][core][rawdb][util]") } TEST_CASE("non-zero hash composite key", "[silkrpc][core][rawdb][util]") { - auto zero_address = 0_address; + auto zero_address = 00_address; constexpr auto hash = 0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6_bytes32; const auto ckey{composite_storage_key(zero_address, 0, hash.bytes)}; @@ -81,8 +81,8 @@ TEST_CASE("non-zero composite key", "[silkrpc][core][rawdb][util]") { } TEST_CASE("max incarnation composite key", "[silkrpc][core][rawdb][util]") { - auto zero_address = 0_address; - auto zero_hash = 0_bytes32; + auto zero_address = 00_address; + auto zero_hash = 00_bytes32; const auto ckey{composite_storage_key(zero_address, std::numeric_limits::max(), zero_hash.bytes)}; CHECK(ckey == silkworm::from_hex( diff --git a/silkrpc/core/state_reader_test.cpp b/silkrpc/core/state_reader_test.cpp index 1cc683af..66d3db2c 100644 --- a/silkrpc/core/state_reader_test.cpp +++ b/silkrpc/core/state_reader_test.cpp @@ -181,9 +181,9 @@ TEST_CASE_METHOD(StateReaderTest, "StateReader::read_storage") { EXPECT_CALL(database_reader_, get(db::table::kStorageHistory, _)).WillOnce(InvokeWithoutArgs( []() -> boost::asio::awaitable { co_return KeyValue{}; } )); - // 2. DatabaseReader::get_one call on kPlainState returns the storage location value - EXPECT_CALL(database_reader_, get_one(db::table::kPlainState, _)).WillOnce(InvokeWithoutArgs( - []() -> boost::asio::awaitable { co_return kStorageLocation; } + // 2. DatabaseReader::get_both_range call on kPlainState returns the storage location value + EXPECT_CALL(database_reader_, get_both_range(db::table::kPlainState, _, _)).WillOnce(InvokeWithoutArgs( + []() -> boost::asio::awaitable> { co_return kStorageLocation; } )); // Execute the test: calling read_storage should return expected storage location diff --git a/silkrpc/json/types_test.cpp b/silkrpc/json/types_test.cpp index 55b62904..e05ddfe5 100644 --- a/silkrpc/json/types_test.cpp +++ b/silkrpc/json/types_test.cpp @@ -148,7 +148,7 @@ TEST_CASE("serialize empty block header", "[silkrpc][to_json]") { R"(000000000000000000000000000000000000000000000000000000000000000000000000)" R"(000000000000000000000000000000000000000000000000000000000000000000000000)" R"(00000000000000000000000000000000000000000000000000000000000000000000000000000000", - "difficulty":"0x", + "difficulty":"0x0", "nonce":"0x0000000000000000", "number":"0x0", "gasLimit":"0x0", @@ -192,7 +192,7 @@ TEST_CASE("serialize block header", "[silkrpc][to_json]") { R"(000000000000000000000000000000000000000000000000000000000000000000000000)" R"(000000000000000000000000000000000000000000000000000000000000000000000000)" R"(00000000000000000000000000000000000000000000000000000000000000000000000000000000", - "difficulty":"0x", + "difficulty":"0x0", "number":"0x5", "gasLimit":"0xf4240", "gasUsed":"0xf4240", @@ -237,7 +237,7 @@ TEST_CASE("serialize block header with baseFeePerGas", "[silkrpc][to_json]") { R"(000000000000000000000000000000000000000000000000000000000000000000000000)" R"(000000000000000000000000000000000000000000000000000000000000000000000000)" R"(00000000000000000000000000000000000000000000000000000000000000000000000000000000", - "difficulty":"0x", + "difficulty":"0x0", "number":"0x5", "gasLimit":"0xf4240", "gasUsed":"0xf4240", @@ -329,7 +329,7 @@ TEST_CASE("serialize block with baseFeePerGas", "[silkrpc][to_json]") { R"(000000000000000000000000000000000000000000000000000000000000000000000000)" R"(000000000000000000000000000000000000000000000000000000000000000000000000)" R"(00000000000000000000000000000000000000000000000000000000000000000000000000000000", - "difficulty":"0x", + "difficulty":"0x0", "number":"0x5", "hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit":"0xf4240", @@ -340,7 +340,7 @@ TEST_CASE("serialize block with baseFeePerGas", "[silkrpc][to_json]") { "mixHash":"0x0000000000000000000000000000000000000000000000000000000000000001", "nonce":"0x00000000000000ff", "baseFeePerGas":"0x244428", - "totalDifficulty":"0x", + "totalDifficulty":"0x0", "transactions":[], "uncles":[] })"_json); @@ -363,7 +363,7 @@ TEST_CASE("serialize empty block", "[silkrpc][to_json]") { R"(000000000000000000000000000000000000000000000000000000000000000000000000)" R"(000000000000000000000000000000000000000000000000000000000000000000000000)" R"(00000000000000000000000000000000000000000000000000000000000000000000000000000000", - "difficulty":"0x", + "difficulty":"0x0", "nonce":"0x0000000000000000", "number":"0x0", "gasLimit":"0x0", @@ -373,7 +373,7 @@ TEST_CASE("serialize empty block", "[silkrpc][to_json]") { "mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000", "hash":"0x0000000000000000000000000000000000000000000000000000000000000000", "size":"0x1f5", - "totalDifficulty":"0x", + "totalDifficulty":"0x0", "transactions":[], "uncles":[] })"_json); @@ -426,7 +426,7 @@ TEST_CASE("serialize EIP-2718 block", "[silkrpc][to_json]") { "size":"0x31c", "stateRoot":"0xef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017", "timestamp":"0x5506eb07", - "totalDifficulty":"0x", + "totalDifficulty":"0x0", "transactions":[ "0x77b19baa4de67e45a7b26e4a220bccdbb6731885aa9927064e239ca232023215", "0x554af720acf477830f996f1bc5d11e54c38aa40042aeac6f66cb66f9084a959d" @@ -607,7 +607,7 @@ TEST_CASE("serialize block body with ommers", "[silkrpc][to_json]") { nlohmann::json rpc_block_json = rpc_block; CHECK(rpc_block_json == R"({ - "difficulty":"0x", + "difficulty":"0x0", "extraData":"0x", "gasLimit":"0x0", "gasUsed":"0x0", @@ -629,7 +629,7 @@ TEST_CASE("serialize block body with ommers", "[silkrpc][to_json]") { "size":"0x40c", "stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp":"0x0", - "totalDifficulty":"0x", + "totalDifficulty":"0x0", "transactions":[], "transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000", "uncles":["0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109"]