Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eoftest to run all tests from a JSON file #935

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions test/eoftest/eoftest_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct EOFValidationTest
ContainerKind kind = ContainerKind::runtime;
std::vector<Expectation> expectations;
};
std::string name;
std::unordered_map<std::string, Case> cases;
};

Expand Down Expand Up @@ -66,27 +67,43 @@ void from_json(const json::json& j, EOFValidationTest& o)
if (!j.is_object() || j.empty())
throw std::invalid_argument{"JSON test must be an object with single key of the test name"};

const auto& j_t = *j.begin(); // Content is in a dict with the test name.

for (const auto& [name, test] : j_t.at("vectors").items())
for (const auto& [name, test] : j.at("vectors").items())
{
o.cases.emplace(name, test.get<EOFValidationTest::Case>());
}
}

void from_json(const json::json& j, std::vector<EOFValidationTest>& o)
{
for (const auto& elem_it : j.items())
{
auto test = elem_it.value().get<EOFValidationTest>();
test.name = elem_it.key();
o.emplace_back(std::move(test));
}
}

std::vector<EOFValidationTest> load_eof_tests(std::istream& input)
{
return json::json::parse(input).get<std::vector<EOFValidationTest>>();
}

} // namespace

void run_eof_test(std::istream& input)
{
const auto test = json::json::parse(input).get<EOFValidationTest>();
for (const auto& [name, cases] : test.cases)
const auto tests = evmone::test::load_eof_tests(input);
for (const auto& test : tests)
{
for (const auto& expectation : cases.expectations)
for (const auto& [name, cases] : test.cases)
{
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);
for (const auto& expectation : cases.expectations)
{
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);
}
}
}
}
Expand Down