From 403e9701fe0fdb3ee2de90b0361583952e071517 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Wed, 28 Dec 2022 21:17:41 +0100 Subject: [PATCH] test: Add basic test for RJUMPV --- test/unittests/evm_eof_test.cpp | 18 ++++++++++++++++++ test/utils/bytecode.hpp | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/test/unittests/evm_eof_test.cpp b/test/unittests/evm_eof_test.cpp index 599ba4105f..f733fc5123 100644 --- a/test/unittests/evm_eof_test.cpp +++ b/test/unittests/evm_eof_test.cpp @@ -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) { diff --git a/test/utils/bytecode.hpp b/test/utils/bytecode.hpp index c0d212d066..2a6cc441bd 100644 --- a/test/utils/bytecode.hpp +++ b/test/utils/bytecode.hpp @@ -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 offsets, bytecode condition) +{ + bytecode ret = condition + OP_RJUMPV + static_cast(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;