Skip to content

Commit

Permalink
test: Compare EVMC and evmone instruction tables
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 12, 2019
1 parent 70ec348 commit 867a4ec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ add_executable(evmone-unittests
analysis_test.cpp
bytecode_test.cpp
evmone_test.cpp
op_table_test.cpp
utils_test.cpp
vm_loader_evmone.cpp
)
target_link_libraries(evmone-unittests PRIVATE evm-unittests evmone testutils GTest::gtest GTest::gtest_main)
target_link_libraries(evmone-unittests PRIVATE evm-unittests evmone testutils evmc::instructions GTest::gtest GTest::gtest_main)
target_include_directories(evmone-unittests PRIVATE ${evmone_private_include_dir})

gtest_discover_tests(evmone-unittests TEST_PREFIX ${PROJECT_NAME}/unittests/)
Expand Down
30 changes: 30 additions & 0 deletions test/unittests/op_table_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2019 The evmone Authors.
// Licensed under the Apache License, Version 2.0.

#include <evmc/instructions.h>
#include <evmone/analysis.hpp>
#include <gtest/gtest.h>

TEST(op_table, compare_with_evmc_instruction_tables)
{
for (int r = EVMC_FRONTIER; r <= EVMC_MAX_REVISION; ++r)
{
const auto rev = static_cast<evmc_revision>(r);
const auto& evmone_tbl = evmone::get_op_table(rev);
const auto* evmc_tbl = evmc_get_instruction_metrics_table(rev);

for (size_t i = 0; i < evmone_tbl.size(); ++i)
{
const auto& metrics = evmone_tbl[i];
const auto& ref_metrics = evmc_tbl[i];

// Compare gas costs. Normalize -1 values in EVMC for undefined instructions.
EXPECT_EQ(metrics.gas_cost, std::max(ref_metrics.gas_cost, int16_t{0}));

EXPECT_EQ(metrics.stack_req, ref_metrics.num_stack_arguments);
EXPECT_EQ(metrics.stack_change,
ref_metrics.num_stack_returned_items - ref_metrics.num_stack_arguments);
}
}
}

0 comments on commit 867a4ec

Please sign in to comment.