diff options
author | chriseth <c@ethdev.com> | 2016-08-08 01:46:11 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-08-17 17:30:40 +0800 |
commit | 774bb8ab3baa9d7b5e6368dcd0f887b13ff26ae8 (patch) | |
tree | d2ba2c8f7f79c5e9d2db46a4ec748844c9968a20 /test/libsolidity | |
parent | e7683f4722791d39ca63913ec98feb1ea9f5164d (diff) | |
download | dexon-solidity-774bb8ab3baa9d7b5e6368dcd0f887b13ff26ae8.tar.gz dexon-solidity-774bb8ab3baa9d7b5e6368dcd0f887b13ff26ae8.tar.zst dexon-solidity-774bb8ab3baa9d7b5e6368dcd0f887b13ff26ae8.zip |
Make function calls throw if target does not have code.
Low-level calls still just execute and will actually report "success".
This allows `x.call.value(y)()` for x being a non-contract account.
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index a1ab7700..8aab3cb9 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -6896,6 +6896,32 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0))); } +BOOST_AUTO_TEST_CASE(calling_nonexisting_contract_throws) +{ + char const* sourceCode = R"( + contract D { function g(); } + contract C { + D d = D(0x1212); + function f() returns (uint) { + d.g(); + return 7; + } + function g() returns (uint) { + d.g.gas(200)(); + return 7; + } + function h() returns (uint) { + d.call(); // this does not throw (low-level) + return 7; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs()); + BOOST_CHECK(callContractFunction("g()") == encodeArgs()); + BOOST_CHECK(callContractFunction("h()") == encodeArgs(u256(7))); +} + BOOST_AUTO_TEST_SUITE_END() } |