Skip to content

Commit

Permalink
test: Add basic test for RJUMPV
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Dec 28, 2022
1 parent 79baead commit 403e970
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/unittests/evm_eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,24 @@ TEST_P(evm, eof2_rjumpi_0_offset)
EXPECT_EQ(result.output_data[0], 1);
}

TEST_P(evm, eof1_rjumpv_single_offset)
{
// Relative jumps are not implemented in Advanced.
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
auto code = eof1_bytecode(rjumpv({3}, 0) + OP_JUMPDEST + OP_JUMPDEST + OP_STOP + 20 + 40 + 0 +
OP_CODECOPY + ret(0, 20),
3, "ef000101000402000100010300000000000000fe");

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
ASSERT_EQ(result.output_size, 20);
EXPECT_EQ(bytes_view(result.output_data, result.output_size),
"ef000101000402000100010300000000000000fe"_hex);
}


TEST_P(evm, relative_jumps_undefined_in_legacy)
{
Expand Down
8 changes: 8 additions & 0 deletions test/utils/bytecode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ inline bytecode rjumpi(int16_t offset, bytecode condition)
return condition + OP_RJUMPI + bytecode{big_endian(offset)};
}

inline bytecode rjumpv(const std::initializer_list<uint16_t> offsets, bytecode condition)
{
bytecode ret = condition + OP_RJUMPV + static_cast<Opcode>(offsets.size());
for (const auto offset : offsets)
ret += bytecode{big_endian(offset)};
return ret;
}

inline bytecode ret(bytecode index, bytecode size)
{
return size + index + OP_RETURN;
Expand Down

0 comments on commit 403e970

Please sign in to comment.