Skip to content

Commit

Permalink
Migrate benchmarks to the JSON State Test format
Browse files Browse the repository at this point in the history
  • Loading branch information
miles170 committed Oct 21, 2022
1 parent 63a6f63 commit 0e16776
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

cmake_minimum_required(VERSION 3.16...3.23)

if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/evmc/.git)
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/evmc/.git OR NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/benchmarks/.git)
message(FATAL_ERROR "Git submodules not initialized, execute:\n git submodule update --init")
endif()

Expand Down
8 changes: 7 additions & 1 deletion test/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <fstream>
#include <iostream>
#include <span>
#include <string>

namespace fs = std::filesystem;

Expand Down Expand Up @@ -53,9 +54,14 @@ struct BenchmarkCase
std::vector<BenchmarkCase::Input> load_inputs(const StateTransitionTest& state_test)
{
std::vector<BenchmarkCase::Input> inputs;
const std::string input_name_prefix = ":label ";
for (size_t i = 0; i < state_test.multi_tx.inputs.size(); ++i)
{
const auto input_name = state_test.info.labels.at(i);
auto input_name = state_test.info.labels.at(i);
const auto prefix_pos = input_name.find_first_of(input_name_prefix);
if (prefix_pos != std::string::npos)
input_name = input_name.substr(prefix_pos + input_name_prefix.size());

const auto input = state_test.multi_tx.inputs[i];
bytes expected_output;

Expand Down
5 changes: 4 additions & 1 deletion test/statetest/statetest_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ static void from_json(const json::json& j, TestMultiTransaction& o)
o.max_gas_price = from_json<intx::uint256>(j.at("maxFeePerGas"));
o.max_priority_gas_price = from_json<intx::uint256>(j.at("maxPriorityFeePerGas"));
}
o.sender = from_json<evmc::address>(j.at("sender"));

if (j.contains("sender"))
o.sender = from_json<evmc::address>(j.at("sender"));

if (!j.at("to").get<std::string>().empty())
o.to = from_json<evmc::address>(j["to"]);

Expand Down

0 comments on commit 0e16776

Please sign in to comment.