Skip to content

Commit 1380198

Browse files
committed
Container kind validation tests
1 parent 65ca196 commit 1380198

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
@@ -1211,3 +1211,59 @@ TEST_F(eof_validation, max_nested_containers)
12111211

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

0 commit comments

Comments
 (0)