Skip to content

Commit

Permalink
Export EOF validation unit tests to json EOFTests
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Feb 21, 2024
1 parent 5492627 commit 55f4e90
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 36 additions & 0 deletions test/unittests/eof_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// SPDX-License-Identifier: Apache-2.0

#include "eof_validation.hpp"
#include <test/statetest/statetest.hpp>
#include <fstream>

namespace fs = std::filesystem;

namespace evmone::test
{
Expand All @@ -15,5 +19,37 @@ void eof_validation::TearDown()
<< "test case " << i << " " << test_case.name << "\n"
<< hex(test_case.container);
}

if (!export_file_path.empty())
export_eof_validation_test();
}

void eof_validation::export_eof_validation_test()
{
json::json j;
auto& jt = j[export_test_name];

auto& jvectors = jt["vectors"];
for (size_t i = 0; i < test_cases.size(); ++i)
{
const auto& test_case = test_cases[i];
const auto case_name = test_case.name.empty() ?
(std::string{export_test_name} + "_" + std::to_string(i)) :
test_case.name;

auto& jcase = jvectors[case_name];
jcase["code"] = hex0x(test_case.container);

auto& jresults = jcase["results"][evmc::to_string(rev)];
if (test_case.error == EOFValidationError::success)
jresults["result"] = true;
else
{
jresults["result"] = false;
jresults["exception"] = get_error_message(test_case.error);
}
}

std::ofstream{export_file_path} << std::setw(2) << j;
}
} // namespace evmone::test
6 changes: 5 additions & 1 deletion test/unittests/eof_validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include "exportable_fixture.hpp"
#include <evmc/evmc.hpp>
#include <evmone/eof.hpp>
#include <evmone/evmone.h>
Expand All @@ -16,7 +17,7 @@ using evmc::bytes;
/// Fixture for defining test cases for EOF validation.
///
/// Each test contains multiple cases, which are validated during test teardown.
class eof_validation : public testing::Test
class eof_validation : public ExportableFixture
{
protected:
/// EOF validation test case.
Expand Down Expand Up @@ -45,6 +46,9 @@ class eof_validation : public testing::Test

/// The test runner.
void TearDown() override;

/// Exports the test in the JSON EOF Test format in the given directory.
void export_eof_validation_test();
};

} // namespace evmone::test

0 comments on commit 55f4e90

Please sign in to comment.