Skip to content

Commit

Permalink
Use standard error messages in EOF validation tests export
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Feb 21, 2024
1 parent d68b94e commit 2d775e2
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion test/unittests/eof_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,85 @@ namespace fs = std::filesystem;

namespace evmone::test
{
namespace
{
std::string_view get_tests_error_message(EOFValidationError err) noexcept
{
switch (err)
{
case EOFValidationError::success:
return "success";

Check warning on line 20 in test/unittests/eof_validation.cpp

View check run for this annotation

Codecov / codecov/patch

test/unittests/eof_validation.cpp#L19-L20

Added lines #L19 - L20 were not covered by tests
case EOFValidationError::invalid_prefix:
return "EOF_InvalidPrefix";
case EOFValidationError::eof_version_unknown:
return "EOF_UnknownVersion";
case EOFValidationError::incomplete_section_size:
return "EOF_IncompleteSectionSize";
case EOFValidationError::incomplete_section_number:
return "EOF_IncompleteSectionNumber";
case EOFValidationError::header_terminator_missing:
return "EOF_HeaderTerminatorMissing";
case EOFValidationError::type_section_missing:
return "EOF_TypeSectionMissing";
case EOFValidationError::code_section_missing:
return "EOF_CodeSectionMissing";
case EOFValidationError::data_section_missing:
return "EOF_DataSectionMissing";
case EOFValidationError::zero_section_size:
return "EOF_InvalidSectionSize";
case EOFValidationError::section_headers_not_terminated:
return "EOF_SectionHeadersNotTerminated";
case EOFValidationError::invalid_section_bodies_size:
return "EOF_InvalidSectionBodiesSize";
case EOFValidationError::unreachable_code_sections:
return "EOF_UnreachableCodeSections";
case EOFValidationError::undefined_instruction:
return "EOF_UndefinedInstruction";
case EOFValidationError::truncated_instruction:
return "EOF_TruncatedInstruction";
case EOFValidationError::invalid_rjump_destination:
return "EOF_InvalidJumpDestination";
case EOFValidationError::too_many_code_sections:
return "EOF_TooManyCodeSections";
case EOFValidationError::invalid_type_section_size:
return "EOF_InvalidTypeSectionSize";
case EOFValidationError::invalid_first_section_type:
return "EOF_InvalidFirstSectionType";
case EOFValidationError::invalid_max_stack_height:
return "EOF_InvalidMaxStackHeight";
case EOFValidationError::max_stack_height_above_limit:
return "EOF_MaxStackHeightExceeded";
case EOFValidationError::inputs_outputs_num_above_limit:
return "EOF_InputsOutputsAboveLimit";
case EOFValidationError::no_terminating_instruction:
return "EOF_InvalidCodeTermination";
case EOFValidationError::stack_height_mismatch:
return "EOF_ConflictingStackHeight";
case EOFValidationError::stack_higher_than_outputs_required:
return "EOF_InvalidNumberOfOutputs";
case EOFValidationError::unreachable_instructions:
return "EOF_UnreachableCode";
case EOFValidationError::stack_underflow:
return "EOF_StackUnderflow";
case EOFValidationError::stack_overflow:
return "EOF_StackOverflow";
case EOFValidationError::invalid_code_section_index:
return "EOF_InvalidCodeSectionIndex";
case EOFValidationError::invalid_dataloadn_index:
return "EOF_InvalidDataloadnIndex";
case EOFValidationError::jumpf_destination_incompatible_outputs:
return "EOF_JumpfDestinationIncompatibleOutputs";
case EOFValidationError::invalid_non_returning_flag:
return "EOF_InvalidNonReturningFlag";
case EOFValidationError::callf_to_non_returning_function:
return "EOF_CallfToNonReturning";
case EOFValidationError::impossible:
return "impossible";

Check warning on line 86 in test/unittests/eof_validation.cpp

View check run for this annotation

Codecov / codecov/patch

test/unittests/eof_validation.cpp#L85-L86

Added lines #L85 - L86 were not covered by tests
}
return "<unknown>";

Check warning on line 88 in test/unittests/eof_validation.cpp

View check run for this annotation

Codecov / codecov/patch

test/unittests/eof_validation.cpp#L88

Added line #L88 was not covered by tests
}
} // namespace

void eof_validation::TearDown()
{
for (size_t i = 0; i < test_cases.size(); ++i)
Expand Down Expand Up @@ -46,7 +125,7 @@ void eof_validation::export_eof_validation_test()
else
{
jresults["result"] = false;
jresults["exception"] = get_error_message(test_case.error);
jresults["exception"] = get_tests_error_message(test_case.error);
}
}

Expand Down

0 comments on commit 2d775e2

Please sign in to comment.