diff options
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | CONTRIBUTING.md | 5 | ||||
-rw-r--r-- | Changelog.md | 37 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | cmake/EthBuildInfo.cmake | 4 | ||||
-rw-r--r-- | cmake/scripts/buildinfo.cmake | 53 | ||||
-rw-r--r-- | cmake/templates/BuildInfo.h.in | 15 | ||||
-rw-r--r-- | docs/contracts.rst | 6 | ||||
-rw-r--r-- | docs/contributing.rst | 55 | ||||
-rw-r--r-- | docs/index.rst | 1 | ||||
-rw-r--r-- | docs/installing-solidity.rst | 6 | ||||
-rw-r--r-- | docs/security-considerations.rst | 4 | ||||
-rw-r--r-- | docs/units-and-global-variables.rst | 4 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 2 | ||||
-rw-r--r-- | libsolidity/codegen/ContractCompiler.cpp | 5 | ||||
-rw-r--r-- | libsolidity/interface/InterfaceHandler.cpp | 10 | ||||
-rw-r--r-- | libsolidity/interface/Version.cpp | 6 | ||||
-rwxr-xr-x | scripts/build_emscripten.sh | 1 | ||||
-rwxr-xr-x | scripts/release_ppa.sh | 4 | ||||
-rw-r--r-- | test/libsolidity/Assembly.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityABIJSON.cpp | 28 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 15 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 10 |
23 files changed, 225 insertions, 53 deletions
diff --git a/.travis.yml b/.travis.yml index 1b0ff15d..da9bd2f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -141,6 +141,8 @@ cache: install: - test $TRAVIS_INSTALL_DEPS != On || ./scripts/install_deps.sh + - echo -n "$TRAVIS_COMMIT" > commit_hash.txt + - test "$TRAVIS_PULL_REQUESTS" != "false" || test "$TRAVIS_BRANCH" != release || echo -n > prerelease.txt # this is a proper release before_script: - test $TRAVIS_EMSCRIPTEN != On || ./scripts/build_emscripten.sh - test $TRAVIS_RELEASE != On || (mkdir -p build diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..2b591f4e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,5 @@ +# Contribution Guidelines + +Please see our contribution guidelines in [the Solidity documentation](http://solidity.readthedocs.io/en/latest/contributing.html). + +Thank you for your help! diff --git a/Changelog.md b/Changelog.md index 8805498e..5cf2898b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,9 +1,44 @@ +### 0.4.0 (unreleased) + +This release deliberately breaks backwards compatibility mostly to +enforce some safety features. The most important change is +... + +Breaking Changes: + + * Contracts that want to receive Ether have to implement a fallback + function (contracts now throw if no fallback function is defined + and no function matches the signature). + * Failing contract creation through "new" throws now. + * Throw on division / modulus by zero + * Function call throws if target contract does not have code + * Modifiers are required to contain ``_`` (use ``if (false) _`` as a workaround if needed). + * Modifiers: return does not skip part in modifier after ``_`` + * ``ecrecover`` now returns zero if the input is malformed (it previously returned garbage) + * Removed ``--interface`` (Solidity interface) output option + * JSON AST: General cleanup, renamed many nodes to match their C++ names. + * Json Output: srcmap-runtime renamed to srcmapRuntime + * Moved (and reworked) standard library contracts from inside the compiler to github.com/ethereum/solidity/std + (``import "std";`` or ``import owned;`` do not work anymore). + * Confusing and undocumented keyword "after" was removed. + * New reserved words: hex, payable, abstract, static, interface + Features: - * Fixed point types (in progress) + * Hexadecimal string literals: ``hex"ab1248fe"`` + * Internal: Inline assembly usable by the code generator. + * Commandline interface: Using ``-`` as filename allows reading from stdin. + * Interface Json: Fallback function is now part of the ABI. + * Interface: Version string now semver compatible. Bugfixes: + * JSON AST: nodes were added at wrong parent + * Why3 translator: crash fix for exponentiation + * Type Checker: Fallback function cannot return data anymore. + +Lots of changes to the documentation mainly by voluntary external contributors. + ### 0.3.6 (2016-08-10) Features: @@ -14,7 +14,6 @@ Solidity is still under development. So please do not hesitate and open an [issu See the [Solidity documentation](http://solidity.readthedocs.io/en/latest/installing-solidity.html#building-from-source) for build instructions. ## How to Contribute -This repository uses the same [coding style](https://github.com/ethereum/cpp-ethereum/blob/develop/CodingStandards.txt) as -all of the cpp-ethereum projects. Please try to align with us in the Gitter channel before making larger changes. +Please see our contribution guidelines in [the Solidity documentation](http://solidity.readthedocs.io/en/latest/contributing.html). Any contributions are welcome! diff --git a/cmake/EthBuildInfo.cmake b/cmake/EthBuildInfo.cmake index cbb9dd24..1f70d371 100644 --- a/cmake/EthBuildInfo.cmake +++ b/cmake/EthBuildInfo.cmake @@ -19,7 +19,7 @@ function(create_build_info NAME) set(ETH_BUILD_COMPILER "unknown") endif () - set(ETH_BUILD_PLATFORM "${ETH_BUILD_OS}/${ETH_BUILD_COMPILER}") + set(ETH_BUILD_PLATFORM "${ETH_BUILD_OS}.${ETH_BUILD_COMPILER}") #cmake build type may be not speCified when using msvc if (CMAKE_BUILD_TYPE) @@ -36,8 +36,6 @@ function(create_build_info NAME) -DETH_BUILD_OS="${ETH_BUILD_OS}" -DETH_BUILD_COMPILER="${ETH_BUILD_COMPILER}" -DETH_BUILD_PLATFORM="${ETH_BUILD_PLATFORM}" - -DETH_BUILD_NUMBER="${BUILD_NUMBER}" - -DETH_VERSION_SUFFIX="${VERSION_SUFFIX}" -DPROJECT_VERSION="${PROJECT_VERSION}" -P "${ETH_SCRIPTS_DIR}/buildinfo.cmake" ) diff --git a/cmake/scripts/buildinfo.cmake b/cmake/scripts/buildinfo.cmake index 39359486..ad23ca86 100644 --- a/cmake/scripts/buildinfo.cmake +++ b/cmake/scripts/buildinfo.cmake @@ -5,11 +5,11 @@ # ETH_DST_DIR - main CMAKE_BINARY_DIR # ETH_BUILD_TYPE # ETH_BUILD_PLATFORM -# ETH_BUILD_NUMBER -# ETH_VERSION_SUFFIX # # example usage: -# cmake -DETH_SOURCE_DIR=. -DETH_DST_DIR=build -DETH_BUILD_TYPE=Debug -DETH_BUILD_PLATFORM=Darwin/appleclang -P scripts/buildinfo.cmake +# cmake -DETH_SOURCE_DIR=. -DETH_DST_DIR=build -DETH_BUILD_TYPE=Debug -DETH_BUILD_PLATFORM=Darwin.appleclang -P scripts/buildinfo.cmake +# +# Its main output variables are SOL_VERSION_BUILDINFO and SOL_VERSION_PRERELEASE if (NOT ETH_BUILD_TYPE) set(ETH_BUILD_TYPE "unknown") @@ -19,26 +19,45 @@ if (NOT ETH_BUILD_PLATFORM) set(ETH_BUILD_PLATFORM "unknown") endif() -execute_process( - COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} rev-parse HEAD - OUTPUT_VARIABLE ETH_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET -) +# Logic here: If prereleases.txt exists but is empty, it is a non-pre release. +# If it does not exist, create our own prerelease string +if (EXISTS ${ETH_SOURCE_DIR}/prerelease.txt) + file(READ ${ETH_SOURCE_DIR}/prerelease.txt SOL_VERSION_PRERELEASE) + string(STRIP ${SOL_VERSION_PRERELEASE} SOL_VERSION_PRERELEASE) +else() + string(TIMESTAMP SOL_VERSION_PRERELEASE "develop.%Y.%m.%d" UTC) +endif() -if (NOT ETH_COMMIT_HASH) - set(ETH_COMMIT_HASH 0) +if (EXISTS ${ETH_SOURCE_DIR}/commit_hash.txt) + file(READ ${ETH_SOURCE_DIR}/commit_hash.txt SOL_COMMIT_HASH) + string(STRIP ${SOL_COMMIT_HASH} SOL_COMMIT_HASH) +else() + execute_process( + COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} rev-parse HEAD + OUTPUT_VARIABLE SOL_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET + ) + execute_process( + COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} diff HEAD --shortstat + OUTPUT_VARIABLE SOL_LOCAL_CHANGES OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET + ) endif() -execute_process( - COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} diff HEAD --shortstat - OUTPUT_VARIABLE ETH_LOCAL_CHANGES OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET -) +if (SOL_COMMIT_HASH) + string(STRIP ${SOL_COMMIT_HASH} SOL_COMMIT_HASH) + string(SUBSTRING ${SOL_COMMIT_HASH} 0 8 SOL_COMMIT_HASH) +endif() -if (ETH_LOCAL_CHANGES) - set(ETH_CLEAN_REPO 0) -else() - set(ETH_CLEAN_REPO 1) +if (SOL_COMMIT_HASH AND SOL_LOCAL_CHANGES) + set(SOL_COMMIT_HASH "${SOL_COMMIT_HASH}-mod") +endif() + +if (NOT SOL_COMMIT_HASH) + message(FATAL_ERROR "Unable to determine commit hash. Either compile from within git repository or " + "supply a file called commit_hash.txt") endif() +set(SOL_VERSION_BUILDINFO "commit.${SOL_COMMIT_HASH}.${ETH_BUILD_PLATFORM}") + set(TMPFILE "${ETH_DST_DIR}/BuildInfo.h.tmp") set(OUTFILE "${ETH_DST_DIR}/BuildInfo.h") diff --git a/cmake/templates/BuildInfo.h.in b/cmake/templates/BuildInfo.h.in index 6f9baf50..6c16e4ac 100644 --- a/cmake/templates/BuildInfo.h.in +++ b/cmake/templates/BuildInfo.h.in @@ -1,11 +1,10 @@ #pragma once #define ETH_PROJECT_VERSION "@PROJECT_VERSION@" -#define ETH_COMMIT_HASH @ETH_COMMIT_HASH@ -#define ETH_CLEAN_REPO @ETH_CLEAN_REPO@ -#define ETH_BUILD_TYPE @ETH_BUILD_TYPE@ -#define ETH_BUILD_OS @ETH_BUILD_OS@ -#define ETH_BUILD_COMPILER @ETH_BUILD_COMPILER@ -#define ETH_BUILD_PLATFORM @ETH_BUILD_PLATFORM@ -#define ETH_BUILD_NUMBER @ETH_BUILD_NUMBER@ -#define ETH_VERSION_SUFFIX "@ETH_VERSION_SUFFIX@" +#define SOL_COMMIT_HASH "@SOL_COMMIT_HASH@" +#define ETH_BUILD_TYPE "@ETH_BUILD_TYPE@" +#define ETH_BUILD_OS "@ETH_BUILD_OS@" +#define ETH_BUILD_COMPILER "@ETH_BUILD_COMPILER@" +#define ETH_BUILD_PLATFORM "@ETH_BUILD_PLATFORM@" +#define SOL_VERSION_PRERELEASE "@SOL_VERSION_PRERELEASE@" +#define SOL_VERSION_BUILDINFO "@SOL_VERSION_BUILDINFO@" diff --git a/docs/contracts.rst b/docs/contracts.rst index d3a89c1e..a22a3544 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -447,6 +447,12 @@ In particular, the following operations will consume more gas than the stipend p Please ensure you test your fallback function thoroughly to ensure the execution cost is less than 2300 gas before deploying a contract. +.. warning:: + Contracts that receive Ether but do not define a fallback function + throw an exception, sending back the Ether (this was different + before Solidity v0.4.0). So if you want your contract to receive Ether, + you have to implement a fallback function. + :: contract Test { diff --git a/docs/contributing.rst b/docs/contributing.rst new file mode 100644 index 00000000..cef6dfd2 --- /dev/null +++ b/docs/contributing.rst @@ -0,0 +1,55 @@ +############ +Contributing +############ + +Help is always appreciated! + +To get started, you can try :ref:`building-from-source` in order to familiarize +yourself with the components of Solidity and the build process. Also, it may be +useful to become well-versed at writing smart-contracts in Solidity. + +In particular, we need help in the following areas: + +* Improving the documentation +* Responding to questions from other users on `StackExchange + <http://ethereum.stackexchange.com/>`_ and the `Solidity Gitter + <https://gitter.im/ethereum/solidity>`_ +* Fixing and responding to `Solidity's GitHub issues + <https://github.com/ethereum/solidity/issues>`_ + +How to Report Issues +==================== + +To report an issue, please use the +`GitHub issues tracker <https://github.com/ethereum/solidity/issues>`_. When +reporting issues, please mention the following details: + +* Which version of Solidity you are using +* Which platform are you running on +* How to reproduce the issue +* What was the result of the issue +* What the expected behaviour is + +Workflow for Pull Requests +========================== + +In order to contribute, please fork off of the ``develop`` branch and make your +changes there. Your commit messages should detail *why* you made your change, as +opposed to *what* you did. + +If you need to pull in any changes from ``develop`` after making your fork (for +example, to resolve potential merge conflicts), please avoid using ``git merge`` +and instead, ``git rebase`` your branch. + +Additionally, if you are writing a new feature, please ensure you write appropriate +Boost test cases and place them under ``test/``. + +However, if you are making a larger change, please consult with the Gitter +channel, first. + +Finally, please make sure you respect the `coding standards +<https://raw.githubusercontent.com/ethereum/cpp-ethereum/develop/CodingStandards.txt>`_ +for this project. Also, even though we do CI testing, please test your code and +ensure that it builds locally before submitting a pull request. + +Thank you for your help! diff --git a/docs/index.rst b/docs/index.rst index 5f8977e8..a5ab3f86 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -113,4 +113,5 @@ Contents security-considerations.rst style-guide.rst common-patterns.rst + contributing.rst frequently-asked-questions.rst diff --git a/docs/installing-solidity.rst b/docs/installing-solidity.rst index 9226b558..ad27e528 100644 --- a/docs/installing-solidity.rst +++ b/docs/installing-solidity.rst @@ -1,3 +1,7 @@ +.. index:: ! installing + +.. _installing-solidity: + ################### Installing Solidity ################### @@ -68,6 +72,8 @@ We will re-add the pre-built bottles soon. brew linkapps solidity +.. _building-from-source: + Building from Source ==================== diff --git a/docs/security-considerations.rst b/docs/security-considerations.rst index f8d099e4..7e846674 100644 --- a/docs/security-considerations.rst +++ b/docs/security-considerations.rst @@ -103,7 +103,9 @@ and stall those. Please be explicit about such cases in the documentation of you Sending and Receiving Ether =========================== -- If a contract receives Ether (without a function being called), the fallback function is executed. The contract can only rely +- If a contract receives Ether (without a function being called), the fallback function is executed. + If it does not have a fallback function, the Ether will be rejected (by throwing an exception). + During the execution of the fallback function, the contract can only rely on the "gas stipend" (2300 gas) being available to it at that time. This stipend is not enough to access storage in any way. To be sure that your contract can receive Ether in that way, check the gas requirements of the fallback function (for example in the "details" section in browser-solidity). diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst index 64ee3408..9ee334cf 100644 --- a/docs/units-and-global-variables.rst +++ b/docs/units-and-global-variables.rst @@ -109,6 +109,10 @@ This means that the following are all identical:: If padding is needed, explicit type conversions can be used: ``sha3("\x00\x12")`` is the same as ``sha3(uint16(0x12))``. +Note that constants will be packed using the minimum number of bytes required to store them. +This means that, for example, ``sha3(0) == sha3(uint8(0))`` and +``sha3(0x12345678) == sha3(uint32(0x12345678))``. + It might be that you run into Out-of-Gas for ``sha256``, ``ripemd160`` or ``ecrecover`` on a *private blockchain*. The reason for this is that those are implemented as so-called precompiled contracts and these contracts only really exist after they received the first message (although their contract code is hardcoded). Messages to non-existing contracts are more expensive and thus the execution runs into an Out-of-Gas error. A workaround for this problem is to first send e.g. 1 Wei to each of the contracts before you use them in your actual contracts. This is not an issue on the official or test net. .. _address_related: diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 235fcabd..bc03da01 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -92,6 +92,8 @@ bool TypeChecker::visit(ContractDefinition const& _contract) else { fallbackFunction = function; + if (_contract.isLibrary()) + typeError(fallbackFunction->location(), "Libraries cannot have fallback functions."); if (!fallbackFunction->parameters().empty()) typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters."); if (!fallbackFunction->returnParameters().empty()) diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 715852be..9d77ccdc 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -247,11 +247,8 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac m_context << returnTag; appendReturnValuePacker(FunctionType(*fallback).returnParameterTypes(), _contract.isLibrary()); } - else if (_contract.isLibrary()) - // Reject invalid library calls and ether sent to a library. - m_context.appendJumpTo(m_context.errorTag()); else - m_context << Instruction::STOP; // function not found + m_context.appendJumpTo(m_context.errorTag()); for (auto const& it: interfaceFunctions) { diff --git a/libsolidity/interface/InterfaceHandler.cpp b/libsolidity/interface/InterfaceHandler.cpp index f5c10356..5d24e1bf 100644 --- a/libsolidity/interface/InterfaceHandler.cpp +++ b/libsolidity/interface/InterfaceHandler.cpp @@ -74,7 +74,15 @@ string InterfaceHandler::abiInterface(ContractDefinition const& _contractDef) ); abi.append(method); } - + if (_contractDef.fallbackFunction()) + { + auto externalFunctionType = FunctionType(*_contractDef.fallbackFunction()).interfaceFunctionType(); + solAssert(!!externalFunctionType, ""); + Json::Value method; + method["type"] = "fallback"; + method["constant"] = externalFunctionType->isConstant(); + abi.append(method); + } for (auto const& it: _contractDef.interfaceEvents()) { Json::Value event; diff --git a/libsolidity/interface/Version.cpp b/libsolidity/interface/Version.cpp index a846efea..31ba4afc 100644 --- a/libsolidity/interface/Version.cpp +++ b/libsolidity/interface/Version.cpp @@ -35,10 +35,8 @@ char const* dev::solidity::VersionNumber = ETH_PROJECT_VERSION; string const dev::solidity::VersionString = string(dev::solidity::VersionNumber) + - "-" + - string(DEV_QUOTED(ETH_COMMIT_HASH)).substr(0, 8) + - (ETH_CLEAN_REPO ? "" : "*") + - "/" DEV_QUOTED(ETH_BUILD_TYPE) "-" DEV_QUOTED(ETH_BUILD_PLATFORM); + (string(SOL_VERSION_PRERELEASE).empty() ? "" : "-" + string(SOL_VERSION_PRERELEASE)) + + (string(SOL_VERSION_BUILDINFO).empty() ? "" : "+" + string(SOL_VERSION_BUILDINFO)); bytes dev::solidity::binaryVersion() diff --git a/scripts/build_emscripten.sh b/scripts/build_emscripten.sh index 6046978e..da2c7df3 100755 --- a/scripts/build_emscripten.sh +++ b/scripts/build_emscripten.sh @@ -29,6 +29,7 @@ set -e if [[ "$OSTYPE" != "darwin"* ]]; then + date -u +"nightly.%Y.%m.%d" > prerelease.txt ./scripts/travis-emscripten/install_deps.sh docker run -v $(pwd):/src trzeci/emscripten:sdk-tag-1.35.4-64bit ./scripts/travis-emscripten/build_emscripten.sh fi diff --git a/scripts/release_ppa.sh b/scripts/release_ppa.sh index 2fd286fd..8e9dc282 100755 --- a/scripts/release_ppa.sh +++ b/scripts/release_ppa.sh @@ -56,13 +56,13 @@ commithash=`git rev-parse --short HEAD` committimestamp=`git show --format=%ci HEAD | head -n 1` commitdate=`git show --format=%ci HEAD | head -n 1 | cut - -b1-10` -# TODO store the commit hash in a file so that the build info mechanism can pick it up even without git - +echo "$commithash" > commit_hash.txt if [ $branch = develop ] then debversion="$version-nightly-$commitdate-$commithash" else debversion="$version" + echo -n > prerelease.txt # proper release fi # gzip will create different tars all the time and we are not allowed diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index 557d496a..81332f4f 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -114,7 +114,7 @@ BOOST_AUTO_TEST_CASE(location_test) shared_ptr<string const> n = make_shared<string>("source"); AssemblyItems items = compileContract(sourceCode); vector<SourceLocation> locations = - vector<SourceLocation>(17, SourceLocation(2, 75, n)) + + vector<SourceLocation>(18, SourceLocation(2, 75, n)) + vector<SourceLocation>(28, SourceLocation(20, 72, n)) + vector<SourceLocation>{SourceLocation(42, 51, n), SourceLocation(65, 67, n)} + vector<SourceLocation>(4, SourceLocation(58, 67, n)) + diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index b21e03eb..cfc7b9bd 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -273,15 +273,6 @@ BOOST_AUTO_TEST_CASE(const_function) checkInterface(sourceCode, interface); } -BOOST_AUTO_TEST_CASE(exclude_fallback_function) -{ - char const* sourceCode = "contract test { function() {} }"; - - char const* interface = "[]"; - - checkInterface(sourceCode, interface); -} - BOOST_AUTO_TEST_CASE(events) { char const* sourceCode = "contract test {\n" @@ -626,6 +617,25 @@ BOOST_AUTO_TEST_CASE(library_function) checkInterface(sourceCode, interface); } +BOOST_AUTO_TEST_CASE(include_fallback_function) +{ + char const* sourceCode = R"( + contract test { + function() {} + } + )"; + + char const* interface = R"( + [ + { + "constant" : false, + "type" : "fallback" + } + ] + )"; + checkInterface(sourceCode, interface); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8a61907a..a370aafa 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2053,6 +2053,7 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) { char const* sourceCode = R"( contract helper { + function() { } // can receive ether } contract test { helper h; @@ -2540,6 +2541,19 @@ BOOST_AUTO_TEST_CASE(inherited_fallback_function) BOOST_CHECK(callContractFunction("getData()") == encodeArgs(1)); } +BOOST_AUTO_TEST_CASE(default_fallback_throws) +{ + char const* sourceCode = R"( + contract A { + function f() returns (bool) { + return this.call(); + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(0)); +} + BOOST_AUTO_TEST_CASE(event) { char const* sourceCode = R"( @@ -5943,6 +5957,7 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library) function f(address x) returns (bool) { return x.send(1); } + function () {} } )"; compileAndRun(sourceCode, 0, "lib"); diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index f0ab07c5..fdd8d7f4 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1102,6 +1102,16 @@ BOOST_AUTO_TEST_CASE(fallback_function_with_arguments) BOOST_CHECK(expectError(text) == Error::Type::TypeError); } +BOOST_AUTO_TEST_CASE(fallback_function_in_library) +{ + char const* text = R"( + library C { + function() {} + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::TypeError); +} + BOOST_AUTO_TEST_CASE(fallback_function_with_return_parameters) { char const* text = R"( |