Skip to content

Commit

Permalink
Tests for validation of terminating instruction in EOF code
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Oct 11, 2021
1 parent ed825f4 commit a73f066
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/unittests/eof_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,29 @@ TEST(eof_validation, EOF1_truncated_push)
EXPECT_EQ(validate_eof(container), EOFValidationErrror::success) << hex(container);
}
}

TEST(eof_validation, EOF1_terminating_instructions)
{
auto eof_header = from_hex("EF0001 010001 00");
auto& code_size_byte = eof_header[5];

const auto& traits = evmone::instr::traits;

for (uint16_t opcode = 0; opcode <= 0xff; ++opcode)
{
const auto& op_traits = traits[opcode];
// Skip undefined opcodes.
if (op_traits.name == nullptr)
continue;

bytes code{static_cast<uint8_t>(opcode) + bytes(op_traits.immediate_size, 0)};
code_size_byte = static_cast<uint8_t>(code.size());
const auto container = eof_header + code;

const auto expected = ((opcode == OP_STOP || opcode == OP_RETURN || opcode == OP_INVALID ||
opcode == OP_REVERT) ?
EOFValidationErrror::success :
EOFValidationErrror::missing_terminating_instruction);
EXPECT_EQ(validate_eof(container), expected) << hex(code);
}
}

0 comments on commit a73f066

Please sign in to comment.