aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorLianaHus <liana@ethdev.com>2015-09-15 17:40:14 +0800
committerLianaHus <liana@ethdev.com>2015-09-15 17:40:14 +0800
commite21632555c1a9df86341d773af88bade4825d674 (patch)
tree8591d4424877865768734d59352576c0ff124460 /test/libsolidity/SolidityEndToEndTest.cpp
parentb7b16b153b7763237ebd8d5b4db8aad4f4b2f4f2 (diff)
downloaddexon-solidity-e21632555c1a9df86341d773af88bade4825d674.tar.gz
dexon-solidity-e21632555c1a9df86341d773af88bade4825d674.tar.zst
dexon-solidity-e21632555c1a9df86341d773af88bade4825d674.zip
added compile time check for out of bounds access for ordinary arrays
todo: check for dynamicaly sized arrays Conflicts: test/libsolidity/SolidityEndToEndTest.cpp
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp78
1 files changed, 52 insertions, 26 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 43a5043d..73b24664 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -1037,12 +1037,9 @@ BOOST_AUTO_TEST_CASE(array_accessor)
)";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("data(uint256)", 0) == encodeArgs(8));
- BOOST_CHECK(callContractFunction("data(uint256)", 8) == encodeArgs());
BOOST_CHECK(callContractFunction("dynamicData(uint256)", 2) == encodeArgs(8));
- BOOST_CHECK(callContractFunction("dynamicData(uint256)", 8) == encodeArgs());
BOOST_CHECK(callContractFunction("smallTypeData(uint256)", 1) == encodeArgs(22));
BOOST_CHECK(callContractFunction("smallTypeData(uint256)", 127) == encodeArgs(2));
- BOOST_CHECK(callContractFunction("smallTypeData(uint256)", 128) == encodeArgs());
BOOST_CHECK(callContractFunction("multiple_map(uint256,uint256,uint256)", 2, 1, 2) == encodeArgs(3));
}
@@ -1061,9 +1058,7 @@ BOOST_AUTO_TEST_CASE(accessors_mapping_for_array)
)";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("data(uint256,uint256)", 2, 2) == encodeArgs(8));
- BOOST_CHECK(callContractFunction("data(uint256, 256)", 2, 8) == encodeArgs());
BOOST_CHECK(callContractFunction("dynamicData(uint256,uint256)", 2, 2) == encodeArgs(8));
- BOOST_CHECK(callContractFunction("dynamicData(uint256,uint256)", 2, 8) == encodeArgs());
}
BOOST_AUTO_TEST_CASE(multiple_elementary_accessors)
@@ -1248,6 +1243,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_same_size)
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("bytesToBytes(bytes4)", "abcd") == encodeArgs("abcd"));
}
+
// fixed bytes to uint conversion tests
BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_size)
{
@@ -1300,6 +1296,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_greater_size)
BOOST_CHECK(callContractFunction("bytesToUint(bytes4)", string("abcd")) ==
encodeArgs(u256("0x61626364")));
}
+
// uint fixed bytes conversion tests
BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_size)
{
@@ -4180,21 +4177,21 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail)
BOOST_CHECK(callContractFunction("test()") == encodeArgs(2));
}
-BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund)
-{
- char const* sourceCode = R"(
- contract A {
- uint public test = 1;
- uint[3] arr;
- function A()
- {
- test = arr[5];
- ++test;
- }
- }
- )";
- BOOST_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "A").empty());
-}
+//BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund)
+//{
+// char const* sourceCode = R"(
+// contract A {
+// uint public test = 1;
+// uint[3] arr;
+// function A()
+// {
+// test = arr[5];
+// ++test;
+// }
+// }
+// )";
+// BOOST_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "A").empty());
+//}
BOOST_AUTO_TEST_CASE(positive_integers_to_signed)
{
@@ -5266,19 +5263,48 @@ BOOST_AUTO_TEST_CASE(array_out_of_bound_access)
{
char const* sourceCode = R"(
contract c {
- uint[4] data;
- function set(uint index) returns (bool) {
- data[index] = 2;
+ uint[2] dataArray;
+ function set5th() returns (bool) {
+ dataArray[5] = 2;
return true;
}
}
)";
-// compileAndRun(sourceCode, 0, "Test");
-// BOOST_CHECK(callContractFunction("set()", u256(7)) == encodeArgs(false));
-// BOOST_CHECK(callContractFunction("set()", u256(3)) == encodeArgs(true));
compileRequireThrow<CompilerError>(sourceCode);
}
+//BOOST_AUTO_TEST_CASE(dynamic_array_out_of_bound_access)
+//{
+// char const* sourceCode = R"(
+// contract c {
+// uint[] dataArrayDynamic;
+// function set5th() returns (bool) {
+// dataArrayDynamic.length = 2;
+// dataArrayDynamic[5] = 3;
+// return true;
+// }
+// }
+// )";
+// compileRequireThrow<CompilerError>(sourceCode);
+//}
+
+//BOOST_AUTO_TEST_CASE(bytes_out_of_bound_access)
+//{
+// char const* sourceCode = R"(
+// contract c {
+// bytes data;
+// function write() returns (uint) {
+// data.length = 3;
+// data[1] = 0x77;
+// data[2] = 0x14;
+
+// data[8] = 3;
+// }
+// }
+// )";
+// compileRequireThrow<CompilerError>(sourceCode);
+//}
+
BOOST_AUTO_TEST_SUITE_END()
}