From 90f461f334eb8d42b3e25670d79e93472e8e6899 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Mon, 7 Aug 2023 15:45:48 +0200 Subject: [PATCH] Add tests for JUMPF outputs compatibility --- test/unittests/eof_validation_test.cpp | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/unittests/eof_validation_test.cpp b/test/unittests/eof_validation_test.cpp index ead35a669b..23f640c849 100644 --- a/test/unittests/eof_validation_test.cpp +++ b/test/unittests/eof_validation_test.cpp @@ -877,6 +877,33 @@ TEST(eof_validation, non_returning_status) EOFValidationError::invalid_non_returning_flag); } +TEST(eof_validation, jumpf_equal_outputs) +{ + const auto code = + bytecode{"ef0001 01000c 020003 0004 0003 0004 040000 00 00800003 00030000 00030003"_hex} + + OP_CALLF + "0001" + OP_STOP + OP_JUMPF + "0002" + 3 * OP_PUSH0 + OP_RETF; + + EXPECT_EQ(validate_eof(code), EOFValidationError::success); +} + +TEST(eof_validation, jumpf_compatible_outputs) +{ + const auto code = + bytecode{"ef0001 01000c 020003 0004 0005 0004 040000 00 00800005 00050002 00030003"_hex} + + OP_CALLF + "0001" + OP_STOP + 2 * OP_PUSH0 + OP_JUMPF + "0002" + 3 * OP_PUSH0 + OP_RETF; + + EXPECT_EQ(validate_eof(code), EOFValidationError::success); +} + +TEST(eof_validation, jumpf_incompatible_outputs) +{ + const auto code = + bytecode{"ef0001 01000c 020003 0004 0005 0004 040000 00 00800003 00030002 00050003"_hex} + + OP_CALLF + "0001" + OP_STOP + OP_JUMPF + "0002" + 5 * OP_PUSH0 + OP_RETF; + + EXPECT_EQ(validate_eof(code), EOFValidationError::jumpf_destination_incompatible_outputs); +} + TEST(eof_validation, jumpf_into_nonreturning_stack_validation) { // Exactly required inputs on stack at JUMPF