Skip to content

Commit

Permalink
tests: Add BlockInfo loader test
Browse files Browse the repository at this point in the history
  • Loading branch information
rodiazet committed Mar 15, 2023
1 parent 6caacb6 commit f63f9cd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ target_sources(
state_mpt_test.cpp
state_new_account_address_test.cpp
state_rlp_test.cpp
statetest_loader_block_info_test.cpp
statetest_loader_test.cpp
statetest_loader_tx_test.cpp
statetest_logs_hash_test.cpp
Expand Down
55 changes: 55 additions & 0 deletions test/unittests/statetest_loader_block_info_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2023 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include <gtest/gtest.h>
#include <test/statetest/statetest.hpp>

using namespace evmone;

TEST(statetest_loader, block_info)
{
constexpr std::string_view input = R"({
"currentCoinbase": "0x1111111111111111111111111111111111111111",
"currentDifficulty": "0x0",
"currentGasLimit": "0x0",
"currentNumber": "0",
"currentTimestamp": "0",
"currentBaseFee": "7",
"currentRandom": "0x00",
"withdrawals": []
})";

const auto bi = test::from_json<state::BlockInfo>(json::json::parse(input));
EXPECT_EQ(bi.coinbase, 0x1111111111111111111111111111111111111111_address);
EXPECT_EQ(
bi.prev_randao, 0x0000000000000000000000000000000000000000000000000000000000000000_bytes32);
EXPECT_EQ(bi.gas_limit, 0x0);
EXPECT_EQ(bi.base_fee, 7);
EXPECT_EQ(bi.timestamp, 0);
EXPECT_EQ(bi.number, 0);
}

// TODO: Enable this test when this case will be properly handled.
TEST(DISABLED_statetest_loader, block_info_0_random)
{
constexpr std::string_view input = R"({
"currentCoinbase": "0x1111111111111111111111111111111111111111",
"currentDifficulty": "0x0",
"currentGasLimit": "0x0",
"currentNumber": "0",
"currentTimestamp": "0",
"currentBaseFee": "7",
"currentRandom": "0",
"withdrawals": []
})";

const auto bi = test::from_json<state::BlockInfo>(json::json::parse(input));
EXPECT_EQ(bi.coinbase, 0x1111111111111111111111111111111111111111_address);
EXPECT_EQ(
bi.prev_randao, 0x0000000000000000000000000000000000000000000000000000000000000000_bytes32);
EXPECT_EQ(bi.gas_limit, 0x0);
EXPECT_EQ(bi.base_fee, 7);
EXPECT_EQ(bi.timestamp, 0);
EXPECT_EQ(bi.number, 0);
}

0 comments on commit f63f9cd

Please sign in to comment.