mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Struct types.
This commit is contained in:
parent
9f64159620
commit
558d0999c8
@ -663,6 +663,43 @@ BOOST_AUTO_TEST_CASE(multi_level_mapping)
|
||||
testSolidityAgainstCpp(0, f, u256(5), u256(4), u256(0));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(structs)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" struct s1 {\n"
|
||||
" uint8 x;\n"
|
||||
" bool y;\n"
|
||||
" }\n"
|
||||
" struct s2 {\n"
|
||||
" uint32 z;\n"
|
||||
" s1 s1data;\n"
|
||||
" mapping(uint8 => s2) recursive;\n"
|
||||
" }\n"
|
||||
" s2 data;\n"
|
||||
" function check() returns (bool ok) {\n"
|
||||
" return data.z == 1 && data.s1data.x == 2 && \n"
|
||||
" data.s1data.y == true && \n"
|
||||
" data.recursive[3].recursive[4].z == 5 && \n"
|
||||
" data.recursive[4].recursive[3].z == 6 && \n"
|
||||
" data.recursive[0].s1data.y == false && \n"
|
||||
" data.recursive[4].z == 9;\n"
|
||||
" }\n"
|
||||
" function set() {\n"
|
||||
" data.z = 1;\n"
|
||||
" data.s1data.x = 2;\n"
|
||||
" data.s1data.y = true;\n"
|
||||
" data.recursive[3].recursive[4].z = 5;\n"
|
||||
" data.recursive[4].recursive[3].z = 6;\n"
|
||||
" data.recursive[0].s1data.y = false;\n"
|
||||
" data.recursive[4].z = 9;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction(0) == bytes({0x00}));
|
||||
BOOST_CHECK(callContractFunction(1) == bytes());
|
||||
BOOST_CHECK(callContractFunction(0) == bytes({0x01}));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -121,6 +121,44 @@ BOOST_AUTO_TEST_CASE(reference_to_later_declaration)
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_definition_directly_recursive)
|
||||
{
|
||||
char const* text = "contract test {\n"
|
||||
" struct MyStructName {\n"
|
||||
" address addr;\n"
|
||||
" MyStructName x;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), ParserError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_definition_indirectly_recursive)
|
||||
{
|
||||
char const* text = "contract test {\n"
|
||||
" struct MyStructName1 {\n"
|
||||
" address addr;\n"
|
||||
" uint256 count;\n"
|
||||
" MyStructName2 x;\n"
|
||||
" }\n"
|
||||
" struct MyStructName2 {\n"
|
||||
" MyStructName1 x;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), ParserError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_definition_recursion_via_mapping)
|
||||
{
|
||||
char const* text = "contract test {\n"
|
||||
" struct MyStructName1 {\n"
|
||||
" address addr;\n"
|
||||
" uint256 count;\n"
|
||||
" mapping(uint => MyStructName1) x;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_inference_smoke_test)
|
||||
{
|
||||
char const* text = "contract test {\n"
|
||||
|
Loading…
Reference in New Issue
Block a user