From 7dc5e2a1a0ef2c0212d852c053fc52e25c16acd9 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 10 Feb 2015 10:45:57 +0100 Subject: [PATCH 1/5] Arbitrary parameters for call() and all hash functions. --- SolidityEndToEndTest.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 5bd1e8578..31b80894e 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -2201,6 +2201,29 @@ BOOST_AUTO_TEST_CASE(sha3_multiple_arguments_with_string_literals) bytes({0x66, 0x6f, 0x6f})))); } +BOOST_AUTO_TEST_CASE(generic_call) +{ + char const* sourceCode = R"**( + contract receiver { + uint public received; + function receive(uint256 x) { received = x; } + } + contract sender { + function doSend(address rec) returns (uint d) + { + string4 signature = string4(string32(sha3("receive(uint256)"))); + rec.call.value(2)(signature, 23); + return receiver(rec).received(); + } + } + )**"; + compileAndRun(sourceCode, 0, "receiver"); + u160 const c_receiverAddress = m_contractAddress; + compileAndRun(sourceCode, 50, "sender"); + BOOST_REQUIRE(callContractFunction("doSend(address)", c_receiverAddress) == encodeArgs(23)); + BOOST_CHECK_EQUAL(m_state.balance(m_contractAddress), 50 - 2); +} + BOOST_AUTO_TEST_SUITE_END() } From 3ce223c6cb30f8e9f1035b6740d8c90f95a91185 Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Sun, 8 Feb 2015 19:23:17 +0800 Subject: [PATCH 2/5] add exponent operator https://www.pivotaltracker.com/n/projects/1189488/stories/83746404 --- SolidityEndToEndTest.cpp | 30 ++++++++++++++++++++++++++++++ SolidityParser.cpp | 11 +++++++++++ 2 files changed, 41 insertions(+) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 31b80894e..748110145 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -56,6 +56,36 @@ BOOST_AUTO_TEST_CASE(empty_contract) BOOST_CHECK(callContractFunction("i_am_not_there()", bytes()).empty()); } +BOOST_AUTO_TEST_CASE(exp_operator) +{ + char const* sourceCode = R"( + contract test { + function f(uint a) returns(uint d) { return 2 ** a; } + })"; + compileAndRun(sourceCode); + testSolidityAgainstCppOnRange("f(uint256)", [](u256 const& a) -> u256 { return u256(1 << a.convert_to()); }, 0, 16); +} + +BOOST_AUTO_TEST_CASE(exp_operator_const) +{ + char const* sourceCode = R"( + contract test { + function f() returns(uint d) { return 2 ** 3; } + })"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(8))); +} + +BOOST_AUTO_TEST_CASE(exp_operator_const_signed) +{ + char const* sourceCode = R"( + contract test { + function f() returns(int d) { return -2 ** 3; } + })"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(-8))); +} + BOOST_AUTO_TEST_CASE(recursive_calls) { char const* sourceCode = "contract test {\n" diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 7af99567b..84f36170f 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -387,6 +387,17 @@ BOOST_AUTO_TEST_CASE(complex_expression) BOOST_CHECK_NO_THROW(parseText(text)); } +BOOST_AUTO_TEST_CASE(exp_expression) +{ + char const* text = R"( + contract test { + function fun(uint256 a) { + uint256 x = 3 ** a; + } + })"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + BOOST_AUTO_TEST_CASE(while_loop) { char const* text = "contract test {\n" From 2f15494f83838faf27502fe7bbeb02ffd34e6d46 Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Mon, 9 Feb 2015 23:15:36 +0800 Subject: [PATCH 3/5] add two more exp tests --- SolidityNameAndTypeResolution.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index f4be31f4b..b529f0b70 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -974,6 +974,24 @@ BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(exp_operator_negative_exponent) +{ + char const* sourceCode = R"( + contract test { + function f() returns(uint d) { return 2 ** -3; } + })"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), InternalCompilerError); +} + +BOOST_AUTO_TEST_CASE(exp_operator_const_overflowed) +{ + char const* sourceCode = R"( + contract test { + function f() returns(uint d) { return 10 ** 256; } + })"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), InternalCompilerError); +} + BOOST_AUTO_TEST_SUITE_END() } From 466f0e01001bae0782d7f41ef944301f1a2e1e7f Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Tue, 10 Feb 2015 22:43:13 +0800 Subject: [PATCH 4/5] small fixes per chris's comments --- SolidityEndToEndTest.cpp | 2 +- SolidityNameAndTypeResolution.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 748110145..13a666fbf 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(exp_operator_const_signed) { char const* sourceCode = R"( contract test { - function f() returns(int d) { return -2 ** 3; } + function f() returns(int d) { return (-2) ** 3; } })"; compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(-8))); diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index b529f0b70..d013f5c5e 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -980,16 +980,16 @@ BOOST_AUTO_TEST_CASE(exp_operator_negative_exponent) contract test { function f() returns(uint d) { return 2 ** -3; } })"; - BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), InternalCompilerError); + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } -BOOST_AUTO_TEST_CASE(exp_operator_const_overflowed) +BOOST_AUTO_TEST_CASE(exp_operator_exponent_too_big) { char const* sourceCode = R"( contract test { - function f() returns(uint d) { return 10 ** 256; } + function f() returns(uint d) { return 2 ** 10000000000; } })"; - BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), InternalCompilerError); + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } BOOST_AUTO_TEST_SUITE_END() From 9a792edb33a95f8034cbb368e94e8ca0f4565415 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 10 Feb 2015 20:53:38 +0100 Subject: [PATCH 5/5] Test stuff into cpp from header. Additional debug stuff in cmake. --- TestHelper.cpp | 3 +++ TestHelper.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 8e4c493eb..8a00a5462 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -64,6 +64,9 @@ void connectClients(Client& c1, Client& c2) namespace test { +struct ValueTooLarge: virtual Exception {}; +bigint const c_max256plus1 = bigint(1) << 256; + ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_TestObject(_o) { importEnv(_o["env"].get_obj()); diff --git a/TestHelper.h b/TestHelper.h index 2b93bccfb..ae6ea20cc 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -42,9 +42,6 @@ void connectClients(Client& c1, Client& c2); namespace test { -struct ValueTooLarge: virtual Exception {}; -bigint const c_max256plus1 = bigint(1) << 256; - class ImportTest { public: