diff --git a/test/eoftest/eoftest_runner.cpp b/test/eoftest/eoftest_runner.cpp index dab423402c..56e202c298 100644 --- a/test/eoftest/eoftest_runner.cpp +++ b/test/eoftest/eoftest_runner.cpp @@ -22,16 +22,29 @@ struct EOFValidationTest { struct Expectation { - evmc_revision rev; - bool result; + evmc_revision rev = EVMC_PRAGUE; + bool result = false; }; std::string name; evmc::bytes code; + ContainerKind kind = ContainerKind::runtime; std::vector expectations; }; std::unordered_map cases; }; +ContainerKind container_kind_from_string(std::string_view s) +{ + if (s == "runtime") + return ContainerKind::runtime; + else if (s == "initcode") + return ContainerKind::initcode; + else if (s == "initcode_runtime") + return ContainerKind::initcode_runtime; + else + throw std::invalid_argument{"unknown container kind"}; +} + void from_json(const json::json& j, EOFValidationTest::Case& o) { const auto op_code = evmc::from_hex(j.at("code").get()); @@ -39,6 +52,9 @@ void from_json(const json::json& j, EOFValidationTest::Case& o) throw std::invalid_argument{"code is invalid hex string"}; o.code = *op_code; + if (const auto it_kind = j.find("kind"); it_kind != j.end()) + o.kind = container_kind_from_string(it_kind->get()); + for (const auto& [rev, result] : j.at("results").items()) { o.expectations.push_back({to_rev(rev), result.at("result").get()}); @@ -67,9 +83,7 @@ void run_eof_test(std::istream& input) { for (const auto& expectation : cases.expectations) { - // TODO read requested container kind from the test - const auto result = - evmone::validate_eof(expectation.rev, ContainerKind::runtime, cases.code); + const auto result = evmone::validate_eof(expectation.rev, cases.kind, cases.code); const bool b_result = (result == EOFValidationError::success); EXPECT_EQ(b_result, expectation.result) << name << " " << expectation.rev << " " << hex(cases.code); diff --git a/test/unittests/eof_validation.cpp b/test/unittests/eof_validation.cpp index 47f52b22a2..12280a23c0 100644 --- a/test/unittests/eof_validation.cpp +++ b/test/unittests/eof_validation.cpp @@ -96,6 +96,21 @@ std::string_view get_tests_error_message(EOFValidationError err) noexcept } return ""; } + +std::string_view to_string(ContainerKind container_kind) noexcept +{ + switch (container_kind) + { + case (ContainerKind::runtime): + return "runtime"; + case (ContainerKind::initcode): + return "initcode"; + case (ContainerKind::initcode_runtime): + return "initcode_runtime"; + } + return ""; +} + } // namespace void eof_validation::TearDown() @@ -127,6 +142,7 @@ void eof_validation::export_eof_validation_test() auto& jcase = jvectors[case_name]; jcase["code"] = hex0x(test_case.container); + jcase["kind"] = to_string(test_case.kind); auto& jresults = jcase["results"][evmc::to_string(rev)]; if (test_case.error == EOFValidationError::success)