From 8967476a8d5371e81e224ec284fb9100816242c7 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 15 May 2015 12:23:13 +0200 Subject: added error jump instead of STOP instraction in case of exception --- libsolidity/SolidityEndToEndTest.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 503615a5..f8d20d70 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -1784,6 +1784,7 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) } )"; compileAndRun(sourceCode, 20); + auto res = callContractFunction("getBalance()"); BOOST_REQUIRE(callContractFunction("getBalance()") == encodeArgs(u256(20 - 5), u256(5))); } -- cgit v1.2.3 From 042491e0ccae9600b6d513c9e9023d35c9184feb Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Tue, 19 May 2015 14:55:12 +0200 Subject: added test to check evm exception --- libsolidity/SolidityEndToEndTest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index f8d20d70..faa5dad4 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4111,6 +4111,30 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) BOOST_CHECK(callContractFunction("deleteIt()") == encodeArgs(0)); } +BOOST_AUTO_TEST_CASE(evm_exceptions) +{ + char const* sourceCode = R"( + contract A { + uint[3] arr; + bool public test = false; + function getElement(uint i) returns (uint) + { + return arr[i]; + } + function testIt() returns (bool) + { + uint i = this.getElement(5); + test = true; + return true; + } + } + )"; + compileAndRun(sourceCode, 0, "A"); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(false)); + BOOST_CHECK(callContractFunction("testIt()") == encodeArgs()); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(false)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 4a2f18b41a9977045a7bd5e859f96715e7f27e84 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 21 May 2015 12:10:26 +0200 Subject: one more test to test the call of non-existed function Conflicts: test/libsolidity/SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index faa5dad4..839ad792 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4111,7 +4111,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) BOOST_CHECK(callContractFunction("deleteIt()") == encodeArgs(0)); } -BOOST_AUTO_TEST_CASE(evm_exceptions) +BOOST_AUTO_TEST_CASE(evm_exceptions_out_of_band_access) { char const* sourceCode = R"( contract A { @@ -4135,6 +4135,32 @@ BOOST_AUTO_TEST_CASE(evm_exceptions) BOOST_CHECK(callContractFunction("test()") == encodeArgs(false)); } +BOOST_AUTO_TEST_CASE(evm_exceptions_when_calling_non_existing_function) +{ + char const* sourceCode = R"( + contract A { + uint public test = 0; + function badFunction() returns (uint) + { + this.call("123"); + test = 1; + return 2; + } + function testIt() returns (bool) + { + this.badFunction(); + test = 2; + return true; + } + } + )"; + compileAndRun(sourceCode, 0, "A"); + + BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); + BOOST_CHECK(callContractFunction("testIt()") == encodeArgs()); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 82dc10d492d74fc1a9e07549f39d5ef2230822cc Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 21 May 2015 13:02:24 +0200 Subject: test for exception in constructor --- libsolidity/SolidityEndToEndTest.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 839ad792..76952c67 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4161,6 +4161,23 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_when_calling_non_existing_function) BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); } +BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor) +{ + char const* sourceCode = R"( + contract A { + uint public test = 0; + function A() + { + this.call("123"); + test = 1; + } + } + )"; + compileAndRun(sourceCode, 0, "A"); + + BOOST_CHECK(callContractFunction("test()") == encodeArgs(1)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From f1c042df8c66f13ba102bdfae03337c45173a248 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 21 May 2015 13:45:32 +0200 Subject: test for constructor (out of band exception) --- libsolidity/SolidityEndToEndTest.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 76952c67..c150a488 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4161,7 +4161,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_when_calling_non_existing_function) BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); } -BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor) +BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) { char const* sourceCode = R"( contract A { @@ -4169,7 +4169,25 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor) function A() { this.call("123"); - test = 1; + ++test; + } + } + )"; + compileAndRun(sourceCode, 0, "A"); + + BOOST_CHECK(callContractFunction("test()") == encodeArgs(1)); +} + +BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_band) +{ + char const* sourceCode = R"( + contract A { + uint public test = 0; + uint[3] arr; + function A() + { + test = arr[5]; + ++test; } } )"; -- cgit v1.2.3 From fde4ed6bf60180d6212ec81f9ecbf630377087b3 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 22 May 2015 14:07:05 +0200 Subject: remove line for debugging --- libsolidity/SolidityEndToEndTest.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index c150a488..e4c5b47f 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -1784,7 +1784,6 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) } )"; compileAndRun(sourceCode, 20); - auto res = callContractFunction("getBalance()"); BOOST_REQUIRE(callContractFunction("getBalance()") == encodeArgs(u256(20 - 5), u256(5))); } -- cgit v1.2.3 From 19fb836bf6440db32c8a392618bb76d44ec90953 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 22 May 2015 17:48:38 +0200 Subject: modified the test --- libsolidity/SolidityEndToEndTest.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index e4c5b47f..538174ab 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4164,24 +4164,32 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) { char const* sourceCode = R"( contract A { - uint public test = 0; function A() { this.call("123"); + + } + } + contract B { + uint public test = 1; + function testIt() + { + A a; ++test; } } )"; - compileAndRun(sourceCode, 0, "A"); + compileAndRun(sourceCode, 0, "B"); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(1)); + BOOST_CHECK(callContractFunction("testIt()") == encodeArgs()); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(2)); } BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_band) { char const* sourceCode = R"( contract A { - uint public test = 0; + uint public test = 1; uint[3] arr; function A() { -- cgit v1.2.3 From 3ddae3209ed3ff8b7a4eae35a8984a7bb8d0ed58 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Tue, 26 May 2015 15:05:58 +0200 Subject: special handle of send --- libsolidity/SolidityEndToEndTest.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 538174ab..efebbb2f 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4167,7 +4167,6 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) function A() { this.call("123"); - } } contract B { -- cgit v1.2.3 From ca8104397dd20195e34e1b6933daef7f84e1d3ba Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 28 May 2015 14:48:37 +0200 Subject: removed exception when function is not found --- libsolidity/SolidityEndToEndTest.cpp | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index efebbb2f..d2faaae0 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4080,7 +4080,6 @@ BOOST_AUTO_TEST_CASE(struct_delete_member) } )"; compileAndRun(sourceCode, 0, "test"); - auto res = callContractFunction("deleteMember()"); BOOST_CHECK(callContractFunction("deleteMember()") == encodeArgs(0)); } @@ -4106,7 +4105,6 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) } )"; compileAndRun(sourceCode, 0, "test"); - auto res = callContractFunction("deleteIt()"); BOOST_CHECK(callContractFunction("deleteIt()") == encodeArgs(0)); } @@ -4134,32 +4132,6 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_out_of_band_access) BOOST_CHECK(callContractFunction("test()") == encodeArgs(false)); } -BOOST_AUTO_TEST_CASE(evm_exceptions_when_calling_non_existing_function) -{ - char const* sourceCode = R"( - contract A { - uint public test = 0; - function badFunction() returns (uint) - { - this.call("123"); - test = 1; - return 2; - } - function testIt() returns (bool) - { - this.badFunction(); - test = 2; - return true; - } - } - )"; - compileAndRun(sourceCode, 0, "A"); - - BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); - BOOST_CHECK(callContractFunction("testIt()") == encodeArgs()); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(0)); -} - BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) { char const* sourceCode = R"( @@ -4184,7 +4156,7 @@ 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_band) +BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) { char const* sourceCode = R"( contract A { @@ -4199,7 +4171,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_band) )"; compileAndRun(sourceCode, 0, "A"); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(1)); + //BOOST_CHECK(m_output.empty()); todo } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 47f0e847e549d6c4bb13cafcb90b49832531cedd Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 29 May 2015 15:39:42 +0200 Subject: style fixes in test/libsolidity/solidityExecutionFramework.h fixed the test --- libsolidity/SolidityEndToEndTest.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index d2faaae0..ef7b5c2a 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4169,9 +4169,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) } } )"; - compileAndRun(sourceCode, 0, "A"); - - //BOOST_CHECK(m_output.empty()); todo + BOOST_CHECK(execute(sourceCode, 0, "A").empty()); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 945418cc108f7abef4e03c6196a4e23245b1fec6 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 29 May 2015 18:38:57 +0200 Subject: style fixes --- libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index ef7b5c2a..db115b10 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4145,7 +4145,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) uint public test = 1; function testIt() { - A a; + A a = new A(); ++test; } } -- cgit v1.2.3 From b810df04f0ebcc65ed7a57fa650d5bb090c8b31d Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 1 Jun 2015 16:48:13 +0200 Subject: renamed the test framwork function. --- libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index db115b10..9f6f27d7 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4169,7 +4169,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) } } )"; - BOOST_CHECK(execute(sourceCode, 0, "A").empty()); + BOOST_CHECK(compileAndRunWthoutCheck(sourceCode, 0, "A").empty()); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 5ef445f64f0e7854dcf9ac89b7867570bbbbbe69 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 1 Jun 2015 22:00:27 +0200 Subject: test Conflicts: test/libsolidity/SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 9f6f27d7..e7287b39 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4172,6 +4172,17 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) BOOST_CHECK(compileAndRunWthoutCheck(sourceCode, 0, "A").empty()); } +BOOST_AUTO_TEST_CASE(positive_integers_to_signed) +{ + char const* sourceCode = R"( + contract test { + int8 public x = 2; + } + )"; + compileAndRun(sourceCode, 0, "test"); + BOOST_CHECK(callContractFunction("x()") == encodeArgs(2)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From c7e6bbb82c7ad989df59906e8287db852012bbb9 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 3 Jun 2015 16:14:23 +0200 Subject: - conversion of positive literals to signed int - tests --- libsolidity/SolidityEndToEndTest.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index e7287b39..1d0f1fc2 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4177,10 +4177,14 @@ BOOST_AUTO_TEST_CASE(positive_integers_to_signed) char const* sourceCode = R"( contract test { int8 public x = 2; + int8 public y = 127; + int16 public q = 250; } )"; compileAndRun(sourceCode, 0, "test"); BOOST_CHECK(callContractFunction("x()") == encodeArgs(2)); + BOOST_CHECK(callContractFunction("y()") == encodeArgs(127)); + BOOST_CHECK(callContractFunction("q()") == encodeArgs(250)); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 7581330e51e3e6619552e2906f790785486ed9f9 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 5 Jun 2015 14:34:10 +0200 Subject: Bare functions return success condition. --- libsolidity/SolidityEndToEndTest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 1d0f1fc2..89ed81e2 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4187,6 +4187,28 @@ BOOST_AUTO_TEST_CASE(positive_integers_to_signed) BOOST_CHECK(callContractFunction("q()") == encodeArgs(250)); } +BOOST_AUTO_TEST_CASE(failing_send) +{ + char const* sourceCode = R"( + contract Helper { + uint[] data; + function () { + data[9]; // trigger exception + } + } + contract Main { + function callHelper(address _a) returns (bool r, uint bal) { + r = !_a.send(5); + bal = this.balance; + } + } + )"; + compileAndRun(sourceCode, 0, "Helper"); + u160 const c_helperAddress = m_contractAddress; + compileAndRun(sourceCode, 20, "Main"); + BOOST_REQUIRE(callContractFunction("callHelper(address)", c_helperAddress) == encodeArgs(true, 20)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 46eb7b08d9fe52f73895bae46648a79cea15c64e Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 8 Jun 2015 11:47:57 +0200 Subject: added test Conflicts: test/libsolidity/SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 51 ++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 89ed81e2..04ad40d7 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -567,7 +567,7 @@ BOOST_AUTO_TEST_CASE(strings) BOOST_AUTO_TEST_CASE(empty_string_on_stack) { char const* sourceCode = "contract test {\n" - " function run(bytes0 empty, uint8 inp) returns(uint16 a, bytes0 b, bytes4 c) {\n" + " function run(string empty, uint8 inp) external returns(uint16 a, string b, bytes4 c) {\n" " var x = \"abc\";\n" " var y = \"\";\n" " var z = inp;\n" @@ -3786,25 +3786,25 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_delete) BOOST_CHECK(m_state.storage(m_contractAddress).empty()); } -BOOST_AUTO_TEST_CASE(packed_storage_structs_with_bytes0) +BOOST_AUTO_TEST_CASE(packed_storage_structs_with_empty_string) { char const* sourceCode = R"( - contract C { - struct str { uint8 a; bytes0 b; uint8 c; } - uint8 a; - bytes0 x; - uint8 b; - str data; - function test() returns (bool) { - a = 2; - b = 3; - data.a = 4; - data.c = 5; - delete x; - delete data.b; - return a == 2 && b == 3 && data.a == 4 && data.c == 5; - } + contract C { + struct str { uint8 a; string b; uint8 c; } + uint8 a; + uint8 b; + str data; + function test() returns (bool) { + a = 2; + b = 3; + var x = ""; + data.a = 4; + data.c = 5; + delete x; + delete data.b; + return a == 2 && b == 3 && data.a == 4 && data.c == 5; } + } )"; compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("test()") == encodeArgs(true)); @@ -4172,6 +4172,23 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) BOOST_CHECK(compileAndRunWthoutCheck(sourceCode, 0, "A").empty()); } +BOOST_AUTO_TEST_CASE(empty_string) +{ + char const* sourceCode = R"( + contract Foo { + var sEmpty = ""; + string sStateVar = "text"; + function Foo() + { + var sLocal = ""; + sEmpty = sLocal; + sLocal = s; + } + } + )"; + compileAndRun(sourceCode, 0, "Foo"); +} + BOOST_AUTO_TEST_CASE(positive_integers_to_signed) { char const* sourceCode = R"( -- cgit v1.2.3 From 1ac5f3c04d3df03df4ae2997c1a2ea0ced9f1311 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 8 Jun 2015 13:08:22 +0200 Subject: removed byte0 keyword --- libsolidity/SolidityEndToEndTest.cpp | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 04ad40d7..a2c5556d 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -564,20 +564,6 @@ BOOST_AUTO_TEST_CASE(strings) BOOST_CHECK(callContractFunction("pipeThrough(bytes2,bool)", string("\0\x02", 2), true) == encodeArgs(string("\0\x2", 2), true)); } -BOOST_AUTO_TEST_CASE(empty_string_on_stack) -{ - char const* sourceCode = "contract test {\n" - " function run(string empty, uint8 inp) external returns(uint16 a, string b, bytes4 c) {\n" - " var x = \"abc\";\n" - " var y = \"\";\n" - " var z = inp;\n" - " a = z; b = y; c = x;" - " }\n" - "}\n"; - compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("run(bytes0,uint8)", string(), byte(0x02)) == encodeArgs(0x2, string(""), string("abc\0"))); -} - BOOST_AUTO_TEST_CASE(inc_dec_operators) { char const* sourceCode = R"( @@ -4172,23 +4158,6 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) BOOST_CHECK(compileAndRunWthoutCheck(sourceCode, 0, "A").empty()); } -BOOST_AUTO_TEST_CASE(empty_string) -{ - char const* sourceCode = R"( - contract Foo { - var sEmpty = ""; - string sStateVar = "text"; - function Foo() - { - var sLocal = ""; - sEmpty = sLocal; - sLocal = s; - } - } - )"; - compileAndRun(sourceCode, 0, "Foo"); -} - BOOST_AUTO_TEST_CASE(positive_integers_to_signed) { char const* sourceCode = R"( -- cgit v1.2.3 From 31fb199acbd9ae8d9d7e5183ce3debd594158837 Mon Sep 17 00:00:00 2001 From: chriseth Date: Sat, 6 Jun 2015 00:57:51 +0200 Subject: Use dynamic memory for argument encoding. --- libsolidity/SolidityEndToEndTest.cpp | 51 ++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 89ed81e2..73f7d60d 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -2396,7 +2396,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data) callContractFunction("deposit()"); BOOST_REQUIRE_EQUAL(m_logs.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK(m_logs[0].data == encodeArgs(10, 4, 15) + FixedHash<4>(dev::sha3("deposit()")).asBytes()); + BOOST_CHECK(m_logs[0].data == encodeArgs(10, 0x60, 15, 4) + FixedHash<4>(dev::sha3("deposit()")).asBytes()); BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(uint256,bytes,uint256)"))); } @@ -2420,7 +2420,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data_from_storage) callContractFunction("deposit()"); BOOST_REQUIRE_EQUAL(m_logs.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK(m_logs[0].data == encodeArgs(10, 3, 15) + asBytes("ABC")); + BOOST_CHECK(m_logs[0].data == encodeArgs(10, 0x60, 15, 3) + asBytes("ABC")); BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(uint256,bytes,uint256)"))); } @@ -2531,6 +2531,27 @@ BOOST_AUTO_TEST_CASE(sha3_with_bytes) BOOST_CHECK(callContractFunction("foo()") == encodeArgs(true)); } +BOOST_AUTO_TEST_CASE(iterated_sha3_with_bytes) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function foo() returns (bytes32) + { + data.length = 3; + data[0] = "x"; + data[1] = "y"; + data[2] = "z"; + return sha3("b", sha3(data), "a"); + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("foo()") == encodeArgs( + u256(dev::sha3(bytes{'b'} + dev::sha3("xyz").asBytes() + bytes{'a'})) + )); +} + BOOST_AUTO_TEST_CASE(generic_call) { char const* sourceCode = R"**( @@ -4209,6 +4230,32 @@ BOOST_AUTO_TEST_CASE(failing_send) BOOST_REQUIRE(callContractFunction("callHelper(address)", c_helperAddress) == encodeArgs(true, 20)); } +BOOST_AUTO_TEST_CASE(reusing_memory) +{ + // Invoke some features that use memory and test that they do not interfere with each other. + char const* sourceCode = R"( + contract Helper { + uint public flag; + function Helper(uint x) { + flag = x; + } + } + contract Main { + mapping(uint => uint) map; + function f(uint x) returns (uint) { + map[x] = x; + return (new Helper(uint(sha3(this.g(map[x]))))).flag(); + } + function g(uint a) returns (uint) + { + return map[a]; + } + } + )"; + compileAndRun(sourceCode, 0, "Main"); + BOOST_REQUIRE(callContractFunction("f(uint256)", 0x34) == encodeArgs(dev::sha3(dev::toBigEndian(u256(0x34))))); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 4967535f8a9b46edfa029793e9d38125afd886cf Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Tue, 9 Jun 2015 11:55:19 +0200 Subject: cleaned up the tests --- libsolidity/SolidityEndToEndTest.cpp | 38 +++++++++++++----------------------- 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'libsolidity/SolidityEndToEndTest.cpp') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index a2c5556d..fdd865e7 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -564,6 +564,20 @@ BOOST_AUTO_TEST_CASE(strings) BOOST_CHECK(callContractFunction("pipeThrough(bytes2,bool)", string("\0\x02", 2), true) == encodeArgs(string("\0\x2", 2), true)); } +BOOST_AUTO_TEST_CASE(empty_string_on_stack) +{ + char const* sourceCode = R"( + contract test { + function run() external returns(bytes2 ret) { + var y = ""; + ret = y; + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("run()") == encodeArgs(byte(0x00))); +} + BOOST_AUTO_TEST_CASE(inc_dec_operators) { char const* sourceCode = R"( @@ -3772,30 +3786,6 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_delete) BOOST_CHECK(m_state.storage(m_contractAddress).empty()); } -BOOST_AUTO_TEST_CASE(packed_storage_structs_with_empty_string) -{ - char const* sourceCode = R"( - contract C { - struct str { uint8 a; string b; uint8 c; } - uint8 a; - uint8 b; - str data; - function test() returns (bool) { - a = 2; - b = 3; - var x = ""; - data.a = 4; - data.c = 5; - delete x; - delete data.b; - return a == 2 && b == 3 && data.a == 4 && data.c == 5; - } - } - )"; - compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("test()") == encodeArgs(true)); -} - BOOST_AUTO_TEST_CASE(overloaded_function_call_resolve_to_first) { char const* sourceCode = R"( -- cgit v1.2.3