Skip to content

Commit

Permalink
Merge pull request #659 from ethereum/read-valid-eof1-header-fix
Browse files Browse the repository at this point in the history
Fix and improve eof.read_valid_eof1_header test
  • Loading branch information
gumb0 authored Jun 1, 2023
2 parents 8fa360b + e401347 commit 6e2a589
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions test/unittests/eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,41 @@ TEST(eof, read_valid_eof1_header)
{
std::string code;
uint16_t types_size;
uint16_t code_size;
uint16_t data_size;
std::vector<uint16_t> code_sizes;
};
std::string nops_255;
for (int i = 0; i < 255; ++i)
nops_255 += "5B";

std::string section_size_1_256;
for (int i = 0; i < 256; ++i)
section_size_1_256 += "0001";

const TestCase test_cases[] = {
{"EF00 01 010004 0200010001 030000 00 00000000 00", 4, 1, 0},
{"EF00 01 010004 0200010006 030000 00 00000400 600160005500", 4, 6, 0},
{"EF00 01 010004 0200010001 030001 00 00000000 00 00 AA", 4, 1, 1},
{"EF00 01 010004 0200010006 030004 00 00000000 600160005500 AABBCCDD", 4, 6, 4},
{"EF00 01 010004 0200010100 031000 00 00000000" + std::string(256, '0') +
std::string(4096, 'F'),
4, 256, 4096},
{"EF00 01 010004 0200010001 030000 00 00000000 00", 4, 0, {1}},
{"EF00 01 010004 0200010006 030000 00 00000002 600160005500", 4, 0, {6}},
{"EF00 01 010004 0200010001 030001 00 00000000 00 AA", 4, 1, {1}},
{"EF00 01 010004 0200010006 030004 00 00000002 600160005500 AABBCCDD", 4, 4, {6}},
{"EF00 01 01000C 020003000100020003 030000 00 000000000000000000000000 00 5B00 5B5B00", 12,
0, {1, 2, 3}},
{"EF00 01 01000C 020003000100020003 030004 00 000000000000000000000000 00 5B00 5B5B00 "
"FFFFFFFF",
12, 4, {1, 2, 3}},
{"EF00 01 010004 0200010100 031000 00 00000000" + nops_255 + "00" + std::string(8192, 'F'),
4, 4096, {256}},
{"EF00 01 010400 020100" + section_size_1_256 + " 031000 00 " +
std::string(4 * 256 * 2, '0') + std::string(512, '0') + std::string(8192, 'F'),
4 * 256, 4096, std::vector<uint16_t>(256, 1)},
};

for (const auto& test_case : test_cases)
{
const auto code = from_spaced_hex(test_case.code).value();
EXPECT_EQ(validate_eof(EVMC_CANCUN, code), EOFValidationError::success) << test_case.code;

const auto header = read_valid_eof1_header(code);
EXPECT_EQ(header.code_sizes[0], test_case.code_size) << test_case.code;
EXPECT_EQ(header.code_sizes, test_case.code_sizes) << test_case.code;
EXPECT_EQ(header.data_size, test_case.data_size) << test_case.code;
EXPECT_EQ(header.types.size() * 4, test_case.types_size) << test_case.code;
}
Expand Down

0 comments on commit 6e2a589

Please sign in to comment.