Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c28ed2a

Browse files
committed
Add tests for ConstantEvaluator
1 parent b8e9046 commit c28ed2a

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

test/libsolidity/SolidityNameAndTypeResolution.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7102,7 +7102,7 @@ BOOST_AUTO_TEST_CASE(address_overload_resolution)
71027102
CHECK_SUCCESS(text);
71037103
}
71047104

7105-
BOOST_AUTO_TEST_CASE(array_length_validation)
7105+
BOOST_AUTO_TEST_CASE(array_length_too_large)
71067106
{
71077107
char const* text = R"(
71087108
contract C {
@@ -7112,6 +7112,44 @@ BOOST_AUTO_TEST_CASE(array_length_validation)
71127112
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
71137113
}
71147114

7115+
BOOST_AUTO_TEST_CASE(array_length_not_convertible_to_integer)
7116+
{
7117+
char const* text = R"(
7118+
contract C {
7119+
uint[true] ids;
7120+
}
7121+
)";
7122+
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
7123+
}
7124+
7125+
BOOST_AUTO_TEST_CASE(array_length_invalid_expression)
7126+
{
7127+
char const* text = R"(
7128+
contract C {
7129+
uint[-true] ids;
7130+
}
7131+
)";
7132+
CHECK_ERROR(text, TypeError, "Invalid constant expression.");
7133+
text = R"(
7134+
contract C {
7135+
uint[true/1] ids;
7136+
}
7137+
)";
7138+
CHECK_ERROR(text, TypeError, "Invalid constant expression.");
7139+
text = R"(
7140+
contract C {
7141+
uint[1/true] ids;
7142+
}
7143+
)";
7144+
CHECK_ERROR(text, TypeError, "Invalid constant expression.");
7145+
text = R"(
7146+
contract C {
7147+
uint[1.111111E1111111111111] ids;
7148+
}
7149+
)";
7150+
CHECK_ERROR(text, TypeError, "Invalid literal value.");
7151+
}
7152+
71157153
BOOST_AUTO_TEST_CASE(no_address_members_on_contract)
71167154
{
71177155
char const* text = R"(

0 commit comments

Comments
 (0)