Skip to content

Commit b6abd3e

Browse files
committed
Container kind validation tests
1 parent f3f028f commit b6abd3e

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/unittests/eof_validation_test.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -1213,3 +1213,59 @@ TEST_F(eof_validation, max_nested_containers)
12131213

12141214
add_test_case(code, EOFValidationError::success);
12151215
}
1216+
1217+
TEST_F(eof_validation, toplevel_container_stop)
1218+
{
1219+
const auto code = bytecode{OP_STOP};
1220+
const auto container = eof_bytecode(code, 0);
1221+
1222+
add_test_case(container, EOFValidationError::success);
1223+
}
1224+
1225+
TEST_F(eof_validation, eofcreate_initcontainer_stop)
1226+
{
1227+
const auto init_code = bytecode{OP_STOP};
1228+
const auto init_container = eof_bytecode(init_code, 0);
1229+
const auto factory_code = eofcreate() + OP_STOP;
1230+
const bytecode factory_container = eof_bytecode(factory_code, 4).container(init_container);
1231+
1232+
add_test_case(factory_container, EOFValidationError::incompatible_container_kind);
1233+
}
1234+
1235+
TEST_F(eof_validation, toplevel_container_return)
1236+
{
1237+
const auto code = ret(0, 0);
1238+
const bytecode container = eof_bytecode(code, 2);
1239+
1240+
add_test_case(container, EOFValidationError::success);
1241+
}
1242+
1243+
TEST_F(eof_validation, eofcreate_initcontainer_return)
1244+
{
1245+
const auto init_code = bytecode{ret(0, 0)};
1246+
const auto init_container = eof_bytecode(init_code, 2);
1247+
const auto factory_code = eofcreate() + OP_STOP;
1248+
const bytecode factory_container = eof_bytecode(factory_code, 4).container(init_container);
1249+
1250+
add_test_case(factory_container, EOFValidationError::incompatible_container_kind);
1251+
}
1252+
1253+
TEST_F(eof_validation, toplevel_container_returncontract)
1254+
{
1255+
const auto code = returncontract(0, 0, 0);
1256+
const auto container = eof_bytecode(code, 2).container(eof_bytecode(OP_INVALID));
1257+
1258+
add_test_case(container, EOFValidationError::success);
1259+
}
1260+
1261+
TEST_F(eof_validation, eofcreate_runtime_container_returncontract)
1262+
{
1263+
const auto runtime_container =
1264+
eof_bytecode(returncontract(0, 0, 0), 2).container(eof_bytecode(OP_INVALID));
1265+
const auto init_container =
1266+
eof_bytecode(returncontract(0, 0, 0), 2).container(runtime_container);
1267+
const auto factory_code = eofcreate() + OP_STOP;
1268+
const bytecode factory_container = eof_bytecode(factory_code, 4).container(init_container);
1269+
1270+
add_test_case(factory_container, EOFValidationError::incompatible_container_kind);
1271+
}

0 commit comments

Comments
 (0)