Skip to content

Commit

Permalink
statetest: Move from_json<Transaction> implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Feb 8, 2023
1 parent 91e7175 commit 895f56f
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions test/statetest/statetest_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,37 @@ evmc_revision to_rev(std::string_view s)
throw std::invalid_argument{"unknown revision: " + std::string{s}};
}

template <>
state::Transaction from_json<state::Transaction>(const json::json& j)
{
state::Transaction o;
o.data = from_json<bytes>(j.at("input"));
o.gas_limit = from_json<int64_t>(j.at("gas"));
o.value = from_json<intx::uint256>(j.at("value"));
o.sender = from_json<evmc::address>(j.at("sender"));

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

if (j.contains("gasPrice"))
{
o.kind = state::Transaction::Kind::legacy;
o.max_gas_price = from_json<intx::uint256>(j.at("gasPrice"));
o.max_priority_gas_price = o.max_gas_price;
}
else
{
o.kind = state::Transaction::Kind::eip1559;
o.max_gas_price = from_json<intx::uint256>(j.at("maxFeePerGas"));
o.max_priority_gas_price = from_json<intx::uint256>(j.at("maxPriorityFeePerGas"));
}

if (j.contains("accessList"))
o.access_list = from_json<state::AccessList>(j.at("accessList"));

return o;
}

static void from_json(const json::json& j, TestMultiTransaction& o)
{
if (j.contains("gasPrice"))
Expand Down Expand Up @@ -255,37 +286,6 @@ static void from_json(const json::json& j, StateTransitionTest& o)
}
}

template <>
state::Transaction from_json<state::Transaction>(const json::json& j)
{
state::Transaction o;
o.data = from_json<bytes>(j.at("input"));
o.gas_limit = from_json<int64_t>(j.at("gas"));
o.value = from_json<intx::uint256>(j.at("value"));
o.sender = from_json<evmc::address>(j.at("sender"));

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

if (j.contains("gasPrice"))
{
o.kind = state::Transaction::Kind::legacy;
o.max_gas_price = from_json<intx::uint256>(j.at("gasPrice"));
o.max_priority_gas_price = o.max_gas_price;
}
else
{
o.kind = state::Transaction::Kind::eip1559;
o.max_gas_price = from_json<intx::uint256>(j.at("maxFeePerGas"));
o.max_priority_gas_price = from_json<intx::uint256>(j.at("maxPriorityFeePerGas"));
}

if (j.contains("accessList"))
o.access_list = from_json<state::AccessList>(j.at("accessList"));

return o;
}

StateTransitionTest load_state_test(const fs::path& test_file)
{
return json::json::parse(std::ifstream{test_file}).get<StateTransitionTest>();
Expand Down

0 comments on commit 895f56f

Please sign in to comment.