aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorFederico Bond <federicobond@gmail.com>2017-07-09 09:42:42 +0800
committerFederico Bond <federicobond@gmail.com>2017-07-13 10:57:53 +0800
commitf20b150f3830d7a014258d92a26aba6a2bbdc8cb (patch)
tree1da74ae9b2a8c7b34f9be6ede23dc8980ec116a3 /test/libsolidity
parent757c500bda9a32cccc86e1ab24da31a99c0e6eac (diff)
downloaddexon-solidity-f20b150f3830d7a014258d92a26aba6a2bbdc8cb.tar.gz
dexon-solidity-f20b150f3830d7a014258d92a26aba6a2bbdc8cb.tar.zst
dexon-solidity-f20b150f3830d7a014258d92a26aba6a2bbdc8cb.zip
Add type error when attempting value transfer to a non-payable contract
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp70
1 files changed, 70 insertions, 0 deletions
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"(