aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-07-13 21:08:36 +0800
committerGitHub <noreply@github.com>2017-07-13 21:08:36 +0800
commit2b33e0bcecdb2afe6a7ea242bce83480bb50a071 (patch)
tree7c72c8b06b3f51a29eef7b11b8c000b97ae86a30 /test
parent757c500bda9a32cccc86e1ab24da31a99c0e6eac (diff)
parentda917333d9e4d084808ccf26b3ef4cd83e4f0bcb (diff)
downloaddexon-solidity-2b33e0bcecdb2afe6a7ea242bce83480bb50a071.tar
dexon-solidity-2b33e0bcecdb2afe6a7ea242bce83480bb50a071.tar.gz
dexon-solidity-2b33e0bcecdb2afe6a7ea242bce83480bb50a071.tar.bz2
dexon-solidity-2b33e0bcecdb2afe6a7ea242bce83480bb50a071.tar.lz
dexon-solidity-2b33e0bcecdb2afe6a7ea242bce83480bb50a071.tar.xz
dexon-solidity-2b33e0bcecdb2afe6a7ea242bce83480bb50a071.tar.zst
dexon-solidity-2b33e0bcecdb2afe6a7ea242bce83480bb50a071.zip
Merge pull request #2544 from federicobond/error-value-transfer-non-payable
Add type error when attempting to transfer value to a non-payable contract
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/ErrorCheck.cpp2
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp70
2 files changed, 71 insertions, 1 deletions
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;
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"(