From 626a57826cd46c25f78cc5cf22e828b3a21b419c Mon Sep 17 00:00:00 2001 From: LianaHus Date: Tue, 25 Aug 2015 17:41:23 +0200 Subject: test --- test/libsolidity/SolidityEndToEndTest.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index c56845aa..43a5043d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5262,6 +5262,23 @@ BOOST_AUTO_TEST_CASE(library_stray_values) BOOST_CHECK(callContractFunction("f(uint256)", u256(33)) == encodeArgs(u256(42))); } +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; + return true; + } + } + )"; +// compileAndRun(sourceCode, 0, "Test"); +// BOOST_CHECK(callContractFunction("set()", u256(7)) == encodeArgs(false)); +// BOOST_CHECK(callContractFunction("set()", u256(3)) == encodeArgs(true)); + compileRequireThrow(sourceCode); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit From e21632555c1a9df86341d773af88bade4825d674 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Tue, 15 Sep 2015 11:40:14 +0200 Subject: added compile time check for out of bounds access for ordinary arrays todo: check for dynamicaly sized arrays Conflicts: test/libsolidity/SolidityEndToEndTest.cpp --- test/libsolidity/SolidityEndToEndTest.cpp | 78 ++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 26 deletions(-) (limited to 'test/libsolidity') 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(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(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(sourceCode); +//} + BOOST_AUTO_TEST_SUITE_END() } -- cgit From 7dbff2489f1f01d78690188bd0966af454999b26 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Tue, 8 Sep 2015 15:26:33 +0200 Subject: some fixes in tests --- test/libsolidity/SolidityEndToEndTest.cpp | 53 +++---------------------------- 1 file changed, 5 insertions(+), 48 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 73b24664..1ad57fb9 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1037,9 +1037,12 @@ 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)); } @@ -1058,7 +1061,9 @@ 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) @@ -4177,22 +4182,6 @@ 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(positive_integers_to_signed) { char const* sourceCode = R"( @@ -5273,38 +5262,6 @@ BOOST_AUTO_TEST_CASE(array_out_of_bound_access) compileRequireThrow(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(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(sourceCode); -//} - BOOST_AUTO_TEST_SUITE_END() } -- cgit From bc914641318a70dada6cd4c8223f95efeb919771 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Wed, 9 Sep 2015 17:15:23 +0200 Subject: - changed implementation - style fixes --- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 1ad57fb9..21e21018 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5259,7 +5259,7 @@ BOOST_AUTO_TEST_CASE(array_out_of_bound_access) } } )"; - compileRequireThrow(sourceCode); + compileRequireThrow(sourceCode); } BOOST_AUTO_TEST_SUITE_END() -- cgit From 466f5a4b88b4f317e8a4d9b5734fd938d4e01e80 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Thu, 10 Sep 2015 10:29:19 +0200 Subject: returned test for exceptions in constructor --- test/libsolidity/SolidityEndToEndTest.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 21e21018..8f94cba1 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -4182,6 +4182,23 @@ 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() + { + uint index = 5; + test = arr[index]; + ++test; + } + } + )"; + BOOST_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "A").empty()); +} + BOOST_AUTO_TEST_CASE(positive_integers_to_signed) { char const* sourceCode = R"( -- cgit From 9d44e659321cad4fe9955895d8487bf4a089ae92 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Tue, 15 Sep 2015 11:41:40 +0200 Subject: moved the test Conflicts: test/libsolidity/SolidityEndToEndTest.cpp test/libsolidity/SolidityNameAndTypeResolution.cpp --- test/libsolidity/SolidityEndToEndTest.cpp | 3 +++ test/libsolidity/SolidityNameAndTypeResolution.cpp | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8f94cba1..05508e2b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5233,6 +5233,7 @@ BOOST_AUTO_TEST_CASE(storage_string_as_mapping_key_without_variable) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(2))); } +<<<<<<< HEAD BOOST_AUTO_TEST_CASE(library_call) { char const* sourceCode = R"( @@ -5279,6 +5280,8 @@ BOOST_AUTO_TEST_CASE(array_out_of_bound_access) compileRequireThrow(sourceCode); } +======= +>>>>>>> 6920415... moved the test BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 5d174367..f671c5ec 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2250,10 +2250,23 @@ BOOST_AUTO_TEST_CASE(creating_contract_within_the_contract) function f() { var x = new Test(); } } )"; - BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(array_out_of_bound_access) +{ + char const* text = R"( + contract c { + uint[2] dataArray; + function set5th() returns (bool) { + dataArray[5] = 2; + return true; + } + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit From dbb36a7a7bc81d5397b5da316c9a7d89c76cc52b Mon Sep 17 00:00:00 2001 From: LianaHus Date: Tue, 15 Sep 2015 11:44:04 +0200 Subject: fixed rebase --- test/libsolidity/SolidityEndToEndTest.cpp | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 05508e2b..cac2d296 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5233,7 +5233,6 @@ BOOST_AUTO_TEST_CASE(storage_string_as_mapping_key_without_variable) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(2))); } -<<<<<<< HEAD BOOST_AUTO_TEST_CASE(library_call) { char const* sourceCode = R"( @@ -5266,22 +5265,6 @@ BOOST_AUTO_TEST_CASE(library_stray_values) BOOST_CHECK(callContractFunction("f(uint256)", u256(33)) == encodeArgs(u256(42))); } -BOOST_AUTO_TEST_CASE(array_out_of_bound_access) -{ - char const* sourceCode = R"( - contract c { - uint[2] dataArray; - function set5th() returns (bool) { - dataArray[5] = 2; - return true; - } - } - )"; - compileRequireThrow(sourceCode); -} - -======= ->>>>>>> 6920415... moved the test BOOST_AUTO_TEST_SUITE_END() } -- cgit From 152bc642a6e8025d7957898e25848c9c836eb462 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Tue, 15 Sep 2015 12:06:16 +0200 Subject: style fix --- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- test/libsolidity/SolidityNameAndTypeResolution.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index cac2d296..2ba6ab85 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -4195,7 +4195,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) ++test; } } - )"; + )"; BOOST_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "A").empty()); } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index f671c5ec..2a720494 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2256,13 +2256,13 @@ BOOST_AUTO_TEST_CASE(creating_contract_within_the_contract) BOOST_AUTO_TEST_CASE(array_out_of_bound_access) { char const* text = R"( - contract c { - uint[2] dataArray; - function set5th() returns (bool) { - dataArray[5] = 2; - return true; + contract c { + uint[2] dataArray; + function set5th() returns (bool) { + dataArray[5] = 2; + return true; + } } - } )"; BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); } -- cgit