From 34a6afbd77f499ca4883a62a8de642db1c062e53 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 4 Aug 2016 16:47:46 +0100 Subject: Include EndToEnd test for payable keyword --- test/libsolidity/SolidityEndToEndTest.cpp | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'test') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f3fdef15..f855c2a3 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -7087,6 +7087,63 @@ BOOST_AUTO_TEST_CASE(calling_nonexisting_contract_throws) BOOST_CHECK(callContractFunction("h()") == encodeArgs(u256(7))); } +BOOST_AUTO_TEST_CASE(payable_accept_explicit_constructor) +{ + char const* sourceCode = R"( + contract C { + function () payable { } + } + )"; + compileAndRun(sourceCode, 27, "C"); +} + + +BOOST_AUTO_TEST_CASE(payable_accept_explicit) +{ + char const* sourceCode = R"( + contract C { + function f() payable returns (uint) { + return msg.value; + } + function() payable returns (uint) { + return msg.value; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunctionWithValue("f()", 27) == encodeArgs(u256(27))); + BOOST_CHECK(callContractFunctionWithValue("", 27) == encodeArgs(u256(27))); +} + +BOOST_AUTO_TEST_CASE(non_payable_throw_constructor) +{ + char const* sourceCode = R"( + contract C { + function() { } + } + )"; + compileAndRun(sourceCode, 27, "C"); +} + +BOOST_AUTO_TEST_CASE(non_payable_throw) +{ + char const* sourceCode = R"( + contract C { + string public a; + function f() returns (uint) { + return msg.value; + } + function() returns (uint) { + return msg.value; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunctionWithValue("f()", 27) == encodeArgs()); + BOOST_CHECK(callContractFunctionWithValue("", 27) == encodeArgs()); + BOOST_CHECK(callContractFunctionWithValue("a()", 27) == encodeArgs()); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3