From f20b150f3830d7a014258d92a26aba6a2bbdc8cb Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Sat, 8 Jul 2017 22:42:42 -0300 Subject: Add type error when attempting value transfer to a non-payable contract --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'test') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 2ee5baac..f6f8b8c9 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -6146,6 +6146,76 @@ BOOST_AUTO_TEST_CASE(callable_crash) CHECK_ERROR(text, TypeError, "Type is not callable"); } +BOOST_AUTO_TEST_CASE(error_transfer_non_payable_fallback) +{ + char const* text = R"( + contract A { + function() {} + } + + contract B { + A a; + + function() { + a.transfer(100); + } + } + )"; + CHECK_ERROR(text, TypeError, "Value transfer to a contract without a payable fallback function."); +} + +BOOST_AUTO_TEST_CASE(error_transfer_no_fallback) +{ + char const* text = R"( + contract A {} + + contract B { + A a; + + function() { + a.transfer(100); + } + } + )"; + CHECK_ERROR(text, TypeError, "Value transfer to a contract without a payable fallback function."); +} + +BOOST_AUTO_TEST_CASE(error_send_non_payable_fallback) +{ + char const* text = R"( + contract A { + function() {} + } + + contract B { + A a; + + function() { + require(a.send(100)); + } + } + )"; + CHECK_ERROR(text, TypeError, "Value transfer to a contract without a payable fallback function."); +} + +BOOST_AUTO_TEST_CASE(does_not_error_transfer_payable_fallback) +{ + char const* text = R"( + contract A { + function() payable {} + } + + contract B { + A a; + + function() { + a.transfer(100); + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} + BOOST_AUTO_TEST_CASE(returndatacopy_as_variable) { char const* text = R"( -- cgit v1.2.3 From da917333d9e4d084808ccf26b3ef4cd83e4f0bcb Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Wed, 12 Jul 2017 23:59:45 -0300 Subject: Fix error message formatting --- test/libsolidity/ErrorCheck.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/libsolidity/ErrorCheck.cpp b/test/libsolidity/ErrorCheck.cpp index 9b0f9fb7..7a66c6c7 100644 --- a/test/libsolidity/ErrorCheck.cpp +++ b/test/libsolidity/ErrorCheck.cpp @@ -32,7 +32,7 @@ bool dev::solidity::searchErrorMessage(Error const& _err, std::string const& _su { if (errorMessage->find(_substr) == std::string::npos) { - cout << "Expected message \"" << _substr << "\" but found" << *errorMessage << endl; + cout << "Expected message \"" << _substr << "\" but found \"" << *errorMessage << "\".\n"; return false; } return true; -- cgit v1.2.3