Skip to content

Commit

Permalink
Container kind validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed May 13, 2024
1 parent 85d6e86 commit face250
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/unittests/eof_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,3 +1213,59 @@ TEST_F(eof_validation, max_nested_containers)

add_test_case(code, EOFValidationError::success);
}

TEST_F(eof_validation, toplevel_container_stop)
{
const auto code = bytecode{OP_STOP};
const auto container = eof_bytecode(code, 0);

add_test_case(container, EOFValidationError::success);
}

TEST_F(eof_validation, eofcreate_initcontainer_stop)
{
const auto init_code = bytecode{OP_STOP};
const auto init_container = eof_bytecode(init_code, 0);
const auto factory_code = eofcreate() + OP_STOP;
const bytecode factory_container = eof_bytecode(factory_code, 4).container(init_container);

add_test_case(factory_container, EOFValidationError::incompatible_container_kind);
}

TEST_F(eof_validation, toplevel_container_return)
{
const auto code = ret(0, 0);
const bytecode container = eof_bytecode(code, 2);

add_test_case(container, EOFValidationError::success);
}

TEST_F(eof_validation, eofcreate_initcontainer_return)
{
const auto init_code = bytecode{ret(0, 0)};
const auto init_container = eof_bytecode(init_code, 2);
const auto factory_code = eofcreate() + OP_STOP;
const bytecode factory_container = eof_bytecode(factory_code, 4).container(init_container);

add_test_case(factory_container, EOFValidationError::incompatible_container_kind);
}

TEST_F(eof_validation, toplevel_container_returncontract)
{
const auto code = returncontract(0, 0, 0);
const auto container = eof_bytecode(code, 2).container(eof_bytecode(OP_INVALID));

add_test_case(container, EOFValidationError::success);
}

TEST_F(eof_validation, eofcreate_runtime_container_returncontract)
{
const auto runtime_container =
eof_bytecode(returncontract(0, 0, 0), 2).container(eof_bytecode(OP_INVALID));
const auto init_container =
eof_bytecode(returncontract(0, 0, 0), 2).container(runtime_container);
const auto factory_code = eofcreate() + OP_STOP;
const bytecode factory_container = eof_bytecode(factory_code, 4).container(init_container);

add_test_case(factory_container, EOFValidationError::incompatible_container_kind);
}

0 comments on commit face250

Please sign in to comment.