Skip to content

Commit

Permalink
Add tests for JUMPF
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jul 25, 2023
1 parent f566571 commit 68d6777
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions test/unittests/evm_eof_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,62 @@ TEST_P(evm, callf_call_stack_size_1025)
execute(bytecode{code});
EXPECT_STATUS(EVMC_STACK_OVERFLOW);
}

TEST_P(evm, minimal_jumpf)
{
// JUMPF is not implemented in Advanced.
if (is_advanced())
return;

rev = EVMC_CANCUN;
const auto code = bytecode{"ef0001 010008 020002 0003 0001 030000 00 00000000 00000000"_hex} +
OP_JUMPF + "0001" + OP_STOP;

ASSERT_EQ(evmone::validate_eof(rev, code), evmone::EOFValidationError::success);
execute(bytecode{code});
EXPECT_STATUS(EVMC_SUCCESS);
}

TEST_P(evm, jumpf_to_returning_function)
{
// JUMPF is not implemented in Advanced.
if (is_advanced())
return;

rev = EVMC_CANCUN;
const auto code =
bytecode{"ef0001 01000c 020003 0009 0005 0004 030000 00 00000002 00010001 01010002"_hex} +
// function 0
OP_CALLF + "0001" + OP_PUSH0 + OP_MSTORE + OP_PUSH1 + "20" + OP_PUSH0 + OP_RETURN +
// function 1 - 1 output
OP_PUSH1 + "01" + OP_JUMPF + "0002" +
// function 2 - 1 output
OP_PUSH1 + "02" + OP_ADD + OP_RETF;

ASSERT_EQ(evmone::validate_eof(rev, code), evmone::EOFValidationError::success);
execute(bytecode{code});
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_OUTPUT_INT(3);
}

TEST_P(evm, jumpf_to_function_with_fewer_outputs)
{
// JUMPF is not implemented in Advanced.
if (is_advanced())
return;

rev = EVMC_CANCUN;
const auto code =
bytecode{"ef0001 01000c 020003 0009 0007 0004 030000 00 00000003 00020002 01010002"_hex} +
// function 0
OP_CALLF + "0001" + OP_PUSH0 + OP_MSTORE + OP_PUSH1 + "20" + OP_PUSH0 + OP_RETURN +
// function 1 - 2 outputs
OP_PUSH1 + "ff" + OP_PUSH1 + "01" + OP_JUMPF + "0002" +
// function 2 - 1 output
OP_PUSH1 + "02" + OP_ADD + OP_RETF;

ASSERT_EQ(evmone::validate_eof(rev, code), evmone::EOFValidationError::success);
execute(bytecode{code});
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_OUTPUT_INT(3);
}

0 comments on commit 68d6777

Please sign in to comment.