diff options
1044 files changed, 11515 insertions, 12525 deletions
diff --git a/circle.yml b/.circleci/config.yml index 30dccead..c577be7b 100644 --- a/circle.yml +++ b/.circleci/config.yml @@ -158,6 +158,23 @@ jobs: - store_artifacts: *solc_artifact - persist_to_workspace: *all_artifacts + test_check_spelling: + docker: + - image: circleci/python:3.6 + environment: + TERM: xterm + steps: + - checkout + - attach_workspace: + at: build + - run: + name: Install dependencies + command: | + pip install --user codespell + - run: + name: Check spelling + command: ~/.local/bin/codespell -S "*.enc,.git" -I ./scripts/codespell_whitelist.txt + test_x86_linux: docker: - image: buildpack-deps:artful @@ -220,6 +237,7 @@ workflows: version: 2 build_all: jobs: + - test_check_spelling: *build_on_tags - build_emscripten: *build_on_tags - test_emscripten_solcjs: <<: *build_on_tags diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..ab452ecf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +# out-of-tree builds usually go here. This helps improving performance of uploading +# the build context to the docker image build server +/build + +# in-tree builds +/deps @@ -35,6 +35,7 @@ build/ docs/_build docs/utils/__pycache__ docs/utils/*.pyc +/deps/downloads/ # vim stuff *.swp @@ -43,3 +44,5 @@ docs/utils/*.pyc .idea browse.VC.db CMakeLists.txt.user +/CMakeSettings.json +/.vs diff --git a/Changelog.md b/Changelog.md index c31aced2..b27254a8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,26 +1,75 @@ ### 0.5.0 (unreleased) +How to update your code: + * Change every ``.call()`` to a ``.call("")`` and every ``.call(signature, a, b, c)`` to use ``.call(abi.encodeWithSignature(signature, a, b, c))`` (the last one only works for value types). + * Change every ``keccak256(a, b, c)`` to ``keccak256(abi.encodePacked(a, b, c))``. + * Make your fallback functions ``external``. + * Explicitly state the storage location for local variables of struct and array types, e.g. change ``uint[] x = m_x`` to ``uint[] storage x = m_x``. + Breaking Changes: - * Disallow conversions between bytesX and uintY of different size. + * ABI Encoder: Properly pad data from calldata (``msg.data`` and external function parameters). Use ``abi.encodePacked`` for unpadded encoding. + * Code Generator: Signed right shift uses proper arithmetic shift, i.e. rounding towards negative infinity. Warning: this may silently change the semantics of existing code! + * Code Generator: Revert at runtime if calldata is too short or points out of bounds. This is done inside the ``ABI decoder`` and therefore also applies to ``abi.decode()``. + * Code Generator: Use ``STATICCALL`` for ``pure`` and ``view`` functions. This was already the case in the experimental 0.5.0 mode. + * Commandline interface: Remove obsolete ``--formal`` option. + * Commandline interface: Rename the ``--julia`` option to ``--yul``. * Commandline interface: Require ``-`` if standard input is used as source. * General: ``continue`` in a ``do...while`` loop jumps to the condition (it used to jump to the loop body). Warning: this may silently change the semantics of existing code. - * Type Checker: Disallow arithmetic operations for Boolean variables. - -Features: - -Bugfixes: - + * General: Disallow declaring empty structs. + * General: Disallow raw ``callcode`` (was already deprecated in 0.4.12). It is still possible to use it via inline assembly. + * General: Disallow ``var`` keyword. + * General: Disallow ``sha3`` and ``suicide`` aliases. + * General: Disallow the ``years`` unit denomination (was already deprecated in 0.4.24) + * General: Introduce ``emit`` as a keyword instead of parsing it as identifier. + * General: New keywords: ``calldata`` + * General: New reserved keywords: ``alias``, ``apply``, ``auto``, ``copyof``, ``define``, ``immutable``, + ``implements``, ``macro``, ``mutable``, ``override``, ``partial``, ``promise``, ``reference``, ``sealed``, + ``sizeof``, ``supports``, ``typedef`` and ``unchecked``. + * General: Remove assembly instruction aliases ``sha3`` and ``suicide`` + * General: C99-style scoping rules are enforced now. This was already the case in the experimental 0.5.0 mode. + * General: Disallow combining hex numbers with unit denominations (e.g. ``0x1e wei``). This was already the case in the experimental 0.5.0 mode. + * Optimizer: Remove the no-op ``PUSH1 0 NOT AND`` sequence. + * Parser: Disallow trailing dots that are not followed by a number. + * Parser: Remove ``constant`` as function state mutability modifer. + * Type Checker: Disallow assignments between tuples with different numbers of components. This was already the case in the experimental 0.5.0 mode. + * Type Checker: Disallow values for constants that are not compile-time constants. This was already the case in the experimental 0.5.0 mode. + * Type Checker: Disallow arithmetic operations for boolean variables. + * Type Checker: Disallow tight packing of literals. This was already the case in the experimental 0.5.0 mode. + * Type Checker: Disallow conversions between ``bytesX`` and ``uintY`` of different size. + * Type Checker: Disallow empty tuple components. This was partly already the case in the experimental 0.5.0 mode. + * Type Checker: Disallow multi-variable declarations with mismatching number of values. This was already the case in the experimental 0.5.0 mode. + * Type Checker: Disallow specifying base constructor arguments multiple times in the same inheritance hierarchy. This was already the case in the experimental 0.5.0 mode. + * Type Checker: Disallow calling constructor with wrong argument count. This was already the case in the experimental 0.5.0 mode. + * Type Checker: Disallow uninitialized storage variables. This was already the case in the experimental 0.5.0 mode. + * Type Checker: Only accept a single ``bytes`` type for ``.call()`` (and family), ``keccak256()``, ``sha256()`` and ``ripemd160()``. + * Type Checker: Fallback function must be external. This was already the case in the experimental 0.5.0 mode. + * Remove obsolete ``std`` directory from the Solidity repository. This means accessing ``https://github.com/ethereum/soldity/blob/develop/std/*.sol`` (or ``https://github.com/ethereum/solidity/std/*.sol`` in Remix) will not be possible. + * References Resolver: Turn missing storage locations into an error. This was already the case in the experimental 0.5.0 mode. + * Syntax Checker: Named return values in function types are an error. + * Syntax Checker: Disallow unary ``+``. This was already the case in the experimental 0.5.0 mode. + * View Pure Checker: Strictly enfore state mutability. This was already the case in the experimental 0.5.0 mode. +Language Features: + * General: Allow appending ``calldata`` keyword to types, to explicitly specify data location for arguments of external functions. + * General: Support ``pop()`` for storage arrays. + * General: Scoping rules now follow the C99-style. -Features: - +Compiler Features: + * C API (``libsolc``): Export the ``solidity_license``, ``solidity_version`` and ``solidity_compile`` methods. + * Type Checker: Show named argument in case of error. + * Tests: Determine transaction status during IPC calls. + * Code Generator: Allocate and free local variables according to their scope. Bugfixes: + * Tests: Fix chain parameters to make ipc tests work with newer versions of cpp-ethereum. + * Code Generator: Fix allocation of byte arrays (zeroed out too much memory). + * Fix NatSpec json output for `@notice` and `@dev` tags on contract definitions. + * Type Checker: Consider fixed size arrays when checking for recursive structs. + * Type System: Allow arbitrary exponents for literals with a mantissa of zero. ### 0.4.24 (2018-05-16) - Language Features: * Code Generator: Use native shift instructions on target Constantinople. * General: Allow multiple variables to be declared as part of a tuple assignment, e.g. ``(uint a, uint b) = ...``. @@ -669,7 +718,7 @@ Bugfixes: * Conditional: `x ? y : z` * Bugfix: Fixed several bugs where the optimizer generated invalid code. * Bugfix: Enums and structs were not accessible to other contracts. - * Bugfix: Fixed segfault connected to function paramater types, appeared during gas estimation. + * Bugfix: Fixed segfault connected to function parameter types, appeared during gas estimation. * Bugfix: Type checker crash for wrong number of base constructor parameters. * Bugfix: Allow function overloads with different array types. * Bugfix: Allow assignments of type `(x) = 7`. diff --git a/ReleaseChecklist.md b/ReleaseChecklist.md index ebdb7539..b84ae4c4 100644 --- a/ReleaseChecklist.md +++ b/ReleaseChecklist.md @@ -8,7 +8,7 @@ Checklist for making a release: - [ ] Make a final check that there are no platform-dependency issues in the ``solc-test-bytecode`` repository. - [ ] Wait for the tests for the commit on ``release``, create a release in Github, creating the tag. - [ ] Thank voluntary contributors in the Github release page (use ``git shortlog -s -n -e origin/release..origin/develop``). - - [ ] Wait for the CI runs on the tag itself (they should push artefacts onto the Github release page). + - [ ] Wait for the CI runs on the tag itself (they should push artifacts onto the Github release page). - [ ] Run ``scripts/release_ppa.sh release`` to create the PPA release (you need the relevant openssl key). - [ ] Check that the Docker release was pushed to Docker Hub (this still seems to have problems, run ``./scripts/docker_deploy_manual.sh release``). - [ ] Update the homebrew realease in https://github.com/ethereum/homebrew-ethereum/blob/master/solidity.rb (version and hash) diff --git a/cmake/EthCompilerSettings.cmake b/cmake/EthCompilerSettings.cmake index 683d1d2e..468a8593 100644 --- a/cmake/EthCompilerSettings.cmake +++ b/cmake/EthCompilerSettings.cmake @@ -90,7 +90,7 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA if (EMSCRIPTEN) # Do not emit a separate memory initialiser file set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --memory-init-file 0") - # Leave only exported symbols as public and agressively remove others + # Leave only exported symbols as public and aggressively remove others set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections -Wl,--gc-sections -fvisibility=hidden") # Optimisation level set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") @@ -132,17 +132,6 @@ elseif (DEFINED MSVC) add_compile_options(-D_WIN32_WINNT=0x0600) # declare Windows Vista API requirement add_compile_options(-DNOMINMAX) # undefine windows.h MAX && MIN macros cause it cause conflicts with std::min && std::max functions - # Always use Release variant of C++ runtime. - # We don't want to provide Debug variants of all dependencies. Some default - # flags set by CMake must be tweaked. - string(REPLACE "/MDd" "/MD" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "/D_DEBUG" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "/MDd" "/MD" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - string(REPLACE "/D_DEBUG" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - string(REPLACE "/RTC1" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS OFF) - # disable empty object file warning set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221") # warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/SAFESEH' specification diff --git a/cmake/jsoncpp.cmake b/cmake/jsoncpp.cmake index cc2da7e7..e886c609 100644 --- a/cmake/jsoncpp.cmake +++ b/cmake/jsoncpp.cmake @@ -6,15 +6,8 @@ else() set(JSONCPP_CMAKE_COMMAND ${CMAKE_COMMAND}) endif() -include(GNUInstallDirs) -set(libdir ${CMAKE_INSTALL_LIBDIR}) -if(CMAKE_LIBRARY_ARCHITECTURE) - # Do not use Debian multiarch library dir. - string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" libdir ${libdir}) -endif() - set(prefix "${CMAKE_BINARY_DIR}/deps") -set(JSONCPP_LIBRARY "${prefix}/${libdir}/${CMAKE_STATIC_LIBRARY_PREFIX}jsoncpp${CMAKE_STATIC_LIBRARY_SUFFIX}") +set(JSONCPP_LIBRARY "${prefix}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}jsoncpp${CMAKE_STATIC_LIBRARY_SUFFIX}") set(JSONCPP_INCLUDE_DIR "${prefix}/include") if(NOT MSVC) @@ -36,14 +29,13 @@ ExternalProject_Add(jsoncpp-project CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_INSTALL_LIBDIR=lib # Build static lib but suitable to be included in a shared lib. -DCMAKE_POSITION_INDEPENDENT_CODE=${BUILD_SHARED_LIBS} -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF -DCMAKE_CXX_FLAGS=${JSONCPP_EXTRA_FLAGS} - # Overwrite build and install commands to force Release build on MSVC. - BUILD_COMMAND cmake --build <BINARY_DIR> --config Release - INSTALL_COMMAND cmake --build <BINARY_DIR> --config Release --target install + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${byproducts} ) diff --git a/docs/_templates/layout.html b/docs/_templates/layout.html index c5886276..1db4ef92 100644 --- a/docs/_templates/layout.html +++ b/docs/_templates/layout.html @@ -1,6 +1,6 @@ {% extends "!layout.html" %} {% block menu %} - <a href="genindex.html">Keyword Index</a> {{ super() }} + <a href="genindex.html">Keyword Index</a> {% endblock %} diff --git a/docs/abi-spec.rst b/docs/abi-spec.rst index 8591a07f..ab1650d8 100644 --- a/docs/abi-spec.rst +++ b/docs/abi-spec.rst @@ -2,14 +2,14 @@ .. _ABI: -****************************************** -Application Binary Interface Specification -****************************************** +************************** +Contract ABI Specification +************************** Basic Design ============ -The Application Binary Interface is the standard way to interact with contracts in the Ethereum ecosystem, both +The Contract Application Binary Interface (ABI) is the standard way to interact with contracts in the Ethereum ecosystem, both from outside the blockchain and for contract-to-contract interaction. Data is encoded according to its type, as described in this specification. The encoding is not self describing and thus requires a schema in order to decode. @@ -72,8 +72,7 @@ The following non-fixed-size types exist: - ``<type>[]``: a variable-length array of elements of the given type. -Types can be combined to a tuple by enclosing a finite non-negative number -of them inside parentheses, separated by commas: +Types can be combined to a tuple by enclosing them inside parentheses, separated by commas: - ``(T1,T2,...,Tn)``: tuple consisting of the types ``T1``, ..., ``Tn``, ``n >= 0`` @@ -278,6 +277,106 @@ All together, the encoding is (newline after function selector and each 32-bytes 000000000000000000000000000000000000000000000000000000000000000d 48656c6c6f2c20776f726c642100000000000000000000000000000000000000 +Let us apply the same principle to encode the data for a function with a signature ``g(uint[][],string[])`` with values ``([[1, 2], [3]], ["one", "two", "three"])`` but start from the most atomic parts of the encoding: + +First we encode the length and data of the first embedded dynamic array ``[1, 2]`` of the first root array ``[[1, 2], [3]]``: + + - ``0x0000000000000000000000000000000000000000000000000000000000000002`` (number of elements in the first array, 2; the elements themselves are ``1`` and ``2``) + - ``0x0000000000000000000000000000000000000000000000000000000000000001`` (first element) + - ``0x0000000000000000000000000000000000000000000000000000000000000002`` (second element) + +Then we encode the length and data of the second embedded dynamic array ``[3]`` of the first root array ``[[1, 2], [3]]``: + + - ``0x0000000000000000000000000000000000000000000000000000000000000001`` (number of elements in the second array, 1; the element is ``3``) + - ``0x0000000000000000000000000000000000000000000000000000000000000003`` (first element) + +Then we need to find the offsets ``a`` and ``b`` for their respective dynamic arrays ``[1, 2]`` and ``[3]``. To calculate the offsets we can take a look at the encoded data of the first root array ``[[1, 2], [3]]`` enumerating each line in the encoding: + +:: + + 0 - a - offset of [1, 2] + 1 - b - offset of [3] + 2 - 0000000000000000000000000000000000000000000000000000000000000002 - count for [1, 2] + 3 - 0000000000000000000000000000000000000000000000000000000000000001 - encoding of 1 + 4 - 0000000000000000000000000000000000000000000000000000000000000002 - encoding of 2 + 5 - 0000000000000000000000000000000000000000000000000000000000000001 - count for [3] + 6 - 0000000000000000000000000000000000000000000000000000000000000003 - encoding of 3 + +Offset ``a`` points to the start of the content of the array ``[1, 2]`` which is line 2 (64 bytes); thus ``a = 0x0000000000000000000000000000000000000000000000000000000000000040``. + +Offset ``b`` points to the start of the content of the array ``[3]`` which is line 5 (160 bytes); thus ``b = 0x00000000000000000000000000000000000000000000000000000000000000a0``. + + +Then we encode the embedded strings of the second root array: + + - ``0x0000000000000000000000000000000000000000000000000000000000000003`` (number of characters in word ``"one"``) + - ``0x6f6e650000000000000000000000000000000000000000000000000000000000`` (utf8 representation of word ``"one"``) + - ``0x0000000000000000000000000000000000000000000000000000000000000003`` (number of characters in word ``"two"``) + - ``0x74776f0000000000000000000000000000000000000000000000000000000000`` (utf8 representation of word ``"two"``) + - ``0x0000000000000000000000000000000000000000000000000000000000000005`` (number of characters in word ``"three"``) + - ``0x7468726565000000000000000000000000000000000000000000000000000000`` (utf8 representation of word ``"three"``) + +In parallel to the first root array, since strings are dynamic elements we need to find their offsets ``c``, ``d`` and ``e``: + +:: + + 0 - c - offset for "one" + 1 - d - offset for "two" + 2 - e - offset for "three" + 3 - 0000000000000000000000000000000000000000000000000000000000000003 - count for "one" + 4 - 6f6e650000000000000000000000000000000000000000000000000000000000 - encoding of "one" + 5 - 0000000000000000000000000000000000000000000000000000000000000003 - count for "two" + 6 - 74776f0000000000000000000000000000000000000000000000000000000000 - encoding of "two" + 7 - 0000000000000000000000000000000000000000000000000000000000000005 - count for "three" + 8 - 7468726565000000000000000000000000000000000000000000000000000000 - encoding of "three" + +Offset ``c`` points to the start of the content of the string ``"one"`` which is line 3 (96 bytes); thus ``c = 0x0000000000000000000000000000000000000000000000000000000000000060``. + +Offset ``d`` points to the start of the content of the string ``"two"`` which is line 5 (160 bytes); thus ``d = 0x00000000000000000000000000000000000000000000000000000000000000a0``. + +Offset ``e`` points to the start of the content of the string ``"three"`` which is line 7 (224 bytes); thus ``e = 0x00000000000000000000000000000000000000000000000000000000000000e0``. + + +Note that the encodings of the embedded elements of the root arrays are not dependent on each other and have the same encodings for a function with a signature ``g(string[],uint[][])``. + +Then we encode the length of the first root array: + + - ``0x0000000000000000000000000000000000000000000000000000000000000002`` (number of elements in the first root array, 2; the elements themselves are ``[1, 2]`` and ``[3]``) + +Then we encode the length of the second root array: + + - ``0x0000000000000000000000000000000000000000000000000000000000000003`` (number of strings in the second root array, 3; the strings themselves are ``"one"``, ``"two"`` and ``"three"``) + +Finally we find the offsets ``f`` and ``g`` for their respective root dynamic arrays ``[[1, 2], [3]]`` and ``["one", "two", "three"]``, and assemble parts in the correct order: + +:: + + 0x2289b18c - function signature + 0 - f - offset of [[1, 2], [3]] + 1 - g - offset of ["one", "two", "three"] + 2 - 0000000000000000000000000000000000000000000000000000000000000002 - count for [[1, 2], [3]] + 3 - 0000000000000000000000000000000000000000000000000000000000000040 - offset of [1, 2] + 4 - 00000000000000000000000000000000000000000000000000000000000000a0 - offset of [3] + 5 - 0000000000000000000000000000000000000000000000000000000000000002 - count for [1, 2] + 6 - 0000000000000000000000000000000000000000000000000000000000000001 - encoding of 1 + 7 - 0000000000000000000000000000000000000000000000000000000000000002 - encoding of 2 + 8 - 0000000000000000000000000000000000000000000000000000000000000001 - count for [3] + 9 - 0000000000000000000000000000000000000000000000000000000000000003 - encoding of 3 + 10 - 0000000000000000000000000000000000000000000000000000000000000003 - count for ["one", "two", "three"] + 11 - 0000000000000000000000000000000000000000000000000000000000000060 - offset for "one" + 12 - 00000000000000000000000000000000000000000000000000000000000000a0 - offset for "two" + 13 - 00000000000000000000000000000000000000000000000000000000000000e0 - offset for "three" + 14 - 0000000000000000000000000000000000000000000000000000000000000003 - count for "one" + 15 - 6f6e650000000000000000000000000000000000000000000000000000000000 - encoding of "one" + 16 - 0000000000000000000000000000000000000000000000000000000000000003 - count for "two" + 17 - 74776f0000000000000000000000000000000000000000000000000000000000 - encoding of "two" + 18 - 0000000000000000000000000000000000000000000000000000000000000005 - count for "three" + 19 - 7468726565000000000000000000000000000000000000000000000000000000 - encoding of "three" + +Offset ``f`` points to the start of the content of the array ``[[1, 2], [3]]`` which is line 2 (64 bytes); thus ``f = 0x0000000000000000000000000000000000000000000000000000000000000040``. + +Offset ``g`` points to the start of the content of the array ``["one", "two", "three"]`` which is line 10 (320 bytes); thus ``g = 0x0000000000000000000000000000000000000000000000000000000000000140``. + Events ====== @@ -338,13 +437,13 @@ For example, :: - pragma solidity ^0.4.0; + pragma solidity >0.4.24; contract Test { - function Test() public { b = 0x12345678901234567890123456789012; } + constructor() public { b = 0x12345678901234567890123456789012; } event Event(uint indexed a, bytes32 b); event Event2(uint indexed a, bytes32 b); - function foo(uint a) public { Event(a, b); } + function foo(uint a) public { emit Event(a, b); } bytes32 b; } @@ -460,7 +559,7 @@ would result in the JSON: Non-standard Packed Mode ======================== -Solidity supports a non-standard packed mode where: +Through ``abi.encodePacked()``, Solidity supports a non-standard packed mode where: - no :ref:`function selector <abi_function_selector>` is encoded, - types shorter than 32 bytes are neither zero padded nor sign extended and @@ -478,3 +577,9 @@ More specifically, each statically-sized type takes as many bytes as its range h and dynamically-sized types like ``string``, ``bytes`` or ``uint[]`` are encoded without their length field. This means that the encoding is ambiguous as soon as there are two dynamically-sized elements. + +Note that constants will be packed using the minimum number of bytes required to store them. +This means that, for example, ``abi.encodePacked(0) == abi.encodePacked(uint8(0)) == hex"00"`` and +``abi.encodePacked(0x12345678) == abi.encodePacked(uint32(0x12345678)) == hex"12345678"``. + +If padding is needed, explicit type conversions can be used: ``abi.encodePacked(uint16(0x12)) == hex"0012"``. diff --git a/docs/assembly.rst b/docs/assembly.rst index f7b721ab..cf114c12 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -212,16 +212,14 @@ In the grammar, opcodes are represented as pre-defined identifiers. +-------------------------+-----+---+-----------------------------------------------------------------+ | sar(x, y) | | C | arithmetic shift right y by x bits | +-------------------------+-----+---+-----------------------------------------------------------------+ -| addmod(x, y, m) | | F | (x + y) % m with arbitrary precision arithmetics | +| addmod(x, y, m) | | F | (x + y) % m with arbitrary precision arithmetic | +-------------------------+-----+---+-----------------------------------------------------------------+ -| mulmod(x, y, m) | | F | (x * y) % m with arbitrary precision arithmetics | +| mulmod(x, y, m) | | F | (x * y) % m with arbitrary precision arithmetic | +-------------------------+-----+---+-----------------------------------------------------------------+ | signextend(i, x) | | F | sign extend from (i*8+7)th bit counting from least significant | +-------------------------+-----+---+-----------------------------------------------------------------+ | keccak256(p, n) | | F | keccak(mem[p...(p+n))) | +-------------------------+-----+---+-----------------------------------------------------------------+ -| sha3(p, n) | | F | keccak(mem[p...(p+n))) | -+-------------------------+-----+---+-----------------------------------------------------------------+ | jump(label) | `-` | F | jump to label / code position | +-------------------------+-----+---+-----------------------------------------------------------------+ | jumpi(label, cond) | `-` | F | jump to label if cond is nonzero | @@ -230,13 +228,13 @@ In the grammar, opcodes are represented as pre-defined identifiers. +-------------------------+-----+---+-----------------------------------------------------------------+ | pop(x) | `-` | F | remove the element pushed by x | +-------------------------+-----+---+-----------------------------------------------------------------+ -| dup1 ... dup16 | | F | copy ith stack slot to the top (counting from top) | +| dup1 ... dup16 | | F | copy nth stack slot to the top (counting from top) | +-------------------------+-----+---+-----------------------------------------------------------------+ -| swap1 ... swap16 | `*` | F | swap topmost and ith stack slot below it | +| swap1 ... swap16 | `*` | F | swap topmost and nth stack slot below it | +-------------------------+-----+---+-----------------------------------------------------------------+ -| mload(p) | | F | mem[p..(p+32)) | +| mload(p) | | F | mem[p...(p+32)) | +-------------------------+-----+---+-----------------------------------------------------------------+ -| mstore(p, v) | `-` | F | mem[p..(p+32)) := v | +| mstore(p, v) | `-` | F | mem[p...(p+32)) := v | +-------------------------+-----+---+-----------------------------------------------------------------+ | mstore8(p, v) | `-` | F | mem[p] := v & 0xff (only modifies a single byte) | +-------------------------+-----+---+-----------------------------------------------------------------+ @@ -274,16 +272,16 @@ In the grammar, opcodes are represented as pre-defined identifiers. +-------------------------+-----+---+-----------------------------------------------------------------+ | returndatacopy(t, f, s) | `-` | B | copy s bytes from returndata at position f to mem at position t | +-------------------------+-----+---+-----------------------------------------------------------------+ -| create(v, p, s) | | F | create new contract with code mem[p..(p+s)) and send v wei | +| create(v, p, s) | | F | create new contract with code mem[p...(p+s)) and send v wei | | | | | and return the new address | +-------------------------+-----+---+-----------------------------------------------------------------+ -| create2(v, n, p, s) | | C | create new contract with code mem[p..(p+s)) at address | -| | | | keccak256(<address> . n . keccak256(mem[p..(p+s))) and send v | +| create2(v, n, p, s) | | C | create new contract with code mem[p...(p+s)) at address | +| | | | keccak256(<address> . n . keccak256(mem[p...(p+s))) and send v | | | | | wei and return the new address | +-------------------------+-----+---+-----------------------------------------------------------------+ -| call(g, a, v, in, | | F | call contract at address a with input mem[in..(in+insize)) | +| call(g, a, v, in, | | F | call contract at address a with input mem[in...(in+insize)) | | insize, out, outsize) | | | providing g gas and v wei and output area | -| | | | mem[out..(out+outsize)) returning 0 on error (eg. out of gas) | +| | | | mem[out...(out+outsize)) returning 0 on error (eg. out of gas) | | | | | and 1 on success | +-------------------------+-----+---+-----------------------------------------------------------------+ | callcode(g, a, v, in, | | F | identical to ``call`` but only use the code from a and stay | @@ -295,23 +293,23 @@ In the grammar, opcodes are represented as pre-defined identifiers. | staticcall(g, a, in, | | B | identical to ``call(g, a, 0, in, insize, out, outsize)`` but do | | insize, out, outsize) | | | not allow state modifications | +-------------------------+-----+---+-----------------------------------------------------------------+ -| return(p, s) | `-` | F | end execution, return data mem[p..(p+s)) | +| return(p, s) | `-` | F | end execution, return data mem[p...(p+s)) | +-------------------------+-----+---+-----------------------------------------------------------------+ -| revert(p, s) | `-` | B | end execution, revert state changes, return data mem[p..(p+s)) | +| revert(p, s) | `-` | B | end execution, revert state changes, return data mem[p...(p+s)) | +-------------------------+-----+---+-----------------------------------------------------------------+ | selfdestruct(a) | `-` | F | end execution, destroy current contract and send funds to a | +-------------------------+-----+---+-----------------------------------------------------------------+ | invalid | `-` | F | end execution with invalid instruction | +-------------------------+-----+---+-----------------------------------------------------------------+ -| log0(p, s) | `-` | F | log without topics and data mem[p..(p+s)) | +| log0(p, s) | `-` | F | log without topics and data mem[p...(p+s)) | +-------------------------+-----+---+-----------------------------------------------------------------+ -| log1(p, s, t1) | `-` | F | log with topic t1 and data mem[p..(p+s)) | +| log1(p, s, t1) | `-` | F | log with topic t1 and data mem[p...(p+s)) | +-------------------------+-----+---+-----------------------------------------------------------------+ -| log2(p, s, t1, t2) | `-` | F | log with topics t1, t2 and data mem[p..(p+s)) | +| log2(p, s, t1, t2) | `-` | F | log with topics t1, t2 and data mem[p...(p+s)) | +-------------------------+-----+---+-----------------------------------------------------------------+ -| log3(p, s, t1, t2, t3) | `-` | F | log with topics t1, t2, t3 and data mem[p..(p+s)) | +| log3(p, s, t1, t2, t3) | `-` | F | log with topics t1, t2, t3 and data mem[p...(p+s)) | +-------------------------+-----+---+-----------------------------------------------------------------+ -| log4(p, s, t1, t2, t3, | `-` | F | log with topics t1, t2, t3, t4 and data mem[p..(p+s)) | +| log4(p, s, t1, t2, t3, | `-` | F | log with topics t1, t2, t3, t4 and data mem[p...(p+s)) | | t4) | | | | +-------------------------+-----+---+-----------------------------------------------------------------+ | origin | | F | transaction sender | diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst index 739e136f..7c38b0e7 100644 --- a/docs/common-patterns.rst +++ b/docs/common-patterns.rst @@ -28,7 +28,7 @@ become the new richest. :: - pragma solidity ^0.4.11; + pragma solidity >0.4.24; contract WithdrawalContract { address public richest; @@ -36,7 +36,7 @@ become the new richest. mapping (address => uint) pendingWithdrawals; - function WithdrawalContract() public payable { + constructor() public payable { richest = msg.sender; mostSent = msg.value; } @@ -65,13 +65,13 @@ This is as opposed to the more intuitive sending pattern: :: - pragma solidity ^0.4.11; + pragma solidity >0.4.24; contract SendContract { address public richest; uint public mostSent; - function SendContract() public payable { + constructor() public payable { richest = msg.sender; mostSent = msg.value; } diff --git a/docs/conf.py b/docs/conf.py index fdb67367..55f4f1a8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,6 +27,8 @@ def setup(sphinx): from pygments_lexer_solidity import SolidityLexer sphinx.add_lexer('Solidity', SolidityLexer()) + sphinx.add_stylesheet('css/custom.css') + # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. diff --git a/docs/contracts.rst b/docs/contracts.rst index 7f1899fa..fa6df6bf 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -20,7 +20,7 @@ Contracts can be created "from outside" via Ethereum transactions or from within IDEs, such as `Remix <https://remix.ethereum.org/>`_, make the creation process seamless using UI elements. -Creating contracts programatically on Ethereum is best done via using the JavaScript API `web3.js <https://github.com/ethereum/web3.js>`_. +Creating contracts programmatically on Ethereum is best done via using the JavaScript API `web3.js <https://github.com/ethereum/web3.js>`_. As of today it has a method called `web3.eth.Contract <https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#new-contract>`_ to facilitate contract creation. @@ -113,7 +113,7 @@ This means that cyclic creation dependencies are impossible. { // Check some arbitrary condition. address tokenAddress = msg.sender; - return (keccak256(newOwner) & 0xff) == (bytes20(tokenAddress) & 0xff); + return (keccak256(abi.encodePacked(newOwner)) & 0xff) == (bytes20(tokenAddress) & 0xff); } } @@ -194,10 +194,10 @@ In the following example, ``D``, can call ``c.getData()`` to retrieve the value contract C { uint private data; - function f(uint a) private returns(uint b) { return a + 1; } + function f(uint a) private pure returns(uint b) { return a + 1; } function setData(uint a) public { data = a; } - function getData() public returns(uint) { return data; } - function compute(uint a, uint b) internal returns (uint) { return a+b; } + function getData() public view returns(uint) { return data; } + function compute(uint a, uint b) internal pure returns (uint) { return a + b; } } contract D { @@ -301,10 +301,10 @@ inheritable properties of contracts and may be overridden by derived contracts. :: - pragma solidity ^0.4.22; + pragma solidity >0.4.24; contract owned { - function owned() public { owner = msg.sender; } + constructor() public { owner = msg.sender; } address owner; // This contract only defines a modifier but does not use @@ -346,7 +346,7 @@ inheritable properties of contracts and may be overridden by derived contracts. mapping (address => bool) registeredAddresses; uint price; - function Register(uint initialPrice) public { price = initialPrice; } + constructor(uint initialPrice) public { price = initialPrice; } // It is important to also provide the // `payable` keyword here, otherwise the function will @@ -377,7 +377,7 @@ inheritable properties of contracts and may be overridden by derived contracts. /// The `return 7` statement assigns 7 to the return value but still /// executes the statement `locked = false` in the modifier. function f() public noReentrancy returns (uint) { - require(msg.sender.call()); + require(msg.sender.call("")); return 7; } } @@ -406,7 +406,7 @@ Constant State Variables State variables can be declared as ``constant``. In this case, they have to be assigned from an expression which is a constant at compile time. Any expression -that accesses storage, blockchain data (e.g. ``now``, ``this.balance`` or +that accesses storage, blockchain data (e.g. ``now``, ``address(this).balance`` or ``block.number``) or execution data (``msg.value`` or ``gasleft()``) or make calls to external contracts are disallowed. Expressions that might have a side-effect on memory allocation are allowed, but those that @@ -451,6 +451,10 @@ View Functions Functions can be declared ``view`` in which case they promise not to modify the state. +.. note:: + If the compiler's EVM target is Byzantium or newer (default) the opcode + ``STATICCALL`` is used. + The following statements are considered modifying the state: #. Writing to state variables. @@ -464,7 +468,7 @@ The following statements are considered modifying the state: :: - pragma solidity ^0.4.16; + pragma solidity >0.4.24; contract C { function f(uint a, uint b) public view returns (uint) { @@ -473,20 +477,18 @@ The following statements are considered modifying the state: } .. note:: - ``constant`` on functions is an alias to ``view``, but this is deprecated and will be dropped in version 0.5.0. + ``constant`` on functions used to be an alias to ``view``, but this was dropped in version 0.5.0. .. note:: Getter methods are marked ``view``. .. note:: - If invalid explicit type conversions are used, state modifications are possible - even though a ``view`` function was called. - You can switch the compiler to use ``STATICCALL`` when calling such functions and thus - prevent modifications to the state on the level of the EVM by adding - ``pragma experimental "v0.5.0";`` - -.. warning:: - The compiler does not enforce yet that a ``view`` method is not modifying state. It raises a warning though. + Prior to version 0.5.0, the compiler did not use the ``STATICCALL`` opcode + for ``view`` functions. + This enabled state modifications in ``view`` functions through the use of + invalid explicit type conversions. + By using ``STATICCALL`` for ``view`` functions, modifications to the + state are prevented on the level of the EVM. .. index:: ! pure function, function;pure @@ -497,17 +499,20 @@ Pure Functions Functions can be declared ``pure`` in which case they promise not to read from or modify the state. +.. note:: + If the compiler's EVM target is Byzantium or newer (default) the opcode ``STATICCALL`` is used. + In addition to the list of state modifying statements explained above, the following are considered reading from the state: #. Reading from state variables. -#. Accessing ``this.balance`` or ``<address>.balance``. +#. Accessing ``address(this).balance`` or ``<address>.balance``. #. Accessing any of the members of ``block``, ``tx``, ``msg`` (with the exception of ``msg.sig`` and ``msg.data``). #. Calling any function not marked ``pure``. #. Using inline assembly that contains certain opcodes. :: - pragma solidity ^0.4.16; + pragma solidity >0.4.24; contract C { function f(uint a, uint b) public pure returns (uint) { @@ -516,11 +521,12 @@ In addition to the list of state modifying statements explained above, the follo } .. note:: - If invalid explicit type conversions are used, state modifications are possible - even though a ``pure`` function was called. - You can switch the compiler to use ``STATICCALL`` when calling such functions and thus - prevent modifications to the state on the level of the EVM by adding - ``pragma experimental "v0.5.0";`` + Prior to version 0.5.0, the compiler did not use the ``STATICCALL`` opcode + for ``pure`` functions. + This enabled state modifications in ``pure`` functions through the use of + invalid explicit type conversions. + By using ``STATICCALL`` for ``pure`` functions, modifications to the + state are prevented on the level of the EVM. .. warning:: It is not possible to prevent functions from reading the state at the level @@ -529,12 +535,15 @@ In addition to the list of state modifying statements explained above, the follo It is a non-circumventable runtime checks done by the EVM. .. warning:: - Before version 0.4.17 the compiler didn't enforce that ``pure`` is not reading the state. + Before version 0.4.17 the compiler did not enforce that ``pure`` is not reading the state. It is a compile-time type check, which can be circumvented doing invalid explicit conversions between contract types, because the compiler can verify that the type of the contract does not do state-changing operations, but it cannot check that the contract that will be called at runtime is actually of that type. +.. warning:: + Before version 0.5.0 the compiler did not enforce that ``view`` is not writing the state. + .. index:: ! fallback function, function;fallback .. _fallback-function: @@ -543,7 +552,7 @@ Fallback Function ================= A contract can have exactly one unnamed function. This function cannot have -arguments and cannot return anything. +arguments, cannot return anything and has to have ``external`` visibility. It is executed on a call to the contract if none of the other functions match the given function identifier (or if no data was supplied at all). @@ -571,7 +580,7 @@ Like any function, the fallback function can execute complex operations as long 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. + you have to implement a payable fallback function. .. warning:: A contract without a payable fallback function can receive Ether as a recipient of a `coinbase transaction` (aka `miner block reward`) @@ -579,11 +588,11 @@ Like any function, the fallback function can execute complex operations as long A contract cannot react to such Ether transfers and thus also cannot reject them. This is a design choice of the EVM and Solidity cannot work around it. - It also means that ``this.balance`` can be higher than the sum of some manual accounting implemented in a contract (i.e. having a counter updated in the fallback function). + It also means that ``address(this).balance`` can be higher than the sum of some manual accounting implemented in a contract (i.e. having a counter updated in the fallback function). :: - pragma solidity ^0.4.0; + pragma solidity >0.4.24; contract Test { // This function is called for all messages sent to @@ -591,7 +600,7 @@ Like any function, the fallback function can execute complex operations as long // Sending Ether to this contract will cause an exception, // because the fallback function does not have the `payable` // modifier. - function() public { x = 1; } + function() external { x = 1; } uint x; } @@ -599,19 +608,18 @@ Like any function, the fallback function can execute complex operations as long // This contract keeps all Ether sent to it with no way // to get it back. contract Sink { - function() public payable { } + function() external payable { } } contract Caller { function callTest(Test test) public { - test.call(0xabcdef01); // hash does not exist + address(test).call(abi.encodeWithSignature("nonExistingFunction()")); // results in test.x becoming == 1. - // The following will not compile, but even - // if someone sends ether to that contract, + // If someone sends ether to that contract, // the transaction will fail and reject the // Ether. - //test.send(2 ether); + address(test).send(2 ether); } } @@ -723,26 +731,22 @@ the contract can only see the last 256 block hashes. Up to three parameters can receive the attribute ``indexed`` which will cause the respective arguments -to be searched for: It is possible to filter for specific values of -indexed arguments in the user interface. - -If arrays (including ``string`` and ``bytes``) are used as indexed arguments, the -Keccak-256 hash of it is stored as topic instead. - -The hash of the signature of the event is one of the topics except if you +to be stored in a special data structure as so-called "topics", which allows them to be searched for, +for example when filtering a sequence of blocks for certain events. Events can always +be filtered by the address of the contract that emitted the event. Also, +the hash of the signature of the event is one of the topics except if you declared the event with ``anonymous`` specifier. This means that it is not possible to filter for specific anonymous events by name. -All non-indexed arguments will be stored in the data part of the log. +If arrays (including ``string`` and ``bytes``) are used as indexed arguments, the +Keccak-256 hash of it is stored as topic instead. This is because a topic +can only hold a single word (32 bytes). -.. note:: - Indexed arguments will not be stored themselves. You can only - search for the values, but it is impossible to retrieve the - values themselves. +All non-indexed arguments will be :ref:`ABI-encoded <ABI>` into the data part of the log. :: - pragma solidity ^0.4.0; + pragma solidity ^0.4.21; contract ClientReceipt { event Deposit( @@ -774,7 +778,7 @@ The use in the JavaScript API would be as follows: // watch for changes event.watch(function(error, result){ // result will contain various information - // including the argumets given to the `Deposit` + // including the arguments given to the `Deposit` // call. if (!error) console.log(result); @@ -994,7 +998,7 @@ default constructor: ``contructor() public {}``. :: - pragma solidity ^0.4.22; + pragma solidity >0.4.24; contract A { uint public a; @@ -1010,24 +1014,8 @@ default constructor: ``contructor() public {}``. A constructor set as ``internal`` causes the contract to be marked as :ref:`abstract <abstract-contract>`. -.. note :: - Prior to version 0.4.22, constructors were defined as functions with the same name as the contract. This syntax is now deprecated. - -:: - - pragma solidity ^0.4.11; - - contract A { - uint public a; - - function A(uint _a) internal { - a = _a; - } - } - - contract B is A(1) { - function B() public {} - } +.. warning :: + Prior to version 0.4.22, constructors were defined as functions with the same name as the contract. This syntax was deprecated and is not allowed anymore in version 0.5.0. .. index:: ! base;constructor @@ -1062,7 +1050,7 @@ constant and defines the behaviour of the contract or describes it. The second way has to be used if the constructor arguments of the base depend on those of the derived contract. Arguments have to be given either in the -inheritance list or in modifier-style in the derived constuctor. +inheritance list or in modifier-style in the derived constructor. Specifying arguments in both places is an error. If a derived contract doesn't specify the arguments to all of its base @@ -1161,11 +1149,11 @@ Interfaces Interfaces are similar to abstract contracts, but they cannot have any functions implemented. There are further restrictions: -#. Cannot inherit other contracts or interfaces. -#. Cannot define constructor. -#. Cannot define variables. -#. Cannot define structs. -#. Cannot define enums. +- Cannot inherit other contracts or interfaces. +- Cannot define constructor. +- Cannot define variables. +- Cannot define structs. +- Cannot define enums. Some of these restrictions might be lifted in the future. @@ -1327,6 +1315,7 @@ custom types without the overhead of external function calls: if (carry > 0) { // too bad, we have to add a limb uint[] memory newLimbs = new uint[](r.limbs.length + 1); + uint i; for (i = 0; i < r.limbs.length; ++i) newLimbs[i] = r.limbs[i]; newLimbs[i] = carry; @@ -1347,9 +1336,9 @@ custom types without the overhead of external function calls: using BigInt for BigInt.bigint; function f() public pure { - var x = BigInt.fromUint(7); - var y = BigInt.fromUint(uint(-1)); - var z = x.add(y); + BigInt.bigint memory x = BigInt.fromUint(7); + BigInt.bigint memory y = BigInt.fromUint(uint(-1)); + BigInt.bigint memory z = x.add(y); } } @@ -1407,22 +1396,23 @@ Using For The directive ``using A for B;`` can be used to attach library functions (from the library ``A``) to any type (``B``). These functions will receive the object they are called on -as their first parameter (like the ``self`` variable in -Python). +as their first parameter (like the ``self`` variable in Python). The effect of ``using A for *;`` is that the functions from -the library ``A`` are attached to any type. +the library ``A`` are attached to *any* type. -In both situations, all functions, even those where the -type of the first parameter does not match the type of -the object, are attached. The type is checked at the +In both situations, *all* functions in the library are attached, +even those where the type of the first parameter does not +match the type of the object. The type is checked at the point the function is called and function overload resolution is performed. -The ``using A for B;`` directive is active for the current -scope, which is limited to a contract for now but will -be lifted to the global scope later, so that by including -a module, its data types including library functions are +The ``using A for B;`` directive is active only within the current +contract, including within all of its functions, and has no effect +outside of the contract in which it is used. The directive +may only be used inside a contract, not inside any of its functions. + +By including a library, its data types including library functions are available without having to add further code. Let us rewrite the set example from the diff --git a/docs/contributing.rst b/docs/contributing.rst index 6717a8b9..ddc02883 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -54,6 +54,8 @@ However, if you are making a larger change, please consult with the `Solidity De <https://gitter.im/ethereum/solidity-dev>`_ (different from the one mentioned above, this on is focused on compiler and language development instead of language use) first. +New features and bugfixes should be added to the ``Changelog.md`` file: please +follow the style of previous entries, when applicable. Finally, please make sure you respect the `coding style <https://raw.githubusercontent.com/ethereum/solidity/develop/CODING_STYLE.md>`_ @@ -108,13 +110,13 @@ Example: ``./test/libsolidity/syntaxTests/double_stateVariable_declaration.sol`` // ---- // DeclarationError: Identifier already declared. -A syntax test must contain at least the contract under test itself, followed by the seperator ``----``. The additional comments above are used to describe the +A syntax test must contain at least the contract under test itself, followed by the separator ``----``. The additional comments above are used to describe the expected compiler errors or warnings. This section can be empty in case that the contract should compile without any errors or warnings. -In the above example, the state variable ``variable`` was declared twice, which is not allowed. This will result in a ``DeclarationError`` stating that the identifer was already declared. +In the above example, the state variable ``variable`` was declared twice, which is not allowed. This will result in a ``DeclarationError`` stating that the identifier was already declared. The tool that is being used for those tests is called ``isoltest`` and can be found under ``./test/tools/``. It is an interactive tool which allows -editing of failing contracts using your prefered text editor. Let's try to break this test by removing the second declaration of ``variable``: +editing of failing contracts using your preferred text editor. Let's try to break this test by removing the second declaration of ``variable``: :: @@ -182,7 +184,8 @@ does not fail if e.g. the code contains an error. This way, internal problems in can be found by fuzzing tools. We mainly use `AFL <http://lcamtuf.coredump.cx/afl/>`_ for fuzzing. You need to download and -build AFL manually. Next, build Solidity (or just the ``solfuzzer`` binary) with AFL as your compiler: +install AFL packages from your repos (afl, afl-clang) or build them manually. +Next, build Solidity (or just the ``solfuzzer`` binary) with AFL as your compiler: :: @@ -192,7 +195,49 @@ build AFL manually. Next, build Solidity (or just the ``solfuzzer`` binary) with cmake .. -DCMAKE_C_COMPILER=path/to/afl-gcc -DCMAKE_CXX_COMPILER=path/to/afl-g++ make solfuzzer -Next, you need some example source files. This will make it much easer for the fuzzer +At this stage you should be able to see a message similar to the following: + +:: + + Scanning dependencies of target solfuzzer + [ 98%] Building CXX object test/tools/CMakeFiles/solfuzzer.dir/fuzzer.cpp.o + afl-cc 2.52b by <lcamtuf@google.com> + afl-as 2.52b by <lcamtuf@google.com> + [+] Instrumented 1949 locations (64-bit, non-hardened mode, ratio 100%). + [100%] Linking CXX executable solfuzzer + +If the instrumentation messages did not appear, try switching the cmake flags pointing to AFL's clang binaries: + +:: + + # if previously failed + make clean + cmake .. -DCMAKE_C_COMPILER=path/to/afl-clang -DCMAKE_CXX_COMPILER=path/to/afl-clang++ + make solfuzzer + +Othwerise, upon execution the fuzzer will halt with an error saying binary is not instrumented: + +:: + + afl-fuzz 2.52b by <lcamtuf@google.com> + ... (truncated messages) + [*] Validating target binary... + + [-] Looks like the target binary is not instrumented! The fuzzer depends on + compile-time instrumentation to isolate interesting test cases while + mutating the input data. For more information, and for tips on how to + instrument binaries, please see /usr/share/doc/afl-doc/docs/README. + + When source code is not available, you may be able to leverage QEMU + mode support. Consult the README for tips on how to enable this. + (It is also possible to use afl-fuzz as a traditional, "dumb" fuzzer. + For that, you can use the -n option - but expect much worse results.) + + [-] PROGRAM ABORT : No instrumentation detected + Location : check_binary(), afl-fuzz.c:6920 + + +Next, you need some example source files. This will make it much easier for the fuzzer to find errors. You can either copy some files from the syntax tests or extract test files from the documentation or the other tests: diff --git a/docs/control-structures.rst b/docs/control-structures.rst index 7849d15a..ead236c4 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -39,7 +39,7 @@ write:: pragma solidity ^0.4.16; contract Simple { - function arithmetics(uint _a, uint _b) + function arithmetic(uint _a, uint _b) public pure returns (uint o_sum, uint o_product) @@ -225,11 +225,11 @@ creation-dependencies are not possible. :: - pragma solidity ^0.4.0; + pragma solidity >0.4.24; contract D { uint x; - function D(uint a) public payable { + constructor(uint a) public payable { x = a; } } @@ -293,18 +293,13 @@ These can then either be assigned to newly declared variables or to pre-existing (x, y) = (y, x); // Components can be left out (also for variable declarations). (data.length,,) = f(); // Sets the length to 7 - // Components can only be left out at the left-hand-side of assignments, with - // one exception: - (x,) = (1,); - // (1,) is the only way to specify a 1-component tuple, because (1) is - // equivalent to 1. } } .. note:: - Prior to version 0.4.24 it was possible to assign to tuples of smaller size, either + Prior to version 0.5.0 it was possible to assign to tuples of smaller size, either filling up on the left or on the right side (which ever was empty). This is - now deprecated, both sides have to have the same number of components. + now disallowed, so both sides have to have the same number of components. Complications for Arrays and Structs ------------------------------------ @@ -325,74 +320,7 @@ is ``false``. The default value for the ``uint`` or ``int`` types is ``0``. For element will be initialized to the default value corresponding to its type. Finally, for dynamically-sized arrays, ``bytes`` and ``string``, the default value is an empty array or string. -A variable declared anywhere within a function will be in scope for the *entire function*, regardless of where it is declared -(this will change soon, see below). -This happens because Solidity inherits its scoping rules from JavaScript. -This is in contrast to many languages where variables are only scoped where they are declared until the end of the semantic block. -As a result, the following code is illegal and cause the compiler to throw an error, ``Identifier already declared``: - -:: - - // This will not compile - - pragma solidity ^0.4.16; - - contract ScopingErrors { - function scoping() public { - uint i = 0; - - while (i++ < 1) { - uint same1 = 0; - } - - while (i++ < 2) { - uint same1 = 0;// Illegal, second declaration of same1 - } - } - - function minimalScoping() public { - { - uint same2 = 0; - } - - { - uint same2 = 0;// Illegal, second declaration of same2 - } - } - - function forLoopScoping() public { - for (uint same3 = 0; same3 < 1; same3++) { - } - - for (uint same3 = 0; same3 < 1; same3++) {// Illegal, second declaration of same3 - } - } - } - -In addition to this, if a variable is declared, it will be initialized at the beginning of the function to its default value. -As a result, the following code is legal, despite being poorly written: - -:: - - pragma solidity ^0.4.0; - - contract C { - function foo() public pure returns (uint) { - // baz is implicitly initialized as 0 - uint bar = 5; - if (true) { - bar += baz; - } else { - uint baz = 10;// never executes - } - return bar;// returns 5 - } - } - -Scoping starting from Version 0.5.0 ------------------------------------ - -Starting from version 0.5.0, Solidity will change to the more widespread scoping rules of C99 +Scoping in Solidity follows the widespread scoping rules of C99 (and many other languages): Variables are visible from the point right after their declaration until the end of a ``{ }``-block. As an exception to this rule, variables declared in the initialization part of a for-loop are only visible until the end of the for-loop. @@ -401,17 +329,12 @@ Variables and other items declared outside of a code block, for example function user-defined types, etc., do not change their scoping behaviour. This means you can use state variables before they are declared and call functions recursively. -These rules are already introduced now as an experimental feature. - As a consequence, the following examples will compile without warnings, since -the two variables have the same name but disjoint scopes. In non-0.5.0-mode, -they have the same scope (the function ``minimalScoping``) and thus it does -not compile there. +the two variables have the same name but disjoint scopes. :: - pragma solidity ^0.4.0; - pragma experimental "v0.5.0"; + pragma solidity >0.4.24; contract C { function minimalScoping() pure public { { @@ -430,8 +353,7 @@ In any case, you will get a warning about the outer variable being shadowed. :: - pragma solidity ^0.4.0; - pragma experimental "v0.5.0"; + pragma solidity >0.4.24; contract C { function f() pure public returns (uint) { uint x = 1; @@ -443,6 +365,24 @@ In any case, you will get a warning about the outer variable being shadowed. } } +.. warning:: + Before version 0.5.0 Solidity followed the same scoping rules as JavaScript, that is, a variable declared anywhere within a function would be in scope + for the entire function, regardless where it was declared. Note that this is a breaking change. The following example shows a code snippet that used + to compile but leads to an error starting from version 0.5.0. + + :: + + // This will not compile + + pragma solidity >0.4.24; + contract C { + function f() pure public returns (uint) { + x = 2; + uint x; + return x; + } + } + .. index:: ! exception, ! throw, ! assert, ! require, ! revert Error handling: Assert, Require, Revert and Exceptions @@ -478,18 +418,18 @@ a message string for ``require``, but not for ``assert``. :: - pragma solidity ^0.4.22; + pragma solidity >0.4.24; contract Sharer { function sendHalf(address addr) public payable returns (uint balance) { require(msg.value % 2 == 0, "Even value required."); - uint balanceBeforeTransfer = this.balance; + uint balanceBeforeTransfer = address(this).balance; addr.transfer(msg.value / 2); // Since transfer throws an exception on failure and // cannot call back here, there should be no way for us to // still have half of the money. - assert(this.balance == balanceBeforeTransfer - msg.value / 2); - return this.balance; + assert(address(this).balance == balanceBeforeTransfer - msg.value / 2); + return address(this).balance; } } diff --git a/docs/docs-css/custom.css b/docs/docs-css/custom.css new file mode 100644 index 00000000..970148ed --- /dev/null +++ b/docs/docs-css/custom.css @@ -0,0 +1,14 @@ +pre { + white-space: pre-wrap; /* css-3 */ + white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: -o-pre-wrap; /* Opera 7 */ + word-wrap: break-word; +} + +.wy-table-responsive table td, .wy-table-responsive table th { + white-space: pre-wrap; +} +.wy-table-responsive table td, .wy-table-responsive table th { + white-space: pre-wrap; +} diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index ca5a1aee..17e71747 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -69,7 +69,7 @@ Can you return an array or a ``string`` from a solidity function call? Yes. See `array_receiver_and_returner.sol <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/60_array_receiver_and_returner.sol>`_. What is problematic, though, is returning any variably-sized data (e.g. a -variably-sized array like ``uint[]``) from a fuction **called from within Solidity**. +variably-sized array like ``uint[]``) from a function **called from within Solidity**. This is a limitation of the EVM and will be solved with the next protocol update. Returning variably-sized data as part of an external transaction or call is fine. @@ -136,14 +136,9 @@ See `struct_and_for_loop_tester.sol <https://github.com/fivedogit/solidity-baby- How do for loops work? ====================== -Very similar to JavaScript. There is one point to watch out for, though: +Very similar to JavaScript. Such as the following example: -If you use ``for (var i = 0; i < a.length; i ++) { a[i] = i; }``, then -the type of ``i`` will be inferred only from ``0``, whose type is ``uint8``. -This means that if ``a`` has more than ``255`` elements, your loop will -not terminate because ``i`` can only hold values up to ``255``. - -Better use ``for (uint i = 0; i < a.length...`` +``for (uint i = 0; i < a.length; i ++) { a[i] = i; }`` See `struct_and_for_loop_tester.sol <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/65_struct_and_for_loop_tester.sol>`_. @@ -265,7 +260,7 @@ The third one is the stack, which is used to hold small local variables. It is almost free to use, but can only hold a limited amount of values. For almost all types, you cannot specify where they should be stored, because -they are copied everytime they are used. +they are copied every time they are used. The types where the so-called storage location is important are structs and arrays. If you e.g. pass such variables in function calls, their @@ -278,9 +273,11 @@ of variable it concerns: * state variables are always in storage * function arguments are in memory by default -* local variables of struct, array or mapping type reference storage by default +* local variables of mapping type reference storage by default * local variables of value type (i.e. neither array, nor struct nor mapping) are stored in the stack +For local variables of struct or array type the storage location has to be stated explicitly. + Example:: pragma solidity ^0.4.0; @@ -311,48 +308,12 @@ independent copy of the state variable is created in memory and is another issue). The modifications to this independent copy do not carry back to ``data1`` or ``data2``. -A common mistake is to declare a local variable and assume that it will -be created in memory, although it will be created in storage:: - - /// THIS CONTRACT CONTAINS AN ERROR - - pragma solidity ^0.4.0; - - contract C { - uint someVariable; - uint[] data; - - function f() public { - uint[] x; - x.push(2); - data = x; - } - } - -The type of the local variable ``x`` is ``uint[] storage``, but since -storage is not dynamically allocated, it has to be assigned from -a state variable before it can be used. So no space in storage will be -allocated for ``x``, but instead it functions only as an alias for -a pre-existing variable in storage. - -What will happen is that the compiler interprets ``x`` as a storage -pointer and will make it point to the storage slot ``0`` by default. -This has the effect that ``someVariable`` (which resides at storage -slot ``0``) is modified by ``x.push(2)``. - -The correct way to do this is the following:: - - pragma solidity ^0.4.0; - - contract C { - uint someVariable; - uint[] data; - - function f() public { - uint[] x = data; - x.push(2); - } - } +.. warning:: + Prior to version 0.5.0, a common mistake was to declare a local variable and assume that it will + be created in memory, although it will be created in storage. Using such a variable without initializing + could lead to unexpected behavior. Starting from 0.5.0, however, the storage location for local variables + has to be specified explicitly and local storage variables have to be initialized, which should prevent + these kinds of mistakes. ****************** Advanced Questions @@ -426,10 +387,10 @@ In the case of a ``contract A`` calling a new instance of ``contract B``, parent You will need to make sure that you have both contracts aware of each other's presence and that ``contract B`` has a ``payable`` constructor. In this example:: - pragma solidity ^0.4.0; + pragma solidity >0.4.24; contract B { - function B() public payable {} + constructor() public payable {} } contract A { diff --git a/docs/grammar.txt b/docs/grammar.txt index 0dda4f49..7b29fc62 100644 --- a/docs/grammar.txt +++ b/docs/grammar.txt @@ -57,8 +57,8 @@ Mapping = 'mapping' '(' ElementaryTypeName '=>' TypeName ')' ArrayTypeName = TypeName '[' Expression? ']' FunctionTypeName = 'function' FunctionTypeParameterList ( 'internal' | 'external' | StateMutability )* ( 'returns' FunctionTypeParameterList )? -StorageLocation = 'memory' | 'storage' -StateMutability = 'pure' | 'constant' | 'view' | 'payable' +StorageLocation = 'memory' | 'storage' | 'calldata' +StateMutability = 'pure' | 'view' | 'payable' Block = '{' Statement* '}' Statement = IfStatement | WhileStatement | ForStatement | Block | InlineAssemblyStatement | @@ -78,7 +78,7 @@ Break = 'break' Return = 'return' Expression? Throw = 'throw' EmitStatement = 'emit' FunctionCall -VariableDefinition = ('var' IdentifierList | VariableDeclaration | '(' VariableDeclaration? (',' VariableDeclaration? )* ')' ) ( '=' Expression )? +VariableDefinition = (VariableDeclaration | '(' VariableDeclaration? (',' VariableDeclaration? )* ')' ) ( '=' Expression )? IdentifierList = '(' ( Identifier? ',' )* Identifier? ')' // Precedence by order (see github.com/ethereum/solidity/pull/732) @@ -140,8 +140,7 @@ TupleExpression = '(' ( Expression? ( ',' Expression? )* )? ')' ElementaryTypeNameExpression = ElementaryTypeName -ElementaryTypeName = 'address' | 'bool' | 'string' | 'var' - | Int | Uint | Byte | Fixed | Ufixed +ElementaryTypeName = 'address' | 'bool' | 'string' | Int | Uint | Byte | Fixed | Ufixed Int = 'int' | 'int8' | 'int16' | 'int24' | 'int32' | 'int40' | 'int48' | 'int56' | 'int64' | 'int72' | 'int80' | 'int88' | 'int96' | 'int104' | 'int112' | 'int120' | 'int128' | 'int136' | 'int144' | 'int152' | 'int160' | 'int168' | 'int176' | 'int184' | 'int192' | 'int200' | 'int208' | 'int216' | 'int224' | 'int232' | 'int240' | 'int248' | 'int256' diff --git a/docs/index.rst b/docs/index.rst index 80b0d6e7..a57b93e4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -169,7 +169,7 @@ Contents using-the-compiler.rst metadata.rst abi-spec.rst - julia.rst + yul.rst style-guide.rst common-patterns.rst bugs.rst diff --git a/docs/installing-solidity.rst b/docs/installing-solidity.rst index 05ee0748..5b3fdf87 100644 --- a/docs/installing-solidity.rst +++ b/docs/installing-solidity.rst @@ -64,7 +64,7 @@ repository contains potentially unstable changes in the develop branch. .. code:: bash - docker run ethereum/solc:stable solc --version + docker run ethereum/solc:stable --version Currently, the docker image only contains the compiler executable, so you have to do some additional work to link in the source and diff --git a/docs/introduction-to-smart-contracts.rst b/docs/introduction-to-smart-contracts.rst index 71f9bd8e..e1b61d8b 100644 --- a/docs/introduction-to-smart-contracts.rst +++ b/docs/introduction-to-smart-contracts.rst @@ -80,7 +80,7 @@ registering with username and password — all you need is an Ethereum keypair. :: - pragma solidity ^0.4.21; + pragma solidity >0.4.24; contract Coin { // The keyword "public" makes those variables @@ -94,7 +94,7 @@ registering with username and password — all you need is an Ethereum keypair. // This is the constructor whose code is // run only when the contract is created. - function Coin() public { + constructor() public { minter = msg.sender; } diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index c7c32528..c0c7cb1b 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -79,6 +79,7 @@ Solidity always places new objects at the free memory pointer and memory is neve .. warning:: There are some operations in Solidity that need a temporary memory area larger than 64 bytes and therefore will not fit into the scratch space. They will be placed where the free memory points to, but given their short lifecycle, the pointer is not updated. The memory may or may not be zeroed out. Because of this, one shouldn't expect the free memory to be zeroed out. + While it may seem like a good idea to use ``msize`` to arrive at a definitely zeroed out memory area, using such a pointer non-temporarily without updating the free memory pointer can have adverse results. .. index: calldata layout @@ -156,7 +157,7 @@ These steps are applied to each basic block and the newly generated code is used :: - var x = 7; + uint x = 7; data[7] = 9; if (data[x] != x + 2) return 2; @@ -190,7 +191,7 @@ important for static analysis tools that operate on bytecode level and for displaying the current position in the source code inside a debugger or for breakpoint handling. -Both kinds of source mappings use integer indentifiers to refer to source files. +Both kinds of source mappings use integer identifiers to refer to source files. These are regular array indices into a list of source files usually called ``"sourceList"``, which is part of the combined-json and the output of the json / npm compiler. @@ -318,10 +319,10 @@ Global Variables ================ - ``abi.encode(...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments -- ``abi.encodePacked(...) returns (bytes)``: Performes :ref:`packed encoding <abi_packed_mode>` of the given arguments +- ``abi.encodePacked(...) returns (bytes)``: Performs :ref:`packed encoding <abi_packed_mode>` of the given arguments - ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments starting from the second and prepends the given four-byte selector -- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(signature), ...)``` +- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)``` - ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent, excluding current, blocks - deprecated in version 0.4.22 and replaced by ``blockhash(uint blockNumber)``. - ``block.coinbase`` (``address``): current block miner's address - ``block.difficulty`` (``uint``): current block difficulty @@ -342,10 +343,10 @@ Global Variables - ``revert()``: abort execution and revert state changes - ``revert(string message)``: abort execution and revert state changes providing an explanatory string - ``blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent blocks -- ``keccak256(...) returns (bytes32)``: compute the Ethereum-SHA-3 (Keccak-256) hash of the :ref:`(tightly packed) arguments <abi_packed_mode>` -- ``sha3(...) returns (bytes32)``: an alias to ``keccak256`` -- ``sha256(...) returns (bytes32)``: compute the SHA-256 hash of the :ref:`(tightly packed) arguments <abi_packed_mode>` -- ``ripemd160(...) returns (bytes20)``: compute the RIPEMD-160 hash of the :ref:`(tightly packed) arguments <abi_packed_mode>` +- ``keccak256(bytes memory) returns (bytes32)``: compute the Ethereum-SHA-3 (Keccak-256) hash of the input +- ``sha3(bytes memory) returns (bytes32)``: an alias to ``keccak256`` +- ``sha256(bytes memory) returns (bytes32)``: compute the SHA-256 hash of the input +- ``ripemd160(bytes memory) returns (bytes20)``: compute the RIPEMD-160 hash of the input - ``ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)``: recover address associated with the public key from elliptic curve signature, return zero on error - ``addmod(uint x, uint y, uint k) returns (uint)``: compute ``(x + y) % k`` where the addition is performed with arbitrary precision and does not wrap around at ``2**256``. Assert that ``k != 0`` starting from version 0.5.0. - ``mulmod(uint x, uint y, uint k) returns (uint)``: compute ``(x * y) % k`` where the multiplication is performed with arbitrary precision and does not wrap around at ``2**256``. Assert that ``k != 0`` starting from version 0.5.0. @@ -396,11 +397,10 @@ Function Visibility Specifiers Modifiers ========= -- ``pure`` for functions: Disallows modification or access of state - this is not enforced yet. -- ``view`` for functions: Disallows modification of state - this is not enforced yet. +- ``pure`` for functions: Disallows modification or access of state. +- ``view`` for functions: Disallows modification of state. - ``payable`` for functions: Allows them to receive Ether together with a call. - ``constant`` for state variables: Disallows assignment (except initialisation), does not occupy storage slot. -- ``constant`` for functions: Same as ``view``. - ``anonymous`` for events: Does not store event signature as topic. - ``indexed`` for event parameters: Stores the parameter as topic. @@ -409,8 +409,11 @@ Reserved Keywords These keywords are reserved in Solidity. They might become part of the syntax in the future: -``abstract``, ``after``, ``case``, ``catch``, ``default``, ``final``, ``in``, ``inline``, ``let``, ``match``, ``null``, -``of``, ``relocatable``, ``static``, ``switch``, ``try``, ``type``, ``typeof``. +``abstract``, ``after``, ``alias``, ``apply``, ``auto``, ``case``, ``catch``, ``copyof``, ``default``, +``define``, ``final``, ``immutable``, ``implements``, ``in``, ``inline``, ``let``, ``macro``, ``match``, +``mutable``, ``null``, ``of``, ``override``, ``partial``, ``promise``, ``reference``, ``relocatable``, +``sealed``, ``sizeof``, ``static``, ``supports``, ``switch``, ``try``, ``type``, ``typedef``, ``typeof``, +``unchecked``. Language Grammar ================ diff --git a/docs/security-considerations.rst b/docs/security-considerations.rst index 4133edb1..afdecb98 100644 --- a/docs/security-considerations.rst +++ b/docs/security-considerations.rst @@ -86,7 +86,7 @@ as it uses ``call`` which forwards all remaining gas by default: mapping(address => uint) shares; /// Withdraw your share. function withdraw() public { - if (msg.sender.call.value(shares[msg.sender])()) + if (msg.sender.call.value(shares[msg.sender])("")) shares[msg.sender] = 0; } } @@ -103,7 +103,7 @@ outlined further below: mapping(address => uint) shares; /// Withdraw your share. function withdraw() public { - var share = shares[msg.sender]; + uint share = shares[msg.sender]; shares[msg.sender] = 0; msg.sender.transfer(share); } @@ -140,7 +140,7 @@ Sending and Receiving Ether (for example in the "details" section in Remix). - There is a way to forward more gas to the receiving contract using - ``addr.call.value(x)()``. This is essentially the same as ``addr.transfer(x)``, + ``addr.call.value(x)("")``. This is essentially the same as ``addr.transfer(x)``, only that it forwards all remaining gas and opens up the ability for the recipient to perform more expensive actions (and it only returns a failure code and does not automatically propagate the error). This might include calling back @@ -180,13 +180,13 @@ Never use tx.origin for authorization. Let's say you have a wallet contract like :: - pragma solidity ^0.4.11; + pragma solidity >0.4.24; // THIS CONTRACT CONTAINS A BUG - DO NOT USE contract TxUserWallet { address owner; - function TxUserWallet() public { + constructor() public { owner = msg.sender; } @@ -200,7 +200,7 @@ Now someone tricks you into sending ether to the address of this attack wallet: :: - pragma solidity ^0.4.11; + pragma solidity >0.4.24; interface TxUserWallet { function transferTo(address dest, uint amount) public; @@ -209,11 +209,11 @@ Now someone tricks you into sending ether to the address of this attack wallet: contract TxAttackWallet { address owner; - function TxAttackWallet() public { + constructor() public { owner = msg.sender; } - function() public { + function() external { TxUserWallet(msg.sender).transferTo(owner, msg.sender.balance); } } @@ -224,7 +224,6 @@ If your wallet had checked ``msg.sender`` for authorization, it would get the ad Minor Details ============= -- In ``for (var i = 0; i < arrayName.length; i++) { ... }``, the type of ``i`` will be ``uint8``, because this is the smallest type that is required to hold the value ``0``. If the array has more than 255 elements, the loop will not terminate. - Types that do not occupy the full 32 bytes might contain "dirty higher order bits". This is especially important if you access ``msg.data`` - it poses a malleability risk: You can craft transactions that call a function ``f(uint8 x)`` with a raw byte argument diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst index 2b3d4b48..cd281aad 100644 --- a/docs/solidity-by-example.rst +++ b/docs/solidity-by-example.rst @@ -428,8 +428,8 @@ high or low invalid bids. revealEnd = biddingEnd + _revealTime; } - /// Place a blinded bid with `_blindedBid` = keccak256(value, - /// fake, secret). + /// Place a blinded bid with `_blindedBid` = + /// keccak256(abi.encodePacked(value, fake, secret)). /// The sent ether is only refunded if the bid is correctly /// revealed in the revealing phase. The bid is valid if the /// ether sent together with the bid is at least "value" and @@ -470,7 +470,7 @@ high or low invalid bids. Bid storage bid = bids[msg.sender][i]; (uint value, bool fake, bytes32 secret) = (_values[i], _fake[i], _secret[i]); - if (bid.blindedBid != keccak256(value, fake, secret)) { + if (bid.blindedBid != keccak256(abi.encodePacked(value, fake, secret))) { // Bid was not actually revealed. // Do not refund deposit. continue; @@ -496,7 +496,7 @@ high or low invalid bids. if (value <= highestBid) { return false; } - if (highestBidder != 0) { + if (highestBidder != address(0)) { // Refund the previously highest bidder. pendingReturns[highestBidder] += highestBid; } @@ -645,4 +645,489 @@ Safe Remote Purchase Micropayment Channel ******************** -To be written. +In this section we will learn how to build a simple implementation +of a payment channel. It use cryptographics signatures to make +repeated transfers of Ether between the same parties secure, instantaneous, and +without transaction fees. To do it we need to understand how to +sign and verify signatures, and setup the payment channel. + +Creating and verifying signatures +================================= + +Imagine Alice wants to send a quantity of Ether to Bob, i.e. +Alice is the sender and the Bob is the recipient. +Alice only needs to send cryptographically signed messages off-chain +(e.g. via email) to Bob and it will be very similar to writing checks. + +Signatures are used to authorize transactions, +and they are a general tool that is available to +smart contracts. Alice will build a simple +smart contract that lets her transmit Ether, but +in a unusual way, instead of calling a function herself +to initiate a payment, she will let Bob +do that, and therefore pay the transaction fee. +The contract will work as follows: + + 1. Alice deploys the ``ReceiverPays`` contract, attaching enough Ether to cover the payments that will be made. + 2. Alice authorizes a payment by signing a message with their private key. + 3. Alice sends the cryptographically signed message to Bob. The message does not need to be kept secret + (you will understand it later), and the mechanism for sending it does not matter. + 4. Bob claims their payment by presenting the signed message to the smart contract, it verifies the + authenticity of the message and then releases the funds. + +Creating the signature +---------------------- + +Alice does not need to interact with Ethereum network to +sign the transaction, the process is completely offline. +In this tutorial, we will sign messages in the browser +using ``web3.js`` and ``MetaMask``. +In particular, we will use the standard way described in `EIP-762 <https://github.com/ethereum/EIPs/pull/712>`_, +as it provides a number of other security benefits. + +:: + + /// Hashing first makes a few things easier + var hash = web3.sha3("message to sign"); + web3.personal.sign(hash, web3.eth.defaultAccount, function () {...}); + + +Note that the ``web3.personal.sign`` prepends the length of the message to the signed data. +Since we hash first, the message will always be exactly 32 bytes long, +and thus this length prefix is always the same, making everything easier. + +What to Sign +------------ + +For a contract that fulfills payments, the signed message must include: + + 1. The recipient's address + 2. The amount to be transferred + 3. Protection against replay attacks + +A replay attack is when a signed message is reused to claim authorization for +a second action. +To avoid replay attacks we will use the same as in Ethereum transactions +themselves, a so-called nonce, which is the number of transactions sent by an +account. +The smart contract will check if a nonce is used multiple times. + +There is another type of replay attacks, it occurs when the +owner deploys a ``ReceiverPays`` smart contract, performs some payments, +and then destroy the contract. Later, she decides to deploy the +``RecipientPays`` smart contract again, but the new contract does not +know the nonces used in the previous deployment, so the attacker +can use the old messages again. + +Alice can protect against it including +the contract's address in the message, and only +messages containing contract's address itself will be accepted. +This functionality can be found in the first two lines of the ``claimPayment()`` function in the full contract +at the end of this chapter. + +Packing arguments +----------------- + +Now that we have identified what information to include in the +signed message, we are ready to put the message together, hash it, +and sign it. For simplicity, we just concatenate the data. +The +`ethereumjs-abi <https://github.com/ethereumjs/ethereumjs-abi>`_ library provides +a function called ``soliditySHA3`` that mimics the behavior +of Solidity's ``keccak256`` function applied to arguments encoded +using ``abi.encodePacked``. +Putting it all together, here is a JavaScript function that +creates the proper signature for the ``ReceiverPays`` example: + +:: + + // recipient is the address that should be paid. + // amount, in wei, specifies how much ether should be sent. + // nonce can be any unique number to prevent replay attacks + // contractAddress is used to prevent cross-contract replay attacks + function signPayment(recipient, amount, nonce, contractAddress, callback) { + var hash = "0x" + ethereumjs.ABI.soliditySHA3( + ["address", "uint256", "uint256", "address"], + [recipient, amount, nonce, contractAddress] + ).toString("hex"); + + web3.personal.sign(hash, web3.eth.defaultAccount, callback); + } + +Recovering the Message Signer in Solidity +----------------------------------------- + +In general, ECDSA signatures consist of two parameters, ``r`` and ``s``. +Signatures in Ethereum include a third parameter called ``v``, that can be used +to recover which account's private key was used to sign in the message, +the transaction's sender. Solidity provides a built-in function +`ecrecover <mathematical-and-cryptographic-functions>`_ +that accepts a message along with the ``r``, ``s`` and ``v`` parameters and +returns the address that was used to sign the message. + +Extracting the Signature Parameters +----------------------------------- + +Signatures produced by web3.js are the concatenation of ``r``, ``s`` and ``v``, +so the first step is splitting those parameters back out. It can be done on the client, +but doing it inside the smart contract means only one signature parameter +needs to be sent rather than three. +Splitting apart a byte array into component parts is a little messy. +We will use `inline assembly <assembly>`_ to do the job +in the ``splitSignature`` function (the third function in the full contract +at the end of this chapter). + +Computing the Message Hash +-------------------------- + +The smart contract needs to know exactly what parameters were signed, +and so it must recreate the message from the parameters and use that +for signature verification. The functions ``prefixed`` and +``recoverSigner`` do this and their use can be found in the +``claimPayment`` function. + + +The full contract +----------------- + +:: + + pragma solidity ^0.4.24; + + contract ReceiverPays { + address owner = msg.sender; + + mapping(uint256 => bool) usedNonces; + + constructor() public payable {} + + function claimPayment(uint256 amount, uint256 nonce, bytes signature) public { + require(!usedNonces[nonce]); + usedNonces[nonce] = true; + + // this recreates the message that was signed on the client + bytes32 message = prefixed(keccak256(abi.encodePacked(msg.sender, amount, nonce, this))); + + require(recoverSigner(message, signature) == owner); + + msg.sender.transfer(amount); + } + + /// destroy the contract and reclaim the leftover funds. + function kill() public { + require(msg.sender == owner); + selfdestruct(msg.sender); + } + + /// signature methods. + function splitSignature(bytes sig) + internal + pure + returns (uint8 v, bytes32 r, bytes32 s) + { + require(sig.length == 65); + + assembly { + // first 32 bytes, after the length prefix. + r := mload(add(sig, 32)) + // second 32 bytes. + s := mload(add(sig, 64)) + // final byte (first byte of the next 32 bytes). + v := byte(0, mload(add(sig, 96))) + } + + return (v, r, s); + } + + function recoverSigner(bytes32 message, bytes sig) + internal + pure + returns (address) + { + (uint8 v, bytes32 r, bytes32 s) = splitSignature(sig); + + return ecrecover(message, v, r, s); + } + + /// builds a prefixed hash to mimic the behavior of eth_sign. + function prefixed(bytes32 hash) internal pure returns (bytes32) { + return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); + } + } + + +Writing a Simple Payment Channel +================================ + +Alice will now build a simple but complete implementation of a payment channel. +Payment channels use cryptographic signatures to make repeated transfers +of Ether securely, instantaneously, and without transaction fees. + +What is a Payment Channel? +-------------------------- + +Payment channels allow participants to make repeated transfers of Ether without +using transactions. This means that the delays and fees associated with transactions +can be avoided. We are going to explore a simple unidirectional payment channel between +two parties (Alice and Bob). Using it involves three steps: + + 1. Alice funds a smart contract with Ether. This "opens" the payment channel. + 2. Alice signs messages that specify how much of that Ether is owed to the recipient. This step is repeated for each payment. + 3. Bob "closes" the payment channel, withdrawing their portion of the Ether and sending the remainder back to the sender. + +Not ethat only steps 1 and 3 require Ethereum transactions, step 2 means that +the sender transmits a cryptographically signed message to the recipient via off chain ways (e.g. email). +This means only two transactions are required to support any number of transfers. + +Bob is guaranteed to receive their funds because the smart contract escrows +the Ether and honors a valid signed message. The smart contract also enforces a timeout, +so Alice is guaranteed to eventually recover their funds even if the recipient refuses +to close the channel. +It is up to the participants in a payment channel to decide how long to keep it open. +For a short-lived transaction, such as paying an internet cafe for each minute of network access, +or for a longer relationship, such as paying an employee an hourly wage, a payment could last for months or years. + +Opening the Payment Channel +--------------------------- + +To open the payment channel, Alice deploys the smart contract, +attaching the Ether to be escrowed and specifying the intendend recipient +and a maximum duration for the channel to exist. It is the function +``SimplePaymentChannel`` in the contract, that is at the end of this chapter. + +Making Payments +--------------- + +Alice makes payments by sending signed messages to Bob. +This step is performed entirely outside of the Ethereum network. +Messages are cryptographically signed by the sender and then transmitted directly to the recipient. + +Each message includes the following information: + + * The smart contract's address, used to prevent cross-contract replay attacks. + * The total amount of Ether that is owed the recipient so far. + +A payment channel is closed just once, at the of a series of transfers. +Because of this, only one of the messages sent will be redeemed. This is why +each message specifies a cumulative total amount of Ether owed, rather than the +amount of the individual micropayment. The recipient will naturally choose to +redeem the most recent message because that is the one with the highest total. +The nonce per-message is not needed anymore, because the smart contract will +only honor a single message. The address of the smart contract is still used +to prevent a message intended for one payment channel from being used for a different channel. + +Here is the modified javascript code to cryptographically sign a message from the previous chapter: + +:: + + function constructPaymentMessage(contractAddress, amount) { + return ethereumjs.ABI.soliditySHA3( + ["address", "uint256"], + [contractAddress, amount] + ); + } + + function signMessage(message, callback) { + web3.personal.sign( + "0x" + message.toString("hex"), + web3.eth.defaultAccount, + callback + ); + } + + // contractAddress is used to prevent cross-contract replay attacks. + // amount, in wei, specifies how much Ether should be sent. + + function signPayment(contractAddress, amount, callback) { + var message = constructPaymentMessage(contractAddress, amount); + signMessage(message, callback); + } + + +Closing the Payment Channel +--------------------------- + +When Bob is ready to receive their funds, it is time to +close the payment channel by calling a ``close`` function on the smart contract. +Closing the channel pays the recipient the Ether they are owed and destroys the contract, +sending any remaining Ether back to Alice. +To close the channel, Bob needs to provide a message signed by Alice. + +The smart contract must verify that the message contains a valid signature from the sender. +The process for doing this verification is the same as the process the recipient uses. +The Solidity functions ``isValidSignature`` and ``recoverSigner`` work just like their +JavaScript counterparts in the previous section. The latter is borrowed from the +``ReceiverPays`` contract in the previous chapter. + +The ``close`` function can only be called by the payment channel recipient, +who will naturally pass the most recent payment message because that message +carries the highest total owed. If the sender were allowed to call this function, +they could provide a message with a lower amount and cheat the recipient out of what they are owed. + +The function verifies the signed message matches the given parameters. +If everything checks out, the recipient is sent their portion of the Ether, +and the sender is sent the rest via a ``selfdestruct``. +You can see the ``close`` function in the full contract. + +Channel Expiration +------------------- + +Bob can close the payment channel at any time, but if they fail to do so, +Alice needs a way to recover their escrowed funds. An *expiration* time was set +at the time of contract deployment. Once that time is reached, Alice can call +``claimTimeout`` to recover their funds. You can see the ``claimTimeout`` function in the +full contract. + +After this function is called, Bob can no longer receive any Ether, +so it is important that Bob closes the channel before the expiration is reached. + + +The full contract +----------------- + +:: + + pragma solidity ^0.4.24; + + contract SimplePaymentChannel { + address public sender; // The account sending payments. + address public recipient; // The account receiving the payments. + uint256 public expiration; // Timeout in case the recipient never closes. + + constructor (address _recipient, uint256 duration) + public + payable + { + sender = msg.sender; + recipient = _recipient; + expiration = now + duration; + } + + function isValidSignature(uint256 amount, bytes signature) + internal + view + returns (bool) + { + bytes32 message = prefixed(keccak256(abi.encodePacked(this, amount))); + + // check that the signature is from the payment sender + return recoverSigner(message, signature) == sender; + } + + /// the recipient can close the channel at any time by presenting a + /// signed amount from the sender. the recipient will be sent that amount, + /// and the remainder will go back to the sender + function close(uint256 amount, bytes signature) public { + require(msg.sender == recipient); + require(isValidSignature(amount, signature)); + + recipient.transfer(amount); + selfdestruct(sender); + } + + /// the sender can extend the expiration at any time + function extend(uint256 newExpiration) public { + require(msg.sender == sender); + require(newExpiration > expiration); + + expiration = newExpiration; + } + + /// if the timeout is reached without the recipient closing the channel, + /// then the Ether is released back to the sender. + function claimTimeout() public { + require(now >= expiration); + selfdestruct(sender); + } + + /// All functions below this are just taken from the chapter + /// 'creating and verifying signatures' chapter. + + function splitSignature(bytes sig) + internal + pure + returns (uint8 v, bytes32 r, bytes32 s) + { + require(sig.length == 65); + + assembly { + // first 32 bytes, after the length prefix + r := mload(add(sig, 32)) + // second 32 bytes + s := mload(add(sig, 64)) + // final byte (first byte of the next 32 bytes) + v := byte(0, mload(add(sig, 96))) + } + + return (v, r, s); + } + + function recoverSigner(bytes32 message, bytes sig) + internal + pure + returns (address) + { + (uint8 v, bytes32 r, bytes32 s) = splitSignature(sig); + + return ecrecover(message, v, r, s); + } + + /// builds a prefixed hash to mimic the behavior of eth_sign. + function prefixed(bytes32 hash) internal pure returns (bytes32) { + return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); + } + } + + +Note: The function ``splitSignature`` is very simple and does not use all security checks. +A real implementation should use a more rigorously tested library, such as +openzepplin's `version <https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ECRecovery.sol>`_ of this code. + + + +Verifying Payments +------------------ + +Unlike in our previous chapter, messages in a payment channel aren't +redeemed right away. The recipient keeps track of the latest message and +redeems it when it's time to close the payment channel. This means it's +critical that the recipient perform their own verification of each message. +Otherwise there is no guarantee that the recipient will be able to get paid +in the end. + +The recipient should verify each message using the following process: + + 1. Verify that the contact address in the message matches the payment channel. + 2. Verify that the new total is the expected amount. + 3. Verify that the new total does not exceed the amount of Ether escrowed. + 4. Verify that the signature is valid and comes from the payment channel sender. + +We'll use the `ethereumjs-util <https://github.com/ethereumjs/ethereumjs-util>`_ +library to write this verifications. The final step can be done a number of ways, +but if it's being done in **JavaScript**. +The following code borrows the `constructMessage` function from the signing **JavaScript code** +above: + +:: + + // this mimics the prefixing behavior of the eth_sign JSON-RPC method. + function prefixed(hash) { + return ethereumjs.ABI.soliditySHA3( + ["string", "bytes32"], + ["\x19Ethereum Signed Message:\n32", hash] + ); + } + + function recoverSigner(message, signature) { + var split = ethereumjs.Util.fromRpcSig(signature); + var publicKey = ethereumjs.Util.ecrecover(message, split.v, split.r, split.s); + var signer = ethereumjs.Util.pubToAddress(publicKey).toString("hex"); + return signer; + } + + function isValidSignature(contractAddress, amount, signature, expectedSigner) { + var message = prefixed(constructPaymentMessage(contractAddress, amount)); + var signer = recoverSigner(message, signature); + return signer.toLowerCase() == + ethereumjs.Util.stripHexPrefix(expectedSigner).toLowerCase(); + } diff --git a/docs/style-guide.rst b/docs/style-guide.rst index 6b28f2ab..19e3aae5 100644 --- a/docs/style-guide.rst +++ b/docs/style-guide.rst @@ -114,15 +114,15 @@ No:: .. _maximum_line_length: -Maximum Line Length +Maximum Line Length =================== -Keeping lines under the `PEP 8 recommendation <https://www.python.org/dev/peps/pep-0008/#maximum-line-length>`_ to a maximum of 79 (or 99) +Keeping lines under the `PEP 8 recommendation <https://www.python.org/dev/peps/pep-0008/#maximum-line-length>`_ to a maximum of 79 (or 99) characters helps readers easily parse the code. Wrapped lines should conform to the following guidelines. -1. The first argument should not be attached to the opening parenthesis. +1. The first argument should not be attached to the opening parenthesis. 2. One, and only one, indent should be used. 3. Each argument should fall on its own line. 4. The terminating element, :code:`);`, should be placed on the final line by itself. @@ -132,38 +132,38 @@ Function Calls Yes:: thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, + longArgument1, + longArgument2, longArgument3 ); No:: - thisFunctionCallIsReallyLong(longArgument1, - longArgument2, + thisFunctionCallIsReallyLong(longArgument1, + longArgument2, longArgument3 ); - - thisFunctionCallIsReallyLong(longArgument1, - longArgument2, + + thisFunctionCallIsReallyLong(longArgument1, + longArgument2, longArgument3 - ); - + ); + thisFunctionCallIsReallyLong( longArgument1, longArgument2, longArgument3 - ); + ); thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, + longArgument1, + longArgument2, longArgument3 ); thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3); + longArgument1, + longArgument2, + longArgument3); Assignment Statements @@ -188,8 +188,8 @@ Event Definitions and Event Emitters Yes:: event LongAndLotsOfArgs( - adress sender, - adress recipient, + address sender, + address recipient, uint256 publicKey, uint256 amount, bytes32[] options @@ -205,8 +205,8 @@ Yes:: No:: - event LongAndLotsOfArgs(adress sender, - adress recipient, + event LongAndLotsOfArgs(address sender, + address recipient, uint256 publicKey, uint256 amount, bytes32[] options); @@ -215,7 +215,7 @@ No:: recipient, publicKey, amount, - options); + options); Source File Encoding ==================== @@ -274,11 +274,11 @@ Within a grouping, place the ``view`` and ``pure`` functions last. Yes:: contract A { - function A() public { + constructor() public { ... } - function() public { + function() external { ... } @@ -308,17 +308,17 @@ No:: // External functions // ... + function() external { + ... + } + // Private functions // ... // Public functions // ... - function A() public { - ... - } - - function() public { + constructor() public { ... } @@ -374,13 +374,13 @@ Don't include a whitespace in the fallback function: Yes:: - function() public { + function() external { ... } No:: - function () public { + function () external { ... } @@ -529,7 +529,7 @@ No:: function increment(uint x) public pure returns (uint) { return x + 1;} -You should explicitly label the visibility of all functions, including constructors. +You should explicitly label the visibility of all functions, including constructors. Yes:: @@ -540,7 +540,7 @@ Yes:: No:: function implicitlyPublic(uint val) { - doSomething(); + doSomething(); } The visibility modifier for a function should come before any custom @@ -663,19 +663,19 @@ Yes:: address a, address b, address c - ) - public + ) + public returns ( - address someAddressName, - uint256 LongArgument, + address someAddressName, + uint256 LongArgument, uint256 Argument ) - { + { doSomething() - + return ( - veryLongReturnArg1, - veryLongReturnArg2, + veryLongReturnArg1, + veryLongReturnArg2, veryLongReturnArg3 ); } @@ -686,16 +686,16 @@ No:: address a, address b, address c - ) - public - returns (address someAddressName, - uint256 LongArgument, + ) + public + returns (address someAddressName, + uint256 LongArgument, uint256 Argument) - { + { doSomething() - - return (veryLongReturnArg1, - veryLongReturnArg1, + + return (veryLongReturnArg1, + veryLongReturnArg1, veryLongReturnArg1); } @@ -706,7 +706,7 @@ manner as modifiers if the function declaration is long or hard to read. Yes:: contract A is B, C, D { - function A(uint param1, uint param2, uint param3, uint param4, uint param5) + constructor(uint param1, uint param2, uint param3, uint param4, uint param5) B(param1) C(param2, param3) D(param4) @@ -719,7 +719,7 @@ Yes:: No:: contract A is B, C, D { - function A(uint param1, uint param2, uint param3, uint param4, uint param5) + constructor(uint param1, uint param2, uint param3, uint param4, uint param5) B(param1) C(param2, param3) D(param4) @@ -730,7 +730,7 @@ No:: } contract A is B, C, D { - function A(uint param1, uint param2, uint param3, uint param4, uint param5) + constructor(uint param1, uint param2, uint param3, uint param4, uint param5) B(param1) C(param2, param3) D(param4) @@ -830,7 +830,7 @@ The naming recommendations given here are intended to improve the readability, and thus they are not rules, but rather guidelines to try and help convey the most information through the names of things. -Lastly, consistency within a codebase should always supercede any conventions +Lastly, consistency within a codebase should always supersede any conventions outlined in this document. diff --git a/docs/types.rst b/docs/types.rst index 794a70de..16445a34 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -7,10 +7,8 @@ Types ***** Solidity is a statically typed language, which means that the type of each -variable (state and local) needs to be specified (or at least known - -see :ref:`type-deduction` below) at -compile-time. Solidity provides several elementary types which can be combined -to form complex types. +variable (state and local) needs to be specified. +Solidity provides several elementary types which can be combined to form complex types. In addition, types can interact with each other in expressions containing operators. For a quick reference of the various operators, see :ref:`order`. @@ -60,15 +58,14 @@ operators are :ref:`literals<rational_literals>` (or literal expressions). Division by zero and modulus with zero throws a runtime exception. The result of a shift operation is the type of the left operand. The -expression ``x << y`` is equivalent to ``x * 2**y``, and ``x >> y`` is -equivalent to ``x / 2**y``. This means that shifting negative numbers -sign extends. Shifting by a negative amount throws a runtime exception. +expression ``x << y`` is equivalent to ``x * 2**y``, and, for positive integers, +``x >> y`` is equivalent to ``x / 2**y``. For negative ``x``, ``x >> y`` +is equivalent to dividing by a power of ``2`` while rounding down (towards negative infinity). +Shifting by a negative amount throws a runtime exception. .. warning:: - The results produced by shift right of negative values of signed integer types is different from those produced - by other programming languages. In Solidity, shift right maps to division so the shifted negative values - are going to be rounded towards zero (truncated). In other programming languages the shift right of negative values - works like division with rounding down (towards negative infinity). + Before version ``0.5.0`` a right shift ``x >> y`` for negative ``x`` was equivalent to ``x / 2**y``, + i.e. right shifts used rounding towards zero instead of rounding towards negative infinity. .. index:: ! ufixed, ! fixed, ! fixed point number @@ -144,27 +141,37 @@ Send is the low-level counterpart of ``transfer``. If the execution fails, the c * ``call``, ``callcode`` and ``delegatecall`` Furthermore, to interface with contracts that do not adhere to the ABI, -the function ``call`` is provided which takes an arbitrary number of arguments of any type. These arguments are padded to 32 bytes and concatenated. One exception is the case where the first argument is encoded to exactly four bytes. In this case, it is not padded to allow the use of function signatures here. +or to get more direct control over the encoding, +the function ``call`` is provided which takes a single byte array as input. +The functions ``abi.encode``, ``abi.encodePacked``, ``abi.encodeWithSelector`` +and ``abi.encodeWithSignature`` can be used to encode structured data. -:: +.. warning:: + All these functions are low-level functions and should be used with care. + Specifically, any unknown contract might be malicious and if you call it, you + hand over control to that contract which could in turn call back into + your contract, so be prepared for changes to your state variables + when the call returns. The regular way to interact with other contracts + is to call a function on a contract object (``x.f()``). - address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2; - nameReg.call("register", "MyName"); - nameReg.call(bytes4(keccak256("fun(uint256)")), a); +:: note:: + Previous versions of Solidity allowed these functions to receive + arbitrary arguments and would also handle a first argument of type + ``bytes4`` differently. These edge cases were removed in version 0.5.0. -``call`` returns a boolean indicating whether the invoked function terminated (``true``) or caused an EVM exception (``false``). It is not possible to access the actual data returned (for this we would need to know the encoding and size in advance). +``call`` returns a boolean indicating whether the invoked function terminated (``true``) or caused an EVM exception (``false``). It is not possible to access the actual data returned with plain Solidity. However, using inline assembly it is possible to make a raw ``call`` and access the actual data returned with the ``returndatacopy`` instruction. It is possible to adjust the supplied gas with the ``.gas()`` modifier:: - namReg.call.gas(1000000)("register", "MyName"); + namReg.call.gas(1000000)(abi.encodeWithSignature("register(string)", "MyName")); Similarly, the supplied Ether value can be controlled too:: - nameReg.call.value(1 ether)("register", "MyName"); + nameReg.call.value(1 ether)(abi.encodeWithSignature("register(string)", "MyName")); Lastly, these modifiers can be combined. Their order does not matter:: - nameReg.call.gas(1000000).value(1 ether)("register", "MyName"); + nameReg.call.gas(1000000).value(1 ether)(abi.encodeWithSignature("register(string)", "MyName")); .. note:: It is not yet possible to use the gas or value modifiers on overloaded functions. @@ -185,13 +192,6 @@ The ``.gas()`` option is available on all three methods, while the ``.value()`` .. note:: The use of ``callcode`` is discouraged and will be removed in the future. -.. warning:: - All these functions are low-level functions and should be used with care. - Specifically, any unknown contract might be malicious and if you call it, you - hand over control to that contract which could in turn call back into - your contract, so be prepared for changes to your state variables - when the call returns. - .. index:: byte array, bytes32 @@ -226,10 +226,6 @@ Dynamically-sized byte array ``string``: Dynamically-sized UTF-8-encoded string, see :ref:`arrays`. Not a value-type! -As a rule of thumb, use ``bytes`` for arbitrary-length raw byte data and ``string`` -for arbitrary-length string (UTF-8) data. If you can limit the length to a certain -number of bytes, always use one of ``bytes1`` to ``bytes32`` because they are much cheaper. - .. index:: address, literal;address .. _address_literals: @@ -380,7 +376,7 @@ be passed via and returned from external function calls. Function types are notated as follows:: - function (<parameter types>) {internal|external} [pure|constant|view|payable] [returns (<return types>)] + function (<parameter types>) {internal|external} [pure|view|payable] [returns (<return types>)] In contrast to the parameter types, the return types cannot be empty - if the function type should not return anything, the whole ``returns (<return types>)`` @@ -390,10 +386,6 @@ By default, function types are internal, so the ``internal`` keyword can be omitted. In contrast, contract functions themselves are public by default, only when used as the name of a type, the default is internal. -There are two ways to access a function in the current contract: Either directly -by its name, ``f``, or using ``this.f``. The former will result in an internal -function, the latter in an external function. - If a function type variable is not initialized, calling it will result in an exception. The same happens if you call a function after using ``delete`` on it. @@ -550,7 +542,7 @@ memory-stored reference type do not create a copy. // the data location of memoryArray is memory function f(uint[] memoryArray) public { x = memoryArray; // works, copies the whole array to storage - var y = x; // works, assigns a pointer, data location of y is storage + uint[] storage y = x; // works, assigns a pointer, data location of y is storage y[7]; // fine, returns the 8th element y.length = 2; // fine, modifies x through y delete x; // fine, clears the array, also modifies y @@ -602,8 +594,10 @@ shaves off one level in the type from the right). Variables of type ``bytes`` and ``string`` are special arrays. A ``bytes`` is similar to ``byte[]``, but it is packed tightly in calldata. ``string`` is equal to ``bytes`` but does not allow length or index access (for now). - So ``bytes`` should always be preferred over ``byte[]`` because it is cheaper. +As a rule of thumb, use ``bytes`` for arbitrary-length raw byte data and ``string`` +for arbitrary-length string (UTF-8) data. If you can limit the length to a certain +number of bytes, always use one of ``bytes1`` to ``bytes32`` because they are much cheaper. .. note:: If you want to access the byte-representation of a string ``s``, use @@ -682,7 +676,7 @@ possible: It is planned to remove this restriction in the future but currently creates some complications because of how arrays are passed in the ABI. -.. index:: ! array;length, length, push, !array;push +.. index:: ! array;length, length, push, pop, !array;push, !array;pop Members ^^^^^^^ @@ -693,6 +687,8 @@ Members ``.length`` member. This does not happen automatically when attempting to access elements outside the current length. The size of memory arrays is fixed (but dynamic, i.e. it can depend on runtime parameters) once they are created. **push**: Dynamic storage arrays and ``bytes`` (not ``string``) have a member function called ``push`` that can be used to append an element at the end of the array. The function returns the new length. +**pop**: + Dynamic storage arrays and ``bytes`` (not ``string``) have a member function called ``pop`` that can be used to remove an element from the end of the array. .. warning:: It is not yet possible to use arrays of arrays in external functions. @@ -984,26 +980,3 @@ converted to a matching size. This makes alignment and padding explicit:: bytes32(uint256(x)); // pad on the left bytes32(bytes2(x)); // pad on the right -.. index:: ! type;deduction, ! var - -.. _type-deduction: - -Type Deduction -============== - -For convenience, it is not always necessary to explicitly specify the type of a -variable, the compiler automatically infers it from the type of the first -expression that is assigned to the variable:: - - uint24 x = 0x123; - var y = x; - -Here, the type of ``y`` will be ``uint24``. Using ``var`` is not possible for function -parameters or return parameters. - -.. warning:: - The type is only deduced from the first assignment, so - the loop in the following snippet is infinite, as ``i`` will have the type - ``uint8`` and the highest value of this type is smaller than ``2000``. - ``for (var i = 0; i < 2000; i++) { ... }`` - diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst index a6f8ca87..b24b8b71 100644 --- a/docs/units-and-global-variables.rst +++ b/docs/units-and-global-variables.rst @@ -32,7 +32,7 @@ Due to the fact that leap seconds cannot be predicted, an exact calendar library has to be updated by an external oracle. .. note:: - The suffix ``years`` has been deprecated due to the reasons above. + The suffix ``years`` has been deprecated due to the reasons above and cannot be used starting version 0.5.0. These suffixes cannot be applied to variables. If you want to interpret some input variable in e.g. days, you can do it in the following way:: @@ -100,16 +100,16 @@ ABI Encoding Functions ---------------------- - ``abi.encode(...) returns (bytes)``: ABI-encodes the given arguments -- ``abi.encodePacked(...) returns (bytes)``: Performes packed encoding of the given arguments +- ``abi.encodePacked(...) returns (bytes)``: Performs :ref:`packed encoding <abi_packed_mode>` of the given arguments - ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: ABI-encodes the given arguments starting from the second and prepends the given four-byte selector -- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(signature), ...)``` +- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)``` .. note:: These encoding functions can be used to craft data for function calls without actually - calling a function. Furthermore, ``keccak256(abi.encodePacked(a, b))`` is a more - explicit way to compute ``keccak256(a, b)``, which will be deprecated in future - versions. + calling a function. Furthermore, ``keccak256(abi.encodePacked(a, b))`` is a way + to compute the hash of structured data (although be aware that it is possible to + craft a "hash collision" using different inputs types). See the documentation about the :ref:`ABI <ABI>` and the :ref:`tightly packed encoding <abi_packed_mode>` for details about the encoding. @@ -139,34 +139,18 @@ Mathematical and Cryptographic Functions compute ``(x + y) % k`` where the addition is performed with arbitrary precision and does not wrap around at ``2**256``. Assert that ``k != 0`` starting from version 0.5.0. ``mulmod(uint x, uint y, uint k) returns (uint)``: compute ``(x * y) % k`` where the multiplication is performed with arbitrary precision and does not wrap around at ``2**256``. Assert that ``k != 0`` starting from version 0.5.0. -``keccak256(...) returns (bytes32)``: - compute the Ethereum-SHA-3 (Keccak-256) hash of the :ref:`(tightly packed) arguments <abi_packed_mode>` -``sha256(...) returns (bytes32)``: - compute the SHA-256 hash of the :ref:`(tightly packed) arguments <abi_packed_mode>` -``sha3(...) returns (bytes32)``: +``keccak256(bytes memory) returns (bytes32)``: + compute the Ethereum-SHA-3 (Keccak-256) hash of the input +``sha256(bytes memory) returns (bytes32)``: + compute the SHA-256 hash of the input +``sha3(bytes memory) returns (bytes32)``: alias to ``keccak256`` -``ripemd160(...) returns (bytes20)``: - compute RIPEMD-160 hash of the :ref:`(tightly packed) arguments <abi_packed_mode>` +``ripemd160(bytes memory) returns (bytes20)``: + compute RIPEMD-160 hash of the input ``ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)``: recover the address associated with the public key from elliptic curve signature or return zero on error (`example usage <https://ethereum.stackexchange.com/q/1777/222>`_) -In the above, "tightly packed" means that the arguments are concatenated without padding. -This means that the following are all identical:: - - keccak256("ab", "c") - keccak256("abc") - keccak256(0x616263) - keccak256(6382179) - keccak256(97, 98, 99) - -If padding is needed, explicit type conversions can be used: ``keccak256("\x00\x12")`` is the -same as ``keccak256(uint16(0x12))``. - -Note that constants will be packed using the minimum number of bytes required to store them. -This means that, for example, ``keccak256(0) == keccak256(uint8(0))`` and -``keccak256(0x12345678) == keccak256(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. .. index:: balance, send, transfer, call, callcode, delegatecall @@ -181,12 +165,12 @@ Address Related send given amount of Wei to :ref:`address`, throws on failure, forwards 2300 gas stipend, not adjustable ``<address>.send(uint256 amount) returns (bool)``: send given amount of Wei to :ref:`address`, returns ``false`` on failure, forwards 2300 gas stipend, not adjustable -``<address>.call(...) returns (bool)``: - issue low-level ``CALL``, returns ``false`` on failure, forwards all available gas, adjustable -``<address>.callcode(...) returns (bool)``: - issue low-level ``CALLCODE``, returns ``false`` on failure, forwards all available gas, adjustable -``<address>.delegatecall(...) returns (bool)``: - issue low-level ``DELEGATECALL``, returns ``false`` on failure, forwards all available gas, adjustable +``<address>.call(bytes memory) returns (bool)``: + issue low-level ``CALL`` with the given payload, returns ``false`` on failure, forwards all available gas, adjustable +``<address>.callcode(bytes memory) returns (bool)``: + issue low-level ``CALLCODE`` with the given payload, returns ``false`` on failure, forwards all available gas, adjustable +``<address>.delegatecall(bytes memory) returns (bool)``: + issue low-level ``DELEGATECALL`` with the given payload, returns ``false`` on failure, forwards all available gas, adjustable For more information, see the section on :ref:`address`. @@ -197,6 +181,10 @@ For more information, see the section on :ref:`address`. Use a pattern where the recipient withdraws the money. .. note:: + Prior to version 0.5.0, Solidity allowed address members to be accessed by a contract instance, for example ``this.balance``. + This is now forbidden and an explicit conversion to address must be done: ``address(this).balance``. + +.. note:: If storage variables are accessed via a low-level delegatecall, the storage layout of the two contracts must align in order for the called contract to correctly access the storage variables of the calling contract by name. This is of course not the case if storage pointers are passed as function arguments as in the case for diff --git a/docs/julia.rst b/docs/yul.rst index c9b73db2..87ec0c03 100644 --- a/docs/julia.rst +++ b/docs/yul.rst @@ -1,18 +1,19 @@ -################################################# -Joyfully Universal Language for (Inline) Assembly -################################################# +### +Yul +### -.. _julia: +.. _yul: -.. index:: ! assembly, ! asm, ! evmasm, ! julia +.. index:: ! assembly, ! asm, ! evmasm, ! yul, julia, iulia -JULIA is an intermediate language that can compile to various different backends +Yul (previously also called JULIA or IULIA) is an intermediate language that can +compile to various different backends (EVM 1.0, EVM 1.5 and eWASM are planned). Because of that, it is designed to be a usable common denominator of all three platforms. It can already be used for "inline assembly" inside Solidity and -future versions of the Solidity compiler will even use JULIA as intermediate -language. It should also be easy to build high-level optimizer stages for JULIA. +future versions of the Solidity compiler will even use Yul as intermediate +language. It should also be easy to build high-level optimizer stages for Yul. .. note:: @@ -21,14 +22,14 @@ language. It should also be easy to build high-level optimizer stages for JULIA. to the EVM opcodes. Please resort to the inline assembly documentation for details. -The core components of JULIA are functions, blocks, variables, literals, +The core components of Yul are functions, blocks, variables, literals, for-loops, if-statements, switch-statements, expressions and assignments to variables. -JULIA is typed, both variables and literals must specify the type with postfix +Yul is typed, both variables and literals must specify the type with postfix notation. The supported types are ``bool``, ``u8``, ``s8``, ``u32``, ``s32``, ``u64``, ``s64``, ``u128``, ``s128``, ``u256`` and ``s256``. -JULIA in itself does not even provide operators. If the EVM is targeted, +Yul in itself does not even provide operators. If the EVM is targeted, opcodes will be available as built-in functions, but they can be reimplemented if the backend changes. For a list of mandatory built-in functions, see the section below. @@ -69,10 +70,10 @@ and ``add`` to be available. } } -Specification of JULIA -====================== +Specification of Yul +==================== -JULIA code is described in this chapter. JULIA code is usually placed into a JULIA object, which is described in the following chapter. +This chapter describes Yul code. It is usually placed inside a Yul object, which is described in the following chapter. Grammar:: @@ -156,7 +157,7 @@ Literals cannot be larger than the their type. The largest type defined is 256-b Scoping Rules ------------- -Scopes in JULIA are tied to Blocks (exceptions are functions and the for loop +Scopes in Yul are tied to Blocks (exceptions are functions and the for loop as explained below) and all declarations (``FunctionDefinition``, ``VariableDeclaration``) introduce new identifiers into these scopes. @@ -186,7 +187,7 @@ outside of that function. Formal Specification -------------------- -We formally specify JULIA by providing an evaluation function E overloaded +We formally specify Yul by providing an evaluation function E overloaded on the various nodes of the AST. Any functions can have side effects, so E takes two state objects and the AST node and returns two new state objects and a variable number of other values. @@ -303,7 +304,7 @@ We will use a destructuring notation for the AST nodes. Type Conversion Functions ------------------------- -JULIA has no support for implicit type conversion and therefore functions exists to provide explicit conversion. +Yul has no support for implicit type conversion and therefore functions exist to provide explicit conversion. When converting a larger type to a shorter type a runtime exception can occur in case of an overflow. Truncating conversions are supported between the following types: @@ -337,7 +338,7 @@ The following functions must be available: +---------------------------------------------+-----------------------------------------------------------------+ | xor(x:bool, y:bool) -> z:bool | xor | +---------------------------------------------+-----------------------------------------------------------------+ -| *Arithmetics* | +| *Arithmetic* | +---------------------------------------------+-----------------------------------------------------------------+ | addu256(x:u256, y:u256) -> z:u256 | x + y | +---------------------------------------------+-----------------------------------------------------------------+ @@ -357,9 +358,9 @@ The following functions must be available: +---------------------------------------------+-----------------------------------------------------------------+ | expu256(x:u256, y:u256) -> z:u256 | x to the power of y | +---------------------------------------------+-----------------------------------------------------------------+ -| addmodu256(x:u256, y:u256, m:u256) -> z:u256| (x + y) % m with arbitrary precision arithmetics | +| addmodu256(x:u256, y:u256, m:u256) -> z:u256| (x + y) % m with arbitrary precision arithmetic | +---------------------------------------------+-----------------------------------------------------------------+ -| mulmodu256(x:u256, y:u256, m:u256) -> z:u256| (x * y) % m with arbitrary precision arithmetics | +| mulmodu256(x:u256, y:u256, m:u256) -> z:u256| (x * y) % m with arbitrary precision arithmetic | +---------------------------------------------+-----------------------------------------------------------------+ | ltu256(x:u256, y:u256) -> z:bool | true if x < y, false otherwise | +---------------------------------------------+-----------------------------------------------------------------+ @@ -507,7 +508,7 @@ The following functions must be available: Backends -------- -Backends or targets are the translators from JULIA to a specific bytecode. Each of the backends can expose functions +Backends or targets are the translators from Yul to a specific bytecode. Each of the backends can expose functions prefixed with the name of the backend. We reserve ``evm_`` and ``ewasm_`` prefixes for the two proposed backends. Backend: EVM @@ -525,8 +526,8 @@ Backend: eWASM TBD -Specification of JULIA Object -============================= +Specification of Yul Object +=========================== Grammar:: @@ -537,11 +538,11 @@ Grammar:: HexLiteral = 'hex' ('"' ([0-9a-fA-F]{2})* '"' | '\'' ([0-9a-fA-F]{2})* '\'') StringLiteral = '"' ([^"\r\n\\] | '\\' .)* '"' -Above, ``Block`` refers to ``Block`` in the JULIA code grammar explained in the previous chapter. +Above, ``Block`` refers to ``Block`` in the Yul code grammar explained in the previous chapter. -An example JULIA Object is shown below: +An example Yul Object is shown below: -..code:: +.. code:: // Code consists of a single object. A single "code" node is the code of the object. // Every (other) named object or data section is serialized and diff --git a/libevmasm/ControlFlowGraph.h b/libevmasm/ControlFlowGraph.h index ebef543f..f0c9356c 100644 --- a/libevmasm/ControlFlowGraph.h +++ b/libevmasm/ControlFlowGraph.h @@ -39,7 +39,7 @@ using KnownStatePointer = std::shared_ptr<KnownState>; /** * Identifier for a block, coincides with the tag number of an AssemblyItem but adds a special - * ID for the inital block. + * ID for the initial block. */ class BlockId { diff --git a/libevmasm/GasMeter.h b/libevmasm/GasMeter.h index b131802f..fc3740d2 100644 --- a/libevmasm/GasMeter.h +++ b/libevmasm/GasMeter.h @@ -112,9 +112,10 @@ public: static GasConsumption infinite() { return GasConsumption(0, true); } GasConsumption& operator+=(GasConsumption const& _other); - bool operator<(GasConsumption const& _other) const { return this->tuple() < _other.tuple(); } - - std::tuple<bool const&, u256 const&> tuple() const { return std::tie(isInfinite, value); } + bool operator<(GasConsumption const& _other) const + { + return std::make_pair(isInfinite, value) < std::make_pair(_other.isInfinite, _other.value); + } u256 value; bool isInfinite; diff --git a/libevmasm/KnownState.cpp b/libevmasm/KnownState.cpp index e2f10f22..7c593fc9 100644 --- a/libevmasm/KnownState.cpp +++ b/libevmasm/KnownState.cpp @@ -121,28 +121,33 @@ KnownState::StoreOperation KnownState::feedItem(AssemblyItem const& _item, bool vector<Id> arguments(info.args); for (int i = 0; i < info.args; ++i) arguments[i] = stackElement(m_stackHeight - i, _item.location()); - - if (_item.instruction() == Instruction::SSTORE) + switch (_item.instruction()) + { + case Instruction::SSTORE: op = storeInStorage(arguments[0], arguments[1], _item.location()); - else if (_item.instruction() == Instruction::SLOAD) + break; + case Instruction::SLOAD: setStackElement( m_stackHeight + _item.deposit(), loadFromStorage(arguments[0], _item.location()) ); - else if (_item.instruction() == Instruction::MSTORE) + break; + case Instruction::MSTORE: op = storeInMemory(arguments[0], arguments[1], _item.location()); - else if (_item.instruction() == Instruction::MLOAD) + break; + case Instruction::MLOAD: setStackElement( m_stackHeight + _item.deposit(), loadFromMemory(arguments[0], _item.location()) ); - else if (_item.instruction() == Instruction::KECCAK256) + break; + case Instruction::KECCAK256: setStackElement( m_stackHeight + _item.deposit(), applyKeccak256(arguments.at(0), arguments.at(1), _item.location()) ); - else - { + break; + default: bool invMem = SemanticInformation::invalidatesMemory(_item.instruction()); bool invStor = SemanticInformation::invalidatesStorage(_item.instruction()); // We could be a bit more fine-grained here (CALL only invalidates part of diff --git a/libevmasm/LinkerObject.cpp b/libevmasm/LinkerObject.cpp index 8b7d9e06..1d5efecb 100644 --- a/libevmasm/LinkerObject.cpp +++ b/libevmasm/LinkerObject.cpp @@ -68,7 +68,7 @@ LinkerObject::matchLibrary( if (it != _libraryAddresses.end()) return &it->second; // If the user did not supply a fully qualified library name, - // try to match only the simple libary name + // try to match only the simple library name size_t colon = _linkRefName.find(':'); if (colon == string::npos) return nullptr; diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp index 8a39de24..6d8e1df6 100644 --- a/libevmasm/PeepholeOptimiser.cpp +++ b/libevmasm/PeepholeOptimiser.cpp @@ -249,6 +249,23 @@ struct TagConjunctions: SimplePeepholeOptimizerMethod<TagConjunctions, 3> } }; +struct TruthyAnd: SimplePeepholeOptimizerMethod<TruthyAnd, 3> +{ + static bool applySimple( + AssemblyItem const& _push, + AssemblyItem const& _not, + AssemblyItem const& _and, + std::back_insert_iterator<AssemblyItems> + ) + { + return ( + _push.type() == Push && _push.data() == 0 && + _not == Instruction::NOT && + _and == Instruction::AND + ); + } +}; + /// Removes everything after a JUMP (or similar) until the next JUMPDEST. struct UnreachableCode { @@ -305,7 +322,7 @@ bool PeepholeOptimiser::optimise() { OptimiserState state {m_items, 0, std::back_inserter(m_optimisedItems)}; while (state.i < m_items.size()) - applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity()); + applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(), JumpToNext(), UnreachableCode(), TagConjunctions(), TruthyAnd(), Identity()); if (m_optimisedItems.size() < m_items.size() || ( m_optimisedItems.size() == m_items.size() && ( eth::bytesRequired(m_optimisedItems, 3) < eth::bytesRequired(m_items, 3) || diff --git a/libevmasm/RuleList.h b/libevmasm/RuleList.h index 2b7da01b..7a2bc484 100644 --- a/libevmasm/RuleList.h +++ b/libevmasm/RuleList.h @@ -59,7 +59,7 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList( { std::vector<SimplificationRule<Pattern>> rules; rules += std::vector<SimplificationRule<Pattern>>{ - // arithmetics on constants + // arithmetic on constants {{Instruction::ADD, {A, B}}, [=]{ return A.d() + B.d(); }, false}, {{Instruction::MUL, {A, B}}, [=]{ return A.d() * B.d(); }, false}, {{Instruction::SUB, {A, B}}, [=]{ return A.d() - B.d(); }, false}, diff --git a/libevmasm/SimplificationRules.cpp b/libevmasm/SimplificationRules.cpp index 53a5f9fc..504dbc24 100644 --- a/libevmasm/SimplificationRules.cpp +++ b/libevmasm/SimplificationRules.cpp @@ -67,7 +67,7 @@ void Rules::addRule(SimplificationRule<Pattern> const& _rule) Rules::Rules() { - // Multiple occurences of one of these inside one rule must match the same equivalence class. + // Multiple occurrences of one of these inside one rule must match the same equivalence class. // Constants. Pattern A(Push); Pattern B(Push); diff --git a/libjulia/Exceptions.h b/libjulia/Exceptions.h index 20ab6520..48624a56 100644 --- a/libjulia/Exceptions.h +++ b/libjulia/Exceptions.h @@ -15,7 +15,7 @@ along with solidity. If not, see <http://www.gnu.org/licenses/>. */ /** - * Exceptions in Julia. + * Exceptions in Yul. */ #pragma once @@ -28,8 +28,8 @@ namespace dev namespace julia { -struct IuliaException: virtual Exception {}; -struct OptimizerException: virtual IuliaException {}; +struct YulException: virtual Exception {}; +struct OptimizerException: virtual YulException {}; } } diff --git a/libjulia/backends/evm/AbstractAssembly.h b/libjulia/backends/evm/AbstractAssembly.h index 8e90a912..6b1b5c23 100644 --- a/libjulia/backends/evm/AbstractAssembly.h +++ b/libjulia/backends/evm/AbstractAssembly.h @@ -42,7 +42,7 @@ namespace julia { /// -/// Assembly class that abstracts both the libevmasm assembly and the new julia evm assembly. +/// Assembly class that abstracts both the libevmasm assembly and the new Yul assembly. /// class AbstractAssembly { @@ -68,7 +68,7 @@ public: virtual LabelID newLabelId() = 0; /// Returns a label identified by the given name. Creates it if it does not yet exist. virtual LabelID namedLabel(std::string const& _name) = 0; - /// Append a reference to a to-be-linked symobl. + /// Append a reference to a to-be-linked symbol. /// Currently, we assume that the value is always a 20 byte number. virtual void appendLinkerSymbol(std::string const& _name) = 0; diff --git a/libjulia/backends/evm/EVMAssembly.h b/libjulia/backends/evm/EVMAssembly.h index 593cee6a..56ae7655 100644 --- a/libjulia/backends/evm/EVMAssembly.h +++ b/libjulia/backends/evm/EVMAssembly.h @@ -54,7 +54,7 @@ public: virtual LabelID newLabelId() override; /// Returns a label identified by the given name. Creates it if it does not yet exist. virtual LabelID namedLabel(std::string const& _name) override; - /// Append a reference to a to-be-linked symobl. + /// Append a reference to a to-be-linked symbol. /// Currently, we assume that the value is always a 20 byte number. virtual void appendLinkerSymbol(std::string const& _name) override; diff --git a/libjulia/backends/evm/EVMCodeTransform.cpp b/libjulia/backends/evm/EVMCodeTransform.cpp index 2a97429b..ba2d7f75 100644 --- a/libjulia/backends/evm/EVMCodeTransform.cpp +++ b/libjulia/backends/evm/EVMCodeTransform.cpp @@ -15,7 +15,7 @@ along with solidity. If not, see <http://www.gnu.org/licenses/>. */ /** - * Common code generator for translating Julia / inline assembly to EVM and EVM1.5. + * Common code generator for translating Yul / inline assembly to EVM and EVM1.5. */ #include <libjulia/backends/evm/EVMCodeTransform.h> @@ -331,7 +331,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) CodeTransform( m_assembly, m_info, - m_julia, + m_yul, m_evm15, m_identifierAccess, m_useNamedLabelsForFunctions, diff --git a/libjulia/backends/evm/EVMCodeTransform.h b/libjulia/backends/evm/EVMCodeTransform.h index f8eec0b7..ed0785d3 100644 --- a/libjulia/backends/evm/EVMCodeTransform.h +++ b/libjulia/backends/evm/EVMCodeTransform.h @@ -15,7 +15,7 @@ along with solidity. If not, see <http://www.gnu.org/licenses/>. */ /** - * Common code generator for translating Julia / inline assembly to EVM and EVM1.5. + * Common code generator for translating Yul / inline assembly to EVM and EVM1.5. */ #include <libjulia/backends/evm/EVMAssembly.h> @@ -49,14 +49,14 @@ public: CodeTransform( julia::AbstractAssembly& _assembly, solidity::assembly::AsmAnalysisInfo& _analysisInfo, - bool _julia = false, + bool _yul = false, bool _evm15 = false, ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(), bool _useNamedLabelsForFunctions = false ): CodeTransform( _assembly, _analysisInfo, - _julia, + _yul, _evm15, _identifierAccess, _useNamedLabelsForFunctions, @@ -78,7 +78,7 @@ protected: CodeTransform( julia::AbstractAssembly& _assembly, solidity::assembly::AsmAnalysisInfo& _analysisInfo, - bool _julia, + bool _yul, bool _evm15, ExternalIdentifierAccess const& _identifierAccess, bool _useNamedLabelsForFunctions, @@ -87,7 +87,7 @@ protected: ): m_assembly(_assembly), m_info(_analysisInfo), - m_julia(_julia), + m_yul(_yul), m_evm15(_evm15), m_useNamedLabelsForFunctions(_useNamedLabelsForFunctions), m_identifierAccess(_identifierAccess), @@ -142,7 +142,7 @@ private: julia::AbstractAssembly& m_assembly; solidity::assembly::AsmAnalysisInfo& m_info; solidity::assembly::Scope* m_scope = nullptr; - bool m_julia = false; + bool m_yul = false; bool m_evm15 = false; bool m_useNamedLabelsForFunctions = false; ExternalIdentifierAccess m_identifierAccess; diff --git a/libjulia/optimiser/ASTCopier.h b/libjulia/optimiser/ASTCopier.h index 8681f2e0..cb2925e3 100644 --- a/libjulia/optimiser/ASTCopier.h +++ b/libjulia/optimiser/ASTCopier.h @@ -62,7 +62,7 @@ public: }; /** - * Creates a copy of a iulia AST potentially replacing identifier names. + * Creates a copy of a Yul AST potentially replacing identifier names. * Base class to be extended. */ class ASTCopier: public ExpressionCopier, public StatementCopier diff --git a/libjulia/optimiser/DataFlowAnalyzer.cpp b/libjulia/optimiser/DataFlowAnalyzer.cpp index 25f0ffb4..0ad0eac9 100644 --- a/libjulia/optimiser/DataFlowAnalyzer.cpp +++ b/libjulia/optimiser/DataFlowAnalyzer.cpp @@ -15,7 +15,7 @@ along with solidity. If not, see <http://www.gnu.org/licenses/>. */ /** - * Base class to perform data flaw analysis during AST walks. + * Base class to perform data flow analysis during AST walks. * Tracks assignments and is used as base class for both Rematerialiser and * Common Subexpression Eliminator. */ diff --git a/libjulia/optimiser/DataFlowAnalyzer.h b/libjulia/optimiser/DataFlowAnalyzer.h index 4cb3d4cd..66df2f48 100644 --- a/libjulia/optimiser/DataFlowAnalyzer.h +++ b/libjulia/optimiser/DataFlowAnalyzer.h @@ -56,7 +56,7 @@ protected: /// Registers the assignment. void handleAssignment(std::set<std::string> const& _names, Expression* _value); - /// Clears information about the valuse assigned to the given variables, + /// Clears information about the values assigned to the given variables, /// for example at points where control flow is merged. void clearValues(std::set<std::string> const& _names); diff --git a/libjulia/optimiser/Disambiguator.h b/libjulia/optimiser/Disambiguator.h index 6fc8a615..4ef43736 100644 --- a/libjulia/optimiser/Disambiguator.h +++ b/libjulia/optimiser/Disambiguator.h @@ -38,7 +38,7 @@ namespace julia { /** - * Creates a copy of a iulia AST replacing all identifiers by unique names. + * Creates a copy of a Yul AST replacing all identifiers by unique names. */ class Disambiguator: public ASTCopier { diff --git a/libjulia/optimiser/README.md b/libjulia/optimiser/README.md index e8aa777a..b26da0c7 100644 --- a/libjulia/optimiser/README.md +++ b/libjulia/optimiser/README.md @@ -1,6 +1,10 @@ -## IULIA Optimiser +Note that the Yul optimiser is still in research phase. Because of that, +the following description might not fully reflect the current or even +planned state of the optimiser. -The iulia optimiser consists of several stages and components that all transform +## Yul Optimiser + +The Yul optimiser consists of several stages and components that all transform the AST in a semantically equivalent way. The goal is to end up either with code that is shorter or at least only marginally longer but will allow further optimisation steps. @@ -25,13 +29,13 @@ a semantically equivalent transformation as long as it is performed after the disambiguation stage. The reason is that moving a definition upwards cannot decrease its visibility and it is impossible to reference variables defined in a different function. -The benefit of this stage is that function definitions can be lookup up more easily. +The benefit of this stage is that function definitions can be looked up more easily. ## Function Grouper The function grouper has to be applied after the disambiguator and the function hoister. Its effect is that all topmost elements that are not function definitions are moved -into a single block which is the first satement of the root block. +into a single block which is the first statement of the root block. After this step, a program has the following normal form: @@ -81,7 +85,7 @@ a loop or conditional, the first one is not inside), the first assignment is rem ## Expression Simplifier -This step can only be applied for the EVM-flavoured dialect of iulia. It applies +This step can only be applied for the EVM-flavoured dialect of Yul. It applies simple rules like ``x + 0 == x`` to simplify expressions. ## Ineffective Statement Remover diff --git a/libjulia/optimiser/SimplificationRules.cpp b/libjulia/optimiser/SimplificationRules.cpp index 070d5484..a5e296c3 100644 --- a/libjulia/optimiser/SimplificationRules.cpp +++ b/libjulia/optimiser/SimplificationRules.cpp @@ -64,7 +64,7 @@ void SimplificationRules::addRule(SimplificationRule<Pattern> const& _rule) SimplificationRules::SimplificationRules() { - // Multiple occurences of one of these inside one rule must match the same equivalence class. + // Multiple occurrences of one of these inside one rule must match the same equivalence class. // Constants. Pattern A(PatternKind::Constant); Pattern B(PatternKind::Constant); diff --git a/libjulia/optimiser/UnusedPruner.cpp b/libjulia/optimiser/UnusedPruner.cpp index 54e8fd6e..af503712 100644 --- a/libjulia/optimiser/UnusedPruner.cpp +++ b/libjulia/optimiser/UnusedPruner.cpp @@ -59,7 +59,7 @@ void UnusedPruner::operator()(Block& _block) // Multi-variable declarations are special. We can only remove it // if all vairables are unused and the right-hand-side is either // movable or it return a single value. In the latter case, we - // replace `let a := f()` by `pop(f())` (in pure IULIA, this will be + // replace `let a := f()` by `pop(f())` (in pure Yul, this will be // `drop(f())`). if (boost::algorithm::none_of( varDecl.variables, @@ -74,7 +74,7 @@ void UnusedPruner::operator()(Block& _block) statement = Block{std::move(varDecl.location), {}}; } else if (varDecl.variables.size() == 1) - // In pure IULIA, this should be replaced by a function call to `drop` + // In pure Yul, this should be replaced by a function call to `drop` // instead of `pop`. statement = ExpressionStatement{varDecl.location, FunctionalInstruction{ varDecl.location, diff --git a/libsolc/CMakeLists.txt b/libsolc/CMakeLists.txt index e67583dd..63fc1a83 100644 --- a/libsolc/CMakeLists.txt +++ b/libsolc/CMakeLists.txt @@ -1,5 +1,5 @@ if (EMSCRIPTEN) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s EXPORTED_FUNCTIONS='[\"_compileJSON\",\"_license\",\"_version\",\"_compileJSONMulti\",\"_compileJSONCallback\",\"_compileStandard\"]' -s RESERVED_FUNCTION_POINTERS=20") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s EXPORTED_FUNCTIONS='[\"_solidity_license\",\"_solidity_version\",\"_solidity_compile\",\"_license\",\"_version\",\"_compileJSON\",\"_compileJSONMulti\",\"_compileJSONCallback\",\"_compileStandard\"]' -s RESERVED_FUNCTION_POINTERS=20") add_executable(soljson libsolc.cpp) target_link_libraries(soljson PRIVATE solidity) else() diff --git a/libsolc/libsolc.cpp b/libsolc/libsolc.cpp index 6c587e23..26ce98ce 100644 --- a/libsolc/libsolc.cpp +++ b/libsolc/libsolc.cpp @@ -299,4 +299,19 @@ extern char const* compileStandard(char const* _input, CStyleReadFileCallback _r s_outputBuffer = compileStandardInternal(_input, _readCallback); return s_outputBuffer.c_str(); } +extern char const* solidity_license() +{ + /// todo: make this the default or an alias + return license(); +} +extern char const* solidity_version() +{ + /// todo: make this the default or an alias + return version(); +} +extern char const* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback) +{ + /// todo: make this the default or an alias + return compileStandard(_input, _readCallback); +} } diff --git a/libsolc/libsolc.h b/libsolc/libsolc.h index c392ce93..2cc004d4 100644 --- a/libsolc/libsolc.h +++ b/libsolc/libsolc.h @@ -37,6 +37,10 @@ char const* compileJSONMulti(char const* _input, bool _optimize); char const* compileJSONCallback(char const* _input, bool _optimize, CStyleReadFileCallback _readCallback); char const* compileStandard(char const* _input, CStyleReadFileCallback _readCallback); +char const* solidity_license(); +char const* solidity_version(); +char const* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback); + #ifdef __cplusplus } #endif diff --git a/libsolidity/analysis/DeclarationContainer.cpp b/libsolidity/analysis/DeclarationContainer.cpp index 786272e4..9e2bf6d3 100644 --- a/libsolidity/analysis/DeclarationContainer.cpp +++ b/libsolidity/analysis/DeclarationContainer.cpp @@ -96,6 +96,11 @@ void DeclarationContainer::activateVariable(ASTString const& _name) m_invisibleDeclarations.erase(_name); } +bool DeclarationContainer::isInvisible(ASTString const& _name) const +{ + return m_invisibleDeclarations.count(_name); +} + bool DeclarationContainer::registerDeclaration( Declaration const& _declaration, ASTString const* _name, diff --git a/libsolidity/analysis/DeclarationContainer.h b/libsolidity/analysis/DeclarationContainer.h index e4b3320a..9d7a17a3 100644 --- a/libsolidity/analysis/DeclarationContainer.h +++ b/libsolidity/analysis/DeclarationContainer.h @@ -58,10 +58,13 @@ public: /// @returns whether declaration is valid, and if not also returns previous declaration. Declaration const* conflictingDeclaration(Declaration const& _declaration, ASTString const* _name = nullptr) const; - /// Activates a previously inactive (invisible) variable. To be used in C99 scpoing for + /// Activates a previously inactive (invisible) variable. To be used in C99 scoping for /// VariableDeclarationStatements. void activateVariable(ASTString const& _name); + /// @returns true if declaration is currently invisible. + bool isInvisible(ASTString const& _name) const; + /// @returns existing declaration names similar to @a _name. /// Searches this and all parent containers. std::vector<ASTString> similarNames(ASTString const& _name) const; diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp index 756bb540..7b4bc3aa 100644 --- a/libsolidity/analysis/GlobalContext.cpp +++ b/libsolidity/analysis/GlobalContext.cpp @@ -42,7 +42,7 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{ make_shared<MagicVariableDeclaration>("blockhash", make_shared<FunctionType>(strings{"uint256"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)), make_shared<MagicVariableDeclaration>("ecrecover", make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, false, StateMutability::Pure)), make_shared<MagicVariableDeclaration>("gasleft", make_shared<FunctionType>(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft, false, StateMutability::View)), - make_shared<MagicVariableDeclaration>("keccak256", make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true, StateMutability::Pure)), + make_shared<MagicVariableDeclaration>("keccak256", make_shared<FunctionType>(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SHA3, false, StateMutability::Pure)), make_shared<MagicVariableDeclaration>("log0", make_shared<FunctionType>(strings{"bytes32"}, strings{}, FunctionType::Kind::Log0)), make_shared<MagicVariableDeclaration>("log1", make_shared<FunctionType>(strings{"bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log1)), make_shared<MagicVariableDeclaration>("log2", make_shared<FunctionType>(strings{"bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log2)), @@ -55,10 +55,10 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{ make_shared<MagicVariableDeclaration>("require", make_shared<FunctionType>(strings{"bool", "string memory"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)), make_shared<MagicVariableDeclaration>("revert", make_shared<FunctionType>(strings(), strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)), make_shared<MagicVariableDeclaration>("revert", make_shared<FunctionType>(strings{"string memory"}, strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)), - make_shared<MagicVariableDeclaration>("ripemd160", make_shared<FunctionType>(strings(), strings{"bytes20"}, FunctionType::Kind::RIPEMD160, true, StateMutability::Pure)), + make_shared<MagicVariableDeclaration>("ripemd160", make_shared<FunctionType>(strings{"bytes memory"}, strings{"bytes20"}, FunctionType::Kind::RIPEMD160, false, StateMutability::Pure)), make_shared<MagicVariableDeclaration>("selfdestruct", make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Kind::Selfdestruct)), - make_shared<MagicVariableDeclaration>("sha256", make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA256, true, StateMutability::Pure)), - make_shared<MagicVariableDeclaration>("sha3", make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true, StateMutability::Pure)), + make_shared<MagicVariableDeclaration>("sha256", make_shared<FunctionType>(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SHA256, false, StateMutability::Pure)), + make_shared<MagicVariableDeclaration>("sha3", make_shared<FunctionType>(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SHA3, false, StateMutability::Pure)), make_shared<MagicVariableDeclaration>("suicide", make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Kind::Selfdestruct)), make_shared<MagicVariableDeclaration>("tx", make_shared<MagicType>(MagicType::Kind::Transaction)) }) diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index 0a356f04..7c23c992 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -54,11 +54,10 @@ NameAndTypeResolver::NameAndTypeResolver( bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit, ASTNode const* _currentScope) { - bool useC99Scoping = _sourceUnit.annotation().experimentalFeatures.count(ExperimentalFeature::V050); // The helper registers all declarations in m_scopes as a side-effect of its construction. try { - DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, useC99Scoping, m_errorReporter, _currentScope); + DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, m_errorReporter, _currentScope); } catch (FatalError const&) { @@ -157,7 +156,13 @@ bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration) void NameAndTypeResolver::activateVariable(string const& _name) { solAssert(m_currentScope, ""); - m_currentScope->activateVariable(_name); + // Scoped local variables are invisible before activation. + // When a local variable is activated, its name is removed + // from a scope's invisible variables. + // This is used to avoid activation of variables of same name + // in the same scope (an error is returned). + if (m_currentScope->isInvisible(_name)) + m_currentScope->activateVariable(_name); } vector<Declaration const*> NameAndTypeResolver::resolveName(ASTString const& _name, ASTNode const* _scope) const @@ -449,11 +454,9 @@ string NameAndTypeResolver::similarNameSuggestions(ASTString const& _name) const DeclarationRegistrationHelper::DeclarationRegistrationHelper( map<ASTNode const*, shared_ptr<DeclarationContainer>>& _scopes, ASTNode& _astRoot, - bool _useC99Scoping, ErrorReporter& _errorReporter, ASTNode const* _currentScope ): - m_useC99Scoping(_useC99Scoping), m_scopes(_scopes), m_currentScope(_currentScope), m_errorReporter(_errorReporter) @@ -629,29 +632,25 @@ void DeclarationRegistrationHelper::endVisit(ModifierDefinition&) bool DeclarationRegistrationHelper::visit(Block& _block) { _block.setScope(m_currentScope); - if (m_useC99Scoping) - enterNewSubScope(_block); + enterNewSubScope(_block); return true; } void DeclarationRegistrationHelper::endVisit(Block&) { - if (m_useC99Scoping) - closeCurrentScope(); + closeCurrentScope(); } bool DeclarationRegistrationHelper::visit(ForStatement& _for) { _for.setScope(m_currentScope); - if (m_useC99Scoping) - enterNewSubScope(_for); + enterNewSubScope(_for); return true; } void DeclarationRegistrationHelper::endVisit(ForStatement&) { - if (m_useC99Scoping) - closeCurrentScope(); + closeCurrentScope(); } void DeclarationRegistrationHelper::endVisit(VariableDeclarationStatement& _variableDeclarationStatement) @@ -716,9 +715,8 @@ void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaratio if (fun->isConstructor()) warnAboutShadowing = false; - // Register declaration as inactive if we are in block scope and C99 mode. + // Register declaration as inactive if we are in block scope. bool inactive = - m_useC99Scoping && (dynamic_cast<Block const*>(m_currentScope) || dynamic_cast<ForStatement const*>(m_currentScope)); registerDeclaration(*m_scopes[m_currentScope], _declaration, nullptr, nullptr, warnAboutShadowing, inactive, m_errorReporter); diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index 3d10fbd8..8178ee17 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -69,7 +69,7 @@ public: /// that create their own scope. /// @returns false in case of error. bool updateDeclaration(Declaration const& _declaration); - /// Activates a previously inactive (invisible) variable. To be used in C99 scpoing for + /// Activates a previously inactive (invisible) variable. To be used in C99 scoping for /// VariableDeclarationStatements. void activateVariable(std::string const& _name); @@ -142,7 +142,6 @@ public: DeclarationRegistrationHelper( std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& _scopes, ASTNode& _astRoot, - bool _useC99Scoping, ErrorReporter& _errorReporter, ASTNode const* _currentScope = nullptr ); @@ -190,7 +189,6 @@ private: /// @returns the canonical name of the current scope. std::string currentCanonicalName() const; - bool m_useC99Scoping = false; std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& m_scopes; ASTNode const* m_currentScope = nullptr; VariableScope* m_currentFunction = nullptr; diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index f91eaf6e..dfcbf888 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -48,9 +48,7 @@ bool ReferencesResolver::visit(Block const& _block) if (!m_resolveInsideCode) return false; m_experimental050Mode = _block.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); - // C99-scoped variables - if (m_experimental050Mode) - m_resolver.setScope(&_block); + m_resolver.setScope(&_block); return true; } @@ -59,9 +57,7 @@ void ReferencesResolver::endVisit(Block const& _block) if (!m_resolveInsideCode) return; - // C99-scoped variables - if (m_experimental050Mode) - m_resolver.setScope(_block.scope()); + m_resolver.setScope(_block.scope()); } bool ReferencesResolver::visit(ForStatement const& _for) @@ -69,9 +65,7 @@ bool ReferencesResolver::visit(ForStatement const& _for) if (!m_resolveInsideCode) return false; m_experimental050Mode = _for.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); - // C99-scoped variables - if (m_experimental050Mode) - m_resolver.setScope(&_for); + m_resolver.setScope(&_for); return true; } @@ -79,18 +73,16 @@ void ReferencesResolver::endVisit(ForStatement const& _for) { if (!m_resolveInsideCode) return; - if (m_experimental050Mode) - m_resolver.setScope(_for.scope()); + m_resolver.setScope(_for.scope()); } void ReferencesResolver::endVisit(VariableDeclarationStatement const& _varDeclStatement) { if (!m_resolveInsideCode) return; - if (m_experimental050Mode) - for (auto const& var: _varDeclStatement.declarations()) - if (var) - m_resolver.activateVariable(var->name()); + for (auto const& var: _varDeclStatement.declarations()) + if (var) + m_resolver.activateVariable(var->name()); } bool ReferencesResolver::visit(Identifier const& _identifier) @@ -99,9 +91,14 @@ bool ReferencesResolver::visit(Identifier const& _identifier) if (declarations.empty()) { string suggestions = m_resolver.similarNameSuggestions(_identifier.name()); - string errorMessage = - "Undeclared identifier." + - (suggestions.empty()? "": " Did you mean " + std::move(suggestions) + "?"); + string errorMessage = "Undeclared identifier."; + if (!suggestions.empty()) + { + if ("\"" + _identifier.name() + "\"" == suggestions) + errorMessage += " " + std::move(suggestions) + " is not (or not yet) visible at this point."; + else + errorMessage += " Did you mean " + std::move(suggestions) + "?"; + } declarationError(_identifier.location(), errorMessage); } else if (declarations.size() == 1) @@ -327,7 +324,7 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable) else { // force location of external function parameters (not return) to calldata - if (varLoc != Location::Default) + if (varLoc != Location::CallData && varLoc != Location::Default) fatalTypeError(_variable.location(), "Location has to be calldata for external functions " "(remove the \"memory\" or \"storage\" keyword)." @@ -344,15 +341,22 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable) *dynamic_cast<Declaration const&>(*_variable.scope()).scope() ); // force locations of public or external function (return) parameters to memory - if (varLoc == Location::Storage && !contract.isLibrary()) + if (varLoc != Location::Memory && varLoc != Location::Default && !contract.isLibrary()) fatalTypeError(_variable.location(), "Location has to be memory for publicly visible functions " - "(remove the \"storage\" keyword)." + "(remove the \"storage\" or \"calldata\" keyword)." ); if (varLoc == Location::Default || !contract.isLibrary()) typeLoc = DataLocation::Memory; else + { + if (varLoc == Location::CallData) + fatalTypeError(_variable.location(), + "Location cannot be calldata for non-external functions " + "(remove the \"calldata\" keyword)." + ); typeLoc = varLoc == Location::Memory ? DataLocation::Memory : DataLocation::Storage; + } } else { @@ -361,7 +365,7 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable) if (varLoc != Location::Default && varLoc != Location::Memory) fatalTypeError( _variable.location(), - "Storage location has to be \"memory\" (or unspecified) for constants." + "Data location has to be \"memory\" (or unspecified) for constants." ); typeLoc = DataLocation::Memory; } @@ -373,30 +377,38 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable) { typeLoc = DataLocation::Storage; if (_variable.isLocalVariable()) - { - if (_variable.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050)) - typeError( - _variable.location(), - "Storage location must be specified as either \"memory\" or \"storage\"." - ); - else - m_errorReporter.warning( - _variable.location(), - "Variable is declared as a storage pointer. " - "Use an explicit \"storage\" keyword to silence this warning." - ); - } + typeError( + _variable.location(), + "Data location must be specified as either \"memory\" or \"storage\"." + ); } } else - typeLoc = varLoc == Location::Memory ? DataLocation::Memory : DataLocation::Storage; + { + switch (varLoc) + { + case Location::Memory: + typeLoc = DataLocation::Memory; + break; + case Location::Storage: + typeLoc = DataLocation::Storage; + break; + case Location::CallData: + fatalTypeError(_variable.location(), + "Variable cannot be declared as \"calldata\" (remove the \"calldata\" keyword)." + ); + break; + default: + solAssert(false, "Unknown data location"); + } + } isPointer = !_variable.isStateVariable(); } type = ref->copyForLocation(typeLoc, isPointer); } else if (varLoc != Location::Default && !ref) - typeError(_variable.location(), "Storage location can only be given for array or struct types."); + typeError(_variable.location(), "Data location can only be given for array or struct types."); _variable.annotation().type = type; } diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index 00a581d0..323282ca 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -58,8 +58,8 @@ bool StaticAnalyzer::visit(FunctionDefinition const& _function) _function.location(), "No visibility specified. Defaulting to \"" + Declaration::visibilityToString(_function.visibility()) + - "\". " + - (isInterface ? "In interfaces it defaults to external." : "") + "\"." + + (isInterface ? " In interfaces it defaults to external." : "") ); if (_function.isImplemented()) m_currentFunction = &_function; @@ -150,36 +150,18 @@ bool StaticAnalyzer::visit(ExpressionStatement const& _statement) bool StaticAnalyzer::visit(MemberAccess const& _memberAccess) { - bool const v050 = m_currentContract->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); - if (MagicType const* type = dynamic_cast<MagicType const*>(_memberAccess.expression().annotation().type.get())) { if (type->kind() == MagicType::Kind::Message && _memberAccess.memberName() == "gas") - { - if (v050) - m_errorReporter.typeError( - _memberAccess.location(), - "\"msg.gas\" has been deprecated in favor of \"gasleft()\"" - ); - else - m_errorReporter.warning( - _memberAccess.location(), - "\"msg.gas\" has been deprecated in favor of \"gasleft()\"" - ); - } - if (type->kind() == MagicType::Kind::Block && _memberAccess.memberName() == "blockhash") - { - if (v050) - m_errorReporter.typeError( - _memberAccess.location(), - "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\"" - ); - else - m_errorReporter.warning( - _memberAccess.location(), - "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\"" - ); - } + m_errorReporter.typeError( + _memberAccess.location(), + "\"msg.gas\" has been deprecated in favor of \"gasleft()\"" + ); + else if (type->kind() == MagicType::Kind::Block && _memberAccess.memberName() == "blockhash") + m_errorReporter.typeError( + _memberAccess.location(), + "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\"" + ); } if (m_nonPayablePublic && !m_library) @@ -193,18 +175,10 @@ bool StaticAnalyzer::visit(MemberAccess const& _memberAccess) if (_memberAccess.memberName() == "callcode") if (auto const* type = dynamic_cast<FunctionType const*>(_memberAccess.annotation().type.get())) if (type->kind() == FunctionType::Kind::BareCallCode) - { - if (v050) - m_errorReporter.typeError( - _memberAccess.location(), - "\"callcode\" has been deprecated in favour of \"delegatecall\"." - ); - else - m_errorReporter.warning( - _memberAccess.location(), - "\"callcode\" has been deprecated in favour of \"delegatecall\"." - ); - } + m_errorReporter.typeError( + _memberAccess.location(), + "\"callcode\" has been deprecated in favour of \"delegatecall\"." + ); if (m_constructor) { diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 396058f4..e33aafed 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -22,6 +22,7 @@ #include <libsolidity/analysis/SemVerHandler.h> #include <libsolidity/interface/ErrorReporter.h> #include <libsolidity/interface/Version.h> +#include <boost/algorithm/cxx11/all_of.hpp> using namespace std; using namespace dev; @@ -192,15 +193,9 @@ bool SyntaxChecker::visit(Throw const& _throwStatement) bool SyntaxChecker::visit(UnaryOperation const& _operation) { - bool const v050 = m_sourceUnit->annotation().experimentalFeatures.count(ExperimentalFeature::V050); - if (_operation.getOperator() == Token::Add) - { - if (v050) - m_errorReporter.syntaxError(_operation.location(), "Use of unary + is deprecated."); - else - m_errorReporter.warning(_operation.location(), "Use of unary + is deprecated."); - } + m_errorReporter.syntaxError(_operation.location(), "Use of unary + is disallowed."); + return true; } @@ -255,35 +250,27 @@ bool SyntaxChecker::visit(FunctionTypeName const& _node) for (auto const& decl: _node.returnParameterTypeList()->parameters()) if (!decl->name().empty()) - m_errorReporter.warning(decl->location(), "Naming function type return parameters is deprecated."); + m_errorReporter.syntaxError(decl->location(), "Return parameters in function types may not be named."); return true; } -bool SyntaxChecker::visit(VariableDeclaration const& _declaration) +bool SyntaxChecker::visit(VariableDeclarationStatement const& _statement) { - bool const v050 = m_sourceUnit->annotation().experimentalFeatures.count(ExperimentalFeature::V050); + // Report if none of the variable components in the tuple have a name (only possible via deprecated "var") + if (boost::algorithm::all_of_equal(_statement.declarations(), nullptr)) + m_errorReporter.syntaxError( + _statement.location(), + "The use of the \"var\" keyword is disallowed. The declaration part of the statement can be removed, since it is empty." + ); - if (!_declaration.typeName()) - { - if (v050) - m_errorReporter.syntaxError(_declaration.location(), "Use of the \"var\" keyword is deprecated."); - else - m_errorReporter.warning(_declaration.location(), "Use of the \"var\" keyword is deprecated."); - } return true; } bool SyntaxChecker::visit(StructDefinition const& _struct) { - bool const v050 = m_sourceUnit->annotation().experimentalFeatures.count(ExperimentalFeature::V050); - if (_struct.members().empty()) - { - if (v050) - m_errorReporter.syntaxError(_struct.location(), "Defining empty structs is disallowed."); - else - m_errorReporter.warning(_struct.location(), "Defining empty structs is deprecated."); - } + m_errorReporter.syntaxError(_struct.location(), "Defining empty structs is disallowed."); + return true; } diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h index 1579df57..5460e3be 100644 --- a/libsolidity/analysis/SyntaxChecker.h +++ b/libsolidity/analysis/SyntaxChecker.h @@ -69,7 +69,7 @@ private: virtual bool visit(FunctionDefinition const& _function) override; virtual bool visit(FunctionTypeName const& _node) override; - virtual bool visit(VariableDeclaration const& _declaration) override; + virtual bool visit(VariableDeclarationStatement const& _statement) override; virtual bool visit(StructDefinition const& _struct) override; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 30302908..cc373e03 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -23,12 +23,14 @@ #include <libsolidity/analysis/TypeChecker.h> #include <memory> #include <boost/algorithm/string/predicate.hpp> +#include <boost/algorithm/string/join.hpp> #include <boost/range/adaptor/reversed.hpp> #include <libsolidity/ast/AST.h> #include <libsolidity/inlineasm/AsmAnalysis.h> #include <libsolidity/inlineasm/AsmAnalysisInfo.h> #include <libsolidity/inlineasm/AsmData.h> #include <libsolidity/interface/ErrorReporter.h> +#include <libdevcore/Algorithms.h> using namespace std; using namespace dev; @@ -41,15 +43,13 @@ bool typeSupportedByOldABIEncoder(Type const& _type) { if (_type.dataStoredIn(DataLocation::Storage)) return true; - else if (_type.category() == Type::Category::Struct) + if (_type.category() == Type::Category::Struct) return false; - else if (_type.category() == Type::Category::Array) + if (_type.category() == Type::Category::Array) { auto const& arrayType = dynamic_cast<ArrayType const&>(_type); auto base = arrayType.baseType(); - if (!typeSupportedByOldABIEncoder(*base)) - return false; - else if (base->category() == Type::Category::Array && base->isDynamicallySized()) + if (!typeSupportedByOldABIEncoder(*base) || (base->category() == Type::Category::Array && base->isDynamicallySized())) return false; } return true; @@ -125,10 +125,7 @@ bool TypeChecker::visit(ContractDefinition const& _contract) m_errorReporter.typeError(function->parameterList().location(), "Fallback function cannot take parameters."); if (!function->returnParameters().empty()) m_errorReporter.typeError(function->returnParameterList()->location(), "Fallback function cannot return values."); - if ( - _contract.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050) && - function->visibility() != FunctionDefinition::Visibility::External - ) + if (function->visibility() != FunctionDefinition::Visibility::External) m_errorReporter.typeError(function->location(), "Fallback function must be defined as \"external\"."); } @@ -337,8 +334,6 @@ void TypeChecker::annotateBaseConstructorArguments( ASTNode const* _argumentNode ) { - bool const v050 = _currentContract.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); - solAssert(_baseConstructor, ""); solAssert(_argumentNode, ""); @@ -351,7 +346,7 @@ void TypeChecker::annotateBaseConstructorArguments( SourceLocation const* mainLocation = nullptr; SecondarySourceLocation ssl; - + if ( _currentContract.location().contains(previousNode->location()) || _currentContract.location().contains(_argumentNode->location()) @@ -367,18 +362,11 @@ void TypeChecker::annotateBaseConstructorArguments( ssl.append("Second constructor call is here: ", previousNode->location()); } - if (v050) - m_errorReporter.declarationError( - *mainLocation, - ssl, - "Base constructor arguments given twice." - ); - else - m_errorReporter.warning( - *mainLocation, - "Base constructor arguments given twice.", - ssl - ); + m_errorReporter.declarationError( + *mainLocation, + ssl, + "Base constructor arguments given twice." + ); } } @@ -462,7 +450,7 @@ void TypeChecker::overrideError(FunctionDefinition const& function, FunctionDefi { m_errorReporter.typeError( function.location(), - SecondarySourceLocation().append("Overriden function is here:", super.location()), + SecondarySourceLocation().append("Overridden function is here:", super.location()), message ); } @@ -562,33 +550,18 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance) if (arguments) { - bool v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); - if (parameterTypes.size() != arguments->size()) { - if (arguments->size() == 0 && !v050) - m_errorReporter.warning( - _inheritance.location(), - "Wrong argument count for constructor call: " + - toString(arguments->size()) + - " arguments given but expected " + - toString(parameterTypes.size()) + - "." - ); - else - { - m_errorReporter.typeError( - _inheritance.location(), - "Wrong argument count for constructor call: " + - toString(arguments->size()) + - " arguments given but expected " + - toString(parameterTypes.size()) + - "." - ); - return; - } + m_errorReporter.typeError( + _inheritance.location(), + "Wrong argument count for constructor call: " + + toString(arguments->size()) + + " arguments given but expected " + + toString(parameterTypes.size()) + + ". Remove parentheses if you do not want to provide arguments here." + ); } - for (size_t i = 0; i < arguments->size(); ++i) + for (size_t i = 0; i < std::min(arguments->size(), parameterTypes.size()); ++i) if (!type(*(*arguments)[i])->isImplicitlyConvertibleTo(*parameterTypes[i])) m_errorReporter.typeError( (*arguments)[i]->location(), @@ -621,22 +594,24 @@ bool TypeChecker::visit(StructDefinition const& _struct) m_errorReporter.typeError(member->location(), "Type cannot be used in struct."); // Check recursion, fatal error if detected. - using StructPointer = StructDefinition const*; - using StructPointersSet = set<StructPointer>; - function<void(StructPointer,StructPointersSet const&)> check = [&](StructPointer _struct, StructPointersSet const& _parents) - { - if (_parents.count(_struct)) - m_errorReporter.fatalTypeError(_struct->location(), "Recursive struct definition."); - StructPointersSet parents = _parents; - parents.insert(_struct); - for (ASTPointer<VariableDeclaration> const& member: _struct->members()) - if (type(*member)->category() == Type::Category::Struct) + auto visitor = [&](StructDefinition const& _struct, CycleDetector<StructDefinition>& _cycleDetector) + { + for (ASTPointer<VariableDeclaration> const& member: _struct.members()) + { + Type const* memberType = type(*member).get(); + while (auto arrayType = dynamic_cast<ArrayType const*>(memberType)) { - auto const& typeName = dynamic_cast<UserDefinedTypeName const&>(*member->typeName()); - check(&dynamic_cast<StructDefinition const&>(*typeName.annotation().referencedDeclaration), parents); + if (arrayType->isDynamicallySized()) + break; + memberType = arrayType->baseType().get(); } + if (auto structType = dynamic_cast<StructType const*>(memberType)) + if (_cycleDetector.run(structType->structDefinition())) + return; + } }; - check(&_struct, StructPointersSet{}); + if (CycleDetector<StructDefinition>(visitor).run(_struct) != nullptr) + m_errorReporter.fatalTypeError(_struct.location(), "Recursive struct definition."); ASTNode::listAccept(_struct.members(), *this); @@ -760,19 +735,10 @@ bool TypeChecker::visit(VariableDeclaration const& _variable) if (!_variable.value()) m_errorReporter.typeError(_variable.location(), "Uninitialized \"constant\" variable."); else if (!_variable.value()->annotation().isPure) - { - if (_variable.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050)) - m_errorReporter.typeError( - _variable.value()->location(), - "Initial value for constant variable has to be compile-time constant." - ); - else - m_errorReporter.warning( - _variable.value()->location(), - "Initial value for constant variable has to be compile-time constant. " - "This will fail to compile with the next breaking version change." - ); - } + m_errorReporter.typeError( + _variable.value()->location(), + "Initial value for constant variable has to be compile-time constant." + ); } if (!_variable.isStateVariable()) { @@ -931,7 +897,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) } else if (var->type()->dataStoredIn(DataLocation::Storage)) { - m_errorReporter.typeError(_identifier.location, "You have to use the _slot or _offset prefix to access storage reference variables."); + m_errorReporter.typeError(_identifier.location, "You have to use the _slot or _offset suffix to access storage reference variables."); return size_t(-1); } else if (var->type()->sizeOnStack() != 1) @@ -1074,9 +1040,49 @@ void TypeChecker::endVisit(EmitStatement const& _emit) m_insideEmitStatement = false; } +namespace +{ +/** + * @returns a suggested left-hand-side of a multi-variable declaration contairing + * the variable declarations given in @a _decls. + */ +string createTupleDecl(vector<ASTPointer<VariableDeclaration>> const& _decls) +{ + vector<string> components; + for (ASTPointer<VariableDeclaration> const& decl: _decls) + if (decl) + components.emplace_back(decl->annotation().type->toString(false) + " " + decl->name()); + else + components.emplace_back(); + + if (_decls.size() == 1) + return components.front(); + else + return "(" + boost::algorithm::join(components, ", ") + ")"; +} + +bool typeCanBeExpressed(vector<ASTPointer<VariableDeclaration>> const& decls) +{ + for (ASTPointer<VariableDeclaration> const& decl: decls) + { + // skip empty tuples (they can be expressed of course) + if (!decl) + continue; + + if (auto functionType = dynamic_cast<FunctionType const*>(decl->annotation().type.get())) + if ( + functionType->kind() != FunctionType::Kind::Internal && + functionType->kind() != FunctionType::Kind::External + ) + return false; + } + + return true; +} +} + bool TypeChecker::visit(VariableDeclarationStatement const& _statement) { - bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); if (!_statement.initialValue()) { // No initial value is only permitted for single variables with specified type. @@ -1093,10 +1099,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) if (varDecl.referenceLocation() == VariableDeclaration::Location::Default) errorText += " Did you mean '<type> memory " + varDecl.name() + "'?"; solAssert(m_scope, ""); - if (v050) - m_errorReporter.declarationError(varDecl.location(), errorText); - else - m_errorReporter.warning(varDecl.location(), errorText); + m_errorReporter.declarationError(varDecl.location(), errorText); } } else if (dynamic_cast<MappingType const*>(type(varDecl).get())) @@ -1118,85 +1121,34 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) else valueTypes = TypePointers{type(*_statement.initialValue())}; - // Determine which component is assigned to which variable. - // If numbers do not match, fill up if variables begin or end empty (not both). - vector<VariableDeclaration const*>& assignments = _statement.annotation().assignments; - assignments.resize(valueTypes.size(), nullptr); vector<ASTPointer<VariableDeclaration>> const& variables = _statement.declarations(); if (variables.empty()) - { - if (!valueTypes.empty()) - m_errorReporter.fatalTypeError( - _statement.location(), - "Too many components (" + - toString(valueTypes.size()) + - ") in value for variable assignment (0) needed" - ); - } + // We already have an error for this in the SyntaxChecker. + solAssert(m_errorReporter.hasErrors(), ""); else if (valueTypes.size() != variables.size()) - { - if (v050) - m_errorReporter.fatalTypeError( - _statement.location(), - "Different number of components on the left hand side (" + - toString(variables.size()) + - ") than on the right hand side (" + - toString(valueTypes.size()) + - ")." - ); - else if (!variables.front() && !variables.back()) - m_errorReporter.fatalTypeError( - _statement.location(), - "Wildcard both at beginning and end of variable declaration list is only allowed " - "if the number of components is equal." - ); - else - m_errorReporter.warning( - _statement.location(), - "Different number of components on the left hand side (" + - toString(variables.size()) + - ") than on the right hand side (" + - toString(valueTypes.size()) + - ")." - ); - } - size_t minNumValues = variables.size(); - if (!variables.empty() && (!variables.back() || !variables.front())) - --minNumValues; - if (valueTypes.size() < minNumValues) - m_errorReporter.fatalTypeError( - _statement.location(), - "Not enough components (" + - toString(valueTypes.size()) + - ") in value to assign all variables (" + - toString(minNumValues) + ")." - ); - if (valueTypes.size() > variables.size() && variables.front() && variables.back()) - m_errorReporter.fatalTypeError( + m_errorReporter.typeError( _statement.location(), - "Too many components (" + + "Different number of components on the left hand side (" + + toString(variables.size()) + + ") than on the right hand side (" + toString(valueTypes.size()) + - ") in value for variable assignment (" + - toString(minNumValues) + - " needed)." + ")." ); - bool fillRight = !variables.empty() && (!variables.back() || variables.front()); - for (size_t i = 0; i < min(variables.size(), valueTypes.size()); ++i) - if (fillRight) - assignments[i] = variables[i].get(); - else - assignments[assignments.size() - i - 1] = variables[variables.size() - i - 1].get(); - for (size_t i = 0; i < assignments.size(); ++i) + bool autoTypeDeductionNeeded = false; + + for (size_t i = 0; i < min(variables.size(), valueTypes.size()); ++i) { - if (!assignments[i]) + if (!variables[i]) continue; - VariableDeclaration const& var = *assignments[i]; + VariableDeclaration const& var = *variables[i]; solAssert(!var.value(), "Value has to be tied to statement."); TypePointer const& valueComponentType = valueTypes[i]; solAssert(!!valueComponentType, ""); if (!var.annotation().type) { + autoTypeDeductionNeeded = true; + // Infer type from value. solAssert(!var.typeName(), ""); var.annotation().type = valueComponentType->mobileType(); @@ -1240,14 +1192,6 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) } else solAssert(dynamic_cast<FixedPointType const*>(var.annotation().type.get()), "Unknown type."); - - m_errorReporter.warning( - _statement.location(), - "The type of this variable was inferred as " + - typeName + - extension + - ". This is probably not desired. Use an explicit type to silence this warning." - ); } var.accept(*this); @@ -1284,6 +1228,23 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) } } } + + if (autoTypeDeductionNeeded) + { + if (!typeCanBeExpressed(variables)) + m_errorReporter.syntaxError( + _statement.location(), + "Use of the \"var\" keyword is disallowed. " + "Type cannot be expressed in syntax." + ); + else + m_errorReporter.syntaxError( + _statement.location(), + "Use of the \"var\" keyword is disallowed. " + "Use explicit declaration `" + createTupleDecl(variables) + " = ...´ instead." + ); + } + return false; } @@ -1357,7 +1318,6 @@ bool TypeChecker::visit(Conditional const& _conditional) bool TypeChecker::visit(Assignment const& _assignment) { - bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); requireLValue(_assignment.leftHandSide()); TypePointer t = type(_assignment.leftHandSide()); _assignment.annotation().type = t; @@ -1374,25 +1334,8 @@ bool TypeChecker::visit(Assignment const& _assignment) expectType(_assignment.rightHandSide(), *tupleType); // expectType does not cause fatal errors, so we have to check again here. - if (TupleType const* rhsType = dynamic_cast<TupleType const*>(type(_assignment.rightHandSide()).get())) - { + if (dynamic_cast<TupleType const*>(type(_assignment.rightHandSide()).get())) checkDoubleStorageAssignment(_assignment); - // @todo For 0.5.0, this code shoud move to TupleType::isImplicitlyConvertibleTo, - // but we cannot do it right now. - if (rhsType->components().size() != tupleType->components().size()) - { - string message = - "Different number of components on the left hand side (" + - toString(tupleType->components().size()) + - ") than on the right hand side (" + - toString(rhsType->components().size()) + - ")."; - if (v050) - m_errorReporter.typeError(_assignment.location(), message); - else - m_errorReporter.warning(_assignment.location(), message); - } - } } else if (t->category() == Type::Category::Mapping) { @@ -1449,14 +1392,12 @@ bool TypeChecker::visit(TupleExpression const& _tuple) } else { - bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); bool isPure = true; TypePointer inlineArrayType; for (size_t i = 0; i < components.size(); ++i) { - // Outside of an lvalue-context, the only situation where a component can be empty is (x,). - if (!components[i] && !(i == 1 && components.size() == 2)) + if (!components[i]) m_errorReporter.fatalTypeError(_tuple.location(), "Tuple component cannot be empty."); else if (components[i]) { @@ -1468,10 +1409,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple) { if (_tuple.isInlineArray()) m_errorReporter.fatalTypeError(components[i]->location(), "Array component cannot be empty."); - if (v050) - m_errorReporter.fatalTypeError(components[i]->location(), "Tuple component cannot be empty."); - else - m_errorReporter.warning(components[i]->location(), "Tuple component cannot be empty."); + m_errorReporter.typeError(components[i]->location(), "Tuple component cannot be empty."); } // Note: code generation will visit each of the expression even if they are not assigned from. @@ -1509,11 +1447,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple) if (components.size() == 1) _tuple.annotation().type = type(*components[0]); else - { - if (components.size() == 2 && !components[1]) - types.pop_back(); _tuple.annotation().type = make_shared<TupleType>(types); - } } } @@ -1704,30 +1638,15 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) else _functionCall.annotation().type = make_shared<TupleType>(returnTypes); - bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); - if (auto functionName = dynamic_cast<Identifier const*>(&_functionCall.expression())) { - string msg; if (functionName->name() == "sha3" && functionType->kind() == FunctionType::Kind::SHA3) - msg = "\"sha3\" has been deprecated in favour of \"keccak256\""; + m_errorReporter.typeError(_functionCall.location(), "\"sha3\" has been deprecated in favour of \"keccak256\""); else if (functionName->name() == "suicide" && functionType->kind() == FunctionType::Kind::Selfdestruct) - msg = "\"suicide\" has been deprecated in favour of \"selfdestruct\""; - if (!msg.empty()) - { - if (v050) - m_errorReporter.typeError(_functionCall.location(), msg); - else - m_errorReporter.warning(_functionCall.location(), msg); - } + m_errorReporter.typeError(_functionCall.location(), "\"suicide\" has been deprecated in favour of \"selfdestruct\""); } if (!m_insideEmitStatement && functionType->kind() == FunctionType::Kind::Event) - { - if (m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050)) - m_errorReporter.typeError(_functionCall.location(), "Event invocations have to be prefixed by \"emit\"."); - else - m_errorReporter.warning(_functionCall.location(), "Invoking events without \"emit\" prefix is deprecated."); - } + m_errorReporter.typeError(_functionCall.location(), "Event invocations have to be prefixed by \"emit\"."); TypePointers parameterTypes = functionType->parameterTypes(); @@ -1738,57 +1657,20 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) auto const& argType = type(*arguments[i]); if (auto literal = dynamic_cast<RationalNumberType const*>(argType.get())) { - /* If no mobile type is available an error will be raised elsewhere. */ if (literal->mobileType()) + m_errorReporter.typeError( + arguments[i]->location(), + "Cannot perform packed encoding for a literal. Please convert it to an explicit type first." + ); + else { - if (v050) - m_errorReporter.typeError( - arguments[i]->location(), - "Cannot perform packed encoding for a literal. Please convert it to an explicit type first." - ); - else - m_errorReporter.warning( - arguments[i]->location(), - "The type of \"" + - argType->toString() + - "\" was inferred as " + - literal->mobileType()->toString() + - ". This is probably not desired. Use an explicit type to silence this warning." - ); + /* If no mobile type is available an error will be raised elsewhere. */ + solAssert(m_errorReporter.hasErrors(), ""); } } } } - if (functionType->takesSinglePackedBytesParameter()) - { - if ( - (arguments.size() > 1) || - (arguments.size() == 1 && !type(*arguments.front())->isImplicitlyConvertibleTo(ArrayType(DataLocation::Memory))) - ) - { - string msg = - "This function only accepts a single \"bytes\" argument. Please use " - "\"abi.encodePacked(...)\" or a similar function to encode the data."; - if (v050) - m_errorReporter.typeError(_functionCall.location(), msg); - else - m_errorReporter.warning(_functionCall.location(), msg); - } - - if (arguments.size() == 1 && !type(*arguments.front())->isImplicitlyConvertibleTo(ArrayType(DataLocation::Memory))) - { - string msg = - "The provided argument of type " + - type(*arguments.front())->toString() + - " is not implicitly convertible to expected type bytes memory."; - if (v050) - m_errorReporter.typeError(_functionCall.location(), msg); - else - m_errorReporter.warning(_functionCall.location(), msg); - } - } - if (functionType->takesArbitraryParameters() && arguments.size() < parameterTypes.size()) { solAssert(_functionCall.annotation().kind == FunctionCallKind::FunctionCall, ""); @@ -1820,6 +1702,26 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) for (auto const& member: membersRemovedForStructConstructor) msg += " " + member; } + else if ( + functionType->kind() == FunctionType::Kind::BareCall || + functionType->kind() == FunctionType::Kind::BareCallCode || + functionType->kind() == FunctionType::Kind::BareDelegateCall + ) + { + if (arguments.empty()) + msg += " This function requires a single bytes argument. Use \"\" as argument to provide empty calldata."; + else + msg += " This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it."; + } + else if ( + functionType->kind() == FunctionType::Kind::SHA3 || + functionType->kind() == FunctionType::Kind::SHA256 || + functionType->kind() == FunctionType::Kind::RIPEMD160 + ) + msg += + " This function requires a single bytes argument." + " Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour" + " or abi.encode(...) to use ABI encoding."; m_errorReporter.typeError(_functionCall.location(), msg); } else if (isPositionalCall) @@ -1856,15 +1758,31 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) } } else if (!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i])) - m_errorReporter.typeError( - arguments[i]->location(), + { + string msg = "Invalid type for argument in function call. " "Invalid implicit conversion from " + type(*arguments[i])->toString() + " to " + parameterTypes[i]->toString() + - " requested." - ); + " requested."; + if ( + functionType->kind() == FunctionType::Kind::BareCall || + functionType->kind() == FunctionType::Kind::BareCallCode || + functionType->kind() == FunctionType::Kind::BareDelegateCall + ) + msg += " This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it."; + else if ( + functionType->kind() == FunctionType::Kind::SHA3 || + functionType->kind() == FunctionType::Kind::SHA256 || + functionType->kind() == FunctionType::Kind::RIPEMD160 + ) + msg += + " This function requires a single bytes argument." + " Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour" + " or abi.encode(...) to use ABI encoding."; + m_errorReporter.typeError(arguments[i]->location(), msg); + } } } else @@ -1874,7 +1792,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) if (functionType->takesArbitraryParameters()) m_errorReporter.typeError( _functionCall.location(), - "Named arguments cannnot be used for functions that take arbitrary parameters." + "Named arguments cannot be used for functions that take arbitrary parameters." ); else if (parameterNames.size() > argumentNames.size()) m_errorReporter.typeError(_functionCall.location(), "Some argument names are missing."); @@ -1918,7 +1836,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) if (!found) m_errorReporter.typeError( _functionCall.location(), - "Named argument does not match function declaration." + "Named argument \"" + *argumentNames[i] + "\" does not match function declaration." ); } } @@ -2293,51 +2211,46 @@ void TypeChecker::endVisit(ElementaryTypeNameExpression const& _expr) void TypeChecker::endVisit(Literal const& _literal) { - bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); - if (_literal.looksLikeAddress()) { - if (_literal.passesAddressChecksum()) - _literal.annotation().type = make_shared<IntegerType>(160, IntegerType::Modifier::Address); - else - m_errorReporter.warning( + // Assign type here if it even looks like an address. This prevents double errors for invalid addresses + _literal.annotation().type = make_shared<IntegerType>(160, IntegerType::Modifier::Address); + + string msg; + if (_literal.value().length() != 42) // "0x" + 40 hex digits + // looksLikeAddress enforces that it is a hex literal starting with "0x" + msg = + "This looks like an address but is not exactly 40 hex digits. It is " + + to_string(_literal.value().length() - 2) + + " hex digits."; + else if (!_literal.passesAddressChecksum()) + { + msg = "This looks like an address but has an invalid checksum."; + if (!_literal.getChecksummedAddress().empty()) + msg += " Correct checksummed address: \"" + _literal.getChecksummedAddress() + "\"."; + } + + if (!msg.empty()) + m_errorReporter.syntaxError( _literal.location(), - "This looks like an address but has an invalid checksum. " - "If this is not used as an address, please prepend '00'. " + - (!_literal.getChecksummedAddress().empty() ? "Correct checksummed address: '" + _literal.getChecksummedAddress() + "'. " : "") + + msg + + " If this is not used as an address, please prepend '00'. " + "For more information please see https://solidity.readthedocs.io/en/develop/types.html#address-literals" ); } if (_literal.isHexNumber() && _literal.subDenomination() != Literal::SubDenomination::None) - { - if (v050) - m_errorReporter.fatalTypeError( - _literal.location(), - "Hexadecimal numbers cannot be used with unit denominations. " - "You can use an expression of the form \"0x1234 * 1 day\" instead." - ); - else - m_errorReporter.warning( - _literal.location(), - "Hexadecimal numbers with unit denominations are deprecated. " - "You can use an expression of the form \"0x1234 * 1 day\" instead." - ); - } + m_errorReporter.fatalTypeError( + _literal.location(), + "Hexadecimal numbers cannot be used with unit denominations. " + "You can use an expression of the form \"0x1234 * 1 day\" instead." + ); if (_literal.subDenomination() == Literal::SubDenomination::Year) - { - if (v050) - m_errorReporter.typeError( - _literal.location(), - "Using \"years\" as a unit denomination is deprecated." - ); - else - m_errorReporter.warning( - _literal.location(), - "Using \"years\" as a unit denomination is deprecated." - ); - } + m_errorReporter.typeError( + _literal.location(), + "Using \"years\" as a unit denomination is deprecated." + ); if (!_literal.annotation().type) _literal.annotation().type = Type::forLiteral(_literal); diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index 2245abd6..8dc6b376 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -68,7 +68,7 @@ private: void checkContractDuplicateFunctions(ContractDefinition const& _contract); void checkContractDuplicateEvents(ContractDefinition const& _contract); void checkContractIllegalOverrides(ContractDefinition const& _contract); - /// Reports a type error with an appropiate message if overriden function signature differs. + /// Reports a type error with an appropriate message if overridden function signature differs. /// Also stores the direct super function in the AST annotations. void checkFunctionOverride(FunctionDefinition const& function, FunctionDefinition const& super); void overrideError(FunctionDefinition const& function, FunctionDefinition const& super, std::string message); diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index d9843012..18c642c3 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -116,31 +116,22 @@ private: bool ViewPureChecker::check() { - // The bool means "enforce view with errors". - map<ContractDefinition const*, bool> contracts; + vector<ContractDefinition const*> contracts; for (auto const& node: m_ast) { SourceUnit const* source = dynamic_cast<SourceUnit const*>(node.get()); solAssert(source, ""); - bool enforceView = source->annotation().experimentalFeatures.count(ExperimentalFeature::V050); - for (ContractDefinition const* c: source->filteredNodes<ContractDefinition>(source->nodes())) - contracts[c] = enforceView; + contracts += source->filteredNodes<ContractDefinition>(source->nodes()); } // Check modifiers first to infer their state mutability. for (auto const& contract: contracts) - { - m_enforceViewWithError = contract.second; - for (ModifierDefinition const* mod: contract.first->functionModifiers()) + for (ModifierDefinition const* mod: contract->functionModifiers()) mod->accept(*this); - } for (auto const& contract: contracts) - { - m_enforceViewWithError = contract.second; - contract.first->accept(*this); - } + contract->accept(*this); return !m_errors; } @@ -232,17 +223,20 @@ void ViewPureChecker::reportMutability(StateMutability _mutability, SourceLocati { if (m_currentFunction && m_currentFunction->stateMutability() < _mutability) { - string text; if (_mutability == StateMutability::View) - text = + m_errorReporter.typeError( + _location, "Function declared as pure, but this expression (potentially) reads from the " - "environment or state and thus requires \"view\"."; + "environment or state and thus requires \"view\"." + ); else if (_mutability == StateMutability::NonPayable) - text = + m_errorReporter.typeError( + _location, "Function declared as " + stateMutabilityToString(m_currentFunction->stateMutability()) + ", but this expression (potentially) modifies the state and thus " - "requires non-payable (the default) or payable."; + "requires non-payable (the default) or payable." + ); else solAssert(false, ""); @@ -251,13 +245,7 @@ void ViewPureChecker::reportMutability(StateMutability _mutability, SourceLocati m_currentFunction->stateMutability() == StateMutability::Pure, "" ); - if (!m_enforceViewWithError && m_currentFunction->stateMutability() == StateMutability::View) - m_errorReporter.warning(_location, text); - else - { - m_errors = true; - m_errorReporter.typeError(_location, text); - } + m_errors = true; } if (_mutability > m_currentBestMutability) m_currentBestMutability = _mutability; diff --git a/libsolidity/analysis/ViewPureChecker.h b/libsolidity/analysis/ViewPureChecker.h index 0b882cd8..3db52e7e 100644 --- a/libsolidity/analysis/ViewPureChecker.h +++ b/libsolidity/analysis/ViewPureChecker.h @@ -71,7 +71,6 @@ private: ErrorReporter& m_errorReporter; bool m_errors = false; - bool m_enforceViewWithError = false; StateMutability m_currentBestMutability = StateMutability::Payable; FunctionDefinition const* m_currentFunction = nullptr; std::map<ModifierDefinition const*, StateMutability> m_inferredMutability; diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index 16c9b2d2..7719d080 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -535,13 +535,6 @@ ReturnAnnotation& Return::annotation() const return dynamic_cast<ReturnAnnotation&>(*m_annotation); } -VariableDeclarationStatementAnnotation& VariableDeclarationStatement::annotation() const -{ - if (!m_annotation) - m_annotation = new VariableDeclarationStatementAnnotation(); - return dynamic_cast<VariableDeclarationStatementAnnotation&>(*m_annotation); -} - ExpressionAnnotation& Expression::annotation() const { if (!m_annotation) diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index fa0d6921..acd90ad8 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -656,7 +656,7 @@ private: class VariableDeclaration: public Declaration { public: - enum Location { Default, Storage, Memory }; + enum Location { Default, Storage, Memory, CallData }; VariableDeclaration( SourceLocation const& _sourceLocation, @@ -1169,11 +1169,11 @@ public: Statement const& body() const { return *m_body; } private: - /// For statement's initialization expresion. for(XXX; ; ). Can be empty + /// For statement's initialization expression. for(XXX; ; ). Can be empty ASTPointer<Statement> m_initExpression; - /// For statement's condition expresion. for(; XXX ; ). Can be empty + /// For statement's condition expression. for(; XXX ; ). Can be empty ASTPointer<Expression> m_condExpression; - /// For statement's loop expresion. for(;;XXX). Can be empty + /// For statement's loop expression. for(;;XXX). Can be empty ASTPointer<ExpressionStatement> m_loopExpression; /// The body of the loop ASTPointer<Statement> m_body; @@ -1250,13 +1250,12 @@ private: }; /** - * Definition of a variable as a statement inside a function. It requires a type name (which can - * also be "var") but the actual assignment can be missing. - * Examples: var a = 2; uint256 a; - * As a second form, multiple variables can be declared, cannot have a type and must be assigned - * right away. If the first or last component is unnamed, it can "consume" an arbitrary number - * of components. - * Examples: var (a, b) = f(); var (a,,,c) = g(); var (a,) = d(); + * Definition of one or more variables as a statement inside a function. + * If multiple variables are declared, a value has to be assigned directly. + * If only a single variable is declared, the value can be missing. + * Examples: + * uint[] memory a; uint a = 2; + * (uint a, bytes32 b, ) = f(); (, uint a, , StructName storage x) = g(); */ class VariableDeclarationStatement: public Statement { @@ -1271,13 +1270,14 @@ public: virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - VariableDeclarationStatementAnnotation& annotation() const override; - std::vector<ASTPointer<VariableDeclaration>> const& declarations() const { return m_variables; } Expression const* initialValue() const { return m_initialValue.get(); } private: /// List of variables, some of which can be empty pointers (unnamed components). + /// Note that the ``m_value`` member of these is unused. Instead, ``m_initialValue`` + /// below is used, because the initial value can be a single expression assigned + /// to all variables. std::vector<ASTPointer<VariableDeclaration>> m_variables; /// The assigned expression / initial value. ASTPointer<Expression> m_initialValue; diff --git a/libsolidity/ast/ASTAnnotations.h b/libsolidity/ast/ASTAnnotations.h index 5cbe42bd..e0b3f492 100644 --- a/libsolidity/ast/ASTAnnotations.h +++ b/libsolidity/ast/ASTAnnotations.h @@ -164,13 +164,6 @@ struct UserDefinedTypeNameAnnotation: TypeNameAnnotation ContractDefinition const* contractScope = nullptr; }; -struct VariableDeclarationStatementAnnotation: StatementAnnotation -{ - /// Information about which component of the value is assigned to which variable. - /// The pointer can be null to signify that the component is discarded. - std::vector<VariableDeclaration const*> assignments; -}; - struct ExpressionAnnotation: ASTAnnotation { /// Inferred type of the expression. diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index b8e00b60..a26828a6 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -555,8 +555,8 @@ bool ASTJsonConverter::visit(EmitStatement const& _node) bool ASTJsonConverter::visit(VariableDeclarationStatement const& _node) { Json::Value varDecs(Json::arrayValue); - for (auto const& v: _node.annotation().assignments) - appendMove(varDecs, idOrNull(v)); + for (auto const& v: _node.declarations()) + appendMove(varDecs, idOrNull(v.get())); setJsonNode(_node, "VariableDeclarationStatement", { make_pair("assignments", std::move(varDecs)), make_pair("declarations", toJson(_node.declarations())), @@ -751,6 +751,8 @@ string ASTJsonConverter::location(VariableDeclaration::Location _location) return "storage"; case VariableDeclaration::Location::Memory: return "memory"; + case VariableDeclaration::Location::CallData: + return "calldata"; default: solAssert(false, "Unknown declaration location."); } diff --git a/libsolidity/ast/ExperimentalFeatures.h b/libsolidity/ast/ExperimentalFeatures.h index 30ea7ec5..c66a3659 100644 --- a/libsolidity/ast/ExperimentalFeatures.h +++ b/libsolidity/ast/ExperimentalFeatures.h @@ -29,7 +29,7 @@ namespace solidity enum class ExperimentalFeature { - ABIEncoderV2, // new ABI encoder that makes use of JULIA + ABIEncoderV2, // new ABI encoder that makes use of Yul SMTChecker, V050, // v0.5.0 breaking changes Test, diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 59668e1d..dd0736e9 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -599,9 +599,9 @@ MemberList::MemberMap IntegerType::nativeMembers(ContractDefinition const*) cons if (isAddress()) return { {"balance", make_shared<IntegerType>(256)}, - {"call", make_shared<FunctionType>(strings(), strings{"bool"}, FunctionType::Kind::BareCall, true, StateMutability::Payable)}, - {"callcode", make_shared<FunctionType>(strings(), strings{"bool"}, FunctionType::Kind::BareCallCode, true, StateMutability::Payable)}, - {"delegatecall", make_shared<FunctionType>(strings(), strings{"bool"}, FunctionType::Kind::BareDelegateCall, true)}, + {"call", make_shared<FunctionType>(strings{"bytes memory"}, strings{"bool"}, FunctionType::Kind::BareCall, false, StateMutability::Payable)}, + {"callcode", make_shared<FunctionType>(strings{"bytes memory"}, strings{"bool"}, FunctionType::Kind::BareCallCode, false, StateMutability::Payable)}, + {"delegatecall", make_shared<FunctionType>(strings{"bytes memory"}, strings{"bool"}, FunctionType::Kind::BareDelegateCall, false)}, {"send", make_shared<FunctionType>(strings{"uint"}, strings{"bool"}, FunctionType::Kind::Send)}, {"transfer", make_shared<FunctionType>(strings{"uint"}, strings(), FunctionType::Kind::Transfer)} }; @@ -678,7 +678,7 @@ string FixedPointType::toString(bool) const bigint FixedPointType::maxIntegerValue() const { bigint maxValue = (bigint(1) << (m_totalBits - (isSigned() ? 1 : 0))) - 1; - return maxValue / pow(bigint(10), m_fractionalDigits); + return maxValue / boost::multiprecision::pow(bigint(10), m_fractionalDigits); } bigint FixedPointType::minIntegerValue() const @@ -686,7 +686,7 @@ bigint FixedPointType::minIntegerValue() const if (isSigned()) { bigint minValue = -(bigint(1) << (m_totalBits - (isSigned() ? 1 : 0))); - return minValue / pow(bigint(10), m_fractionalDigits); + return minValue / boost::multiprecision::pow(bigint(10), m_fractionalDigits); } else return bigint(0); @@ -771,20 +771,23 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal } else if (expPoint != _literal.value().end()) { - // Parse base and exponent. Checks numeric limit. - bigint exp = bigint(string(expPoint + 1, _literal.value().end())); + // Parse mantissa and exponent. Checks numeric limit. + tuple<bool, rational> mantissa = parseRational(string(_literal.value().begin(), expPoint)); - if (exp > numeric_limits<int32_t>::max() || exp < numeric_limits<int32_t>::min()) + if (!get<0>(mantissa)) return make_tuple(false, rational(0)); + value = get<1>(mantissa); - uint32_t expAbs = bigint(abs(exp)).convert_to<uint32_t>(); + // 0E... is always zero. + if (value == 0) + return make_tuple(true, rational(0)); + bigint exp = bigint(string(expPoint + 1, _literal.value().end())); - tuple<bool, rational> base = parseRational(string(_literal.value().begin(), expPoint)); - - if (!get<0>(base)) + if (exp > numeric_limits<int32_t>::max() || exp < numeric_limits<int32_t>::min()) return make_tuple(false, rational(0)); - value = get<1>(base); + + uint32_t expAbs = bigint(abs(exp)).convert_to<uint32_t>(); if (exp < 0) { @@ -856,43 +859,49 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal bool RationalNumberType::isImplicitlyConvertibleTo(Type const& _convertTo) const { - if (_convertTo.category() == Category::Integer) + switch (_convertTo.category()) + { + case Category::Integer: { - if (m_value == rational(0)) - return true; if (isFractional()) return false; IntegerType const& targetType = dynamic_cast<IntegerType const&>(_convertTo); + if (targetType.isAddress()) + return false; + if (m_value == rational(0)) + return true; unsigned forSignBit = (targetType.isSigned() ? 1 : 0); if (m_value > rational(0)) { if (m_value.numerator() <= (u256(-1) >> (256 - targetType.numBits() + forSignBit))) return true; + return false; + } + if (targetType.isSigned()) + { + if (-m_value.numerator() <= (u256(1) << (targetType.numBits() - forSignBit))) + return true; } - else if (targetType.isSigned() && -m_value.numerator() <= (u256(1) << (targetType.numBits() - forSignBit))) - return true; return false; } - else if (_convertTo.category() == Category::FixedPoint) + case Category::FixedPoint: { if (auto fixed = fixedPointType()) return fixed->isImplicitlyConvertibleTo(_convertTo); - else - return false; + return false; } - else if (_convertTo.category() == Category::FixedBytes) + case Category::FixedBytes: { FixedBytesType const& fixedBytes = dynamic_cast<FixedBytesType const&>(_convertTo); - if (!isFractional()) - { - if (integerType()) - return fixedBytes.numBytes() * 8 >= integerType()->numBits(); - return false; - } - else + if (isFractional()) return false; + if (integerType()) + return fixedBytes.numBytes() * 8 >= integerType()->numBits(); + return false; + } + default: + return false; } - return false; } bool RationalNumberType::isExplicitlyConvertibleTo(Type const& _convertTo) const @@ -943,7 +952,7 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ RationalNumberType const& other = dynamic_cast<RationalNumberType const&>(*_other); if (Token::isCompareOp(_operator)) { - // Since we do not have a "BoolConstantType", we have to do the acutal comparison + // Since we do not have a "BoolConstantType", we have to do the actual comparison // at runtime and convert to mobile typse first. Such a comparison is not a very common // use-case and will be optimized away. TypePointer thisMobile = mobileType(); @@ -1002,7 +1011,6 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ break; case Token::Exp: { - using boost::multiprecision::pow; if (other.isFractional()) return TypePointer(); solAssert(other.m_value.denominator() == 1, ""); @@ -1036,7 +1044,7 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ else if (_base == -1) return 1 - 2 * int(_exponent & 1); else - return pow(_base, _exponent); + return boost::multiprecision::pow(_base, _exponent); }; bigint numerator = optimizedPow(m_value.numerator(), absExp); @@ -1052,7 +1060,6 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ } case Token::SHL: { - using boost::multiprecision::pow; if (fractional) return TypePointer(); else if (other.m_value < 0) @@ -1066,7 +1073,7 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ uint32_t exponent = other.m_value.numerator().convert_to<uint32_t>(); if (!fitsPrecisionBase2(abs(m_value.numerator()), exponent)) return TypePointer(); - value = m_value.numerator() * pow(bigint(2), exponent); + value = m_value.numerator() * boost::multiprecision::pow(bigint(2), exponent); } break; } @@ -1074,7 +1081,6 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ // determines the resulting type and the type of shift (SAR or SHR). case Token::SAR: { - namespace mp = boost::multiprecision; if (fractional) return TypePointer(); else if (other.m_value < 0) @@ -1086,10 +1092,22 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ else { uint32_t exponent = other.m_value.numerator().convert_to<uint32_t>(); - if (exponent > mostSignificantBit(mp::abs(m_value.numerator()))) - value = 0; + if (exponent > mostSignificantBit(boost::multiprecision::abs(m_value.numerator()))) + value = m_value.numerator() < 0 ? -1 : 0; else - value = rational(m_value.numerator() / mp::pow(bigint(2), exponent), 1); + { + if (m_value.numerator() < 0) + // Add 1 to the negative value before dividing to get a result that is strictly too large, + // then subtract 1 afterwards to round towards negative infinity. + // This is the same algorithm as used in ExpressionCompiler::appendShiftOperatorCode(...). + // To see this note that for negative x, xor(x,all_ones) = (-x-1) and + // therefore xor(div(xor(x,all_ones), exp(2, shift_amount)), all_ones) is + // -(-x - 1) / 2^shift_amount - 1, which is the same as + // (x + 1) / 2^shift_amount - 1. + value = rational((m_value.numerator() + 1) / boost::multiprecision::pow(bigint(2), exponent) - bigint(1), 1); + else + value = rational(m_value.numerator() / boost::multiprecision::pow(bigint(2), exponent), 1); + } } break; } @@ -1154,7 +1172,7 @@ u256 RationalNumberType::literalValue(Literal const*) const auto fixed = fixedPointType(); solAssert(fixed, ""); int fractionalDigits = fixed->fractionalDigits(); - shiftedValue = m_value.numerator() * pow(bigint(10), fractionalDigits) / m_value.denominator(); + shiftedValue = m_value.numerator() * boost::multiprecision::pow(bigint(10), fractionalDigits) / m_value.denominator(); } // we ignore the literal and hope that the type was correctly determined @@ -1469,12 +1487,20 @@ string ReferenceType::stringForReferencePart() const string ReferenceType::identifierLocationSuffix() const { string id; - if (location() == DataLocation::Storage) + switch (location()) + { + case DataLocation::Storage: id += "_storage"; - else if (location() == DataLocation::Memory) + break; + case DataLocation::Memory: id += "_memory"; - else + break; + case DataLocation::CallData: id += "_calldata"; + break; + default: + solAssert(false, "Unknown location returned by location()"); + } if (isPointer()) id += "_ptr"; return id; @@ -1689,6 +1715,7 @@ MemberList::MemberMap ArrayType::nativeMembers(ContractDefinition const*) const { members.push_back({"length", make_shared<IntegerType>(256)}); if (isDynamicallySized() && location() == DataLocation::Storage) + { members.push_back({"push", make_shared<FunctionType>( TypePointers{baseType()}, TypePointers{make_shared<IntegerType>(256)}, @@ -1696,6 +1723,14 @@ MemberList::MemberMap ArrayType::nativeMembers(ContractDefinition const*) const strings{string()}, isByteArray() ? FunctionType::Kind::ByteArrayPush : FunctionType::Kind::ArrayPush )}); + members.push_back({"pop", make_shared<FunctionType>( + TypePointers{}, + TypePointers{}, + strings{string()}, + strings{string()}, + FunctionType::Kind::ArrayPop + )}); + } } return members; } @@ -2206,25 +2241,13 @@ bool TupleType::isImplicitlyConvertibleTo(Type const& _other) const TypePointers const& targets = tupleType->components(); if (targets.empty()) return components().empty(); - if (components().size() != targets.size() && !targets.front() && !targets.back()) - return false; // (,a,) = (1,2,3,4) - unable to position `a` in the tuple. - size_t minNumValues = targets.size(); - if (!targets.back() || !targets.front()) - --minNumValues; // wildcards can also match 0 components - if (components().size() < minNumValues) + if (components().size() != targets.size()) return false; - if (components().size() > targets.size() && targets.front() && targets.back()) - return false; // larger source and no wildcard - bool fillRight = !targets.back() || targets.front(); - for (size_t i = 0; i < min(targets.size(), components().size()); ++i) - { - auto const& s = components()[fillRight ? i : components().size() - i - 1]; - auto const& t = targets[fillRight ? i : targets.size() - i - 1]; - if (!s && t) + for (size_t i = 0; i < targets.size(); ++i) + if (!components()[i] && targets[i]) return false; - else if (s && t && !s->isImplicitlyConvertibleTo(*t)) + else if (components()[i] && targets[i] && !components()[i]->isImplicitlyConvertibleTo(*targets[i])) return false; - } return true; } else @@ -2512,6 +2535,7 @@ string FunctionType::richIdentifier() const case Kind::AddMod: id += "addmod"; break; case Kind::MulMod: id += "mulmod"; break; case Kind::ArrayPush: id += "arraypush"; break; + case Kind::ArrayPop: id += "arraypop"; break; case Kind::ByteArrayPush: id += "bytearraypush"; break; case Kind::ObjectCreation: id += "objectcreation"; break; case Kind::Assert: id += "assert"; break; @@ -2666,6 +2690,7 @@ unsigned FunctionType::sizeOnStack() const case Kind::BareDelegateCall: case Kind::Internal: case Kind::ArrayPush: + case Kind::ArrayPop: case Kind::ByteArrayPush: size = 1; break; @@ -2971,6 +2996,25 @@ ASTPointer<ASTString> FunctionType::documentation() const return ASTPointer<ASTString>(); } +bool FunctionType::padArguments() const +{ + // No padding only for hash functions, low-level calls and the packed encoding function. + switch (m_kind) + { + case Kind::BareCall: + case Kind::BareCallCode: + case Kind::BareDelegateCall: + case Kind::SHA256: + case Kind::RIPEMD160: + case Kind::SHA3: + case Kind::ABIEncodePacked: + return false; + default: + return true; + } + return true; +} + string MappingType::richIdentifier() const { return "t_mapping" + identifierList(m_keyType, m_valueType); diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 7c6f179b..135f4a0e 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -914,6 +914,7 @@ public: AddMod, ///< ADDMOD MulMod, ///< MULMOD ArrayPush, ///< .push() to a dynamically sized array in storage + ArrayPop, ///< .pop() from a dynamically sized array in storage ByteArrayPush, ///< .push() to a dynamically sized byte array in storage ObjectCreation, ///< array creation using new Assert, ///< assert() @@ -1030,7 +1031,7 @@ public: /// @param _selfType if the function is bound, this has to be supplied and is the type of the /// expression the function is called on. bool canTakeArguments(TypePointers const& _arguments, TypePointer const& _selfType = TypePointer()) const; - /// @returns true if the types of parameters are equal (does't check return parameter types) + /// @returns true if the types of parameters are equal (doesn't check return parameter types) bool hasEqualArgumentTypes(FunctionType const& _other) const; /// @returns true if the ABI is used for this call (only meaningful for external calls) @@ -1057,18 +1058,21 @@ public: ASTPointer<ASTString> documentation() const; /// true iff arguments are to be padded to multiples of 32 bytes for external calls - bool padArguments() const { return !(m_kind == Kind::SHA3 || m_kind == Kind::SHA256 || m_kind == Kind::RIPEMD160 || m_kind == Kind::ABIEncodePacked); } + /// The only functions that do not pad are hash functions, the low-level call functions + /// and abi.encodePacked. + bool padArguments() const; bool takesArbitraryParameters() const { return m_arbitraryParameters; } /// true iff the function takes a single bytes parameter and it is passed on without padding. - /// @todo until 0.5.0, this is just a "recommendation". bool takesSinglePackedBytesParameter() const { - // @todo add the call kinds here with 0.5.0 and perhaps also log0. switch (m_kind) { case FunctionType::Kind::SHA3: case FunctionType::Kind::SHA256: case FunctionType::Kind::RIPEMD160: + case FunctionType::Kind::BareCall: + case FunctionType::Kind::BareCallCode: + case FunctionType::Kind::BareDelegateCall: return true; default: return false; diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index 3e3aa0ae..b3f1bc7e 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -17,7 +17,7 @@ /** * @author Christian <chris@ethereum.org> * @date 2017 - * Routines that generate JULIA code related to ABI encoding, decoding and type conversions. + * Routines that generate Yul code related to ABI encoding, decoding and type conversions. */ #include <libsolidity/codegen/ABIFunctions.h> @@ -989,7 +989,7 @@ string ABIFunctions::abiEncodingFunctionStringLiteral( )"); templ("functionName", functionName); - // TODO this can make use of CODECOPY for large strings once we have that in JULIA + // TODO this can make use of CODECOPY for large strings once we have that in Yul size_t words = (value.size() + 31) / 32; templ("overallSize", to_string(32 + words * 32)); templ("length", to_string(value.size())); @@ -1188,7 +1188,8 @@ string ABIFunctions::abiDecodingFunctionCalldataArray(ArrayType const& _type) solAssert(_type.dataStoredIn(DataLocation::CallData), ""); if (!_type.isDynamicallySized()) solAssert(_type.length() < u256("0xffffffffffffffff"), ""); - solAssert(!_type.baseType()->isDynamicallyEncoded(), ""); + if (_type.baseType()->isDynamicallyEncoded()) + solUnimplemented("Calldata arrays with non-value base types are not yet supported by Solidity."); solAssert(_type.baseType()->calldataEncodedSize() < u256("0xffffffffffffffff"), ""); string functionName = diff --git a/libsolidity/codegen/ABIFunctions.h b/libsolidity/codegen/ABIFunctions.h index db4d40f5..3caaa1d9 100644 --- a/libsolidity/codegen/ABIFunctions.h +++ b/libsolidity/codegen/ABIFunctions.h @@ -17,7 +17,7 @@ /** * @author Christian <chris@ethereum.org> * @date 2017 - * Routines that generate JULIA code related to ABI encoding, decoding and type conversions. + * Routines that generate Yul code related to ABI encoding, decoding and type conversions. */ #pragma once @@ -203,7 +203,7 @@ private: std::string arrayLengthFunction(ArrayType const& _type); /// @returns the name of a function that computes the number of bytes required /// to store an array in memory given its length (internally encoded, not ABI encoded). - /// The function reverts for too large lengthes. + /// The function reverts for too large lengths. std::string arrayAllocationSizeFunction(ArrayType const& _type); /// @returns the name of a function that converts a storage slot number /// or a memory pointer to the slot number / memory pointer for the data position of an array diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index 0fe66d2d..2b77db8f 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -303,12 +303,17 @@ void ArrayUtils::copyArrayToMemory(ArrayType const& _sourceType, bool _padToWord m_context << _sourceType.length(); if (baseSize > 1) m_context << u256(baseSize) << Instruction::MUL; - // stack: target source_offset source_len - m_context << Instruction::DUP1 << Instruction::DUP3 << Instruction::DUP5; - // stack: target source_offset source_len source_len source_offset target - m_context << Instruction::CALLDATACOPY; - m_context << Instruction::DUP3 << Instruction::ADD; - m_context << Instruction::SWAP2 << Instruction::POP << Instruction::POP; + + string routine = "calldatacopy(target, source, len)\n"; + if (_padToWordBoundaries) + routine += R"( + // Set padding suffix to zero + mstore(add(target, len), 0) + len := and(add(len, 0x1f), not(0x1f)) + )"; + routine += "target := add(target, len)\n"; + m_context.appendInlineAssembly("{" + routine + "}", {"target", "source", "len"}); + m_context << Instruction::POP << Instruction::POP; } else if (_sourceType.location() == DataLocation::Memory) { @@ -823,6 +828,85 @@ void ArrayUtils::incrementDynamicArraySize(ArrayType const& _type) const })", {"ref"}); } +void ArrayUtils::popStorageArrayElement(ArrayType const& _type) const +{ + solAssert(_type.location() == DataLocation::Storage, ""); + solAssert(_type.isDynamicallySized(), ""); + if (!_type.isByteArray() && _type.baseType()->storageBytes() < 32) + solAssert(_type.baseType()->isValueType(), "Invalid storage size for non-value type."); + + if (_type.isByteArray()) + { + m_context.appendInlineAssembly(R"({ + let slot_value := sload(ref) + switch and(slot_value, 1) + case 0 { + // short byte array + let length := and(div(slot_value, 2), 0x1f) + if iszero(length) { invalid() } + + // Zero-out the suffix including the least significant byte. + let mask := sub(exp(0x100, sub(33, length)), 1) + length := sub(length, 1) + slot_value := or(and(not(mask), slot_value), mul(length, 2)) + sstore(ref, slot_value) + } + case 1 { + // long byte array + mstore(0, ref) + let length := div(slot_value, 2) + let slot := keccak256(0, 0x20) + switch length + case 32 + { + let data := sload(slot) + sstore(slot, 0) + data := and(data, not(0xff)) + sstore(ref, or(data, 62)) + } + default + { + let offset_inside_slot := and(sub(length, 1), 0x1f) + slot := add(slot, div(sub(length, 1), 32)) + let data := sload(slot) + + // Zero-out the suffix of the byte array by masking it. + // ((1<<(8 * (32 - offset))) - 1) + let mask := sub(exp(0x100, sub(32, offset_inside_slot)), 1) + data := and(not(mask), data) + sstore(slot, data) + + // Reduce the length by 1 + slot_value := sub(slot_value, 2) + sstore(ref, slot_value) + } + } + })", {"ref"}); + m_context << Instruction::POP; + } + else + { + // stack: ArrayReference + retrieveLength(_type); + // stack: ArrayReference oldLength + m_context << Instruction::DUP1; + // stack: ArrayReference oldLength oldLength + m_context << Instruction::ISZERO; + m_context.appendConditionalInvalid(); + + // Stack: ArrayReference oldLength + m_context << u256(1) << Instruction::SWAP1 << Instruction::SUB; + // Stack ArrayReference newLength + m_context << Instruction::DUP2 << Instruction::DUP2; + // Stack ArrayReference newLength ArrayReference newLength; + accessIndex(_type, false); + // Stack: ArrayReference newLength storage_slot byte_offset + StorageItem(m_context, *_type.baseType()).setToZero(SourceLocation(), true); + // Stack: ArrayReference newLength + m_context << Instruction::SWAP1 << Instruction::SSTORE; + } +} + void ArrayUtils::clearStorageLoop(TypePointer const& _type) const { m_context.callLowLevelFunction( diff --git a/libsolidity/codegen/ArrayUtils.h b/libsolidity/codegen/ArrayUtils.h index 99786397..daf50bf5 100644 --- a/libsolidity/codegen/ArrayUtils.h +++ b/libsolidity/codegen/ArrayUtils.h @@ -73,6 +73,11 @@ public: /// Stack pre: reference (excludes byte offset) /// Stack post: new_length void incrementDynamicArraySize(ArrayType const& _type) const; + /// Decrements the size of a dynamic array by one if length is nonzero. Causes an invalid instruction otherwise. + /// Clears the removed data element. In case of a byte array, this might move the data. + /// Stack pre: reference + /// Stack post: + void popStorageArrayElement(ArrayType const& _type) const; /// Appends a loop that clears a sequence of storage slots of the given type (excluding end). /// Stack pre: end_ref start_ref /// Stack post: end_ref diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index a35eea73..3b1b4ec0 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -127,10 +127,14 @@ void CompilerContext::addVariable(VariableDeclaration const& _declaration, unsigned _offsetToCurrent) { solAssert(m_asm->deposit() >= 0 && unsigned(m_asm->deposit()) >= _offsetToCurrent, ""); + unsigned sizeOnStack = _declaration.annotation().type->sizeOnStack(); + // Variables should not have stack size other than [1, 2], + // but that might change when new types are introduced. + solAssert(sizeOnStack == 1 || sizeOnStack == 2, ""); m_localVariables[&_declaration].push_back(unsigned(m_asm->deposit()) - _offsetToCurrent); } -void CompilerContext::removeVariable(VariableDeclaration const& _declaration) +void CompilerContext::removeVariable(Declaration const& _declaration) { solAssert(m_localVariables.count(&_declaration) && !m_localVariables[&_declaration].empty(), ""); m_localVariables[&_declaration].pop_back(); @@ -138,6 +142,25 @@ void CompilerContext::removeVariable(VariableDeclaration const& _declaration) m_localVariables.erase(&_declaration); } +void CompilerContext::removeVariablesAboveStackHeight(unsigned _stackHeight) +{ + vector<Declaration const*> toRemove; + for (auto _var: m_localVariables) + { + solAssert(!_var.second.empty(), ""); + solAssert(_var.second.back() <= stackHeight(), ""); + if (_var.second.back() >= _stackHeight) + toRemove.push_back(_var.first); + } + for (auto _var: toRemove) + removeVariable(*_var); +} + +unsigned CompilerContext::numberOfLocalVariables() const +{ + return m_localVariables.size(); +} + eth::Assembly const& CompilerContext::compiledContract(const ContractDefinition& _contract) const { auto ret = m_compiledContracts.find(&_contract); diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index 5776b5d1..3f357821 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -71,7 +71,11 @@ public: void addStateVariable(VariableDeclaration const& _declaration, u256 const& _storageOffset, unsigned _byteOffset); void addVariable(VariableDeclaration const& _declaration, unsigned _offsetToCurrent = 0); - void removeVariable(VariableDeclaration const& _declaration); + void removeVariable(Declaration const& _declaration); + /// Removes all local variables currently allocated above _stackHeight. + void removeVariablesAboveStackHeight(unsigned _stackHeight); + /// Returns the number of currently allocated local variables. + unsigned numberOfLocalVariables() const; void setCompiledContracts(std::map<ContractDefinition const*, eth::Assembly const*> const& _contracts) { m_compiledContracts = _contracts; } eth::Assembly const& compiledContract(ContractDefinition const& _contract) const; diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index d9f17263..2d81a106 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -181,12 +181,12 @@ void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBound } } -void CompilerUtils::abiDecode(TypePointers const& _typeParameters, bool _fromMemory, bool _revertOnOutOfBounds) +void CompilerUtils::abiDecode(TypePointers const& _typeParameters, bool _fromMemory) { /// Stack: <source_offset> <length> if (m_context.experimentalFeatureActive(ExperimentalFeature::ABIEncoderV2)) { - // Use the new JULIA-based decoding function + // Use the new Yul-based decoding function auto stackHeightBefore = m_context.stackHeight(); abiDecodeV2(_typeParameters, _fromMemory); solAssert(m_context.stackHeight() - stackHeightBefore == sizeOnStack(_typeParameters) - 2, ""); @@ -194,14 +194,10 @@ void CompilerUtils::abiDecode(TypePointers const& _typeParameters, bool _fromMem } //@todo this does not yet support nested dynamic arrays - - if (_revertOnOutOfBounds) - { - size_t encodedSize = 0; - for (auto const& t: _typeParameters) - encodedSize += t->decodingType()->calldataEncodedSize(true); - m_context.appendInlineAssembly("{ if lt(len, " + to_string(encodedSize) + ") { revert(0, 0) } }", {"len"}); - } + size_t encodedSize = 0; + for (auto const& t: _typeParameters) + encodedSize += t->decodingType()->calldataEncodedSize(true); + m_context.appendInlineAssembly("{ if lt(len, " + to_string(encodedSize) + ") { revert(0, 0) } }", {"len"}); m_context << Instruction::DUP2 << Instruction::ADD; m_context << Instruction::SWAP1; @@ -231,26 +227,21 @@ void CompilerUtils::abiDecode(TypePointers const& _typeParameters, bool _fromMem { // compute data pointer m_context << Instruction::DUP1 << Instruction::MLOAD; - if (_revertOnOutOfBounds) - { - // Check that the data pointer is valid and that length times - // item size is still inside the range. - Whiskers templ(R"({ - if gt(ptr, 0x100000000) { revert(0, 0) } - ptr := add(ptr, base_offset) - let array_data_start := add(ptr, 0x20) - if gt(array_data_start, input_end) { revert(0, 0) } - let array_length := mload(ptr) - if or( - gt(array_length, 0x100000000), - gt(add(array_data_start, mul(array_length, <item_size>)), input_end) - ) { revert(0, 0) } - })"); - templ("item_size", to_string(arrayType.isByteArray() ? 1 : arrayType.baseType()->calldataEncodedSize(true))); - m_context.appendInlineAssembly(templ.render(), {"input_end", "base_offset", "offset", "ptr"}); - } - else - m_context << Instruction::DUP3 << Instruction::ADD; + // Check that the data pointer is valid and that length times + // item size is still inside the range. + Whiskers templ(R"({ + if gt(ptr, 0x100000000) { revert(0, 0) } + ptr := add(ptr, base_offset) + let array_data_start := add(ptr, 0x20) + if gt(array_data_start, input_end) { revert(0, 0) } + let array_length := mload(ptr) + if or( + gt(array_length, 0x100000000), + gt(add(array_data_start, mul(array_length, <item_size>)), input_end) + ) { revert(0, 0) } + })"); + templ("item_size", to_string(arrayType.isByteArray() ? 1 : arrayType.baseType()->calldataEncodedSize(true))); + m_context.appendInlineAssembly(templ.render(), {"input_end", "base_offset", "offset", "ptr"}); // stack: v1 v2 ... v(k-1) input_end base_offset current_offset v(k) moveIntoStack(3); m_context << u256(0x20) << Instruction::ADD; @@ -273,30 +264,25 @@ void CompilerUtils::abiDecode(TypePointers const& _typeParameters, bool _fromMem loadFromMemoryDynamic(IntegerType(256), !_fromMemory); m_context << Instruction::SWAP1; // stack: input_end base_offset next_pointer data_offset - if (_revertOnOutOfBounds) - m_context.appendInlineAssembly("{ if gt(data_offset, 0x100000000) { revert(0, 0) } }", {"data_offset"}); + m_context.appendInlineAssembly("{ if gt(data_offset, 0x100000000) { revert(0, 0) } }", {"data_offset"}); m_context << Instruction::DUP3 << Instruction::ADD; // stack: input_end base_offset next_pointer array_head_ptr - if (_revertOnOutOfBounds) - m_context.appendInlineAssembly( - "{ if gt(add(array_head_ptr, 0x20), input_end) { revert(0, 0) } }", - {"input_end", "base_offset", "next_ptr", "array_head_ptr"} - ); + m_context.appendInlineAssembly( + "{ if gt(add(array_head_ptr, 0x20), input_end) { revert(0, 0) } }", + {"input_end", "base_offset", "next_ptr", "array_head_ptr"} + ); // retrieve length loadFromMemoryDynamic(IntegerType(256), !_fromMemory, true); // stack: input_end base_offset next_pointer array_length data_pointer m_context << Instruction::SWAP2; // stack: input_end base_offset data_pointer array_length next_pointer - if (_revertOnOutOfBounds) - { - unsigned itemSize = arrayType.isByteArray() ? 1 : arrayType.baseType()->calldataEncodedSize(true); - m_context.appendInlineAssembly(R"({ - if or( - gt(array_length, 0x100000000), - gt(add(data_ptr, mul(array_length, )" + to_string(itemSize) + R"()), input_end) - ) { revert(0, 0) } - })", {"input_end", "base_offset", "data_ptr", "array_length", "next_ptr"}); - } + unsigned itemSize = arrayType.isByteArray() ? 1 : arrayType.baseType()->calldataEncodedSize(true); + m_context.appendInlineAssembly(R"({ + if or( + gt(array_length, 0x100000000), + gt(add(data_ptr, mul(array_length, )" + to_string(itemSize) + R"()), input_end) + ) { revert(0, 0) } + })", {"input_end", "base_offset", "data_ptr", "array_length", "next_ptr"}); } else { @@ -368,7 +354,7 @@ void CompilerUtils::encodeToMemory( m_context.experimentalFeatureActive(ExperimentalFeature::ABIEncoderV2) ) { - // Use the new JULIA-based encoding function + // Use the new Yul-based encoding function auto stackHeightBefore = m_context.stackHeight(); abiEncodeV2(_givenTypes, targetTypes, _encodeAsLibraryTypes); solAssert(stackHeightBefore - m_context.stackHeight() == sizeOnStack(_givenTypes), ""); @@ -377,8 +363,8 @@ void CompilerUtils::encodeToMemory( // Stack during operation: // <v1> <v2> ... <vn> <mem_start> <dyn_head_1> ... <dyn_head_r> <end_of_mem> - // The values dyn_head_i are added during the first loop and they point to the head part - // of the ith dynamic parameter, which is filled once the dynamic parts are processed. + // The values dyn_head_n are added during the first loop and they point to the head part + // of the nth dynamic parameter, which is filled once the dynamic parts are processed. // store memory start pointer m_context << Instruction::DUP1; @@ -524,7 +510,7 @@ void CompilerUtils::zeroInitialiseMemoryArray(ArrayType const& _type) codecopy(memptr, codesize(), size) memptr := add(memptr, size) })"); - templ("element_size", to_string(_type.baseType()->memoryHeadSize())); + templ("element_size", to_string(_type.isByteArray() ? 1 : _type.baseType()->memoryHeadSize())); m_context.appendInlineAssembly(templ.render(), {"length", "memptr"}); } else @@ -1184,6 +1170,15 @@ void CompilerUtils::popStackSlots(size_t _amount) m_context << Instruction::POP; } +void CompilerUtils::popAndJump(unsigned _toHeight, eth::AssemblyItem const& _jumpTo) +{ + solAssert(m_context.stackHeight() >= _toHeight, ""); + unsigned amount = m_context.stackHeight() - _toHeight; + popStackSlots(amount); + m_context.appendJumpTo(_jumpTo); + m_context.adjustStackOffset(amount); +} + unsigned CompilerUtils::sizeOnStack(vector<shared_ptr<Type const>> const& _variableTypes) { unsigned size = 0; diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h index 8e3a8a5d..26df4765 100644 --- a/libsolidity/codegen/CompilerUtils.h +++ b/libsolidity/codegen/CompilerUtils.h @@ -102,7 +102,7 @@ public: /// area. Also has a hard cap of 0x100000000 for any given length/offset field. /// Stack pre: <source_offset> <length> /// Stack post: <value0> <value1> ... <valuen> - void abiDecode(TypePointers const& _typeParameters, bool _fromMemory = false, bool _revertOnOutOfBounds = false); + void abiDecode(TypePointers const& _typeParameters, bool _fromMemory = false); /// Copies values (of types @a _givenTypes) given on the stack to a location in memory given /// at the stack top, encoding them according to the ABI as the given types @a _targetTypes. @@ -241,6 +241,10 @@ public: void popStackElement(Type const& _type); /// Removes element from the top of the stack _amount times. void popStackSlots(size_t _amount); + /// Pops slots from the stack such that its height is _toHeight. + /// Adds jump to _jumpTo. + /// Readjusts the stack offset to the original value. + void popAndJump(unsigned _toHeight, eth::AssemblyItem const& _jumpTo); template <class T> static unsigned sizeOnStack(std::vector<T> const& _variables); diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index f195b416..bbb3db3d 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -427,7 +427,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) m_context.startFunction(_function); // stack upon entry: [return address] [arg0] [arg1] ... [argn] - // reserve additional slots: [retarg0] ... [retargm] [localvar0] ... [localvarp] + // reserve additional slots: [retarg0] ... [retargm] unsigned parametersSize = CompilerUtils::sizeOnStack(_function.parameters()); if (!_function.isConstructor()) @@ -441,8 +441,6 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) for (ASTPointer<VariableDeclaration const> const& variable: _function.returnParameters()) appendStackVariableInitialisation(*variable); - for (VariableDeclaration const* localVariable: _function.localVariables()) - appendStackVariableInitialisation(*localVariable); if (_function.isConstructor()) if (auto c = m_context.nextConstructor(dynamic_cast<ContractDefinition const&>(*_function.scope()))) @@ -451,12 +449,11 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) solAssert(m_returnTags.empty(), ""); m_breakTags.clear(); m_continueTags.clear(); - m_stackCleanupForReturn = 0; m_currentFunction = &_function; m_modifierDepth = -1; + m_scopeStackHeight.clear(); appendModifierOrFunctionCode(); - solAssert(m_returnTags.empty(), ""); // Now we need to re-shuffle the stack. For this we keep a record of the stack layout @@ -467,14 +464,12 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) unsigned const c_argumentsSize = CompilerUtils::sizeOnStack(_function.parameters()); unsigned const c_returnValuesSize = CompilerUtils::sizeOnStack(_function.returnParameters()); - unsigned const c_localVariablesSize = CompilerUtils::sizeOnStack(_function.localVariables()); vector<int> stackLayout; stackLayout.push_back(c_returnValuesSize); // target of return address stackLayout += vector<int>(c_argumentsSize, -1); // discard all arguments for (unsigned i = 0; i < c_returnValuesSize; ++i) stackLayout.push_back(i); - stackLayout += vector<int>(c_localVariablesSize, -1); if (stackLayout.size() > 17) BOOST_THROW_EXCEPTION( @@ -493,18 +488,23 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) m_context << swapInstruction(stackLayout.size() - stackLayout.back() - 1); swap(stackLayout[stackLayout.back()], stackLayout.back()); } - //@todo assert that everything is in place now + for (int i = 0; i < int(stackLayout.size()); ++i) + if (stackLayout[i] != i) + solAssert(false, "Invalid stack layout on cleanup."); for (ASTPointer<VariableDeclaration const> const& variable: _function.parameters() + _function.returnParameters()) m_context.removeVariable(*variable); - for (VariableDeclaration const* localVariable: _function.localVariables()) - m_context.removeVariable(*localVariable); m_context.adjustStackOffset(-(int)c_returnValuesSize); /// The constructor and the fallback function doesn't to jump out. - if (!_function.isConstructor() && !_function.isFallback()) - m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction); + if (!_function.isConstructor()) + { + solAssert(m_context.numberOfLocalVariables() == 0, ""); + if (!_function.isFallback()) + m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction); + } + return false; } @@ -669,14 +669,14 @@ bool ContractCompiler::visit(WhileStatement const& _whileStatement) eth::AssemblyItem loopStart = m_context.newTag(); eth::AssemblyItem loopEnd = m_context.newTag(); - m_breakTags.push_back(loopEnd); + m_breakTags.push_back({loopEnd, m_context.stackHeight()}); m_context << loopStart; if (_whileStatement.isDoWhile()) { eth::AssemblyItem condition = m_context.newTag(); - m_continueTags.push_back(condition); + m_continueTags.push_back({condition, m_context.stackHeight()}); _whileStatement.body().accept(*this); @@ -687,7 +687,7 @@ bool ContractCompiler::visit(WhileStatement const& _whileStatement) } else { - m_continueTags.push_back(loopStart); + m_continueTags.push_back({loopStart, m_context.stackHeight()}); compileExpression(_whileStatement.condition()); m_context << Instruction::ISZERO; m_context.appendConditionalJumpTo(loopEnd); @@ -712,12 +712,14 @@ bool ContractCompiler::visit(ForStatement const& _forStatement) eth::AssemblyItem loopStart = m_context.newTag(); eth::AssemblyItem loopEnd = m_context.newTag(); eth::AssemblyItem loopNext = m_context.newTag(); - m_continueTags.push_back(loopNext); - m_breakTags.push_back(loopEnd); + + storeStackHeight(&_forStatement); if (_forStatement.initializationExpression()) _forStatement.initializationExpression()->accept(*this); + m_breakTags.push_back({loopEnd, m_context.stackHeight()}); + m_continueTags.push_back({loopNext, m_context.stackHeight()}); m_context << loopStart; // if there is no terminating condition in for, default is to always be true @@ -737,11 +739,16 @@ bool ContractCompiler::visit(ForStatement const& _forStatement) _forStatement.loopExpression()->accept(*this); m_context.appendJumpTo(loopStart); + m_context << loopEnd; m_continueTags.pop_back(); m_breakTags.pop_back(); + // For the case where no break/return is executed: + // loop initialization variables have to be freed + popScopedVariables(&_forStatement); + checker.check(); return false; } @@ -749,16 +756,16 @@ bool ContractCompiler::visit(ForStatement const& _forStatement) bool ContractCompiler::visit(Continue const& _continueStatement) { CompilerContext::LocationSetter locationSetter(m_context, _continueStatement); - if (!m_continueTags.empty()) - m_context.appendJumpTo(m_continueTags.back()); + solAssert(!m_continueTags.empty(), ""); + CompilerUtils(m_context).popAndJump(m_continueTags.back().second, m_continueTags.back().first); return false; } bool ContractCompiler::visit(Break const& _breakStatement) { CompilerContext::LocationSetter locationSetter(m_context, _breakStatement); - if (!m_breakTags.empty()) - m_context.appendJumpTo(m_breakTags.back()); + solAssert(!m_breakTags.empty(), ""); + CompilerUtils(m_context).popAndJump(m_breakTags.back().second, m_breakTags.back().first); return false; } @@ -784,10 +791,8 @@ bool ContractCompiler::visit(Return const& _return) for (auto const& retVariable: boost::adaptors::reverse(returnParameters)) CompilerUtils(m_context).moveToStackVariable(*retVariable); } - for (unsigned i = 0; i < m_stackCleanupForReturn; ++i) - m_context << Instruction::POP; - m_context.appendJumpTo(m_returnTags.back()); - m_context.adjustStackOffset(m_stackCleanupForReturn); + + CompilerUtils(m_context).popAndJump(m_returnTags.back().second, m_returnTags.back().first); return false; } @@ -810,8 +815,15 @@ bool ContractCompiler::visit(EmitStatement const& _emit) bool ContractCompiler::visit(VariableDeclarationStatement const& _variableDeclarationStatement) { - StackHeightChecker checker(m_context); CompilerContext::LocationSetter locationSetter(m_context, _variableDeclarationStatement); + + // Local variable slots are reserved when their declaration is visited, + // and freed in the end of their scope. + for (auto _decl: _variableDeclarationStatement.declarations()) + if (_decl) + appendStackVariableInitialisation(*_decl); + + StackHeightChecker checker(m_context); if (Expression const* expression = _variableDeclarationStatement.initialValue()) { CompilerUtils utils(m_context); @@ -821,20 +833,19 @@ bool ContractCompiler::visit(VariableDeclarationStatement const& _variableDeclar valueTypes = tupleType->components(); else valueTypes = TypePointers{expression->annotation().type}; - auto const& assignments = _variableDeclarationStatement.annotation().assignments; - solAssert(assignments.size() == valueTypes.size(), ""); - for (size_t i = 0; i < assignments.size(); ++i) + auto const& declarations = _variableDeclarationStatement.declarations(); + solAssert(declarations.size() == valueTypes.size(), ""); + for (size_t i = 0; i < declarations.size(); ++i) { - size_t j = assignments.size() - i - 1; + size_t j = declarations.size() - i - 1; solAssert(!!valueTypes[j], ""); - VariableDeclaration const* varDecl = assignments[j]; - if (!varDecl) - utils.popStackElement(*valueTypes[j]); - else + if (VariableDeclaration const* varDecl = declarations[j].get()) { utils.convertType(*valueTypes[j], *varDecl->annotation().type); utils.moveToStackVariable(*varDecl); } + else + utils.popStackElement(*valueTypes[j]); } } checker.check(); @@ -861,6 +872,18 @@ bool ContractCompiler::visit(PlaceholderStatement const& _placeholderStatement) return true; } +bool ContractCompiler::visit(Block const& _block) +{ + storeStackHeight(&_block); + return true; +} + +void ContractCompiler::endVisit(Block const& _block) +{ + // Frees local variables declared in the scope of this block. + popScopedVariables(&_block); +} + void ContractCompiler::appendMissingFunctions() { while (Declaration const* function = m_context.nextFunctionToCompile()) @@ -916,27 +939,19 @@ void ContractCompiler::appendModifierOrFunctionCode() modifier.parameters()[i]->annotation().type ); } - for (VariableDeclaration const* localVariable: modifier.localVariables()) - { - addedVariables.push_back(localVariable); - appendStackVariableInitialisation(*localVariable); - } - stackSurplus = - CompilerUtils::sizeOnStack(modifier.parameters()) + - CompilerUtils::sizeOnStack(modifier.localVariables()); + stackSurplus = CompilerUtils::sizeOnStack(modifier.parameters()); codeBlock = &modifier.body(); } } if (codeBlock) { - m_returnTags.push_back(m_context.newTag()); - + m_returnTags.push_back({m_context.newTag(), m_context.stackHeight()}); codeBlock->accept(*this); solAssert(!m_returnTags.empty(), ""); - m_context << m_returnTags.back(); + m_context << m_returnTags.back().first; m_returnTags.pop_back(); CompilerUtils(m_context).popStackSlots(stackSurplus); @@ -983,3 +998,20 @@ eth::AssemblyPointer ContractCompiler::cloneRuntime() const a << u256(0x20) << u256(0) << Instruction::RETURN; return make_shared<eth::Assembly>(a); } + +void ContractCompiler::popScopedVariables(ASTNode const* _node) +{ + unsigned blockHeight = m_scopeStackHeight.at(m_modifierDepth).at(_node); + m_context.removeVariablesAboveStackHeight(blockHeight); + solAssert(m_context.stackHeight() >= blockHeight, ""); + unsigned stackDiff = m_context.stackHeight() - blockHeight; + CompilerUtils(m_context).popStackSlots(stackDiff); + m_scopeStackHeight[m_modifierDepth].erase(_node); + if (m_scopeStackHeight[m_modifierDepth].size() == 0) + m_scopeStackHeight.erase(m_modifierDepth); +} + +void ContractCompiler::storeStackHeight(ASTNode const* _node) +{ + m_scopeStackHeight[m_modifierDepth][_node] = m_context.stackHeight(); +} diff --git a/libsolidity/codegen/ContractCompiler.h b/libsolidity/codegen/ContractCompiler.h index 02a3452f..8516ec2c 100644 --- a/libsolidity/codegen/ContractCompiler.h +++ b/libsolidity/codegen/ContractCompiler.h @@ -109,6 +109,8 @@ private: virtual bool visit(VariableDeclarationStatement const& _variableDeclarationStatement) override; virtual bool visit(ExpressionStatement const& _expressionStatement) override; virtual bool visit(PlaceholderStatement const&) override; + virtual bool visit(Block const& _block) override; + virtual void endVisit(Block const& _block) override; /// Repeatedly visits all function which are referenced but which are not compiled yet. void appendMissingFunctions(); @@ -123,19 +125,31 @@ private: /// @returns the runtime assembly for clone contracts. eth::AssemblyPointer cloneRuntime() const; + /// Frees the variables of a certain scope (to be used when leaving). + void popScopedVariables(ASTNode const* _node); + + /// Sets the stack height for the visited loop. + void storeStackHeight(ASTNode const* _node); + bool const m_optimise; /// Pointer to the runtime compiler in case this is a creation compiler. ContractCompiler* m_runtimeCompiler = nullptr; CompilerContext& m_context; - std::vector<eth::AssemblyItem> m_breakTags; ///< tag to jump to for a "break" statement - std::vector<eth::AssemblyItem> m_continueTags; ///< tag to jump to for a "continue" statement - /// Tag to jump to for a "return" statement, needs to be stacked because of modifiers. - std::vector<eth::AssemblyItem> m_returnTags; + /// Tag to jump to for a "break" statement and the stack height after freeing the local loop variables. + std::vector<std::pair<eth::AssemblyItem, unsigned>> m_breakTags; + /// Tag to jump to for a "continue" statement and the stack height after freeing the local loop variables. + std::vector<std::pair<eth::AssemblyItem, unsigned>> m_continueTags; + /// Tag to jump to for a "return" statement and the stack height after freeing the local function or modifier variables. + /// Needs to be stacked because of modifiers. + std::vector<std::pair<eth::AssemblyItem, unsigned>> m_returnTags; unsigned m_modifierDepth = 0; FunctionDefinition const* m_currentFunction = nullptr; - unsigned m_stackCleanupForReturn = 0; ///< this number of stack elements need to be removed before jump to m_returnTag + // arguments for base constructors, filled in derived-to-base order std::map<FunctionDefinition const*, ASTNode const*> const* m_baseArguments; + + /// Stores the variables that were declared inside a specific scope, for each modifier depth. + std::map<unsigned, std::map<ASTNode const*, unsigned>> m_scopeStackHeight; }; } diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 4bcc1fa9..4cec69c8 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -349,6 +349,10 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation) case Token::Inc: // ++ (pre- or postfix) case Token::Dec: // -- (pre- or postfix) solAssert(!!m_currentLValue, "LValue not retrieved."); + solUnimplementedAssert( + _unaryOperation.annotation().type->category() != Type::Category::FixedPoint, + "Not yet implemented - FixedPointType." + ); m_currentLValue->retrieveValue(_unaryOperation.location()); if (!_unaryOperation.isPrefixOperation()) { @@ -699,16 +703,24 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) } case FunctionType::Kind::SHA3: { - TypePointers argumentTypes; - for (auto const& arg: arguments) + solAssert(arguments.size() == 1, ""); + solAssert(!function.padArguments(), ""); + TypePointer const& argType = arguments.front()->annotation().type; + solAssert(argType, ""); + arguments.front()->accept(*this); + // Optimization: If type is bytes or string, then do not encode, + // but directly compute keccak256 on memory. + if (*argType == ArrayType(DataLocation::Memory) || *argType == ArrayType(DataLocation::Memory, true)) { - arg->accept(*this); - argumentTypes.push_back(arg->annotation().type); + ArrayUtils(m_context).retrieveLength(ArrayType(DataLocation::Memory)); + m_context << Instruction::SWAP1 << u256(0x20) << Instruction::ADD; + } + else + { + utils().fetchFreeMemoryPointer(); + utils().packedEncode({argType}, TypePointers()); + utils().toSizeAfterFreeMemoryPointer(); } - utils().fetchFreeMemoryPointer(); - solAssert(!function.padArguments(), ""); - utils().packedEncode(argumentTypes, TypePointers()); - utils().toSizeAfterFreeMemoryPointer(); m_context << Instruction::KECCAK256; break; } @@ -866,6 +878,19 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) StorageByteArrayElement(m_context).storeValue(*type, _functionCall.location(), true); break; } + case FunctionType::Kind::ArrayPop: + { + _functionCall.expression().accept(*this); + solAssert(function.parameterTypes().empty(), ""); + + ArrayType const& arrayType = dynamic_cast<ArrayType const&>( + *dynamic_cast<MemberAccess const&>(_functionCall.expression()).expression().annotation().type + ); + solAssert(arrayType.dataStoredIn(DataLocation::Storage), ""); + + ArrayUtils(m_context).popStorageArrayElement(arrayType); + break; + } case FunctionType::Kind::ObjectCreation: { ArrayType const& arrayType = dynamic_cast<ArrayType const&>(*_functionCall.annotation().type); @@ -1345,11 +1370,13 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) break; } } - else if (member == "push") + else if (member == "push" || member == "pop") { solAssert( - type.isDynamicallySized() && type.location() == DataLocation::Storage, - "Tried to use .push() on a non-dynamically sized array" + type.isDynamicallySized() && + type.location() == DataLocation::Storage && + type.category() == Type::Category::Array, + "Tried to use ." + member + "() on a non-dynamically sized array" ); } else @@ -1624,12 +1651,12 @@ void ExpressionCompiler::appendOrdinaryBinaryOperatorCode(Token::Value _operator void ExpressionCompiler::appendArithmeticOperatorCode(Token::Value _operator, Type const& _type) { - IntegerType const& type = dynamic_cast<IntegerType const&>(_type); - bool const c_isSigned = type.isSigned(); - if (_type.category() == Type::Category::FixedPoint) solUnimplemented("Not yet implemented - FixedPointType."); + IntegerType const& type = dynamic_cast<IntegerType const&>(_type); + bool const c_isSigned = type.isSigned(); + switch (_operator) { case Token::Add: @@ -1722,11 +1749,36 @@ void ExpressionCompiler::appendShiftOperatorCode(Token::Value _operator, Type co m_context << u256(2) << Instruction::EXP << Instruction::MUL; break; case Token::SAR: - // NOTE: SAR rounds differently than SDIV - if (m_context.evmVersion().hasBitwiseShifting() && !c_valueSigned) - m_context << Instruction::SHR; + if (m_context.evmVersion().hasBitwiseShifting()) + m_context << (c_valueSigned ? Instruction::SAR : Instruction::SHR); else - m_context << u256(2) << Instruction::EXP << Instruction::SWAP1 << (c_valueSigned ? Instruction::SDIV : Instruction::DIV); + { + if (c_valueSigned) + // In the following assembly snippet, xor_mask will be zero, if value_to_shift is positive. + // Therefore xor'ing with xor_mask is the identity and the computation reduces to + // div(value_to_shift, exp(2, shift_amount)), which is correct, since for positive values + // arithmetic right shift is dividing by a power of two (which, as a bitwise operation, results + // in discarding bits on the right and filling with zeros from the left). + // For negative values arithmetic right shift, viewed as a bitwise operation, discards bits to the + // right and fills in ones from the left. This is achieved as follows: + // If value_to_shift is negative, then xor_mask will have all bits set, so xor'ing with xor_mask + // will flip all bits. First all bits in value_to_shift are flipped. As for the positive case, + // dividing by a power of two using integer arithmetic results in discarding bits to the right + // and filling with zeros from the left. Flipping all bits in the result again, turns all zeros + // on the left to ones and restores the non-discarded, shifted bits to their original value (they + // have now been flipped twice). In summary we now have discarded bits to the right and filled with + // ones from the left, i.e. we have performed an arithmetic right shift. + m_context.appendInlineAssembly(R"({ + let xor_mask := sub(0, slt(value_to_shift, 0)) + value_to_shift := xor(div(xor(value_to_shift, xor_mask), exp(2, shift_amount)), xor_mask) + })", {"value_to_shift", "shift_amount"}); + else + m_context.appendInlineAssembly(R"({ + value_to_shift := div(value_to_shift, exp(2, shift_amount)) + })", {"value_to_shift", "shift_amount"}); + m_context << Instruction::POP; + + } break; case Token::SHR: default: @@ -1766,10 +1818,7 @@ void ExpressionCompiler::appendExternalFunctionCall( bool returnSuccessCondition = funKind == FunctionType::Kind::BareCall || funKind == FunctionType::Kind::BareCallCode || funKind == FunctionType::Kind::BareDelegateCall; bool isCallCode = funKind == FunctionType::Kind::BareCallCode || funKind == FunctionType::Kind::CallCode; bool isDelegateCall = funKind == FunctionType::Kind::BareDelegateCall || funKind == FunctionType::Kind::DelegateCall; - bool useStaticCall = - _functionType.stateMutability() <= StateMutability::View && - m_context.experimentalFeatureActive(ExperimentalFeature::V050) && - m_context.evmVersion().hasStaticCall(); + bool useStaticCall = _functionType.stateMutability() <= StateMutability::View && m_context.evmVersion().hasStaticCall(); bool haveReturndatacopy = m_context.evmVersion().supportsReturndata(); unsigned retSize = 0; @@ -1796,38 +1845,12 @@ void ExpressionCompiler::appendExternalFunctionCall( // Evaluate arguments. TypePointers argumentTypes; TypePointers parameterTypes = _functionType.parameterTypes(); - bool manualFunctionId = false; - if ( - (funKind == FunctionType::Kind::BareCall || funKind == FunctionType::Kind::BareCallCode || funKind == FunctionType::Kind::BareDelegateCall) && - !_arguments.empty() - ) - { - solAssert(_arguments.front()->annotation().type->mobileType(), ""); - manualFunctionId = - _arguments.front()->annotation().type->mobileType()->calldataEncodedSize(false) == - CompilerUtils::dataStartOffset; - } - if (manualFunctionId) - { - // If we have a Bare* and the first type has exactly 4 bytes, use it as - // function identifier. - _arguments.front()->accept(*this); - utils().convertType( - *_arguments.front()->annotation().type, - IntegerType(8 * CompilerUtils::dataStartOffset), - true - ); - for (unsigned i = 0; i < gasValueSize; ++i) - m_context << swapInstruction(gasValueSize - i); - gasStackPos++; - valueStackPos++; - } if (_functionType.bound()) { argumentTypes.push_back(_functionType.selfType()); parameterTypes.insert(parameterTypes.begin(), _functionType.selfType()); } - for (size_t i = manualFunctionId ? 1 : 0; i < _arguments.size(); ++i) + for (size_t i = 0; i < _arguments.size(); ++i) { _arguments[i]->accept(*this); argumentTypes.push_back(_arguments[i]->annotation().type); @@ -1856,26 +1879,27 @@ void ExpressionCompiler::appendExternalFunctionCall( { m_context << u256(0); utils().fetchFreeMemoryPointer(); - // This touches too much, but that way we save some rounding arithmetics + // This touches too much, but that way we save some rounding arithmetic m_context << u256(retSize) << Instruction::ADD << Instruction::MSTORE; } } // Copy function identifier to memory. utils().fetchFreeMemoryPointer(); - if (!_functionType.isBareCall() || manualFunctionId) + if (!_functionType.isBareCall()) { m_context << dupInstruction(2 + gasValueSize + CompilerUtils::sizeOnStack(argumentTypes)); utils().storeInMemoryDynamic(IntegerType(8 * CompilerUtils::dataStartOffset), false); } - // If the function takes arbitrary parameters, copy dynamic length data in place. + + // If the function takes arbitrary parameters or is a bare call, copy dynamic length data in place. // Move arguments to memory, will not update the free memory pointer (but will update the memory // pointer on the stack). utils().encodeToMemory( argumentTypes, parameterTypes, _functionType.padArguments(), - _functionType.takesArbitraryParameters(), + _functionType.takesArbitraryParameters() || _functionType.isBareCall(), isCallCode || isDelegateCall ); @@ -1956,9 +1980,9 @@ void ExpressionCompiler::appendExternalFunctionCall( unsigned remainsSize = 2 + // contract address, input_memory_end - _functionType.valueSet() + - _functionType.gasSet() + - (!_functionType.isBareCall() || manualFunctionId); + (_functionType.valueSet() ? 1 : 0) + + (_functionType.gasSet() ? 1 : 0) + + (!_functionType.isBareCall() ? 1 : 0); if (returnSuccessCondition) m_context << swapInstruction(remainsSize); @@ -2025,7 +2049,7 @@ void ExpressionCompiler::appendExternalFunctionCall( mstore(0x40, newMem) })", {"start", "size"}); - utils().abiDecode(returnTypes, true, true); + utils().abiDecode(returnTypes, true); } } diff --git a/libsolidity/formal/SMTChecker.cpp b/libsolidity/formal/SMTChecker.cpp index 8639317b..e2a51267 100644 --- a/libsolidity/formal/SMTChecker.cpp +++ b/libsolidity/formal/SMTChecker.cpp @@ -68,7 +68,7 @@ bool SMTChecker::visit(ContractDefinition const& _contract) void SMTChecker::endVisit(ContractDefinition const&) { - m_stateVariables.clear(); + m_variables.clear(); } void SMTChecker::endVisit(VariableDeclaration const& _varDecl) @@ -86,20 +86,19 @@ bool SMTChecker::visit(FunctionDefinition const& _function) ); m_currentFunction = &_function; m_interface->reset(); - m_variables.clear(); - m_variables.insert(m_stateVariables.begin(), m_stateVariables.end()); m_pathConditions.clear(); m_loopExecutionHappened = false; - initializeLocalVariables(_function); resetStateVariables(); + initializeLocalVariables(_function); return true; } void SMTChecker::endVisit(FunctionDefinition const&) { - // TOOD we could check for "reachability", i.e. satisfiability here. + // TODO we could check for "reachability", i.e. satisfiability here. // We only handle local variables, so we clear at the beginning of the function. // If we add storage variables, those should be cleared differently. + removeLocalVariables(); m_currentFunction = nullptr; } @@ -110,7 +109,7 @@ bool SMTChecker::visit(IfStatement const& _node) checkBooleanNotConstant(_node.condition(), "Condition is always $VALUE."); auto countersEndTrue = visitBranch(_node.trueStatement(), expr(_node.condition())); - vector<Declaration const*> touchedVariables = m_variableUsage->touchedVariables(_node.trueStatement()); + vector<VariableDeclaration const*> touchedVariables = m_variableUsage->touchedVariables(_node.trueStatement()); decltype(countersEndTrue) countersEndFalse; if (_node.falseStatement()) { @@ -230,10 +229,10 @@ void SMTChecker::endVisit(Assignment const& _assignment) ); else if (Identifier const* identifier = dynamic_cast<Identifier const*>(&_assignment.leftHandSide())) { - Declaration const* decl = identifier->annotation().referencedDeclaration; - if (knownVariable(*decl)) + VariableDeclaration const& decl = dynamic_cast<VariableDeclaration const&>(*identifier->annotation().referencedDeclaration); + if (knownVariable(decl)) { - assignment(*decl, _assignment.rightHandSide(), _assignment.location()); + assignment(decl, _assignment.rightHandSide(), _assignment.location()); defineExpr(_assignment, expr(_assignment.rightHandSide())); } else @@ -296,12 +295,12 @@ void SMTChecker::endVisit(UnaryOperation const& _op) solAssert(_op.subExpression().annotation().lValueRequested, ""); if (Identifier const* identifier = dynamic_cast<Identifier const*>(&_op.subExpression())) { - Declaration const* decl = identifier->annotation().referencedDeclaration; - if (knownVariable(*decl)) + VariableDeclaration const& decl = dynamic_cast<VariableDeclaration const&>(*identifier->annotation().referencedDeclaration); + if (knownVariable(decl)) { - auto innerValue = currentValue(*decl); + auto innerValue = currentValue(decl); auto newValue = _op.getOperator() == Token::Inc ? innerValue + 1 : innerValue - 1; - assignment(*decl, newValue, _op.location()); + assignment(decl, newValue, _op.location()); defineExpr(_op, _op.isPrefixOperation() ? newValue : innerValue); } else @@ -383,14 +382,15 @@ void SMTChecker::endVisit(FunctionCall const& _funCall) void SMTChecker::endVisit(Identifier const& _identifier) { - Declaration const* decl = _identifier.annotation().referencedDeclaration; - solAssert(decl, ""); if (_identifier.annotation().lValueRequested) { // Will be translated as part of the node that requested the lvalue. } else if (SSAVariable::isSupportedType(_identifier.annotation().type->category())) - defineExpr(_identifier, currentValue(*decl)); + { + VariableDeclaration const& decl = dynamic_cast<VariableDeclaration const&>(*(_identifier.annotation().referencedDeclaration)); + defineExpr(_identifier, currentValue(decl)); + } else if (FunctionType const* fun = dynamic_cast<FunctionType const*>(_identifier.annotation().type.get())) { if (fun->kind() == FunctionType::Kind::Assert || fun->kind() == FunctionType::Kind::Require) @@ -530,12 +530,12 @@ smt::Expression SMTChecker::division(smt::Expression _left, smt::Expression _rig return _left / _right; } -void SMTChecker::assignment(Declaration const& _variable, Expression const& _value, SourceLocation const& _location) +void SMTChecker::assignment(VariableDeclaration const& _variable, Expression const& _value, SourceLocation const& _location) { assignment(_variable, expr(_value), _location); } -void SMTChecker::assignment(Declaration const& _variable, smt::Expression const& _value, SourceLocation const& _location) +void SMTChecker::assignment(VariableDeclaration const& _variable, smt::Expression const& _value, SourceLocation const& _location) { TypePointer type = _variable.type(); if (auto const* intType = dynamic_cast<IntegerType const*>(type.get())) @@ -583,19 +583,7 @@ void SMTChecker::checkCondition( expressionsToEvaluate.emplace_back(*_additionalValue); expressionNames.push_back(_additionalValueName); } - for (auto const& param: m_currentFunction->parameters()) - if (knownVariable(*param)) - { - expressionsToEvaluate.emplace_back(currentValue(*param)); - expressionNames.push_back(param->name()); - } - for (auto const& var: m_currentFunction->localVariables()) - if (knownVariable(*var)) - { - expressionsToEvaluate.emplace_back(currentValue(*var)); - expressionNames.push_back(var->name()); - } - for (auto const& var: m_stateVariables) + for (auto const& var: m_variables) if (knownVariable(*var.first)) { expressionsToEvaluate.emplace_back(currentValue(*var.first)); @@ -740,14 +728,17 @@ void SMTChecker::initializeLocalVariables(FunctionDefinition const& _function) void SMTChecker::resetStateVariables() { - for (auto const& variable: m_stateVariables) + for (auto const& variable: m_variables) { - newValue(*variable.first); - setUnknownValue(*variable.first); + if (variable.first->isStateVariable()) + { + newValue(*variable.first); + setUnknownValue(*variable.first); + } } } -void SMTChecker::resetVariables(vector<Declaration const*> _variables) +void SMTChecker::resetVariables(vector<VariableDeclaration const*> _variables) { for (auto const* decl: _variables) { @@ -756,9 +747,9 @@ void SMTChecker::resetVariables(vector<Declaration const*> _variables) } } -void SMTChecker::mergeVariables(vector<Declaration const*> const& _variables, smt::Expression const& _condition, VariableSequenceCounters const& _countersEndTrue, VariableSequenceCounters const& _countersEndFalse) +void SMTChecker::mergeVariables(vector<VariableDeclaration const*> const& _variables, smt::Expression const& _condition, VariableSequenceCounters const& _countersEndTrue, VariableSequenceCounters const& _countersEndFalse) { - set<Declaration const*> uniqueVars(_variables.begin(), _variables.end()); + set<VariableDeclaration const*> uniqueVars(_variables.begin(), _variables.end()); for (auto const* decl: uniqueVars) { int trueCounter = _countersEndTrue.at(decl).index(); @@ -777,14 +768,7 @@ bool SMTChecker::createVariable(VariableDeclaration const& _varDecl) if (SSAVariable::isSupportedType(_varDecl.type()->category())) { solAssert(m_variables.count(&_varDecl) == 0, ""); - solAssert(m_stateVariables.count(&_varDecl) == 0, ""); - if (_varDecl.isLocalVariable()) - m_variables.emplace(&_varDecl, SSAVariable(_varDecl, *m_interface)); - else - { - solAssert(_varDecl.isStateVariable(), ""); - m_stateVariables.emplace(&_varDecl, SSAVariable(_varDecl, *m_interface)); - } + m_variables.emplace(&_varDecl, SSAVariable(_varDecl, *m_interface)); return true; } else @@ -802,37 +786,37 @@ string SMTChecker::uniqueSymbol(Expression const& _expr) return "expr_" + to_string(_expr.id()); } -bool SMTChecker::knownVariable(Declaration const& _decl) +bool SMTChecker::knownVariable(VariableDeclaration const& _decl) { return m_variables.count(&_decl); } -smt::Expression SMTChecker::currentValue(Declaration const& _decl) +smt::Expression SMTChecker::currentValue(VariableDeclaration const& _decl) { solAssert(knownVariable(_decl), ""); return m_variables.at(&_decl)(); } -smt::Expression SMTChecker::valueAtSequence(Declaration const& _decl, int _sequence) +smt::Expression SMTChecker::valueAtSequence(VariableDeclaration const& _decl, int _sequence) { solAssert(knownVariable(_decl), ""); return m_variables.at(&_decl)(_sequence); } -smt::Expression SMTChecker::newValue(Declaration const& _decl) +smt::Expression SMTChecker::newValue(VariableDeclaration const& _decl) { solAssert(knownVariable(_decl), ""); ++m_variables.at(&_decl); return m_variables.at(&_decl)(); } -void SMTChecker::setZeroValue(Declaration const& _decl) +void SMTChecker::setZeroValue(VariableDeclaration const& _decl) { solAssert(knownVariable(_decl), ""); m_variables.at(&_decl).setZeroValue(); } -void SMTChecker::setUnknownValue(Declaration const& _decl) +void SMTChecker::setUnknownValue(VariableDeclaration const& _decl) { solAssert(knownVariable(_decl), ""); m_variables.at(&_decl).setUnknownValue(); @@ -909,3 +893,14 @@ void SMTChecker::addPathImpliedExpression(smt::Expression const& _e) { m_interface->addAssertion(smt::Expression::implies(currentPathConditions(), _e)); } + +void SMTChecker::removeLocalVariables() +{ + for (auto it = m_variables.begin(); it != m_variables.end(); ) + { + if (it->first->isLocalVariable()) + it = m_variables.erase(it); + else + ++it; + } +} diff --git a/libsolidity/formal/SMTChecker.h b/libsolidity/formal/SMTChecker.h index 50d40ab9..6cf4e48a 100644 --- a/libsolidity/formal/SMTChecker.h +++ b/libsolidity/formal/SMTChecker.h @@ -76,11 +76,11 @@ private: /// of rounding for signed division. smt::Expression division(smt::Expression _left, smt::Expression _right, IntegerType const& _type); - void assignment(Declaration const& _variable, Expression const& _value, SourceLocation const& _location); - void assignment(Declaration const& _variable, smt::Expression const& _value, SourceLocation const& _location); + void assignment(VariableDeclaration const& _variable, Expression const& _value, SourceLocation const& _location); + void assignment(VariableDeclaration const& _variable, smt::Expression const& _value, SourceLocation const& _location); /// Maps a variable to an SSA index. - using VariableSequenceCounters = std::map<Declaration const*, SSAVariable>; + using VariableSequenceCounters = std::map<VariableDeclaration const*, SSAVariable>; /// Visits the branch given by the statement, pushes and pops the current path conditions. /// @param _condition if present, asserts that this condition is true within the branch. @@ -114,11 +114,11 @@ private: void initializeLocalVariables(FunctionDefinition const& _function); void resetStateVariables(); - void resetVariables(std::vector<Declaration const*> _variables); + void resetVariables(std::vector<VariableDeclaration const*> _variables); /// Given two different branches and the touched variables, /// merge the touched variables into after-branch ite variables /// using the branch condition as guard. - void mergeVariables(std::vector<Declaration const*> const& _variables, smt::Expression const& _condition, VariableSequenceCounters const& _countersEndTrue, VariableSequenceCounters const& _countersEndFalse); + void mergeVariables(std::vector<VariableDeclaration const*> const& _variables, smt::Expression const& _condition, VariableSequenceCounters const& _countersEndTrue, VariableSequenceCounters const& _countersEndFalse); /// Tries to create an uninitialized variable and returns true on success. /// This fails if the type is not supported. bool createVariable(VariableDeclaration const& _varDecl); @@ -127,21 +127,21 @@ private: /// @returns true if _delc is a variable that is known at the current point, i.e. /// has a valid sequence number - bool knownVariable(Declaration const& _decl); + bool knownVariable(VariableDeclaration const& _decl); /// @returns an expression denoting the value of the variable declared in @a _decl /// at the current point. - smt::Expression currentValue(Declaration const& _decl); + smt::Expression currentValue(VariableDeclaration const& _decl); /// @returns an expression denoting the value of the variable declared in @a _decl /// at the given sequence point. Does not ensure that this sequence point exists. - smt::Expression valueAtSequence(Declaration const& _decl, int _sequence); + smt::Expression valueAtSequence(VariableDeclaration const& _decl, int _sequence); /// Allocates a new sequence number for the declaration, updates the current /// sequence number to this value and returns the expression. - smt::Expression newValue(Declaration const& _decl); + smt::Expression newValue(VariableDeclaration const& _decl); /// Sets the value of the declaration to zero. - void setZeroValue(Declaration const& _decl); + void setZeroValue(VariableDeclaration const& _decl); /// Resets the variable to an unknown value (in its range). - void setUnknownValue(Declaration const& decl); + void setUnknownValue(VariableDeclaration const& decl); /// Returns the expression corresponding to the AST node. Throws if the expression does not exist. smt::Expression expr(Expression const& _e); @@ -161,12 +161,14 @@ private: /// Add to the solver: the given expression implied by the current path conditions void addPathImpliedExpression(smt::Expression const& _e); + /// Removes the local variables of a function. + void removeLocalVariables(); + std::shared_ptr<smt::SolverInterface> m_interface; std::shared_ptr<VariableUsage> m_variableUsage; bool m_loopExecutionHappened = false; std::map<Expression const*, smt::Expression> m_expressions; - std::map<Declaration const*, SSAVariable> m_variables; - std::map<Declaration const*, SSAVariable> m_stateVariables; + std::map<VariableDeclaration const*, SSAVariable> m_variables; std::vector<smt::Expression> m_pathConditions; ErrorReporter& m_errorReporter; diff --git a/libsolidity/formal/VariableUsage.cpp b/libsolidity/formal/VariableUsage.cpp index c2dea844..9282a560 100644 --- a/libsolidity/formal/VariableUsage.cpp +++ b/libsolidity/formal/VariableUsage.cpp @@ -50,12 +50,12 @@ VariableUsage::VariableUsage(ASTNode const& _node) _node.accept(reducer); } -vector<Declaration const*> VariableUsage::touchedVariables(ASTNode const& _node) const +vector<VariableDeclaration const*> VariableUsage::touchedVariables(ASTNode const& _node) const { if (!m_children.count(&_node) && !m_touchedVariable.count(&_node)) return {}; - set<Declaration const*> touched; + set<VariableDeclaration const*> touched; vector<ASTNode const*> toVisit; toVisit.push_back(&_node); diff --git a/libsolidity/formal/VariableUsage.h b/libsolidity/formal/VariableUsage.h index 62561cce..dda13de2 100644 --- a/libsolidity/formal/VariableUsage.h +++ b/libsolidity/formal/VariableUsage.h @@ -27,7 +27,7 @@ namespace solidity { class ASTNode; -class Declaration; +class VariableDeclaration; /** * This class collects information about which local variables of value type @@ -38,11 +38,11 @@ class VariableUsage public: explicit VariableUsage(ASTNode const& _node); - std::vector<Declaration const*> touchedVariables(ASTNode const& _node) const; + std::vector<VariableDeclaration const*> touchedVariables(ASTNode const& _node) const; private: // Variable touched by a specific AST node. - std::map<ASTNode const*, Declaration const*> m_touchedVariable; + std::map<ASTNode const*, VariableDeclaration const*> m_touchedVariable; std::map<ASTNode const*, std::vector<ASTNode const*>> m_children; }; diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index 9f505889..d5580dd2 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -99,7 +99,7 @@ bool AsmAnalyzer::operator()(assembly::Literal const& _literal) } else if (_literal.kind == assembly::LiteralKind::Boolean) { - solAssert(m_flavour == AsmFlavour::IULIA, ""); + solAssert(m_flavour == AsmFlavour::Yul, ""); solAssert(_literal.value == "true" || _literal.value == "false", ""); } m_info.stackHeightInfo[&_literal] = m_stackHeight; @@ -162,7 +162,7 @@ bool AsmAnalyzer::operator()(assembly::Identifier const& _identifier) bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr) { - solAssert(m_flavour != AsmFlavour::IULIA, ""); + solAssert(m_flavour != AsmFlavour::Yul, ""); bool success = true; for (auto const& arg: _instr.arguments | boost::adaptors::reversed) if (!expectExpression(arg)) @@ -550,7 +550,7 @@ Scope& AsmAnalyzer::scope(Block const* _block) } void AsmAnalyzer::expectValidType(string const& type, SourceLocation const& _location) { - if (m_flavour != AsmFlavour::IULIA) + if (m_flavour != AsmFlavour::Yul) return; if (!builtinTypes.count(type)) diff --git a/libsolidity/inlineasm/AsmDataForward.h b/libsolidity/inlineasm/AsmDataForward.h index 3a9600fe..69cf8f1d 100644 --- a/libsolidity/inlineasm/AsmDataForward.h +++ b/libsolidity/inlineasm/AsmDataForward.h @@ -17,7 +17,7 @@ /** * @author Christian <c@ethdev.com> * @date 2016 - * Forward declaration of classes for inline assembly / JULIA AST + * Forward declaration of classes for inline assembly / Yul AST */ #pragma once @@ -57,7 +57,7 @@ enum class AsmFlavour { Loose, // no types, EVM instructions as function, jumps and direct stack manipulations Strict, // no types, EVM instructions as functions, but no jumps and no direct stack manipulations - IULIA // same as Strict mode with types + Yul // same as Strict mode with types }; } diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp index d300f8fb..cd429a98 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libsolidity/inlineasm/AsmParser.cpp @@ -150,7 +150,7 @@ assembly::Statement Parser::parseStatement() expectToken(Token::Comma); elementary = parseElementaryOperation(); if (elementary.type() != typeid(assembly::Identifier)) - fatalParserError("Variable name expected in multiple assignemnt."); + fatalParserError("Variable name expected in multiple assignment."); assignment.variableNames.emplace_back(boost::get<assembly::Identifier>(elementary)); } while (currentToken() == Token::Comma); @@ -173,7 +173,7 @@ assembly::Statement Parser::parseStatement() if (currentToken() == Token::Assign && peekNextToken() != Token::Colon) { assembly::Assignment assignment = createWithLocation<assembly::Assignment>(identifier.location); - if (m_flavour != AsmFlavour::IULIA && instructions().count(identifier.name)) + if (m_flavour != AsmFlavour::Yul && instructions().count(identifier.name)) fatalParserError("Cannot use instruction names for identifier names."); advance(); assignment.variableNames.emplace_back(identifier); @@ -318,11 +318,6 @@ std::map<string, dev::solidity::Instruction> const& Parser::instructions() transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); }); s_instructions[name] = instruction.second; } - - // add alias for suicide - s_instructions["suicide"] = solidity::Instruction::SELFDESTRUCT; - // add alis for sha3 - s_instructions["sha3"] = solidity::Instruction::KECCAK256; } return s_instructions; } @@ -362,7 +357,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation() else literal = currentLiteral(); // first search the set of instructions. - if (m_flavour != AsmFlavour::IULIA && instructions().count(literal)) + if (m_flavour != AsmFlavour::Yul && instructions().count(literal)) { dev::solidity::Instruction const& instr = instructions().at(literal); ret = Instruction{location(), instr}; @@ -403,7 +398,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation() "" }; advance(); - if (m_flavour == AsmFlavour::IULIA) + if (m_flavour == AsmFlavour::Yul) { expectToken(Token::Colon); literal.location.end = endPosition(); @@ -416,7 +411,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation() } default: fatalParserError( - m_flavour == AsmFlavour::IULIA ? + m_flavour == AsmFlavour::Yul ? "Literal or identifier expected." : "Literal, identifier or instruction expected." ); @@ -486,7 +481,7 @@ assembly::Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) RecursionGuard recursionGuard(*this); if (_initialOp.type() == typeid(Instruction)) { - solAssert(m_flavour != AsmFlavour::IULIA, "Instructions are invalid in JULIA"); + solAssert(m_flavour != AsmFlavour::Yul, "Instructions are invalid in Yul"); Instruction& instruction = boost::get<Instruction>(_initialOp); FunctionalInstruction ret; ret.instruction = instruction.instruction; @@ -557,7 +552,7 @@ assembly::Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) } else fatalParserError( - m_flavour == AsmFlavour::IULIA ? + m_flavour == AsmFlavour::Yul ? "Function name expected." : "Assembly instruction or function name required in front of \"(\")" ); @@ -570,7 +565,7 @@ TypedName Parser::parseTypedName() RecursionGuard recursionGuard(*this); TypedName typedName = createWithLocation<TypedName>(); typedName.name = expectAsmIdentifier(); - if (m_flavour == AsmFlavour::IULIA) + if (m_flavour == AsmFlavour::Yul) { expectToken(Token::Colon); typedName.location.end = endPosition(); @@ -582,7 +577,7 @@ TypedName Parser::parseTypedName() string Parser::expectAsmIdentifier() { string name = currentLiteral(); - if (m_flavour == AsmFlavour::IULIA) + if (m_flavour == AsmFlavour::Yul) { switch (currentToken()) { diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp index bacd7a94..1a15d7eb 100644 --- a/libsolidity/inlineasm/AsmPrinter.cpp +++ b/libsolidity/inlineasm/AsmPrinter.cpp @@ -40,7 +40,7 @@ using namespace dev::solidity::assembly; string AsmPrinter::operator()(assembly::Instruction const& _instruction) { - solAssert(!m_julia, ""); + solAssert(!m_yul, ""); return boost::to_lower_copy(instructionInfo(_instruction.instruction).name); } @@ -92,7 +92,7 @@ string AsmPrinter::operator()(assembly::Identifier const& _identifier) string AsmPrinter::operator()(assembly::FunctionalInstruction const& _functionalInstruction) { - solAssert(!m_julia, ""); + solAssert(!m_yul, ""); return boost::to_lower_copy(instructionInfo(_functionalInstruction.instruction).name) + "(" + @@ -109,13 +109,13 @@ string AsmPrinter::operator()(ExpressionStatement const& _statement) string AsmPrinter::operator()(assembly::Label const& _label) { - solAssert(!m_julia, ""); + solAssert(!m_yul, ""); return _label.name + ":"; } string AsmPrinter::operator()(assembly::StackAssignment const& _assignment) { - solAssert(!m_julia, ""); + solAssert(!m_yul, ""); return "=: " + (*this)(_assignment.variableName); } @@ -225,7 +225,7 @@ string AsmPrinter::operator()(Block const& _block) string AsmPrinter::appendTypeName(std::string const& _type) const { - if (m_julia) + if (m_yul) return ":" + _type; return ""; } diff --git a/libsolidity/inlineasm/AsmPrinter.h b/libsolidity/inlineasm/AsmPrinter.h index 5bd87aba..9f2b842a 100644 --- a/libsolidity/inlineasm/AsmPrinter.h +++ b/libsolidity/inlineasm/AsmPrinter.h @@ -36,7 +36,7 @@ namespace assembly class AsmPrinter: public boost::static_visitor<std::string> { public: - explicit AsmPrinter(bool _julia = false): m_julia(_julia) {} + explicit AsmPrinter(bool _yul = false): m_yul(_yul) {} std::string operator()(assembly::Instruction const& _instruction); std::string operator()(assembly::Literal const& _literal); @@ -57,7 +57,7 @@ public: private: std::string appendTypeName(std::string const& _type) const; - bool m_julia = false; + bool m_yul = false; }; } diff --git a/libsolidity/inlineasm/AsmScope.cpp b/libsolidity/inlineasm/AsmScope.cpp index 64d5bd9a..af81b301 100644 --- a/libsolidity/inlineasm/AsmScope.cpp +++ b/libsolidity/inlineasm/AsmScope.cpp @@ -32,7 +32,7 @@ bool Scope::registerLabel(string const& _name) return true; } -bool Scope::registerVariable(string const& _name, JuliaType const& _type) +bool Scope::registerVariable(string const& _name, YulType const& _type) { if (exists(_name)) return false; @@ -42,7 +42,7 @@ bool Scope::registerVariable(string const& _name, JuliaType const& _type) return true; } -bool Scope::registerFunction(string const& _name, std::vector<JuliaType> const& _arguments, std::vector<JuliaType> const& _returns) +bool Scope::registerFunction(string const& _name, std::vector<YulType> const& _arguments, std::vector<YulType> const& _returns) { if (exists(_name)) return false; diff --git a/libsolidity/inlineasm/AsmScope.h b/libsolidity/inlineasm/AsmScope.h index 447d6490..c8c63f8f 100644 --- a/libsolidity/inlineasm/AsmScope.h +++ b/libsolidity/inlineasm/AsmScope.h @@ -62,27 +62,27 @@ struct GenericVisitor<>: public boost::static_visitor<> { struct Scope { - using JuliaType = std::string; + using YulType = std::string; using LabelID = size_t; - struct Variable { JuliaType type; }; + struct Variable { YulType type; }; struct Label { }; struct Function { - std::vector<JuliaType> arguments; - std::vector<JuliaType> returns; + std::vector<YulType> arguments; + std::vector<YulType> returns; }; using Identifier = boost::variant<Variable, Label, Function>; using Visitor = GenericVisitor<Variable const, Label const, Function const>; using NonconstVisitor = GenericVisitor<Variable, Label, Function>; - bool registerVariable(std::string const& _name, JuliaType const& _type); + bool registerVariable(std::string const& _name, YulType const& _type); bool registerLabel(std::string const& _name); bool registerFunction( std::string const& _name, - std::vector<JuliaType> const& _arguments, - std::vector<JuliaType> const& _returns + std::vector<YulType> const& _arguments, + std::vector<YulType> const& _returns ); /// Looks up the identifier in this or super scopes and returns a valid pointer if found diff --git a/libsolidity/inlineasm/AsmScopeFiller.cpp b/libsolidity/inlineasm/AsmScopeFiller.cpp index 86f3809c..2d15c820 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.cpp +++ b/libsolidity/inlineasm/AsmScopeFiller.cpp @@ -75,10 +75,10 @@ bool ScopeFiller::operator()(assembly::VariableDeclaration const& _varDecl) bool ScopeFiller::operator()(assembly::FunctionDefinition const& _funDef) { bool success = true; - vector<Scope::JuliaType> arguments; + vector<Scope::YulType> arguments; for (auto const& _argument: _funDef.parameters) arguments.push_back(_argument.type); - vector<Scope::JuliaType> returns; + vector<Scope::YulType> returns; for (auto const& _return: _funDef.returnVariables) returns.push_back(_return.type); if (!m_currentScope->registerFunction(_funDef.name, arguments, returns)) diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp index 7f97336b..46fa1d6b 100644 --- a/libsolidity/interface/AssemblyStack.cpp +++ b/libsolidity/interface/AssemblyStack.cpp @@ -15,7 +15,7 @@ along with solidity. If not, see <http://www.gnu.org/licenses/>. */ /** - * Full assembly stack that can support EVM-assembly and JULIA as input and EVM, EVM1.5 and + * Full assembly stack that can support EVM-assembly and Yul as input and EVM, EVM1.5 and * eWasm as output. */ @@ -48,11 +48,11 @@ assembly::AsmFlavour languageToAsmFlavour(AssemblyStack::Language _language) return assembly::AsmFlavour::Loose; case AssemblyStack::Language::StrictAssembly: return assembly::AsmFlavour::Strict; - case AssemblyStack::Language::JULIA: - return assembly::AsmFlavour::IULIA; + case AssemblyStack::Language::Yul: + return assembly::AsmFlavour::Yul; } solAssert(false, ""); - return assembly::AsmFlavour::IULIA; + return assembly::AsmFlavour::Yul; } } @@ -117,9 +117,9 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const { MachineAssemblyObject object; julia::EVMAssembly assembly(true); - julia::CodeTransform(assembly, *m_analysisInfo, m_language == Language::JULIA, true)(*m_parserResult); + julia::CodeTransform(assembly, *m_analysisInfo, m_language == Language::Yul, true)(*m_parserResult); object.bytecode = make_shared<eth::LinkerObject>(assembly.finalize()); - /// TOOD: fill out text representation + /// TODO: fill out text representation return object; } case Machine::eWasm: @@ -132,5 +132,5 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const string AssemblyStack::print() const { solAssert(m_parserResult, ""); - return assembly::AsmPrinter(m_language == Language::JULIA)(*m_parserResult); + return assembly::AsmPrinter(m_language == Language::Yul)(*m_parserResult); } diff --git a/libsolidity/interface/AssemblyStack.h b/libsolidity/interface/AssemblyStack.h index 720220ab..8132ce63 100644 --- a/libsolidity/interface/AssemblyStack.h +++ b/libsolidity/interface/AssemblyStack.h @@ -15,7 +15,7 @@ along with solidity. If not, see <http://www.gnu.org/licenses/>. */ /** - * Full assembly stack that can support EVM-assembly and JULIA as input and EVM, EVM1.5 and + * Full assembly stack that can support EVM-assembly and Yul as input and EVM, EVM1.5 and * eWasm as output. */ @@ -47,13 +47,13 @@ struct MachineAssemblyObject }; /* - * Full assembly stack that can support EVM-assembly and JULIA as input and EVM, EVM1.5 and + * Full assembly stack that can support EVM-assembly and Yul as input and EVM, EVM1.5 and * eWasm as output. */ class AssemblyStack { public: - enum class Language { JULIA, Assembly, StrictAssembly }; + enum class Language { Yul, Assembly, StrictAssembly }; enum class Machine { EVM, EVM15, eWasm }; explicit AssemblyStack(EVMVersion _evmVersion = EVMVersion(), Language _language = Language::Assembly): diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 47dc30cf..aa33bad8 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -669,7 +669,7 @@ void CompilerStack::resolveImports() swap(m_sourceOrder, sourceOrder); } -string CompilerStack::absolutePath(string const& _path, string const& _reference) const +string CompilerStack::absolutePath(string const& _path, string const& _reference) { using path = boost::filesystem::path; path p(_path); @@ -711,39 +711,33 @@ void CompilerStack::compileContract( for (auto const* dependency: _contract.annotation().contractDependencies) compileContract(*dependency, _compiledContracts); - shared_ptr<Compiler> compiler = make_shared<Compiler>(m_evmVersion, m_optimize, m_optimizeRuns); Contract& compiledContract = m_contracts.at(_contract.fullyQualifiedName()); - string metadata = createMetadata(compiledContract); - bytes cborEncodedHash = - // CBOR-encoding of the key "bzzr0" - bytes{0x65, 'b', 'z', 'z', 'r', '0'}+ - // CBOR-encoding of the hash - bytes{0x58, 0x20} + dev::swarmHash(metadata).asBytes(); - bytes cborEncodedMetadata; - if (onlySafeExperimentalFeaturesActivated(_contract.sourceUnit().annotation().experimentalFeatures)) - cborEncodedMetadata = - // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata)} - bytes{0xa1} + - cborEncodedHash; - else - cborEncodedMetadata = - // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata), "experimental": true} - bytes{0xa2} + - cborEncodedHash + - bytes{0x6c, 'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l', 0xf5}; - solAssert(cborEncodedMetadata.size() <= 0xffff, "Metadata too large"); - // 16-bit big endian length - cborEncodedMetadata += toCompactBigEndian(cborEncodedMetadata.size(), 2); - compiler->compileContract(_contract, _compiledContracts, cborEncodedMetadata); + + shared_ptr<Compiler> compiler = make_shared<Compiler>(m_evmVersion, m_optimize, m_optimizeRuns); compiledContract.compiler = compiler; + string metadata = createMetadata(compiledContract); + compiledContract.metadata = metadata; + + bytes cborEncodedMetadata = createCBORMetadata( + metadata, + !onlySafeExperimentalFeaturesActivated(_contract.sourceUnit().annotation().experimentalFeatures) + ); + try { - compiledContract.object = compiler->assembledObject(); + // Run optimiser and compile the contract. + compiler->compileContract(_contract, _compiledContracts, cborEncodedMetadata); } catch(eth::OptimizerException const&) { - solAssert(false, "Assembly optimizer exception for bytecode"); + solAssert(false, "Optimizer exception during compilation"); + } + + try + { + // Assemble deployment (incl. runtime) object. + compiledContract.object = compiler->assembledObject(); } catch(eth::AssemblyException const&) { @@ -752,18 +746,14 @@ void CompilerStack::compileContract( try { + // Assemble runtime object. compiledContract.runtimeObject = compiler->runtimeObject(); } - catch(eth::OptimizerException const&) - { - solAssert(false, "Assembly optimizer exception for deployed bytecode"); - } catch(eth::AssemblyException const&) { solAssert(false, "Assembly exception for deployed bytecode"); } - compiledContract.metadata = metadata; _compiledContracts[compiledContract.contract] = &compiler->assembly(); try @@ -894,6 +884,31 @@ string CompilerStack::createMetadata(Contract const& _contract) const return jsonCompactPrint(meta); } +bytes CompilerStack::createCBORMetadata(string _metadata, bool _experimentalMode) +{ + bytes cborEncodedHash = + // CBOR-encoding of the key "bzzr0" + bytes{0x65, 'b', 'z', 'z', 'r', '0'}+ + // CBOR-encoding of the hash + bytes{0x58, 0x20} + dev::swarmHash(_metadata).asBytes(); + bytes cborEncodedMetadata; + if (_experimentalMode) + cborEncodedMetadata = + // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata), "experimental": true} + bytes{0xa2} + + cborEncodedHash + + bytes{0x6c, 'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l', 0xf5}; + else + cborEncodedMetadata = + // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata)} + bytes{0xa1} + + cborEncodedHash; + solAssert(cborEncodedMetadata.size() <= 0xffff, "Metadata too large"); + // 16-bit big endian length + cborEncodedMetadata += toCompactBigEndian(cborEncodedMetadata.size(), 2); + return cborEncodedMetadata; +} + string CompilerStack::computeSourceMapping(eth::AssemblyItems const& _items) const { string ret; diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 13c9cc7a..0578ac86 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -93,7 +93,7 @@ public: m_errorList(), m_errorReporter(m_errorList) {} - /// @returns the list of errors that occured during parsing and type checking. + /// @returns the list of errors that occurred during parsing and type checking. ErrorList const& errors() const { return m_errorReporter.errors(); } /// @returns the current state. @@ -122,6 +122,8 @@ public: m_optimizeRuns = _runs; } + /// Set the EVM version used before running compile. + /// When called without an argument it will revert to the default version. void setEVMVersion(EVMVersion _version = EVMVersion{}); /// Sets the list of requested contract names. If empty, no filtering is performed and every contract @@ -240,9 +242,7 @@ public: Json::Value gasEstimates(std::string const& _contractName) const; private: - /** - * Information pertaining to one source unit, filled gradually during parsing and compilation. - */ + /// The state per source unit. Filled gradually during parsing. struct Source { std::shared_ptr<Scanner> scanner; @@ -251,13 +251,14 @@ private: void reset() { scanner.reset(); ast.reset(); } }; + /// The state per contract. Filled gradually during compilation. struct Contract { ContractDefinition const* contract = nullptr; std::shared_ptr<Compiler> compiler; - eth::LinkerObject object; - eth::LinkerObject runtimeObject; - eth::LinkerObject cloneObject; + eth::LinkerObject object; ///< Deployment object (includes the runtime sub-object). + eth::LinkerObject runtimeObject; ///< Runtime object. + eth::LinkerObject cloneObject; ///< Clone object (deprecated). std::string metadata; ///< The metadata json that will be hashed into the chain. mutable std::unique_ptr<Json::Value const> abi; mutable std::unique_ptr<Json::Value const> userDocumentation; @@ -272,10 +273,12 @@ private: StringMap loadMissingSources(SourceUnit const& _ast, std::string const& _path); std::string applyRemapping(std::string const& _path, std::string const& _context); void resolveImports(); + /// @returns the absolute path corresponding to @a _path relative to @a _reference. - std::string absolutePath(std::string const& _path, std::string const& _reference) const; + static std::string absolutePath(std::string const& _path, std::string const& _reference); + /// Helper function to return path converted strings. - std::string sanitizePath(std::string const& _path) const { return boost::filesystem::path(_path).generic_string(); } + static std::string sanitizePath(std::string const& _path) { return boost::filesystem::path(_path).generic_string(); } /// @returns true if the contract is requested to be compiled. bool isRequestedContract(ContractDefinition const& _contract) const; @@ -285,19 +288,42 @@ private: ContractDefinition const& _contract, std::map<ContractDefinition const*, eth::Assembly const*>& _compiledContracts ); + + /// Links all the known library addresses in the available objects. Any unknown + /// library will still be kept as an unlinked placeholder in the objects. void link(); + /// @returns the contract object for the given @a _contractName. + /// Can only be called after state is CompilationSuccessful. Contract const& contract(std::string const& _contractName) const; + + /// @returns the source object for the given @a _sourceName. + /// Can only be called after state is SourcesSet. Source const& source(std::string const& _sourceName) const; /// @returns the parsed contract with the supplied name. Throws an exception if the contract /// does not exist. ContractDefinition const& contractDefinition(std::string const& _contractName) const; + /// @returns the metadata JSON as a compact string for the given contract. std::string createMetadata(Contract const& _contract) const; + + /// @returns the metadata CBOR for the given serialised metadata JSON. + static bytes createCBORMetadata(std::string _metadata, bool _experimentalMode); + + /// @returns the computer source mapping string. std::string computeSourceMapping(eth::AssemblyItems const& _items) const; + + /// @returns the contract ABI as a JSON object. + /// This will generate the JSON object and store it in the Contract object if it is not present yet. Json::Value const& contractABI(Contract const&) const; + + /// @returns the Natspec User documentation as a JSON object. + /// This will generate the JSON object and store it in the Contract object if it is not present yet. Json::Value const& natspecUser(Contract const&) const; + + /// @returns the Natspec Developer documentation as a JSON object. + /// This will generate the JSON object and store it in the Contract object if it is not present yet. Json::Value const& natspecDev(Contract const&) const; /// @returns the offset of the entry point of the given function into the list of assembly items diff --git a/libsolidity/interface/ErrorReporter.h b/libsolidity/interface/ErrorReporter.h index d1a0030f..fd53587a 100644 --- a/libsolidity/interface/ErrorReporter.h +++ b/libsolidity/interface/ErrorReporter.h @@ -92,6 +92,12 @@ public: void clear(); + /// @returns true iff there is any error (ignores warnings). + bool hasErrors() const + { + return m_errorCount > 0; + } + private: void error(Error::Type _type, SourceLocation const& _location, diff --git a/libsolidity/interface/Natspec.cpp b/libsolidity/interface/Natspec.cpp index 7f7084ef..29a5b798 100644 --- a/libsolidity/interface/Natspec.cpp +++ b/libsolidity/interface/Natspec.cpp @@ -36,6 +36,10 @@ Json::Value Natspec::userDocumentation(ContractDefinition const& _contractDef) Json::Value doc; Json::Value methods(Json::objectValue); + string notice = extractDoc(_contractDef.annotation().docTags, "notice"); + if (!notice.empty()) + doc["notice"] = Json::Value(notice); + for (auto const& it: _contractDef.interfaceFunctions()) if (it.second->hasDeclaration()) if (auto const* f = dynamic_cast<FunctionDefinition const*>(&it.second->declaration())) @@ -65,6 +69,9 @@ Json::Value Natspec::devDocumentation(ContractDefinition const& _contractDef) auto title = extractDoc(_contractDef.annotation().docTags, "title"); if (!title.empty()) doc["title"] = title; + auto dev = extractDoc(_contractDef.annotation().docTags, "dev"); + if (!dev.empty()) + doc["details"] = Json::Value(dev); for (auto const& it: _contractDef.interfaceFunctions()) { diff --git a/libsolidity/interface/Natspec.h b/libsolidity/interface/Natspec.h index 0701f821..6a827d3b 100644 --- a/libsolidity/interface/Natspec.h +++ b/libsolidity/interface/Natspec.h @@ -45,7 +45,7 @@ public: /// @param _contractDef The contract definition /// @return A JSON representation of the contract's user documentation static Json::Value userDocumentation(ContractDefinition const& _contractDef); - /// Genereates the Developer's documentation of the contract + /// Generates the Developer's documentation of the contract /// @param _contractDef The contract definition /// @return A JSON representation /// of the contract's developer documentation diff --git a/libsolidity/interface/StandardCompiler.h b/libsolidity/interface/StandardCompiler.h index 11a0b4c2..2772394a 100644 --- a/libsolidity/interface/StandardCompiler.h +++ b/libsolidity/interface/StandardCompiler.h @@ -31,7 +31,7 @@ namespace solidity { /** - * Standard JSON compiler interface, which expects a JSON input and returns a JSON ouput. + * Standard JSON compiler interface, which expects a JSON input and returns a JSON output. * See docs/using-the-compiler#compiler-input-and-output-json-description. */ class StandardCompiler: boost::noncopyable diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index e2e1eebc..e2bd6fb4 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -322,11 +322,18 @@ StateMutability Parser::parseStateMutability(Token::Value _token) StateMutability stateMutability(StateMutability::NonPayable); if (_token == Token::Payable) stateMutability = StateMutability::Payable; - // FIXME: constant should be removed at the next breaking release - else if (_token == Token::View || _token == Token::Constant) + else if (_token == Token::View) stateMutability = StateMutability::View; else if (_token == Token::Pure) stateMutability = StateMutability::Pure; + else if (_token == Token::Constant) + { + stateMutability = StateMutability::View; + parserError( + "The state mutability modifier \"constant\" was removed in version 0.5.0. " + "Use \"view\" or \"pure\" instead." + ); + } else solAssert(false, "Invalid state mutability specifier."); m_scanner->next(); @@ -592,11 +599,22 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration( else if (!type) parserError(string("Location specifier needs explicit type name.")); else - location = ( - token == Token::Memory ? - VariableDeclaration::Location::Memory : - VariableDeclaration::Location::Storage - ); + { + switch (token) + { + case Token::Storage: + location = VariableDeclaration::Location::Storage; + break; + case Token::Memory: + location = VariableDeclaration::Location::Memory; + break; + case Token::CallData: + location = VariableDeclaration::Location::CallData; + break; + default: + solAssert(false, "Unknown data location."); + } + } } else break; @@ -928,10 +946,11 @@ ASTPointer<Statement> Parser::parseStatement() } case Token::Assembly: return parseInlineAssembly(docString); + case Token::Emit: + statement = parseEmitStatement(docString); + break; case Token::Identifier: - if (m_scanner->currentLiteral() == "emit") - statement = parseEmitStatement(docString); - else if (m_insideModifier && m_scanner->currentLiteral() == "_") + if (m_insideModifier && m_scanner->currentLiteral() == "_") { statement = ASTNodeFactory(*this).createNode<PlaceholderStatement>(docString); m_scanner->next(); @@ -1051,6 +1070,8 @@ ASTPointer<ForStatement> Parser::parseForStatement(ASTPointer<ASTString> const& ASTPointer<EmitStatement> Parser::parseEmitStatement(ASTPointer<ASTString> const& _docString) { + expectToken(Token::Emit, false); + ASTNodeFactory nodeFactory(*this); m_scanner->next(); ASTNodeFactory eventCallNodeFactory(*this); diff --git a/libsolidity/parsing/Scanner.cpp b/libsolidity/parsing/Scanner.cpp index 6541f6c2..801d2cc4 100644 --- a/libsolidity/parsing/Scanner.cpp +++ b/libsolidity/parsing/Scanner.cpp @@ -768,8 +768,14 @@ Token::Value Scanner::scanNumber(char _charSeen) scanDecimalDigits(); // optional if (m_char == '.') { + // A '.' has to be followed by a number. + if (m_source.isPastEndOfInput() || !isDecimalDigit(m_source.get(1))) + { + literal.complete(); + return Token::Number; + } addLiteralCharAndAdvance(); - scanDecimalDigits(); // optional + scanDecimalDigits(); } } } diff --git a/libsolidity/parsing/Scanner.h b/libsolidity/parsing/Scanner.h index 0adaa6fd..8a3011eb 100644 --- a/libsolidity/parsing/Scanner.h +++ b/libsolidity/parsing/Scanner.h @@ -223,7 +223,7 @@ private: bool isSourcePastEndOfInput() const { return m_source.isPastEndOfInput(); } TokenDesc m_skippedComment; // desc for current skipped comment - TokenDesc m_nextSkippedComment; // desc for next skiped comment + TokenDesc m_nextSkippedComment; // desc for next skipped comment TokenDesc m_currentToken; // desc for current token (as returned by Next()) TokenDesc m_nextToken; // desc for next token (one token look-ahead) diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index 4d7a7bc6..cb855cbe 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -149,6 +149,7 @@ namespace solidity K(Do, "do", 0) \ K(Else, "else", 0) \ K(Enum, "enum", 0) \ + K(Emit, "emit", 0) \ K(Event, "event", 0) \ K(External, "external", 0) \ K(For, "for", 0) \ @@ -173,6 +174,7 @@ namespace solidity K(Return, "return", 0) \ K(Returns, "returns", 0) \ K(Storage, "storage", 0) \ + K(CallData, "calldata", 0) \ K(Struct, "struct", 0) \ K(Throw, "throw", 0) \ K(Using, "using", 0) \ @@ -221,22 +223,41 @@ namespace solidity /* Keywords reserved for future use. */ \ K(Abstract, "abstract", 0) \ K(After, "after", 0) \ + K(Alias, "alias", 0) \ + K(Apply, "apply", 0) \ + K(Auto, "auto", 0) \ K(Case, "case", 0) \ K(Catch, "catch", 0) \ + K(CopyOf, "copyof", 0) \ K(Default, "default", 0) \ + K(Define, "define", 0) \ K(Final, "final", 0) \ + K(Immutable, "immutable", 0) \ + K(Implements, "implements", 0) \ K(In, "in", 0) \ K(Inline, "inline", 0) \ K(Let, "let", 0) \ + K(Macro, "macro", 0) \ K(Match, "match", 0) \ + K(Mutable, "mutable", 0) \ K(NullLiteral, "null", 0) \ K(Of, "of", 0) \ + K(Override, "override", 0) \ + K(Partial, "partial", 0) \ + K(Promise, "promise", 0) \ + K(Reference, "reference", 0) \ K(Relocatable, "relocatable", 0) \ + K(Sealed, "sealed", 0) \ + K(Sizeof, "sizeof", 0) \ K(Static, "static", 0) \ + K(Supports, "supports", 0) \ K(Switch, "switch", 0) \ K(Try, "try", 0) \ K(Type, "type", 0) \ + K(Typedef, "typedef", 0) \ K(TypeOf, "typeof", 0) \ + K(Unchecked, "unchecked", 0) \ + \ /* Illegal token - not able to scan. */ \ T(Illegal, "ILLEGAL", 0) \ \ @@ -289,11 +310,11 @@ public: static bool isShiftOp(Value op) { return (SHL <= op) && (op <= SHR); } static bool isVisibilitySpecifier(Value op) { return isVariableVisibilitySpecifier(op) || op == External; } static bool isVariableVisibilitySpecifier(Value op) { return op == Public || op == Private || op == Internal; } - static bool isLocationSpecifier(Value op) { return op == Memory || op == Storage; } + static bool isLocationSpecifier(Value op) { return op == Memory || op == Storage || op == CallData; } static bool isStateMutabilitySpecifier(Value op) { return op == Pure || op == Constant || op == View || op == Payable; } static bool isEtherSubdenomination(Value op) { return op == SubWei || op == SubSzabo || op == SubFinney || op == SubEther; } static bool isTimeSubdenomination(Value op) { return op == SubSecond || op == SubMinute || op == SubHour || op == SubDay || op == SubWeek || op == SubYear; } - static bool isReservedKeyword(Value op) { return (Abstract <= op && op <= TypeOf); } + static bool isReservedKeyword(Value op) { return (Abstract <= op && op <= Unchecked); } // @returns a string corresponding to the JS token string // (.e., "<" for the token LT) or NULL if the token doesn't @@ -348,7 +369,7 @@ public: unsigned int secondNumber() const { return m_secondNumber; } Token::Value token() const { return m_token; } ///if tokValue is set to true, then returns the actual token type name, otherwise, returns full type - std::string toString(bool const& tokenValue = false) const + std::string toString(bool const& tokenValue = false) const { std::string name = Token::toString(m_token); if (tokenValue || (firstNumber() == 0 && secondNumber() == 0)) diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 654a9f29..2b2de1e2 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -1,18 +1,39 @@ -FROM alpine +FROM alpine AS build MAINTAINER chriseth <chris@ethereum.org> #Official solidity docker image #Establish working directory as solidity WORKDIR /solidity + +# Build dependencies +ADD /scripts/install_deps.sh /solidity/scripts/install_deps.sh +RUN ./scripts/install_deps.sh + #Copy working directory on travis to the image COPY / $WORKDIR -#Install dependencies, eliminate annoying warnings, and build release, delete all remaining points and statically link. -RUN ./scripts/install_deps.sh && sed -i -E -e 's/include <sys\/poll.h>/include <poll.h>/' /usr/include/boost/asio/detail/socket_types.hpp &&\ -cmake -DCMAKE_BUILD_TYPE=Release -DTESTS=0 -DSOLC_LINK_STATIC=1 &&\ -make solc && install -s solc/solc /usr/bin &&\ -cd / && rm -rf solidity &&\ -apk del sed build-base git make cmake gcc g++ musl-dev curl-dev boost-dev &&\ -rm -rf /var/cache/apk/* +# Number of parallel jobs during build +# or 0 for auto-computing (max(1, CPU_core_count * 2/3), a greedy value) +ARG BUILD_CONCURRENCY="0" + +#Install dependencies, eliminate annoying warnings +RUN sed -i -E -e 's/include <sys\/poll.h>/include <poll.h>/' /usr/include/boost/asio/detail/socket_types.hpp +RUN cmake -DCMAKE_BUILD_TYPE=Release -DTESTS=0 -DSOLC_LINK_STATIC=1 +RUN make solc \ + -j$(awk "BEGIN { \ + if (${BUILD_CONCURRENCY} != 0) { \ + print(${BUILD_CONCURRENCY}); \ + } else { \ + x=($(grep -c ^processor /proc/cpuinfo) * 2/3); \ + if (x > 1) { \ + printf(\"%d\n\", x); \ + } else { \ + print(1); \ + } \ + } \ + }") +RUN strip solc/solc -ENTRYPOINT ["/usr/bin/solc"]
\ No newline at end of file +FROM scratch +COPY --from=build /solidity/solc/solc /usr/bin/solc +ENTRYPOINT ["/usr/bin/solc"] diff --git a/scripts/bytecodecompare/storebytecode.bat b/scripts/bytecodecompare/storebytecode.bat index e64e9276..ef20a320 100644 --- a/scripts/bytecodecompare/storebytecode.bat +++ b/scripts/bytecodecompare/storebytecode.bat @@ -39,4 +39,5 @@ set REPORT=%DIRECTORY%/windows.txt cp ../report.txt %REPORT% git add %REPORT% git commit -a -m "Added report." +git pull --rebase git push origin 2>&1 diff --git a/scripts/codespell_whitelist.txt b/scripts/codespell_whitelist.txt new file mode 100644 index 00000000..31f03981 --- /dev/null +++ b/scripts/codespell_whitelist.txt @@ -0,0 +1,3 @@ +iff +nd +assignend diff --git a/scripts/extract_test_cases.py b/scripts/extract_test_cases.py index 07ef9a96..47c53f3c 100755 --- a/scripts/extract_test_cases.py +++ b/scripts/extract_test_cases.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python2 # # This script reads C++ or RST source files and writes all # multi-line strings into individual files. diff --git a/scripts/install_deps.sh b/scripts/install_deps.sh index ace6580a..96501499 100755 --- a/scripts/install_deps.sh +++ b/scripts/install_deps.sh @@ -133,7 +133,7 @@ case $(uname -s) in # Arch Linux #------------------------------------------------------------------------------ - Arch*) + Arch*|ManjaroLinux) #Arch echo "Installing solidity dependencies on Arch Linux." diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py index 5bf577d3..1f913504 100755 --- a/scripts/isolate_tests.py +++ b/scripts/isolate_tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python2 # # This script reads C++ or RST source files and writes all # multi-line strings into individual files. @@ -10,7 +10,7 @@ import sys import re import os import hashlib -from os.path import join +from os.path import join, isfile def extract_test_cases(path): lines = open(path, 'rb').read().splitlines() @@ -77,24 +77,31 @@ def write_cases(tests): for test in tests: open('test_%s.sol' % hashlib.sha256(test).hexdigest(), 'wb').write(test) + +def extract_and_write(f, path): + if docs: + cases = extract_docs_cases(path) + else: + if f.endswith('.sol'): + cases = [open(path, 'r').read()] + else: + cases = extract_test_cases(path) + write_cases(cases) + if __name__ == '__main__': path = sys.argv[1] docs = False if len(sys.argv) > 2 and sys.argv[2] == 'docs': docs = True - for root, subdirs, files in os.walk(path): - if '_build' in subdirs: - subdirs.remove('_build') - if 'compilationTests' in subdirs: - subdirs.remove('compilationTests') - for f in files: - path = join(root, f) - if docs: - cases = extract_docs_cases(path) - else: - if f.endswith(".sol"): - cases = [open(path, "r").read()] - else: - cases = extract_test_cases(path) - write_cases(cases) + if isfile(path): + extract_and_write(path, path) + else: + for root, subdirs, files in os.walk(path): + if '_build' in subdirs: + subdirs.remove('_build') + if 'compilationTests' in subdirs: + subdirs.remove('compilationTests') + for f in files: + path = join(root, f) + extract_and_write(f, path) diff --git a/scripts/release.bat b/scripts/release.bat index be95b35e..6415a040 100644 --- a/scripts/release.bat +++ b/scripts/release.bat @@ -32,11 +32,10 @@ set VERSION=%2 IF "%VERSION%"=="2015" ( set "DLLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x86\Microsoft.VC140.CRT\msvc*.dll" ) ELSE ( - - IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.13.26020\x86\Microsoft.VC141.CRT\" ( - set "DLLS=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.13.26020\x86\Microsoft.VC141.CRT\msvc*.dll" + IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.14.26405\x86\Microsoft.VC141.CRT\" ( + set "DLLS=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.14.26405\x86\Microsoft.VC141.CRT\msvc*.dll" ) ELSE ( - set "DLLS=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Redist\MSVC\14.13.26020\x86\Microsoft.VC141.CRT\msvc*.dll" + set "DLLS=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Redist\MSVC\14.14.26405\x86\Microsoft.VC141.CRT\msvc*.dll" ) ) diff --git a/scripts/release_ppa.sh b/scripts/release_ppa.sh index b1601336..ae565a02 100755 --- a/scripts/release_ppa.sh +++ b/scripts/release_ppa.sh @@ -50,11 +50,11 @@ else ppafilesurl=https://launchpad.net/~ethereum/+archive/ubuntu/ethereum/+files fi -keyid=703F83D0 +keyid=70D110489D66E2F6 email=builds@ethereum.org packagename=solc -for distribution in trusty vivid xenial zesty artful bionic +for distribution in trusty xenial artful bionic do cd /tmp/ rm -rf $distribution diff --git a/scripts/tests.sh b/scripts/tests.sh index d63c1fe4..ab9b2f76 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -56,7 +56,6 @@ fi function printError() { echo "$(tput setaf 1)$1$(tput sgr0)"; } function printTask() { echo "$(tput bold)$(tput setaf 2)$1$(tput sgr0)"; } - printTask "Running commandline tests..." "$REPO_ROOT/test/cmdlineTests.sh" & CMDLINE_PID=$! @@ -70,49 +69,58 @@ then fi fi -function download_eth() +function download_aleth() { if [[ "$OSTYPE" == "darwin"* ]]; then - ETH_PATH="$REPO_ROOT/eth" + ALETH_PATH="$REPO_ROOT/aleth" elif [ -z $CI ]; then - ETH_PATH="eth" + ALETH_PATH="aleth" else mkdir -p /tmp/test if grep -i trusty /etc/lsb-release >/dev/null 2>&1 then - # built from 5ac09111bd0b6518365fe956e1bdb97a2db82af1 at 2018-04-05 - ETH_BINARY=eth_2018-04-05_trusty - ETH_HASH="1e5e178b005e5b51f9d347df4452875ba9b53cc6" + # built from d661ac4fec0aeffbedcdc195f67f5ded0c798278 at 2018-06-20 + ALETH_BINARY=aleth_2018-06-20_trusty + ALETH_HASH="54b8a5455e45b295e3a962f353ff8f1580ed106c" else - # built from 5ac09111bd0b6518365fe956e1bdb97a2db82af1 at 2018-04-05 - ETH_BINARY=eth_2018-04-05_artful - ETH_HASH="eb2d0df022753bb2b442ba73e565a9babf6828d6" + # built from d661ac4fec0aeffbedcdc195f67f5ded0c798278 at 2018-06-20 + ALETH_BINARY=aleth_2018-06-20_artful + ALETH_HASH="02e6c4b3d98299885e73f7db6c9e3fbe3d66d444" fi - wget -q -O /tmp/test/eth https://github.com/ethereum/cpp-ethereum/releases/download/solidityTester/$ETH_BINARY - test "$(shasum /tmp/test/eth)" = "$ETH_HASH /tmp/test/eth" + ALETH_PATH="/tmp/test/aleth" + wget -q -O $ALETH_PATH https://github.com/ethereum/cpp-ethereum/releases/download/solidityTester/$ALETH_BINARY + test "$(shasum $ALETH_PATH)" = "$ALETH_HASH $ALETH_PATH" sync - chmod +x /tmp/test/eth + chmod +x $ALETH_PATH sync # Otherwise we might get a "text file busy" error - ETH_PATH="/tmp/test/eth" fi } # $1: data directory # echos the PID -function run_eth() +function run_aleth() { - $ETH_PATH --test -d "$1" >/dev/null 2>&1 & + $ALETH_PATH --test -d "$1" >/dev/null 2>&1 & echo $! # Wait until the IPC endpoint is available. while [ ! -S "$1"/geth.ipc ] ; do sleep 1; done sleep 2 } +function check_aleth() { + printTask "Running IPC tests with $ALETH_PATH..." + if ! hash $ALETH_PATH 2>/dev/null; then + printError "$ALETH_PATH not found" + exit 1 + fi +} + if [ "$IPC_ENABLED" = true ]; then - download_eth - ETH_PID=$(run_eth /tmp/test) + download_aleth + check_aleth + ALETH_PID=$(run_aleth /tmp/test) fi progress="--show-progress" @@ -157,7 +165,7 @@ fi if [ "$IPC_ENABLED" = true ] then - pkill "$ETH_PID" || true + pkill "$ALETH_PID" || true sleep 4 - pgrep "$ETH_PID" && pkill -9 "$ETH_PID" || true + pgrep "$ALETH_PID" && pkill -9 "$ALETH_PID" || true fi diff --git a/scripts/update_bugs_by_version.py b/scripts/update_bugs_by_version.py index cbedf1a5..68ccd72a 100755 --- a/scripts/update_bugs_by_version.py +++ b/scripts/update_bugs_by_version.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # # This script is used to generate the list of bugs per compiler version # from the list of bugs. diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 5fe75a14..6a768a00 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -88,12 +88,11 @@ static string const g_strEVM = "evm"; static string const g_strEVM15 = "evm15"; static string const g_strEVMVersion = "evm-version"; static string const g_streWasm = "ewasm"; -static string const g_strFormal = "formal"; static string const g_strGas = "gas"; static string const g_strHelp = "help"; static string const g_strInputFile = "input-file"; static string const g_strInterface = "interface"; -static string const g_strJulia = "julia"; +static string const g_strYul = "yul"; static string const g_strLicense = "license"; static string const g_strLibraries = "libraries"; static string const g_strLink = "link"; @@ -132,11 +131,10 @@ static string const g_argBinaryRuntime = g_strBinaryRuntime; static string const g_argCloneBinary = g_strCloneBinary; static string const g_argCombinedJson = g_strCombinedJson; static string const g_argCompactJSON = g_strCompactJSON; -static string const g_argFormal = g_strFormal; static string const g_argGas = g_strGas; static string const g_argHelp = g_strHelp; static string const g_argInputFile = g_strInputFile; -static string const g_argJulia = g_strJulia; +static string const g_argYul = g_strYul; static string const g_argLibraries = g_strLibraries; static string const g_argLink = g_strLink; static string const g_argMachine = g_strMachine; @@ -216,7 +214,6 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) g_argBinary, g_argBinaryRuntime, g_argCloneBinary, - g_argFormal, g_argMetadata, g_argNatspecUser, g_argNatspecDev, @@ -450,7 +447,7 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() m_sourceCodes[g_stdinFileName] = dev::readStandardInput(); if (m_sourceCodes.size() == 0) { - cerr << "No input files given. If you wish to use the standard input please specify \"-\" explicity." << endl; + cerr << "No input files given. If you wish to use the standard input please specify \"-\" explicitly." << endl; return false; } @@ -600,8 +597,8 @@ Allowed options)", "Switch to assembly mode, ignoring all options except --machine and assumes input is assembly." ) ( - g_argJulia.c_str(), - "Switch to JULIA mode, ignoring all options except --machine and assumes input is JULIA." + g_argYul.c_str(), + "Switch to Yul mode, ignoring all options except --machine and assumes input is Yul." ) ( g_argStrictAssembly.c_str(), @@ -610,7 +607,7 @@ Allowed options)", ( g_argMachine.c_str(), po::value<string>()->value_name(boost::join(g_machineArgs, ",")), - "Target machine in assembly or JULIA mode." + "Target machine in assembly or Yul mode." ) ( g_argLink.c_str(), @@ -639,8 +636,7 @@ Allowed options)", (g_argSignatureHashes.c_str(), "Function signature hashes of the contracts.") (g_argNatspecUser.c_str(), "Natspec user documentation of all contracts.") (g_argNatspecDev.c_str(), "Natspec developer documentation of all contracts.") - (g_argMetadata.c_str(), "Combined Metadata JSON whose Swarm hash is stored on-chain.") - (g_argFormal.c_str(), "Translated source suitable for formal analysis. (Deprecated)"); + (g_argMetadata.c_str(), "Combined Metadata JSON whose Swarm hash is stored on-chain."); desc.add(outputComponents); po::options_description allOptions = desc; @@ -785,13 +781,13 @@ bool CommandLineInterface::processInput() m_evmVersion = *versionOption; } - if (m_args.count(g_argAssemble) || m_args.count(g_argStrictAssembly) || m_args.count(g_argJulia)) + if (m_args.count(g_argAssemble) || m_args.count(g_argStrictAssembly) || m_args.count(g_argYul)) { // switch to assembly mode m_onlyAssemble = true; using Input = AssemblyStack::Language; using Machine = AssemblyStack::Machine; - Input inputLanguage = m_args.count(g_argJulia) ? Input::JULIA : (m_args.count(g_argStrictAssembly) ? Input::StrictAssembly : Input::Assembly); + Input inputLanguage = m_args.count(g_argYul) ? Input::Yul : (m_args.count(g_argStrictAssembly) ? Input::StrictAssembly : Input::Assembly); Machine targetMachine = Machine::EVM; if (m_args.count(g_argMachine)) { @@ -1241,9 +1237,6 @@ void CommandLineInterface::outputCompilationResults() handleNatspec(true, contract); handleNatspec(false, contract); } // end of contracts iteration - - if (m_args.count(g_argFormal)) - cerr << "Support for the Why3 output was removed." << endl; } } diff --git a/std/StandardToken.sol b/std/StandardToken.sol deleted file mode 100644 index c2fc3a66..00000000 --- a/std/StandardToken.sol +++ /dev/null @@ -1,59 +0,0 @@ -pragma solidity ^0.4.22; - -import "./Token.sol"; - -contract StandardToken is Token { - uint256 supply; - mapping (address => uint256) balance; - mapping (address => - mapping (address => uint256)) m_allowance; - - constructor(address _initialOwner, uint256 _supply) public { - supply = _supply; - balance[_initialOwner] = _supply; - } - - function balanceOf(address _account) view public returns (uint) { - return balance[_account]; - } - - function totalSupply() view public returns (uint) { - return supply; - } - - function transfer(address _to, uint256 _value) public returns (bool success) { - return doTransfer(msg.sender, _to, _value); - } - - function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { - if (m_allowance[_from][msg.sender] >= _value) { - if (doTransfer(_from, _to, _value)) { - m_allowance[_from][msg.sender] -= _value; - } - return true; - } else { - return false; - } - } - - function doTransfer(address _from, address _to, uint _value) internal returns (bool success) { - if (balance[_from] >= _value && balance[_to] + _value >= balance[_to]) { - balance[_from] -= _value; - balance[_to] += _value; - emit Transfer(_from, _to, _value); - return true; - } else { - return false; - } - } - - function approve(address _spender, uint256 _value) public returns (bool success) { - m_allowance[msg.sender][_spender] = _value; - emit Approval(msg.sender, _spender, _value); - return true; - } - - function allowance(address _owner, address _spender) view public returns (uint256) { - return m_allowance[_owner][_spender]; - } -} diff --git a/std/Token.sol b/std/Token.sol deleted file mode 100644 index 7348a8f5..00000000 --- a/std/Token.sol +++ /dev/null @@ -1,13 +0,0 @@ -pragma solidity ^0.4.0; - -contract Token { - event Transfer(address indexed _from, address indexed _to, uint256 _value); - event Approval(address indexed _owner, address indexed _spender, uint256 _value); - - function totalSupply() view public returns (uint256 supply); - function balanceOf(address _owner) view public returns (uint256 balance); - function transfer(address _to, uint256 _value) public returns (bool success); - function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); - function approve(address _spender, uint256 _value) public returns (bool success); - function allowance(address _owner, address _spender) view public returns (uint256 remaining); -} diff --git a/std/mortal.sol b/std/mortal.sol deleted file mode 100644 index c43f1e4f..00000000 --- a/std/mortal.sol +++ /dev/null @@ -1,10 +0,0 @@ -pragma solidity ^0.4.0; - -import "./owned.sol"; - -contract mortal is owned { - function kill() public { - if (msg.sender == owner) - selfdestruct(owner); - } -} diff --git a/std/owned.sol b/std/owned.sol deleted file mode 100644 index 75007f3e..00000000 --- a/std/owned.sol +++ /dev/null @@ -1,15 +0,0 @@ -pragma solidity ^0.4.22; - -contract owned { - address owner; - - modifier onlyowner() { - if (msg.sender == owner) { - _; - } - } - - constructor() public { - owner = msg.sender; - } -} diff --git a/std/std.sol b/std/std.sol deleted file mode 100644 index 4d65bef2..00000000 --- a/std/std.sol +++ /dev/null @@ -1,6 +0,0 @@ -pragma solidity ^0.4.0; - -import "./owned.sol"; -import "./mortal.sol"; -import "./Token.sol"; -import "./StandardToken.sol"; diff --git a/test/ExecutionFramework.cpp b/test/ExecutionFramework.cpp index a24f78fb..00f5e697 100644 --- a/test/ExecutionFramework.cpp +++ b/test/ExecutionFramework.cpp @@ -142,6 +142,11 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256 entry.data = fromHex(log.data, WhenError::Throw); m_logs.push_back(entry); } + + if (!receipt.status.empty()) + m_transactionSuccessful = (receipt.status == "1"); + else + m_transactionSuccessful = (m_gas != m_gasUsed); } void ExecutionFramework::sendEther(Address const& _to, u256 const& _value) diff --git a/test/ExecutionFramework.h b/test/ExecutionFramework.h index 4525cbf9..cdbec81d 100644 --- a/test/ExecutionFramework.h +++ b/test/ExecutionFramework.h @@ -72,6 +72,7 @@ public: ) { compileAndRunWithoutCheck(_sourceCode, _value, _contractName, _arguments, _libraryAddresses); + BOOST_REQUIRE(m_transactionSuccessful); BOOST_REQUIRE(!m_output.empty()); return m_output; } @@ -234,6 +235,7 @@ protected: unsigned m_optimizeRuns = 200; bool m_optimize = false; bool m_showMessages = false; + bool m_transactionSuccessful = true; Address m_sender; Address m_contractAddress; u256 m_blockNumber; diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index f4eae865..b9b19b2f 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -163,6 +163,11 @@ RPCSession::TransactionReceipt RPCSession::eth_getTransactionReceipt(string cons receipt.gasUsed = result["gasUsed"].asString(); receipt.contractAddress = result["contractAddress"].asString(); receipt.blockNumber = result["blockNumber"].asString(); + if (m_receiptHasStatusField) + { + BOOST_REQUIRE(!result["status"].isNull()); + receipt.status = result["status"].asString(); + } for (auto const& log: result["logs"]) { LogEntry entry; @@ -225,7 +230,10 @@ void RPCSession::test_setChainParams(vector<string> const& _accounts) if (test::Options::get().evmVersion() >= solidity::EVMVersion::spuriousDragon()) forks += "\"EIP158ForkBlock\": \"0x00\",\n"; if (test::Options::get().evmVersion() >= solidity::EVMVersion::byzantium()) + { forks += "\"byzantiumForkBlock\": \"0x00\",\n"; + m_receiptHasStatusField = true; + } if (test::Options::get().evmVersion() >= solidity::EVMVersion::constantinople()) forks += "\"constantinopleForkBlock\": \"0x00\",\n"; static string const c_configString = R"( @@ -244,8 +252,11 @@ void RPCSession::test_setChainParams(vector<string> const& _accounts) "timestamp": "0x00", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x", - "gasLimit": "0x1000000000000" - }, + "gasLimit": "0x1000000000000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "nonce": "0x0000000000000042", + "difficulty": "131072" + }, "accounts": { "0000000000000000000000000000000000000001": { "wei": "1", "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } }, "0000000000000000000000000000000000000002": { "wei": "1", "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } }, diff --git a/test/RPCSession.h b/test/RPCSession.h index 63f1dd21..5af2e26a 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -99,6 +99,8 @@ public: std::string contractAddress; std::vector<LogEntry> logEntries; std::string blockNumber; + /// note: pre-byzantium the status field will be empty + std::string status; }; static RPCSession& instance(std::string const& _path); @@ -136,6 +138,7 @@ private: unsigned m_maxMiningTime = 6000000; // 600 seconds unsigned m_sleepTime = 10; // 10 milliseconds unsigned m_successfulMineRuns = 0; + bool m_receiptHasStatusField = false; std::vector<std::string> m_accounts; }; diff --git a/test/boostTest.cpp b/test/boostTest.cpp index f16973b5..145be6e4 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -38,7 +38,26 @@ #include <test/Options.h> #include <test/libsolidity/SyntaxTest.h> +#include <boost/algorithm/string.hpp> +#include <boost/algorithm/string/predicate.hpp> +#include <boost/filesystem.hpp> + using namespace boost::unit_test; +using namespace dev::solidity::test; +namespace fs = boost::filesystem; +using namespace std; + +#if BOOST_VERSION < 105900 +test_case *make_test_case( + function<void()> const& _fn, + string const& _name, + string const& /* _filename */, + size_t /* _line */ +) +{ + return make_test_case(_fn, _name); +} +#endif namespace { @@ -49,6 +68,56 @@ void removeTestSuite(std::string const& _name) assert(id != INV_TEST_UNIT_ID); master.remove(id); } + +int registerTests( + boost::unit_test::test_suite& _suite, + boost::filesystem::path const& _basepath, + boost::filesystem::path const& _path, + TestCase::TestCaseCreator _testCaseCreator +) +{ + int numTestsAdded = 0; + fs::path fullpath = _basepath / _path; + if (fs::is_directory(fullpath)) + { + test_suite* sub_suite = BOOST_TEST_SUITE(_path.filename().string()); + for (auto const& entry: boost::iterator_range<fs::directory_iterator>( + fs::directory_iterator(fullpath), + fs::directory_iterator() + )) + if (fs::is_directory(entry.path()) || TestCase::isTestFilename(entry.path().filename())) + numTestsAdded += registerTests(*sub_suite, _basepath, _path / entry.path().filename(), _testCaseCreator); + _suite.add(sub_suite); + } + else + { + static vector<unique_ptr<string>> filenames; + + filenames.emplace_back(new string(_path.string())); + _suite.add(make_test_case( + [fullpath, _testCaseCreator] + { + BOOST_REQUIRE_NO_THROW({ + try + { + stringstream errorStream; + if (!_testCaseCreator(fullpath.string())->run(errorStream)) + BOOST_ERROR("Test expectation mismatch.\n" + errorStream.str()); + } + catch (boost::exception const& _e) + { + BOOST_ERROR("Exception during extracted test: " << boost::diagnostic_information(_e)); + } + }); + }, + _path.stem().string(), + *filenames.back(), + 0 + )); + numTestsAdded = 1; + } + return numTestsAdded; +} } test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) @@ -56,10 +125,11 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) master_test_suite_t& master = framework::master_test_suite(); master.p_name.value = "SolidityTests"; dev::test::Options::get().validate(); - solAssert(dev::solidity::test::SyntaxTest::registerTests( + solAssert(registerTests( master, dev::test::Options::get().testPath / "libsolidity", - "syntaxTests" + "syntaxTests", + SyntaxTest::create ) > 0, "no syntax tests found"); if (dev::test::Options::get().disableIPC) { diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index 74b6a5a7..bc0ee786 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -37,10 +37,6 @@ FULLARGS="--optimize --ignore-missing --combined-json abi,asm,ast,bin,bin-runtim echo "Checking that the bug list is up to date..." "$REPO_ROOT"/scripts/update_bugs_by_version.py -echo "Checking that StandardToken.sol, owned.sol and mortal.sol produce bytecode..." -output=$("$REPO_ROOT"/build/solc/solc --bin "$REPO_ROOT"/std/*.sol 2>/dev/null | grep "ffff" | wc -l) -test "${output//[[:blank:]]/}" = "3" - function printTask() { echo "$(tput bold)$(tput setaf 2)$1$(tput sgr0)"; } function printError() { echo "$(tput setaf 1)$1$(tput sgr0)"; } @@ -113,14 +109,6 @@ do done ) -printTask "Compiling all files in std and examples..." - -for f in "$REPO_ROOT"/std/*.sol -do - echo "$f" - compileWithoutWarning "$f" -done - printTask "Compiling all examples from the documentation..." TMPDIR=$(mktemp -d) ( @@ -160,7 +148,7 @@ rm -rf "$TMPDIR" printTask "Testing assemble, yul, strict-assembly..." echo '{}' | "$SOLC" - --assemble &>/dev/null -echo '{}' | "$SOLC" - --julia &>/dev/null +echo '{}' | "$SOLC" - --yul &>/dev/null echo '{}' | "$SOLC" - --strict-assembly &>/dev/null printTask "Testing standard input..." diff --git a/test/compilationTests/MultiSigWallet/Factory.sol b/test/compilationTests/MultiSigWallet/Factory.sol index f1be6884..f37d230f 100644 --- a/test/compilationTests/MultiSigWallet/Factory.sol +++ b/test/compilationTests/MultiSigWallet/Factory.sol @@ -10,7 +10,7 @@ contract Factory { /// @return Returns number of instantiations by creator. function getInstantiationCount(address creator) public - constant + view returns (uint) { return instantiations[creator].length; @@ -23,6 +23,6 @@ contract Factory { { isInstantiation[instantiation] = true; instantiations[msg.sender].push(instantiation); - ContractInstantiation(msg.sender, instantiation); + emit ContractInstantiation(msg.sender, instantiation); } } diff --git a/test/compilationTests/MultiSigWallet/MultiSigWallet.sol b/test/compilationTests/MultiSigWallet/MultiSigWallet.sol index a6f67c7a..c2a6c3ef 100644 --- a/test/compilationTests/MultiSigWallet/MultiSigWallet.sol +++ b/test/compilationTests/MultiSigWallet/MultiSigWallet.sol @@ -50,7 +50,7 @@ contract MultiSigWallet { } modifier transactionExists(uint transactionId) { - if (transactions[transactionId].destination == 0) + if (transactions[transactionId].destination == address(0)) throw; _; } @@ -74,7 +74,7 @@ contract MultiSigWallet { } modifier notNull(address _address) { - if (_address == 0) + if (_address == address(0)) throw; _; } @@ -90,10 +90,11 @@ contract MultiSigWallet { /// @dev Fallback function allows to deposit ether. function() + external payable { if (msg.value > 0) - Deposit(msg.sender, msg.value); + emit Deposit(msg.sender, msg.value); } /* @@ -102,12 +103,12 @@ contract MultiSigWallet { /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. - function MultiSigWallet(address[] _owners, uint _required) + constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i=0; i<_owners.length; i++) { - if (isOwner[_owners[i]] || _owners[i] == 0) + if (isOwner[_owners[i]] || _owners[i] == address(0)) throw; isOwner[_owners[i]] = true; } @@ -126,7 +127,7 @@ contract MultiSigWallet { { isOwner[owner] = true; owners.push(owner); - OwnerAddition(owner); + emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. @@ -145,7 +146,7 @@ contract MultiSigWallet { owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); - OwnerRemoval(owner); + emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. @@ -164,8 +165,8 @@ contract MultiSigWallet { } isOwner[owner] = false; isOwner[newOwner] = true; - OwnerRemoval(owner); - OwnerAddition(newOwner); + emit OwnerRemoval(owner); + emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. @@ -176,7 +177,7 @@ contract MultiSigWallet { validRequirement(owners.length, _required) { required = _required; - RequirementChange(_required); + emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. @@ -201,7 +202,7 @@ contract MultiSigWallet { notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; - Confirmation(msg.sender, transactionId); + emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } @@ -214,7 +215,7 @@ contract MultiSigWallet { notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; - Revocation(msg.sender, transactionId); + emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. @@ -224,12 +225,12 @@ contract MultiSigWallet { notExecuted(transactionId) { if (isConfirmed(transactionId)) { - Transaction tx = transactions[transactionId]; + Transaction storage tx = transactions[transactionId]; tx.executed = true; if (tx.destination.call.value(tx.value)(tx.data)) - Execution(transactionId); + emit Execution(transactionId); else { - ExecutionFailure(transactionId); + emit ExecutionFailure(transactionId); tx.executed = false; } } @@ -240,7 +241,7 @@ contract MultiSigWallet { /// @return Confirmation status. function isConfirmed(uint transactionId) public - constant + view returns (bool) { uint count = 0; @@ -273,7 +274,7 @@ contract MultiSigWallet { executed: false }); transactionCount += 1; - Submission(transactionId); + emit Submission(transactionId); } /* @@ -284,7 +285,7 @@ contract MultiSigWallet { /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public - constant + view returns (uint count) { for (uint i=0; i<owners.length; i++) @@ -298,7 +299,7 @@ contract MultiSigWallet { /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public - constant + view returns (uint count) { for (uint i=0; i<transactionCount; i++) @@ -311,7 +312,7 @@ contract MultiSigWallet { /// @return List of owner addresses. function getOwners() public - constant + view returns (address[]) { return owners; @@ -322,7 +323,7 @@ contract MultiSigWallet { /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public - constant + view returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); @@ -346,7 +347,7 @@ contract MultiSigWallet { /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public - constant + view returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); diff --git a/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol b/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol index 024d3ef4..c1b1d7ea 100644 --- a/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol +++ b/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol @@ -19,7 +19,7 @@ contract MultiSigWalletWithDailyLimit is MultiSigWallet { /// @param _owners List of initial owners. /// @param _required Number of required confirmations. /// @param _dailyLimit Amount in wei, which can be withdrawn without confirmations on a daily basis. - function MultiSigWalletWithDailyLimit(address[] _owners, uint _required, uint _dailyLimit) + constructor(address[] _owners, uint _required, uint _dailyLimit) public MultiSigWallet(_owners, _required) { @@ -33,7 +33,7 @@ contract MultiSigWalletWithDailyLimit is MultiSigWallet { onlyWallet { dailyLimit = _dailyLimit; - DailyLimitChange(_dailyLimit); + emit DailyLimitChange(_dailyLimit); } /// @dev Allows anyone to execute a confirmed transaction or ether withdraws until daily limit is reached. @@ -42,16 +42,16 @@ contract MultiSigWalletWithDailyLimit is MultiSigWallet { public notExecuted(transactionId) { - Transaction tx = transactions[transactionId]; + Transaction storage tx = transactions[transactionId]; bool confirmed = isConfirmed(transactionId); if (confirmed || tx.data.length == 0 && isUnderLimit(tx.value)) { tx.executed = true; if (!confirmed) spentToday += tx.value; if (tx.destination.call.value(tx.value)(tx.data)) - Execution(transactionId); + emit Execution(transactionId); else { - ExecutionFailure(transactionId); + emit ExecutionFailure(transactionId); tx.executed = false; if (!confirmed) spentToday -= tx.value; @@ -85,7 +85,7 @@ contract MultiSigWalletWithDailyLimit is MultiSigWallet { /// @return Returns amount. function calcMaxWithdraw() public - constant + view returns (uint) { if (now > lastDay + 24 hours) diff --git a/test/compilationTests/MultiSigWallet/TestToken.sol b/test/compilationTests/MultiSigWallet/TestToken.sol index 0f6cd20e..df195c58 100644 --- a/test/compilationTests/MultiSigWallet/TestToken.sol +++ b/test/compilationTests/MultiSigWallet/TestToken.sol @@ -31,7 +31,7 @@ contract TestToken { } balances[msg.sender] -= _value; balances[_to] += _value; - Transfer(msg.sender, _to, _value); + emit Transfer(msg.sender, _to, _value); return true; } @@ -45,7 +45,7 @@ contract TestToken { balances[_to] += _value; balances[_from] -= _value; allowed[_from][msg.sender] -= _value; - Transfer(_from, _to, _value); + emit Transfer(_from, _to, _value); return true; } @@ -54,12 +54,12 @@ contract TestToken { returns (bool success) { allowed[msg.sender][_spender] = _value; - Approval(msg.sender, _spender, _value); + emit Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) - constant + view public returns (uint256 remaining) { @@ -67,7 +67,7 @@ contract TestToken { } function balanceOf(address _owner) - constant + view public returns (uint256 balance) { diff --git a/test/compilationTests/corion/ico.sol b/test/compilationTests/corion/ico.sol index 6c9f8cb2..abb6020b 100644 --- a/test/compilationTests/corion/ico.sol +++ b/test/compilationTests/corion/ico.sol @@ -49,8 +49,8 @@ contract ico is safeMath { mapping (address => mapping(uint256 => interest_s)) public interestDB; uint256 public totalMint; uint256 public totalPremiumMint; - - function ico(address foundation, address priceSet, uint256 exchangeRate, uint256 startBlockNum, address[] genesisAddr, uint256[] genesisValue) { + + constructor(address foundation, address priceSet, uint256 exchangeRate, uint256 startBlockNum, address[] genesisAddr, uint256[] genesisValue) public { /* Installation function. @@ -81,7 +81,7 @@ contract ico is safeMath { } } - function ICObonus() public constant returns(uint256 bonus) { + function ICObonus() public view returns(uint256 bonus) { /* Query of current bonus @@ -113,7 +113,7 @@ contract ico is safeMath { return true; } - function checkInterest(address addr) public constant returns(uint256 amount) { + function checkInterest(address addr) public view returns(uint256 amount) { /* Query of compound interest @@ -162,7 +162,7 @@ contract ico is safeMath { interest_s memory _idb; address _addr = beneficiary; uint256 _to = (block.number - startBlock) / interestBlockDelay; - if ( _addr == 0x00 ) { _addr = msg.sender; } + if ( _addr == address(0x00) ) { _addr = msg.sender; } require( block.number > icoDelay ); require( ! aborted ); @@ -231,7 +231,7 @@ contract ico is safeMath { require( ! aborted ); require( token(tokenAddr).mint(foundationAddress, token(tokenAddr).totalSupply() * 96 / 100) ); require( premium(premiumAddr).mint(foundationAddress, totalMint / 5000 - totalPremiumMint) ); - require( foundationAddress.send(this.balance) ); + require( foundationAddress.send(address(this).balance) ); require( token(tokenAddr).closeIco() ); require( premium(premiumAddr).closeIco() ); } @@ -257,7 +257,7 @@ contract ico is safeMath { @premiumContractAddr Address of the corion premium token contract */ require( msg.sender == owner ); - require( tokenAddr == 0x00 && premiumAddr == 0x00 ); + require( tokenAddr == address(0x00) && premiumAddr == address(0x00) ); tokenAddr = tokenContractAddr; premiumAddr = premiumContractAddr; } @@ -275,24 +275,24 @@ contract ico is safeMath { require( msg.sender.send(_val) ); } - function () payable { + function () external payable { /* - Callback function. Simply calls the buy function as a beneficiary and there is no affilate address. + Callback function. Simply calls the buy function as a beneficiary and there is no affiliate address. If they call the contract without any function then this process will be taken place. */ require( isICO() ); - require( buy(msg.sender, 0x00) ); + require( buy(msg.sender, address(0x00)) ); } - - function buy(address beneficiaryAddress, address affilateAddress) payable returns (bool success) { + + function buy(address beneficiaryAddress, address affilateAddress) public payable returns (bool success) { /* Buying a token If there is not at least 0.2 ether balance on the beneficiaryAddress then the amount of the ether which was intended for the purchase will be reduced by 0.2 and that will be sent to the address of the beneficiary. From the remaining amount calculate the reward with the help of the getIcoReward function. - Only that affilate address is valid which has some token on it’s account. - If there is a valid affilate address then calculate and credit the reward as well in the following way: - With more than 1e12 token contract credit 5% reward based on the calculation that how many tokens did they buy when he was added as an affilate. + Only that affiliate address is valid which has some token on it’s account. + If there is a valid affiliate address then calculate and credit the reward as well in the following way: + With more than 1e12 token contract credit 5% reward based on the calculation that how many tokens did they buy when he was added as an affiliate. More than 1e11 token: 4% More than 1e10 token: 3% More than 1e9 token: 2% below 1% @@ -300,16 +300,16 @@ contract ico is safeMath { @affilateAddress The address of the person who offered who will get the referral reward. It can not be equal with the beneficiaryAddress. */ require( isICO() ); - if ( beneficiaryAddress == 0x00) { beneficiaryAddress = msg.sender; } + if ( beneficiaryAddress == address(0x00)) { beneficiaryAddress = msg.sender; } if ( beneficiaryAddress == affilateAddress ) { - affilateAddress = 0x00; + affilateAddress = address(0x00); } uint256 _value = msg.value; if ( beneficiaryAddress.balance < 0.2 ether ) { require( beneficiaryAddress.send(0.2 ether) ); _value = safeSub(_value, 0.2 ether); } - var _reward = getIcoReward(_value); + uint256 _reward = getIcoReward(_value); require( _reward > 0 ); require( token(tokenAddr).mint(beneficiaryAddress, _reward) ); brought[beneficiaryAddress].eth = safeAdd(brought[beneficiaryAddress].eth, _value); @@ -317,7 +317,7 @@ contract ico is safeMath { totalMint = safeAdd(totalMint, _reward); require( foundationAddress.send(_value * 10 / 100) ); uint256 extra; - if ( affilateAddress != 0x00 && ( brought[affilateAddress].eth > 0 || interestDB[affilateAddress][0].amount > 0 ) ) { + if ( affilateAddress != address(0x00) && ( brought[affilateAddress].eth > 0 || interestDB[affilateAddress][0].amount > 0 ) ) { affiliate[affilateAddress].weight = safeAdd(affiliate[affilateAddress].weight, _reward); extra = affiliate[affilateAddress].weight; uint256 rate; @@ -337,7 +337,7 @@ contract ico is safeMath { token(tokenAddr).mint(affilateAddress, extra); } checkPremium(beneficiaryAddress); - EICO(beneficiaryAddress, _reward, affilateAddress, extra); + emit EICO(beneficiaryAddress, _reward, affilateAddress, extra); return true; } @@ -345,7 +345,7 @@ contract ico is safeMath { /* Crediting the premium token - @owner The corion token balance of this address will be set based on the calculation which shows that how many times can be the amount of the purchased tokens devided by 5000. So after each 5000 token we give 1 premium token. + @owner The corion token balance of this address will be set based on the calculation which shows that how many times can be the amount of the purchased tokens divided by 5000. So after each 5000 token we give 1 premium token. */ uint256 _reward = (brought[owner].cor / 5e9) - brought[owner].corp; if ( _reward > 0 ) { @@ -355,7 +355,7 @@ contract ico is safeMath { } } - function getIcoReward(uint256 value) public constant returns (uint256 reward) { + function getIcoReward(uint256 value) public view returns (uint256 reward) { /* Expected token volume at token purchase @@ -368,9 +368,9 @@ contract ico is safeMath { if ( reward < 5e6) { return 0; } } - function isICO() public constant returns (bool success) { + function isICO() public view returns (bool success) { return startBlock <= block.number && block.number <= icoDelay && ( ! aborted ) && ( ! closed ); } - event EICO(address indexed Address, uint256 indexed value, address Affilate, uint256 AffilateValue); + event EICO(address indexed Address, uint256 indexed value, address Affiliate, uint256 AffilateValue); } diff --git a/test/compilationTests/corion/module.sol b/test/compilationTests/corion/module.sol index d64044cb..e0084ea5 100644 --- a/test/compilationTests/corion/module.sol +++ b/test/compilationTests/corion/module.sol @@ -2,7 +2,7 @@ pragma solidity ^0.4.11; contract abstractModuleHandler { function transfer(address from, address to, uint256 value, bool fee) external returns (bool success) {} - function balanceOf(address owner) public constant returns (bool success, uint256 value) {} + function balanceOf(address owner) public view returns (bool success, uint256 value) {} } contract module { @@ -90,13 +90,13 @@ contract module { @newModuleAddress New module handler address */ require( moduleStatus != status.New && moduleStatus != status.Disconnected); - var (_success, _balance) = abstractModuleHandler(moduleHandlerAddress).balanceOf(address(this)); + (bool _success, uint256 _balance) = abstractModuleHandler(moduleHandlerAddress).balanceOf(address(this)); require( _success ); if ( _balance > 0 ) { require( abstractModuleHandler(moduleHandlerAddress).transfer(address(this), newModuleAddress, _balance, false) ); } - if ( this.balance > 0 ) { - require( newModuleAddress.send(this.balance) ); + if ( address(this).balance > 0 ) { + require( newModuleAddress.send(address(this).balance) ); } moduleStatus = status.Disconnected; } @@ -123,15 +123,15 @@ contract module { @ret This is the module handler address or not */ - if ( moduleHandlerAddress == 0x00 ) { return true; } + if ( moduleHandlerAddress == address(0x00) ) { return true; } if ( moduleStatus != status.Connected ) { return false; } return addr == moduleHandlerAddress; } - function isActive() public constant returns (bool success, bool active) { + function isActive() public view returns (bool success, bool active) { /* Check self for ready for functions or not. - @success Function call was successfull or not + @success Function call was successful or not @active Ready for functions or not */ return (true, moduleStatus == status.Connected && block.number >= disabledUntil); diff --git a/test/compilationTests/corion/moduleHandler.sol b/test/compilationTests/corion/moduleHandler.sol index 682f81dd..fddd2a29 100644 --- a/test/compilationTests/corion/moduleHandler.sol +++ b/test/compilationTests/corion/moduleHandler.sol @@ -16,7 +16,7 @@ contract abstractModule { function disconnectModule() external returns (bool success) {} function replaceModule(address addr) external returns (bool success) {} function disableModule(bool forever) external returns (bool success) {} - function isActive() public constant returns (bool success) {} + function isActive() public view returns (bool success) {} function replaceModuleHandler(address newHandler) external returns (bool success) {} function transferEvent(address from, address to, uint256 value) external returns (bool success) {} function newSchellingRoundEvent(uint256 roundID, uint256 reward) external returns (bool success) {} @@ -34,10 +34,10 @@ contract moduleHandler is multiOwner, announcementTypes { modules_s[] public modules; address public foundationAddress; uint256 debugModeUntil = block.number + 1000000; - - function moduleHandler(address[] newOwners) multiOwner(newOwners) {} - - function load(address foundation, bool forReplace, address Token, address Premium, address Publisher, address Schelling, address Provider) { + + + constructor(address[] newOwners) multiOwner(newOwners) public {} + function load(address foundation, bool forReplace, address Token, address Premium, address Publisher, address Schelling, address Provider) public { /* Loading modulest to ModuleHandler. @@ -54,26 +54,26 @@ contract moduleHandler is multiOwner, announcementTypes { require( owners[msg.sender] ); require( modules.length == 0 ); foundationAddress = foundation; - addModule( modules_s(Token, sha3('Token'), false, false), ! forReplace); - addModule( modules_s(Premium, sha3('Premium'), false, false), ! forReplace); - addModule( modules_s(Publisher, sha3('Publisher'), false, true), ! forReplace); - addModule( modules_s(Schelling, sha3('Schelling'), false, true), ! forReplace); - addModule( modules_s(Provider, sha3('Provider'), true, true), ! forReplace); + addModule( modules_s(Token, keccak256('Token'), false, false), ! forReplace); + addModule( modules_s(Premium, keccak256('Premium'), false, false), ! forReplace); + addModule( modules_s(Publisher, keccak256('Publisher'), false, true), ! forReplace); + addModule( modules_s(Schelling, keccak256('Schelling'), false, true), ! forReplace); + addModule( modules_s(Provider, keccak256('Provider'), true, true), ! forReplace); } function addModule(modules_s input, bool call) internal { /* Inside function for registration of the modules in the database. - If the call is false, wont happen any direct call. + If the call is false, won't happen any direct call. @input _Structure of module. @call Is connect to the module or not. */ if ( call ) { require( abstractModule(input.addr).connectModule() ); } - var (success, found, id) = getModuleIDByAddress(input.addr); + (bool success, bool found, uint256 id) = getModuleIDByAddress(input.addr); require( success && ! found ); (success, found, id) = getModuleIDByHash(input.name); require( success && ! found ); - (success, found, id) = getModuleIDByAddress(0x00); + (success, found, id) = getModuleIDByAddress(address(0x00)); require( success ); if ( ! found ) { id = modules.length; @@ -81,20 +81,20 @@ contract moduleHandler is multiOwner, announcementTypes { } modules[id] = input; } - function getModuleAddressByName(string name) public constant returns( bool success, bool found, address addr ) { + function getModuleAddressByName(string name) public view returns( bool success, bool found, address addr ) { /* Search by name for module. The result is an Ethereum address. @name Name of module. @addr Address of module. @found Is there any result. - @success Was the transaction succesfull or not. + @success Was the transaction successful or not. */ - var (_success, _found, _id) = getModuleIDByName(name); + (bool _success, bool _found, uint256 _id) = getModuleIDByName(name); if ( _success && _found ) { return (true, true, modules[_id].addr); } - return (true, false, 0x00); + return (true, false, address(0x00)); } - function getModuleIDByHash(bytes32 hashOfName) public constant returns( bool success, bool found, uint256 id ) { + function getModuleIDByHash(bytes32 hashOfName) public view returns( bool success, bool found, uint256 id ) { /* Search by hash of name in the module array. The result is an index array. @@ -109,7 +109,7 @@ contract moduleHandler is multiOwner, announcementTypes { } return (true, false, 0); } - function getModuleIDByName(string name) public constant returns( bool success, bool found, uint256 id ) { + function getModuleIDByName(string name) public view returns( bool success, bool found, uint256 id ) { /* Search by name for module. The result is an index array. @@ -117,7 +117,7 @@ contract moduleHandler is multiOwner, announcementTypes { @id Index of module. @found Was there any result or not. */ - bytes32 _name = sha3(name); + bytes32 _name = keccak256(bytes(name)); for ( uint256 a=0 ; a<modules.length ; a++ ) { if ( modules[a].name == _name ) { return (true, true, a); @@ -125,7 +125,7 @@ contract moduleHandler is multiOwner, announcementTypes { } return (true, false, 0); } - function getModuleIDByAddress(address addr) public constant returns( bool success, bool found, uint256 id ) { + function getModuleIDByAddress(address addr) public view returns( bool success, bool found, uint256 id ) { /* Search by ethereum address for module. The result is an index array. @@ -149,11 +149,11 @@ contract moduleHandler is multiOwner, announcementTypes { @bool Was there any result or not. @callCallback Call the replaceable module to confirm replacement or not. */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); require( _success ); - if ( ! ( _found && modules[_id].name == sha3('Publisher') )) { + if ( ! ( _found && modules[_id].name == keccak256('Publisher') )) { require( block.number < debugModeUntil ); - if ( ! insertAndCheckDo(calcDoHash("replaceModule", sha3(name, addr, callCallback))) ) { + if ( ! insertAndCheckDo(calcDoHash("replaceModule", keccak256(abi.encodePacked(name, addr, callCallback)))) ) { return true; } } @@ -169,10 +169,10 @@ contract moduleHandler is multiOwner, announcementTypes { function callReplaceCallback(string moduleName, address newModule) external returns (bool success) { require( block.number < debugModeUntil ); - if ( ! insertAndCheckDo(calcDoHash("callReplaceCallback", sha3(moduleName, newModule))) ) { + if ( ! insertAndCheckDo(calcDoHash("callReplaceCallback", keccak256(abi.encodePacked(moduleName, newModule)))) ) { return true; } - var (_success, _found, _id) = getModuleIDByName(moduleName); + (bool _success, bool _found, uint256 _id) = getModuleIDByName(moduleName); require( _success); require( abstractModule(modules[_id].addr).replaceModule(newModule) ); return true; @@ -188,15 +188,15 @@ contract moduleHandler is multiOwner, announcementTypes { @transferEvent Gets it new transaction notification? @bool Was there any result or not. */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); require( _success ); - if ( ! ( _found && modules[_id].name == sha3('Publisher') )) { + if ( ! ( _found && modules[_id].name == keccak256('Publisher') )) { require( block.number < debugModeUntil ); - if ( ! insertAndCheckDo(calcDoHash("newModule", sha3(name, addr, schellingEvent, transferEvent))) ) { + if ( ! insertAndCheckDo(calcDoHash("newModule", keccak256(abi.encodePacked(name, addr, schellingEvent, transferEvent)))) ) { return true; } } - addModule( modules_s(addr, sha3(name), schellingEvent, transferEvent), true); + addModule( modules_s(addr, keccak256(bytes(name)), schellingEvent, transferEvent), true); return true; } function dropModule(string name, bool callCallback) external returns (bool success) { @@ -204,14 +204,14 @@ contract moduleHandler is multiOwner, announcementTypes { Deleting module from the database. Can be called only by the Publisher contract. @name Name of module to delete. - @bool Was the function successfull? + @bool Was the function successful? @callCallback Call the replaceable module to confirm replacement or not. */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); require( _success ); - if ( ! ( _found && modules[_id].name == sha3('Publisher') )) { + if ( ! ( _found && modules[_id].name == keccak256('Publisher') )) { require( block.number < debugModeUntil ); - if ( ! insertAndCheckDo(calcDoHash("replaceModule", sha3(name, callCallback))) ) { + if ( ! insertAndCheckDo(calcDoHash("replaceModule", keccak256(abi.encodePacked(name, callCallback)))) ) { return true; } } @@ -226,10 +226,10 @@ contract moduleHandler is multiOwner, announcementTypes { function callDisableCallback(string moduleName) external returns (bool success) { require( block.number < debugModeUntil ); - if ( ! insertAndCheckDo(calcDoHash("callDisableCallback", sha3(moduleName))) ) { + if ( ! insertAndCheckDo(calcDoHash("callDisableCallback", keccak256(bytes(moduleName)))) ) { return true; } - var (_success, _found, _id) = getModuleIDByName(moduleName); + (bool _success, bool _found, uint256 _id) = getModuleIDByName(moduleName); require( _success); require( abstractModule(modules[_id].addr).disableModule(true) ); return true; @@ -245,10 +245,10 @@ contract moduleHandler is multiOwner, announcementTypes { @from from who. @to to who. @value amount. - @bool Was the function successfull? + @bool Was the function successful? */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); - require( _success && _found && modules[_id].name == sha3('Token') ); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); + require( _success && _found && modules[_id].name == keccak256('Token') ); for ( uint256 a=0 ; a<modules.length ; a++ ) { if ( modules[a].transferEvent && abstractModule(modules[a].addr).isActive() ) { require( abstractModule(modules[a].addr).transferEvent(from, to, value) ); @@ -264,10 +264,10 @@ contract moduleHandler is multiOwner, announcementTypes { @roundID Number of Schelling round. @reward Coin emission in this Schelling round. - @bool Was the function successfull? + @bool Was the function successful? */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); - require( _success && _found && modules[_id].name == sha3('Schelling') ); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); + require( _success && _found && modules[_id].name == keccak256('Schelling') ); for ( uint256 a=0 ; a<modules.length ; a++ ) { if ( modules[a].schellingEvent && abstractModule(modules[a].addr).isActive() ) { require( abstractModule(modules[a].addr).newSchellingRoundEvent(roundID, reward) ); @@ -283,13 +283,13 @@ contract moduleHandler is multiOwner, announcementTypes { Every module will be informed about the ModuleHandler replacement. @newHandler Address of the new ModuleHandler. - @bool Was the function successfull? + @bool Was the function successful? */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); require( _success ); - if ( ! ( _found && modules[_id].name == sha3('Publisher') )) { + if ( ! ( _found && modules[_id].name == keccak256('Publisher') )) { require( block.number < debugModeUntil ); - if ( ! insertAndCheckDo(calcDoHash("replaceModuleHandler", sha3(newHandler))) ) { + if ( ! insertAndCheckDo(calcDoHash("replaceModuleHandler", keccak256(abi.encodePacked(newHandler)))) ) { return true; } } @@ -298,48 +298,48 @@ contract moduleHandler is multiOwner, announcementTypes { } return true; } - function balanceOf(address owner) public constant returns (bool success, uint256 value) { + function balanceOf(address owner) public view returns (bool success, uint256 value) { /* Query of token balance. @owner address @value balance. - @success was the function successfull? + @success was the function successful? */ - var (_success, _found, _id) = getModuleIDByName('Token'); + (bool _success, bool _found, uint256 _id) = getModuleIDByName('Token'); require( _success && _found ); return (true, token(modules[_id].addr).balanceOf(owner)); } - function totalSupply() public constant returns (bool success, uint256 value) { + function totalSupply() public view returns (bool success, uint256 value) { /* Query of the whole token amount. @value amount. - @success was the function successfull? + @success was the function successful? */ - var (_success, _found, _id) = getModuleIDByName('Token'); + (bool _success, bool _found, uint256 _id) = getModuleIDByName('Token'); require( _success && _found ); return (true, token(modules[_id].addr).totalSupply()); } - function isICO() public constant returns (bool success, bool ico) { + function isICO() public view returns (bool success, bool ico) { /* Query of ICO state @ico Is ICO in progress?. - @success was the function successfull? + @success was the function successful? */ - var (_success, _found, _id) = getModuleIDByName('Token'); + (bool _success, bool _found, uint256 _id) = getModuleIDByName('Token'); require( _success && _found ); return (true, token(modules[_id].addr).isICO()); } - function getCurrentSchellingRoundID() public constant returns (bool success, uint256 round) { + function getCurrentSchellingRoundID() public view returns (bool success, uint256 round) { /* Query of number of the actual Schelling round. @round Schelling round. - @success was the function successfull? + @success was the function successful? */ - var (_success, _found, _id) = getModuleIDByName('Schelling'); + (bool _success, bool _found, uint256 _id) = getModuleIDByName('Schelling'); require( _success && _found ); return (true, schelling(modules[_id].addr).getCurrentSchellingRoundID()); } @@ -350,10 +350,10 @@ contract moduleHandler is multiOwner, announcementTypes { @to Place of new token @value Token amount - @success Was the function successfull? + @success Was the function successful? */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); - require( _success && _found && modules[_id].name == sha3('Provider') ); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); + require( _success && _found && modules[_id].name == keccak256('Provider') ); (_success, _found, _id) = getModuleIDByName('Token'); require( _success && _found ); require( token(modules[_id].addr).mint(to, value) ); @@ -367,9 +367,9 @@ contract moduleHandler is multiOwner, announcementTypes { @to To who. @value Token amount. @fee Transaction fee will be charged or not? - @success Was the function successfull? + @success Was the function successful? */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); require( _success && _found ); (_success, _found, _id) = getModuleIDByName('Token'); require( _success && _found ); @@ -382,10 +382,10 @@ contract moduleHandler is multiOwner, announcementTypes { @from From who. @value Token amount. - @success Was the function successfull? + @success Was the function successful? */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); - require( _success && _found && modules[_id].name == sha3('Provider') ); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); + require( _success && _found && modules[_id].name == keccak256('Provider') ); (_success, _found, _id) = getModuleIDByName('Token'); require( _success && _found ); require( token(modules[_id].addr).processTransactionFee(from, value) ); @@ -397,10 +397,10 @@ contract moduleHandler is multiOwner, announcementTypes { @from From who. @value Token amount. - @success Was the function successfull? + @success Was the function successful? */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); - require( _success && _found && modules[_id].name == sha3('Schelling') ); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); + require( _success && _found && modules[_id].name == keccak256('Schelling') ); (_success, _found, _id) = getModuleIDByName('Token'); require( _success && _found ); require( token(modules[_id].addr).burn(from, value) ); @@ -413,13 +413,13 @@ contract moduleHandler is multiOwner, announcementTypes { @moduleName Module name which will be configured @aType Type of variable (announcementType). @value New value - @success Was the function successfull? + @success Was the function successful? */ - var (_success, _found, _id) = getModuleIDByAddress(msg.sender); + (bool _success, bool _found, uint256 _id) = getModuleIDByAddress(msg.sender); require( _success ); - if ( ! ( _found && modules[_id].name == sha3('Publisher') )) { + if ( ! ( _found && modules[_id].name == keccak256('Publisher') )) { require( block.number < debugModeUntil ); - if ( ! insertAndCheckDo(calcDoHash("configureModule", sha3(moduleName, aType, value))) ) { + if ( ! insertAndCheckDo(calcDoHash("configureModule", keccak256(abi.encodePacked(moduleName, aType, value)))) ) { return true; } } @@ -431,13 +431,13 @@ contract moduleHandler is multiOwner, announcementTypes { function freezing(bool forever) external { /* Freezing CORION Platform. Can be called only by the owner. - Freez can not be recalled! + Freeze can not be recalled! @forever Is it forever or not? */ require( owners[msg.sender] ); if ( forever ) { - if ( ! insertAndCheckDo(calcDoHash("freezing", sha3(forever))) ) { + if ( ! insertAndCheckDo(calcDoHash("freezing", keccak256(abi.encodePacked(forever)))) ) { return; } } diff --git a/test/compilationTests/corion/multiOwner.sol b/test/compilationTests/corion/multiOwner.sol index 9aae0ebd..337467db 100644 --- a/test/compilationTests/corion/multiOwner.sol +++ b/test/compilationTests/corion/multiOwner.sol @@ -12,7 +12,7 @@ contract multiOwner is safeMath { /* Constructor */ - function multiOwner(address[] newOwners) { + constructor(address[] newOwners) public { for ( uint256 a=0 ; a<newOwners.length ; a++ ) { _addOwner(newOwners[a]); } @@ -21,12 +21,12 @@ contract multiOwner is safeMath { Externals */ function insertOwner(address addr) external { - if ( insertAndCheckDo(calcDoHash("insertOwner", sha3(addr))) ) { + if ( insertAndCheckDo(calcDoHash("insertOwner", keccak256(abi.encodePacked(addr)))) ) { _addOwner(addr); } } function dropOwner(address addr) external { - if ( insertAndCheckDo(calcDoHash("dropOwner", sha3(addr))) ) { + if ( insertAndCheckDo(calcDoHash("dropOwner", keccak256(abi.encodePacked(addr)))) ) { _delOwner(addr); } } @@ -38,13 +38,13 @@ contract multiOwner is safeMath { /* Constants */ - function ownersForChange() public constant returns (uint256 owners) { + function ownersForChange() public view returns (uint256 owners) { return ownerCount * 75 / 100; } - function calcDoHash(string job, bytes32 data) public constant returns (bytes32 hash) { - return sha3(job, data); + function calcDoHash(string job, bytes32 data) public pure returns (bytes32 hash) { + return keccak256(abi.encodePacked(job, data)); } - function validDoHash(bytes32 doHash) public constant returns (bool valid) { + function validDoHash(bytes32 doHash) public view returns (bool valid) { return doDB[doHash].length > 0; } /* diff --git a/test/compilationTests/corion/owned.sol b/test/compilationTests/corion/owned.sol index bd187775..4a5ba673 100644 --- a/test/compilationTests/corion/owned.sol +++ b/test/compilationTests/corion/owned.sol @@ -20,7 +20,7 @@ contract ownedDB { @bool Owner has called the contract or not
*/
- if ( owner == 0x00 ) {
+ if ( owner == address(0x00) ) {
return true;
}
return owner == msg.sender;
diff --git a/test/compilationTests/corion/premium.sol b/test/compilationTests/corion/premium.sol index be2c5de0..e1f12ed0 100644 --- a/test/compilationTests/corion/premium.sol +++ b/test/compilationTests/corion/premium.sol @@ -19,7 +19,7 @@ contract premium is module, safeMath { return true; } modifier isReady { - var (_success, _active) = super.isActive(); + (bool _success, bool _active) = super.isActive(); require( _success && _active ); _; } @@ -39,8 +39,8 @@ contract premium is module, safeMath { bool public isICO; mapping(address => bool) public genesis; - - function premium(bool forReplace, address moduleHandler, address dbAddress, address icoContractAddr, address[] genesisAddr, uint256[] genesisValue) { + + constructor(bool forReplace, address moduleHandler, address dbAddress, address icoContractAddr, address[] genesisAddr, uint256[] genesisValue) public { /* Setup function. If an ICOaddress is defined then the balance of the genesis addresses will be set as well. @@ -53,7 +53,7 @@ contract premium is module, safeMath { @genesisValue Array of the balance of the genesis addresses */ super.registerModuleHandler(moduleHandler); - require( dbAddress != 0x00 ); + require( dbAddress != address(0x00) ); db = ptokenDB(dbAddress); if ( ! forReplace ) { require( db.replaceOwner(this) ); @@ -63,7 +63,7 @@ contract premium is module, safeMath { for ( uint256 a=0 ; a<genesisAddr.length ; a++ ) { genesis[genesisAddr[a]] = true; require( db.increase(genesisAddr[a], genesisValue[a]) ); - Mint(genesisAddr[a], genesisValue[a]); + emit Mint(genesisAddr[a], genesisValue[a]); } } } @@ -118,7 +118,7 @@ contract premium is module, safeMath { @extraData Extra data to be received by the receiver @nonce Transaction count - @sucess Was the Function successful? + @success Was the Function successful? */ _approve(spender, amount, nonce); require( thirdPartyPContractAbstract(spender).approvedCorionPremiumToken(msg.sender, amount, extraData) ); @@ -137,10 +137,10 @@ contract premium is module, safeMath { require( msg.sender != spender ); require( db.balanceOf(msg.sender) >= amount ); require( db.setAllowance(msg.sender, spender, amount, nonce) ); - Approval(msg.sender, spender, amount); + emit Approval(msg.sender, spender, amount); } - - function allowance(address owner, address spender) constant returns (uint256 remaining, uint256 nonce) { + + function allowance(address owner, address spender) public view returns (uint256 remaining, uint256 nonce) { /* Get the quantity of tokens given to be used @@ -150,7 +150,7 @@ contract premium is module, safeMath { @remaining Tokens to be spent @nonce Transaction count */ - var (_success, _remaining, _nonce) = db.getAllowance(owner, spender); + (bool _success, uint256 _remaining, uint256 _nonce) = db.getAllowance(owner, spender); require( _success ); return (_remaining, _nonce); } @@ -178,7 +178,7 @@ contract premium is module, safeMath { } else { _transfer(msg.sender, to, amount); } - Transfer(msg.sender, to, amount, _data); + emit Transfer(msg.sender, to, amount, _data); return true; } @@ -202,12 +202,12 @@ contract premium is module, safeMath { @success If the function was successful. */ if ( from != msg.sender ) { - var (_success, _reamining, _nonce) = db.getAllowance(from, msg.sender); + (bool _success, uint256 _reamining, uint256 _nonce) = db.getAllowance(from, msg.sender); require( _success ); _reamining = safeSub(_reamining, amount); _nonce = safeAdd(_nonce, 1); require( db.setAllowance(from, msg.sender, _reamining, _nonce) ); - AllowanceUsed(msg.sender, from, amount); + emit AllowanceUsed(msg.sender, from, amount); } bytes memory _data; if ( isContract(to) ) { @@ -215,7 +215,7 @@ contract premium is module, safeMath { } else { _transfer( from, to, amount); } - Transfer(from, to, amount, _data); + emit Transfer(from, to, amount, _data); return true; } @@ -242,7 +242,7 @@ contract premium is module, safeMath { } else { _transfer( msg.sender, to, amount); } - Transfer(msg.sender, to, amount, extraData); + emit Transfer(msg.sender, to, amount, extraData); return true; } @@ -255,7 +255,7 @@ contract premium is module, safeMath { @extraData Extra data that will be given to the receiver */ _transfer(from, to, amount); - var (_success, _back) = thirdPartyPContractAbstract(to).receiveCorionPremiumToken(from, amount, extraData); + (bool _success, uint256 _back) = thirdPartyPContractAbstract(to).receiveCorionPremiumToken(from, amount, extraData); require( _success ); require( amount > _back ); if ( _back > 0 ) { @@ -273,7 +273,7 @@ contract premium is module, safeMath { @to For who? @amount Amount */ - require( from != 0x00 && to != 0x00 && to != 0xa636a97578d26a3b76b060bbc18226d954cf3757 ); + require( from != address(0x00) && to != address(0x00) && to != 0xa636A97578d26A3b76B060Bbc18226d954cf3757 ); require( ( ! isICO) || genesis[from] ); require( db.decrease(from, amount) ); require( db.increase(to, amount) ); @@ -301,7 +301,7 @@ contract premium is module, safeMath { @value Amount */ require( db.increase(owner, value) ); - Mint(owner, value); + emit Mint(owner, value); } function isContract(address addr) internal returns (bool success) { @@ -318,8 +318,8 @@ contract premium is module, safeMath { } return _codeLength > 0; } - - function balanceOf(address owner) constant returns (uint256 value) { + + function balanceOf(address owner) public view returns (uint256 value) { /* Token balance query @@ -328,8 +328,8 @@ contract premium is module, safeMath { */ return db.balanceOf(owner); } - - function totalSupply() constant returns (uint256 value) { + + function totalSupply() public view returns (uint256 value) { /* Total token quantity query diff --git a/test/compilationTests/corion/provider.sol b/test/compilationTests/corion/provider.sol index 5fa90fcd..35ade69f 100644 --- a/test/compilationTests/corion/provider.sol +++ b/test/compilationTests/corion/provider.sol @@ -12,13 +12,13 @@ contract provider is module, safeMath, announcementTypes { function connectModule() external returns (bool success) { require( super.isModuleHandler(msg.sender) ); super._connectModule(); - var (_success, currentSchellingRound) = moduleHandler(moduleHandlerAddress).getCurrentSchellingRoundID(); + (bool _success, uint256 currentSchellingRound) = moduleHandler(moduleHandlerAddress).getCurrentSchellingRoundID(); require( _success ); return true; } function transferEvent(address from, address to, uint256 value) external returns (bool success) { /* - Transaction completed. This function is ony available for the modulehandler. + Transaction completed. This function is only available for the modulehandler. It should be checked if the sender or the acceptor does not connect to the provider or it is not a provider itself if so than the change should be recorded. @from From whom? @@ -35,7 +35,7 @@ contract provider is module, safeMath, announcementTypes { /* New schelling round. This function is only available for the moduleHandler. We are recording the new schelling round and we are storing the whole current quantity of the tokens. - We generate a reward quantity of tokens directed to the providers address. The collected interest will be tranfered from this contract. + We generate a reward quantity of tokens directed to the providers address. The collected interest will be transferred from this contract. @roundID Number of the schelling round. @reward token emission @@ -49,7 +49,7 @@ contract provider is module, safeMath, announcementTypes { return true; } modifier isReady { - var (_success, _active) = super.isActive(); + (bool _success, bool _active) = super.isActive(); require( _success && _active ); _; } @@ -118,7 +118,7 @@ contract provider is module, safeMath, announcementTypes { uint256 private currentSchellingRound = 1; - function provider(address _moduleHandler) { + constructor(address _moduleHandler) public { /* Install function. @@ -147,7 +147,7 @@ contract provider is module, safeMath, announcementTypes { else { return false; } return true; } - function getUserDetails(address addr, uint256 schellingRound) public constant returns (address ProviderAddress, uint256 ProviderHeight, uint256 ConnectedOn, uint256 value) { + function getUserDetails(address addr, uint256 schellingRound) public view returns (address ProviderAddress, uint256 ProviderHeight, uint256 ConnectedOn, uint256 value) { /* Collecting the datas of the client. @@ -161,14 +161,14 @@ contract provider is module, safeMath, announcementTypes { if ( schellingRound == 0 ) { schellingRound = currentSchellingRound; } - if ( clients[addr].providerAddress != 0 ) { + if ( clients[addr].providerAddress != address(0x00) ) { ProviderAddress = clients[addr].providerAddress; ProviderHeight = clients[addr].providerHeight; ConnectedOn = clients[addr].providerConnected; value = clients[addr].supply[schellingRound]; } } - function rightForInterest(uint256 value, bool priv) internal returns (bool) { + function rightForInterest(uint256 value, bool priv) internal view returns (bool) { /* the share from the token emission. In case is a private provider it has to be checked if it has enough connected capital to be able to accept share from the token emission. @@ -192,8 +192,8 @@ contract provider is module, safeMath, announcementTypes { @newValue new @priv Is the provider private? */ - var a = rightForInterest(oldValue, priv); - var b = rightForInterest(newValue, priv); + bool a = rightForInterest(oldValue, priv); + bool b = rightForInterest(newValue, priv); if ( a && b ) { globalFunds[currentSchellingRound].supply = globalFunds[currentSchellingRound].supply - oldValue + newValue; } else if ( a && ! b ) { @@ -228,12 +228,12 @@ contract provider is module, safeMath, announcementTypes { @website Provider’s website @country Provider’s country @info Provider’s short introduction. - @rate Rate of the emission what is going to be transfered to the client by the provider. + @rate Rate of the emission what is going to be transferred to the client by the provider. @isForRent is for Rent or not? @admin The admin’s address */ require( ! providers[msg.sender].data[providers[msg.sender].currentHeight].valid ); - require( clients[msg.sender].providerAddress == 0x00 ); + require( clients[msg.sender].providerAddress == address(0x00) ); require( ! checkICO() ); if ( priv ) { require( getTokenBalance(msg.sender) >= minFundsForPrivate ); @@ -243,9 +243,9 @@ contract provider is module, safeMath, announcementTypes { require( checkCorrectRate(priv, rate) ); providers[msg.sender].currentHeight++; - var currHeight = providers[msg.sender].currentHeight; + uint256 currHeight = providers[msg.sender].currentHeight; providers[msg.sender].data[currHeight].valid = true; - if ( admin == 0x00 ) { + if ( admin == address(0x00) ) { providers[msg.sender].data[currHeight].admin = msg.sender; } else { providers[msg.sender].data[currHeight].admin = admin; @@ -268,7 +268,7 @@ contract provider is module, safeMath, announcementTypes { } else { delete providers[msg.sender].data[currHeight].supply[currentSchellingRound]; } - EProviderOpen(msg.sender, currHeight); + emit EProviderOpen(msg.sender, currHeight); } function setProviderDetails(address addr, string website, string country, string info, uint8 rate, address admin) isReady external { /* @@ -284,11 +284,11 @@ contract provider is module, safeMath, announcementTypes { @info Short intro. @rate Rate of the emission what will be given to the client. */ - var currHeight = providers[addr].currentHeight; + uint256 currHeight = providers[addr].currentHeight; require( providers[addr].data[currHeight].valid ); require( checkCorrectRate(providers[addr].data[currHeight].priv, rate) ); require( providers[addr].data[currHeight].admin == msg.sender || msg.sender == addr ); - if ( admin != 0x00 ) { + if ( admin != address(0x00) ) { require( msg.sender == addr ); providers[addr].data[currHeight].admin = admin; } @@ -297,9 +297,9 @@ contract provider is module, safeMath, announcementTypes { providers[addr].data[currHeight].country = country; providers[addr].data[currHeight].info = info; providers[addr].data[currHeight].currentRate = rate; - EProviderDetailsChanged(addr, currHeight, website, country, info, rate, admin); + emit EProviderDetailsChanged(addr, currHeight, website, country, info, rate, admin); } - function getProviderInfo(address addr, uint256 height) public constant returns (string name, string website, string country, string info, uint256 create) { + function getProviderInfo(address addr, uint256 height) public view returns (string name, string website, string country, string info, uint256 create) { /* for the infos of the provider. In case the height is unknown then the system will use the last known height. @@ -321,14 +321,14 @@ contract provider is module, safeMath, announcementTypes { info = providers[addr].data[height].info; create = providers[addr].data[height].create; } - function getProviderDetails(address addr, uint256 height) public constant returns (uint8 rate, bool isForRent, uint256 clientsCount, bool priv, bool getInterest, bool valid) { + function getProviderDetails(address addr, uint256 height) public view returns (uint8 rate, bool isForRent, uint256 clientsCount, bool priv, bool getInterest, bool valid) { /* Asking for the datas of the provider. In case the height is unknown then the system will use the last known height. @addr Address of the provider @height Height - @rate The rate of the emission which will be transfered to the client. + @rate The rate of the emission which will be transferred to the client. @isForRent Rent or not. @clientsCount Number of the clients. @priv Private or not? @@ -345,7 +345,7 @@ contract provider is module, safeMath, announcementTypes { getInterest = rightForInterest(getProviderCurrentSupply(addr), providers[addr].data[height].priv ); valid = providers[addr].data[height].valid; } - function getProviderCurrentSupply(address addr) internal returns (uint256) { + function getProviderCurrentSupply(address addr) internal view returns (uint256) { /* Inner function for polling the current height and the current quantity of the connected capital of the schelling round. @@ -356,28 +356,28 @@ contract provider is module, safeMath, announcementTypes { } function closeProvider() isReady external { /* - Closing and inactivate the provider. + Closing and deactivating the provider. It is only possible to close that active provider which is owned by the sender itself after calling the whole share of the emission. Whom were connected to the provider those clients will have to disconnect after they’ve called their share of emission which was not called before. */ - var currHeight = providers[msg.sender].currentHeight; + uint256 currHeight = providers[msg.sender].currentHeight; require( providers[msg.sender].data[currHeight].valid ); require( providers[msg.sender].data[currHeight].paidUpTo == currentSchellingRound ); providers[msg.sender].data[currHeight].valid = false; providers[msg.sender].data[currHeight].close = currentSchellingRound; setRightForInterest(getProviderCurrentSupply(msg.sender), 0, providers[msg.sender].data[currHeight].priv); - EProviderClose(msg.sender, currHeight); + emit EProviderClose(msg.sender, currHeight); } function allowUsers(address provider, address[] addr) isReady external { /* Permition of the user to be able to connect to the provider. This can only be invited by the provider’s admin. - With this kind of call only 100 address can be permited. + With this kind of call only 100 address can be permitted. @addr Array of the addresses for whom the connection is allowed. */ - var currHeight = providers[provider].currentHeight; + uint256 currHeight = providers[provider].currentHeight; require( providers[provider].data[currHeight].valid ); require( providers[provider].data[currHeight].priv ); require( providers[provider].data[currHeight].admin == msg.sender ); @@ -391,11 +391,11 @@ contract provider is module, safeMath, announcementTypes { /* Disable of the user not to be able to connect to the provider. It is can called only for the admin of the provider. - With this kind of call only 100 address can be permited. + With this kind of call only 100 address can be permitted. @addr Array of the addresses for whom the connection is allowed. */ - var currHeight = providers[provider].currentHeight; + uint256 currHeight = providers[provider].currentHeight; require( providers[provider].data[currHeight].valid ); require( providers[provider].data[currHeight].priv ); require( providers[provider].data[currHeight].admin == msg.sender ); @@ -411,21 +411,21 @@ contract provider is module, safeMath, announcementTypes { Providers can not connect to other providers. If is a client at any provider, then it is not possible to connect to other provider one. It is only possible to connect to valid and active providers. - If is an active provider then the client can only connect, if address is permited at the provider (Whitelist). + If is an active provider then the client can only connect, if address is permitted at the provider (Whitelist). At private providers, the number of the client is restricted. If it reaches the limit no further clients are allowed to connect. This process has a transaction fee based on the senders whole token quantity. @provider Address of the provider. */ - var currHeight = providers[provider].currentHeight; + uint256 currHeight = providers[provider].currentHeight; require( ! providers[msg.sender].data[currHeight].valid ); - require( clients[msg.sender].providerAddress == 0x00 ); + require( clients[msg.sender].providerAddress == address(0x00) ); require( providers[provider].data[currHeight].valid ); if ( providers[provider].data[currHeight].priv ) { require( providers[provider].data[currHeight].allowedUsers[msg.sender] && providers[provider].data[currHeight].clientsCount < privateProviderLimit ); } - var bal = getTokenBalance(msg.sender); + uint256 bal = getTokenBalance(msg.sender); require( moduleHandler(moduleHandlerAddress).processTransactionFee(msg.sender, bal) ); checkFloatingSupply(provider, currHeight, false, bal); @@ -437,7 +437,7 @@ contract provider is module, safeMath, announcementTypes { clients[msg.sender].paidUpTo = currentSchellingRound; clients[msg.sender].lastRate = providers[provider].data[currHeight].currentRate; clients[msg.sender].providerConnected = now; - ENewClient(msg.sender, provider, currHeight, bal); + emit ENewClient(msg.sender, provider, currHeight, bal); } function partProvider() isReady external { /* @@ -445,9 +445,9 @@ contract provider is module, safeMath, announcementTypes { Before disconnecting we should poll our share from the token emission even if there was nothing factually. It is only possible to disconnect those providers who were connected by us before. */ - var provider = clients[msg.sender].providerAddress; - require( provider != 0x0 ); - var currHeight = clients[msg.sender].providerHeight; + address provider = clients[msg.sender].providerAddress; + require( provider != address(0x00) ); + uint256 currHeight = clients[msg.sender].providerHeight; bool providerHasClosed = false; if ( providers[provider].data[currHeight].close > 0 ) { providerHasClosed = true; @@ -456,7 +456,7 @@ contract provider is module, safeMath, announcementTypes { require( clients[msg.sender].paidUpTo == currentSchellingRound ); } - var bal = getTokenBalance(msg.sender); + uint256 bal = getTokenBalance(msg.sender); if ( ! providerHasClosed ) { providers[provider].data[currHeight].clientsCount--; checkFloatingSupply(provider, currHeight, true, bal); @@ -467,9 +467,9 @@ contract provider is module, safeMath, announcementTypes { delete clients[msg.sender].paidUpTo; delete clients[msg.sender].lastRate; delete clients[msg.sender].providerConnected; - EClientLost(msg.sender, provider, currHeight, bal); + emit EClientLost(msg.sender, provider, currHeight, bal); } - function checkReward(address addr) public constant returns (uint256 reward) { + function checkReward(address addr) public returns (uint256 reward) { /* Polling the share from the token emission for clients and for providers. @@ -479,7 +479,7 @@ contract provider is module, safeMath, announcementTypes { if ( providers[addr].data[providers[addr].currentHeight].valid ) { uint256 a; (reward, a) = getProviderReward(addr, 0); - } else if ( clients[addr].providerAddress != 0x0 ) { + } else if ( clients[addr].providerAddress != address(0x00) ) { reward = getClientReward(0); } } @@ -487,12 +487,12 @@ contract provider is module, safeMath, announcementTypes { /* Polling the share from the token emission token emission for clients and for providers. - It is optionaly possible to give an address of a beneficiary for whom we can transfer the accumulated amount. In case we don’t enter any address then the amount will be transfered to the caller’s address. + It is optionally possible to give an address of a beneficiary for whom we can transfer the accumulated amount. In case we don’t enter any address then the amount will be transferred to the caller’s address. As the interest should be checked at each schelling round in order to get the share from that so to avoid the overflow of the gas the number of the check-rounds should be limited. - Opcionalisan megadhato az ellenorzes koreinek szama. It is possible to enter optionaly the number of the check-rounds. If it is 0 then it is automatic. + Opcionalisan megadhato az ellenorzes koreinek szama. It is possible to enter optionally the number of the check-rounds. If it is 0 then it is automatic. Provider variable should only be entered if the real owner of the provider is not the caller’s address. In case the client/provider was far behind then it is possible that this function should be called several times to check the total generated schelling rounds and to collect the share. - If is neighter a client nor a provider then the function is not available. + If is neither a client nor a provider then the function is not available. The tokens will be sent to the beneficiary from the address of the provider without any transaction fees. @beneficiary Address of the beneficiary @@ -500,18 +500,18 @@ contract provider is module, safeMath, announcementTypes { @provider Address of the provider @reward Accumulated amount from the previous rounds. */ - var _limit = limit; - var _beneficiary = beneficiary; - var _provider = provider; + uint256 _limit = limit; + address _beneficiary = beneficiary; + address _provider = provider; if ( _limit == 0 ) { _limit = gasProtectMaxRounds; } - if ( _beneficiary == 0x00 ) { _beneficiary = msg.sender; } - if ( _provider == 0x00 ) { _provider = msg.sender; } + if ( _beneficiary == address(0x00) ) { _beneficiary = msg.sender; } + if ( _provider == address(0x00) ) { _provider = msg.sender; } uint256 clientReward; uint256 providerReward; if ( providers[_provider].data[providers[_provider].currentHeight].valid ) { require( providers[_provider].data[providers[_provider].currentHeight].admin == msg.sender || msg.sender == _provider ); (providerReward, clientReward) = getProviderReward(_provider, _limit); - } else if ( clients[msg.sender].providerAddress != 0x00 ) { + } else if ( clients[msg.sender].providerAddress != address(0x00) ) { clientReward = getClientReward(_limit); } else { throw; @@ -522,7 +522,7 @@ contract provider is module, safeMath, announcementTypes { if ( providerReward > 0 ) { require( moduleHandler(moduleHandlerAddress).transfer(address(this), provider, providerReward, false) ); } - EReward(msg.sender, provider, clientReward, providerReward); + emit EReward(msg.sender, provider, clientReward, providerReward); } function getClientReward(uint256 limit) internal returns (uint256 reward) { /* @@ -536,8 +536,9 @@ contract provider is module, safeMath, announcementTypes { address provAddr; uint256 provHeight; bool interest = false; - var rate = clients[msg.sender].lastRate; - for ( uint256 a = (clients[msg.sender].paidUpTo + 1) ; a <= currentSchellingRound ; a++ ) { + uint256 a; + uint8 rate = clients[msg.sender].lastRate; + for ( a = (clients[msg.sender].paidUpTo + 1) ; a <= currentSchellingRound ; a++ ) { if (globalFunds[a].reward > 0 && globalFunds[a].supply > 0) { provAddr = clients[msg.sender].providerAddress; provHeight = clients[msg.sender].providerHeight; @@ -585,8 +586,9 @@ contract provider is module, safeMath, announcementTypes { uint256 steps; uint256 currHeight = providers[addr].currentHeight; uint256 LTSID = providers[addr].data[currHeight].lastSupplyID; - var rate = providers[addr].data[currHeight].lastPaidRate; - for ( uint256 a = (providers[addr].data[currHeight].paidUpTo + 1) ; a <= currentSchellingRound ; a++ ) { + uint256 a; + uint8 rate = providers[addr].data[currHeight].lastPaidRate; + for ( a = (providers[addr].data[currHeight].paidUpTo + 1) ; a <= currentSchellingRound ; a++ ) { if (globalFunds[a].reward > 0 && globalFunds[a].supply > 0) { if ( providers[addr].data[currHeight].rateHistory[a].valid ) { rate = providers[addr].data[currHeight].rateHistory[a].value; @@ -743,7 +745,7 @@ contract provider is module, safeMath, announcementTypes { @value Rate of the change. @neg ype of the change. If it is TRUE then the balance has been decreased if it is FALSE then it has been increased. */ - if ( clients[addr].providerAddress != 0 ) { + if ( clients[addr].providerAddress != address(0x00) ) { checkFloatingSupply(clients[addr].providerAddress, providers[clients[addr].providerAddress].currentHeight, ! neg, value); if (clients[addr].lastSupplyID != currentSchellingRound) { clients[addr].supply[currentSchellingRound] = TEMath(clients[addr].supply[clients[addr].lastSupplyID], value, neg); @@ -752,7 +754,7 @@ contract provider is module, safeMath, announcementTypes { clients[addr].supply[currentSchellingRound] = TEMath(clients[addr].supply[currentSchellingRound], value, neg); } } else if ( providers[addr].data[providers[addr].currentHeight].valid ) { - var currentHeight = providers[addr].currentHeight; + uint256 currentHeight = providers[addr].currentHeight; if ( neg ) { uint256 balance = getTokenBalance(addr); if ( providers[addr].data[currentHeight].priv ) { @@ -774,7 +776,7 @@ contract provider is module, safeMath, announcementTypes { @balance Balance of the address. */ - var (_success, _balance) = moduleHandler(moduleHandlerAddress).balanceOf(addr); + (bool _success, uint256 _balance) = moduleHandler(moduleHandlerAddress).balanceOf(addr); require( _success ); return _balance; } @@ -782,9 +784,9 @@ contract provider is module, safeMath, announcementTypes { /* Inner function to check the ICO status. - @isICO Is the ICO in proccess or not? + @isICO Is the ICO in process or not? */ - var (_success, _isICO) = moduleHandler(moduleHandlerAddress).isICO(); + (bool _success, bool _isICO) = moduleHandler(moduleHandlerAddress).isICO(); require( _success ); return _isICO; } diff --git a/test/compilationTests/corion/publisher.sol b/test/compilationTests/corion/publisher.sol index e94b9a92..44bc5964 100644 --- a/test/compilationTests/corion/publisher.sol +++ b/test/compilationTests/corion/publisher.sol @@ -60,8 +60,8 @@ contract publisher is announcementTypes, module, safeMath { uint256 announcementsLength = 1;
mapping (address => uint256[]) public opponents;
-
- function publisher(address moduleHandler) {
+
+ constructor(address moduleHandler) public {
/*
Installation function. The installer will be registered in the admin list automatically
@@ -70,7 +70,7 @@ contract publisher is announcementTypes, module, safeMath { super.registerModuleHandler(moduleHandler);
}
- function Announcements(uint256 id) public constant returns (uint256 Type, uint256 Start, uint256 End, bool Closed, string Announcement, string Link, bool Opposited, string _str, uint256 _uint, address _addr) {
+ function Announcements(uint256 id) public view returns (uint256 Type, uint256 Start, uint256 End, bool Closed, string Announcement, string Link, bool Opposited, string _str, uint256 _uint, address _addr) {
/*
Announcement data query
@@ -101,7 +101,7 @@ contract publisher is announcementTypes, module, safeMath { _addr = announcements[id]._addr;
}
- function checkOpposited(uint256 weight, bool oppositable) public constant returns (bool success) {
+ function checkOpposited(uint256 weight, bool oppositable) public view returns (bool success) {
/*
Veto check
@@ -111,7 +111,7 @@ contract publisher is announcementTypes, module, safeMath { @success Opposed or not
*/
if ( ! oppositable ) { return false; }
- var (_success, _amount) = moduleHandler(moduleHandlerAddress).totalSupply();
+ (bool _success, uint256 _amount) = moduleHandler(moduleHandlerAddress).totalSupply();
require( _success );
return _amount * oppositeRate / 100 > weight;
}
@@ -148,7 +148,7 @@ contract publisher is announcementTypes, module, safeMath { announcements[announcementsLength]._str = _str;
announcements[announcementsLength]._uint = _uint;
announcements[announcementsLength]._addr = _addr;
- ENewAnnouncement(announcementsLength, Type);
+ emit ENewAnnouncement(announcementsLength, Type);
}
function closeAnnouncement(uint256 id) onlyOwner external {
@@ -229,7 +229,7 @@ contract publisher is announcementTypes, module, safeMath { newArrayID = a;
}
}
- var (_success, _balance) = moduleHandler(moduleHandlerAddress).balanceOf(msg.sender);
+ (bool _success, uint256 _balance) = moduleHandler(moduleHandlerAddress).balanceOf(msg.sender);
require( _success );
require( _balance > 0);
if ( foundEmptyArrayID ) {
@@ -238,7 +238,7 @@ contract publisher is announcementTypes, module, safeMath { opponents[msg.sender].push(id);
}
announcements[id].oppositionWeight += _balance;
- EOppositeAnnouncement(id, msg.sender, _balance);
+ emit EOppositeAnnouncement(id, msg.sender, _balance);
}
function invalidateAnnouncement(uint256 id) onlyOwner external {
@@ -250,7 +250,7 @@ contract publisher is announcementTypes, module, safeMath { require( announcements[id].open );
announcements[id].end = block.number;
announcements[id].open = false;
- EInvalidateAnnouncement(id);
+ emit EInvalidateAnnouncement(id);
}
modifier onlyOwner() {
@@ -264,9 +264,9 @@ contract publisher is announcementTypes, module, safeMath { function checkICO() internal returns (bool isICO) {
/*
Inner function to check the ICO status.
- @bool Is the ICO in proccess or not?
+ @bool Is the ICO in process or not?
*/
- var (_success, _isICO) = moduleHandler(moduleHandlerAddress).isICO();
+ (bool _success, bool _isICO) = moduleHandler(moduleHandlerAddress).isICO();
require( _success );
return _isICO;
}
diff --git a/test/compilationTests/corion/schelling.sol b/test/compilationTests/corion/schelling.sol index 8c8e093c..b8beaa3a 100644 --- a/test/compilationTests/corion/schelling.sol +++ b/test/compilationTests/corion/schelling.sol @@ -37,7 +37,7 @@ contract schellingDB is safeMath, schellingVars { */ address private owner; function replaceOwner(address newOwner) external returns(bool) { - require( owner == 0x00 || msg.sender == owner ); + require( owner == address(0x00) || msg.sender == owner ); owner = newOwner; return true; } @@ -45,7 +45,7 @@ contract schellingDB is safeMath, schellingVars { /* Constructor */ - function schellingDB() { + constructor() public { rounds.length = 2; rounds[0].blockHeight = block.number; currentSchellingRound = 1; @@ -54,7 +54,7 @@ contract schellingDB is safeMath, schellingVars { Funds */ mapping(address => uint256) private funds; - function getFunds(address _owner) constant returns(bool, uint256) { + function getFunds(address _owner) public view returns(bool, uint256) { return (true, funds[_owner]); } function setFunds(address _owner, uint256 _amount) isOwner external returns(bool) { @@ -65,7 +65,7 @@ contract schellingDB is safeMath, schellingVars { Rounds */ _rounds[] private rounds; - function getRound(uint256 _id) constant returns(bool, uint256, uint256, uint256, uint256, bool) { + function getRound(uint256 _id) public view returns(bool, uint256, uint256, uint256, uint256, bool) { if ( rounds.length <= _id ) { return (false, 0, 0, 0, 0, false); } else { return (true, rounds[_id].totalAboveWeight, rounds[_id].totalBelowWeight, rounds[_id].reward, rounds[_id].blockHeight, rounds[_id].voted); } } @@ -76,14 +76,14 @@ contract schellingDB is safeMath, schellingVars { rounds[_id] = _rounds(_totalAboveWeight, _totalBelowWeight, _reward, _blockHeight, _voted); return true; } - function getCurrentRound() constant returns(bool, uint256) { + function getCurrentRound() public view returns(bool, uint256) { return (true, rounds.length-1); } /* Voter */ mapping(address => _voter) private voter; - function getVoter(address _owner) constant returns(bool success, uint256 roundID, + function getVoter(address _owner) public view returns(bool success, uint256 roundID, bytes32 hash, voterStatus status, bool voteResult, uint256 rewards) { roundID = voter[_owner].roundID; hash = voter[_owner].hash; @@ -106,7 +106,7 @@ contract schellingDB is safeMath, schellingVars { Schelling Token emission */ mapping(uint256 => uint256) private schellingExpansion; - function getSchellingExpansion(uint256 _id) constant returns(bool, uint256) { + function getSchellingExpansion(uint256 _id) public view returns(bool, uint256) { return (true, schellingExpansion[_id]); } function setSchellingExpansion(uint256 _id, uint256 _expansion) isOwner external returns(bool) { @@ -121,7 +121,7 @@ contract schellingDB is safeMath, schellingVars { currentSchellingRound = _id; return true; } - function getCurrentSchellingRound() constant returns(bool, uint256) { + function getCurrentSchellingRound() public view returns(bool, uint256) { return (true, currentSchellingRound); } } @@ -147,19 +147,19 @@ contract schelling is module, announcementTypes, schellingVars { @from From who @to To who @value Amount - @bool Was the transaction succesfull? + @bool Was the transaction successful? */ require( super.isModuleHandler(msg.sender) ); if ( to == address(this) ) { - var currentRound = getCurrentRound(); - var round = getRound(currentRound); + uint256 currentRound = getCurrentRound(); + schellingVars._rounds memory round = getRound(currentRound); round.reward += value; setRound(currentRound, round); } return true; } modifier isReady { - var (_success, _active) = super.isActive(); + (bool _success, bool _active) = super.isActive(); require( _success && _active ); _; } @@ -167,7 +167,7 @@ contract schelling is module, announcementTypes, schellingVars { Schelling database functions. */ function getFunds(address addr) internal returns (uint256) { - var (a, b) = db.getFunds(addr); + (bool a, uint256 b) = db.getFunds(addr); require( a ); return b; } @@ -183,8 +183,8 @@ contract schelling is module, announcementTypes, schellingVars { voter.rewards ) ); } - function getVoter(address addr) internal returns (_voter) { - var (a, b, c, d, e, f) = db.getVoter(addr); + function getVoter(address addr) internal view returns (_voter) { + (bool a, uint256 b, bytes32 c, schellingVars.voterStatus d, bool e, uint256 f) = db.getVoter(addr); require( a ); return _voter(b, c, d, e, f); } @@ -198,7 +198,7 @@ contract schelling is module, announcementTypes, schellingVars { ) ); } function pushRound(_rounds round) internal returns (uint256) { - var (a, b) = db.pushRound( + (bool a, uint256 b) = db.pushRound( round.totalAboveWeight, round.totalBelowWeight, round.reward, @@ -209,28 +209,28 @@ contract schelling is module, announcementTypes, schellingVars { return b; } function getRound(uint256 id) internal returns (_rounds) { - var (a, b, c, d, e, f) = db.getRound(id); + (bool a, uint256 b, uint256 c, uint256 d, uint256 e, bool f) = db.getRound(id); require( a ); return _rounds(b, c, d, e, f); } function getCurrentRound() internal returns (uint256) { - var (a, b) = db.getCurrentRound(); + (bool a, uint256 b) = db.getCurrentRound(); require( a ); return b; } function setCurrentSchellingRound(uint256 id) internal { require( db.setCurrentSchellingRound(id) ); } - function getCurrentSchellingRound() internal returns(uint256) { - var (a, b) = db.getCurrentSchellingRound(); + function getCurrentSchellingRound() internal view returns(uint256) { + (bool a, uint256 b) = db.getCurrentSchellingRound(); require( a ); return b; } function setSchellingExpansion(uint256 id, uint256 amount) internal { require( db.setSchellingExpansion(id, amount) ); } - function getSchellingExpansion(uint256 id) internal returns(uint256) { - var (a, b) = db.getSchellingExpansion(id); + function getSchellingExpansion(uint256 id) internal view returns(uint256) { + (bool a, uint256 b) = db.getSchellingExpansion(id); require( a ); return b; } @@ -246,8 +246,8 @@ contract schelling is module, announcementTypes, schellingVars { bytes1 public aboveChar = 0x31; bytes1 public belowChar = 0x30; schellingDB private db; - - function schelling(address _moduleHandler, address _db, bool _forReplace) { + + constructor(address _moduleHandler, address _db, bool _forReplace) public { /* Installation function. @@ -289,8 +289,8 @@ contract schelling is module, announcementTypes, schellingVars { */ nextRound(); - var currentRound = getCurrentRound(); - var round = getRound(currentRound); + uint256 currentRound = getCurrentRound(); + schellingVars._rounds memory round = getRound(currentRound); _voter memory voter; uint256 funds; @@ -323,7 +323,7 @@ contract schelling is module, announcementTypes, schellingVars { */ nextRound(); - var currentRound = getCurrentRound(); + uint256 currentRound = getCurrentRound(); _rounds memory round; _voter memory voter; uint256 funds; @@ -335,7 +335,7 @@ contract schelling is module, announcementTypes, schellingVars { require( voter.status == voterStatus.afterPrepareVote ); require( voter.roundID < currentRound ); - if ( sha3(vote) == voter.hash ) { + if ( keccak256(bytes(vote)) == voter.hash ) { delete voter.hash; if (round.blockHeight+roundBlockDelay/2 >= block.number) { if ( bytes(vote)[0] == aboveChar ) { @@ -369,7 +369,7 @@ contract schelling is module, announcementTypes, schellingVars { */ nextRound(); - var currentRound = getCurrentRound(); + uint256 currentRound = getCurrentRound(); _rounds memory round; _voter memory voter; uint256 funds; @@ -403,11 +403,11 @@ contract schelling is module, announcementTypes, schellingVars { @beneficiary Address of the beneficiary */ - var voter = getVoter(msg.sender); - var funds = getFunds(msg.sender); + schellingVars._voter memory voter = getVoter(msg.sender); + uint256 funds = getFunds(msg.sender); address _beneficiary = msg.sender; - if (beneficiary != 0x0) { _beneficiary = beneficiary; } + if (beneficiary != address(0x00)) { _beneficiary = beneficiary; } uint256 reward; require( voter.rewards > 0 ); require( voter.status == voterStatus.base ); @@ -417,24 +417,24 @@ contract schelling is module, announcementTypes, schellingVars { setVoter(msg.sender, voter); } - function checkReward() public constant returns (uint256 reward) { + function checkReward() public view returns (uint256 reward) { /* Withdraw of the amount of the prize (it’s only information). @reward Prize */ - var voter = getVoter(msg.sender); + schellingVars._voter memory voter = getVoter(msg.sender); return voter.rewards; } function nextRound() internal returns (bool) { /* Inside function, checks the time of the Schelling round and if its needed, creates a new Schelling round. */ - var currentRound = getCurrentRound(); - var round = getRound(currentRound); + uint256 currentRound = getCurrentRound(); + _rounds memory round = getRound(currentRound); _rounds memory newRound; _rounds memory prevRound; - var currentSchellingRound = getCurrentSchellingRound(); + uint256 currentSchellingRound = getCurrentSchellingRound(); if ( round.blockHeight+roundBlockDelay > block.number) { return false; } @@ -442,14 +442,14 @@ contract schelling is module, announcementTypes, schellingVars { if ( ! round.voted ) { newRound.reward = round.reward; } - uint256 aboves; + uint256 above; for ( uint256 a=currentRound ; a>=currentRound-interestCheckRounds ; a-- ) { if (a == 0) { break; } prevRound = getRound(a); - if ( prevRound.totalAboveWeight > prevRound.totalBelowWeight ) { aboves++; } + if ( prevRound.totalAboveWeight > prevRound.totalBelowWeight ) { above++; } } uint256 expansion; - if ( aboves >= interestCheckAboves ) { + if ( above >= interestCheckAboves ) { expansion = getTotalSupply() * interestRate / interestRateM / 100; } @@ -469,10 +469,10 @@ contract schelling is module, announcementTypes, schellingVars { @amount Amount of deposit. */ - var voter = getVoter(msg.sender); - var funds = getFunds(msg.sender); + _voter memory voter = getVoter(msg.sender); + uint256 funds = getFunds(msg.sender); - var (a, b) = moduleHandler(moduleHandlerAddress).isICO(); + (bool a, bool b) = moduleHandler(moduleHandlerAddress).isICO(); require( b && b ); require( voter.status == voterStatus.base ); require( amount > 0 ); @@ -487,8 +487,8 @@ contract schelling is module, announcementTypes, schellingVars { If the deposit isn’t lost, it can be withdrawn. By withdrawn, the deposit will be sent from Schelling address to the users address, charged with transaction fee.. */ - var voter = getVoter(msg.sender); - var funds = getFunds(msg.sender); + _voter memory voter = getVoter(msg.sender); + uint256 funds = getFunds(msg.sender); require( funds > 0 ); require( voter.status == voterStatus.base ); @@ -496,7 +496,7 @@ contract schelling is module, announcementTypes, schellingVars { require( moduleHandler(moduleHandlerAddress).transfer(address(this), msg.sender, funds, true) ); } - function getCurrentSchellingRoundID() public constant returns (uint256) { + function getCurrentSchellingRoundID() public view returns (uint256) { /* Number of actual Schelling round. @@ -504,7 +504,7 @@ contract schelling is module, announcementTypes, schellingVars { */ return getCurrentSchellingRound(); } - function getSchellingRound(uint256 id) public constant returns (uint256 expansion) { + function getSchellingRound(uint256 id) public view returns (uint256 expansion) { /* Amount of token emission of the Schelling round. @@ -550,7 +550,7 @@ contract schelling is module, announcementTypes, schellingVars { @uint256 Whole token amount */ - var (_success, _amount) = moduleHandler(moduleHandlerAddress).totalSupply(); + (bool _success, uint256 _amount) = moduleHandler(moduleHandlerAddress).totalSupply(); require( _success ); return _amount; } @@ -563,7 +563,7 @@ contract schelling is module, announcementTypes, schellingVars { @balance Balance of the address. */ - var (_success, _balance) = moduleHandler(moduleHandlerAddress).balanceOf(addr); + (bool _success, uint256 _balance) = moduleHandler(moduleHandlerAddress).balanceOf(addr); require( _success ); return _balance; } diff --git a/test/compilationTests/corion/token.sol b/test/compilationTests/corion/token.sol index 3aa0bf23..8ca18083 100644 --- a/test/compilationTests/corion/token.sol +++ b/test/compilationTests/corion/token.sol @@ -22,7 +22,7 @@ contract token is safeMath, module, announcementTypes { return true; } modifier isReady { - var (_success, _active) = super.isActive(); + (bool _success, bool _active) = super.isActive(); require( _success && _active ); _; } @@ -47,8 +47,8 @@ contract token is safeMath, module, announcementTypes { bool public isICO = true; mapping(address => bool) public genesis; - - function token(bool forReplace, address moduleHandler, address dbAddr, address icoContractAddr, address exchangeContractAddress, address[] genesisAddr, uint256[] genesisValue) payable { + + constructor(bool forReplace, address moduleHandler, address dbAddr, address icoContractAddr, address exchangeContractAddress, address[] genesisAddr, uint256[] genesisValue) public payable { /* Installation function @@ -63,9 +63,9 @@ contract token is safeMath, module, announcementTypes { @genesisValue Array of balance of genesis addresses */ super.registerModuleHandler(moduleHandler); - require( dbAddr != 0x00 ); - require( icoContractAddr != 0x00 ); - require( exchangeContractAddress != 0x00 ); + require( dbAddr != address(0x00) ); + require( icoContractAddr != address(0x00) ); + require( exchangeContractAddress != address(0x00) ); db = tokenDB(dbAddr); icoAddr = icoContractAddr; exchangeAddress = exchangeContractAddress; @@ -73,12 +73,12 @@ contract token is safeMath, module, announcementTypes { if ( ! forReplace ) { require( db.replaceOwner(this) ); assert( genesisAddr.length == genesisValue.length ); - require( this.balance >= genesisAddr.length * 0.2 ether ); + require( address(this).balance >= genesisAddr.length * 0.2 ether ); for ( uint256 a=0 ; a<genesisAddr.length ; a++ ) { genesis[genesisAddr[a]] = true; require( db.increase(genesisAddr[a], genesisValue[a]) ); if ( ! genesisAddr[a].send(0.2 ether) ) {} - Mint(genesisAddr[a], genesisValue[a]); + emit Mint(genesisAddr[a], genesisValue[a]); } } } @@ -152,10 +152,10 @@ contract token is safeMath, module, announcementTypes { require( msg.sender != spender ); require( db.balanceOf(msg.sender) >= amount ); require( db.setAllowance(msg.sender, spender, amount, nonce) ); - Approval(msg.sender, spender, amount); + emit Approval(msg.sender, spender, amount); } - - function allowance(address owner, address spender) constant returns (uint256 remaining, uint256 nonce) { + + function allowance(address owner, address spender) public view returns (uint256 remaining, uint256 nonce) { /* Get the quantity of tokens given to be used @@ -165,7 +165,7 @@ contract token is safeMath, module, announcementTypes { @remaining Tokens to be spent @nonce Transaction count */ - var (_success, _remaining, _nonce) = db.getAllowance(owner, spender); + (bool _success, uint256 _remaining, uint256 _nonce) = db.getAllowance(owner, spender); require( _success ); return (_remaining, _nonce); } @@ -193,7 +193,7 @@ contract token is safeMath, module, announcementTypes { } else { _transfer( msg.sender, to, amount, true); } - Transfer(msg.sender, to, amount, _data); + emit Transfer(msg.sender, to, amount, _data); return true; } @@ -217,12 +217,12 @@ contract token is safeMath, module, announcementTypes { @success Was the Function successful? */ if ( from != msg.sender ) { - var (_success, _reamining, _nonce) = db.getAllowance(from, msg.sender); + (bool _success, uint256 _reamining, uint256 _nonce) = db.getAllowance(from, msg.sender); require( _success ); _reamining = safeSub(_reamining, amount); _nonce = safeAdd(_nonce, 1); require( db.setAllowance(from, msg.sender, _reamining, _nonce) ); - AllowanceUsed(msg.sender, from, amount); + emit AllowanceUsed(msg.sender, from, amount); } bytes memory _data; if ( isContract(to) ) { @@ -230,7 +230,7 @@ contract token is safeMath, module, announcementTypes { } else { _transfer( from, to, amount, true); } - Transfer(from, to, amount, _data); + emit Transfer(from, to, amount, _data); return true; } @@ -256,7 +256,7 @@ contract token is safeMath, module, announcementTypes { bytes memory _data; require( super.isModuleHandler(msg.sender) ); _transfer( from, to, amount, fee); - Transfer(from, to, amount, _data); + emit Transfer(from, to, amount, _data); return true; } @@ -284,7 +284,7 @@ contract token is safeMath, module, announcementTypes { } else { _transfer( msg.sender, to, amount, true); } - Transfer(msg.sender, to, amount, extraData); + emit Transfer(msg.sender, to, amount, extraData); return true; } @@ -298,7 +298,7 @@ contract token is safeMath, module, announcementTypes { @extraData Extra data the receiver will get */ _transfer(from, to, amount, exchangeAddress == to); - var (_success, _back) = thirdPartyContractAbstract(to).receiveCorionToken(from, amount, extraData); + (bool _success, uint256 _back) = thirdPartyContractAbstract(to).receiveCorionToken(from, amount, extraData); require( _success ); require( amount > _back ); if ( _back > 0 ) { @@ -321,11 +321,11 @@ contract token is safeMath, module, announcementTypes { @fee Deduct transaction fee - yes or no? */ if( fee ) { - var (success, _fee) = getTransactionFee(amount); + (bool success, uint256 _fee) = getTransactionFee(amount); require( success ); require( db.balanceOf(from) >= amount + _fee ); } - require( from != 0x00 && to != 0x00 && to != 0xa636a97578d26a3b76b060bbc18226d954cf3757 ); + require( from != address(0x00) && to != address(0x00) && to != 0xa636A97578d26A3b76B060Bbc18226d954cf3757 ); require( ( ! isICO) || genesis[from] ); require( db.decrease(from, amount) ); require( db.increase(to, amount) ); @@ -366,7 +366,7 @@ contract token is safeMath, module, announcementTypes { @value Quantity to calculate the fee */ if ( isICO ) { return; } - var (_success, _fee) = getTransactionFee(value); + (bool _success, uint256 _fee) = getTransactionFee(value); require( _success ); uint256 _forBurn = _fee * transactionFeeBurn / 100; uint256 _forSchelling = _fee - _forBurn; @@ -374,19 +374,19 @@ contract token is safeMath, module, announcementTypes { address _schellingAddr; (_success, _found, _schellingAddr) = moduleHandler(moduleHandlerAddress).getModuleAddressByName('Schelling'); require( _success ); - if ( _schellingAddr != 0x00 && _found) { + if ( _schellingAddr != address(0x00) && _found) { require( db.decrease(owner, _forSchelling) ); require( db.increase(_schellingAddr, _forSchelling) ); _burn(owner, _forBurn); bytes memory _data; - Transfer(owner, _schellingAddr, _forSchelling, _data); + emit Transfer(owner, _schellingAddr, _forSchelling, _data); require( moduleHandler(moduleHandlerAddress).broadcastTransfer(owner, _schellingAddr, _forSchelling) ); } else { _burn(owner, _fee); } } - function getTransactionFee(uint256 value) public constant returns (bool success, uint256 fee) { + function getTransactionFee(uint256 value) public view returns (bool success, uint256 fee) { /* Transaction fee query. @@ -424,11 +424,11 @@ contract token is safeMath, module, announcementTypes { @value Quantity */ require( db.increase(owner, value) ); - require( moduleHandler(moduleHandlerAddress).broadcastTransfer(0x00, owner, value) ); + require( moduleHandler(moduleHandlerAddress).broadcastTransfer(address(0x00), owner, value) ); if ( isICO ) { require( ico(icoAddr).setInterestDB(owner, db.balanceOf(owner)) ); } - Mint(owner, value); + emit Mint(owner, value); } function burn(address owner, uint256 value) isReady external returns (bool success) { @@ -453,8 +453,8 @@ contract token is safeMath, module, announcementTypes { @value Quantity */ require( db.decrease(owner, value) ); - require( moduleHandler(moduleHandlerAddress).broadcastTransfer(owner, 0x00, value) ); - Burn(owner, value); + require( moduleHandler(moduleHandlerAddress).broadcastTransfer(owner, address(0x00), value) ); + emit Burn(owner, value); } function isContract(address addr) internal returns (bool success) { @@ -471,8 +471,8 @@ contract token is safeMath, module, announcementTypes { } return _codeLength > 0; } - - function balanceOf(address owner) constant returns (uint256 value) { + + function balanceOf(address owner) public view returns (uint256 value) { /* Token balance query @@ -482,8 +482,8 @@ contract token is safeMath, module, announcementTypes { */ return db.balanceOf(owner); } - - function totalSupply() constant returns (uint256 value) { + + function totalSupply() public view returns (uint256 value) { /* Total token quantity query diff --git a/test/compilationTests/corion/tokenDB.sol b/test/compilationTests/corion/tokenDB.sol index 6de1b6c3..484135ca 100644 --- a/test/compilationTests/corion/tokenDB.sol +++ b/test/compilationTests/corion/tokenDB.sol @@ -60,8 +60,8 @@ contract tokenDB is safeMath, ownedDB { allowance[owner][spender].nonce = nonce;
return true;
}
-
- function getAllowance(address owner, address spender) constant returns(bool success, uint256 remaining, uint256 nonce) {
+
+ function getAllowance(address owner, address spender) public view returns(bool success, uint256 remaining, uint256 nonce) {
/*
Get allowance from the database.
diff --git a/test/compilationTests/gnosis/Events/CategoricalEvent.sol b/test/compilationTests/gnosis/Events/CategoricalEvent.sol index fbd1d744..4815e315 100644 --- a/test/compilationTests/gnosis/Events/CategoricalEvent.sol +++ b/test/compilationTests/gnosis/Events/CategoricalEvent.sol @@ -13,7 +13,7 @@ contract CategoricalEvent is Event { /// @param _collateralToken Tokens used as collateral in exchange for outcome tokens /// @param _oracle Oracle contract used to resolve the event /// @param outcomeCount Number of event outcomes - function CategoricalEvent( + constructor( Token _collateralToken, Oracle _oracle, uint8 outcomeCount @@ -38,16 +38,16 @@ contract CategoricalEvent is Event { outcomeTokens[uint(outcome)].revoke(msg.sender, winnings); // Payout winnings require(collateralToken.transfer(msg.sender, winnings)); - WinningsRedemption(msg.sender, winnings); + emit WinningsRedemption(msg.sender, winnings); } /// @dev Calculates and returns event hash /// @return Event hash function getEventHash() public - constant + view returns (bytes32) { - return keccak256(collateralToken, oracle, outcomeTokens.length); + return keccak256(abi.encodePacked(collateralToken, oracle, outcomeTokens.length)); } } diff --git a/test/compilationTests/gnosis/Events/Event.sol b/test/compilationTests/gnosis/Events/Event.sol index 9aa257c4..177f61df 100644 --- a/test/compilationTests/gnosis/Events/Event.sol +++ b/test/compilationTests/gnosis/Events/Event.sol @@ -33,18 +33,18 @@ contract Event { /// @param _collateralToken Tokens used as collateral in exchange for outcome tokens /// @param _oracle Oracle contract used to resolve the event /// @param outcomeCount Number of event outcomes - function Event(Token _collateralToken, Oracle _oracle, uint8 outcomeCount) + constructor(Token _collateralToken, Oracle _oracle, uint8 outcomeCount) public { // Validate input - require(address(_collateralToken) != 0 && address(_oracle) != 0 && outcomeCount >= 2); + require(address(_collateralToken) != address(0) && address(_oracle) != address(0) && outcomeCount >= 2); collateralToken = _collateralToken; oracle = _oracle; // Create an outcome token for each outcome for (uint8 i = 0; i < outcomeCount; i++) { OutcomeToken outcomeToken = new OutcomeToken(); outcomeTokens.push(outcomeToken); - OutcomeTokenCreation(outcomeToken, i); + emit OutcomeTokenCreation(outcomeToken, i); } } @@ -58,7 +58,7 @@ contract Event { // Issue new outcome tokens to sender for (uint8 i = 0; i < outcomeTokens.length; i++) outcomeTokens[i].issue(msg.sender, collateralTokenCount); - OutcomeTokenSetIssuance(msg.sender, collateralTokenCount); + emit OutcomeTokenSetIssuance(msg.sender, collateralTokenCount); } /// @dev Sells equal number of tokens of all outcomes, exchanging collateral tokens and sets of outcome tokens 1:1 @@ -71,7 +71,7 @@ contract Event { outcomeTokens[i].revoke(msg.sender, outcomeTokenCount); // Transfer collateral tokens to sender require(collateralToken.transfer(msg.sender, outcomeTokenCount)); - OutcomeTokenSetRevocation(msg.sender, outcomeTokenCount); + emit OutcomeTokenSetRevocation(msg.sender, outcomeTokenCount); } /// @dev Sets winning event outcome @@ -83,14 +83,14 @@ contract Event { // Set winning outcome outcome = oracle.getOutcome(); isOutcomeSet = true; - OutcomeAssignment(outcome); + emit OutcomeAssignment(outcome); } /// @dev Returns outcome count /// @return Outcome count function getOutcomeCount() public - constant + view returns (uint8) { return uint8(outcomeTokens.length); @@ -100,7 +100,7 @@ contract Event { /// @return Outcome tokens function getOutcomeTokens() public - constant + view returns (OutcomeToken[]) { return outcomeTokens; @@ -110,7 +110,7 @@ contract Event { /// @return Outcome token distribution function getOutcomeTokenDistribution(address owner) public - constant + view returns (uint[] outcomeTokenDistribution) { outcomeTokenDistribution = new uint[](outcomeTokens.length); @@ -120,7 +120,7 @@ contract Event { /// @dev Calculates and returns event hash /// @return Event hash - function getEventHash() public constant returns (bytes32); + function getEventHash() public view returns (bytes32); /// @dev Exchanges sender's winning outcome tokens for collateral tokens /// @return Sender's winnings diff --git a/test/compilationTests/gnosis/Events/EventFactory.sol b/test/compilationTests/gnosis/Events/EventFactory.sol index dfb1a579..cfe772ec 100644 --- a/test/compilationTests/gnosis/Events/EventFactory.sol +++ b/test/compilationTests/gnosis/Events/EventFactory.sol @@ -35,9 +35,9 @@ contract EventFactory { public returns (CategoricalEvent eventContract) { - bytes32 eventHash = keccak256(collateralToken, oracle, outcomeCount); + bytes32 eventHash = keccak256(abi.encodePacked(collateralToken, oracle, outcomeCount)); // Event should not exist yet - require(address(categoricalEvents[eventHash]) == 0); + require(address(categoricalEvents[eventHash]) == address(0)); // Create event eventContract = new CategoricalEvent( collateralToken, @@ -45,7 +45,7 @@ contract EventFactory { outcomeCount ); categoricalEvents[eventHash] = eventContract; - CategoricalEventCreation(msg.sender, eventContract, collateralToken, oracle, outcomeCount); + emit CategoricalEventCreation(msg.sender, eventContract, collateralToken, oracle, outcomeCount); } /// @dev Creates a new scalar event and adds it to the event mapping @@ -63,9 +63,9 @@ contract EventFactory { public returns (ScalarEvent eventContract) { - bytes32 eventHash = keccak256(collateralToken, oracle, lowerBound, upperBound); + bytes32 eventHash = keccak256(abi.encodePacked(collateralToken, oracle, lowerBound, upperBound)); // Event should not exist yet - require(address(scalarEvents[eventHash]) == 0); + require(address(scalarEvents[eventHash]) == address(0)); // Create event eventContract = new ScalarEvent( collateralToken, @@ -74,6 +74,6 @@ contract EventFactory { upperBound ); scalarEvents[eventHash] = eventContract; - ScalarEventCreation(msg.sender, eventContract, collateralToken, oracle, lowerBound, upperBound); + emit ScalarEventCreation(msg.sender, eventContract, collateralToken, oracle, lowerBound, upperBound); } } diff --git a/test/compilationTests/gnosis/Events/ScalarEvent.sol b/test/compilationTests/gnosis/Events/ScalarEvent.sol index 2e5718ef..832c2ab1 100644 --- a/test/compilationTests/gnosis/Events/ScalarEvent.sol +++ b/test/compilationTests/gnosis/Events/ScalarEvent.sol @@ -28,7 +28,7 @@ contract ScalarEvent is Event { /// @param _oracle Oracle contract used to resolve the event /// @param _lowerBound Lower bound for event outcome /// @param _upperBound Lower bound for event outcome - function ScalarEvent( + constructor( Token _collateralToken, Oracle _oracle, int _lowerBound, @@ -72,16 +72,16 @@ contract ScalarEvent is Event { outcomeTokens[LONG].revoke(msg.sender, longOutcomeTokenCount); // Payout winnings to sender require(collateralToken.transfer(msg.sender, winnings)); - WinningsRedemption(msg.sender, winnings); + emit WinningsRedemption(msg.sender, winnings); } /// @dev Calculates and returns event hash /// @return Event hash function getEventHash() public - constant + view returns (bytes32) { - return keccak256(collateralToken, oracle, lowerBound, upperBound); + return keccak256(abi.encodePacked(collateralToken, oracle, lowerBound, upperBound)); } } diff --git a/test/compilationTests/gnosis/MarketMakers/LMSRMarketMaker.sol b/test/compilationTests/gnosis/MarketMakers/LMSRMarketMaker.sol index 1529129d..cf4fcd7d 100644 --- a/test/compilationTests/gnosis/MarketMakers/LMSRMarketMaker.sol +++ b/test/compilationTests/gnosis/MarketMakers/LMSRMarketMaker.sol @@ -24,7 +24,7 @@ contract LMSRMarketMaker is MarketMaker { /// @return Cost function calcCost(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount) public - constant + view returns (uint cost) { require(market.eventContract().getOutcomeCount() > 1); @@ -59,7 +59,7 @@ contract LMSRMarketMaker is MarketMaker { /// @return Profit function calcProfit(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount) public - constant + view returns (uint profit) { require(market.eventContract().getOutcomeCount() > 1); @@ -85,7 +85,7 @@ contract LMSRMarketMaker is MarketMaker { /// @return Marginal price of an outcome as a fixed point number function calcMarginalPrice(Market market, uint8 outcomeTokenIndex) public - constant + view returns (uint price) { require(market.eventContract().getOutcomeCount() > 1); @@ -95,7 +95,7 @@ contract LMSRMarketMaker is MarketMaker { // The price function is exp(quantities[i]/b) / sum(exp(q/b) for q in quantities) // To avoid overflow, calculate with // exp(quantities[i]/b - offset) / sum(exp(q/b - offset) for q in quantities) - var (sum, , outcomeExpTerm) = sumExpOffset(logN, netOutcomeTokensSold, funding, outcomeTokenIndex); + (uint256 sum, , uint256 outcomeExpTerm) = sumExpOffset(logN, netOutcomeTokensSold, funding, outcomeTokenIndex); return outcomeExpTerm / (sum / ONE); } @@ -110,13 +110,13 @@ contract LMSRMarketMaker is MarketMaker { /// @return Cost level function calcCostLevel(int logN, int[] netOutcomeTokensSold, uint funding) private - constant + view returns(int costLevel) { // The cost function is C = b * log(sum(exp(q/b) for q in quantities)). // To avoid overflow, we need to calc with an exponent offset: // C = b * (offset + log(sum(exp(q/b - offset) for q in quantities))) - var (sum, offset, ) = sumExpOffset(logN, netOutcomeTokensSold, funding, 0); + (uint256 sum, int256 offset, ) = sumExpOffset(logN, netOutcomeTokensSold, funding, 0); costLevel = Math.ln(sum); costLevel = costLevel.add(offset); costLevel = (costLevel.mul(int(ONE)) / logN).mul(int(funding)); @@ -131,7 +131,7 @@ contract LMSRMarketMaker is MarketMaker { /// @return A result structure composed of the sum, the offset used, and the summand associated with the supplied index function sumExpOffset(int logN, int[] netOutcomeTokensSold, uint funding, uint8 outcomeIndex) private - constant + view returns (uint sum, int offset, uint outcomeExpTerm) { // Naive calculation of this causes an overflow @@ -170,7 +170,7 @@ contract LMSRMarketMaker is MarketMaker { /// @return Net outcome tokens sold by market function getNetOutcomeTokensSold(Market market) private - constant + view returns (int[] quantities) { quantities = new int[](market.eventContract().getOutcomeCount()); diff --git a/test/compilationTests/gnosis/MarketMakers/MarketMaker.sol b/test/compilationTests/gnosis/MarketMakers/MarketMaker.sol index 3162ce64..ef5942cd 100644 --- a/test/compilationTests/gnosis/MarketMakers/MarketMaker.sol +++ b/test/compilationTests/gnosis/MarketMakers/MarketMaker.sol @@ -8,7 +8,7 @@ contract MarketMaker { /* * Public functions */ - function calcCost(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount) public constant returns (uint); - function calcProfit(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount) public constant returns (uint); - function calcMarginalPrice(Market market, uint8 outcomeTokenIndex) public constant returns (uint); + function calcCost(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount) public view returns (uint); + function calcProfit(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount) public view returns (uint); + function calcMarginalPrice(Market market, uint8 outcomeTokenIndex) public view returns (uint); } diff --git a/test/compilationTests/gnosis/Markets/Campaign.sol b/test/compilationTests/gnosis/Markets/Campaign.sol index 9aee1033..f99ede53 100644 --- a/test/compilationTests/gnosis/Markets/Campaign.sol +++ b/test/compilationTests/gnosis/Markets/Campaign.sol @@ -70,7 +70,7 @@ contract Campaign { /// @param _fee Market fee /// @param _funding Initial funding for market /// @param _deadline Campaign deadline - function Campaign( + constructor( Event _eventContract, MarketFactory _marketFactory, MarketMaker _marketMaker, @@ -81,9 +81,9 @@ contract Campaign { public { // Validate input - require( address(_eventContract) != 0 - && address(_marketFactory) != 0 - && address(_marketMaker) != 0 + require( address(_eventContract) != address(0) + && address(_marketFactory) != address(0) + && address(_marketMaker) != address(0) && _fee < FEE_RANGE && _funding > 0 && now < _deadline); @@ -111,7 +111,7 @@ contract Campaign { contributions[msg.sender] = contributions[msg.sender].add(amount); if (amount == maxAmount) stage = Stages.AuctionSuccessful; - CampaignFunding(msg.sender, amount); + emit CampaignFunding(msg.sender, amount); } /// @dev Withdraws refund amount @@ -126,7 +126,7 @@ contract Campaign { contributions[msg.sender] = 0; // Refund collateral tokens require(eventContract.collateralToken().transfer(msg.sender, refundAmount)); - CampaignRefund(msg.sender, refundAmount); + emit CampaignRefund(msg.sender, refundAmount); } /// @dev Allows to create market after successful funding @@ -141,7 +141,7 @@ contract Campaign { require(eventContract.collateralToken().approve(market, funding)); market.fund(funding); stage = Stages.MarketCreated; - MarketCreation(market); + emit MarketCreation(market); return market; } @@ -158,7 +158,7 @@ contract Campaign { eventContract.redeemWinnings(); finalBalance = eventContract.collateralToken().balanceOf(this); stage = Stages.MarketClosed; - MarketClosing(); + emit MarketClosing(); } /// @dev Allows to withdraw fees from campaign contract to contributor @@ -172,6 +172,6 @@ contract Campaign { contributions[msg.sender] = 0; // Send fee share to contributor require(eventContract.collateralToken().transfer(msg.sender, fees)); - FeeWithdrawal(msg.sender, fees); + emit FeeWithdrawal(msg.sender, fees); } } diff --git a/test/compilationTests/gnosis/Markets/CampaignFactory.sol b/test/compilationTests/gnosis/Markets/CampaignFactory.sol index 930ec2e2..d80d7d63 100644 --- a/test/compilationTests/gnosis/Markets/CampaignFactory.sol +++ b/test/compilationTests/gnosis/Markets/CampaignFactory.sol @@ -34,6 +34,6 @@ contract CampaignFactory { returns (Campaign campaign) { campaign = new Campaign(eventContract, marketFactory, marketMaker, fee, funding, deadline); - CampaignCreation(msg.sender, campaign, eventContract, marketFactory, marketMaker, fee, funding, deadline); + emit CampaignCreation(msg.sender, campaign, eventContract, marketFactory, marketMaker, fee, funding, deadline); } } diff --git a/test/compilationTests/gnosis/Markets/Market.sol b/test/compilationTests/gnosis/Markets/Market.sol index 635b14db..7bcecfe5 100644 --- a/test/compilationTests/gnosis/Markets/Market.sol +++ b/test/compilationTests/gnosis/Markets/Market.sol @@ -43,5 +43,5 @@ contract Market { function buy(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint maxCost) public returns (uint); function sell(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint minProfit) public returns (uint); function shortSell(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint minProfit) public returns (uint); - function calcMarketFee(uint outcomeTokenCost) public constant returns (uint); + function calcMarketFee(uint outcomeTokenCost) public view returns (uint); } diff --git a/test/compilationTests/gnosis/Markets/StandardMarket.sol b/test/compilationTests/gnosis/Markets/StandardMarket.sol index b973119a..0a9f77db 100644 --- a/test/compilationTests/gnosis/Markets/StandardMarket.sol +++ b/test/compilationTests/gnosis/Markets/StandardMarket.sol @@ -38,11 +38,11 @@ contract StandardMarket is Market { /// @param _eventContract Event contract /// @param _marketMaker Market maker contract /// @param _fee Market fee - function StandardMarket(address _creator, Event _eventContract, MarketMaker _marketMaker, uint24 _fee) + constructor(address _creator, Event _eventContract, MarketMaker _marketMaker, uint24 _fee) public { // Validate inputs - require(address(_eventContract) != 0 && address(_marketMaker) != 0 && _fee < FEE_RANGE); + require(address(_eventContract) != address(0) && address(_marketMaker) != address(0) && _fee < FEE_RANGE); creator = _creator; createdAtBlock = block.number; eventContract = _eventContract; @@ -65,7 +65,7 @@ contract StandardMarket is Market { eventContract.buyAllOutcomes(_funding); funding = _funding; stage = Stages.MarketFunded; - MarketFunding(funding); + emit MarketFunding(funding); } /// @dev Allows market creator to close the markets by transferring all remaining outcome tokens to the creator @@ -78,7 +78,7 @@ contract StandardMarket is Market { for (uint8 i = 0; i < outcomeCount; i++) require(eventContract.outcomeTokens(i).transfer(creator, eventContract.outcomeTokens(i).balanceOf(this))); stage = Stages.MarketClosed; - MarketClosing(); + emit MarketClosing(); } /// @dev Allows market creator to withdraw fees generated by trades @@ -91,7 +91,7 @@ contract StandardMarket is Market { fees = eventContract.collateralToken().balanceOf(this); // Transfer fees require(eventContract.collateralToken().transfer(creator, fees)); - FeeWithdrawal(fees); + emit FeeWithdrawal(fees); } /// @dev Allows to buy outcome tokens from market maker @@ -121,7 +121,7 @@ contract StandardMarket is Market { // Add outcome token count to market maker net balance require(int(outcomeTokenCount) >= 0); netOutcomeTokensSold[outcomeTokenIndex] = netOutcomeTokensSold[outcomeTokenIndex].add(int(outcomeTokenCount)); - OutcomeTokenPurchase(msg.sender, outcomeTokenIndex, outcomeTokenCount, cost); + emit OutcomeTokenPurchase(msg.sender, outcomeTokenIndex, outcomeTokenCount, cost); } /// @dev Allows to sell outcome tokens to market maker @@ -150,7 +150,7 @@ contract StandardMarket is Market { // Subtract outcome token count from market maker net balance require(int(outcomeTokenCount) >= 0); netOutcomeTokensSold[outcomeTokenIndex] = netOutcomeTokensSold[outcomeTokenIndex].sub(int(outcomeTokenCount)); - OutcomeTokenSale(msg.sender, outcomeTokenIndex, outcomeTokenCount, profit); + emit OutcomeTokenSale(msg.sender, outcomeTokenIndex, outcomeTokenCount, profit); } /// @dev Buys all outcomes, then sells all shares of selected outcome which were bought, keeping @@ -178,7 +178,7 @@ contract StandardMarket is Market { require(eventContract.outcomeTokens(i).transfer(msg.sender, outcomeTokenCount)); // Send change back to buyer require(eventContract.collateralToken().transfer(msg.sender, profit)); - OutcomeTokenShortSale(msg.sender, outcomeTokenIndex, outcomeTokenCount, cost); + emit OutcomeTokenShortSale(msg.sender, outcomeTokenIndex, outcomeTokenCount, cost); } /// @dev Calculates fee to be paid to market maker @@ -186,7 +186,7 @@ contract StandardMarket is Market { /// @return Fee for trade function calcMarketFee(uint outcomeTokenCost) public - constant + view returns (uint) { return outcomeTokenCost * fee / FEE_RANGE; diff --git a/test/compilationTests/gnosis/Markets/StandardMarketFactory.sol b/test/compilationTests/gnosis/Markets/StandardMarketFactory.sol index 101c37a2..88dcbe79 100644 --- a/test/compilationTests/gnosis/Markets/StandardMarketFactory.sol +++ b/test/compilationTests/gnosis/Markets/StandardMarketFactory.sol @@ -20,6 +20,6 @@ contract StandardMarketFactory is MarketFactory { returns (Market market) { market = new StandardMarket(msg.sender, eventContract, marketMaker, fee); - MarketCreation(msg.sender, market, eventContract, marketMaker, fee); + emit MarketCreation(msg.sender, market, eventContract, marketMaker, fee); } } diff --git a/test/compilationTests/gnosis/Migrations.sol b/test/compilationTests/gnosis/Migrations.sol index 7e7fe8d4..f1a3ea9d 100644 --- a/test/compilationTests/gnosis/Migrations.sol +++ b/test/compilationTests/gnosis/Migrations.sol @@ -8,15 +8,15 @@ contract Migrations { if (msg.sender == owner) _; } - function Migrations() { + constructor() public { owner = msg.sender; } - function setCompleted(uint completed) restricted { + function setCompleted(uint completed) public restricted { last_completed_migration = completed; } - function upgrade(address new_address) restricted { + function upgrade(address new_address) public restricted { Migrations upgraded = Migrations(new_address); upgraded.setCompleted(last_completed_migration); } diff --git a/test/compilationTests/gnosis/Oracles/CentralizedOracle.sol b/test/compilationTests/gnosis/Oracles/CentralizedOracle.sol index 26acf526..de182a61 100644 --- a/test/compilationTests/gnosis/Oracles/CentralizedOracle.sol +++ b/test/compilationTests/gnosis/Oracles/CentralizedOracle.sol @@ -34,7 +34,7 @@ contract CentralizedOracle is Oracle { */ /// @dev Constructor sets owner address and IPFS hash /// @param _ipfsHash Hash identifying off chain event description - function CentralizedOracle(address _owner, bytes _ipfsHash) + constructor(address _owner, bytes _ipfsHash) public { // Description hash cannot be null @@ -52,7 +52,7 @@ contract CentralizedOracle is Oracle { // Result is not set yet require(!isSet); owner = newOwner; - OwnerReplacement(newOwner); + emit OwnerReplacement(newOwner); } /// @dev Sets event outcome @@ -65,14 +65,14 @@ contract CentralizedOracle is Oracle { require(!isSet); isSet = true; outcome = _outcome; - OutcomeAssignment(_outcome); + emit OutcomeAssignment(_outcome); } /// @dev Returns if winning outcome is set /// @return Is outcome set? function isOutcomeSet() public - constant + view returns (bool) { return isSet; @@ -82,7 +82,7 @@ contract CentralizedOracle is Oracle { /// @return Outcome function getOutcome() public - constant + view returns (int) { return outcome; diff --git a/test/compilationTests/gnosis/Oracles/CentralizedOracleFactory.sol b/test/compilationTests/gnosis/Oracles/CentralizedOracleFactory.sol index 62a12cf4..ca4e37d2 100644 --- a/test/compilationTests/gnosis/Oracles/CentralizedOracleFactory.sol +++ b/test/compilationTests/gnosis/Oracles/CentralizedOracleFactory.sol @@ -22,6 +22,6 @@ contract CentralizedOracleFactory { returns (CentralizedOracle centralizedOracle) { centralizedOracle = new CentralizedOracle(msg.sender, ipfsHash); - CentralizedOracleCreation(msg.sender, centralizedOracle, ipfsHash); + emit CentralizedOracleCreation(msg.sender, centralizedOracle, ipfsHash); } } diff --git a/test/compilationTests/gnosis/Oracles/DifficultyOracle.sol b/test/compilationTests/gnosis/Oracles/DifficultyOracle.sol index 87351dfa..3d801da1 100644 --- a/test/compilationTests/gnosis/Oracles/DifficultyOracle.sol +++ b/test/compilationTests/gnosis/Oracles/DifficultyOracle.sol @@ -22,7 +22,7 @@ contract DifficultyOracle is Oracle { */ /// @dev Contract constructor validates and sets target block number /// @param _blockNumber Target block number - function DifficultyOracle(uint _blockNumber) + constructor(uint _blockNumber) public { // Block has to be in the future @@ -37,14 +37,14 @@ contract DifficultyOracle is Oracle { // Block number was reached and outcome was not set yet require(block.number >= blockNumber && difficulty == 0); difficulty = block.difficulty; - OutcomeAssignment(difficulty); + emit OutcomeAssignment(difficulty); } /// @dev Returns if difficulty is set /// @return Is outcome set? function isOutcomeSet() public - constant + view returns (bool) { // Difficulty is always bigger than 0 @@ -55,7 +55,7 @@ contract DifficultyOracle is Oracle { /// @return Outcome function getOutcome() public - constant + view returns (int) { return int(difficulty); diff --git a/test/compilationTests/gnosis/Oracles/DifficultyOracleFactory.sol b/test/compilationTests/gnosis/Oracles/DifficultyOracleFactory.sol index 2e97362c..fc5dcc3b 100644 --- a/test/compilationTests/gnosis/Oracles/DifficultyOracleFactory.sol +++ b/test/compilationTests/gnosis/Oracles/DifficultyOracleFactory.sol @@ -22,6 +22,6 @@ contract DifficultyOracleFactory { returns (DifficultyOracle difficultyOracle) { difficultyOracle = new DifficultyOracle(blockNumber); - DifficultyOracleCreation(msg.sender, difficultyOracle, blockNumber); + emit DifficultyOracleCreation(msg.sender, difficultyOracle, blockNumber); } } diff --git a/test/compilationTests/gnosis/Oracles/FutarchyOracle.sol b/test/compilationTests/gnosis/Oracles/FutarchyOracle.sol index 524103d8..cf851f5b 100644 --- a/test/compilationTests/gnosis/Oracles/FutarchyOracle.sol +++ b/test/compilationTests/gnosis/Oracles/FutarchyOracle.sol @@ -55,7 +55,7 @@ contract FutarchyOracle is Oracle { /// @param marketMaker Market maker contract /// @param fee Market fee /// @param _deadline Decision deadline - function FutarchyOracle( + constructor( address _creator, EventFactory eventFactory, Token collateralToken, @@ -105,7 +105,7 @@ contract FutarchyOracle is Oracle { require(market.eventContract().collateralToken().approve(market, funding)); market.fund(funding); } - FutarchyFunding(funding); + emit FutarchyFunding(funding); } /// @dev Closes market for winning outcome and redeems winnings and sends all collateral tokens to creator @@ -123,7 +123,7 @@ contract FutarchyOracle is Oracle { // Redeem collateral token for winning outcome tokens and transfer collateral tokens to creator categoricalEvent.redeemWinnings(); require(categoricalEvent.collateralToken().transfer(creator, categoricalEvent.collateralToken().balanceOf(this))); - FutarchyClosing(); + emit FutarchyClosing(); } /// @dev Allows to set the oracle outcome based on the market with largest long position @@ -144,14 +144,14 @@ contract FutarchyOracle is Oracle { } winningMarketIndex = highestIndex; isSet = true; - OutcomeAssignment(winningMarketIndex); + emit OutcomeAssignment(winningMarketIndex); } /// @dev Returns if winning outcome is set /// @return Is outcome set? function isOutcomeSet() public - constant + view returns (bool) { return isSet; @@ -161,7 +161,7 @@ contract FutarchyOracle is Oracle { /// @return Outcome function getOutcome() public - constant + view returns (int) { return int(winningMarketIndex); diff --git a/test/compilationTests/gnosis/Oracles/FutarchyOracleFactory.sol b/test/compilationTests/gnosis/Oracles/FutarchyOracleFactory.sol index 62eab4f0..3c6e5c15 100644 --- a/test/compilationTests/gnosis/Oracles/FutarchyOracleFactory.sol +++ b/test/compilationTests/gnosis/Oracles/FutarchyOracleFactory.sol @@ -33,10 +33,10 @@ contract FutarchyOracleFactory { */ /// @dev Constructor sets event factory contract /// @param _eventFactory Event factory contract - function FutarchyOracleFactory(EventFactory _eventFactory) + constructor(EventFactory _eventFactory) public { - require(address(_eventFactory) != 0); + require(address(_eventFactory) != address(0)); eventFactory = _eventFactory; } @@ -78,7 +78,7 @@ contract FutarchyOracleFactory { fee, deadline ); - FutarchyOracleCreation( + emit FutarchyOracleCreation( msg.sender, futarchyOracle, collateralToken, diff --git a/test/compilationTests/gnosis/Oracles/MajorityOracle.sol b/test/compilationTests/gnosis/Oracles/MajorityOracle.sol index 1562ce48..d8097370 100644 --- a/test/compilationTests/gnosis/Oracles/MajorityOracle.sol +++ b/test/compilationTests/gnosis/Oracles/MajorityOracle.sol @@ -16,14 +16,14 @@ contract MajorityOracle is Oracle { */ /// @dev Allows to create an oracle for a majority vote based on other oracles /// @param _oracles List of oracles taking part in the majority vote - function MajorityOracle(Oracle[] _oracles) + constructor(Oracle[] _oracles) public { // At least 2 oracles should be defined require(_oracles.length > 2); for (uint i = 0; i < _oracles.length; i++) // Oracle address cannot be null - require(address(_oracles[i]) != 0); + require(address(_oracles[i]) != address(0)); oracles = _oracles; } @@ -32,6 +32,7 @@ contract MajorityOracle is Oracle { /// @return Outcome function getStatusAndOutcome() public + view returns (bool outcomeSet, int outcome) { uint i; @@ -69,10 +70,10 @@ contract MajorityOracle is Oracle { /// @return Is outcome set? function isOutcomeSet() public - constant + view returns (bool) { - var (outcomeSet, ) = getStatusAndOutcome(); + (bool outcomeSet, ) = getStatusAndOutcome(); return outcomeSet; } @@ -80,10 +81,10 @@ contract MajorityOracle is Oracle { /// @return Outcome function getOutcome() public - constant + view returns (int) { - var (, winningOutcome) = getStatusAndOutcome(); + (, int winningOutcome) = getStatusAndOutcome(); return winningOutcome; } } diff --git a/test/compilationTests/gnosis/Oracles/MajorityOracleFactory.sol b/test/compilationTests/gnosis/Oracles/MajorityOracleFactory.sol index 0024516a..3c02fef4 100644 --- a/test/compilationTests/gnosis/Oracles/MajorityOracleFactory.sol +++ b/test/compilationTests/gnosis/Oracles/MajorityOracleFactory.sol @@ -22,6 +22,6 @@ contract MajorityOracleFactory { returns (MajorityOracle majorityOracle) { majorityOracle = new MajorityOracle(oracles); - MajorityOracleCreation(msg.sender, majorityOracle, oracles); + emit MajorityOracleCreation(msg.sender, majorityOracle, oracles); } } diff --git a/test/compilationTests/gnosis/Oracles/Oracle.sol b/test/compilationTests/gnosis/Oracles/Oracle.sol index cf96eb9f..450aff00 100644 --- a/test/compilationTests/gnosis/Oracles/Oracle.sol +++ b/test/compilationTests/gnosis/Oracles/Oracle.sol @@ -4,6 +4,6 @@ pragma solidity ^0.4.11; /// @title Abstract oracle contract - Functions to be implemented by oracles contract Oracle { - function isOutcomeSet() public constant returns (bool); - function getOutcome() public constant returns (int); + function isOutcomeSet() public view returns (bool); + function getOutcome() public view returns (int); } diff --git a/test/compilationTests/gnosis/Oracles/SignedMessageOracle.sol b/test/compilationTests/gnosis/Oracles/SignedMessageOracle.sol index d541ab46..284f420e 100644 --- a/test/compilationTests/gnosis/Oracles/SignedMessageOracle.sol +++ b/test/compilationTests/gnosis/Oracles/SignedMessageOracle.sol @@ -38,7 +38,7 @@ contract SignedMessageOracle is Oracle { /// @param v Signature parameter /// @param r Signature parameter /// @param s Signature parameter - function SignedMessageOracle(bytes32 _descriptionHash, uint8 v, bytes32 r, bytes32 s) + constructor(bytes32 _descriptionHash, uint8 v, bytes32 r, bytes32 s) public { signer = ecrecover(_descriptionHash, v, r, s); @@ -58,10 +58,10 @@ contract SignedMessageOracle is Oracle { // Result is not set yet and nonce and signer are valid require( !isSet && _nonce > nonce - && signer == ecrecover(keccak256(descriptionHash, newSigner, _nonce), v, r, s)); + && signer == ecrecover(keccak256(abi.encodePacked(descriptionHash, newSigner, _nonce)), v, r, s)); nonce = _nonce; signer = newSigner; - SignerReplacement(newSigner); + emit SignerReplacement(newSigner); } /// @dev Sets outcome based on signed message @@ -74,17 +74,17 @@ contract SignedMessageOracle is Oracle { { // Result is not set yet and signer is valid require( !isSet - && signer == ecrecover(keccak256(descriptionHash, _outcome), v, r, s)); + && signer == ecrecover(keccak256(abi.encodePacked(descriptionHash, _outcome)), v, r, s)); isSet = true; outcome = _outcome; - OutcomeAssignment(_outcome); + emit OutcomeAssignment(_outcome); } /// @dev Returns if winning outcome /// @return Is outcome set? function isOutcomeSet() public - constant + view returns (bool) { return isSet; @@ -94,7 +94,7 @@ contract SignedMessageOracle is Oracle { /// @return Outcome function getOutcome() public - constant + view returns (int) { return outcome; diff --git a/test/compilationTests/gnosis/Oracles/SignedMessageOracleFactory.sol b/test/compilationTests/gnosis/Oracles/SignedMessageOracleFactory.sol index 0884d8ca..ea70b2aa 100644 --- a/test/compilationTests/gnosis/Oracles/SignedMessageOracleFactory.sol +++ b/test/compilationTests/gnosis/Oracles/SignedMessageOracleFactory.sol @@ -26,6 +26,6 @@ contract SignedMessageOracleFactory { { signedMessageOracle = new SignedMessageOracle(descriptionHash, v, r, s); address oracle = ecrecover(descriptionHash, v, r, s); - SignedMessageOracleCreation(msg.sender, signedMessageOracle, oracle); + emit SignedMessageOracleCreation(msg.sender, signedMessageOracle, oracle); } } diff --git a/test/compilationTests/gnosis/Oracles/UltimateOracle.sol b/test/compilationTests/gnosis/Oracles/UltimateOracle.sol index fe8b4ec7..b7cc231c 100644 --- a/test/compilationTests/gnosis/Oracles/UltimateOracle.sol +++ b/test/compilationTests/gnosis/Oracles/UltimateOracle.sol @@ -46,7 +46,7 @@ contract UltimateOracle is Oracle { /// @param _challengePeriod Time to challenge oracle outcome /// @param _challengeAmount Amount to challenge the outcome /// @param _frontRunnerPeriod Time to overbid the front-runner - function UltimateOracle( + constructor( Oracle _forwardedOracle, Token _collateralToken, uint8 _spreadMultiplier, @@ -57,8 +57,8 @@ contract UltimateOracle is Oracle { public { // Validate inputs - require( address(_forwardedOracle) != 0 - && address(_collateralToken) != 0 + require( address(_forwardedOracle) != address(0) + && address(_collateralToken) != address(0) && _spreadMultiplier >= 2 && _challengePeriod > 0 && _challengeAmount > 0 @@ -81,7 +81,7 @@ contract UltimateOracle is Oracle { && forwardedOracle.isOutcomeSet()); forwardedOutcome = forwardedOracle.getOutcome(); forwardedOutcomeSetTimestamp = now; - ForwardedOracleOutcomeAssignment(forwardedOutcome); + emit ForwardedOracleOutcomeAssignment(forwardedOutcome); } /// @dev Allows to challenge the oracle outcome @@ -98,7 +98,7 @@ contract UltimateOracle is Oracle { totalAmount = challengeAmount; frontRunner = _outcome; frontRunnerSetTimestamp = now; - OutcomeChallenge(msg.sender, _outcome); + emit OutcomeChallenge(msg.sender, _outcome); } /// @dev Allows to challenge the oracle outcome @@ -122,7 +122,7 @@ contract UltimateOracle is Oracle { frontRunner = _outcome; frontRunnerSetTimestamp = now; } - OutcomeVote(msg.sender, _outcome, amount); + emit OutcomeVote(msg.sender, _outcome, amount); } /// @dev Withdraws winnings for user @@ -137,13 +137,14 @@ contract UltimateOracle is Oracle { outcomeAmounts[msg.sender][frontRunner] = 0; // Transfer earnings to contributor require(collateralToken.transfer(msg.sender, amount)); - Withdrawal(msg.sender, amount); + emit Withdrawal(msg.sender, amount); } /// @dev Checks if time to challenge the outcome is over /// @return Is challenge period over? function isChallengePeriodOver() public + view returns (bool) { return forwardedOutcomeSetTimestamp != 0 && now.sub(forwardedOutcomeSetTimestamp) > challengePeriod; @@ -153,6 +154,7 @@ contract UltimateOracle is Oracle { /// @return Is front runner period over? function isFrontRunnerPeriodOver() public + view returns (bool) { return frontRunnerSetTimestamp != 0 && now.sub(frontRunnerSetTimestamp) > frontRunnerPeriod; @@ -162,6 +164,7 @@ contract UltimateOracle is Oracle { /// @return Is challenged? function isChallenged() public + view returns (bool) { return frontRunnerSetTimestamp != 0; @@ -171,7 +174,7 @@ contract UltimateOracle is Oracle { /// @return Is outcome set? function isOutcomeSet() public - constant + view returns (bool) { return isChallengePeriodOver() && !isChallenged() @@ -182,7 +185,7 @@ contract UltimateOracle is Oracle { /// @return Outcome function getOutcome() public - constant + view returns (int) { if (isFrontRunnerPeriodOver()) diff --git a/test/compilationTests/gnosis/Oracles/UltimateOracleFactory.sol b/test/compilationTests/gnosis/Oracles/UltimateOracleFactory.sol index 67f8a96e..51f5610e 100644 --- a/test/compilationTests/gnosis/Oracles/UltimateOracleFactory.sol +++ b/test/compilationTests/gnosis/Oracles/UltimateOracleFactory.sol @@ -50,7 +50,7 @@ contract UltimateOracleFactory { challengeAmount, frontRunnerPeriod ); - UltimateOracleCreation( + emit UltimateOracleCreation( msg.sender, ultimateOracle, oracle, diff --git a/test/compilationTests/gnosis/Tokens/EtherToken.sol b/test/compilationTests/gnosis/Tokens/EtherToken.sol index f6e73e5a..32e64583 100644 --- a/test/compilationTests/gnosis/Tokens/EtherToken.sol +++ b/test/compilationTests/gnosis/Tokens/EtherToken.sol @@ -30,7 +30,7 @@ contract EtherToken is StandardToken { { balances[msg.sender] = balances[msg.sender].add(msg.value); totalTokens = totalTokens.add(msg.value); - Deposit(msg.sender, msg.value); + emit Deposit(msg.sender, msg.value); } /// @dev Sells tokens in exchange for Ether, exchanging them 1:1 @@ -42,6 +42,6 @@ contract EtherToken is StandardToken { balances[msg.sender] = balances[msg.sender].sub(value); totalTokens = totalTokens.sub(value); msg.sender.transfer(value); - Withdrawal(msg.sender, value); + emit Withdrawal(msg.sender, value); } } diff --git a/test/compilationTests/gnosis/Tokens/OutcomeToken.sol b/test/compilationTests/gnosis/Tokens/OutcomeToken.sol index fd1fa590..0bc7307d 100644 --- a/test/compilationTests/gnosis/Tokens/OutcomeToken.sol +++ b/test/compilationTests/gnosis/Tokens/OutcomeToken.sol @@ -31,7 +31,7 @@ contract OutcomeToken is StandardToken { * Public functions */ /// @dev Constructor sets events contract address - function OutcomeToken() + constructor() public { eventContract = msg.sender; @@ -46,7 +46,7 @@ contract OutcomeToken is StandardToken { { balances[_for] = balances[_for].add(outcomeTokenCount); totalTokens = totalTokens.add(outcomeTokenCount); - Issuance(_for, outcomeTokenCount); + emit Issuance(_for, outcomeTokenCount); } /// @dev Events contract revokes tokens for address. Returns success @@ -58,6 +58,6 @@ contract OutcomeToken is StandardToken { { balances[_for] = balances[_for].sub(outcomeTokenCount); totalTokens = totalTokens.sub(outcomeTokenCount); - Revocation(_for, outcomeTokenCount); + emit Revocation(_for, outcomeTokenCount); } } diff --git a/test/compilationTests/gnosis/Tokens/StandardToken.sol b/test/compilationTests/gnosis/Tokens/StandardToken.sol index fc899ca6..5fb20210 100644 --- a/test/compilationTests/gnosis/Tokens/StandardToken.sol +++ b/test/compilationTests/gnosis/Tokens/StandardToken.sol @@ -30,7 +30,7 @@ contract StandardToken is Token { return false; balances[msg.sender] -= value; balances[to] += value; - Transfer(msg.sender, to, value); + emit Transfer(msg.sender, to, value); return true; } @@ -50,7 +50,7 @@ contract StandardToken is Token { balances[from] -= value; allowances[from][msg.sender] -= value; balances[to] += value; - Transfer(from, to, value); + emit Transfer(from, to, value); return true; } @@ -63,7 +63,7 @@ contract StandardToken is Token { returns (bool) { allowances[msg.sender][spender] = value; - Approval(msg.sender, spender, value); + emit Approval(msg.sender, spender, value); return true; } @@ -73,7 +73,7 @@ contract StandardToken is Token { /// @return Remaining allowance for spender function allowance(address owner, address spender) public - constant + view returns (uint) { return allowances[owner][spender]; @@ -84,7 +84,7 @@ contract StandardToken is Token { /// @return Balance of owner function balanceOf(address owner) public - constant + view returns (uint) { return balances[owner]; @@ -94,7 +94,7 @@ contract StandardToken is Token { /// @return Total supply function totalSupply() public - constant + view returns (uint) { return totalTokens; diff --git a/test/compilationTests/gnosis/Tokens/Token.sol b/test/compilationTests/gnosis/Tokens/Token.sol index 19bb618b..70ecdff7 100644 --- a/test/compilationTests/gnosis/Tokens/Token.sol +++ b/test/compilationTests/gnosis/Tokens/Token.sol @@ -17,7 +17,7 @@ contract Token { function transfer(address to, uint value) public returns (bool); function transferFrom(address from, address to, uint value) public returns (bool); function approve(address spender, uint value) public returns (bool); - function balanceOf(address owner) public constant returns (uint); - function allowance(address owner, address spender) public constant returns (uint); - function totalSupply() public constant returns (uint); + function balanceOf(address owner) public view returns (uint); + function allowance(address owner, address spender) public view returns (uint); + function totalSupply() public view returns (uint); } diff --git a/test/compilationTests/gnosis/Utils/Math.sol b/test/compilationTests/gnosis/Utils/Math.sol index 95d95346..93456c33 100644 --- a/test/compilationTests/gnosis/Utils/Math.sol +++ b/test/compilationTests/gnosis/Utils/Math.sol @@ -22,7 +22,7 @@ library Math { /// @return e**x function exp(int x) public - constant + pure returns (uint) { // revert if x is > MAX_POWER, where @@ -107,7 +107,7 @@ library Math { /// @return ln(x) function ln(uint x) public - constant + pure returns (int) { require(x > 0); @@ -157,7 +157,7 @@ library Math { /// @return logarithmic value function floorLog2(uint x) public - constant + pure returns (int lo) { lo = -64; @@ -178,7 +178,7 @@ library Math { /// @return Maximum number function max(int[] nums) public - constant + pure returns (int max) { require(nums.length > 0); @@ -194,7 +194,7 @@ library Math { /// @return Did no overflow occur? function safeToAdd(uint a, uint b) public - constant + pure returns (bool) { return a + b >= a; @@ -206,7 +206,7 @@ library Math { /// @return Did no underflow occur? function safeToSub(uint a, uint b) public - constant + pure returns (bool) { return a >= b; @@ -218,7 +218,7 @@ library Math { /// @return Did no overflow occur? function safeToMul(uint a, uint b) public - constant + pure returns (bool) { return b == 0 || a * b / b == a; @@ -230,7 +230,7 @@ library Math { /// @return Sum function add(uint a, uint b) public - constant + pure returns (uint) { require(safeToAdd(a, b)); @@ -243,7 +243,7 @@ library Math { /// @return Difference function sub(uint a, uint b) public - constant + pure returns (uint) { require(safeToSub(a, b)); @@ -256,7 +256,7 @@ library Math { /// @return Product function mul(uint a, uint b) public - constant + pure returns (uint) { require(safeToMul(a, b)); @@ -269,7 +269,7 @@ library Math { /// @return Did no overflow occur? function safeToAdd(int a, int b) public - constant + pure returns (bool) { return (b >= 0 && a + b >= a) || (b < 0 && a + b < a); @@ -281,7 +281,7 @@ library Math { /// @return Did no underflow occur? function safeToSub(int a, int b) public - constant + pure returns (bool) { return (b >= 0 && a - b <= a) || (b < 0 && a - b > a); @@ -293,7 +293,7 @@ library Math { /// @return Did no overflow occur? function safeToMul(int a, int b) public - constant + pure returns (bool) { return (b == 0) || (a * b / b == a); @@ -305,7 +305,7 @@ library Math { /// @return Sum function add(int a, int b) public - constant + pure returns (int) { require(safeToAdd(a, b)); @@ -318,7 +318,7 @@ library Math { /// @return Difference function sub(int a, int b) public - constant + pure returns (int) { require(safeToSub(a, b)); @@ -331,7 +331,7 @@ library Math { /// @return Product function mul(int a, int b) public - constant + pure returns (int) { require(safeToMul(a, b)); diff --git a/test/compilationTests/milestonetracker/MilestoneTracker.sol b/test/compilationTests/milestonetracker/MilestoneTracker.sol index 318330df..bc182f9d 100644 --- a/test/compilationTests/milestonetracker/MilestoneTracker.sol +++ b/test/compilationTests/milestonetracker/MilestoneTracker.sol @@ -22,7 +22,7 @@ pragma solidity ^0.4.6; /// @dev This contract tracks the -/// is rules the relation betwen a donor and a recipient +/// is rules the relation between a donor and a recipient /// in order to guaranty to the donor that the job will be done and to guaranty /// to the recipient that he will be paid @@ -108,11 +108,11 @@ contract MilestoneTracker { /// @param _arbitrator Address assigned to be the arbitrator /// @param _donor Address assigned to be the donor /// @param _recipient Address assigned to be the recipient - function MilestoneTracker ( + constructor ( address _arbitrator, address _donor, address _recipient - ) { + ) public { arbitrator = _arbitrator; donor = _donor; recipient = _recipient; @@ -124,7 +124,7 @@ contract MilestoneTracker { ///////// /// @return The number of milestones ever created even if they were canceled - function numberOfMilestones() constant returns (uint) { + function numberOfMilestones() public view returns (uint) { return milestones.length; } @@ -135,19 +135,19 @@ contract MilestoneTracker { /// @notice `onlyArbitrator` Reassigns the arbitrator to a new address /// @param _newArbitrator The new arbitrator - function changeArbitrator(address _newArbitrator) onlyArbitrator { + function changeArbitrator(address _newArbitrator) public onlyArbitrator { arbitrator = _newArbitrator; } /// @notice `onlyDonor` Reassigns the `donor` to a new address /// @param _newDonor The new donor - function changeDonor(address _newDonor) onlyDonor { + function changeDonor(address _newDonor) public onlyDonor { donor = _newDonor; } /// @notice `onlyRecipient` Reassigns the `recipient` to a new address /// @param _newRecipient The new recipient - function changeRecipient(address _newRecipient) onlyRecipient { + function changeRecipient(address _newRecipient) public onlyRecipient { recipient = _newRecipient; } @@ -176,10 +176,10 @@ contract MilestoneTracker { /// address paymentSource, /// bytes payData, function proposeMilestones(bytes _newMilestones - ) onlyRecipient campaignNotCanceled { + ) public onlyRecipient campaignNotCanceled { proposedMilestones = _newMilestones; changingMilestones = true; - NewMilestoneListProposed(); + emit NewMilestoneListProposed(); } @@ -189,23 +189,23 @@ contract MilestoneTracker { /// @notice `onlyRecipient` Cancels the proposed milestones and reactivates /// the previous set of milestones - function unproposeMilestones() onlyRecipient campaignNotCanceled { + function unproposeMilestones() public onlyRecipient campaignNotCanceled { delete proposedMilestones; changingMilestones = false; - NewMilestoneListUnproposed(); + emit NewMilestoneListUnproposed(); } /// @notice `onlyDonor` Approves the proposed milestone list - /// @param _hashProposals The sha3() of the proposed milestone list's + /// @param _hashProposals The keccak256() of the proposed milestone list's /// bytecode; this confirms that the `donor` knows the set of milestones /// they are approving function acceptProposedMilestones(bytes32 _hashProposals - ) onlyDonor campaignNotCanceled { + ) public onlyDonor campaignNotCanceled { uint i; if (!changingMilestones) throw; - if (sha3(proposedMilestones) != _hashProposals) throw; + if (keccak256(proposedMilestones) != _hashProposals) throw; // Cancel all the unfinished milestones for (i=0; i<milestones.length; i++) { @@ -216,22 +216,22 @@ contract MilestoneTracker { // Decode the RLP encoded milestones and add them to the milestones list bytes memory mProposedMilestones = proposedMilestones; - var itmProposals = mProposedMilestones.toRLPItem(true); + RLP.RLPItem memory itmProposals = mProposedMilestones.toRLPItem(true); if (!itmProposals.isList()) throw; - var itrProposals = itmProposals.iterator(); + RLP.Iterator memory itrProposals = itmProposals.iterator(); while(itrProposals.hasNext()) { - var itmProposal = itrProposals.next(); + RLP.RLPItem memory itmProposal = itrProposals.next(); - Milestone milestone = milestones[milestones.length ++]; + Milestone storage milestone = milestones[milestones.length ++]; if (!itmProposal.isList()) throw; - var itrProposal = itmProposal.iterator(); + RLP.Iterator memory itrProposal = itmProposal.iterator(); milestone.description = itrProposal.next().toAscii(); milestone.url = itrProposal.next().toAscii(); @@ -249,17 +249,17 @@ contract MilestoneTracker { delete proposedMilestones; changingMilestones = false; - NewMilestoneListAccepted(); + emit NewMilestoneListAccepted(); } /// @notice `onlyRecipientOrLeadLink`Marks a milestone as DONE and /// ready for review /// @param _idMilestone ID of the milestone that has been completed function markMilestoneComplete(uint _idMilestone) - campaignNotCanceled notChanging + public campaignNotCanceled notChanging { if (_idMilestone >= milestones.length) throw; - Milestone milestone = milestones[_idMilestone]; + Milestone storage milestone = milestones[_idMilestone]; if ( (msg.sender != milestone.milestoneLeadLink) &&(msg.sender != recipient)) throw; @@ -268,16 +268,16 @@ contract MilestoneTracker { if (now > milestone.maxCompletionDate) throw; milestone.status = MilestoneStatus.Completed; milestone.doneTime = now; - ProposalStatusChanged(_idMilestone, milestone.status); + emit ProposalStatusChanged(_idMilestone, milestone.status); } /// @notice `onlyReviewer` Approves a specific milestone /// @param _idMilestone ID of the milestone that is approved function approveCompletedMilestone(uint _idMilestone) - campaignNotCanceled notChanging + public campaignNotCanceled notChanging { if (_idMilestone >= milestones.length) throw; - Milestone milestone = milestones[_idMilestone]; + Milestone storage milestone = milestones[_idMilestone]; if ((msg.sender != milestone.reviewer) || (milestone.status != MilestoneStatus.Completed)) throw; @@ -289,15 +289,15 @@ contract MilestoneTracker { /// state /// @param _idMilestone ID of the milestone that is being rejected function rejectMilestone(uint _idMilestone) - campaignNotCanceled notChanging + public campaignNotCanceled notChanging { if (_idMilestone >= milestones.length) throw; - Milestone milestone = milestones[_idMilestone]; + Milestone storage milestone = milestones[_idMilestone]; if ((msg.sender != milestone.reviewer) || (milestone.status != MilestoneStatus.Completed)) throw; milestone.status = MilestoneStatus.AcceptedAndInProgress; - ProposalStatusChanged(_idMilestone, milestone.status); + emit ProposalStatusChanged(_idMilestone, milestone.status); } /// @notice `onlyRecipientOrLeadLink` Sends the milestone payment as @@ -305,9 +305,9 @@ contract MilestoneTracker { /// `reviewTime` has elapsed /// @param _idMilestone ID of the milestone to be paid out function requestMilestonePayment(uint _idMilestone - ) campaignNotCanceled notChanging { + ) public campaignNotCanceled notChanging { if (_idMilestone >= milestones.length) throw; - Milestone milestone = milestones[_idMilestone]; + Milestone storage milestone = milestones[_idMilestone]; if ( (msg.sender != milestone.milestoneLeadLink) &&(msg.sender != recipient)) throw; @@ -321,25 +321,25 @@ contract MilestoneTracker { /// @notice `onlyRecipient` Cancels a previously accepted milestone /// @param _idMilestone ID of the milestone to be canceled function cancelMilestone(uint _idMilestone) - onlyRecipient campaignNotCanceled notChanging + public onlyRecipient campaignNotCanceled notChanging { if (_idMilestone >= milestones.length) throw; - Milestone milestone = milestones[_idMilestone]; + Milestone storage milestone = milestones[_idMilestone]; if ((milestone.status != MilestoneStatus.AcceptedAndInProgress) && (milestone.status != MilestoneStatus.Completed)) throw; milestone.status = MilestoneStatus.Canceled; - ProposalStatusChanged(_idMilestone, milestone.status); + emit ProposalStatusChanged(_idMilestone, milestone.status); } /// @notice `onlyArbitrator` Forces a milestone to be paid out as long as it /// has not been paid or canceled /// @param _idMilestone ID of the milestone to be paid out function arbitrateApproveMilestone(uint _idMilestone - ) onlyArbitrator campaignNotCanceled notChanging { + ) public onlyArbitrator campaignNotCanceled notChanging { if (_idMilestone >= milestones.length) throw; - Milestone milestone = milestones[_idMilestone]; + Milestone storage milestone = milestones[_idMilestone]; if ((milestone.status != MilestoneStatus.AcceptedAndInProgress) && (milestone.status != MilestoneStatus.Completed)) throw; @@ -348,20 +348,20 @@ contract MilestoneTracker { /// @notice `onlyArbitrator` Cancels the entire campaign voiding all /// milestones. - function arbitrateCancelCampaign() onlyArbitrator campaignNotCanceled { + function arbitrateCancelCampaign() public onlyArbitrator campaignNotCanceled { campaignCanceled = true; - CampaignCanceled(); + emit CampaignCanceled(); } // @dev This internal function is executed when the milestone is paid out function authorizePayment(uint _idMilestone) internal { if (_idMilestone >= milestones.length) throw; - Milestone milestone = milestones[_idMilestone]; + Milestone storage milestone = milestones[_idMilestone]; // Recheck again to not pay twice if (milestone.status == MilestoneStatus.AuthorizedForPayment) throw; milestone.status = MilestoneStatus.AuthorizedForPayment; if (!milestone.paymentSource.call.value(0)(milestone.payData)) throw; - ProposalStatusChanged(_idMilestone, milestone.status); + emit ProposalStatusChanged(_idMilestone, milestone.status); } } diff --git a/test/compilationTests/milestonetracker/RLP.sol b/test/compilationTests/milestonetracker/RLP.sol index 1b8cd1cb..e96bb332 100644 --- a/test/compilationTests/milestonetracker/RLP.sol +++ b/test/compilationTests/milestonetracker/RLP.sol @@ -30,10 +30,10 @@ library RLP { /* Iterator */ - function next(Iterator memory self) internal constant returns (RLPItem memory subItem) { + function next(Iterator memory self) internal view returns (RLPItem memory subItem) { if(hasNext(self)) { - var ptr = self._unsafe_nextPtr; - var itemLength = _itemLength(ptr); + uint ptr = self._unsafe_nextPtr; + uint itemLength = _itemLength(ptr); subItem._unsafe_memPtr = ptr; subItem._unsafe_length = itemLength; self._unsafe_nextPtr = ptr + itemLength; @@ -42,15 +42,15 @@ library RLP { throw; } - function next(Iterator memory self, bool strict) internal constant returns (RLPItem memory subItem) { + function next(Iterator memory self, bool strict) internal view returns (RLPItem memory subItem) { subItem = next(self); if(strict && !_validate(subItem)) throw; return; } - function hasNext(Iterator memory self) internal constant returns (bool) { - var item = self._unsafe_item; + function hasNext(Iterator memory self) internal view returns (bool) { + RLPItem memory item = self._unsafe_item; return self._unsafe_nextPtr < item._unsafe_memPtr + item._unsafe_length; } @@ -59,7 +59,7 @@ library RLP { /// @dev Creates an RLPItem from an array of RLP encoded bytes. /// @param self The RLP encoded bytes. /// @return An RLPItem - function toRLPItem(bytes memory self) internal constant returns (RLPItem memory) { + function toRLPItem(bytes memory self) internal view returns (RLPItem memory) { uint len = self.length; if (len == 0) { return RLPItem(0, 0); @@ -75,8 +75,8 @@ library RLP { /// @param self The RLP encoded bytes. /// @param strict Will throw if the data is not RLP encoded. /// @return An RLPItem - function toRLPItem(bytes memory self, bool strict) internal constant returns (RLPItem memory) { - var item = toRLPItem(self); + function toRLPItem(bytes memory self, bool strict) internal view returns (RLPItem memory) { + RLPItem memory item = toRLPItem(self); if(strict) { uint len = self.length; if(_payloadOffset(item) > len) @@ -92,14 +92,14 @@ library RLP { /// @dev Check if the RLP item is null. /// @param self The RLP item. /// @return 'true' if the item is null. - function isNull(RLPItem memory self) internal constant returns (bool ret) { + function isNull(RLPItem memory self) internal view returns (bool ret) { return self._unsafe_length == 0; } /// @dev Check if the RLP item is a list. /// @param self The RLP item. /// @return 'true' if the item is a list. - function isList(RLPItem memory self) internal constant returns (bool ret) { + function isList(RLPItem memory self) internal view returns (bool ret) { if (self._unsafe_length == 0) return false; uint memPtr = self._unsafe_memPtr; @@ -111,7 +111,7 @@ library RLP { /// @dev Check if the RLP item is data. /// @param self The RLP item. /// @return 'true' if the item is data. - function isData(RLPItem memory self) internal constant returns (bool ret) { + function isData(RLPItem memory self) internal view returns (bool ret) { if (self._unsafe_length == 0) return false; uint memPtr = self._unsafe_memPtr; @@ -123,7 +123,7 @@ library RLP { /// @dev Check if the RLP item is empty (string or list). /// @param self The RLP item. /// @return 'true' if the item is null. - function isEmpty(RLPItem memory self) internal constant returns (bool ret) { + function isEmpty(RLPItem memory self) internal view returns (bool ret) { if(isNull(self)) return false; uint b0; @@ -137,7 +137,7 @@ library RLP { /// @dev Get the number of items in an RLP encoded list. /// @param self The RLP item. /// @return The number of items. - function items(RLPItem memory self) internal constant returns (uint) { + function items(RLPItem memory self) internal view returns (uint) { if (!isList(self)) return 0; uint b0; @@ -158,7 +158,7 @@ library RLP { /// @dev Create an iterator. /// @param self The RLP item. /// @return An 'Iterator' over the item. - function iterator(RLPItem memory self) internal constant returns (Iterator memory it) { + function iterator(RLPItem memory self) internal view returns (Iterator memory it) { if (!isList(self)) throw; uint ptr = self._unsafe_memPtr + _payloadOffset(self); @@ -169,8 +169,8 @@ library RLP { /// @dev Return the RLP encoded bytes. /// @param self The RLPItem. /// @return The bytes. - function toBytes(RLPItem memory self) internal constant returns (bytes memory bts) { - var len = self._unsafe_length; + function toBytes(RLPItem memory self) internal returns (bytes memory bts) { + uint len = self._unsafe_length; if (len == 0) return; bts = new bytes(len); @@ -181,10 +181,10 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toData(RLPItem memory self) internal constant returns (bytes memory bts) { + function toData(RLPItem memory self) internal returns (bytes memory bts) { if(!isData(self)) throw; - var (rStartPos, len) = _decode(self); + (uint rStartPos, uint len) = _decode(self); bts = new bytes(len); _copyToBytes(rStartPos, bts, len); } @@ -193,12 +193,12 @@ library RLP { /// Warning: This is inefficient, as it requires that the list is read twice. /// @param self The RLP item. /// @return Array of RLPItems. - function toList(RLPItem memory self) internal constant returns (RLPItem[] memory list) { + function toList(RLPItem memory self) internal view returns (RLPItem[] memory list) { if(!isList(self)) throw; - var numItems = items(self); + uint numItems = items(self); list = new RLPItem[](numItems); - var it = iterator(self); + Iterator memory it = iterator(self); uint idx; while(hasNext(it)) { list[idx] = next(it); @@ -210,10 +210,10 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toAscii(RLPItem memory self) internal constant returns (string memory str) { + function toAscii(RLPItem memory self) internal returns (string memory str) { if(!isData(self)) throw; - var (rStartPos, len) = _decode(self); + (uint rStartPos, uint len) = _decode(self); bytes memory bts = new bytes(len); _copyToBytes(rStartPos, bts, len); str = string(bts); @@ -223,10 +223,10 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toUint(RLPItem memory self) internal constant returns (uint data) { + function toUint(RLPItem memory self) internal view returns (uint data) { if(!isData(self)) throw; - var (rStartPos, len) = _decode(self); + (uint rStartPos, uint len) = _decode(self); if (len > 32 || len == 0) throw; assembly { @@ -238,10 +238,10 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toBool(RLPItem memory self) internal constant returns (bool data) { + function toBool(RLPItem memory self) internal view returns (bool data) { if(!isData(self)) throw; - var (rStartPos, len) = _decode(self); + (uint rStartPos, uint len) = _decode(self); if (len != 1) throw; uint temp; @@ -257,10 +257,10 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toByte(RLPItem memory self) internal constant returns (byte data) { + function toByte(RLPItem memory self) internal view returns (byte data) { if(!isData(self)) throw; - var (rStartPos, len) = _decode(self); + (uint rStartPos, uint len) = _decode(self); if (len != 1) throw; uint8 temp; @@ -274,7 +274,7 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toInt(RLPItem memory self) internal constant returns (int data) { + function toInt(RLPItem memory self) internal view returns (int data) { return int(toUint(self)); } @@ -282,7 +282,7 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toBytes32(RLPItem memory self) internal constant returns (bytes32 data) { + function toBytes32(RLPItem memory self) internal view returns (bytes32 data) { return bytes32(toUint(self)); } @@ -290,10 +290,10 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toAddress(RLPItem memory self) internal constant returns (address data) { + function toAddress(RLPItem memory self) internal view returns (address data) { if(!isData(self)) throw; - var (rStartPos, len) = _decode(self); + (uint rStartPos, uint len) = _decode(self); if (len != 20) throw; assembly { @@ -302,7 +302,7 @@ library RLP { } // Get the payload offset. - function _payloadOffset(RLPItem memory self) private constant returns (uint) { + function _payloadOffset(RLPItem memory self) private view returns (uint) { if(self._unsafe_length == 0) return 0; uint b0; @@ -320,7 +320,7 @@ library RLP { } // Get the full length of an RLP item. - function _itemLength(uint memPtr) private constant returns (uint len) { + function _itemLength(uint memPtr) private view returns (uint len) { uint b0; assembly { b0 := byte(0, mload(memPtr)) @@ -348,7 +348,7 @@ library RLP { } // Get start position and length of the data. - function _decode(RLPItem memory self) private constant returns (uint memPtr, uint len) { + function _decode(RLPItem memory self) private view returns (uint memPtr, uint len) { if(!isData(self)) throw; uint b0; @@ -376,7 +376,7 @@ library RLP { } // Assumes that enough memory has been allocated to store in target. - function _copyToBytes(uint btsPtr, bytes memory tgt, uint btsLen) private constant { + function _copyToBytes(uint btsPtr, bytes memory tgt, uint btsLen) private { // Exploiting the fact that 'tgt' was the last thing to be allocated, // we can write entire words, and just overwrite any excess. assembly { @@ -400,7 +400,7 @@ library RLP { } // Check that an RLP item is valid. - function _validate(RLPItem memory self) private constant returns (bool ret) { + function _validate(RLPItem memory self) private view returns (bool ret) { // Check that RLP is well-formed. uint b0; uint b1; diff --git a/test/compilationTests/stringutils/strings.sol b/test/compilationTests/stringutils/strings.sol index 0a2d68bd..fc46ec5a 100644 --- a/test/compilationTests/stringutils/strings.sol +++ b/test/compilationTests/stringutils/strings.sol @@ -135,7 +135,7 @@ library strings { * @return A newly allocated string containing the slice's text. */ function toString(slice self) internal returns (string) { - var ret = new string(self._len); + string memory ret = new string(self._len); uint retptr; assembly { retptr := add(ret, 32) } @@ -153,9 +153,10 @@ library strings { */ function len(slice self) internal returns (uint) { // Starting at ptr-31 means the LSB will be the byte we care about - var ptr = self._ptr - 31; - var end = ptr + self._len; - for (uint len = 0; ptr < end; len++) { + uint ptr = self._ptr - 31; + uint end = ptr + self._len; + uint len; + for (len = 0; ptr < end; len++) { uint8 b; assembly { b := and(mload(ptr), 0xFF) } if (b < 0x80) { @@ -198,8 +199,8 @@ library strings { if (other._len < self._len) shortest = other._len; - var selfptr = self._ptr; - var otherptr = other._ptr; + uint selfptr = self._ptr; + uint otherptr = other._ptr; for (uint idx = 0; idx < shortest; idx += 32) { uint a; uint b; @@ -210,7 +211,7 @@ library strings { if (a != b) { // Mask out irrelevant bytes and check again uint mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); - var diff = (a & mask) - (b & mask); + uint diff = (a & mask) - (b & mask); if (diff != 0) return int(diff); } @@ -299,7 +300,7 @@ library strings { // Load the rune into the MSBs of b assembly { word:= mload(mload(add(self, 32))) } - var b = word / div; + uint b = word / div; if (b < 0x80) { ret = b; len = 1; @@ -339,7 +340,7 @@ library strings { */ function keccak(slice self) internal returns (bytes32 ret) { assembly { - ret := sha3(mload(add(self, 32)), mload(self)) + ret := keccak256(mload(add(self, 32)), mload(self)) } } @@ -363,7 +364,7 @@ library strings { let len := mload(needle) let selfptr := mload(add(self, 0x20)) let needleptr := mload(add(needle, 0x20)) - equal := eq(sha3(selfptr, len), sha3(needleptr, len)) + equal := eq(keccak256(selfptr, len), keccak256(needleptr, len)) } return equal; } @@ -386,7 +387,7 @@ library strings { let len := mload(needle) let selfptr := mload(add(self, 0x20)) let needleptr := mload(add(needle, 0x20)) - equal := eq(sha3(selfptr, len), sha3(needleptr, len)) + equal := eq(keccak256(selfptr, len), keccak256(needleptr, len)) } } @@ -409,7 +410,7 @@ library strings { return false; } - var selfptr = self._ptr + self._len - needle._len; + uint selfptr = self._ptr + self._len - needle._len; if (selfptr == needle._ptr) { return true; @@ -419,7 +420,7 @@ library strings { assembly { let len := mload(needle) let needleptr := mload(add(needle, 0x20)) - equal := eq(sha3(selfptr, len), sha3(needleptr, len)) + equal := eq(keccak256(selfptr, len), keccak256(needleptr, len)) } return equal; @@ -437,13 +438,13 @@ library strings { return self; } - var selfptr = self._ptr + self._len - needle._len; + uint selfptr = self._ptr + self._len - needle._len; bool equal = true; if (selfptr != needle._ptr) { assembly { let len := mload(needle) let needleptr := mload(add(needle, 0x20)) - equal := eq(sha3(selfptr, len), sha3(needleptr, len)) + equal := eq(keccak256(selfptr, len), keccak256(needleptr, len)) } } @@ -479,11 +480,11 @@ library strings { } else { // For long needles, use hashing bytes32 hash; - assembly { hash := sha3(needleptr, needlelen) } + assembly { hash := keccak256(needleptr, needlelen) } ptr = selfptr; for (idx = 0; idx <= selflen - needlelen; idx++) { bytes32 testHash; - assembly { testHash := sha3(ptr, needlelen) } + assembly { testHash := keccak256(ptr, needlelen) } if (hash == testHash) return ptr; ptr += 1; @@ -519,11 +520,11 @@ library strings { } else { // For long needles, use hashing bytes32 hash; - assembly { hash := sha3(needleptr, needlelen) } + assembly { hash := keccak256(needleptr, needlelen) } ptr = selfptr + (selflen - needlelen); while (ptr >= selfptr) { bytes32 testHash; - assembly { testHash := sha3(ptr, needlelen) } + assembly { testHash := keccak256(ptr, needlelen) } if (hash == testHash) return ptr + needlelen; ptr -= 1; @@ -667,7 +668,7 @@ library strings { * @return The concatenation of the two strings. */ function concat(slice self, slice other) internal returns (string) { - var ret = new string(self._len + other._len); + string memory ret = new string(self._len + other._len); uint retptr; assembly { retptr := add(ret, 32) } memcpy(retptr, self._ptr, self._len); @@ -691,11 +692,11 @@ library strings { for(uint i = 0; i < parts.length; i++) len += parts[i]._len; - var ret = new string(len); + string memory ret = new string(len); uint retptr; assembly { retptr := add(ret, 32) } - for(i = 0; i < parts.length; i++) { + for(uint i = 0; i < parts.length; i++) { memcpy(retptr, parts[i]._ptr, parts[i]._len); retptr += parts[i]._len; if (i < parts.length - 1) { diff --git a/test/compilationTests/zeppelin/Bounty.sol b/test/compilationTests/zeppelin/Bounty.sol index 4425b7a5..a5e75cd3 100644 --- a/test/compilationTests/zeppelin/Bounty.sol +++ b/test/compilationTests/zeppelin/Bounty.sol @@ -16,9 +16,9 @@ contract Bounty is PullPayment, Destructible { event TargetCreated(address createdAddress); /** - * @dev Fallback function allowing the contract to recieve funds, if they haven't already been claimed. + * @dev Fallback function allowing the contract to receive funds, if they haven't already been claimed. */ - function() payable { + function() external payable { if (claimed) { throw; } @@ -29,10 +29,10 @@ contract Bounty is PullPayment, Destructible { * msg.sender as a researcher * @return A target contract */ - function createTarget() returns(Target) { + function createTarget() public returns(Target) { Target target = Target(deployContract()); researchers[target] = msg.sender; - TargetCreated(target); + emit TargetCreated(target); return target; } @@ -46,16 +46,16 @@ contract Bounty is PullPayment, Destructible { * @dev Sends the contract funds to the researcher that proved the contract is broken. * @param target contract */ - function claim(Target target) { + function claim(Target target) public { address researcher = researchers[target]; - if (researcher == 0) { + if (researcher == address(0)) { throw; } // Check Target contract invariants if (target.checkInvariant()) { throw; } - asyncSend(researcher, this.balance); + asyncSend(researcher, address(this).balance); claimed = true; } @@ -74,5 +74,5 @@ contract Target { * In order to win the bounty, security researchers will try to cause this broken state. * @return True if all invariant values are correct, false otherwise. */ - function checkInvariant() returns(bool); + function checkInvariant() public returns(bool); } diff --git a/test/compilationTests/zeppelin/DayLimit.sol b/test/compilationTests/zeppelin/DayLimit.sol index 3c8d5b0c..5a2937b5 100644 --- a/test/compilationTests/zeppelin/DayLimit.sol +++ b/test/compilationTests/zeppelin/DayLimit.sol @@ -15,7 +15,7 @@ contract DayLimit { * @dev Constructor that sets the passed value as a dailyLimit. * @param _limit uint256 to represent the daily limit. */ - function DayLimit(uint256 _limit) { + constructor(uint256 _limit) public { dailyLimit = _limit; lastDay = today(); } @@ -59,7 +59,7 @@ contract DayLimit { * @dev Private function to determine today's index * @return uint256 of today's index. */ - function today() private constant returns (uint256) { + function today() private view returns (uint256) { return now / 1 days; } diff --git a/test/compilationTests/zeppelin/LimitBalance.sol b/test/compilationTests/zeppelin/LimitBalance.sol index 57477c74..9682ff1c 100644 --- a/test/compilationTests/zeppelin/LimitBalance.sol +++ b/test/compilationTests/zeppelin/LimitBalance.sol @@ -15,7 +15,7 @@ contract LimitBalance { * @dev Constructor that sets the passed value as a limit. * @param _limit uint256 to represent the limit. */ - function LimitBalance(uint256 _limit) { + constructor(uint256 _limit) public { limit = _limit; } @@ -23,7 +23,7 @@ contract LimitBalance { * @dev Checks if limit was reached. Case true, it throws. */ modifier limitedPayable() { - if (this.balance > limit) { + if (address(this).balance > limit) { throw; } _; diff --git a/test/compilationTests/zeppelin/MultisigWallet.sol b/test/compilationTests/zeppelin/MultisigWallet.sol index 939e70f2..e8e8d05d 100644 --- a/test/compilationTests/zeppelin/MultisigWallet.sol +++ b/test/compilationTests/zeppelin/MultisigWallet.sol @@ -25,31 +25,31 @@ contract MultisigWallet is Multisig, Shareable, DayLimit { * @param _owners A list of owners. * @param _required The amount required for a transaction to be approved. */ - function MultisigWallet(address[] _owners, uint256 _required, uint256 _daylimit) - Shareable(_owners, _required) - DayLimit(_daylimit) { } + constructor(address[] _owners, uint256 _required, uint256 _daylimit) + Shareable(_owners, _required) + DayLimit(_daylimit) public { } - /** - * @dev destroys the contract sending everything to `_to`. + /** + * @dev destroys the contract sending everything to `_to`. */ function destroy(address _to) onlymanyowners(keccak256(msg.data)) external { selfdestruct(_to); } - /** - * @dev Fallback function, receives value and emits a deposit event. + /** + * @dev Fallback function, receives value and emits a deposit event. */ - function() payable { + function() external payable { // just being sent some cash? if (msg.value > 0) - Deposit(msg.sender, msg.value); + emit Deposit(msg.sender, msg.value); } /** - * @dev Outside-visible transaction entry point. Executes transaction immediately if below daily - * spending limit. If not, goes into multisig process. We provide a hash on return to allow the - * sender to provide shortcuts for the other confirmations (allowing them to avoid replicating - * the _to, _value, and _data arguments). They still get the option of using them if they want, + * @dev Outside-visible transaction entry point. Executes transaction immediately if below daily + * spending limit. If not, goes into multisig process. We provide a hash on return to allow the + * sender to provide shortcuts for the other confirmations (allowing them to avoid replicating + * the _to, _value, and _data arguments). They still get the option of using them if they want, * anyways. * @param _to The receiver address * @param _value The value to send @@ -58,7 +58,7 @@ contract MultisigWallet is Multisig, Shareable, DayLimit { function execute(address _to, uint256 _value, bytes _data) external onlyOwner returns (bytes32 _r) { // first, take the opportunity to check that we're under the daily limit. if (underLimit(_value)) { - SingleTransact(msg.sender, _value, _to, _data); + emit SingleTransact(msg.sender, _value, _to, _data); // yes - just execute the call. if (!_to.call.value(_value)(_data)) { throw; @@ -66,40 +66,40 @@ contract MultisigWallet is Multisig, Shareable, DayLimit { return 0; } // determine our operation hash. - _r = keccak256(msg.data, block.number); - if (!confirm(_r) && txs[_r].to == 0) { + _r = keccak256(abi.encodePacked(msg.data, block.number)); + if (!confirm(_r) && txs[_r].to == address(0)) { txs[_r].to = _to; txs[_r].value = _value; txs[_r].data = _data; - ConfirmationNeeded(_r, msg.sender, _value, _to, _data); + emit ConfirmationNeeded(_r, msg.sender, _value, _to, _data); } } /** - * @dev Confirm a transaction by providing just the hash. We use the previous transactions map, + * @dev Confirm a transaction by providing just the hash. We use the previous transactions map, * txs, in order to determine the body of the transaction from the hash provided. * @param _h The transaction hash to approve. */ - function confirm(bytes32 _h) onlymanyowners(_h) returns (bool) { - if (txs[_h].to != 0) { + function confirm(bytes32 _h) onlymanyowners(_h) public returns (bool) { + if (txs[_h].to != address(0)) { if (!txs[_h].to.call.value(txs[_h].value)(txs[_h].data)) { throw; } - MultiTransact(msg.sender, _h, txs[_h].value, txs[_h].to, txs[_h].data); + emit MultiTransact(msg.sender, _h, txs[_h].value, txs[_h].to, txs[_h].data); delete txs[_h]; return true; } } - /** - * @dev Updates the daily limit value. + /** + * @dev Updates the daily limit value. * @param _newLimit uint256 to represent the new limit. */ function setDailyLimit(uint256 _newLimit) onlymanyowners(keccak256(msg.data)) external { _setDailyLimit(_newLimit); } - /** + /** * @dev Resets the value spent to enable more spending */ function resetSpentToday() onlymanyowners(keccak256(msg.data)) external { @@ -108,7 +108,7 @@ contract MultisigWallet is Multisig, Shareable, DayLimit { // INTERNAL METHODS - /** + /** * @dev Clears the list of transactions pending approval. */ function clearPending() internal { diff --git a/test/compilationTests/zeppelin/ReentrancyGuard.sol b/test/compilationTests/zeppelin/ReentrancyGuard.sol index ca8b643b..60c7927b 100644 --- a/test/compilationTests/zeppelin/ReentrancyGuard.sol +++ b/test/compilationTests/zeppelin/ReentrancyGuard.sol @@ -1,7 +1,7 @@ pragma solidity ^0.4.11; /** - * @title Helps contracts guard agains rentrancy attacks. + * @title Helps contracts guard against rentrancy attacks. * @author Remco Bloemen <remco@2π.com> * @notice If you mark a function `nonReentrant`, you should also * mark it `external`. diff --git a/test/compilationTests/zeppelin/crowdsale/CappedCrowdsale.sol b/test/compilationTests/zeppelin/crowdsale/CappedCrowdsale.sol index f04649f3..98c8c3d4 100644 --- a/test/compilationTests/zeppelin/crowdsale/CappedCrowdsale.sol +++ b/test/compilationTests/zeppelin/crowdsale/CappedCrowdsale.sol @@ -12,20 +12,20 @@ contract CappedCrowdsale is Crowdsale { uint256 public cap; - function CappedCrowdsale(uint256 _cap) { + constructor(uint256 _cap) public { cap = _cap; } // overriding Crowdsale#validPurchase to add extra cap logic // @return true if investors can buy at the moment - function validPurchase() internal constant returns (bool) { + function validPurchase() internal view returns (bool) { bool withinCap = weiRaised.add(msg.value) <= cap; return super.validPurchase() && withinCap; } // overriding Crowdsale#hasEnded to add cap logic // @return true if crowdsale event has ended - function hasEnded() public constant returns (bool) { + function hasEnded() public view returns (bool) { bool capReached = weiRaised >= cap; return super.hasEnded() || capReached; } diff --git a/test/compilationTests/zeppelin/crowdsale/Crowdsale.sol b/test/compilationTests/zeppelin/crowdsale/Crowdsale.sol index bee1efd2..51eeb7b8 100644 --- a/test/compilationTests/zeppelin/crowdsale/Crowdsale.sol +++ b/test/compilationTests/zeppelin/crowdsale/Crowdsale.sol @@ -4,11 +4,11 @@ import '../token/MintableToken.sol'; import '../math/SafeMath.sol'; /** - * @title Crowdsale + * @title Crowdsale * @dev Crowdsale is a base contract for managing a token crowdsale. * Crowdsales have a start and end block, where investors can make * token purchases and the crowdsale will assign them tokens based - * on a token per ETH rate. Funds collected are forwarded to a wallet + * on a token per ETH rate. Funds collected are forwarded to a wallet * as they arrive. */ contract Crowdsale { @@ -36,15 +36,15 @@ contract Crowdsale { * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased - */ + */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); - function Crowdsale(uint256 _startBlock, uint256 _endBlock, uint256 _rate, address _wallet) { + constructor(uint256 _startBlock, uint256 _endBlock, uint256 _rate, address _wallet) public { require(_startBlock >= block.number); require(_endBlock >= _startBlock); require(_rate > 0); - require(_wallet != 0x0); + require(_wallet != address(0x0)); token = createTokenContract(); startBlock = _startBlock; @@ -53,7 +53,7 @@ contract Crowdsale { wallet = _wallet; } - // creates the token to be sold. + // creates the token to be sold. // override this method to have crowdsale of a specific mintable token. function createTokenContract() internal returns (MintableToken) { return new MintableToken(); @@ -61,13 +61,13 @@ contract Crowdsale { // fallback function can be used to buy tokens - function () payable { + function () external payable { buyTokens(msg.sender); } // low level token purchase function - function buyTokens(address beneficiary) payable { - require(beneficiary != 0x0); + function buyTokens(address beneficiary) public payable { + require(beneficiary != address(0x0)); require(validPurchase()); uint256 weiAmount = msg.value; @@ -80,7 +80,7 @@ contract Crowdsale { weiRaised = updatedWeiRaised; token.mint(beneficiary, tokens); - TokenPurchase(msg.sender, beneficiary, weiAmount, tokens); + emit TokenPurchase(msg.sender, beneficiary, weiAmount, tokens); forwardFunds(); } @@ -92,7 +92,7 @@ contract Crowdsale { } // @return true if the transaction can buy tokens - function validPurchase() internal constant returns (bool) { + function validPurchase() internal view returns (bool) { uint256 current = block.number; bool withinPeriod = current >= startBlock && current <= endBlock; bool nonZeroPurchase = msg.value != 0; @@ -100,7 +100,7 @@ contract Crowdsale { } // @return true if crowdsale event has ended - function hasEnded() public constant returns (bool) { + function hasEnded() public view returns (bool) { return block.number > endBlock; } diff --git a/test/compilationTests/zeppelin/crowdsale/FinalizableCrowdsale.sol b/test/compilationTests/zeppelin/crowdsale/FinalizableCrowdsale.sol index 1a736083..da4e3b7f 100644 --- a/test/compilationTests/zeppelin/crowdsale/FinalizableCrowdsale.sol +++ b/test/compilationTests/zeppelin/crowdsale/FinalizableCrowdsale.sol @@ -18,12 +18,12 @@ contract FinalizableCrowdsale is Crowdsale, Ownable { // should be called after crowdsale ends, to do // some extra finalization work - function finalize() onlyOwner { + function finalize() public onlyOwner { require(!isFinalized); require(hasEnded()); finalization(); - Finalized(); + emit Finalized(); isFinalized = true; } diff --git a/test/compilationTests/zeppelin/crowdsale/RefundVault.sol b/test/compilationTests/zeppelin/crowdsale/RefundVault.sol index cc92ff9f..b7db8ef2 100644 --- a/test/compilationTests/zeppelin/crowdsale/RefundVault.sol +++ b/test/compilationTests/zeppelin/crowdsale/RefundVault.sol @@ -22,35 +22,35 @@ contract RefundVault is Ownable { event RefundsEnabled(); event Refunded(address indexed beneficiary, uint256 weiAmount); - function RefundVault(address _wallet) { - require(_wallet != 0x0); + constructor(address _wallet) public { + require(_wallet != address(0x0)); wallet = _wallet; state = State.Active; } - function deposit(address investor) onlyOwner payable { + function deposit(address investor) public onlyOwner payable { require(state == State.Active); deposited[investor] = deposited[investor].add(msg.value); } - function close() onlyOwner { + function close() public onlyOwner { require(state == State.Active); state = State.Closed; - Closed(); - wallet.transfer(this.balance); + emit Closed(); + wallet.transfer(address(this).balance); } - function enableRefunds() onlyOwner { + function enableRefunds() public onlyOwner { require(state == State.Active); state = State.Refunding; - RefundsEnabled(); + emit RefundsEnabled(); } - function refund(address investor) { + function refund(address investor) public { require(state == State.Refunding); uint256 depositedValue = deposited[investor]; deposited[investor] = 0; investor.transfer(depositedValue); - Refunded(investor, depositedValue); + emit Refunded(investor, depositedValue); } } diff --git a/test/compilationTests/zeppelin/crowdsale/RefundableCrowdsale.sol b/test/compilationTests/zeppelin/crowdsale/RefundableCrowdsale.sol index f45df1d3..94e3af99 100644 --- a/test/compilationTests/zeppelin/crowdsale/RefundableCrowdsale.sol +++ b/test/compilationTests/zeppelin/crowdsale/RefundableCrowdsale.sol @@ -21,7 +21,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale { // refund vault used to hold funds while crowdsale is running RefundVault public vault; - function RefundableCrowdsale(uint256 _goal) { + constructor(uint256 _goal) public { vault = new RefundVault(wallet); goal = _goal; } @@ -34,7 +34,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale { } // if crowdsale is unsuccessful, investors can claim refunds here - function claimRefund() { + function claimRefund() public { require(isFinalized); require(!goalReached()); @@ -52,7 +52,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale { super.finalization(); } - function goalReached() public constant returns (bool) { + function goalReached() public view returns (bool) { return weiRaised >= goal; } diff --git a/test/compilationTests/zeppelin/lifecycle/Destructible.sol b/test/compilationTests/zeppelin/lifecycle/Destructible.sol index 3561e3b7..5b0e9f58 100644 --- a/test/compilationTests/zeppelin/lifecycle/Destructible.sol +++ b/test/compilationTests/zeppelin/lifecycle/Destructible.sol @@ -10,16 +10,16 @@ import "../ownership/Ownable.sol"; */ contract Destructible is Ownable { - function Destructible() payable { } + constructor() public payable { } /** * @dev Transfers the current balance to the owner and terminates the contract. */ - function destroy() onlyOwner { + function destroy() public onlyOwner { selfdestruct(owner); } - function destroyAndSend(address _recipient) onlyOwner { + function destroyAndSend(address _recipient) public onlyOwner { selfdestruct(_recipient); } } diff --git a/test/compilationTests/zeppelin/lifecycle/Migrations.sol b/test/compilationTests/zeppelin/lifecycle/Migrations.sol index d5b05308..4ca95d36 100644 --- a/test/compilationTests/zeppelin/lifecycle/Migrations.sol +++ b/test/compilationTests/zeppelin/lifecycle/Migrations.sol @@ -10,11 +10,11 @@ import '../ownership/Ownable.sol'; contract Migrations is Ownable { uint256 public lastCompletedMigration; - function setCompleted(uint256 completed) onlyOwner { + function setCompleted(uint256 completed) public onlyOwner { lastCompletedMigration = completed; } - function upgrade(address newAddress) onlyOwner { + function upgrade(address newAddress) public onlyOwner { Migrations upgraded = Migrations(newAddress); upgraded.setCompleted(lastCompletedMigration); } diff --git a/test/compilationTests/zeppelin/lifecycle/Pausable.sol b/test/compilationTests/zeppelin/lifecycle/Pausable.sol index b14f8767..4ffd281a 100644 --- a/test/compilationTests/zeppelin/lifecycle/Pausable.sol +++ b/test/compilationTests/zeppelin/lifecycle/Pausable.sol @@ -34,18 +34,18 @@ contract Pausable is Ownable { /** * @dev called by the owner to pause, triggers stopped state */ - function pause() onlyOwner whenNotPaused returns (bool) { + function pause() public onlyOwner whenNotPaused returns (bool) { paused = true; - Pause(); + emit Pause(); return true; } /** * @dev called by the owner to unpause, returns to normal state */ - function unpause() onlyOwner whenPaused returns (bool) { + function unpause() public onlyOwner whenPaused returns (bool) { paused = false; - Unpause(); + emit Unpause(); return true; } } diff --git a/test/compilationTests/zeppelin/lifecycle/TokenDestructible.sol b/test/compilationTests/zeppelin/lifecycle/TokenDestructible.sol index fe0b46b6..0b19eb71 100644 --- a/test/compilationTests/zeppelin/lifecycle/TokenDestructible.sol +++ b/test/compilationTests/zeppelin/lifecycle/TokenDestructible.sol @@ -12,7 +12,7 @@ import "../token/ERC20Basic.sol"; */ contract TokenDestructible is Ownable { - function TokenDestructible() payable { } + constructor() public payable { } /** * @notice Terminate contract and refund to owner @@ -21,7 +21,7 @@ contract TokenDestructible is Ownable { * @notice The called token contracts could try to re-enter this contract. Only supply token contracts you trust. */ - function destroy(address[] tokens) onlyOwner { + function destroy(address[] tokens) public onlyOwner { // Transfer tokens to owner for(uint256 i = 0; i < tokens.length; i++) { diff --git a/test/compilationTests/zeppelin/math/Math.sol b/test/compilationTests/zeppelin/math/Math.sol index 3d016c0a..9997998a 100644 --- a/test/compilationTests/zeppelin/math/Math.sol +++ b/test/compilationTests/zeppelin/math/Math.sol @@ -6,19 +6,19 @@ pragma solidity ^0.4.11; */ library Math { - function max64(uint64 a, uint64 b) internal constant returns (uint64) { + function max64(uint64 a, uint64 b) internal pure returns (uint64) { return a >= b ? a : b; } - function min64(uint64 a, uint64 b) internal constant returns (uint64) { + function min64(uint64 a, uint64 b) internal pure returns (uint64) { return a < b ? a : b; } - function max256(uint256 a, uint256 b) internal constant returns (uint256) { + function max256(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } - function min256(uint256 a, uint256 b) internal constant returns (uint256) { + function min256(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } } diff --git a/test/compilationTests/zeppelin/math/SafeMath.sol b/test/compilationTests/zeppelin/math/SafeMath.sol index dc05ba28..a98635e2 100644 --- a/test/compilationTests/zeppelin/math/SafeMath.sol +++ b/test/compilationTests/zeppelin/math/SafeMath.sol @@ -6,25 +6,25 @@ pragma solidity ^0.4.11; * @dev Math operations with safety checks that throw on error */ library SafeMath { - function mul(uint256 a, uint256 b) internal returns (uint256) { + function mul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } - function div(uint256 a, uint256 b) internal returns (uint256) { + function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } - function sub(uint256 a, uint256 b) internal returns (uint256) { + function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } - function add(uint256 a, uint256 b) internal returns (uint256) { + function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; diff --git a/test/compilationTests/zeppelin/ownership/Claimable.sol b/test/compilationTests/zeppelin/ownership/Claimable.sol index d063502d..72390411 100644 --- a/test/compilationTests/zeppelin/ownership/Claimable.sol +++ b/test/compilationTests/zeppelin/ownership/Claimable.sol @@ -26,15 +26,15 @@ contract Claimable is Ownable { * @dev Allows the current owner to set the pendingOwner address. * @param newOwner The address to transfer ownership to. */ - function transferOwnership(address newOwner) onlyOwner { + function transferOwnership(address newOwner) public onlyOwner { pendingOwner = newOwner; } /** * @dev Allows the pendingOwner address to finalize the transfer. */ - function claimOwnership() onlyPendingOwner { + function claimOwnership() public onlyPendingOwner { owner = pendingOwner; - pendingOwner = 0x0; + pendingOwner = address(0x0); } } diff --git a/test/compilationTests/zeppelin/ownership/Contactable.sol b/test/compilationTests/zeppelin/ownership/Contactable.sol index 0db3ee07..11b0e1dd 100644 --- a/test/compilationTests/zeppelin/ownership/Contactable.sol +++ b/test/compilationTests/zeppelin/ownership/Contactable.sol @@ -15,7 +15,7 @@ contract Contactable is Ownable{ * @dev Allows the owner to set a string with their contact information. * @param info The contact information to attach to the contract. */ - function setContactInformation(string info) onlyOwner{ + function setContactInformation(string info) public onlyOwner{ contactInformation = info; } } diff --git a/test/compilationTests/zeppelin/ownership/DelayedClaimable.sol b/test/compilationTests/zeppelin/ownership/DelayedClaimable.sol index f5fee614..f019d2f1 100644 --- a/test/compilationTests/zeppelin/ownership/DelayedClaimable.sol +++ b/test/compilationTests/zeppelin/ownership/DelayedClaimable.sol @@ -20,7 +20,7 @@ contract DelayedClaimable is Claimable { * @param _start The earliest time ownership can be claimed. * @param _end The latest time ownership can be claimed. */ - function setLimits(uint256 _start, uint256 _end) onlyOwner { + function setLimits(uint256 _start, uint256 _end) public onlyOwner { if (_start > _end) throw; end = _end; @@ -32,11 +32,11 @@ contract DelayedClaimable is Claimable { * @dev Allows the pendingOwner address to finalize the transfer, as long as it is called within * the specified start and end time. */ - function claimOwnership() onlyPendingOwner { + function claimOwnership() public onlyPendingOwner { if ((block.number > end) || (block.number < start)) throw; owner = pendingOwner; - pendingOwner = 0x0; + pendingOwner = address(0x0); end = 0; } diff --git a/test/compilationTests/zeppelin/ownership/HasNoEther.sol b/test/compilationTests/zeppelin/ownership/HasNoEther.sol index 2bcaf1b8..9f294679 100644 --- a/test/compilationTests/zeppelin/ownership/HasNoEther.sol +++ b/test/compilationTests/zeppelin/ownership/HasNoEther.sol @@ -21,7 +21,7 @@ contract HasNoEther is Ownable { * constructor. By doing it this way we prevent a payable constructor from working. Alternatively * we could use assembly to access msg.value. */ - function HasNoEther() payable { + constructor() public payable { if(msg.value > 0) { throw; } @@ -37,7 +37,7 @@ contract HasNoEther is Ownable { * @dev Transfer all Ether held by the contract to the owner. */ function reclaimEther() external onlyOwner { - if(!owner.send(this.balance)) { + if(!owner.send(address(this).balance)) { throw; } } diff --git a/test/compilationTests/zeppelin/ownership/Multisig.sol b/test/compilationTests/zeppelin/ownership/Multisig.sol index 76c78411..25531d8d 100644 --- a/test/compilationTests/zeppelin/ownership/Multisig.sol +++ b/test/compilationTests/zeppelin/ownership/Multisig.sol @@ -24,5 +24,5 @@ contract Multisig { // TODO: document function changeOwner(address _from, address _to) external; function execute(address _to, uint256 _value, bytes _data) external returns (bytes32); - function confirm(bytes32 _h) returns (bool); + function confirm(bytes32 _h) public returns (bool); } diff --git a/test/compilationTests/zeppelin/ownership/Ownable.sol b/test/compilationTests/zeppelin/ownership/Ownable.sol index f1628454..7417b2bd 100644 --- a/test/compilationTests/zeppelin/ownership/Ownable.sol +++ b/test/compilationTests/zeppelin/ownership/Ownable.sol @@ -14,7 +14,7 @@ contract Ownable { * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ - function Ownable() { + constructor() public { owner = msg.sender; } @@ -34,7 +34,7 @@ contract Ownable { * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ - function transferOwnership(address newOwner) onlyOwner { + function transferOwnership(address newOwner) public onlyOwner { if (newOwner != address(0)) { owner = newOwner; } diff --git a/test/compilationTests/zeppelin/ownership/Shareable.sol b/test/compilationTests/zeppelin/ownership/Shareable.sol index 9fdaccfd..d44f63b8 100644 --- a/test/compilationTests/zeppelin/ownership/Shareable.sol +++ b/test/compilationTests/zeppelin/ownership/Shareable.sol @@ -59,7 +59,7 @@ contract Shareable { * @param _owners A list of owners. * @param _required The amount required for a transaction to be approved. */ - function Shareable(address[] _owners, uint256 _required) { + constructor(address[] _owners, uint256 _required) public { owners[1] = msg.sender; ownerIndex[msg.sender] = 1; for (uint256 i = 0; i < _owners.length; ++i) { @@ -83,11 +83,11 @@ contract Shareable { return; } uint256 ownerIndexBit = 2**index; - var pending = pendings[_operation]; + PendingState memory pending = pendings[_operation]; if (pending.ownersDone & ownerIndexBit > 0) { pending.yetNeeded++; pending.ownersDone -= ownerIndexBit; - Revoke(msg.sender, _operation); + emit Revoke(msg.sender, _operation); } } @@ -96,7 +96,7 @@ contract Shareable { * @param ownerIndex uint256 The index of the owner * @return The address of the owner */ - function getOwner(uint256 ownerIndex) external constant returns (address) { + function getOwner(uint256 ownerIndex) external view returns (address) { return address(owners[ownerIndex + 1]); } @@ -105,7 +105,7 @@ contract Shareable { * @param _addr address The address which you want to check. * @return True if the address is an owner and fase otherwise. */ - function isOwner(address _addr) constant returns (bool) { + function isOwner(address _addr) public view returns (bool) { return ownerIndex[_addr] > 0; } @@ -115,8 +115,8 @@ contract Shareable { * @param _owner The owner address. * @return True if the owner has confirmed and false otherwise. */ - function hasConfirmed(bytes32 _operation, address _owner) constant returns (bool) { - var pending = pendings[_operation]; + function hasConfirmed(bytes32 _operation, address _owner) public view returns (bool) { + PendingState memory pending = pendings[_operation]; uint256 index = ownerIndex[_owner]; // make sure they're an owner @@ -142,7 +142,7 @@ contract Shareable { throw; } - var pending = pendings[_operation]; + PendingState memory pending = pendings[_operation]; // if we're not yet working on this operation, switch over and reset the confirmation status. if (pending.yetNeeded == 0) { // reset count of confirmations needed. @@ -156,7 +156,7 @@ contract Shareable { uint256 ownerIndexBit = 2**index; // make sure we (the message sender) haven't confirmed this operation previously. if (pending.ownersDone & ownerIndexBit == 0) { - Confirmation(msg.sender, _operation); + emit Confirmation(msg.sender, _operation); // ok - check if count is enough to go ahead. if (pending.yetNeeded <= 1) { // enough confirmations: reset and run interior. diff --git a/test/compilationTests/zeppelin/payment/PullPayment.sol b/test/compilationTests/zeppelin/payment/PullPayment.sol index ba710b53..2f3e1b51 100644 --- a/test/compilationTests/zeppelin/payment/PullPayment.sol +++ b/test/compilationTests/zeppelin/payment/PullPayment.sol @@ -28,7 +28,7 @@ contract PullPayment { /** * @dev withdraw accumulated balance, called by payee. */ - function withdrawPayments() { + function withdrawPayments() public { address payee = msg.sender; uint256 payment = payments[payee]; @@ -36,7 +36,7 @@ contract PullPayment { throw; } - if (this.balance < payment) { + if (address(this).balance < payment) { throw; } diff --git a/test/compilationTests/zeppelin/token/BasicToken.sol b/test/compilationTests/zeppelin/token/BasicToken.sol index 5618227a..bc085f85 100644 --- a/test/compilationTests/zeppelin/token/BasicToken.sol +++ b/test/compilationTests/zeppelin/token/BasicToken.sol @@ -19,10 +19,10 @@ contract BasicToken is ERC20Basic { * @param _to The address to transfer to. * @param _value The amount to be transferred. */ - function transfer(address _to, uint256 _value) { + function transfer(address _to, uint256 _value) public { balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); - Transfer(msg.sender, _to, _value); + emit Transfer(msg.sender, _to, _value); } /** @@ -30,7 +30,7 @@ contract BasicToken is ERC20Basic { * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ - function balanceOf(address _owner) constant returns (uint256 balance) { + function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } diff --git a/test/compilationTests/zeppelin/token/ERC20.sol b/test/compilationTests/zeppelin/token/ERC20.sol index 1045ac35..5b5dc748 100644 --- a/test/compilationTests/zeppelin/token/ERC20.sol +++ b/test/compilationTests/zeppelin/token/ERC20.sol @@ -9,8 +9,8 @@ import './ERC20Basic.sol'; * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 is ERC20Basic { - function allowance(address owner, address spender) constant returns (uint256); - function transferFrom(address from, address to, uint256 value); - function approve(address spender, uint256 value); + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public; + function approve(address spender, uint256 value) public; event Approval(address indexed owner, address indexed spender, uint256 value); } diff --git a/test/compilationTests/zeppelin/token/ERC20Basic.sol b/test/compilationTests/zeppelin/token/ERC20Basic.sol index 0e98779e..fbe33134 100644 --- a/test/compilationTests/zeppelin/token/ERC20Basic.sol +++ b/test/compilationTests/zeppelin/token/ERC20Basic.sol @@ -8,7 +8,7 @@ pragma solidity ^0.4.11; */ contract ERC20Basic { uint256 public totalSupply; - function balanceOf(address who) constant returns (uint256); - function transfer(address to, uint256 value); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public; event Transfer(address indexed from, address indexed to, uint256 value); } diff --git a/test/compilationTests/zeppelin/token/LimitedTransferToken.sol b/test/compilationTests/zeppelin/token/LimitedTransferToken.sol index ee5032c9..052c28e6 100644 --- a/test/compilationTests/zeppelin/token/LimitedTransferToken.sol +++ b/test/compilationTests/zeppelin/token/LimitedTransferToken.sol @@ -10,7 +10,7 @@ import "./ERC20.sol"; * LimitedTransferToken has been designed to allow for different limiting factors, * this can be achieved by recursively calling super.transferableTokens() until the base class is * hit. For example: - * function transferableTokens(address holder, uint64 time) constant public returns (uint256) { + * function transferableTokens(address holder, uint64 time) view public returns (uint256) { * return min256(unlockedTokens, super.transferableTokens(holder, time)); * } * A working example is VestedToken.sol: @@ -29,20 +29,20 @@ contract LimitedTransferToken is ERC20 { /** * @dev Checks modifier and allows transfer if tokens are not locked. - * @param _to The address that will recieve the tokens. + * @param _to The address that will receive the tokens. * @param _value The amount of tokens to be transferred. */ - function transfer(address _to, uint256 _value) canTransfer(msg.sender, _value) { + function transfer(address _to, uint256 _value) canTransfer(msg.sender, _value) public { super.transfer(_to, _value); } /** * @dev Checks modifier and allows transfer if tokens are not locked. * @param _from The address that will send the tokens. - * @param _to The address that will recieve the tokens. + * @param _to The address that will receive the tokens. * @param _value The amount of tokens to be transferred. */ - function transferFrom(address _from, address _to, uint256 _value) canTransfer(_from, _value) { + function transferFrom(address _from, address _to, uint256 _value) public canTransfer(_from, _value) { super.transferFrom(_from, _to, _value); } @@ -51,7 +51,7 @@ contract LimitedTransferToken is ERC20 { * @dev Overwriting transferableTokens(address holder, uint64 time) is the way to provide the * specific logic for limiting token transferability for a holder over time. */ - function transferableTokens(address holder, uint64 time) constant public returns (uint256) { + function transferableTokens(address holder, uint64 time) view public returns (uint256) { return balanceOf(holder); } } diff --git a/test/compilationTests/zeppelin/token/MintableToken.sol b/test/compilationTests/zeppelin/token/MintableToken.sol index 505d13c3..f99964d0 100644 --- a/test/compilationTests/zeppelin/token/MintableToken.sol +++ b/test/compilationTests/zeppelin/token/MintableToken.sol @@ -27,14 +27,14 @@ contract MintableToken is StandardToken, Ownable { /** * @dev Function to mint tokens - * @param _to The address that will recieve the minted tokens. + * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ - function mint(address _to, uint256 _amount) onlyOwner canMint returns (bool) { + function mint(address _to, uint256 _amount) public onlyOwner canMint returns (bool) { totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); - Mint(_to, _amount); + emit Mint(_to, _amount); return true; } @@ -42,9 +42,9 @@ contract MintableToken is StandardToken, Ownable { * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ - function finishMinting() onlyOwner returns (bool) { + function finishMinting() public onlyOwner returns (bool) { mintingFinished = true; - MintFinished(); + emit MintFinished(); return true; } } diff --git a/test/compilationTests/zeppelin/token/PausableToken.sol b/test/compilationTests/zeppelin/token/PausableToken.sol index 8ee114e1..66f80b80 100644 --- a/test/compilationTests/zeppelin/token/PausableToken.sol +++ b/test/compilationTests/zeppelin/token/PausableToken.sol @@ -11,11 +11,11 @@ import '../lifecycle/Pausable.sol'; contract PausableToken is StandardToken, Pausable { - function transfer(address _to, uint _value) whenNotPaused { + function transfer(address _to, uint _value) public whenNotPaused { super.transfer(_to, _value); } - function transferFrom(address _from, address _to, uint _value) whenNotPaused { + function transferFrom(address _from, address _to, uint _value) public whenNotPaused { super.transferFrom(_from, _to, _value); } } diff --git a/test/compilationTests/zeppelin/token/SimpleToken.sol b/test/compilationTests/zeppelin/token/SimpleToken.sol index 898cb21d..6c3f5740 100644 --- a/test/compilationTests/zeppelin/token/SimpleToken.sol +++ b/test/compilationTests/zeppelin/token/SimpleToken.sol @@ -18,9 +18,9 @@ contract SimpleToken is StandardToken { uint256 public INITIAL_SUPPLY = 10000; /** - * @dev Contructor that gives msg.sender all of existing tokens. + * @dev Constructor that gives msg.sender all of existing tokens. */ - function SimpleToken() { + constructor() public { totalSupply = INITIAL_SUPPLY; balances[msg.sender] = INITIAL_SUPPLY; } diff --git a/test/compilationTests/zeppelin/token/StandardToken.sol b/test/compilationTests/zeppelin/token/StandardToken.sol index b1b49fe3..94b12e57 100644 --- a/test/compilationTests/zeppelin/token/StandardToken.sol +++ b/test/compilationTests/zeppelin/token/StandardToken.sol @@ -21,10 +21,10 @@ contract StandardToken is ERC20, BasicToken { * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to - * @param _value uint256 the amout of tokens to be transfered + * @param _value uint256 the amount of tokens to be transferred */ - function transferFrom(address _from, address _to, uint256 _value) { - var _allowance = allowed[_from][msg.sender]; + function transferFrom(address _from, address _to, uint256 _value) public { + uint256 _allowance = allowed[_from][msg.sender]; // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met // if (_value > _allowance) throw; @@ -32,7 +32,7 @@ contract StandardToken is ERC20, BasicToken { balances[_to] = balances[_to].add(_value); balances[_from] = balances[_from].sub(_value); allowed[_from][msg.sender] = _allowance.sub(_value); - Transfer(_from, _to, _value); + emit Transfer(_from, _to, _value); } /** @@ -40,7 +40,7 @@ contract StandardToken is ERC20, BasicToken { * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ - function approve(address _spender, uint256 _value) { + function approve(address _spender, uint256 _value) public { // To change the approve amount you first have to reduce the addresses` // allowance to zero by calling `approve(_spender, 0)` if it is not @@ -49,16 +49,16 @@ contract StandardToken is ERC20, BasicToken { if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw; allowed[msg.sender][_spender] = _value; - Approval(msg.sender, _spender, _value); + emit Approval(msg.sender, _spender, _value); } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. - * @return A uint256 specifing the amount of tokens still avaible for the spender. + * @return A uint256 specifying the amount of tokens still available for the spender. */ - function allowance(address _owner, address _spender) constant returns (uint256 remaining) { + function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } diff --git a/test/compilationTests/zeppelin/token/TokenTimelock.sol b/test/compilationTests/zeppelin/token/TokenTimelock.sol index 595bf8d0..fa1af025 100644 --- a/test/compilationTests/zeppelin/token/TokenTimelock.sol +++ b/test/compilationTests/zeppelin/token/TokenTimelock.sol @@ -19,7 +19,7 @@ contract TokenTimelock { // timestamp when token release is enabled uint releaseTime; - function TokenTimelock(ERC20Basic _token, address _beneficiary, uint _releaseTime) { + constructor(ERC20Basic _token, address _beneficiary, uint _releaseTime) public { require(_releaseTime > now); token = _token; beneficiary = _beneficiary; @@ -29,7 +29,7 @@ contract TokenTimelock { /** * @dev beneficiary claims tokens held by time lock */ - function claim() { + function claim() public { require(msg.sender == beneficiary); require(now >= releaseTime); diff --git a/test/compilationTests/zeppelin/token/VestedToken.sol b/test/compilationTests/zeppelin/token/VestedToken.sol index b7748b09..48818c3f 100644 --- a/test/compilationTests/zeppelin/token/VestedToken.sol +++ b/test/compilationTests/zeppelin/token/VestedToken.sol @@ -65,16 +65,16 @@ contract VestedToken is StandardToken, LimitedTransferToken { transfer(_to, _value); - NewTokenGrant(msg.sender, _to, _value, count - 1); + emit NewTokenGrant(msg.sender, _to, _value, count - 1); } /** - * @dev Revoke the grant of tokens of a specifed address. + * @dev Revoke the grant of tokens of a specified address. * @param _holder The address which will have its tokens revoked. * @param _grantId The id of the token grant. */ function revokeTokenGrant(address _holder, uint256 _grantId) public { - TokenGrant grant = grants[_holder][_grantId]; + TokenGrant storage grant = grants[_holder][_grantId]; if (!grant.revokable) { // Check if grant was revokable throw; @@ -96,7 +96,7 @@ contract VestedToken is StandardToken, LimitedTransferToken { balances[receiver] = balances[receiver].add(nonVested); balances[_holder] = balances[_holder].sub(nonVested); - Transfer(_holder, receiver, nonVested); + emit Transfer(_holder, receiver, nonVested); } @@ -106,7 +106,7 @@ contract VestedToken is StandardToken, LimitedTransferToken { * @param time uint64 The specific time. * @return An uint256 representing a holder's total amount of transferable tokens. */ - function transferableTokens(address holder, uint64 time) constant public returns (uint256) { + function transferableTokens(address holder, uint64 time) view public returns (uint256) { uint256 grantIndex = tokenGrantsCount(holder); if (grantIndex == 0) return balanceOf(holder); // shortcut for holder without grants @@ -130,18 +130,18 @@ contract VestedToken is StandardToken, LimitedTransferToken { * @param _holder The holder of the grants. * @return A uint256 representing the total amount of grants. */ - function tokenGrantsCount(address _holder) constant returns (uint256 index) { + function tokenGrantsCount(address _holder) public view returns (uint256 index) { return grants[_holder].length; } /** - * @dev Calculate amount of vested tokens at a specifc time. - * @param tokens uint256 The amount of tokens grantted. + * @dev Calculate amount of vested tokens at a specific time. + * @param tokens uint256 The amount of tokens granted. * @param time uint64 The time to be checked - * @param start uint64 A time representing the begining of the grant + * @param start uint64 A time representing the beginning of the grant * @param cliff uint64 The cliff period. * @param vesting uint64 The vesting period. - * @return An uint256 representing the amount of vested tokensof a specif grant. + * @return An uint256 representing the amount of vested tokens of a specific grant. * transferableTokens * | _/-------- vestedTokens rect * | _/ @@ -163,7 +163,7 @@ contract VestedToken is StandardToken, LimitedTransferToken { uint256 time, uint256 start, uint256 cliff, - uint256 vesting) constant returns (uint256) + uint256 vesting) public view returns (uint256) { // Shortcuts for before cliff and after vesting cases. if (time < cliff) return 0; @@ -186,14 +186,14 @@ contract VestedToken is StandardToken, LimitedTransferToken { } /** - * @dev Get all information about a specifc grant. + * @dev Get all information about a specific grant. * @param _holder The address which will have its tokens revoked. * @param _grantId The id of the token grant. * @return Returns all the values that represent a TokenGrant(address, value, start, cliff, * revokability, burnsOnRevoke, and vesting) plus the vested value at the current time. */ - function tokenGrant(address _holder, uint256 _grantId) constant returns (address granter, uint256 value, uint256 vested, uint64 start, uint64 cliff, uint64 vesting, bool revokable, bool burnsOnRevoke) { - TokenGrant grant = grants[_holder][_grantId]; + function tokenGrant(address _holder, uint256 _grantId) public view returns (address granter, uint256 value, uint256 vested, uint64 start, uint64 cliff, uint64 vesting, bool revokable, bool burnsOnRevoke) { + TokenGrant storage grant = grants[_holder][_grantId]; granter = grant.granter; value = grant.value; @@ -212,7 +212,7 @@ contract VestedToken is StandardToken, LimitedTransferToken { * @param time The time to be checked * @return An uint256 representing the amount of vested tokens of a specific grant at a specific time. */ - function vestedTokens(TokenGrant grant, uint64 time) private constant returns (uint256) { + function vestedTokens(TokenGrant grant, uint64 time) private view returns (uint256) { return calculateVestedTokens( grant.value, uint256(time), @@ -226,10 +226,10 @@ contract VestedToken is StandardToken, LimitedTransferToken { * @dev Calculate the amount of non vested tokens at a specific time. * @param grant TokenGrant The grant to be checked. * @param time uint64 The time to be checked - * @return An uint256 representing the amount of non vested tokens of a specifc grant on the + * @return An uint256 representing the amount of non vested tokens of a specific grant on the * passed time frame. */ - function nonVestedTokens(TokenGrant grant, uint64 time) private constant returns (uint256) { + function nonVestedTokens(TokenGrant grant, uint64 time) private view returns (uint256) { return grant.value.sub(vestedTokens(grant, time)); } @@ -238,7 +238,7 @@ contract VestedToken is StandardToken, LimitedTransferToken { * @param holder address The address of the holder * @return An uint256 representing the date of the last transferable tokens. */ - function lastTokenIsTransferableDate(address holder) constant public returns (uint64 date) { + function lastTokenIsTransferableDate(address holder) view public returns (uint64 date) { date = uint64(now); uint256 grantIndex = grants[holder].length; for (uint256 i = 0; i < grantIndex; i++) { diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp index 5e4991e2..0fc093e7 100644 --- a/test/contracts/AuctionRegistrar.cpp +++ b/test/contracts/AuctionRegistrar.cpp @@ -43,20 +43,20 @@ static char const* registrarCode = R"DELIMITER( pragma solidity ^0.4.0; contract NameRegister { - function addr(string _name) constant returns (address o_owner); - function name(address _owner) constant returns (string o_name); + function addr(string _name) view returns (address o_owner); + function name(address _owner) view returns (string o_name); } contract Registrar is NameRegister { event Changed(string indexed name); event PrimaryChanged(string indexed name, address indexed addr); - function owner(string _name) constant returns (address o_owner); - function addr(string _name) constant returns (address o_address); - function subRegistrar(string _name) constant returns (address o_subRegistrar); - function content(string _name) constant returns (bytes32 o_content); + function owner(string _name) view returns (address o_owner); + function addr(string _name) view returns (address o_address); + function subRegistrar(string _name) view returns (address o_subRegistrar); + function content(string _name) view returns (bytes32 o_content); - function name(address _owner) constant returns (string o_name); + function name(address _owner) view returns (string o_name); } contract AuctionSystem { @@ -67,10 +67,10 @@ contract AuctionSystem { function onAuctionEnd(string _name) internal; function bid(string _name, address _bidder, uint _value) internal { - var auction = m_auctions[_name]; + Auction storage auction = m_auctions[_name]; if (auction.endDate > 0 && now > auction.endDate) { - AuctionEnded(_name, auction.highestBidder); + emit AuctionEnded(_name, auction.highestBidder); onAuctionEnd(_name); delete m_auctions[_name]; return; @@ -84,7 +84,7 @@ contract AuctionSystem { auction.highestBidder = _bidder; auction.endDate = now + c_biddingTime; - NewBid(_name, _bidder, _value); + emit NewBid(_name, _bidder, _value); } } @@ -109,7 +109,7 @@ contract GlobalRegistrar is Registrar, AuctionSystem { uint renewalDate; } - uint constant c_renewalInterval = 1 years; + uint constant c_renewalInterval = 365 days; uint constant c_freeBytes = 12; function Registrar() { @@ -117,13 +117,13 @@ contract GlobalRegistrar is Registrar, AuctionSystem { } function onAuctionEnd(string _name) internal { - var auction = m_auctions[_name]; - var record = m_toRecord[_name]; - var previousOwner = record.owner; + Auction storage auction = m_auctions[_name]; + Record storage record = m_toRecord[_name]; + address previousOwner = record.owner; record.renewalDate = now + c_renewalInterval; record.owner = auction.highestBidder; - Changed(_name); - if (previousOwner != 0) { + emit Changed(_name); + if (previousOwner != 0x0000000000000000000000000000000000000000) { if (!record.owner.send(auction.sumOfBids - auction.highestBid / 100)) throw; } else { @@ -142,11 +142,11 @@ contract GlobalRegistrar is Registrar, AuctionSystem { throw; bid(_name, msg.sender, msg.value); } else { - Record record = m_toRecord[_name]; - if (record.owner != 0) + Record storage record = m_toRecord[_name]; + if (record.owner != 0x0000000000000000000000000000000000000000) throw; m_toRecord[_name].owner = msg.sender; - Changed(_name); + emit Changed(_name); } } @@ -158,35 +158,35 @@ contract GlobalRegistrar is Registrar, AuctionSystem { function transfer(string _name, address _newOwner) onlyrecordowner(_name) { m_toRecord[_name].owner = _newOwner; - Changed(_name); + emit Changed(_name); } function disown(string _name) onlyrecordowner(_name) { if (stringsEqual(m_toName[m_toRecord[_name].primary], _name)) { - PrimaryChanged(_name, m_toRecord[_name].primary); + emit PrimaryChanged(_name, m_toRecord[_name].primary); m_toName[m_toRecord[_name].primary] = ""; } delete m_toRecord[_name]; - Changed(_name); + emit Changed(_name); } function setAddress(string _name, address _a, bool _primary) onlyrecordowner(_name) { m_toRecord[_name].primary = _a; if (_primary) { - PrimaryChanged(_name, _a); + emit PrimaryChanged(_name, _a); m_toName[_a] = _name; } - Changed(_name); + emit Changed(_name); } function setSubRegistrar(string _name, address _registrar) onlyrecordowner(_name) { m_toRecord[_name].subRegistrar = _registrar; - Changed(_name); + emit Changed(_name); } function setContent(string _name, bytes32 _content) onlyrecordowner(_name) { m_toRecord[_name].content = _content; - Changed(_name); + emit Changed(_name); } function stringsEqual(string storage _a, string memory _b) internal returns (bool) { @@ -201,11 +201,11 @@ contract GlobalRegistrar is Registrar, AuctionSystem { return true; } - function owner(string _name) constant returns (address) { return m_toRecord[_name].owner; } - function addr(string _name) constant returns (address) { return m_toRecord[_name].primary; } - function subRegistrar(string _name) constant returns (address) { return m_toRecord[_name].subRegistrar; } - function content(string _name) constant returns (bytes32) { return m_toRecord[_name].content; } - function name(address _addr) constant returns (string o_name) { return m_toName[_addr]; } + function owner(string _name) view returns (address) { return m_toRecord[_name].owner; } + function addr(string _name) view returns (address) { return m_toRecord[_name].primary; } + function subRegistrar(string _name) view returns (address) { return m_toRecord[_name].subRegistrar; } + function content(string _name) view returns (bytes32) { return m_toRecord[_name].content; } + function name(address _addr) view returns (string o_name) { return m_toName[_addr]; } mapping (address => string) m_toName; mapping (string => Record) m_toRecord; @@ -223,6 +223,7 @@ protected: s_compiledRegistrar.reset(new bytes(compileContract(registrarCode, "GlobalRegistrar"))); sendMessage(*s_compiledRegistrar, true); + BOOST_REQUIRE(m_transactionSuccessful); BOOST_REQUIRE(!m_output.empty()); } diff --git a/test/contracts/FixedFeeRegistrar.cpp b/test/contracts/FixedFeeRegistrar.cpp index a3a27c37..aebdb053 100644 --- a/test/contracts/FixedFeeRegistrar.cpp +++ b/test/contracts/FixedFeeRegistrar.cpp @@ -58,10 +58,10 @@ pragma solidity ^0.4.0; contract Registrar { event Changed(string indexed name); - function owner(string _name) constant returns (address o_owner); - function addr(string _name) constant returns (address o_address); - function subRegistrar(string _name) constant returns (address o_subRegistrar); - function content(string _name) constant returns (bytes32 o_content); + function owner(string _name) view returns (address o_owner); + function addr(string _name) view returns (address o_address); + function subRegistrar(string _name) view returns (address o_subRegistrar); + function content(string _name) view returns (bytes32 o_content); } contract FixedFeeRegistrar is Registrar { @@ -75,50 +75,50 @@ contract FixedFeeRegistrar is Registrar { modifier onlyrecordowner(string _name) { if (m_record(_name).owner == msg.sender) _; } function reserve(string _name) payable { - Record rec = m_record(_name); - if (rec.owner == 0 && msg.value >= c_fee) { + Record storage rec = m_record(_name); + if (rec.owner == 0x0000000000000000000000000000000000000000 && msg.value >= c_fee) { rec.owner = msg.sender; - Changed(_name); + emit Changed(_name); } } function disown(string _name, address _refund) onlyrecordowner(_name) { - delete m_recordData[uint(keccak256(_name)) / 8]; + delete m_recordData[uint(keccak256(bytes(_name))) / 8]; if (!_refund.send(c_fee)) throw; - Changed(_name); + emit Changed(_name); } function transfer(string _name, address _newOwner) onlyrecordowner(_name) { m_record(_name).owner = _newOwner; - Changed(_name); + emit Changed(_name); } function setAddr(string _name, address _a) onlyrecordowner(_name) { m_record(_name).addr = _a; - Changed(_name); + emit Changed(_name); } function setSubRegistrar(string _name, address _registrar) onlyrecordowner(_name) { m_record(_name).subRegistrar = _registrar; - Changed(_name); + emit Changed(_name); } function setContent(string _name, bytes32 _content) onlyrecordowner(_name) { m_record(_name).content = _content; - Changed(_name); + emit Changed(_name); } - function record(string _name) constant returns (address o_addr, address o_subRegistrar, bytes32 o_content, address o_owner) { - Record rec = m_record(_name); + function record(string _name) view returns (address o_addr, address o_subRegistrar, bytes32 o_content, address o_owner) { + Record storage rec = m_record(_name); o_addr = rec.addr; o_subRegistrar = rec.subRegistrar; o_content = rec.content; o_owner = rec.owner; } - function addr(string _name) constant returns (address) { return m_record(_name).addr; } - function subRegistrar(string _name) constant returns (address) { return m_record(_name).subRegistrar; } - function content(string _name) constant returns (bytes32) { return m_record(_name).content; } - function owner(string _name) constant returns (address) { return m_record(_name).owner; } + function addr(string _name) view returns (address) { return m_record(_name).addr; } + function subRegistrar(string _name) view returns (address) { return m_record(_name).subRegistrar; } + function content(string _name) view returns (bytes32) { return m_record(_name).content; } + function owner(string _name) view returns (address) { return m_record(_name).owner; } Record[2**253] m_recordData; - function m_record(string _name) constant internal returns (Record storage o_record) { - return m_recordData[uint(keccak256(_name)) / 8]; + function m_record(string _name) view internal returns (Record storage o_record) { + return m_recordData[uint(keccak256(bytes(_name))) / 8]; } uint constant c_fee = 69 ether; } @@ -135,6 +135,7 @@ protected: s_compiledRegistrar.reset(new bytes(compileContract(registrarCode, "FixedFeeRegistrar"))); sendMessage(*s_compiledRegistrar, true); + BOOST_REQUIRE(m_transactionSuccessful); BOOST_REQUIRE(!m_output.empty()); } u256 const m_fee = u256("69000000000000000000"); diff --git a/test/contracts/LLL_ENS.cpp b/test/contracts/LLL_ENS.cpp index 028d58c8..3461c577 100644 --- a/test/contracts/LLL_ENS.cpp +++ b/test/contracts/LLL_ENS.cpp @@ -349,6 +349,7 @@ protected: BOOST_REQUIRE(errors.empty()); } sendMessage(*s_compiledEns, true); + BOOST_REQUIRE(m_transactionSuccessful); BOOST_REQUIRE(!m_output.empty()); } diff --git a/test/contracts/LLL_ERC20.cpp b/test/contracts/LLL_ERC20.cpp index 60b43e4f..89d1c4f0 100644 --- a/test/contracts/LLL_ERC20.cpp +++ b/test/contracts/LLL_ERC20.cpp @@ -400,6 +400,7 @@ protected: BOOST_REQUIRE(errors.empty()); } sendMessage(*s_compiledErc20, true); + BOOST_REQUIRE(m_transactionSuccessful); BOOST_REQUIRE(!m_output.empty()); } @@ -629,18 +630,22 @@ BOOST_AUTO_TEST_CASE(bad_data) // Correct data: transfer(address _to, 1). sendMessage((bytes)fromHex("a9059cbb") + (bytes)fromHex("000000000000000000000000123456789a123456789a123456789a123456789a") + encodeArgs(1), false, 0); + BOOST_CHECK(m_transactionSuccessful); BOOST_CHECK(m_output == SUCCESS); // Too little data (address is truncated by one byte). sendMessage((bytes)fromHex("a9059cbb") + (bytes)fromHex("000000000000000000000000123456789a123456789a123456789a12345678") + encodeArgs(1), false, 0); + BOOST_CHECK(!m_transactionSuccessful); BOOST_CHECK(m_output != SUCCESS); // Too much data (address is extended with a zero byte). sendMessage((bytes)fromHex("a9059cbb") + (bytes)fromHex("000000000000000000000000123456789a123456789a123456789a123456789a00") + encodeArgs(1), false, 0); + BOOST_CHECK(!m_transactionSuccessful); BOOST_CHECK(m_output != SUCCESS); // Invalid address (a bit above the 160th is set). sendMessage((bytes)fromHex("a9059cbb") + (bytes)fromHex("000000000000000000000100123456789a123456789a123456789a123456789a") + encodeArgs(1), false, 0); + BOOST_CHECK(!m_transactionSuccessful); BOOST_CHECK(m_output != SUCCESS); } diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp index 1031e8f1..45fe5bbd 100644 --- a/test/contracts/Wallet.cpp +++ b/test/contracts/Wallet.cpp @@ -101,7 +101,7 @@ contract multiowned { // constructor is given number of sigs required to do protected "onlymanyowners" transactions // as well as the selection of addresses capable of confirming them. - function multiowned(address[] _owners, uint _required) { + constructor(address[] _owners, uint _required) { m_numOwners = _owners.length + 1; m_owners[1] = uint(msg.sender); m_ownerIndex[uint(msg.sender)] = 1; @@ -119,11 +119,11 @@ contract multiowned { // make sure they're an owner if (ownerIndex == 0) return; uint ownerIndexBit = 2**ownerIndex; - var pending = m_pending[_operation]; + PendingState storage pending = m_pending[_operation]; if (pending.ownersDone & ownerIndexBit > 0) { pending.yetNeeded++; pending.ownersDone -= ownerIndexBit; - Revoke(msg.sender, _operation); + emit Revoke(msg.sender, _operation); } } @@ -137,7 +137,7 @@ contract multiowned { m_owners[ownerIndex] = uint(_to); m_ownerIndex[uint(_from)] = 0; m_ownerIndex[uint(_to)] = ownerIndex; - OwnerChanged(_from, _to); + emit OwnerChanged(_from, _to); } function addOwner(address _owner) onlymanyowners(keccak256(msg.data)) external { @@ -151,7 +151,7 @@ contract multiowned { m_numOwners++; m_owners[m_numOwners] = uint(_owner); m_ownerIndex[uint(_owner)] = m_numOwners; - OwnerAdded(_owner); + emit OwnerAdded(_owner); } function removeOwner(address _owner) onlymanyowners(keccak256(msg.data)) external { @@ -163,22 +163,22 @@ contract multiowned { m_ownerIndex[uint(_owner)] = 0; clearPending(); reorganizeOwners(); //make sure m_numOwner is equal to the number of owners and always points to the optimal free slot - OwnerRemoved(_owner); + emit OwnerRemoved(_owner); } function changeRequirement(uint _newRequired) onlymanyowners(keccak256(msg.data)) external { if (_newRequired > m_numOwners) return; m_required = _newRequired; clearPending(); - RequirementChanged(_newRequired); + emit RequirementChanged(_newRequired); } function isOwner(address _addr) returns (bool) { return m_ownerIndex[uint(_addr)] > 0; } - function hasConfirmed(bytes32 _operation, address _owner) constant returns (bool) { - var pending = m_pending[_operation]; + function hasConfirmed(bytes32 _operation, address _owner) view returns (bool) { + PendingState storage pending = m_pending[_operation]; uint ownerIndex = m_ownerIndex[uint(_owner)]; // make sure they're an owner @@ -201,7 +201,7 @@ contract multiowned { // make sure they're an owner if (ownerIndex == 0) return; - var pending = m_pending[_operation]; + PendingState storage pending = m_pending[_operation]; // if we're not yet working on this operation, switch over and reset the confirmation status. if (pending.yetNeeded == 0) { // reset count of confirmations needed. @@ -215,7 +215,7 @@ contract multiowned { uint ownerIndexBit = 2**ownerIndex; // make sure we (the message sender) haven't confirmed this operation previously. if (pending.ownersDone & ownerIndexBit == 0) { - Confirmation(msg.sender, _operation); + emit Confirmation(msg.sender, _operation); // ok - check if count is enough to go ahead. if (pending.yetNeeded <= 1) { // enough confirmations: reset and run interior. @@ -288,7 +288,7 @@ contract daylimit is multiowned { // METHODS // constructor - stores initial daily limit and records the present day's index. - function daylimit(uint _limit) { + constructor(uint _limit) { m_dailyLimit = _limit; m_lastDay = today(); } @@ -319,7 +319,7 @@ contract daylimit is multiowned { return false; } // determines today's index. - function today() private constant returns (uint) { return now / 1 days; } + function today() private view returns (uint) { return now / 1 days; } // FIELDS @@ -369,7 +369,7 @@ contract Wallet is multisig, multiowned, daylimit { // constructor - just pass on the owner array to the multiowned and // the limit to daylimit - function Wallet(address[] _owners, uint _required, uint _daylimit) payable + constructor(address[] _owners, uint _required, uint _daylimit) payable multiowned(_owners, _required) daylimit(_daylimit) { } @@ -379,40 +379,40 @@ contract Wallet is multisig, multiowned, daylimit { } // gets called when no other function matches - function() payable { + function() external payable { // just being sent some cash? if (msg.value > 0) - Deposit(msg.sender, msg.value); + emit Deposit(msg.sender, msg.value); } - // Outside-visible transact entry point. Executes transacion immediately if below daily spend limit. + // Outside-visible transact entry point. Executes transaction immediately if below daily spend limit. // If not, goes into multisig process. We provide a hash on return to allow the sender to provide // shortcuts for the other confirmations (allowing them to avoid replicating the _to, _value // and _data arguments). They still get the option of using them if they want, anyways. function execute(address _to, uint _value, bytes _data) external onlyowner returns (bytes32 _r) { // first, take the opportunity to check that we're under the daily limit. if (underLimit(_value)) { - SingleTransact(msg.sender, _value, _to, _data); + emit SingleTransact(msg.sender, _value, _to, _data); // yes - just execute the call. _to.call.value(_value)(_data); return 0; } // determine our operation hash. - _r = keccak256(msg.data, block.number); - if (!confirm(_r) && m_txs[_r].to == 0) { + _r = keccak256(abi.encodePacked(msg.data, block.number)); + if (!confirm(_r) && m_txs[_r].to == 0x0000000000000000000000000000000000000000) { m_txs[_r].to = _to; m_txs[_r].value = _value; m_txs[_r].data = _data; - ConfirmationNeeded(_r, msg.sender, _value, _to, _data); + emit ConfirmationNeeded(_r, msg.sender, _value, _to, _data); } } // confirm a transaction through just the hash. we use the previous transactions map, m_txs, in order // to determine the body of the transaction from the hash provided. function confirm(bytes32 _h) onlymanyowners(_h) returns (bool) { - if (m_txs[_h].to != 0) { + if (m_txs[_h].to != 0x0000000000000000000000000000000000000000) { m_txs[_h].to.call.value(m_txs[_h].value)(m_txs[_h].data); - MultiTransact(msg.sender, _h, m_txs[_h].value, m_txs[_h].to, m_txs[_h].data); + emit MultiTransact(msg.sender, _h, m_txs[_h].value, m_txs[_h].to, m_txs[_h].data); delete m_txs[_h]; return true; } @@ -451,6 +451,7 @@ protected: bytes args = encodeArgs(u256(0x60), _required, _dailyLimit, u256(_owners.size()), _owners); sendMessage(*s_compiledWallet + args, true, _value); + BOOST_REQUIRE(m_transactionSuccessful); BOOST_REQUIRE(!m_output.empty()); } }; diff --git a/test/externalTests.sh b/test/externalTests.sh index cd6deb75..f2839083 100755 --- a/test/externalTests.sh +++ b/test/externalTests.sh @@ -40,21 +40,41 @@ function test_truffle { name="$1" repo="$2" + branch="$3" echo "Running $name tests..." DIR=$(mktemp -d) ( - git clone --depth 1 "$repo" "$DIR" + if [ -n "$branch" ] + then + echo "Cloning $branch of $repo..." + git clone --depth 1 "$repo" -b "$branch" "$DIR" + else + echo "Cloning $repo..." + git clone --depth 1 "$repo" "$DIR" + fi cd "$DIR" + echo "Current commit hash: `git rev-parse HEAD`" npm install find . -name soljson.js -exec cp "$SOLJSON" {} \; if [ "$name" == "Gnosis" ]; then + echo "Replaced fixed-version pragmas..." # Replace fixed-version pragmas in Gnosis (part of Consensys best practice) find contracts test -name '*.sol' -type f -print0 | xargs -0 sed -i -e 's/pragma solidity 0/pragma solidity ^0/' fi + assertsol="node_modules/truffle/build/Assert.sol" + if [ -f "$assertsol" ] + then + echo "Replace Truffle's Assert.sol with a known good version" + rm "$assertsol" + wget https://raw.githubusercontent.com/trufflesuite/truffle-core/ef31bcaa15dbd9bd0f6a0070a5c63f271cde2dbc/lib/testing/Assert.sol -o "$assertsol" + fi npm run test ) rm -rf "$DIR" } -test_truffle Gnosis https://github.com/gnosis/gnosis-contracts.git -test_truffle Zeppelin https://github.com/OpenZeppelin/zeppelin-solidity.git +# Using our temporary fork here. Hopefully to be merged into upstream after the 0.5.0 release. +test_truffle Zeppelin https://github.com/axic/openzeppelin-solidity.git solidity-050 + +# Disabled temporarily as it needs to be updated to latest Truffle first. +#test_truffle Gnosis https://github.com/axic/pm-contracts.git solidity-050 diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp index 4b399a14..5687ffcc 100644 --- a/test/libevmasm/Optimiser.cpp +++ b/test/libevmasm/Optimiser.cpp @@ -967,6 +967,31 @@ BOOST_AUTO_TEST_CASE(peephole_swap_comparison) } } +BOOST_AUTO_TEST_CASE(peephole_truthy_and) +{ + AssemblyItems items{ + AssemblyItem(Tag, 1), + Instruction::BALANCE, + u256(0), + Instruction::NOT, + Instruction::AND, + AssemblyItem(PushTag, 1), + Instruction::JUMPI + }; + AssemblyItems expectation{ + AssemblyItem(Tag, 1), + Instruction::BALANCE, + AssemblyItem(PushTag, 1), + Instruction::JUMPI + }; + PeepholeOptimiser peepOpt(items); + BOOST_REQUIRE(peepOpt.optimise()); + BOOST_CHECK_EQUAL_COLLECTIONS( + items.begin(), items.end(), + expectation.begin(), expectation.end() + ); +} + BOOST_AUTO_TEST_CASE(jumpdest_removal) { AssemblyItems items{ diff --git a/test/libjulia/Common.cpp b/test/libjulia/Common.cpp index 24519b01..a0592667 100644 --- a/test/libjulia/Common.cpp +++ b/test/libjulia/Common.cpp @@ -16,7 +16,7 @@ */ /** * @date 2017 - * Common functions the iulia tests. + * Common functions the Yul tests. */ #include <test/libjulia/Common.h> @@ -52,9 +52,9 @@ void dev::julia::test::printErrors(ErrorList const& _errors, Scanner const& _sca } -pair<shared_ptr<Block>, shared_ptr<assembly::AsmAnalysisInfo>> dev::julia::test::parse(string const& _source, bool _julia) +pair<shared_ptr<Block>, shared_ptr<assembly::AsmAnalysisInfo>> dev::julia::test::parse(string const& _source, bool _yul) { - auto flavour = _julia ? assembly::AsmFlavour::IULIA : assembly::AsmFlavour::Strict; + auto flavour = _yul ? assembly::AsmFlavour::Yul : assembly::AsmFlavour::Strict; ErrorList errors; ErrorReporter errorReporter(errors); auto scanner = make_shared<Scanner>(CharStream(_source), ""); @@ -83,13 +83,13 @@ pair<shared_ptr<Block>, shared_ptr<assembly::AsmAnalysisInfo>> dev::julia::test: return {}; } -assembly::Block dev::julia::test::disambiguate(string const& _source, bool _julia) +assembly::Block dev::julia::test::disambiguate(string const& _source, bool _yul) { - auto result = parse(_source, _julia); + auto result = parse(_source, _yul); return boost::get<Block>(Disambiguator(*result.second)(*result.first)); } -string dev::julia::test::format(string const& _source, bool _julia) +string dev::julia::test::format(string const& _source, bool _yul) { - return assembly::AsmPrinter(_julia)(*parse(_source, _julia).first); + return assembly::AsmPrinter(_yul)(*parse(_source, _yul).first); } diff --git a/test/libjulia/Common.h b/test/libjulia/Common.h index 1371101c..b9c3d2fb 100644 --- a/test/libjulia/Common.h +++ b/test/libjulia/Common.h @@ -16,7 +16,7 @@ */ /** * @date 2017 - * Common functions the iulia tests. + * Common functions the Yul tests. */ #pragma once @@ -46,9 +46,9 @@ namespace test void printErrors(solidity::ErrorList const& _errors, solidity::Scanner const& _scanner); std::pair<std::shared_ptr<solidity::assembly::Block>, std::shared_ptr<solidity::assembly::AsmAnalysisInfo>> -parse(std::string const& _source, bool _julia = true); -solidity::assembly::Block disambiguate(std::string const& _source, bool _julia = true); -std::string format(std::string const& _source, bool _julia = true); +parse(std::string const& _source, bool _yul = true); +solidity::assembly::Block disambiguate(std::string const& _source, bool _yul = true); +std::string format(std::string const& _source, bool _yul = true); } } diff --git a/test/libjulia/CommonSubexpression.cpp b/test/libjulia/CommonSubexpression.cpp index 8a575c48..6c8edf1f 100644 --- a/test/libjulia/CommonSubexpression.cpp +++ b/test/libjulia/CommonSubexpression.cpp @@ -47,7 +47,7 @@ do\ }\ while(false) -BOOST_AUTO_TEST_SUITE(IuliaCSE) +BOOST_AUTO_TEST_SUITE(YulCSE) BOOST_AUTO_TEST_CASE(smoke_test) { diff --git a/test/libjulia/Disambiguator.cpp b/test/libjulia/Disambiguator.cpp index a6338449..48e02c7e 100644 --- a/test/libjulia/Disambiguator.cpp +++ b/test/libjulia/Disambiguator.cpp @@ -16,7 +16,7 @@ */ /** * @date 2017 - * Unit tests for the iulia name disambiguator. + * Unit tests for the Yul name disambiguator. */ #include <test/libjulia/Common.h> @@ -39,7 +39,7 @@ do\ }\ while(false) -BOOST_AUTO_TEST_SUITE(IuliaDisambiguator) +BOOST_AUTO_TEST_SUITE(YulDisambiguator) BOOST_AUTO_TEST_CASE(smoke_test) { diff --git a/test/libjulia/FunctionGrouper.cpp b/test/libjulia/FunctionGrouper.cpp index 78f382cb..f1e83449 100644 --- a/test/libjulia/FunctionGrouper.cpp +++ b/test/libjulia/FunctionGrouper.cpp @@ -16,7 +16,7 @@ */ /** * @date 2017 - * Unit tests for the iulia function grouper. + * Unit tests for the Yul function grouper. */ #include <test/libjulia/Common.h> @@ -43,7 +43,7 @@ do\ }\ while(false) -BOOST_AUTO_TEST_SUITE(IuliaFunctionGrouper) +BOOST_AUTO_TEST_SUITE(YulFunctionGrouper) BOOST_AUTO_TEST_CASE(smoke_test) { diff --git a/test/libjulia/FunctionHoister.cpp b/test/libjulia/FunctionHoister.cpp index 3d6fff85..348963b4 100644 --- a/test/libjulia/FunctionHoister.cpp +++ b/test/libjulia/FunctionHoister.cpp @@ -16,7 +16,7 @@ */ /** * @date 2017 - * Unit tests for the iulia function hoister. + * Unit tests for the Yul function hoister. */ #include <test/libjulia/Common.h> @@ -43,7 +43,7 @@ do\ }\ while(false) -BOOST_AUTO_TEST_SUITE(IuliaFunctionHoister) +BOOST_AUTO_TEST_SUITE(YulFunctionHoister) BOOST_AUTO_TEST_CASE(smoke_test) { diff --git a/test/libjulia/Inliner.cpp b/test/libjulia/Inliner.cpp index 464dcd93..2f5b7cff 100644 --- a/test/libjulia/Inliner.cpp +++ b/test/libjulia/Inliner.cpp @@ -16,7 +16,7 @@ */ /** * @date 2017 - * Unit tests for the iulia function inliner. + * Unit tests for the Yul function inliner. */ #include <test/libjulia/Common.h> @@ -55,24 +55,24 @@ string inlinableFunctions(string const& _source) ); } -string inlineFunctions(string const& _source, bool _julia = true) +string inlineFunctions(string const& _source, bool _yul = true) { - auto ast = disambiguate(_source, _julia); + auto ast = disambiguate(_source, _yul); ExpressionInliner(ast).run(); - return assembly::AsmPrinter(_julia)(ast); + return assembly::AsmPrinter(_yul)(ast); } -string fullInline(string const& _source, bool _julia = true) +string fullInline(string const& _source, bool _yul = true) { - Block ast = disambiguate(_source, _julia); + Block ast = disambiguate(_source, _yul); (FunctionHoister{})(ast); (FunctionGrouper{})(ast);\ FullInliner(ast).run(); - return assembly::AsmPrinter(_julia)(ast); + return assembly::AsmPrinter(_yul)(ast); } } -BOOST_AUTO_TEST_SUITE(IuliaInlinableFunctionFilter) +BOOST_AUTO_TEST_SUITE(YulInlinableFunctionFilter) BOOST_AUTO_TEST_CASE(smoke_test) { @@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE(negative) BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE(IuliaFunctionInliner) +BOOST_AUTO_TEST_SUITE(YulFunctionInliner) BOOST_AUTO_TEST_CASE(simple) { @@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(double_recursive_calls) BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE(IuliaFullInliner) +BOOST_AUTO_TEST_SUITE(YulFullInliner) BOOST_AUTO_TEST_CASE(simple) { diff --git a/test/libjulia/MainFunction.cpp b/test/libjulia/MainFunction.cpp index c26b002d..e7263d13 100644 --- a/test/libjulia/MainFunction.cpp +++ b/test/libjulia/MainFunction.cpp @@ -16,7 +16,7 @@ */ /** * @date 2018 - * Unit tests for the Julia MainFunction transformation. + * Unit tests for the Yul MainFunction transformation. */ #include <test/libjulia/Common.h> @@ -45,7 +45,7 @@ do\ }\ while(false) -BOOST_AUTO_TEST_SUITE(JuliaMainFunction) +BOOST_AUTO_TEST_SUITE(YulMainFunction) BOOST_AUTO_TEST_CASE(smoke_test) { diff --git a/test/libjulia/Parser.cpp b/test/libjulia/Parser.cpp index 96261dec..3f329d28 100644 --- a/test/libjulia/Parser.cpp +++ b/test/libjulia/Parser.cpp @@ -16,7 +16,7 @@ */ /** * @date 2017 - * Unit tests for parsing Julia. + * Unit tests for parsing Yul. */ #include <test/Options.h> @@ -52,7 +52,7 @@ bool parse(string const& _source, ErrorReporter& errorReporter) try { auto scanner = make_shared<Scanner>(CharStream(_source)); - auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::IULIA).parse(scanner, false); + auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::Yul).parse(scanner, false); if (parserResult) { assembly::AsmAnalysisInfo analysisInfo; @@ -61,7 +61,7 @@ bool parse(string const& _source, ErrorReporter& errorReporter) errorReporter, dev::test::Options::get().evmVersion(), boost::none, - assembly::AsmFlavour::IULIA + assembly::AsmFlavour::Yul )).analyze(*parserResult); } } @@ -119,7 +119,7 @@ do \ BOOST_CHECK(searchErrorMessage(err, (substring))); \ } while(0) -BOOST_AUTO_TEST_SUITE(JuliaParser) +BOOST_AUTO_TEST_SUITE(YulParser) BOOST_AUTO_TEST_CASE(smoke_test) { @@ -267,7 +267,7 @@ BOOST_AUTO_TEST_CASE(recursion_depth) BOOST_AUTO_TEST_CASE(multiple_assignment) { CHECK_ERROR("{ let x:u256 function f() -> a:u256, b:u256 {} 123:u256, x := f() }", ParserError, "Label name / variable name must precede \",\" (multiple assignment)."); - CHECK_ERROR("{ let x:u256 function f() -> a:u256, b:u256 {} x, 123:u256 := f() }", ParserError, "Variable name expected in multiple assignemnt."); + CHECK_ERROR("{ let x:u256 function f() -> a:u256, b:u256 {} x, 123:u256 := f() }", ParserError, "Variable name expected in multiple assignment."); /// NOTE: Travis hiccups if not having a variable char const* text = R"( diff --git a/test/libjulia/Rematerialiser.cpp b/test/libjulia/Rematerialiser.cpp index 8f928f8e..63e525d5 100644 --- a/test/libjulia/Rematerialiser.cpp +++ b/test/libjulia/Rematerialiser.cpp @@ -48,7 +48,7 @@ do\ }\ while(false) -BOOST_AUTO_TEST_SUITE(IuliaRematerialiser) +BOOST_AUTO_TEST_SUITE(YulRematerialiser) BOOST_AUTO_TEST_CASE(smoke_test) { diff --git a/test/libjulia/Simplifier.cpp b/test/libjulia/Simplifier.cpp index 4d4e8d53..8ed8287a 100644 --- a/test/libjulia/Simplifier.cpp +++ b/test/libjulia/Simplifier.cpp @@ -48,7 +48,7 @@ do\ }\ while(false) -BOOST_AUTO_TEST_SUITE(IuliaSimplifier) +BOOST_AUTO_TEST_SUITE(YulSimplifier) BOOST_AUTO_TEST_CASE(smoke_test) { diff --git a/test/libjulia/UnusedPruner.cpp b/test/libjulia/UnusedPruner.cpp index b86a54b3..649ee149 100644 --- a/test/libjulia/UnusedPruner.cpp +++ b/test/libjulia/UnusedPruner.cpp @@ -48,7 +48,7 @@ do\ }\ while(false) -BOOST_AUTO_TEST_SUITE(IuliaUnusedPruner) +BOOST_AUTO_TEST_SUITE(YulUnusedPruner) BOOST_AUTO_TEST_CASE(smoke_test) { diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index fd8099f2..ceaf450e 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -50,6 +50,7 @@ BOOST_AUTO_TEST_CASE(bare_panic) { char const* sourceCode = "(panic)"; compileAndRunWithoutCheck(sourceCode); + BOOST_REQUIRE(!m_transactionSuccessful); BOOST_REQUIRE(m_output.empty()); } @@ -57,6 +58,7 @@ BOOST_AUTO_TEST_CASE(panic) { char const* sourceCode = "{ (panic) }"; compileAndRunWithoutCheck(sourceCode); + BOOST_REQUIRE(!m_transactionSuccessful); BOOST_REQUIRE(m_output.empty()); } @@ -69,6 +71,7 @@ BOOST_AUTO_TEST_CASE(macro_zeroarg) (zeroarg))) )"; compileAndRun(sourceCode); + BOOST_CHECK(m_transactionSuccessful); BOOST_CHECK(callFallback() == encodeArgs(u256(0x1234))); } diff --git a/test/libsolidity/ABIDecoderTests.cpp b/test/libsolidity/ABIDecoderTests.cpp index b3ebb7a5..6504f6bc 100644 --- a/test/libsolidity/ABIDecoderTests.cpp +++ b/test/libsolidity/ABIDecoderTests.cpp @@ -266,7 +266,6 @@ BOOST_AUTO_TEST_CASE(calldata_arrays_too_large) } } )"; - bool newEncoder = false; BOTH_ENCODERS( compileAndRun(sourceCode); bytes args = encodeArgs( @@ -275,9 +274,8 @@ BOOST_AUTO_TEST_CASE(calldata_arrays_too_large) ); ABI_CHECK( callContractFunction("f(uint256,uint256[],uint256)", args), - newEncoder ? encodeArgs() : encodeArgs(7) + encodeArgs() ); - newEncoder = true; ) } @@ -287,7 +285,7 @@ BOOST_AUTO_TEST_CASE(decode_from_memory_simple) contract C { uint public _a; uint[] public _b; - function C(uint a, uint[] b) { + constructor(uint a, uint[] b) public { _a = a; _b = b; } @@ -312,24 +310,24 @@ BOOST_AUTO_TEST_CASE(decode_function_type) string sourceCode = R"( contract D { function () external returns (uint) public _a; - function D(function () external returns (uint) a) { + constructor(function () external returns (uint) a) public { _a = a; } } contract C { - function f() returns (uint) { + function f() public returns (uint) { return 3; } - function g(function () external returns (uint) _f) returns (uint) { + function g(function () external returns (uint) _f) public returns (uint) { return _f(); } // uses "decode from memory" - function test1() returns (uint) { + function test1() public returns (uint) { D d = new D(this.f); return d._a()(); } // uses "decode from calldata" - function test2() returns (uint) { + function test2() public returns (uint) { return this.g(this.f); } } @@ -346,13 +344,13 @@ BOOST_AUTO_TEST_CASE(decode_function_type_array) string sourceCode = R"( contract D { function () external returns (uint)[] public _a; - function D(function () external returns (uint)[] a) { + constructor(function () external returns (uint)[] a) public { _a = a; } } contract E { function () external returns (uint)[3] public _a; - function E(function () external returns (uint)[3] a) { + constructor(function () external returns (uint)[3] a) public { _a = a; } } @@ -374,7 +372,7 @@ BOOST_AUTO_TEST_CASE(decode_function_type_array) } // uses "decode from memory" function test1_dynamic() public returns (uint) { - var x = new function() external returns (uint)[](3); + function () external returns (uint)[] memory x = new function() external returns (uint)[](4); x[0] = this.f1; x[1] = this.f2; x[2] = this.f3; @@ -387,7 +385,7 @@ BOOST_AUTO_TEST_CASE(decode_function_type_array) } // uses "decode from calldata" function test2_dynamic() public returns (uint) { - var x = new function() external returns (uint)[](3); + function () external returns (uint)[] memory x = new function() external returns (uint)[](3); x[0] = this.f1; x[1] = this.f2; x[2] = this.f3; @@ -414,7 +412,7 @@ BOOST_AUTO_TEST_CASE(decode_from_memory_complex) uint public _a; uint[] public _b; bytes[2] public _c; - function C(uint a, uint[] b, bytes[2] c) { + constructor(uint a, uint[] b, bytes[2] c) public { _a = a; _b = b; _c = c; @@ -449,13 +447,11 @@ BOOST_AUTO_TEST_CASE(short_input_value_type) function f(uint a, uint b) public pure returns (uint) { return a; } } )"; - bool newDecoder = false; BOTH_ENCODERS( compileAndRun(sourceCode); ABI_CHECK(callContractFunction("f(uint256,uint256)", 1, 2), encodeArgs(1)); ABI_CHECK(callContractFunctionNoEncoding("f(uint256,uint256)", bytes(64, 0)), encodeArgs(0)); - ABI_CHECK(callContractFunctionNoEncoding("f(uint256,uint256)", bytes(63, 0)), newDecoder ? encodeArgs() : encodeArgs(0)); - newDecoder = true; + ABI_CHECK(callContractFunctionNoEncoding("f(uint256,uint256)", bytes(63, 0)), encodeArgs()); ) } @@ -466,15 +462,13 @@ BOOST_AUTO_TEST_CASE(short_input_array) function f(uint[] a) public pure returns (uint) { return 7; } } )"; - bool newDecoder = false; BOTH_ENCODERS( compileAndRun(sourceCode); ABI_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 0)), encodeArgs(7)); - ABI_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 1)), newDecoder ? encodeArgs() : encodeArgs(7)); - ABI_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 1) + bytes(31, 0)), newDecoder ? encodeArgs() : encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 1)), encodeArgs()); + ABI_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 1) + bytes(31, 0)), encodeArgs()); ABI_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 1) + bytes(32, 0)), encodeArgs(7)); ABI_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 2, 5, 6)), encodeArgs(7)); - newDecoder = true; ) } @@ -558,7 +552,7 @@ BOOST_AUTO_TEST_CASE(storage_ptr) r[2] = 3; s.x = 11; s.y = 12; - var (a, b, c, d) = L.f(r, s); + (uint a, uint b, uint c, uint d) = L.f(r, s); return (r[2], s.x, a, b, c, d); } } @@ -659,26 +653,6 @@ BOOST_AUTO_TEST_CASE(struct_function) ) } -BOOST_AUTO_TEST_CASE(empty_struct) -{ - string sourceCode = R"( - contract C { - struct S { } - function f(uint a, S s, uint b) public pure returns (uint x, uint y) { - assembly { x := a y := b } - } - function g() public returns (uint, uint) { - return this.f(7, S(), 8); - } - } - )"; - NEW_ENCODER( - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("f(uint256,(),uint256)", 7, 8), encodeArgs(7, 8)); - ABI_CHECK(callContractFunction("g()"), encodeArgs(7, 8)); - ) -} - BOOST_AUTO_TEST_CASE(mediocre_struct) { string sourceCode = R"( diff --git a/test/libsolidity/ABIEncoderTests.cpp b/test/libsolidity/ABIEncoderTests.cpp index 49db9ce1..9b6250d8 100644 --- a/test/libsolidity/ABIEncoderTests.cpp +++ b/test/libsolidity/ABIEncoderTests.cpp @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(value_types) assembly { b := 7 } C c; assembly { c := sub(0, 5) } - E(10, uint16(uint256(-2)), uint24(0x12121212), int24(int256(-1)), bytes3(x), b, c); + emit E(10, uint16(uint256(-2)), uint24(0x12121212), int24(int256(-1)), bytes3(x), b, c); } } )"; @@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(string_literal) contract C { event E(string, bytes20, string); function f() public { - E("abcdef", "abcde", "abcdefabcdefgehabcabcasdfjklabcdefabcedefghabcabcasdfjklabcdefabcdefghabcabcasdfjklabcdeefabcdefghabcabcasdefjklabcdefabcdefghabcabcasdfjkl"); + emit E("abcdef", "abcde", "abcdefabcdefgehabcabcasdfjklabcdefabcedefghabcabcasdfjklabcdefabcdefghabcabcasdfjklabcdeefabcdefghabcabcasdefjklabcdefabcdefghabcabcasdfjkl"); } } )"; @@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(conversion) int8 c; int16 d; assembly { a := sub(0, 1) c := 0x0101ff d := 0xff01 } - E(10, x, a, uint8(b), c, int8(d)); + emit E(10, x, a, uint8(b), c, int8(d)); } } )"; @@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE(memory_array_one_dim) mstore(add(x, mul(add(i, 1), 0x20)), add(0xfffffffe, i)) } } - E(10, x, 11); + emit E(10, x, 11); } } )"; @@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE(memory_array_two_dim) x[0][2] = -1; x[1][0] = 4; x[1][1] = 5; - E(10, x, 11); + emit E(10, x, 11); } } )"; @@ -208,7 +208,7 @@ BOOST_AUTO_TEST_CASE(memory_byte_array) bytes[] memory x = new bytes[](2); x[0] = "abcabcdefghjklmnopqrsuvwabcdefgijklmnopqrstuwabcdefgijklmnoprstuvw"; x[1] = "abcdefghijklmnopqrtuvwabcfghijklmnopqstuvwabcdeghijklmopqrstuvw"; - E(10, x, 11); + emit E(10, x, 11); } } )"; @@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(storage_byte_array) function f() public { short = "123456789012345678901234567890a"; long = "ffff123456789012345678901234567890afffffffff123456789012345678901234567890a"; - E(short, long); + emit E(short, long); } } )"; @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(storage_array) sstore(1, sub(0, 2)) sstore(2, sub(0, 3)) } - E(addr); + emit E(addr); } } )"; @@ -279,10 +279,10 @@ BOOST_AUTO_TEST_CASE(storage_array_dyn) address[] addr; event E(address[] a); function f() public { - addr.push(1); - addr.push(2); - addr.push(3); - E(addr); + addr.push(0x0000000000000000000000000000000000000001); + addr.push(0x0000000000000000000000000000000000000002); + addr.push(0x0000000000000000000000000000000000000003); + emit E(addr); } } )"; @@ -308,7 +308,7 @@ BOOST_AUTO_TEST_CASE(storage_array_compact) x.push(6); x.push(-7); x.push(8); - E(x); + emit E(x); } } )"; @@ -329,7 +329,7 @@ BOOST_AUTO_TEST_CASE(external_function) function(uint) external returns (uint) g; function f(uint) public returns (uint) { g = this.f; - E(this.f, g); + emit E(this.f, g); } } )"; @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(external_function_cleanup) function f(uint) public returns (uint) { function(uint) external returns (uint)[1] memory h; assembly { sstore(0, sub(0, 1)) mstore(h, sub(0, 1)) } - E(h[0], g); + emit E(h[0], g); } } )"; @@ -368,21 +368,18 @@ BOOST_AUTO_TEST_CASE(calldata) contract C { event E(bytes); function f(bytes a) external { - E(a); + emit E(a); } } )"; string s("abcdef"); string t("abcdefgggggggggggggggggggggggggggggggggggggggghhheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeggg"); - bool newEncoder = false; BOTH_ENCODERS( compileAndRun(sourceCode); callContractFunction("f(bytes)", 0x20, s.size(), s); - // The old encoder did not pad to multiples of 32 bytes - REQUIRE_LOG_DATA(encodeArgs(0x20, s.size()) + (newEncoder ? encodeArgs(s) : asBytes(s))); + REQUIRE_LOG_DATA(encodeArgs(0x20, s.size(), s)); callContractFunction("f(bytes)", 0x20, t.size(), t); - REQUIRE_LOG_DATA(encodeArgs(0x20, t.size()) + (newEncoder ? encodeArgs(t) : asBytes(t))); - newEncoder = true; + REQUIRE_LOG_DATA(encodeArgs(0x20, t.size(), t)); ) } @@ -429,7 +426,7 @@ BOOST_AUTO_TEST_CASE(structs) s.sub[0].x[0] = 11; s.sub[1].x[0] = 12; s.sub[2].x[1] = 13; - e(x, s); + emit e(x, s); return (x, s); } } @@ -450,28 +447,6 @@ BOOST_AUTO_TEST_CASE(structs) ) } -BOOST_AUTO_TEST_CASE(empty_struct) -{ - string sourceCode = R"( - contract C { - struct S { } - S s; - event e(uint16, S, uint16); - function f() returns (uint, S, uint) { - e(7, s, 8); - return (7, s, 8); - } - } - )"; - - NEW_ENCODER( - compileAndRun(sourceCode, 0, "C"); - bytes encoded = encodeArgs(7, 8); - BOOST_CHECK(callContractFunction("f()") == encoded); - REQUIRE_LOG_DATA(encoded); - ) -} - BOOST_AUTO_TEST_CASE(structs2) { string sourceCode = R"( diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 5d5b14e8..482b05e6 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_SUITE(SolidityASTJSON) BOOST_AUTO_TEST_CASE(short_type_name) { CompilerStack c; - c.addSource("a", "contract c { function f() { uint[] memory x; } }"); + c.addSource("a", "contract c { function f() public { uint[] memory x; } }"); c.setEVMVersion(dev::test::Options::get().evmVersion()); c.parseAndAnalyze(); map<string, unsigned> sourceIndices; @@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE(short_type_name) BOOST_AUTO_TEST_CASE(short_type_name_ref) { CompilerStack c; - c.addSource("a", "contract c { function f() { uint[][] memory rows; } }"); + c.addSource("a", "contract c { function f() public { uint[][] memory rows; } }"); c.setEVMVersion(dev::test::Options::get().evmVersion()); c.parseAndAnalyze(); map<string, unsigned> sourceIndices; @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(long_type_name_binary_operation) BOOST_AUTO_TEST_CASE(long_type_name_identifier) { CompilerStack c; - c.addSource("a", "contract c { uint[] a; function f() public { uint[] b = a; } }"); + c.addSource("a", "contract c { uint[] a; function f() public { uint[] storage b = a; } }"); c.setEVMVersion(dev::test::Options::get().evmVersion()); c.parseAndAnalyze(); map<string, unsigned> sourceIndices; diff --git a/test/libsolidity/ASTLegacyJSON.cpp b/test/libsolidity/ASTLegacyJSON.cpp index 13148682..69cb1bb9 100644 --- a/test/libsolidity/ASTLegacyJSON.cpp +++ b/test/libsolidity/ASTLegacyJSON.cpp @@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(enum_value) BOOST_AUTO_TEST_CASE(modifier_definition) { CompilerStack c; - c.addSource("a", "contract C { modifier M(uint i) { _; } function F() M(1) {} }"); + c.addSource("a", "contract C { modifier M(uint i) { _; } function F() M(1) public {} }"); c.setEVMVersion(dev::test::Options::get().evmVersion()); c.parseAndAnalyze(); map<string, unsigned> sourceIndices; @@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(modifier_definition) BOOST_AUTO_TEST_CASE(modifier_invocation) { CompilerStack c; - c.addSource("a", "contract C { modifier M(uint i) { _; } function F() M(1) {} }"); + c.addSource("a", "contract C { modifier M(uint i) { _; } function F() M(1) public {} }"); c.setEVMVersion(dev::test::Options::get().evmVersion()); c.parseAndAnalyze(); map<string, unsigned> sourceIndices; @@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE(array_type_name) BOOST_AUTO_TEST_CASE(short_type_name) { CompilerStack c; - c.addSource("a", "contract c { function f() { uint[] memory x; } }"); + c.addSource("a", "contract c { function f() public { uint[] memory x; } }"); c.setEVMVersion(dev::test::Options::get().evmVersion()); c.parseAndAnalyze(); map<string, unsigned> sourceIndices; @@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(short_type_name) BOOST_AUTO_TEST_CASE(short_type_name_ref) { CompilerStack c; - c.addSource("a", "contract c { function f() { uint[][] memory rows; } }"); + c.addSource("a", "contract c { function f() public { uint[][] memory rows; } }"); c.setEVMVersion(dev::test::Options::get().evmVersion()); c.parseAndAnalyze(); map<string, unsigned> sourceIndices; @@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE(placeholder_statement) BOOST_AUTO_TEST_CASE(non_utf8) { CompilerStack c; - c.addSource("a", "contract C { function f() { var x = hex\"ff\"; } }"); + c.addSource("a", "contract C { function f() public { var x = hex\"ff\"; } }"); c.setEVMVersion(dev::test::Options::get().evmVersion()); c.parseAndAnalyze(); map<string, unsigned> sourceIndices; @@ -252,7 +252,7 @@ BOOST_AUTO_TEST_CASE(function_type) CompilerStack c; c.addSource("a", "contract C { function f(function() external payable returns (uint) x) " - "returns (function() external constant returns (uint)) {} }" + "returns (function() external view returns (uint)) {} }" ); c.setEVMVersion(dev::test::Options::get().evmVersion()); c.parseAndAnalyze(); diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index 7b3df043..e815d7d5 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE(location_test) { char const* sourceCode = R"( contract test { - function f() returns (uint256 a) { + function f() public returns (uint256 a) { return 16; } } @@ -160,19 +160,19 @@ BOOST_AUTO_TEST_CASE(location_test) AssemblyItems items = compileContract(sourceCode); bool hasShifts = dev::test::Options::get().evmVersion().hasBitwiseShifting(); vector<SourceLocation> locations = - vector<SourceLocation>(hasShifts ? 23 : 24, SourceLocation(2, 75, make_shared<string>(""))) + - vector<SourceLocation>(2, SourceLocation(20, 72, make_shared<string>(""))) + + vector<SourceLocation>(hasShifts ? 23 : 24, SourceLocation(2, 82, make_shared<string>(""))) + + vector<SourceLocation>(2, SourceLocation(20, 79, make_shared<string>(""))) + vector<SourceLocation>(1, SourceLocation(8, 17, make_shared<string>("--CODEGEN--"))) + vector<SourceLocation>(3, SourceLocation(5, 7, make_shared<string>("--CODEGEN--"))) + vector<SourceLocation>(1, SourceLocation(30, 31, make_shared<string>("--CODEGEN--"))) + vector<SourceLocation>(1, SourceLocation(27, 28, make_shared<string>("--CODEGEN--"))) + vector<SourceLocation>(1, SourceLocation(20, 32, make_shared<string>("--CODEGEN--"))) + vector<SourceLocation>(1, SourceLocation(5, 7, make_shared<string>("--CODEGEN--"))) + - vector<SourceLocation>(24, SourceLocation(20, 72, make_shared<string>(""))) + - vector<SourceLocation>(1, SourceLocation(42, 51, make_shared<string>(""))) + - vector<SourceLocation>(1, SourceLocation(65, 67, make_shared<string>(""))) + - vector<SourceLocation>(2, SourceLocation(58, 67, make_shared<string>(""))) + - vector<SourceLocation>(2, SourceLocation(20, 72, make_shared<string>(""))); + vector<SourceLocation>(24, SourceLocation(20, 79, make_shared<string>(""))) + + vector<SourceLocation>(1, SourceLocation(49, 58, make_shared<string>(""))) + + vector<SourceLocation>(1, SourceLocation(72, 74, make_shared<string>(""))) + + vector<SourceLocation>(2, SourceLocation(65, 74, make_shared<string>(""))) + + vector<SourceLocation>(2, SourceLocation(20, 79, make_shared<string>(""))); checkAssemblyLocations(items, locations); } diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp index f16d9abe..a404c072 100644 --- a/test/libsolidity/GasMeter.cpp +++ b/test/libsolidity/GasMeter.cpp @@ -87,6 +87,7 @@ public: for (bytes const& arguments: _argumentVariants) { sendMessage(hash.asBytes() + arguments, false, 0); + BOOST_CHECK(m_transactionSuccessful); gasUsed = max(gasUsed, m_gasUsed); gas = max(gas, gasForTransaction(hash.asBytes() + arguments, false)); } @@ -152,7 +153,7 @@ BOOST_AUTO_TEST_CASE(simple_contract) contract test { bytes32 public shaValue; function f(uint a) { - shaValue = keccak256(a); + shaValue = keccak256(abi.encodePacked(a)); } } )"; @@ -164,8 +165,8 @@ BOOST_AUTO_TEST_CASE(store_keccak256) char const* sourceCode = R"( contract test { bytes32 public shaValue; - function test(uint a) { - shaValue = keccak256(a); + constructor(uint a) { + shaValue = keccak256(abi.encodePacked(a)); } } )"; @@ -178,7 +179,7 @@ BOOST_AUTO_TEST_CASE(updating_store) contract test { uint data; uint data2; - function test() { + constructor() { data = 1; data = 2; data2 = 0; @@ -301,7 +302,7 @@ BOOST_AUTO_TEST_CASE(regular_functions_exclude_fallback) char const* sourceCode = R"( contract A { uint public x; - function() { x = 2; } + function() external { x = 2; } } )"; testCreationTimeGas(sourceCode); @@ -315,7 +316,7 @@ BOOST_AUTO_TEST_CASE(complex_control_flow) // we previously considered. This of course reduces accuracy. char const* sourceCode = R"( contract log { - function ln(int128 x) constant returns (int128 result) { + function ln(int128 x) pure returns (int128 result) { int128 t = x / 256; int128 y = 5545177; x = t; diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp index 1b5dd4a5..4b700ceb 100644 --- a/test/libsolidity/Imports.cpp +++ b/test/libsolidity/Imports.cpp @@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE(simple_alias) { CompilerStack c; c.addSource("a", "contract A {} pragma solidity >=0.0;"); - c.addSource("dir/a/b/c", "import \"../../.././a\" as x; contract B is x.A { function() { x.A r = x.A(20); } } pragma solidity >=0.0;"); + c.addSource("dir/a/b/c", "import \"../../.././a\" as x; contract B is x.A { function() external { x.A r = x.A(20); } } pragma solidity >=0.0;"); c.setEVMVersion(dev::test::Options::get().evmVersion()); BOOST_CHECK(c.compile()); } diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 181ca959..a9ce6e49 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -178,9 +178,9 @@ BOOST_AUTO_TEST_CASE(simple_instructions) BOOST_CHECK(successParse("{ dup1 dup1 mul dup1 sub pop }")); } -BOOST_AUTO_TEST_CASE(suicide_selfdestruct) +BOOST_AUTO_TEST_CASE(selfdestruct) { - BOOST_CHECK(successParse("{ 0x01 suicide 0x02 selfdestruct }")); + BOOST_CHECK(successParse("{ 0x02 selfdestruct }")); } BOOST_AUTO_TEST_CASE(keywords) @@ -461,7 +461,7 @@ BOOST_AUTO_TEST_CASE(recursion_depth) BOOST_AUTO_TEST_CASE(multiple_assignment) { CHECK_PARSE_ERROR("{ let x function f() -> a, b {} 123, x := f() }", ParserError, "Label name / variable name must precede \",\" (multiple assignment)."); - CHECK_PARSE_ERROR("{ let x function f() -> a, b {} x, 123 := f() }", ParserError, "Variable name expected in multiple assignemnt."); + CHECK_PARSE_ERROR("{ let x function f() -> a, b {} x, 123 := f() }", ParserError, "Variable name expected in multiple assignment."); /// NOTE: Travis hiccups if not having a variable char const* text = R"( @@ -740,8 +740,6 @@ BOOST_AUTO_TEST_CASE(keccak256) { BOOST_CHECK(successAssemble("{ 0 0 keccak256 pop }")); BOOST_CHECK(successAssemble("{ pop(keccak256(0, 0)) }")); - BOOST_CHECK(successAssemble("{ 0 0 sha3 pop }")); - BOOST_CHECK(successAssemble("{ pop(sha3(0, 0)) }")); } BOOST_AUTO_TEST_CASE(returndatasize) diff --git a/test/libsolidity/JSONCompiler.cpp b/test/libsolidity/LibSolc.cpp index 2b3df3a7..9d5ffa27 100644 --- a/test/libsolidity/JSONCompiler.cpp +++ b/test/libsolidity/LibSolc.cpp @@ -16,7 +16,7 @@ */ /** * @date 2017 - * Unit tests for solc/jsonCompiler.cpp. + * Unit tests for libsolc/libsolc.cpp. */ #include <string> @@ -70,7 +70,7 @@ Json::Value compile(string const& _input) } // end anonymous namespace -BOOST_AUTO_TEST_SUITE(JSONCompiler) +BOOST_AUTO_TEST_SUITE(LibSolc) BOOST_AUTO_TEST_CASE(read_version) { @@ -201,6 +201,26 @@ BOOST_AUTO_TEST_CASE(standard_compilation) BOOST_CHECK(result.isMember("contracts")); } +BOOST_AUTO_TEST_CASE(new_api) +{ + char const* input = R"( + { + "language": "Solidity", + "sources": { + "fileA": { + "content": "contract A { }" + } + } + } + )"; + BOOST_CHECK_EQUAL(string(version()), string(solidity_version())); + BOOST_CHECK_EQUAL(string(license()), string(solidity_license())); + BOOST_CHECK_EQUAL( + string(compileStandard(input, nullptr)), + string(solidity_compile(input, nullptr)) + ); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SMTChecker.cpp b/test/libsolidity/SMTChecker.cpp index ec23f452..57f414db 100644 --- a/test/libsolidity/SMTChecker.cpp +++ b/test/libsolidity/SMTChecker.cpp @@ -133,22 +133,6 @@ BOOST_AUTO_TEST_CASE(assignment_in_declaration) CHECK_SUCCESS_NO_WARNINGS(text); } -BOOST_AUTO_TEST_CASE(use_before_declaration) -{ - string text = R"( - contract C { - function f() public pure { a = 3; uint a = 2; assert(a == 2); } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - function f() public pure { assert(a == 0); uint a = 2; assert(a == 2); } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - BOOST_AUTO_TEST_CASE(function_call_does_not_clear_local_vars) { string text = R"( @@ -449,15 +433,15 @@ BOOST_AUTO_TEST_CASE(storage_value_vars) function f(uint x) public { if (x == 0) { - a = 100; + a = 0x0000000000000000000000000000000000000100; b = true; } else { - a = 200; + a = 0x0000000000000000000000000000000000000200; b = false; } - assert(a > 0 && b); + assert(a > 0x0000000000000000000000000000000000000000 && b); } } )"; @@ -480,19 +464,19 @@ BOOST_AUTO_TEST_CASE(storage_value_vars) function f(uint x) public { if (x == 0) { - a = 100; + a = 0x0000000000000000000000000000000000000100; b = true; } else { - a = 200; + a = 0x0000000000000000000000000000000000000200; b = false; } - assert(b == (a < 200)); + assert(b == (a < 0x0000000000000000000000000000000000000200)); } function g() public view { - require(a < 100); + require(a < 0x0000000000000000000000000000000000000100); assert(c >= 0); } address a; diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index 107abc26..736b0b33 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(basic_test) { char const* sourceCode = R"( contract test { - function f(uint a) returns(uint d) { return a * 7; } + function f(uint a) public returns (uint d) { return a * 7; } } )"; @@ -111,8 +111,8 @@ BOOST_AUTO_TEST_CASE(multiple_methods) { char const* sourceCode = R"( contract test { - function f(uint a) returns(uint d) { return a * 7; } - function g(uint b) returns(uint e) { return b * 8; } + function f(uint a) public returns (uint d) { return a * 7; } + function g(uint b) public returns (uint e) { return b * 8; } } )"; @@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE(multiple_params) { char const* sourceCode = R"( contract test { - function f(uint a, uint b) returns(uint d) { return a + b; } + function f(uint a, uint b) public returns (uint d) { return a + b; } } )"; @@ -199,11 +199,11 @@ BOOST_AUTO_TEST_CASE(multiple_params) BOOST_AUTO_TEST_CASE(multiple_methods_order) { - // methods are expected to be in alpabetical order + // methods are expected to be in alphabetical order char const* sourceCode = R"( contract test { - function f(uint a) returns(uint d) { return a * 7; } - function c(uint b) returns(uint e) { return b * 8; } + function f(uint a) public returns (uint d) { return a * 7; } + function c(uint b) public returns (uint e) { return b * 8; } } )"; @@ -255,7 +255,7 @@ BOOST_AUTO_TEST_CASE(view_function) { char const* sourceCode = R"( contract test { - function foo(uint a, uint b) returns(uint d) { return a + b; } + function foo(uint a, uint b) public returns (uint d) { return a + b; } function boo(uint32 a) view returns(uint b) { return a * 4; } } )"; @@ -306,67 +306,11 @@ BOOST_AUTO_TEST_CASE(view_function) checkInterface(sourceCode, interface); } -// constant is an alias to view above -BOOST_AUTO_TEST_CASE(constant_function) -{ - char const* sourceCode = R"( - contract test { - function foo(uint a, uint b) returns(uint d) { return a + b; } - function boo(uint32 a) constant returns(uint b) { return a * 4; } - } - )"; - - char const* interface = R"([ - { - "name": "foo", - "constant": false, - "payable" : false, - "stateMutability": "nonpayable", - "type": "function", - "inputs": [ - { - "name": "a", - "type": "uint256" - }, - { - "name": "b", - "type": "uint256" - } - ], - "outputs": [ - { - "name": "d", - "type": "uint256" - } - ] - }, - { - "name": "boo", - "constant": true, - "payable" : false, - "stateMutability": "view", - "type": "function", - "inputs": [{ - "name": "a", - "type": "uint32" - }], - "outputs": [ - { - "name": "b", - "type": "uint256" - } - ] - } - ])"; - - checkInterface(sourceCode, interface); -} - BOOST_AUTO_TEST_CASE(pure_function) { char const* sourceCode = R"( contract test { - function foo(uint a, uint b) returns(uint d) { return a + b; } + function foo(uint a, uint b) public returns (uint d) { return a + b; } function boo(uint32 a) pure returns(uint b) { return a * 4; } } )"; @@ -421,7 +365,7 @@ BOOST_AUTO_TEST_CASE(events) { char const* sourceCode = R"( contract test { - function f(uint a) returns(uint d) { return a * 7; } + function f(uint a) public returns (uint d) { return a * 7; } event e1(uint b, address indexed c); event e2(); event e2(uint a); @@ -519,11 +463,11 @@ BOOST_AUTO_TEST_CASE(inherited) { char const* sourceCode = R"( contract Base { - function baseFunction(uint p) returns (uint i) { return p; } + function baseFunction(uint p) public returns (uint i) { return p; } event baseEvent(bytes32 indexed evtArgBase); } contract Derived is Base { - function derivedFunction(bytes32 p) returns (bytes32 i) { return p; } + function derivedFunction(bytes32 p) public returns (bytes32 i) { return p; } event derivedEvent(uint indexed evtArgDerived); } )"; @@ -593,7 +537,7 @@ BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one) { char const* sourceCode = R"( contract test { - function f(uint, uint k) returns(uint ret_k, uint ret_g) { + function f(uint, uint k) public returns (uint ret_k, uint ret_g) { uint g = 8; ret_k = k; ret_g = g; @@ -638,7 +582,7 @@ BOOST_AUTO_TEST_CASE(empty_name_return_parameter) { char const* sourceCode = R"( contract test { - function f(uint k) returns(uint) { + function f(uint k) public returns (uint) { return k; } } @@ -672,7 +616,7 @@ BOOST_AUTO_TEST_CASE(constructor_abi) { char const* sourceCode = R"( contract test { - function test(uint param1, test param2, bool param3) {} + constructor(uint param1, test param2, bool param3) {} } )"; @@ -704,7 +648,7 @@ BOOST_AUTO_TEST_CASE(payable_constructor_abi) { char const* sourceCode = R"( contract test { - function test(uint param1, test param2, bool param3) payable {} + constructor(uint param1, test param2, bool param3) payable {} } )"; @@ -738,8 +682,8 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi) char const* sourceCode = R"( contract test { enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test(ActionChoices param) {} - function ret() returns(ActionChoices) { + constructor(ActionChoices param) {} + function ret() public returns (ActionChoices) { ActionChoices action = ActionChoices.GoLeft; return action; } @@ -812,7 +756,7 @@ BOOST_AUTO_TEST_CASE(library_function) char const* sourceCode = R"( library test { struct StructType { uint a; } - function f(StructType storage b, uint[] storage c, test d) returns (uint[] e, StructType storage f) {} + function f(StructType storage b, uint[] storage c, test d) public returns (uint[] e, StructType storage f) {} } )"; @@ -843,7 +787,7 @@ BOOST_AUTO_TEST_CASE(include_fallback_function) { char const* sourceCode = R"( contract test { - function() {} + function() external {} } )"; @@ -897,7 +841,7 @@ BOOST_AUTO_TEST_CASE(payable_fallback_function) { char const* sourceCode = R"( contract test { - function () payable {} + function () external payable {} } )"; @@ -947,7 +891,7 @@ BOOST_AUTO_TEST_CASE(return_structs) contract C { struct S { uint a; T[] sub; } struct T { uint[2] x; } - function f() returns (uint x, S s) { + function f() public returns (uint x, S s) { } } )"; @@ -996,7 +940,7 @@ BOOST_AUTO_TEST_CASE(return_structs_with_contracts) pragma experimental ABIEncoderV2; contract C { struct S { C[] x; C y; } - function f() returns (S s, C c) { + function f() public returns (S s, C c) { } } )"; diff --git a/test/libsolidity/SolidityCompiler.cpp b/test/libsolidity/SolidityCompiler.cpp index 90540f3e..0cc80dd8 100644 --- a/test/libsolidity/SolidityCompiler.cpp +++ b/test/libsolidity/SolidityCompiler.cpp @@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE(does_not_include_creation_time_only_internal_functions) char const* sourceCode = R"( contract C { uint x; - function C() { f(); } + constructor() public { f(); } function f() internal { for (uint i = 0; i < 10; ++i) x += 3 + i; } } )"; diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 40962294..bee83007 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -49,11 +49,30 @@ namespace test BOOST_FIXTURE_TEST_SUITE(SolidityEndToEndTest, SolidityExecutionFramework) +BOOST_AUTO_TEST_CASE(transaction_status) +{ + char const* sourceCode = R"( + contract test { + function f() { } + function g() { revert(); } + function h() { assert(false); } + } + )"; + compileAndRun(sourceCode); + callContractFunction("f()"); + BOOST_CHECK(m_transactionSuccessful); + callContractFunction("g()"); + BOOST_CHECK(!m_transactionSuccessful); + callContractFunction("h()"); + BOOST_CHECK(!m_transactionSuccessful); +} + + BOOST_AUTO_TEST_CASE(smoke_test) { char const* sourceCode = R"( contract test { - function f(uint a) returns(uint d) { return a * 7; } + function f(uint a) public returns(uint d) { return a * 7; } } )"; compileAndRun(sourceCode); @@ -73,7 +92,7 @@ BOOST_AUTO_TEST_CASE(exp_operator) { char const* sourceCode = R"( contract test { - function f(uint a) returns(uint d) { return 2 ** a; } + function f(uint a) public returns(uint d) { return 2 ** a; } } )"; compileAndRun(sourceCode); @@ -84,7 +103,7 @@ BOOST_AUTO_TEST_CASE(exp_operator_const) { char const* sourceCode = R"( contract test { - function f() returns(uint d) { return 2 ** 3; } + function f() public returns(uint d) { return 2 ** 3; } } )"; compileAndRun(sourceCode); @@ -95,7 +114,7 @@ BOOST_AUTO_TEST_CASE(exp_operator_const_signed) { char const* sourceCode = R"( contract test { - function f() returns(int d) { return (-2) ** 3; } + function f() public returns(int d) { return (-2) ** 3; } } )"; compileAndRun(sourceCode); @@ -106,7 +125,7 @@ BOOST_AUTO_TEST_CASE(exp_zero) { char const* sourceCode = R"( contract test { - function f(uint a) returns(uint d) { return a ** 0; } + function f(uint a) public returns(uint d) { return a ** 0; } } )"; compileAndRun(sourceCode); @@ -117,7 +136,7 @@ BOOST_AUTO_TEST_CASE(exp_zero_literal) { char const* sourceCode = R"( contract test { - function f() returns(uint d) { return 0 ** 0; } + function f() public returns(uint d) { return 0 ** 0; } } )"; compileAndRun(sourceCode); @@ -129,7 +148,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_true_literal) { char const* sourceCode = R"( contract test { - function f() returns(uint d) { + function f() public returns(uint d) { return true ? 5 : 10; } } @@ -142,7 +161,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_false_literal) { char const* sourceCode = R"( contract test { - function f() returns(uint d) { + function f() public returns(uint d) { return false ? 5 : 10; } } @@ -155,7 +174,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_multiple) { char const* sourceCode = R"( contract test { - function f(uint x) returns(uint d) { + function f(uint x) public returns(uint d) { return x > 100 ? x > 1000 ? 1000 : 100 : @@ -174,7 +193,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_with_return_values) { char const* sourceCode = R"( contract test { - function f(bool cond, uint v) returns (uint a, uint b) { + function f(bool cond, uint v) public returns (uint a, uint b) { cond ? a = v : b = v; } } @@ -189,7 +208,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_storage_memory_1) char const* sourceCode = R"( contract test { bytes2[2] data1; - function f(bool cond) returns (uint) { + function f(bool cond) public returns (uint) { bytes2[2] memory x; x[0] = "aa"; bytes2[2] memory y; @@ -222,7 +241,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_storage_memory_2) char const* sourceCode = R"( contract test { bytes2[2] data1; - function f(bool cond) returns (uint) { + function f(bool cond) public returns (uint) { data1[0] = "cc"; bytes2[2] memory x; @@ -255,7 +274,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_different_types) { char const* sourceCode = R"( contract test { - function f(bool cond) returns (uint) { + function f(bool cond) public returns (uint) { uint8 x = 0xcd; uint16 y = 0xabab; return cond ? x : y; @@ -272,7 +291,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_string_literal) { char const* sourceCode = R"( contract test { - function f(bool cond) returns (bytes32) { + function f(bool cond) public returns (bytes32) { return cond ? "true" : "false"; } } @@ -287,7 +306,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_tuples) { char const* sourceCode = R"( contract test { - function f(bool cond) returns (uint, uint) { + function f(bool cond) public returns (uint, uint) { return cond ? (1, 2) : (3, 4); } } @@ -301,11 +320,11 @@ BOOST_AUTO_TEST_CASE(conditional_expression_functions) { char const* sourceCode = R"( contract test { - function x() returns (uint) { return 1; } - function y() returns (uint) { return 2; } + function x() public returns (uint) { return 1; } + function y() public returns (uint) { return 2; } - function f(bool cond) returns (uint) { - var z = cond ? x : y; + function f(bool cond) public returns (uint) { + function () returns (uint) z = cond ? x : y; return z(); } } @@ -367,7 +386,7 @@ BOOST_AUTO_TEST_CASE(recursive_calls) { char const* sourceCode = R"( contract test { - function f(uint n) returns(uint nfac) { + function f(uint n) public returns(uint nfac) { if (n <= 1) return 1; else return n * f(n - 1); } @@ -389,10 +408,10 @@ BOOST_AUTO_TEST_CASE(multiple_functions) { char const* sourceCode = R"( contract test { - function a() returns(uint n) { return 0; } - function b() returns(uint n) { return 1; } - function c() returns(uint n) { return 2; } - function f() returns(uint n) { return 3; } + function a() public returns(uint n) { return 0; } + function b() public returns(uint n) { return 1; } + function c() public returns(uint n) { return 2; } + function f() public returns(uint n) { return 3; } } )"; compileAndRun(sourceCode); @@ -407,8 +426,8 @@ BOOST_AUTO_TEST_CASE(named_args) { char const* sourceCode = R"( contract test { - function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; } - function b() returns (uint r) { r = a({a: 1, b: 2, c: 3}); } + function a(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; } + function b() public returns (uint r) { r = a({a: 1, b: 2, c: 3}); } } )"; compileAndRun(sourceCode); @@ -419,8 +438,8 @@ BOOST_AUTO_TEST_CASE(disorder_named_args) { char const* sourceCode = R"( contract test { - function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; } - function b() returns (uint r) { r = a({c: 3, a: 1, b: 2}); } + function a(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; } + function b() public returns (uint r) { r = a({c: 3, a: 1, b: 2}); } } )"; compileAndRun(sourceCode); @@ -431,9 +450,9 @@ BOOST_AUTO_TEST_CASE(while_loop) { char const* sourceCode = R"( contract test { - function f(uint n) returns(uint nfac) { + function f(uint n) public returns(uint nfac) { nfac = 1; - var i = 2; + uint i = 2; while (i <= n) nfac *= i++; } } @@ -458,9 +477,9 @@ BOOST_AUTO_TEST_CASE(do_while_loop) { char const* sourceCode = R"( contract test { - function f(uint n) returns(uint nfac) { + function f(uint n) public returns(uint nfac) { nfac = 1; - var i = 2; + uint i = 2; do { nfac *= i++; } while (i <= n); } } @@ -504,12 +523,102 @@ BOOST_AUTO_TEST_CASE(do_while_loop_continue) ABI_CHECK(callContractFunction("f()"), encodeArgs(42)); } +BOOST_AUTO_TEST_CASE(array_multiple_local_vars) +{ + char const* sourceCode = R"( + contract test { + function f(uint256[] seq) external pure returns (uint256) { + uint i = 0; + uint sum = 0; + while (i < seq.length) + { + uint idx = i; + if (idx >= 10) break; + uint x = seq[idx]; + if (x >= 1000) { + uint n = i + 1; + i = n; + continue; + } + else { + uint y = sum + x; + sum = y; + } + if (sum >= 500) return sum; + i++; + } + return sum; + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("f(uint256[])", 32, 3, u256(1000), u256(1), u256(2)), encodeArgs(3)); + ABI_CHECK(callContractFunction("f(uint256[])", 32, 3, u256(100), u256(500), u256(300)), encodeArgs(600)); + ABI_CHECK(callContractFunction( + "f(uint256[])", 32, 11, + u256(1), u256(2), u256(3), u256(4), u256(5), u256(6), u256(7), u256(8), u256(9), u256(10), u256(111) + ), encodeArgs(55)); +} + + +BOOST_AUTO_TEST_CASE(do_while_loop_multiple_local_vars) +{ + char const* sourceCode = R"( + contract test { + function f(uint x) public pure returns(uint r) { + uint i = 0; + do + { + uint z = x * 2; + if (z < 4) break; + else { + uint k = z + 1; + if (k < 8) { + x++; + continue; + } + } + if (z > 12) return 0; + x++; + i++; + } while (true); + return 42; + } + } + )"; + compileAndRun(sourceCode); + + auto do_while = [](u256 n) -> u256 + { + u256 i = 0; + do + { + u256 z = n * 2; + if (z < 4) break; + else { + u256 k = z + 1; + if (k < 8) { + n++; + continue; + } + } + if (z > 12) return 0; + n++; + i++; + } while (true); + return 42; + }; + + testContractAgainstCppOnRange("f(uint256)", do_while, 0, 12); +} + BOOST_AUTO_TEST_CASE(nested_loops) { // tests that break and continue statements in nested loops jump to the correct place char const* sourceCode = R"( contract test { - function f(uint x) returns(uint y) { + function f(uint x) public returns(uint y) { while (x > 1) { if (x == 10) break; while (x > 5) { @@ -555,13 +664,186 @@ BOOST_AUTO_TEST_CASE(nested_loops) testContractAgainstCppOnRange("f(uint256)", nested_loops_cpp, 0, 12); } +BOOST_AUTO_TEST_CASE(nested_loops_multiple_local_vars) +{ + // tests that break and continue statements in nested loops jump to the correct place + // and free local variables properly + char const* sourceCode = R"( + contract test { + function f(uint x) returns(uint y) { + while (x > 0) { + uint z = x + 10; + uint k = z + 1; + if (k > 20) { + break; + uint p = 100; + k += p; + } + if (k > 15) { + x--; + continue; + uint t = 1000; + x += t; + } + while (k > 10) { + uint m = k - 1; + if (m == 10) return x; + return k; + uint h = 10000; + z += h; + } + x--; + break; + } + return x; + } + } + )"; + compileAndRun(sourceCode); + + auto nested_loops_cpp = [](u256 n) -> u256 + { + while (n > 0) + { + u256 z = n + 10; + u256 k = z + 1; + if (k > 20) break; + if (k > 15) { + n--; + continue; + } + while (k > 10) + { + u256 m = k - 1; + if (m == 10) return n; + return k; + } + n--; + break; + } + + return n; + }; + + testContractAgainstCppOnRange("f(uint256)", nested_loops_cpp, 0, 12); +} + +BOOST_AUTO_TEST_CASE(for_loop_multiple_local_vars) +{ + char const* sourceCode = R"( + contract test { + function f(uint x) public pure returns(uint r) { + for (uint i = 0; i < 12; i++) + { + uint z = x + 1; + if (z < 4) break; + else { + uint k = z * 2; + if (i + k < 10) { + x++; + continue; + } + } + if (z > 8) return 0; + x++; + } + return 42; + } + } + )"; + compileAndRun(sourceCode); + + auto for_loop = [](u256 n) -> u256 + { + for (u256 i = 0; i < 12; i++) + { + u256 z = n + 1; + if (z < 4) break; + else { + u256 k = z * 2; + if (i + k < 10) { + n++; + continue; + } + } + if (z > 8) return 0; + n++; + } + return 42; + }; + + testContractAgainstCppOnRange("f(uint256)", for_loop, 0, 12); +} + +BOOST_AUTO_TEST_CASE(nested_for_loop_multiple_local_vars) +{ + char const* sourceCode = R"( + contract test { + function f(uint x) public pure returns(uint r) { + for (uint i = 0; i < 5; i++) + { + uint z = x + 1; + if (z < 3) { + break; + uint p = z + 2; + } + for (uint j = 0; j < 5; j++) + { + uint k = z * 2; + if (j + k < 8) { + x++; + continue; + uint t = z * 3; + } + x++; + if (x > 20) { + return 84; + uint h = x + 42; + } + } + if (x > 30) { + return 42; + uint b = 0xcafe; + } + } + return 42; + } + } + )"; + compileAndRun(sourceCode); + + auto for_loop = [](u256 n) -> u256 + { + for (u256 i = 0; i < 5; i++) + { + u256 z = n + 1; + if (z < 3) break; + for (u256 j = 0; j < 5; j++) + { + u256 k = z * 2; + if (j + k < 8) { + n++; + continue; + } + n++; + if (n > 20) return 84; + } + if (n > 30) return 42; + } + return 42; + }; + + testContractAgainstCppOnRange("f(uint256)", for_loop, 0, 12); +} + BOOST_AUTO_TEST_CASE(for_loop) { char const* sourceCode = R"( contract test { - function f(uint n) returns(uint nfac) { + function f(uint n) public returns(uint nfac) { nfac = 1; - for (var i = 2; i <= n; i++) + uint i; + for (i = 2; i <= n; i++) nfac *= i; } } @@ -583,7 +865,7 @@ BOOST_AUTO_TEST_CASE(for_loop_empty) { char const* sourceCode = R"( contract test { - function f() returns(uint ret) { + function f() public returns(uint ret) { ret = 1; for (;;) { ret += 1; @@ -612,7 +894,7 @@ BOOST_AUTO_TEST_CASE(for_loop_simple_init_expr) { char const* sourceCode = R"( contract test { - function f(uint n) returns(uint nfac) { + function f(uint n) public returns(uint nfac) { nfac = 1; uint256 i; for (i = 2; i <= n; i++) @@ -638,7 +920,7 @@ BOOST_AUTO_TEST_CASE(for_loop_break_continue) { char const* sourceCode = R"( contract test { - function f(uint n) returns (uint r) + function f(uint n) public returns (uint r) { uint i = 1; uint k = 0; @@ -684,16 +966,16 @@ BOOST_AUTO_TEST_CASE(calling_other_functions) { char const* sourceCode = R"( contract collatz { - function run(uint x) returns(uint y) { + function run(uint x) public returns(uint y) { while ((y = x) > 1) { if (x % 2 == 0) x = evenStep(x); else x = oddStep(x); } } - function evenStep(uint x) returns(uint y) { + function evenStep(uint x) public returns(uint y) { return x / 2; } - function oddStep(uint x) returns(uint y) { + function oddStep(uint x) public returns(uint y) { return 3 * x + 1; } } @@ -734,8 +1016,8 @@ BOOST_AUTO_TEST_CASE(many_local_variables) { char const* sourceCode = R"( contract test { - function run(uint x1, uint x2, uint x3) returns(uint y) { - var a = 0x1; var b = 0x10; var c = 0x100; + function run(uint x1, uint x2, uint x3) public returns(uint y) { + uint8 a = 0x1; uint8 b = 0x10; uint16 c = 0x100; y = a + b + c + x1 + x2 + x3; y += b + x2; } @@ -757,7 +1039,7 @@ BOOST_AUTO_TEST_CASE(packing_unpacking_types) { char const* sourceCode = R"( contract test { - function run(bool a, uint32 b, uint64 c) returns(uint256 y) { + function run(bool a, uint32 b, uint64 c) public returns(uint256 y) { if (a) y = 1; y = y * 0x100000000 | ~b; y = y * 0x10000000000000000 | ~c; @@ -775,7 +1057,7 @@ BOOST_AUTO_TEST_CASE(packing_signed_types) { char const* sourceCode = R"( contract test { - function run() returns(int8 y) { + function run() public returns(int8 y) { uint8 x = 0xfa; return int8(x); } @@ -792,7 +1074,7 @@ BOOST_AUTO_TEST_CASE(multiple_return_values) { char const* sourceCode = R"( contract test { - function run(bool x1, uint x2) returns(uint y1, bool y2, uint y3) { + function run(bool x1, uint x2) public returns(uint y1, bool y2, uint y3) { y1 = x2; y2 = x1; } } @@ -805,7 +1087,7 @@ BOOST_AUTO_TEST_CASE(short_circuiting) { char const* sourceCode = R"( contract test { - function run(uint x) returns(uint y) { + function run(uint x) public returns(uint y) { x == 0 || ((x = 8) > 0); return x; } @@ -826,7 +1108,7 @@ BOOST_AUTO_TEST_CASE(high_bits_cleaning) { char const* sourceCode = R"( contract test { - function run() returns(uint256 y) { + function run() public returns(uint256 y) { uint32 t = uint32(0xffffffff); uint32 x = t + 10; if (x >= 0xffffffff) return 0; @@ -850,7 +1132,7 @@ BOOST_AUTO_TEST_CASE(sign_extension) { char const* sourceCode = R"( contract test { - function run() returns(uint256 y) { + function run() public returns(uint256 y) { int64 x = -int32(0xff); if (x >= 0xff) return 0; return -uint256(x); @@ -872,7 +1154,7 @@ BOOST_AUTO_TEST_CASE(small_unsigned_types) { char const* sourceCode = R"( contract test { - function run() returns(uint256 y) { + function run() public returns(uint256 y) { uint32 t = uint32(0xffffff); uint32 x = t * 0xffffff; return x / 0x100; @@ -893,7 +1175,7 @@ BOOST_AUTO_TEST_CASE(small_signed_types) { char const* sourceCode = R"( contract test { - function run() returns(int256 y) { + function run() public returns(int256 y) { return -int32(10) * -int64(20); } } @@ -910,10 +1192,10 @@ BOOST_AUTO_TEST_CASE(strings) { char const* sourceCode = R"( contract test { - function fixedBytes() returns(bytes32 ret) { + function fixedBytes() public returns(bytes32 ret) { return "abc\x00\xff__"; } - function pipeThrough(bytes2 small, bool one) returns(bytes16 large, bool oneRet) { + function pipeThrough(bytes2 small, bool one) public returns(bytes16 large, bool oneRet) { oneRet = one; large = small; } @@ -930,7 +1212,7 @@ BOOST_AUTO_TEST_CASE(inc_dec_operators) contract test { uint8 x; uint v; - function f() returns (uint r) { + function f() public returns (uint r) { uint a = 6; r = a; r += (a++) * 0x10; @@ -949,7 +1231,7 @@ BOOST_AUTO_TEST_CASE(bytes_comparison) { char const* sourceCode = R"( contract test { - function f() returns (bool) { + function f() public returns (bool) { bytes2 a = "a"; bytes2 x = "aa"; bytes2 b = "b"; @@ -967,7 +1249,7 @@ BOOST_AUTO_TEST_CASE(state_smoke_test) contract test { uint256 value1; uint256 value2; - function get(uint8 which) returns (uint256 value) { + function get(uint8 which) public returns (uint256 value) { if (which == 0) return value1; else return value2; } @@ -994,7 +1276,7 @@ BOOST_AUTO_TEST_CASE(compound_assign) contract test { uint value1; uint value2; - function f(uint x, uint y) returns (uint w) { + function f(uint x, uint y) public returns (uint w) { uint value3 = y; value1 += x; value3 *= x; @@ -1030,7 +1312,7 @@ BOOST_AUTO_TEST_CASE(simple_mapping) char const* sourceCode = R"( contract test { mapping(uint8 => uint8) table; - function get(uint8 k) returns (uint8 v) { + function get(uint8 k) public returns (uint8 v) { return table[k]; } function set(uint8 k, uint8 v) { @@ -1064,13 +1346,13 @@ BOOST_AUTO_TEST_CASE(mapping_state) mapping(address => bool) canVote; mapping(address => uint) voteCount; mapping(address => bool) voted; - function getVoteCount(address addr) returns (uint retVoteCount) { + function getVoteCount(address addr) public returns (uint retVoteCount) { return voteCount[addr]; } function grantVoteRight(address addr) { canVote[addr] = true; } - function vote(address voter, address vote) returns (bool success) { + function vote(address voter, address vote) public returns (bool success) { if (!canVote[voter] || voted[voter]) return false; voted[voter] = true; voteCount[vote] = voteCount[vote] + 1; @@ -1140,7 +1422,7 @@ BOOST_AUTO_TEST_CASE(mapping_state_inc_dec) contract test { uint value; mapping(uint => uint) table; - function f(uint x) returns (uint y) { + function f(uint x) public returns (uint y) { value = x; if (x > 0) table[++value] = 8; if (x > 1) value--; @@ -1172,7 +1454,7 @@ BOOST_AUTO_TEST_CASE(multi_level_mapping) char const* sourceCode = R"( contract test { mapping(uint => mapping(uint => uint)) table; - function f(uint x, uint y, uint z) returns (uint w) { + function f(uint x, uint y, uint z) public returns (uint w) { if (z == 0) return table[x][y]; else return table[x][y] = z; } @@ -1210,7 +1492,7 @@ BOOST_AUTO_TEST_CASE(structs) mapping(uint8 => s2) recursive; } s2 data; - function check() returns (bool ok) { + function check() public returns (bool ok) { return data.z == 1 && data.s1data.x == 2 && data.s1data.y == true && data.recursive[3].recursive[4].z == 5 && @@ -1218,7 +1500,7 @@ BOOST_AUTO_TEST_CASE(structs) data.recursive[0].s1data.y == false && data.recursive[4].z == 9; } - function set() { + function set() public { data.z = 1; data.s1data.x = 2; data.s1data.y = true; @@ -1244,16 +1526,16 @@ BOOST_AUTO_TEST_CASE(struct_reference) mapping(uint8 => s2) recursive; } s2 data; - function check() returns (bool ok) { + function check() public returns (bool ok) { return data.z == 2 && data.recursive[0].z == 3 && data.recursive[0].recursive[1].z == 0 && data.recursive[0].recursive[0].z == 1; } - function set() { + function set() public { data.z = 2; - var map = data.recursive; - s2 inner = map[0]; + mapping(uint8 => s2) map = data.recursive; + s2 storage inner = map[0]; inner.z = 3; inner.recursive[0].z = inner.recursive[1].z + 1; } @@ -1271,7 +1553,6 @@ BOOST_AUTO_TEST_CASE(deleteStruct) contract test { struct topStruct { nestedStruct nstr; - emptyStruct empty; uint topValue; mapping (uint => uint) topMapping; } @@ -1281,9 +1562,7 @@ BOOST_AUTO_TEST_CASE(deleteStruct) uint nestedValue; mapping (uint => bool) nestedMapping; } - struct emptyStruct{ - } - function test(){ + constructor(){ toDelete = 5; str.topValue = 1; str.topMapping[0] = 1; @@ -1295,19 +1574,19 @@ BOOST_AUTO_TEST_CASE(deleteStruct) delete str; delete toDelete; } - function getToDelete() returns (uint res){ + function getToDelete() public returns (uint res){ res = toDelete; } - function getTopValue() returns(uint topValue){ + function getTopValue() public returns(uint topValue){ topValue = str.topValue; } - function getNestedValue() returns(uint nestedValue){ + function getNestedValue() public returns(uint nestedValue){ nestedValue = str.nstr.nestedValue; } - function getTopMapping(uint index) returns(uint ret) { + function getTopMapping(uint index) public returns(uint ret) { ret = str.topMapping[index]; } - function getNestedMapping(uint index) returns(bool ret) { + function getNestedMapping(uint index) public returns(bool ret) { return str.nstr.nestedMapping[index]; } } @@ -1327,7 +1606,7 @@ BOOST_AUTO_TEST_CASE(deleteLocal) { char const* sourceCode = R"( contract test { - function delLocal() returns (uint res){ + function delLocal() public returns (uint res){ uint v = 5; delete v; res = v; @@ -1342,7 +1621,7 @@ BOOST_AUTO_TEST_CASE(deleteLocals) { char const* sourceCode = R"( contract test { - function delLocal() returns (uint res1, uint res2){ + function delLocal() public returns (uint res1, uint res2){ uint v = 5; uint w = 6; uint x = 7; @@ -1361,10 +1640,10 @@ BOOST_AUTO_TEST_CASE(constructor) char const* sourceCode = R"( contract test { mapping(uint => uint) data; - function test() { + constructor() public { data[7] = 8; } - function get(uint key) returns (uint value) { + function get(uint key) public returns (uint value) { return data[key]; } } @@ -1385,7 +1664,7 @@ BOOST_AUTO_TEST_CASE(simple_accessor) char const* sourceCode = R"( contract test { uint256 public data; - function test() { + constructor() public { data = 8; } } @@ -1404,7 +1683,7 @@ BOOST_AUTO_TEST_CASE(array_accessor) struct st { uint a; uint[] finalArray; } mapping(uint256 => mapping(uint256 => st[5])) public multiple_map; - function test() { + constructor() public { data[0] = 8; dynamicData.length = 3; dynamicData[2] = 8; @@ -1434,7 +1713,7 @@ BOOST_AUTO_TEST_CASE(accessors_mapping_for_array) contract test { mapping(uint => uint[8]) public data; mapping(uint => uint[]) public dynamicData; - function test() { + constructor() public { data[2][2] = 8; dynamicData[2].length = 3; dynamicData[2][2] = 8; @@ -1456,10 +1735,10 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) bytes6 public name; bytes32 public a_hash; address public an_address; - function test() { + constructor() public { data = 8; name = "Celina"; - a_hash = keccak256(123); + a_hash = keccak256("\x7b"); an_address = address(0x1337); super_secret_data = 42; } @@ -1482,7 +1761,7 @@ BOOST_AUTO_TEST_CASE(complex_accessors) mapping(uint256 => bool) public to_bool_map; mapping(uint256 => uint256) public to_uint_map; mapping(uint256 => mapping(uint256 => uint256)) public to_multiple_map; - function test() { + constructor() public { to_string_map[42] = "24"; to_bool_map[42] = false; to_uint_map[42] = 12; @@ -1503,7 +1782,7 @@ BOOST_AUTO_TEST_CASE(struct_accessor) contract test { struct Data { uint a; uint8 b; mapping(uint => uint) c; bool d; } mapping(uint => Data) public data; - function test() { + constructor() public { data[7].a = 1; data[7].b = 2; data[7].c[0] = 3; @@ -1519,8 +1798,8 @@ BOOST_AUTO_TEST_CASE(balance) { char const* sourceCode = R"( contract test { - function test() payable {} - function getBalance() returns (uint256 balance) { + constructor() public payable {} + function getBalance() public returns (uint256 balance) { return address(this).balance; } } @@ -1533,8 +1812,8 @@ BOOST_AUTO_TEST_CASE(blockchain) { char const* sourceCode = R"( contract test { - function test() payable {} - function someInfo() payable returns (uint256 value, address coinbase, uint256 blockNumber) { + constructor() public payable {} + function someInfo() public payable returns (uint256 value, address coinbase, uint256 blockNumber) { value = msg.value; coinbase = block.coinbase; blockNumber = block.number; @@ -1551,7 +1830,7 @@ BOOST_AUTO_TEST_CASE(msg_sig) { char const* sourceCode = R"( contract test { - function foo(uint256 a) returns (bytes4 value) { + function foo(uint256 a) public returns (bytes4 value) { return msg.sig; } } @@ -1564,10 +1843,10 @@ BOOST_AUTO_TEST_CASE(msg_sig_after_internal_call_is_same) { char const* sourceCode = R"( contract test { - function boo() returns (bytes4 value) { + function boo() public returns (bytes4 value) { return msg.sig; } - function foo(uint256 a) returns (bytes4 value) { + function foo(uint256 a) public returns (bytes4 value) { return boo(); } } @@ -1580,7 +1859,7 @@ BOOST_AUTO_TEST_CASE(now) { char const* sourceCode = R"( contract test { - function someInfo() returns (bool equal, uint val) { + function someInfo() public returns (bool equal, uint val) { equal = block.timestamp == now; val = now; } @@ -1603,7 +1882,7 @@ BOOST_AUTO_TEST_CASE(type_conversions_cleanup) // integer should drop the first two bytes char const* sourceCode = R"( contract Test { - function test() returns (uint ret) { return uint(address(Test(address(0x11223344556677889900112233445566778899001122)))); } + function test() public returns (uint ret) { return uint(address(Test(address(0x11223344556677889900112233445566778899001122)))); } } )"; compileAndRun(sourceCode); @@ -1616,7 +1895,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_smaller_size) { char const* sourceCode = R"( contract Test { - function bytesToBytes(bytes4 input) returns (bytes2 ret) { + function bytesToBytes(bytes4 input) public returns (bytes2 ret) { return bytes2(input); } } @@ -1629,7 +1908,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_greater_size) { char const* sourceCode = R"( contract Test { - function bytesToBytes(bytes2 input) returns (bytes4 ret) { + function bytesToBytes(bytes2 input) public returns (bytes4 ret) { return bytes4(input); } } @@ -1642,7 +1921,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_same_size) { char const* sourceCode = R"( contract Test { - function bytesToBytes(bytes4 input) returns (bytes4 ret) { + function bytesToBytes(bytes4 input) public returns (bytes4 ret) { return bytes4(input); } } @@ -1656,7 +1935,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_size) { char const* sourceCode = R"( contract Test { - function bytesToUint(bytes32 s) returns (uint256 h) { + function bytesToUint(bytes32 s) public returns (uint256 h) { return uint(s); } } @@ -1672,7 +1951,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_min_size) { char const* sourceCode = R"( contract Test { - function bytesToUint(bytes1 s) returns (uint8 h) { + function bytesToUint(bytes1 s) public returns (uint8 h) { return uint8(s); } } @@ -1688,7 +1967,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_smaller_size) { char const* sourceCode = R"( contract Test { - function bytesToUint(bytes4 s) returns (uint16 h) { + function bytesToUint(bytes4 s) public returns (uint16 h) { return uint16(uint32(s)); } } @@ -1704,7 +1983,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_greater_size) { char const* sourceCode = R"( contract Test { - function bytesToUint(bytes4 s) returns (uint64 h) { + function bytesToUint(bytes4 s) public returns (uint64 h) { return uint64(uint32(s)); } } @@ -1721,7 +2000,7 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_size) { char const* sourceCode = R"( contract Test { - function uintToBytes(uint256 h) returns (bytes32 s) { + function uintToBytes(uint256 h) public returns (bytes32 s) { return bytes32(h); } } @@ -1735,7 +2014,7 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_min_size) { char const* sourceCode = R"( contract Test { - function UintToBytes(uint8 h) returns (bytes1 s) { + function UintToBytes(uint8 h) public returns (bytes1 s) { return bytes1(h); } } @@ -1751,7 +2030,7 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_smaller_size) { char const* sourceCode = R"( contract Test { - function uintToBytes(uint32 h) returns (bytes2 s) { + function uintToBytes(uint32 h) public returns (bytes2 s) { return bytes2(uint16(h)); } } @@ -1767,7 +2046,7 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_greater_size) { char const* sourceCode = R"( contract Test { - function UintToBytes(uint16 h) returns (bytes8 s) { + function UintToBytes(uint16 h) public returns (bytes8 s) { return bytes8(uint64(h)); } } @@ -1783,8 +2062,8 @@ BOOST_AUTO_TEST_CASE(send_ether) { char const* sourceCode = R"( contract test { - function test() payable {} - function a(address addr, uint amount) returns (uint ret) { + constructor() payable public {} + function a(address addr, uint amount) public returns (uint ret) { addr.send(amount); return address(this).balance; } @@ -1801,8 +2080,8 @@ BOOST_AUTO_TEST_CASE(transfer_ether) { char const* sourceCode = R"( contract A { - function A() payable {} - function a(address addr, uint amount) returns (uint) { + constructor() public payable {} + function a(address addr, uint amount) public returns (uint) { addr.transfer(amount); return this.balance; } @@ -1815,7 +2094,7 @@ BOOST_AUTO_TEST_CASE(transfer_ether) } contract C { - function () payable { + function () external payable { throw; } } @@ -1839,8 +2118,7 @@ BOOST_AUTO_TEST_CASE(uncalled_blockhash) contract C { function f() public view returns (bytes32) { - var x = block.blockhash; - return x(block.number - 1); + return (blockhash)(block.number - 1); } } )"; @@ -1866,7 +2144,7 @@ BOOST_AUTO_TEST_CASE(log0) { char const* sourceCode = R"( contract test { - function a() { + function a() public { log0(1); } } @@ -1883,7 +2161,7 @@ BOOST_AUTO_TEST_CASE(log1) { char const* sourceCode = R"( contract test { - function a() { + function a() public { log1(1, 2); } } @@ -1901,7 +2179,7 @@ BOOST_AUTO_TEST_CASE(log2) { char const* sourceCode = R"( contract test { - function a() { + function a() public { log2(1, 2, 3); } } @@ -1920,7 +2198,7 @@ BOOST_AUTO_TEST_CASE(log3) { char const* sourceCode = R"( contract test { - function a() { + function a() public { log3(1, 2, 3, 4); } } @@ -1939,7 +2217,7 @@ BOOST_AUTO_TEST_CASE(log4) { char const* sourceCode = R"( contract test { - function a() { + function a() public { log4(1, 2, 3, 4, 5); } } @@ -1958,7 +2236,7 @@ BOOST_AUTO_TEST_CASE(log_in_constructor) { char const* sourceCode = R"( contract test { - function test() { + constructor() public { log1(1, 2); } } @@ -1971,31 +2249,12 @@ BOOST_AUTO_TEST_CASE(log_in_constructor) BOOST_CHECK_EQUAL(m_logs[0].topics[0], h256(u256(2))); } -BOOST_AUTO_TEST_CASE(suicide) -{ - char const* sourceCode = R"( - contract test { - function test() payable {} - function a(address receiver) returns (uint ret) { - suicide(receiver); - return 10; - } - } - )"; - u256 amount(130); - compileAndRun(sourceCode, amount); - u160 address(23); - ABI_CHECK(callContractFunction("a(address)", address), bytes()); - BOOST_CHECK(!addressHasCode(m_contractAddress)); - BOOST_CHECK_EQUAL(balanceAt(address), amount); -} - BOOST_AUTO_TEST_CASE(selfdestruct) { char const* sourceCode = R"( contract test { - function test() payable {} - function a(address receiver) returns (uint ret) { + constructor() public payable {} + function a(address receiver) public returns (uint ret) { selfdestruct(receiver); return 10; } @@ -2013,8 +2272,8 @@ BOOST_AUTO_TEST_CASE(keccak256) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 hash) { - return keccak256(input); + function a(bytes32 input) public returns (bytes32 hash) { + return keccak256(abi.encodePacked(input)); } } )"; @@ -2028,29 +2287,12 @@ BOOST_AUTO_TEST_CASE(keccak256) testContractAgainstCpp("a(bytes32)", f, u256(-1)); } -BOOST_AUTO_TEST_CASE(sha3) -{ - char const* sourceCode = R"( - contract test { - // to confuse the optimiser - function b(bytes32 input) returns (bytes32) { - return sha3(input); - } - function a(bytes32 input) returns (bool) { - return keccak256(input) == b(input); - } - } - )"; - compileAndRun(sourceCode); - BOOST_REQUIRE(callContractFunction("a(bytes32)", u256(42)) == encodeArgs(true)); -} - BOOST_AUTO_TEST_CASE(sha256) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 sha256hash) { - return sha256(input); + function a(bytes32 input) public returns (bytes32 sha256hash) { + return sha256(abi.encodePacked(input)); } } )"; @@ -2074,8 +2316,8 @@ BOOST_AUTO_TEST_CASE(ripemd) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 sha256hash) { - return ripemd160(input); + function a(bytes32 input) public returns (bytes32 sha256hash) { + return ripemd160(abi.encodePacked(input)); } } )"; @@ -2099,10 +2341,10 @@ BOOST_AUTO_TEST_CASE(packed_keccak256) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 hash) { - var b = 65536; + function a(bytes32 input) public returns (bytes32 hash) { + uint24 b = 65536; uint c = 256; - return keccak256(8, input, b, input, c); + return keccak256(abi.encodePacked(uint8(8), input, b, input, c)); } } )"; @@ -2127,14 +2369,14 @@ BOOST_AUTO_TEST_CASE(packed_keccak256_complex_types) char const* sourceCode = R"( contract test { uint120[3] x; - function f() returns (bytes32 hash1, bytes32 hash2, bytes32 hash3) { + function f() public returns (bytes32 hash1, bytes32 hash2, bytes32 hash3) { uint120[] memory y = new uint120[](3); x[0] = y[0] = uint120(-2); x[1] = y[1] = uint120(-3); x[2] = y[2] = uint120(-4); - hash1 = keccak256(x); - hash2 = keccak256(y); - hash3 = keccak256(this.f); + hash1 = keccak256(abi.encodePacked(x)); + hash2 = keccak256(abi.encodePacked(y)); + hash3 = keccak256(abi.encodePacked(this.f)); } } )"; @@ -2151,10 +2393,10 @@ BOOST_AUTO_TEST_CASE(packed_sha256) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 hash) { - var b = 65536; + function a(bytes32 input) public returns (bytes32 hash) { + uint24 b = 65536; uint c = 256; - return sha256(8, input, b, input, c); + return sha256(abi.encodePacked(uint8(8), input, b, input, c)); } } )"; @@ -2178,10 +2420,10 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160) { char const* sourceCode = R"( contract test { - function a(bytes32 input) returns (bytes32 hash) { - var b = 65536; + function a(bytes32 input) public returns (bytes32 hash) { + uint24 b = 65536; uint c = 256; - return ripemd160(8, input, b, input, c); + return ripemd160(abi.encodePacked(uint8(8), input, b, input, c)); } } )"; @@ -2205,7 +2447,7 @@ BOOST_AUTO_TEST_CASE(ecrecover) { char const* sourceCode = R"( contract test { - function a(bytes32 h, uint8 v, bytes32 r, bytes32 s) returns (address addr) { + function a(bytes32 h, uint8 v, bytes32 r, bytes32 s) public returns (address addr) { return ecrecover(h, v, r, s); } } @@ -2223,16 +2465,16 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls) { char const* sourceCode = R"( contract Helper { - function multiply(uint a, uint b) returns (uint c) { + function multiply(uint a, uint b) public returns (uint c) { return a * b; } } contract Main { Helper h; - function callHelper(uint a, uint b) returns (uint c) { + function callHelper(uint a, uint b) public returns (uint c) { return h.multiply(a, b); } - function getHelper() returns (address haddress) { + function getHelper() public returns (address haddress) { return address(h); } function setHelper(address haddress) { @@ -2254,16 +2496,16 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_complex_parameters) { char const* sourceCode = R"( contract Helper { - function sel(uint a, bool select, uint b) returns (uint c) { + function sel(uint a, bool select, uint b) public returns (uint c) { if (select) return a; else return b; } } contract Main { Helper h; - function callHelper(uint a, bool select, uint b) returns (uint c) { + function callHelper(uint a, bool select, uint b) public returns (uint c) { return h.sel(a, select, b) * 3; } - function getHelper() returns (address haddress) { + function getHelper() public returns (address haddress) { return address(h); } function setHelper(address haddress) { @@ -2286,16 +2528,16 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_accessing_this) { char const* sourceCode = R"( contract Helper { - function getAddress() returns (address addr) { + function getAddress() public returns (address addr) { return address(this); } } contract Main { Helper h; - function callHelper() returns (address addr) { + function callHelper() public returns (address addr) { return h.getAddress(); } - function getHelper() returns (address addr) { + function getHelper() public returns (address addr) { return address(h); } function setHelper(address addr) { @@ -2315,19 +2557,19 @@ BOOST_AUTO_TEST_CASE(calls_to_this) { char const* sourceCode = R"( contract Helper { - function invoke(uint a, uint b) returns (uint c) { + function invoke(uint a, uint b) public returns (uint c) { return this.multiply(a, b, 10); } - function multiply(uint a, uint b, uint8 c) returns (uint ret) { + function multiply(uint a, uint b, uint8 c) public returns (uint ret) { return a * b + c; } } contract Main { Helper h; - function callHelper(uint a, uint b) returns (uint ret) { + function callHelper(uint a, uint b) public returns (uint ret) { return h.invoke(a, b); } - function getHelper() returns (address addr) { + function getHelper() public returns (address addr) { return address(h); } function setHelper(address addr) { @@ -2351,19 +2593,18 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars) // so this tests correct stack slot allocation char const* sourceCode = R"( contract Helper { - function multiply(uint a, uint b) returns (uint c) { + function multiply(uint a, uint b) public returns (uint c) { return a * b; } } contract Main { Helper h; - function callHelper(uint a, uint b) returns (uint c) { - var fu = h.multiply; - var y = 9; - var ret = fu(a, b); + function callHelper(uint a, uint b) public returns (uint c) { + uint8 y = 9; + uint256 ret = h.multiply(a, b); return ret + y; } - function getHelper() returns (address haddress) { + function getHelper() public returns (address haddress) { return address(h); } function setHelper(address haddress) { @@ -2385,16 +2626,16 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_in_calls) { char const* sourceCode = R"( contract Helper { - function invoke(bytes3 x, bool stop) returns (bytes4 ret) { + function invoke(bytes3 x, bool stop) public returns (bytes4 ret) { return x; } } contract Main { Helper h; - function callHelper(bytes2 x, bool stop) returns (bytes5 ret) { + function callHelper(bytes2 x, bool stop) public returns (bytes5 ret) { return h.invoke(x, stop); } - function getHelper() returns (address addr) { + function getHelper() public returns (address addr) { return address(h); } function setHelper(address addr) { @@ -2417,20 +2658,20 @@ BOOST_AUTO_TEST_CASE(constructor_arguments_internal) bytes3 name; bool flag; - function Helper(bytes3 x, bool f) { + constructor(bytes3 x, bool f) public { name = x; flag = f; } - function getName() returns (bytes3 ret) { return name; } - function getFlag() returns (bool ret) { return flag; } + function getName() public returns (bytes3 ret) { return name; } + function getFlag() public returns (bool ret) { return flag; } } contract Main { Helper h; - function Main() { + constructor() public { h = new Helper("abc", true); } - function getFlag() returns (bool ret) { return h.getFlag(); } - function getName() returns (bytes3 ret) { return h.getName(); } + function getFlag() public returns (bool ret) { return h.getFlag(); } + function getName() public returns (bytes3 ret) { return h.getName(); } } )"; compileAndRun(sourceCode, 0, "Main"); @@ -2445,12 +2686,12 @@ BOOST_AUTO_TEST_CASE(constructor_arguments_external) bytes3 name; bool flag; - function Main(bytes3 x, bool f) { + constructor(bytes3 x, bool f) public { name = x; flag = f; } - function getName() returns (bytes3 ret) { return name; } - function getFlag() returns (bool ret) { return flag; } + function getName() public returns (bytes3 ret) { return name; } + function getFlag() public returns (bool ret) { return flag; } } )"; compileAndRun(sourceCode, 0, "Main", encodeArgs("abc", true)); @@ -2465,7 +2706,7 @@ BOOST_AUTO_TEST_CASE(constructor_with_long_arguments) string public a; string public b; - function Main(string _a, string _b) { + constructor(string _a, string _b) public { a = _a; b = _b; } @@ -2493,7 +2734,7 @@ BOOST_AUTO_TEST_CASE(constructor_static_array_argument) uint public a; uint[3] public b; - function C(uint _a, uint[3] _b) { + constructor(uint _a, uint[3] _b) public { a = _a; b = _b; } @@ -2513,7 +2754,7 @@ BOOST_AUTO_TEST_CASE(constant_var_as_array_length) uint constant LEN = 3; uint[LEN] public a; - function C(uint[LEN] _a) { + constructor(uint[LEN] _a) public { a = _a; } } @@ -2530,10 +2771,10 @@ BOOST_AUTO_TEST_CASE(functions_called_by_constructor) contract Test { bytes3 name; bool flag; - function Test() { + constructor() public { setName("abc"); } - function getName() returns (bytes3 ret) { return name; } + function getName() public returns (bytes3 ret) { return name; } function setName(bytes3 _name) private { name = _name; } } )"; @@ -2545,12 +2786,12 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) { char const* sourceCode = R"( contract helper { - function() payable { } // can receive ether + function() external payable { } // can receive ether } contract test { helper h; - function test() payable { h = new helper(); h.send(5); } - function getBalance() returns (uint256 myBalance, uint256 helperBalance) { + constructor() public payable { h = new helper(); h.send(5); } + function getBalance() public returns (uint256 myBalance, uint256 helperBalance) { myBalance = this.balance; helperBalance = h.balance; } @@ -2566,23 +2807,23 @@ BOOST_AUTO_TEST_CASE(gas_and_value_basic) char const* sourceCode = R"( contract helper { bool flag; - function getBalance() payable returns (uint256 myBalance) { + function getBalance() payable public returns (uint256 myBalance) { return this.balance; } - function setFlag() { flag = true; } - function getFlag() returns (bool fl) { return flag; } + function setFlag() public { flag = true; } + function getFlag() public returns (bool fl) { return flag; } } contract test { helper h; - function test() payable { h = new helper(); } - function sendAmount(uint amount) payable returns (uint256 bal) { + constructor() public payable { h = new helper(); } + function sendAmount(uint amount) public payable returns (uint256 bal) { return h.getBalance.value(amount)(); } - function outOfGas() returns (bool ret) { + function outOfGas() public returns (bool ret) { h.setFlag.gas(2)(); // should fail due to OOG return true; } - function checkState() returns (bool flagAfter, uint myBal) { + function checkState() public returns (bool flagAfter, uint myBal) { flagAfter = h.getFlag(); myBal = this.balance; } @@ -2599,18 +2840,16 @@ BOOST_AUTO_TEST_CASE(value_complex) { char const* sourceCode = R"( contract helper { - function getBalance() payable returns (uint256 myBalance) { + function getBalance() payable public returns (uint256 myBalance) { return this.balance; } } contract test { helper h; - function test() payable { h = new helper(); } + constructor() public payable { h = new helper(); } function sendAmount(uint amount) payable returns (uint256 bal) { - var x1 = h.getBalance.value(amount); uint someStackElement = 20; - var x2 = x1.gas(1000); - return x2.value(amount + 3)();// overwrite value + return h.getBalance.value(amount).gas(1000).value(amount + 3)(); } } )"; @@ -2622,18 +2861,15 @@ BOOST_AUTO_TEST_CASE(value_insane) { char const* sourceCode = R"( contract helper { - function getBalance() payable returns (uint256 myBalance) { + function getBalance() payable public returns (uint256 myBalance) { return this.balance; } } contract test { helper h; - function test() payable { h = new helper(); } - function sendAmount(uint amount) returns (uint256 bal) { - var x1 = h.getBalance.value; - var x2 = x1(amount).gas; - var x3 = x2(1000).value; - return x3(amount + 3)();// overwrite value + constructor() public payable { h = new helper(); } + function sendAmount(uint amount) public returns (uint256 bal) { + return h.getBalance.value(amount).gas(1000).value(amount + 3)();// overwrite value } } )"; @@ -2647,21 +2883,21 @@ BOOST_AUTO_TEST_CASE(value_for_constructor) contract Helper { bytes3 name; bool flag; - function Helper(bytes3 x, bool f) payable { + constructor(bytes3 x, bool f) payable { name = x; flag = f; } - function getName() returns (bytes3 ret) { return name; } - function getFlag() returns (bool ret) { return flag; } + function getName() public returns (bytes3 ret) { return name; } + function getFlag() public returns (bool ret) { return flag; } } contract Main { Helper h; - function Main() payable { + constructor() payable { h = (new Helper).value(10)("abc", true); } - function getFlag() returns (bool ret) { return h.getFlag(); } - function getName() returns (bytes3 ret) { return h.getName(); } - function getBalances() returns (uint me, uint them) { me = this.balance; them = h.balance;} + function getFlag() public returns (bool ret) { return h.getFlag(); } + function getName() public returns (bytes3 ret) { return h.getName(); } + function getBalances() public returns (uint me, uint them) { me = this.balance; them = h.balance;} } )"; compileAndRun(sourceCode, 22, "Main"); @@ -2674,11 +2910,11 @@ BOOST_AUTO_TEST_CASE(virtual_function_calls) { char const* sourceCode = R"( contract Base { - function f() returns (uint i) { return g(); } - function g() returns (uint i) { return 1; } + function f() public returns (uint i) { return g(); } + function g() public returns (uint i) { return 1; } } contract Derived is Base { - function g() returns (uint i) { return 2; } + function g() public returns (uint i) { return 2; } } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2691,16 +2927,16 @@ BOOST_AUTO_TEST_CASE(access_base_storage) char const* sourceCode = R"( contract Base { uint dataBase; - function getViaBase() returns (uint i) { return dataBase; } + function getViaBase() public returns (uint i) { return dataBase; } } contract Derived is Base { uint dataDerived; - function setData(uint base, uint derived) returns (bool r) { + function setData(uint base, uint derived) public returns (bool r) { dataBase = base; dataDerived = derived; return true; } - function getViaDerived() returns (uint base, uint derived) { + function getViaDerived() public returns (uint base, uint derived) { base = dataBase; derived = dataDerived; } @@ -2718,10 +2954,10 @@ BOOST_AUTO_TEST_CASE(single_copy_with_multiple_inheritance) contract Base { uint data; function setData(uint i) { data = i; } - function getViaBase() returns (uint i) { return data; } + function getViaBase() public returns (uint i) { return data; } } contract A is Base { function setViaA(uint i) { setData(i); } } - contract B is Base { function getViaB() returns (uint i) { return getViaBase(); } } + contract B is Base { function getViaB() public returns (uint i) { return getViaBase(); } } contract Derived is Base, B, A { } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2733,11 +2969,11 @@ BOOST_AUTO_TEST_CASE(single_copy_with_multiple_inheritance) BOOST_AUTO_TEST_CASE(explicit_base_class) { char const* sourceCode = R"( - contract BaseBase { function g() returns (uint r) { return 1; } } - contract Base is BaseBase { function g() returns (uint r) { return 2; } } + contract BaseBase { function g() public returns (uint r) { return 1; } } + contract Base is BaseBase { function g() public returns (uint r) { return 2; } } contract Derived is Base { - function f() returns (uint r) { return BaseBase.g(); } - function g() returns (uint r) { return 3; } + function f() public returns (uint r) { return BaseBase.g(); } + function g() public returns (uint r) { return 3; } } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2750,17 +2986,17 @@ BOOST_AUTO_TEST_CASE(base_constructor_arguments) char const* sourceCode = R"( contract BaseBase { uint m_a; - function BaseBase(uint a) { + constructor(uint a) public { m_a = a; } } contract Base is BaseBase(7) { - function Base() { + constructor() public { m_a *= m_a; } } contract Derived is Base() { - function getA() returns (uint r) { return m_a; } + function getA() public returns (uint r) { return m_a; } } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2772,15 +3008,15 @@ BOOST_AUTO_TEST_CASE(function_usage_in_constructor_arguments) char const* sourceCode = R"( contract BaseBase { uint m_a; - function BaseBase(uint a) { + constructor(uint a) public { m_a = a; } - function g() returns (uint r) { return 2; } + function g() public returns (uint r) { return 2; } } contract Base is BaseBase(BaseBase.g()) { } contract Derived is Base() { - function getA() returns (uint r) { return m_a; } + function getA() public returns (uint r) { return m_a; } } )"; compileAndRun(sourceCode, 0, "Derived"); @@ -2792,46 +3028,28 @@ BOOST_AUTO_TEST_CASE(virtual_function_usage_in_constructor_arguments) char const* sourceCode = R"( contract BaseBase { uint m_a; - function BaseBase(uint a) { + constructor(uint a) public { m_a = a; } - function overridden() returns (uint r) { return 1; } - function g() returns (uint r) { return overridden(); } + function overridden() public returns (uint r) { return 1; } + function g() public returns (uint r) { return overridden(); } } contract Base is BaseBase(BaseBase.g()) { } contract Derived is Base() { - function getA() returns (uint r) { return m_a; } - function overridden() returns (uint r) { return 2; } + function getA() public returns (uint r) { return m_a; } + function overridden() public returns (uint r) { return 2; } } )"; compileAndRun(sourceCode, 0, "Derived"); ABI_CHECK(callContractFunction("getA()"), encodeArgs(2)); } -BOOST_AUTO_TEST_CASE(constructor_argument_overriding) -{ - char const* sourceCode = R"( - contract BaseBase { - uint m_a; - function BaseBase(uint a) { - m_a = a; - } - } - contract Base is BaseBase(2) { } - contract Derived is BaseBase(3), Base { - function getA() returns (uint r) { return m_a; } - } - )"; - compileAndRun(sourceCode, 0, "Derived"); - ABI_CHECK(callContractFunction("getA()"), encodeArgs(3)); -} - BOOST_AUTO_TEST_CASE(internal_constructor) { char const* sourceCode = R"( contract C { - function C() internal {} + constructor() internal {} } )"; BOOST_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "C").empty()); @@ -2841,7 +3059,7 @@ BOOST_AUTO_TEST_CASE(function_modifier) { char const* sourceCode = R"( contract C { - function getOne() payable nonFree returns (uint r) { return 1; } + function getOne() payable nonFree public returns (uint r) { return 1; } modifier nonFree { if (msg.value > 0) _; } } )"; @@ -2854,9 +3072,9 @@ BOOST_AUTO_TEST_CASE(function_modifier_local_variables) { char const* sourceCode = R"( contract C { - modifier mod1 { var a = 1; var b = 2; _; } + modifier mod1 { uint8 a = 1; uint8 b = 2; _; } modifier mod2(bool a) { if (a) return; else _; } - function f(bool a) mod1 mod2(a) returns (uint r) { return 3; } + function f(bool a) mod1 mod2(a) public returns (uint r) { return 3; } } )"; compileAndRun(sourceCode); @@ -2868,8 +3086,8 @@ BOOST_AUTO_TEST_CASE(function_modifier_loop) { char const* sourceCode = R"( contract C { - modifier repeat(uint count) { for (var i = 0; i < count; ++i) _; } - function f() repeat(10) returns (uint r) { r += 1; } + modifier repeat(uint count) { uint i; for (i = 0; i < count; ++i) _; } + function f() repeat(10) public returns (uint r) { r += 1; } } )"; compileAndRun(sourceCode); @@ -2881,7 +3099,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_multi_invocation) char const* sourceCode = R"( contract C { modifier repeat(bool twice) { if (twice) _; _; } - function f(bool twice) repeat(twice) returns (uint r) { r += 1; } + function f(bool twice) repeat(twice) public returns (uint r) { r += 1; } } )"; compileAndRun(sourceCode); @@ -2896,7 +3114,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_multi_with_return) char const* sourceCode = R"( contract C { modifier repeat(bool twice) { if (twice) _; _; } - function f(bool twice) repeat(twice) returns (uint r) { r += 1; return r; } + function f(bool twice) repeat(twice) public returns (uint r) { r += 1; return r; } } )"; compileAndRun(sourceCode); @@ -2908,7 +3126,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_overriding) { char const* sourceCode = R"( contract A { - function f() mod returns (bool r) { return true; } + function f() mod public returns (bool r) { return true; } modifier mod { _; } } contract C is A { @@ -2924,18 +3142,18 @@ BOOST_AUTO_TEST_CASE(function_modifier_calling_functions_in_creation_context) char const* sourceCode = R"( contract A { uint data; - function A() mod1 { f1(); } - function f1() mod2 { data |= 0x1; } - function f2() { data |= 0x20; } - function f3() { } + constructor() mod1 public { f1(); } + function f1() mod2 public { data |= 0x1; } + function f2() public { data |= 0x20; } + function f3() public { } modifier mod1 { f2(); _; } modifier mod2 { f3(); if (false) _; } - function getData() returns (uint r) { return data; } + function getData() public returns (uint r) { return data; } } contract C is A { modifier mod1 { f4(); _; } - function f3() { data |= 0x300; } - function f4() { data |= 0x4000; } + function f3() public { data |= 0x300; } + function f4() public { data |= 0x4000; } } )"; compileAndRun(sourceCode); @@ -2947,9 +3165,9 @@ BOOST_AUTO_TEST_CASE(function_modifier_for_constructor) char const* sourceCode = R"( contract A { uint data; - function A() mod1 { data |= 2; } + constructor() mod1 { data |= 2; } modifier mod1 { data |= 1; _; } - function getData() returns (uint r) { return data; } + function getData() public returns (uint r) { return data; } } contract C is A { modifier mod1 { data |= 4; _; } @@ -2965,7 +3183,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_multiple_times) contract C { uint public a; modifier mod(uint x) { a += x; _; } - function f(uint x) mod(2) mod(5) mod(x) returns(uint) { return a; } + function f(uint x) mod(2) mod(5) mod(x) public returns(uint) { return a; } } )"; compileAndRun(sourceCode); @@ -2979,7 +3197,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_multiple_times_local_vars) contract C { uint public a; modifier mod(uint x) { uint b = x; a += b; _; a -= b; assert(b == x); } - function f(uint x) mod(2) mod(5) mod(x) returns(uint) { return a; } + function f(uint x) mod(2) mod(5) mod(x) public returns(uint) { return a; } } )"; compileAndRun(sourceCode); @@ -3043,11 +3261,10 @@ BOOST_AUTO_TEST_CASE(crazy_elementary_typenames_on_stack) { char const* sourceCode = R"( contract C { - function f() returns (uint r) { + function f() public returns (uint r) { uint; uint; uint; uint; int x = -7; - var a = uint; - return a(x); + return uint(x); } } )"; @@ -3058,10 +3275,10 @@ BOOST_AUTO_TEST_CASE(crazy_elementary_typenames_on_stack) BOOST_AUTO_TEST_CASE(super) { char const* sourceCode = R"( - contract A { function f() returns (uint r) { return 1; } } - contract B is A { function f() returns (uint r) { return super.f() | 2; } } - contract C is A { function f() returns (uint r) { return super.f() | 4; } } - contract D is B, C { function f() returns (uint r) { return super.f() | 8; } } + contract A { function f() public returns (uint r) { return 1; } } + contract B is A { function f() public returns (uint r) { return super.f() | 2; } } + contract C is A { function f() public returns (uint r) { return super.f() | 4; } } + contract D is B, C { function f() public returns (uint r) { return super.f() | 8; } } )"; compileAndRun(sourceCode, 0, "D"); ABI_CHECK(callContractFunction("f()"), encodeArgs(1 | 2 | 4 | 8)); @@ -3070,10 +3287,10 @@ BOOST_AUTO_TEST_CASE(super) BOOST_AUTO_TEST_CASE(super_in_constructor) { char const* sourceCode = R"( - contract A { function f() returns (uint r) { return 1; } } - contract B is A { function f() returns (uint r) { return super.f() | 2; } } - contract C is A { function f() returns (uint r) { return super.f() | 4; } } - contract D is B, C { uint data; function D() { data = super.f() | 8; } function f() returns (uint r) { return data; } } + contract A { function f() public returns (uint r) { return 1; } } + contract B is A { function f() public returns (uint r) { return super.f() | 2; } } + contract C is A { function f() public returns (uint r) { return super.f() | 4; } } + contract D is B, C { uint data; constructor() public { data = super.f() | 8; } function f() public returns (uint r) { return data; } } )"; compileAndRun(sourceCode, 0, "D"); ABI_CHECK(callContractFunction("f()"), encodeArgs(1 | 2 | 4 | 8)); @@ -3082,7 +3299,7 @@ BOOST_AUTO_TEST_CASE(super_in_constructor) BOOST_AUTO_TEST_CASE(super_alone) { char const* sourceCode = R"( - contract A { function f() { super; } } + contract A { function f() public { super; } } )"; compileAndRun(sourceCode, 0, "A"); ABI_CHECK(callContractFunction("f()"), encodeArgs()); @@ -3093,8 +3310,8 @@ BOOST_AUTO_TEST_CASE(fallback_function) char const* sourceCode = R"( contract A { uint data; - function() { data = 1; } - function getData() returns (uint r) { return data; } + function() external { data = 1; } + function getData() public returns (uint r) { return data; } } )"; compileAndRun(sourceCode); @@ -3108,8 +3325,8 @@ BOOST_AUTO_TEST_CASE(inherited_fallback_function) char const* sourceCode = R"( contract A { uint data; - function() { data = 1; } - function getData() returns (uint r) { return data; } + function() external { data = 1; } + function getData() public returns (uint r) { return data; } } contract B is A {} )"; @@ -3121,13 +3338,13 @@ BOOST_AUTO_TEST_CASE(inherited_fallback_function) BOOST_AUTO_TEST_CASE(default_fallback_throws) { - char const* sourceCode = R"( + char const* sourceCode = R"YY( contract A { - function f() returns (bool) { - return this.call(); + function f() public returns (bool) { + return this.call(""); } } - )"; + )YY"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("f()"), encodeArgs(0)); } @@ -3138,16 +3355,18 @@ BOOST_AUTO_TEST_CASE(short_data_calls_fallback) contract A { uint public x; // Signature is d88e0b00 - function fow() { x = 3; } - function () { x = 2; } + function fow() public { x = 3; } + function () external { x = 2; } } )"; compileAndRun(sourceCode); // should call fallback sendMessage(asBytes("\xd8\x8e\x0b"), false, 0); + BOOST_CHECK(m_transactionSuccessful); ABI_CHECK(callContractFunction("x()"), encodeArgs(2)); // should call function sendMessage(asBytes(string("\xd8\x8e\x0b") + string(1, 0)), false, 0); + BOOST_CHECK(m_transactionSuccessful); ABI_CHECK(callContractFunction("x()"), encodeArgs(3)); } @@ -3161,7 +3380,7 @@ BOOST_AUTO_TEST_CASE(event) bytes32 s = 0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f; log3(bytes32(msg.value), s, bytes32(uint256(msg.sender)), _id); } else { - Deposit(msg.sender, _id, msg.value); + emit Deposit(msg.sender, _id, msg.value); } } } @@ -3210,8 +3429,8 @@ BOOST_AUTO_TEST_CASE(event_no_arguments) char const* sourceCode = R"( contract ClientReceipt { event Deposit(); - function deposit() { - Deposit(); + function deposit() public { + emit Deposit(); } } )"; @@ -3225,28 +3444,6 @@ BOOST_AUTO_TEST_CASE(event_no_arguments) BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit()"))); } -BOOST_AUTO_TEST_CASE(event_access_through_base_name) -{ - char const* sourceCode = R"( - contract A { - event x(); - } - contract B is A { - function f() returns (uint) { - A.x(); - return 1; - } - } - )"; - compileAndRun(sourceCode); - callContractFunction("f()"); - BOOST_REQUIRE_EQUAL(m_logs.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK(m_logs[0].data.empty()); - BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("x()"))); -} - BOOST_AUTO_TEST_CASE(event_access_through_base_name_emit) { char const* sourceCode = R"( @@ -3254,7 +3451,7 @@ BOOST_AUTO_TEST_CASE(event_access_through_base_name_emit) event x(); } contract B is A { - function f() returns (uint) { + function f() public returns (uint) { emit A.x(); return 1; } @@ -3276,68 +3473,16 @@ BOOST_AUTO_TEST_CASE(events_with_same_name) event Deposit(); event Deposit(address _addr); event Deposit(address _addr, uint _amount); - function deposit() returns (uint) { - Deposit(); - return 1; - } - function deposit(address _addr) returns (uint) { - Deposit(_addr); - return 1; - } - function deposit(address _addr, uint _amount) returns (uint) { - Deposit(_addr, _amount); - return 1; - } - } - )"; - u160 const c_loggedAddress = m_contractAddress; - - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("deposit()"), encodeArgs(u256(1))); - BOOST_REQUIRE_EQUAL(m_logs.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK(m_logs[0].data.empty()); - BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit()"))); - - ABI_CHECK(callContractFunction("deposit(address)", c_loggedAddress), encodeArgs(u256(1))); - BOOST_REQUIRE_EQUAL(m_logs.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK(m_logs[0].data == encodeArgs(c_loggedAddress)); - BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(address)"))); - - ABI_CHECK(callContractFunction("deposit(address,uint256)", c_loggedAddress, u256(100)), encodeArgs(u256(1))); - BOOST_REQUIRE_EQUAL(m_logs.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK(m_logs[0].data == encodeArgs(c_loggedAddress, 100)); - BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(address,uint256)"))); -} - -BOOST_AUTO_TEST_CASE(events_with_same_name_inherited) -{ - char const* sourceCode = R"( - contract A { - event Deposit(); - } - - contract B { - event Deposit(address _addr); - } - - contract ClientReceipt is A, B { - event Deposit(address _addr, uint _amount); - function deposit() returns (uint) { - Deposit(); + function deposit() public returns (uint) { + emit Deposit(); return 1; } - function deposit(address _addr) returns (uint) { - Deposit(_addr); + function deposit(address _addr) public returns (uint) { + emit Deposit(_addr); return 1; } - function deposit(address _addr, uint _amount) returns (uint) { - Deposit(_addr, _amount); + function deposit(address _addr, uint _amount) public returns (uint) { + emit Deposit(_addr, _amount); return 1; } } @@ -3380,15 +3525,15 @@ BOOST_AUTO_TEST_CASE(events_with_same_name_inherited_emit) contract ClientReceipt is A, B { event Deposit(address _addr, uint _amount); - function deposit() returns (uint) { + function deposit() public returns (uint) { emit Deposit(); return 1; } - function deposit(address _addr) returns (uint) { + function deposit(address _addr) public returns (uint) { emit Deposit(_addr); return 1; } - function deposit(address _addr, uint _amount) returns (uint) { + function deposit(address _addr, uint _amount) public returns (uint) { emit Deposit(_addr, _amount); return 1; } @@ -3424,8 +3569,8 @@ BOOST_AUTO_TEST_CASE(event_anonymous) char const* sourceCode = R"( contract ClientReceipt { event Deposit() anonymous; - function deposit() { - Deposit(); + function deposit() public { + emit Deposit(); } } )"; @@ -3440,7 +3585,7 @@ BOOST_AUTO_TEST_CASE(event_anonymous_with_topics) contract ClientReceipt { event Deposit(address indexed _from, bytes32 indexed _id, uint indexed _value, uint indexed _value2, bytes32 data) anonymous; function deposit(bytes32 _id) payable { - Deposit(msg.sender, _id, msg.value, 2, "abc"); + emit Deposit(msg.sender, _id, msg.value, 2, "abc"); } } )"; @@ -3464,7 +3609,7 @@ BOOST_AUTO_TEST_CASE(event_lots_of_data) contract ClientReceipt { event Deposit(address _from, bytes32 _id, uint _value, bool _flag); function deposit(bytes32 _id) payable { - Deposit(msg.sender, _id, msg.value, true); + emit Deposit(msg.sender, _id, msg.value, true); } } )"; @@ -3484,8 +3629,8 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data) char const* sourceCode = R"( contract ClientReceipt { event Deposit(uint fixeda, bytes dynx, uint fixedb); - function deposit() { - Deposit(10, msg.data, 15); + function deposit() public { + emit Deposit(10, msg.data, 15); } } )"; @@ -3493,7 +3638,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data) callContractFunction("deposit()"); BOOST_REQUIRE_EQUAL(m_logs.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); - BOOST_CHECK_EQUAL(toHex(m_logs[0].data), toHex(encodeArgs(10, 0x60, 15, 4) + FixedHash<4>(dev::keccak256("deposit()")).asBytes())); + BOOST_CHECK_EQUAL(toHex(m_logs[0].data), toHex(encodeArgs(10, 0x60, 15, 4, asString(FixedHash<4>(dev::keccak256("deposit()")).asBytes())))); BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(uint256,bytes,uint256)"))); } @@ -3504,12 +3649,12 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data_from_storage) contract ClientReceipt { bytes x; event Deposit(uint fixeda, bytes dynx, uint fixedb); - function deposit() { + function deposit() public { x.length = 3; x[0] = "A"; x[1] = "B"; x[2] = "C"; - Deposit(10, x, 15); + emit Deposit(10, x, 15); } } )"; @@ -3528,13 +3673,13 @@ BOOST_AUTO_TEST_CASE(event_really_really_lots_of_data_from_storage) contract ClientReceipt { bytes x; event Deposit(uint fixeda, bytes dynx, uint fixedb); - function deposit() { + function deposit() public { x.length = 31; x[0] = "A"; x[1] = "B"; x[2] = "C"; x[30] = "Z"; - Deposit(10, x, 15); + emit Deposit(10, x, 15); } } )"; @@ -3554,7 +3699,7 @@ BOOST_AUTO_TEST_CASE(event_indexed_string) string x; uint[4] y; event E(string indexed r, uint[4] indexed t); - function deposit() { + function deposit() public { bytes(x).length = 90; for (uint8 i = 0; i < 90; i++) bytes(x)[i] = byte(i); @@ -3562,7 +3707,7 @@ BOOST_AUTO_TEST_CASE(event_indexed_string) y[1] = 5; y[2] = 6; y[3] = 7; - E(x, y); + emit E(x, y); } } )"; @@ -3586,7 +3731,7 @@ BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one) { char const* sourceCode = R"( contract test { - function f(uint, uint k) returns(uint ret_k, uint ret_g){ + function f(uint, uint k) public returns(uint ret_k, uint ret_g){ uint g = 8; ret_k = k; ret_g = g; @@ -3602,7 +3747,7 @@ BOOST_AUTO_TEST_CASE(empty_name_return_parameter) { char const* sourceCode = R"( contract test { - function f(uint k) returns(uint){ + function f(uint k) public returns(uint){ return k; } } @@ -3615,8 +3760,8 @@ BOOST_AUTO_TEST_CASE(sha256_empty) { char const* sourceCode = R"( contract C { - function f() returns (bytes32) { - return sha256(); + function f() public returns (bytes32) { + return sha256(""); } } )"; @@ -3628,8 +3773,8 @@ BOOST_AUTO_TEST_CASE(ripemd160_empty) { char const* sourceCode = R"( contract C { - function f() returns (bytes20) { - return ripemd160(); + function f() public returns (bytes20) { + return ripemd160(""); } } )"; @@ -3641,8 +3786,8 @@ BOOST_AUTO_TEST_CASE(keccak256_empty) { char const* sourceCode = R"( contract C { - function f() returns (bytes32) { - return keccak256(); + function f() public returns (bytes32) { + return keccak256(""); } } )"; @@ -3654,9 +3799,9 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments) { char const* sourceCode = R"( contract c { - function foo(uint a, uint b, uint c) returns (bytes32 d) + function foo(uint a, uint b, uint c) public returns (bytes32 d) { - d = keccak256(a, b, c); + d = keccak256(abi.encodePacked(a, b, c)); } } )"; @@ -3675,9 +3820,9 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_numeric_literals) { char const* sourceCode = R"( contract c { - function foo(uint a, uint16 b) returns (bytes32 d) + function foo(uint a, uint16 b) public returns (bytes32 d) { - d = keccak256(a, b, 145); + d = keccak256(abi.encodePacked(a, b, uint8(145))); } } )"; @@ -3696,13 +3841,13 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_string_literals) { char const* sourceCode = R"( contract c { - function foo() returns (bytes32 d) + function foo() public returns (bytes32 d) { d = keccak256("foo"); } - function bar(uint a, uint16 b) returns (bytes32 d) + function bar(uint a, uint16 b) public returns (bytes32 d) { - d = keccak256(a, b, 145, "foo"); + d = keccak256(abi.encodePacked(a, b, uint8(145), "foo")); } } )"; @@ -3725,7 +3870,7 @@ BOOST_AUTO_TEST_CASE(keccak256_with_bytes) char const* sourceCode = R"( contract c { bytes data; - function foo() returns (bool) + function foo() public returns (bool) { data.length = 3; data[0] = "f"; @@ -3741,46 +3886,25 @@ BOOST_AUTO_TEST_CASE(keccak256_with_bytes) BOOST_AUTO_TEST_CASE(iterated_keccak256_with_bytes) { - char const* sourceCode = R"( + char const* sourceCode = R"ABC( contract c { bytes data; - function foo() returns (bytes32) + function foo() public returns (bytes32) { data.length = 3; data[0] = "x"; data[1] = "y"; data[2] = "z"; - return keccak256("b", keccak256(data), "a"); + return keccak256(abi.encodePacked("b", keccak256(data), "a")); } } - )"; + )ABC"; compileAndRun(sourceCode); ABI_CHECK(callContractFunction("foo()"), encodeArgs( u256(dev::keccak256(bytes{'b'} + dev::keccak256("xyz").asBytes() + bytes{'a'})) )); } -BOOST_AUTO_TEST_CASE(sha3_multiple_arguments) -{ - char const* sourceCode = R"( - contract c { - function foo(uint a, uint b, uint c) returns (bytes32 d) - { - d = sha3(a, b, c); - } - } - )"; - compileAndRun(sourceCode); - - ABI_CHECK(callContractFunction("foo(uint256,uint256,uint256)", 10, 12, 13), encodeArgs( - dev::keccak256( - toBigEndian(u256(10)) + - toBigEndian(u256(12)) + - toBigEndian(u256(13)) - ) - )); -} - BOOST_AUTO_TEST_CASE(generic_call) { char const* sourceCode = R"**( @@ -3789,11 +3913,11 @@ BOOST_AUTO_TEST_CASE(generic_call) function receive(uint256 x) payable { received = x; } } contract sender { - function sender() payable {} - function doSend(address rec) returns (uint d) + constructor() public payable {} + function doSend(address rec) public returns (uint d) { bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); - rec.call.value(2)(signature, 23); + rec.call.value(2)(abi.encodeWithSelector(signature, 23)); return receiver(rec).received(); } } @@ -3805,38 +3929,6 @@ BOOST_AUTO_TEST_CASE(generic_call) BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 50 - 2); } -BOOST_AUTO_TEST_CASE(generic_callcode) -{ - char const* sourceCode = R"**( - contract Receiver { - uint public received; - function receive(uint256 x) payable { received = x; } - } - contract Sender { - uint public received; - function Sender() payable { } - function doSend(address rec) returns (uint d) - { - bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); - rec.callcode.value(2)(signature, 23); - return Receiver(rec).received(); - } - } - )**"; - compileAndRun(sourceCode, 0, "Receiver"); - u160 const c_receiverAddress = m_contractAddress; - compileAndRun(sourceCode, 50, "Sender"); - u160 const c_senderAddress = m_contractAddress; - ABI_CHECK(callContractFunction("doSend(address)", c_receiverAddress), encodeArgs(0)); - ABI_CHECK(callContractFunction("received()"), encodeArgs(23)); - m_contractAddress = c_receiverAddress; - ABI_CHECK(callContractFunction("received()"), encodeArgs(0)); - BOOST_CHECK(storageEmpty(c_receiverAddress)); - BOOST_CHECK(!storageEmpty(c_senderAddress)); - BOOST_CHECK_EQUAL(balanceAt(c_receiverAddress), 0); - BOOST_CHECK_EQUAL(balanceAt(c_senderAddress), 50); -} - BOOST_AUTO_TEST_CASE(generic_delegatecall) { char const* sourceCode = R"**( @@ -3844,18 +3936,18 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall) uint public received; address public sender; uint public value; - function Receiver() payable {} + constructor() payable {} function receive(uint256 x) payable { received = x; sender = msg.sender; value = msg.value; } } contract Sender { uint public received; address public sender; uint public value; - function Sender() payable {} + constructor() payable {} function doSend(address rec) payable { bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)"))); - if (rec.delegatecall(signature, 23)) {} + if (rec.delegatecall(abi.encodeWithSelector(signature, 23))) {} } } )**"; @@ -3881,10 +3973,10 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall) BOOST_AUTO_TEST_CASE(library_call_in_homestead) { char const* sourceCode = R"( - library Lib { function m() returns (address) { return msg.sender; } } + library Lib { function m() public returns (address) { return msg.sender; } } contract Test { address public sender; - function f() { + function f() public { sender = Lib.m(); } } @@ -3933,7 +4025,7 @@ BOOST_AUTO_TEST_CASE(store_bytes) // this test just checks that the copy loop does not mess up the stack char const* sourceCode = R"( contract C { - function save() returns (uint r) { + function save() public returns (uint r) { r = 23; savedData = msg.data; r = 24; @@ -3951,14 +4043,15 @@ BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory) { char const* sourceCode = R"( contract C { - function f() returns (bytes32) { - return keccak256("abc", msg.data); + function f() public returns (bytes32) { + return keccak256(abi.encodePacked("abc", msg.data)); } } )"; compileAndRun(sourceCode); bytes calldata1 = FixedHash<4>(dev::keccak256("f()")).asBytes() + bytes(61, 0x22) + bytes(12, 0x12); sendMessage(calldata1, false); + BOOST_CHECK(m_transactionSuccessful); BOOST_CHECK(m_output == encodeArgs(dev::keccak256(bytes{'a', 'b', 'c'} + calldata1))); } @@ -3967,15 +4060,15 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes) char const* sourceCode = R"( contract receiver { uint public received; - function receive(uint x) { received += x + 1; } - function() { received = 0x80; } + function receive(uint x) public { received += x + 1; } + function() external { received = 0x80; } } contract sender { - function sender() { rec = new receiver(); } - function() { savedData = msg.data; } - function forward() returns (bool) { !rec.call(savedData); return true; } - function clear() returns (bool) { delete savedData; return true; } - function val() returns (uint) { return rec.received(); } + constructor() public { rec = new receiver(); } + function() external { savedData = msg.data; } + function forward() public returns (bool) { !rec.call(savedData); return true; } + function clear() public returns (bool) { delete savedData; return true; } + function val() public returns (uint) { return rec.received(); } receiver rec; bytes savedData; } @@ -3996,22 +4089,22 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) char const* sourceCode = R"( contract receiver { uint public calledLength; - function() { calledLength = msg.data.length; } + function() external { calledLength = msg.data.length; } } contract sender { receiver rec; - constructor() { rec = new receiver(); } - function viaCalldata() returns (uint) { + constructor() public { rec = new receiver(); } + function viaCalldata() public returns (uint) { require(rec.call(msg.data)); return rec.calledLength(); } - function viaMemory() returns (uint) { + function viaMemory() public returns (uint) { bytes memory x = msg.data; require(rec.call(x)); return rec.calledLength(); } bytes s; - function viaStorage() returns (uint) { + function viaStorage() public returns (uint) { s = msg.data; require(rec.call(s)); return rec.calledLength(); @@ -4022,18 +4115,14 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) // No additional data, just function selector ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(4)); - ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(0x20)); - // Should be this with 0.5.0: encodeArgs(4)); - ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(0x20)); - // Should be this with 0.5.0: encodeArgs(4)); + ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(4)); + ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(4)); // Some additional unpadded data bytes unpadded = asBytes(string("abc")); ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(7)); - ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(0x20)); - // Should be this with 0.5.0: encodeArgs(7)); - ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(0x20)); - // Should be this with 0.5.0: encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(7)); } BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) @@ -4042,17 +4131,17 @@ BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) contract receiver { uint public received; function receive(uint x) { received += x + 1; } - function() { received = 0x80; } + function() external { received = 0x80; } } contract sender { - function sender() { rec = new receiver(); } - function() { savedData1 = savedData2 = msg.data; } - function forward(bool selector) returns (bool) { + constructor() public { rec = new receiver(); } + function() external { savedData1 = savedData2 = msg.data; } + function forward(bool selector) public returns (bool) { if (selector) { rec.call(savedData1); delete savedData1; } else { rec.call(savedData2); delete savedData2; } return true; } - function val() returns (uint) { return rec.received(); } + function val() public returns (uint) { return rec.received(); } receiver rec; bytes savedData1; bytes savedData2; @@ -4073,8 +4162,8 @@ BOOST_AUTO_TEST_CASE(delete_removes_bytes_data) { char const* sourceCode = R"( contract c { - function() { data = msg.data; } - function del() returns (bool) { delete data; return true; } + function() external { data = msg.data; } + function del() public returns (bool) { delete data; return true; } bytes data; } )"; @@ -4089,8 +4178,8 @@ BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data) { char const* sourceCode = R"( contract c { - function set() returns (bool) { data = msg.data; return true; } - function() { data = msg.data; } + function set() public returns (bool) { data = msg.data; return true; } + function() external { data = msg.data; } bytes data; } )"; @@ -4098,7 +4187,8 @@ BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data) ABI_CHECK(callContractFunction("set()", 1, 2, 3, 4, 5), encodeArgs(true)); BOOST_CHECK(!storageEmpty(m_contractAddress)); sendMessage(bytes(), false); - BOOST_CHECK(m_output == bytes()); + BOOST_CHECK(m_transactionSuccessful); + BOOST_CHECK(m_output.empty()); BOOST_CHECK(storageEmpty(m_contractAddress)); } @@ -4106,8 +4196,8 @@ BOOST_AUTO_TEST_CASE(copy_removes_bytes_data) { char const* sourceCode = R"( contract c { - function set() returns (bool) { data1 = msg.data; return true; } - function reset() returns (bool) { data1 = data2; return true; } + function set() public returns (bool) { data1 = msg.data; return true; } + function reset() public returns (bool) { data1 = data2; return true; } bytes data1; bytes data2; } @@ -4123,8 +4213,8 @@ BOOST_AUTO_TEST_CASE(bytes_inside_mappings) { char const* sourceCode = R"( contract c { - function set(uint key) returns (bool) { data[key] = msg.data; return true; } - function copy(uint from, uint to) returns (bool) { data[to] = data[from]; return true; } + function set(uint key) public returns (bool) { data[key] = msg.data; return true; } + function copy(uint from, uint to) public returns (bool) { data[to] = data[from]; return true; } mapping(uint => bytes) data; } )"; @@ -4147,8 +4237,8 @@ BOOST_AUTO_TEST_CASE(bytes_length_member) { char const* sourceCode = R"( contract c { - function set() returns (bool) { data = msg.data; return true; } - function getLength() returns (uint) { return data.length; } + function set() public returns (bool) { data = msg.data; return true; } + function getLength() public returns (uint) { return data.length; } bytes data; } )"; @@ -4165,18 +4255,18 @@ BOOST_AUTO_TEST_CASE(struct_copy) struct Nested { uint x; uint y; } struct Struct { uint a; mapping(uint => Struct) b; Nested nested; uint c; } mapping(uint => Struct) data; - function set(uint k) returns (bool) { + function set(uint k) public returns (bool) { data[k].a = 1; data[k].nested.x = 3; data[k].nested.y = 4; data[k].c = 2; return true; } - function copy(uint from, uint to) returns (bool) { + function copy(uint from, uint to) public returns (bool) { data[to] = data[from]; return true; } - function retrieve(uint k) returns (uint a, uint x, uint y, uint c) + function retrieve(uint k) public returns (uint a, uint x, uint y, uint c) { a = data[k].a; x = data[k].nested.x; @@ -4211,11 +4301,11 @@ BOOST_AUTO_TEST_CASE(struct_containing_bytes_copy_and_delete) data1.data = _data; return true; } - function copy() returns (bool) { + function copy() public returns (bool) { data1 = data2; return true; } - function del() returns (bool) { + function del() public returns (bool) { delete data1; return true; } @@ -4241,10 +4331,10 @@ BOOST_AUTO_TEST_CASE(struct_copy_via_local) struct Struct { uint a; uint b; } Struct data1; Struct data2; - function test() returns (bool) { + function test() public returns (bool) { data1.a = 1; data1.b = 2; - var x = data1; + Struct memory x = data1; data2 = x; return data2.a == data1.a && data2.b == data1.b; } @@ -4259,11 +4349,11 @@ BOOST_AUTO_TEST_CASE(using_enums) char const* sourceCode = R"( contract test { enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test() + constructor() { choices = ActionChoices.GoStraight; } - function getChoice() returns (uint d) + function getChoice() public returns (uint d) { d = uint256(choices); } @@ -4279,20 +4369,20 @@ BOOST_AUTO_TEST_CASE(enum_explicit_overflow) char const* sourceCode = R"( contract test { enum ActionChoices { GoLeft, GoRight, GoStraight } - function test() + constructor() { } - function getChoiceExp(uint x) returns (uint d) + function getChoiceExp(uint x) public returns (uint d) { choice = ActionChoices(x); d = uint256(choice); } - function getChoiceFromSigned(int x) returns (uint d) + function getChoiceFromSigned(int x) public returns (uint d) { choice = ActionChoices(x); d = uint256(choice); } - function getChoiceFromNegativeLiteral() returns (uint d) + function getChoiceFromNegativeLiteral() public returns (uint d) { choice = ActionChoices(-1); d = uint256(choice); @@ -4316,7 +4406,7 @@ BOOST_AUTO_TEST_CASE(storing_invalid_boolean) contract C { event Ev(bool); bool public perm; - function set() returns(uint) { + function set() public returns(uint) { bool tmp; assembly { tmp := 5 @@ -4324,19 +4414,19 @@ BOOST_AUTO_TEST_CASE(storing_invalid_boolean) perm = tmp; return 1; } - function ret() returns(bool) { + function ret() public returns(bool) { bool tmp; assembly { tmp := 5 } return tmp; } - function ev() returns(uint) { + function ev() public returns(uint) { bool tmp; assembly { tmp := 5 } - Ev(tmp); + emit Ev(tmp); return 1; } } @@ -4359,7 +4449,7 @@ BOOST_AUTO_TEST_CASE(using_contract_enums_with_explicit_contract_name) char const* sourceCode = R"( contract test { enum Choice { A, B, C } - function answer () returns (test.Choice _ret) + function answer () public returns (test.Choice _ret) { _ret = test.Choice.B; } @@ -4377,7 +4467,7 @@ BOOST_AUTO_TEST_CASE(using_inherited_enum) } contract test is base { - function answer () returns (Choice _ret) + function answer () public returns (Choice _ret) { _ret = Choice.B; } @@ -4395,7 +4485,7 @@ BOOST_AUTO_TEST_CASE(using_inherited_enum_excplicitly) } contract test is base { - function answer () returns (base.Choice _ret) + function answer () public returns (base.Choice _ret) { _ret = base.Choice.B; } @@ -4410,7 +4500,7 @@ BOOST_AUTO_TEST_CASE(constructing_enums_from_ints) char const* sourceCode = R"( contract c { enum Truth { False, True } - function test() returns (uint) + function test() public returns (uint) { return uint(Truth(uint8(0x701))); } @@ -4424,14 +4514,14 @@ BOOST_AUTO_TEST_CASE(inline_member_init) { char const* sourceCode = R"( contract test { - function test(){ + constructor(){ m_b = 6; m_c = 8; } uint m_a = 5; uint m_b; uint m_c = 7; - function get() returns (uint a, uint b, uint c){ + function get() public returns (uint a, uint b, uint c){ a = m_a; b = m_b; c = m_c; @@ -4446,14 +4536,14 @@ BOOST_AUTO_TEST_CASE(inline_member_init_inheritence) { char const* sourceCode = R"( contract Base { - function Base(){} + constructor(){} uint m_base = 5; - function getBMember() returns (uint i) { return m_base; } + function getBMember() public returns (uint i) { return m_base; } } contract Derived is Base { - function Derived(){} + constructor(){} uint m_derived = 6; - function getDMember() returns (uint i) { return m_derived; } + function getDMember() public returns (uint i) { return m_derived; } } )"; compileAndRun(sourceCode); @@ -4466,11 +4556,11 @@ BOOST_AUTO_TEST_CASE(inline_member_init_inheritence_without_constructor) char const* sourceCode = R"( contract Base { uint m_base = 5; - function getBMember() returns (uint i) { return m_base; } + function getBMember() public returns (uint i) { return m_base; } } contract Derived is Base { uint m_derived = 6; - function getDMember() returns (uint i) { return m_derived; } + function getDMember() public returns (uint i) { return m_derived; } } )"; compileAndRun(sourceCode); @@ -4482,7 +4572,7 @@ BOOST_AUTO_TEST_CASE(external_function) { char const* sourceCode = R"( contract c { - function f(uint a) returns (uint) { return a; } + function f(uint a) public returns (uint) { return a; } function test(uint a, uint b) external returns (uint r_a, uint r_b) { r_a = f(a + 7); r_b = b; @@ -4534,9 +4624,9 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_in_storage) function setIDStatic(uint id) { ids[2] = id; } function setID(uint index, uint id) { ids[index] = id; } function setData(uint index, uint x, uint y) { data[index].x = x; data[index].y = y; } - function getID(uint index) returns (uint) { return ids[index]; } - function getData(uint index) returns (uint x, uint y) { x = data[index].x; y = data[index].y; } - function getLengths() returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } + function getID(uint index) public returns (uint) { return ids[index]; } + function getData(uint index) public returns (uint x, uint y) { x = data[index].x; y = data[index].y; } + function getLengths() public returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } } )"; compileAndRun(sourceCode); @@ -4561,9 +4651,9 @@ BOOST_AUTO_TEST_CASE(dynamic_arrays_in_storage) function setIDStatic(uint id) { ids[2] = id; } function setID(uint index, uint id) { ids[index] = id; } function setData(uint index, uint x, uint y) { data[index].x = x; data[index].y = y; } - function getID(uint index) returns (uint) { return ids[index]; } - function getData(uint index) returns (uint x, uint y) { x = data[index].x; y = data[index].y; } - function getLengths() returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } + function getID(uint index) public returns (uint) { return ids[index]; } + function getData(uint index) public returns (uint x, uint y) { x = data[index].x; y = data[index].y; } + function getLengths() public returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } function setLengths(uint l1, uint l2) { data.length = l1; ids.length = l2; } } )"; @@ -4586,9 +4676,9 @@ BOOST_AUTO_TEST_CASE(fixed_out_of_bounds_array_access) char const* sourceCode = R"( contract c { uint[4] data; - function set(uint index, uint value) returns (bool) { data[index] = value; return true; } - function get(uint index) returns (uint) { return data[index]; } - function length() returns (uint) { return data.length; } + function set(uint index, uint value) public returns (bool) { data[index] = value; return true; } + function get(uint index) public returns (uint) { return data[index]; } + function length() public returns (uint) { return data.length; } } )"; compileAndRun(sourceCode); @@ -4607,10 +4697,10 @@ BOOST_AUTO_TEST_CASE(dynamic_out_of_bounds_array_access) char const* sourceCode = R"( contract c { uint[] data; - function enlarge(uint amount) returns (uint) { return data.length += amount; } - function set(uint index, uint value) returns (bool) { data[index] = value; return true; } - function get(uint index) returns (uint) { return data[index]; } - function length() returns (uint) { return data.length; } + function enlarge(uint amount) public returns (uint) { return data.length += amount; } + function set(uint index, uint value) public returns (bool) { data[index] = value; return true; } + function get(uint index) public returns (uint) { return data[index]; } + function length() public returns (uint) { return data.length; } } )"; compileAndRun(sourceCode); @@ -4632,10 +4722,10 @@ BOOST_AUTO_TEST_CASE(fixed_array_cleanup) uint spacer1; uint spacer2; uint[20] data; - function fill() { + function fill() public { for (uint i = 0; i < data.length; ++i) data[i] = i+1; } - function clear() { delete data; } + function clear() public { delete data; } } )"; compileAndRun(sourceCode); @@ -4653,10 +4743,10 @@ BOOST_AUTO_TEST_CASE(short_fixed_array_cleanup) uint spacer1; uint spacer2; uint[3] data; - function fill() { + function fill() public { for (uint i = 0; i < data.length; ++i) data[i] = i+1; } - function clear() { delete data; } + function clear() public { delete data; } } )"; compileAndRun(sourceCode); @@ -4673,12 +4763,12 @@ BOOST_AUTO_TEST_CASE(dynamic_array_cleanup) contract c { uint[20] spacer; uint[] dynamic; - function fill() { + function fill() public { dynamic.length = 21; for (uint i = 0; i < dynamic.length; ++i) dynamic[i] = i+1; } - function halfClear() { dynamic.length = 5; } - function fullClear() { delete dynamic; } + function halfClear() public { dynamic.length = 5; } + function fullClear() public { delete dynamic; } } )"; compileAndRun(sourceCode); @@ -4697,14 +4787,14 @@ BOOST_AUTO_TEST_CASE(dynamic_multi_array_cleanup) contract c { struct s { uint[][] d; } s[] data; - function fill() returns (uint) { + function fill() public returns (uint) { data.length = 3; data[2].d.length = 4; data[2].d[3].length = 5; data[2].d[3][4] = 8; return data[2].d[3][4]; } - function clear() { delete data; } + function clear() public { delete data; } } )"; compileAndRun(sourceCode); @@ -4724,8 +4814,8 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_storage_dyn_dyn) function setData1(uint length, uint index, uint value) { data1.length = length; if (index < length) data1[index] = value; } - function copyStorageStorage() { data2 = data1; } - function getData2(uint index) returns (uint len, uint val) { + function copyStorageStorage() public { data2 = data1; } + function getData2(uint index) public returns (uint len, uint val) { len = data2.length; if (index < len) val = data2[index]; } } @@ -4746,7 +4836,7 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_storage_static_static) contract c { uint[40] data1; uint[20] data2; - function test() returns (uint x, uint y){ + function test() public returns (uint x, uint y){ data1[30] = 4; data1[2] = 7; data1[3] = 9; @@ -4767,7 +4857,7 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_storage_static_dynamic) contract c { uint[9] data1; uint[] data2; - function test() returns (uint x, uint y){ + function test() public returns (uint x, uint y){ data1[8] = 4; data2 = data1; x = data2.length; @@ -4785,7 +4875,7 @@ BOOST_AUTO_TEST_CASE(array_copy_different_packing) contract c { bytes8[] data1; // 4 per slot bytes10[] data2; // 3 per slot - function test() returns (bytes10 a, bytes10 b, bytes10 c, bytes10 d, bytes10 e) { + function test() public returns (bytes10 a, bytes10 b, bytes10 c, bytes10 d, bytes10 e) { data1.length = 9; for (uint i = 0; i < data1.length; ++i) data1[i] = bytes8(uint64(i)); @@ -4814,7 +4904,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_simple) contract c { bytes8[9] data1; // 4 per slot bytes17[10] data2; // 1 per slot, no offset counter - function test() returns (bytes17 a, bytes17 b, bytes17 c, bytes17 d, bytes17 e) { + function test() public returns (bytes17 a, bytes17 b, bytes17 c, bytes17 d, bytes17 e) { for (uint i = 0; i < data1.length; ++i) data1[i] = bytes8(uint64(i)); data2[8] = data2[9] = 2; @@ -4844,7 +4934,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover) contract c { byte[10] data1; bytes2[32] data2; - function test() returns (uint check, uint res1, uint res2) { + function test() public returns (uint check, uint res1, uint res2) { uint i; for (i = 0; i < data2.length; ++i) data2[i] = 0xffff; @@ -4875,7 +4965,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover2) contract c { bytes8[4] data1; // fits into one slot bytes10[6] data2; // 4 elements need two slots - function test() returns (bytes10 r1, bytes10 r2, bytes10 r3) { + function test() public returns (bytes10 r1, bytes10 r2, bytes10 r3) { data1[0] = 1; data1[1] = 2; data1[2] = 3; @@ -4904,7 +4994,7 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_storage_struct) struct Data { uint x; uint y; } Data[] data1; Data[] data2; - function test() returns (uint x, uint y) { + function test() public returns (uint x, uint y) { data1.length = 9; data1[8].x = 4; data1[8].y = 5; @@ -4932,22 +5022,22 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_abi) uint16[] y; uint24[] z; uint24[][] w; - function test1() returns (uint8[]) { + function test1() public returns (uint8[]) { for (uint i = 0; i < 101; ++i) x.push(uint8(i)); return x; } - function test2() returns (uint16[]) { + function test2() public returns (uint16[]) { for (uint i = 0; i < 101; ++i) y.push(uint16(i)); return y; } - function test3() returns (uint24[]) { + function test3() public returns (uint24[]) { for (uint i = 0; i < 101; ++i) z.push(uint24(i)); return z; } - function test4() returns (uint24[][]) { + function test4() public returns (uint24[][]) { w.length = 5; for (uint i = 0; i < 5; ++i) for (uint j = 0; j < 101; ++j) @@ -4980,7 +5070,7 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_abi_signed) char const* sourceCode = R"( contract c { int16[] x; - function test() returns (int16[]) { + function test() public returns (int16[]) { x.push(int16(-1)); x.push(int16(-1)); x.push(int16(8)); @@ -5012,7 +5102,7 @@ BOOST_AUTO_TEST_CASE(array_push) char const* sourceCode = R"( contract c { uint[] data; - function test() returns (uint x, uint y, uint z, uint l) { + function test() public returns (uint x, uint y, uint z, uint l) { data.push(5); x = data[0]; data.push(4); @@ -5032,7 +5122,7 @@ BOOST_AUTO_TEST_CASE(array_push_struct) contract c { struct S { uint16 a; uint16 b; uint16[3] c; uint16[] d; } S[] data; - function test() returns (uint16, uint16, uint16, uint16) { + function test() public returns (uint16, uint16, uint16, uint16) { S memory s; s.a = 2; s.b = 3; @@ -5053,7 +5143,7 @@ BOOST_AUTO_TEST_CASE(array_push_packed_array) char const* sourceCode = R"( contract c { uint80[] x; - function test() returns (uint80, uint80, uint80, uint80) { + function test() public returns (uint80, uint80, uint80, uint80) { x.push(1); x.push(2); x.push(3); @@ -5073,7 +5163,7 @@ BOOST_AUTO_TEST_CASE(byte_array_push) char const* sourceCode = R"( contract c { bytes data; - function test() returns (bool x) { + function test() public returns (bool x) { if (data.push(5) != 1) return true; if (data[0] != 5) return true; data.push(4); @@ -5094,14 +5184,14 @@ BOOST_AUTO_TEST_CASE(byte_array_push_transition) char const* sourceCode = R"( contract c { bytes data; - function test() returns (uint) { + function test() public returns (uint) { for (uint8 i = 1; i < 40; i++) { data.push(byte(i)); if (data.length != i) return 0x1000 + i; if (data[data.length - 1] != byte(i)) return i; } - for (i = 1; i < 40; i++) + for (uint8 i = 1; i < 40; i++) if (data[i - 1] != byte(i)) return 0x1000000 + i; return 0; } @@ -5111,6 +5201,326 @@ BOOST_AUTO_TEST_CASE(byte_array_push_transition) ABI_CHECK(callContractFunction("test()"), encodeArgs(0)); } +BOOST_AUTO_TEST_CASE(array_pop) +{ + char const* sourceCode = R"( + contract c { + uint[] data; + function test() public returns (uint x, uint l) { + data.push(7); + x = data.push(3); + data.pop(); + x = data.length; + data.pop(); + l = data.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(1, 0)); +} + +BOOST_AUTO_TEST_CASE(array_pop_uint16_transition) +{ + char const* sourceCode = R"( + contract c { + uint16[] data; + function test() public returns (uint16 x, uint16 y, uint16 z) { + for (uint i = 1; i <= 48; i++) + data.push(uint16(i)); + for (uint j = 1; j <= 10; j++) + data.pop(); + x = data[data.length - 1]; + for (uint k = 1; k <= 10; k++) + data.pop(); + y = data[data.length - 1]; + for (uint l = 1; l <= 10; l++) + data.pop(); + z = data[data.length - 1]; + for (uint m = 1; m <= 18; m++) + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(38, 28, 18)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(array_pop_uint24_transition) +{ + char const* sourceCode = R"( + contract c { + uint256 a; + uint256 b; + uint256 c; + uint24[] data; + function test() public returns (uint24 x, uint24 y) { + for (uint i = 1; i <= 30; i++) + data.push(uint24(i)); + for (uint j = 1; j <= 10; j++) + data.pop(); + x = data[data.length - 1]; + for (uint k = 1; k <= 10; k++) + data.pop(); + y = data[data.length - 1]; + for (uint l = 1; l <= 10; l++) + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(20, 10)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(array_pop_array_transition) +{ + char const* sourceCode = R"( + contract c { + uint256 a; + uint256 b; + uint256 c; + uint16[] inner = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; + uint16[][] data; + function test() public returns (uint x, uint y, uint z) { + for (uint i = 1; i <= 48; i++) + data.push(inner); + for (uint j = 1; j <= 10; j++) + data.pop(); + x = data[data.length - 1][0]; + for (uint k = 1; k <= 10; k++) + data.pop(); + y = data[data.length - 1][1]; + for (uint l = 1; l <= 10; l++) + data.pop(); + z = data[data.length - 1][2]; + for (uint m = 1; m <= 18; m++) + data.pop(); + delete inner; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(1, 2, 3)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(array_pop_empty_exception) +{ + char const* sourceCode = R"( + contract c { + uint[] data; + function test() public returns (bool) { + data.pop(); + return true; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); +} + +BOOST_AUTO_TEST_CASE(array_pop_storage_empty) +{ + char const* sourceCode = R"( + contract c { + uint[] data; + function test() public { + data.push(7); + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (uint x, uint y, uint l) { + data.push(7); + x = data.push(3); + data.pop(); + data.pop(); + y = data.push(2); + l = data.length; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 1, 1)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_empty_exception) +{ + char const* sourceCode = R"( + contract c { + uint256 a; + uint256 b; + uint256 c; + bytes data; + function test() public returns (bool) { + data.pop(); + return true; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public { + data.push(7); + data.push(5); + data.push(3); + data.pop(); + data.pop(); + data.pop(); + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_long_storage_empty) +{ + char const* sourceCode = R"( + contract c { + uint256 a; + uint256 b; + uint256 c; + bytes data; + function test() public returns (bool) { + for (uint8 i = 0; i <= 40; i++) + data.push(byte(i+1)); + for (int8 j = 40; j >= 0; j--) { + require(data[uint8(j)] == byte(j+1)); + require(data.length == uint8(j+1)); + data.pop(); + } + return true; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(true)); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_long_storage_empty_garbage_ref) +{ + char const* sourceCode = R"( + contract c { + uint256 a; + uint256 b; + bytes data; + function test() public { + for (uint8 i = 0; i <= 40; i++) + data.push(3); + for (uint8 j = 0; j <= 40; j++) { + assembly { + mstore(0, "garbage") + } + data.pop(); + } + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs()); + BOOST_CHECK(storageEmpty(m_contractAddress)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_masking_long) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (bytes) { + for (uint i = 0; i < 34; i++) + data.push(3); + data.pop(); + return data; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs( + u256(0x20), + u256(33), + asString(fromHex("0303030303030303030303030303030303030303030303030303030303030303")), + asString(fromHex("03")) + )); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_copy_long) +{ + char const* sourceCode = R"( + contract c { + bytes data; + function test() public returns (bytes) { + for (uint i = 0; i < 33; i++) + data.push(3); + for (uint j = 0; j < 4; j++) + data.pop(); + return data; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs( + u256(0x20), + u256(29), + asString(fromHex("0303030303030303030303030303030303030303030303030303030303")) + )); +} + +BOOST_AUTO_TEST_CASE(array_pop_isolated) +{ + char const* sourceCode = R"( + // This tests that the compiler knows the correct size of the function on the stack. + contract c { + uint[] data; + function test() public returns (uint x) { + x = 2; + data.pop; + x = 3; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(3)); +} + +BOOST_AUTO_TEST_CASE(byte_array_pop_isolated) +{ + char const* sourceCode = R"( + // This tests that the compiler knows the correct size of the function on the stack. + contract c { + bytes data; + function test() public returns (uint x) { + x = 2; + data.pop; + x = 3; + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("test()"), encodeArgs(3)); +} + BOOST_AUTO_TEST_CASE(external_array_args) { char const* sourceCode = R"( @@ -5204,7 +5614,7 @@ BOOST_AUTO_TEST_CASE(array_copy_calldata_storage) m_byte_data = b; return b[3][1]; // note that access and declaration are reversed to each other } - function retrieve() returns (uint a, uint b, uint c, uint d, uint e, uint f, uint g) { + function retrieve() public returns (uint a, uint b, uint c, uint d, uint e, uint f, uint g) { a = m_data.length; b = m_data[7]; c = m_data_dyn.length; @@ -5260,7 +5670,7 @@ BOOST_AUTO_TEST_CASE(array_copy_including_mapping) contract c { mapping(uint=>uint)[90][] large; mapping(uint=>uint)[3][] small; - function test() returns (uint r) { + function test() public returns (uint r) { large.length = small.length = 7; large[3][2][0] = 2; large[1] = large[3]; @@ -5274,7 +5684,7 @@ BOOST_AUTO_TEST_CASE(array_copy_including_mapping) delete small; delete large; } - function clear() returns (uint r) { + function clear() public returns (uint r) { large.length = small.length = 7; small[3][2][0] = 0; large[3][2][0] = 0; @@ -5303,11 +5713,11 @@ BOOST_AUTO_TEST_CASE(swap_in_storage_overwrite) struct S { uint a; uint b; } S public x; S public y; - function set() { + function set() public { x.a = 1; x.b = 2; y.a = 3; y.b = 4; } - function swap() { + function swap() public { (x, y) = (y, x); } } @@ -5327,14 +5737,14 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base) { char const* sourceCode = R"( contract Base { - function Base(uint i) + constructor(uint i) { m_i = i; } uint public m_i; } contract Derived is Base { - function Derived(uint i) Base(i) + constructor(uint i) Base(i) {} } contract Final is Derived(4) { @@ -5348,17 +5758,17 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base) { char const* sourceCode = R"( contract Base { - function Base(uint j) + constructor(uint j) public { m_i = j; } uint public m_i; } contract Base1 is Base { - function Base1(uint k) Base(k*k) {} + constructor(uint k) Base(k) public {} } contract Derived is Base, Base1 { - function Derived(uint i) Base(i) Base1(i) + constructor(uint i) Base1(i) public {} } contract Final is Derived(4) { @@ -5372,15 +5782,17 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap) { char const* sourceCode = R"( contract Base { - function Base(uint i) + constructor(uint i) { m_i = i; } uint public m_i; } - contract Base1 is Base(3) {} + contract Base1 is Base { + constructor(uint k) {} + } contract Derived is Base, Base1 { - function Derived(uint i) Base(i) {} + constructor(uint i) Base(i) Base1(7) public {} } contract Final is Derived(4) { } @@ -5393,7 +5805,7 @@ BOOST_AUTO_TEST_CASE(simple_constant_variables_test) { char const* sourceCode = R"( contract Foo { - function getX() returns (uint r) { return x; } + function getX() public returns (uint r) { return x; } uint constant x = 56; } )"; @@ -5419,7 +5831,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_expression) char const* sourceCode = R"( contract C { uint constant x = 0x123 + 0x456; - function f() returns (uint) { return x + 1; } + function f() public returns (uint) { return x + 1; } } )"; compileAndRun(sourceCode); @@ -5431,7 +5843,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak) char const* sourceCode = R"( contract C { bytes32 constant x = keccak256("abc"); - function f() returns (bytes32) { return x; } + function f() public returns (bytes32) { return x; } } )"; compileAndRun(sourceCode); @@ -5445,7 +5857,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak) // contract C { // uint[3] constant x = [uint(1), 2, 3]; // uint constant y = x[0] + x[1] + x[2]; -// function f() returns (uint) { return y; } +// function f() public returns (uint) { return y; } // } // )"; // compileAndRun(sourceCode); @@ -5459,7 +5871,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak) // contract C { // struct S { uint x; uint[] y; } // S constant x = S(5, new uint[](4)); -// function f() returns (uint) { return x.x; } +// function f() public returns (uint) { return x.x; } // } // )"; // compileAndRun(sourceCode); @@ -5472,7 +5884,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_uint) contract C { struct str { uint8 a; uint16 b; uint248 c; } str data; - function test() returns (uint) { + function test() public returns (uint) { data.a = 2; if (data.a != 2) return 2; data.b = 0xabcd; @@ -5504,7 +5916,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_enum) enum larger { A, B, C, D, E} struct str { small a; small b; larger c; larger d; } str data; - function test() returns (uint) { + function test() public returns (uint) { data.a = small.B; if (data.a != small.B) return 2; data.b = small.C; @@ -5537,7 +5949,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_bytes) byte x; s2 data; byte y; - function test() returns (bool) { + function test() public returns (bool) { x = 1; data.a = 2; data.inner.a = 3; @@ -5566,7 +5978,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_delete) uint8 x; uint16 y; str data; - function test() returns (uint) { + function test() public returns (uint) { x = 1; y = 2; data.a = 2; @@ -5593,9 +6005,9 @@ BOOST_AUTO_TEST_CASE(overloaded_function_call_resolve_to_first) { char const* sourceCode = R"( contract test { - function f(uint k) returns(uint d) { return k; } - function f(uint a, uint b) returns(uint d) { return a + b; } - function g() returns(uint d) { return f(3); } + function f(uint k) public returns(uint d) { return k; } + function f(uint a, uint b) public returns(uint d) { return a + b; } + function g() public returns(uint d) { return f(3); } } )"; compileAndRun(sourceCode); @@ -5606,9 +6018,9 @@ BOOST_AUTO_TEST_CASE(overloaded_function_call_resolve_to_second) { char const* sourceCode = R"( contract test { - function f(uint a, uint b) returns(uint d) { return a + b; } - function f(uint k) returns(uint d) { return k; } - function g() returns(uint d) { return f(3, 7); } + function f(uint a, uint b) public returns(uint d) { return a + b; } + function f(uint k) public returns(uint d) { return k; } + function g() public returns(uint d) { return f(3, 7); } } )"; compileAndRun(sourceCode); @@ -5619,9 +6031,9 @@ BOOST_AUTO_TEST_CASE(overloaded_function_call_with_if_else) { char const* sourceCode = R"( contract test { - function f(uint a, uint b) returns(uint d) { return a + b; } - function f(uint k) returns(uint d) { return k; } - function g(bool flag) returns(uint d) { + function f(uint a, uint b) public returns(uint d) { return a + b; } + function f(uint k) public returns(uint d) { return k; } + function g(bool flag) public returns(uint d) { if (flag) return f(3); else @@ -5637,10 +6049,10 @@ BOOST_AUTO_TEST_CASE(overloaded_function_call_with_if_else) BOOST_AUTO_TEST_CASE(derived_overload_base_function_direct) { char const* sourceCode = R"( - contract B { function f() returns(uint) { return 10; } } + contract B { function f() public returns(uint) { return 10; } } contract C is B { - function f(uint i) returns(uint) { return 2 * i; } - function g() returns(uint) { return f(1); } + function f(uint i) public returns(uint) { return 2 * i; } + function g() public returns(uint) { return f(1); } } )"; compileAndRun(sourceCode, 0, "C"); @@ -5650,11 +6062,11 @@ BOOST_AUTO_TEST_CASE(derived_overload_base_function_direct) BOOST_AUTO_TEST_CASE(derived_overload_base_function_indirect) { char const* sourceCode = R"( - contract A { function f(uint a) returns(uint) { return 2 * a; } } - contract B { function f() returns(uint) { return 10; } } + contract A { function f(uint a) public returns(uint) { return 2 * a; } } + contract B { function f() public returns(uint) { return 10; } } contract C is A, B { - function g() returns(uint) { return f(); } - function h() returns(uint) { return f(1); } + function g() public returns(uint) { return f(); } + function h() public returns(uint) { return f(1); } } )"; compileAndRun(sourceCode, 0, "C"); @@ -5665,11 +6077,11 @@ BOOST_AUTO_TEST_CASE(derived_overload_base_function_indirect) BOOST_AUTO_TEST_CASE(super_overload) { char const* sourceCode = R"( - contract A { function f(uint a) returns(uint) { return 2 * a; } } - contract B { function f(bool b) returns(uint) { return 10; } } + contract A { function f(uint a) public returns(uint) { return 2 * a; } } + contract B { function f(bool b) public returns(uint) { return 10; } } contract C is A, B { - function g() returns(uint) { return super.f(true); } - function h() returns(uint) { return super.f(1); } + function g() public returns(uint) { return super.f(true); } + function h() public returns(uint) { return super.f(1); } } )"; compileAndRun(sourceCode, 0, "C"); @@ -5681,8 +6093,8 @@ BOOST_AUTO_TEST_CASE(gasleft_shadow_resolution) { char const* sourceCode = R"( contract C { - function gasleft() returns(uint256) { return 0; } - function f() returns(uint256) { return gasleft(); } + function gasleft() public returns(uint256) { return 0; } + function f() public returns(uint256) { return gasleft(); } } )"; compileAndRun(sourceCode, 0, "C"); @@ -5693,13 +6105,13 @@ BOOST_AUTO_TEST_CASE(bool_conversion) { char const* sourceCode = R"( contract C { - function f(bool _b) returns(uint) { + function f(bool _b) public returns(uint) { if (_b) return 1; else return 0; } - function g(bool _in) returns (bool _out) { + function g(bool _in) public returns (bool _out) { _out = _in; } } @@ -5725,7 +6137,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_signed) uint8 b; int8 c; uint8 d; - function test() returns (uint x1, uint x2, uint x3, uint x4) { + function test() public returns (uint x1, uint x2, uint x3, uint x4) { a = -2; b = -uint8(a) * 2; c = a * int8(120) * int8(121); @@ -5743,15 +6155,15 @@ BOOST_AUTO_TEST_CASE(packed_storage_signed) BOOST_AUTO_TEST_CASE(external_types_in_calls) { char const* sourceCode = R"( - contract C1 { C1 public bla; function C1(C1 x) { bla = x; } } + contract C1 { C1 public bla; constructor(C1 x) public { bla = x; } } contract C { - function test() returns (C1 x, C1 y) { + function test() public returns (C1 x, C1 y) { C1 c = new C1(C1(9)); x = c.bla(); y = this.t1(C1(7)); } - function t1(C1 a) returns (C1) { return a; } - function t2() returns (C1) { return C1(9); } + function t1(C1 a) public returns (C1) { return a; } + function t2() public returns (C1) { return C1(9); } } )"; compileAndRun(sourceCode, 0, "C"); @@ -5765,18 +6177,18 @@ BOOST_AUTO_TEST_CASE(invalid_enum_compared) contract C { enum X { A, B } - function test_eq() returns (bool) { + function test_eq() public returns (bool) { X garbled; assembly { garbled := 5 } return garbled == garbled; } - function test_eq_ok() returns (bool) { + function test_eq_ok() public returns (bool) { X garbled = X.A; return garbled == garbled; } - function test_neq() returns (bool) { + function test_neq() public returns (bool) { X garbled; assembly { garbled := 5 @@ -5799,17 +6211,17 @@ BOOST_AUTO_TEST_CASE(invalid_enum_logged) enum X { A, B } event Log(X); - function test_log() returns (uint) { + function test_log() public returns (uint) { X garbled = X.A; assembly { garbled := 5 } - Log(garbled); + emit Log(garbled); return 1; } - function test_log_ok() returns (uint) { + function test_log_ok() public returns (uint) { X x = X.A; - Log(x); + emit Log(x); return 1; } } @@ -5833,7 +6245,7 @@ BOOST_AUTO_TEST_CASE(invalid_enum_stored) enum X { A, B } X public x; - function test_store() returns (uint) { + function test_store() public returns (uint) { X garbled = X.A; assembly { garbled := 5 @@ -5841,7 +6253,7 @@ BOOST_AUTO_TEST_CASE(invalid_enum_stored) x = garbled; return 1; } - function test_store_ok() returns (uint) { + function test_store_ok() public returns (uint) { x = X.A; return 1; } @@ -5861,19 +6273,19 @@ BOOST_AUTO_TEST_CASE(invalid_enum_as_external_ret) contract C { enum X { A, B } - function test_return() returns (X) { + function test_return() public returns (X) { X garbled; assembly { garbled := 5 } return garbled; } - function test_inline_assignment() returns (X _ret) { + function test_inline_assignment() public returns (X _ret) { assembly { _ret := 5 } } - function test_assignment() returns (X _ret) { + function test_assignment() public returns (X _ret) { X tmp; assembly { tmp := 5 @@ -5895,11 +6307,11 @@ BOOST_AUTO_TEST_CASE(invalid_enum_as_external_arg) contract C { enum X { A, B } - function tested (X x) returns (uint) { + function tested (X x) public returns (uint) { return 1; } - function test() returns (uint) { + function test() public returns (uint) { X garbled; assembly { @@ -5921,19 +6333,19 @@ BOOST_AUTO_TEST_CASE(proper_order_of_overwriting_of_attributes) // bug #1798 char const* sourceCode = R"( contract init { - function isOk() returns (bool) { return false; } + function isOk() public returns (bool) { return false; } bool public ok = false; } contract fix { - function isOk() returns (bool) { return true; } + function isOk() public returns (bool) { return true; } bool public ok = true; } contract init_fix is init, fix { - function checkOk() returns (bool) { return ok; } + function checkOk() public returns (bool) { return ok; } } contract fix_init is fix, init { - function checkOk() returns (bool) { return ok; } + function checkOk() public returns (bool) { return ok; } } )"; compileAndRun(sourceCode, 0, "init_fix"); @@ -5956,13 +6368,13 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) testStruct data1; testStruct data2; testStruct data3; - function test() + constructor() { data1.m_value = 2; } - function assign() returns (uint ret_local, uint ret_global, uint ret_global3, uint ret_global1) + function assign() public returns (uint ret_local, uint ret_global, uint ret_global3, uint ret_global1) { - testStruct x = data1; //x is a reference data1.m_value == 2 as well as x.m_value = 2 + testStruct storage x = data1; //x is a reference data1.m_value == 2 as well as x.m_value = 2 data2 = data1; // should copy data. data2.m_value == 2 ret_local = x.m_value; // = 2 @@ -5988,13 +6400,13 @@ BOOST_AUTO_TEST_CASE(struct_delete_member) uint m_value; } testStruct data1; - function test() + constructor() { data1.m_value = 2; } - function deleteMember() returns (uint ret_value) + function deleteMember() public returns (uint ret_value) { - testStruct x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0 + testStruct storage x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0 x.m_value = 4; delete x.m_value; ret_value = data1.m_value; @@ -6015,11 +6427,11 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) } mapping (uint => testStruct) campaigns; - function test() + constructor() { campaigns[0].m_value = 2; } - function deleteIt() returns (uint) + function deleteIt() public returns (uint) { delete campaigns[0]; return campaigns[0].m_value; @@ -6036,11 +6448,11 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_out_of_band_access) contract A { uint[3] arr; bool public test = false; - function getElement(uint i) returns (uint) + function getElement(uint i) public returns (uint) { return arr[i]; } - function testIt() returns (bool) + function testIt() public returns (bool) { uint i = this.getElement(5); test = true; @@ -6058,7 +6470,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) { char const* sourceCode = R"( contract A { - function A() + constructor() { this.call("123"); } @@ -6084,7 +6496,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) contract A { uint public test = 1; uint[3] arr; - function A() + constructor() { uint index = 5; test = arr[index]; @@ -6093,6 +6505,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) } )"; ABI_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "A"), encodeArgs()); + BOOST_CHECK(!m_transactionSuccessful); } BOOST_AUTO_TEST_CASE(positive_integers_to_signed) @@ -6115,13 +6528,13 @@ BOOST_AUTO_TEST_CASE(failing_send) char const* sourceCode = R"( contract Helper { uint[] data; - function () { + function () external { data[9]; // trigger exception } } contract Main { - function Main() payable {} - function callHelper(address _a) returns (bool r, uint bal) { + constructor() public payable {} + function callHelper(address _a) public returns (bool r, uint bal) { r = !_a.send(5); bal = this.balance; } @@ -6139,13 +6552,13 @@ BOOST_AUTO_TEST_CASE(send_zero_ether) // (it previously did not because the gas stipend was not provided by the EVM) char const* sourceCode = R"( contract Receiver { - function () payable { + function () external payable { } } contract Main { - function Main() payable {} - function s() returns (bool) { - var r = new Receiver(); + constructor() public payable {} + function s() public returns (bool) { + Receiver r = new Receiver(); return r.send(0); } } @@ -6160,17 +6573,17 @@ BOOST_AUTO_TEST_CASE(reusing_memory) char const* sourceCode = R"( contract Helper { uint public flag; - function Helper(uint x) { + constructor(uint x) public { flag = x; } } contract Main { mapping(uint => uint) map; - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { map[x] = x; - return (new Helper(uint(keccak256(this.g(map[x]))))).flag(); + return (new Helper(uint(keccak256(abi.encodePacked(this.g(map[x])))))).flag(); } - function g(uint a) returns (uint) + function g(uint a) public returns (uint) { return map[a]; } @@ -6188,10 +6601,10 @@ BOOST_AUTO_TEST_CASE(return_string) function set(string _s) external { s = _s; } - function get1() returns (string r) { + function get1() public returns (string r) { return s; } - function get2() returns (string r) { + function get2() public returns (string r) { r = s; } } @@ -6216,7 +6629,7 @@ BOOST_AUTO_TEST_CASE(return_multiple_strings_of_various_sizes) s2 = _s2; return x; } - function get() returns (string r1, string r2) { + function get() public returns (string r1, string r2) { r1 = s1; r2 = s2; } @@ -6236,9 +6649,9 @@ BOOST_AUTO_TEST_CASE(return_multiple_strings_of_various_sizes) "ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ" "ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ" ); - vector<size_t> lengthes{0, 30, 32, 63, 64, 65, 210, 300}; - for (auto l1: lengthes) - for (auto l2: lengthes) + vector<size_t> lengths{0, 30, 32, 63, 64, 65, 210, 300}; + for (auto l1: lengths) + for (auto l2: lengths) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes dyn2 = encodeArgs(u256(l2), s2.substr(0, l2)); @@ -6289,12 +6702,12 @@ BOOST_AUTO_TEST_CASE(bytes_in_function_calls) contract Main { string public s1; string public s2; - function set(string _s1, uint x, string _s2) returns (uint) { + function set(string _s1, uint x, string _s2) public returns (uint) { s1 = _s1; s2 = _s2; return x; } - function setIndirectFromMemory(string _s1, uint x, string _s2) returns (uint) { + function setIndirectFromMemory(string _s1, uint x, string _s2) public returns (uint) { return this.set(_s1, x, _s2); } function setIndirectFromCalldata(string _s1, uint x, string _s2) external returns (uint) { @@ -6305,9 +6718,9 @@ BOOST_AUTO_TEST_CASE(bytes_in_function_calls) compileAndRun(sourceCode, 0, "Main"); string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); string s2("ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"); - vector<size_t> lengthes{0, 31, 64, 65}; - for (auto l1: lengthes) - for (auto l2: lengthes) + vector<size_t> lengths{0, 31, 64, 65}; + for (auto l1: lengths) + for (auto l2: lengths) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes dyn2 = encodeArgs(u256(l2), s2.substr(0, l2)); @@ -6334,7 +6747,7 @@ BOOST_AUTO_TEST_CASE(return_bytes_internal) char const* sourceCode = R"( contract Main { bytes s1; - function doSet(bytes _s1) returns (bytes _r1) { + function doSet(bytes _s1) public returns (bytes _r1) { s1 = _s1; _r1 = s1; } @@ -6346,8 +6759,8 @@ BOOST_AUTO_TEST_CASE(return_bytes_internal) )"; compileAndRun(sourceCode, 0, "Main"); string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - vector<size_t> lengthes{0, 31, 64, 65}; - for (auto l1: lengthes) + vector<size_t> lengths{0, 31, 64, 65}; + for (auto l1: lengths) { bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1)); bytes args1 = encodeArgs(u256(0x20)) + dyn1; @@ -6362,15 +6775,15 @@ BOOST_AUTO_TEST_CASE(bytes_index_access_memory) { char const* sourceCode = R"( contract Main { - function f(bytes _s1, uint i1, uint i2, uint i3) returns (byte c1, byte c2, byte c3) { + function f(bytes _s1, uint i1, uint i2, uint i3) public returns (byte c1, byte c2, byte c3) { c1 = _s1[i1]; c2 = intern(_s1, i2); c3 = internIndirect(_s1)[i3]; } - function intern(bytes _s1, uint i) returns (byte c) { + function intern(bytes _s1, uint i) public returns (byte c) { return _s1[i]; } - function internIndirect(bytes _s1) returns (bytes) { + function internIndirect(bytes _s1) public returns (bytes) { return _s1; } } @@ -6391,7 +6804,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_unpacker) contract Test { uint public m_x; bytes public m_s; - function Test(uint x, bytes s) { + constructor(uint x, bytes s) public { m_x = x; m_s = s; } @@ -6412,23 +6825,23 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer) contract Base { uint public m_x; bytes m_s; - function Base(uint x, bytes s) { + constructor(uint x, bytes s) public { m_x = x; m_s = s; } - function part(uint i) returns (byte) { + function part(uint i) public returns (byte) { return m_s[i]; } } contract Main is Base { - function Main(bytes s, uint x) Base(x, f(s)) {} - function f(bytes s) returns (bytes) { + constructor(bytes s, uint x) Base(x, f(s)) public {} + function f(bytes s) public returns (bytes) { return s; } } contract Creator { - function f(uint x, bytes s) returns (uint r, byte ch) { - var c = new Main(s, x); + function f(uint x, bytes s) public returns (uint r, byte ch) { + Main c = new Main(s, x); r = c.m_x(); ch = c.part(x); } @@ -6451,23 +6864,23 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors) contract Base { uint public m_x; address[] m_s; - function Base(uint x, address[] s) { + constructor(uint x, address[] s) public { m_x = x; m_s = s; } - function part(uint i) returns (address) { + function part(uint i) public returns (address) { return m_s[i]; } } contract Main is Base { - function Main(address[] s, uint x) Base(x, f(s)) {} - function f(address[] s) returns (address[]) { + constructor(address[] s, uint x) Base(x, f(s)) public {} + function f(address[] s) public returns (address[]) { return s; } } contract Creator { - function f(uint x, address[] s) returns (uint r, address ch) { - var c = new Main(s, x); + function f(uint x, address[] s) public returns (uint r, address ch) { + Main c = new Main(s, x); r = c.m_x(); ch = c.part(x); } @@ -6490,7 +6903,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_in_constructors) contract Creator { uint public r; address public ch; - function Creator(address[3] s, uint x) { + constructor(address[3] s, uint x) public { r = x; ch = s[2]; } @@ -6506,11 +6919,11 @@ BOOST_AUTO_TEST_CASE(arrays_from_and_to_storage) char const* sourceCode = R"( contract Test { uint24[] public data; - function set(uint24[] _data) returns (uint) { + function set(uint24[] _data) public returns (uint) { data = _data; return data.length; } - function get() returns (uint24[]) { + function get() public returns (uint24[]) { return data; } } @@ -6533,11 +6946,11 @@ BOOST_AUTO_TEST_CASE(arrays_complex_from_and_to_storage) char const* sourceCode = R"( contract Test { uint24[3][] public data; - function set(uint24[3][] _data) returns (uint) { + function set(uint24[3][] _data) public returns (uint) { data = _data; return data.length; } - function get() returns (uint24[3][]) { + function get() public returns (uint24[3][]) { return data; } } @@ -6559,7 +6972,7 @@ BOOST_AUTO_TEST_CASE(arrays_complex_memory_index_access) { char const* sourceCode = R"( contract Test { - function set(uint24[3][] _data, uint a, uint b) returns (uint l, uint e) { + function set(uint24[3][] _data, uint a, uint b) public returns (uint l, uint e) { l = _data.length; e = _data[a][b]; } @@ -6582,7 +6995,7 @@ BOOST_AUTO_TEST_CASE(bytes_memory_index_access) { char const* sourceCode = R"( contract Test { - function set(bytes _data, uint i) returns (uint l, byte c) { + function set(bytes _data, uint i) public returns (uint l, byte c) { l = _data.length; c = _data[i]; } @@ -6629,7 +7042,7 @@ BOOST_AUTO_TEST_CASE(storage_array_ref) data.length++; data[data.length - 1] = v; } - function find(uint v) returns (uint) { + function find(uint v) public returns (uint) { return find(data, v); } } @@ -6658,13 +7071,13 @@ BOOST_AUTO_TEST_CASE(memory_types_initialisation) char const* sourceCode = R"( contract Test { mapping(uint=>uint) data; - function stat() returns (uint[5]) + function stat() public returns (uint[5]) { data[2] = 3; // make sure to use some memory } - function dyn() returns (uint[]) { stat(); } - function nested() returns (uint[3][]) { stat(); } - function nestedStat() returns (uint[3][7]) { stat(); } + function dyn() public returns (uint[]) { stat(); } + function nested() public returns (uint[3][]) { stat(); } + function nestedStat() public returns (uint[3][7]) { stat(); } } )"; compileAndRun(sourceCode, 0, "Test"); @@ -6679,7 +7092,7 @@ BOOST_AUTO_TEST_CASE(memory_arrays_delete) { char const* sourceCode = R"( contract Test { - function del() returns (uint24[3][4]) { + function del() public returns (uint24[3][4]) { uint24[3][4] memory x; for (uint24 i = 0; i < x.length; i ++) for (uint24 j = 0; j < x[i].length; j ++) @@ -6712,7 +7125,7 @@ BOOST_AUTO_TEST_CASE(memory_arrays_index_access_write) x[2][2] = 1; x[3][2] = 7; } - function f() returns (uint24[3][4]){ + function f() public returns (uint24[3][4]){ uint24[3][4] memory data; set(data); return data; @@ -6737,7 +7150,7 @@ BOOST_AUTO_TEST_CASE(memory_arrays_dynamic_index_access_write) x[1][3][2] = 7; return x; } - function f() returns (uint24[3][]) { + function f() public returns (uint24[3][]) { data[1].length = 4; return set(data)[1]; } @@ -6757,7 +7170,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_read_write) contract Test { struct S { uint8 x; uint16 y; uint z; uint8[2] a; } S[5] data; - function testInit() returns (uint8 x, uint16 y, uint z, uint8 a, bool flag) { + function testInit() public returns (uint8 x, uint16 y, uint z, uint8 a, bool flag) { S[2] memory d; x = d[0].x; y = d[0].y; @@ -6765,7 +7178,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_read_write) a = d[0].a[1]; flag = true; } - function testCopyRead() returns (uint8 x, uint16 y, uint z, uint8 a) { + function testCopyRead() public returns (uint8 x, uint16 y, uint z, uint8 a) { data[2].x = 1; data[2].y = 2; data[2].z = 3; @@ -6776,7 +7189,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_read_write) z = s.z; a = s.a[1]; } - function testAssign() returns (uint8 x, uint16 y, uint z, uint8 a) { + function testAssign() public returns (uint8 x, uint16 y, uint z, uint8 a) { S memory s; s.x = 1; s.y = 2; @@ -6801,7 +7214,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_as_function_args) char const* sourceCode = R"( contract Test { struct S { uint8 x; uint16 y; uint z; } - function test() returns (uint x, uint y, uint z) { + function test() public returns (uint x, uint y, uint z) { S memory data = combine(1, 2, 3); x = extract(data, 0); y = extract(data, 1); @@ -6830,7 +7243,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_nested) contract Test { struct S { uint8 x; uint16 y; uint z; } struct X { uint8 x; S s; } - function test() returns (uint a, uint x, uint y, uint z) { + function test() public returns (uint a, uint x, uint y, uint z) { X memory d = combine(1, 2, 3, 4); a = extract(d, 0); x = extract(d, 1); @@ -6863,7 +7276,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_nested_load) struct S { uint8 x; uint16 y; uint z; } struct X { uint8 x; S s; uint8[2] a; } X m_x; - function load() returns (uint a, uint x, uint y, uint z, uint a1, uint a2) { + function load() public returns (uint a, uint x, uint y, uint z, uint a1, uint a2) { m_x.x = 1; m_x.s.x = 2; m_x.s.y = 3; @@ -6878,7 +7291,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_nested_load) a1 = d.a[0]; a2 = d.a[1]; } - function store() returns (uint a, uint x, uint y, uint z, uint a1, uint a2) { + function store() public returns (uint a, uint x, uint y, uint z, uint a1, uint a2) { X memory d; d.x = 1; d.s.x = 2; @@ -6910,12 +7323,12 @@ BOOST_AUTO_TEST_CASE(struct_constructor_nested) struct X { uint x1; uint x2; } struct S { uint s1; uint[3] s2; X s3; } S s; - function C() { + constructor() public { uint[3] memory s2; s2[1] = 9; s = S(1, s2, X(4, 5)); } - function get() returns (uint s1, uint[3] s2, uint x1, uint x2) + function get() public returns (uint s1, uint[3] s2, uint x1, uint x2) { s1 = s.s1; s2 = s.s2; @@ -6936,7 +7349,7 @@ BOOST_AUTO_TEST_CASE(struct_named_constructor) contract C { struct S { uint a; bool x; } S public s; - function C() { + constructor() public { s = S({a: 1, x: true}); } } @@ -6954,7 +7367,7 @@ BOOST_AUTO_TEST_CASE(literal_strings) string public medium; string public short; string public empty; - function f() returns (string) { + function f() public returns (string) { long = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; medium = "01234567890123456789012345678901234567890123456789012345678901234567890123456789"; short = "123"; @@ -6998,7 +7411,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_with_mappings) contract Test { struct S { uint8 a; mapping(uint => uint) b; uint8 c; } S s; - function f() returns (uint) { + function f() public returns (uint) { S memory x; if (x.a != 0 || x.c != 0) return 1; x.a = 4; x.c = 5; @@ -7021,12 +7434,12 @@ BOOST_AUTO_TEST_CASE(string_bytes_conversion) contract Test { string s; bytes b; - function f(string _s, uint n) returns (byte) { + function f(string _s, uint n) public returns (byte) { b = bytes(_s); s = string(b); return bytes(s)[n]; } - function l() returns (uint) { return bytes(s).length; } + function l() public returns (uint) { return bytes(s).length; } } )"; compileAndRun(sourceCode, 0, "Test"); @@ -7046,7 +7459,7 @@ BOOST_AUTO_TEST_CASE(string_as_mapping_key) contract Test { mapping(string => uint) data; function set(string _s, uint _v) { data[_s] = _v; } - function get(string _s) returns (uint) { return data[_s]; } + function get(string _s) public returns (uint) { return data[_s]; } } )"; compileAndRun(sourceCode, 0, "Test"); @@ -7103,7 +7516,7 @@ BOOST_AUTO_TEST_CASE(state_variable_under_contract_name) contract Scope { uint stateVar = 42; - function getStateVar() view returns (uint stateVar) { + function getStateVar() public view returns (uint stateVar) { stateVar = Scope.stateVar; } } @@ -7118,7 +7531,7 @@ BOOST_AUTO_TEST_CASE(state_variable_local_variable_mixture) contract A { uint x = 1; uint y = 2; - function a() returns (uint x) { + function a() public returns (uint x) { x = A.y; } } @@ -7133,7 +7546,7 @@ BOOST_AUTO_TEST_CASE(inherited_function) { contract A { function f() internal returns (uint) { return 1; } } contract B is A { function f() internal returns (uint) { return 2; } - function g() returns (uint) { + function g() public returns (uint) { return A.f(); } } @@ -7148,7 +7561,7 @@ BOOST_AUTO_TEST_CASE(inherited_function_from_a_library) { library A { function f() internal returns (uint) { return 1; } } contract B { function f() internal returns (uint) { return 2; } - function g() returns (uint) { + function g() public returns (uint) { return A.f(); } } @@ -7165,7 +7578,7 @@ BOOST_AUTO_TEST_CASE(inherited_constant_state_var) uint constant x = 7; } contract B is A { - function f() returns (uint) { + function f() public returns (uint) { return A.x; } } @@ -7185,17 +7598,17 @@ BOOST_AUTO_TEST_CASE(multiple_inherited_state_vars) uint x = 9; } contract C is A, B { - function a() returns (uint) { + function a() public returns (uint) { return A.x; } - function b() returns (uint) { + function b() public returns (uint) { return B.x; } - function a_set(uint _x) returns (uint) { + function a_set(uint _x) public returns (uint) { A.x = _x; return 1; } - function b_set(uint _x) returns (uint) { + function b_set(uint _x) public returns (uint) { B.x = _x; return 1; } @@ -7218,14 +7631,14 @@ BOOST_AUTO_TEST_CASE(constant_string_literal) bytes32 constant public b = "abcdefghijklmnopq"; string constant public x = "abefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabca"; - function Test() { - var xx = x; - var bb = b; + constructor() public { + string memory xx = x; + bytes32 bb = b; } - function getB() returns (bytes32) { return b; } - function getX() returns (string) { return x; } - function getX2() returns (string r) { r = x; } - function unused() returns (uint) { + function getB() public returns (bytes32) { return b; } + function getX() public returns (string) { return x; } + function getX2() public returns (string r) { r = x; } + function unused() public returns (uint) { "unusedunusedunusedunusedunusedunusedunusedunusedunusedunusedunusedunused"; return 2; } @@ -7248,7 +7661,7 @@ BOOST_AUTO_TEST_CASE(storage_string_as_mapping_key_without_variable) char const* sourceCode = R"( contract Test { mapping(string => uint) data; - function f() returns (uint) { + function f() public returns (uint) { data["abc"] = 2; return data["abc"]; } @@ -7261,9 +7674,9 @@ BOOST_AUTO_TEST_CASE(storage_string_as_mapping_key_without_variable) BOOST_AUTO_TEST_CASE(library_call) { char const* sourceCode = R"( - library Lib { function m(uint x, uint y) returns (uint) { return x * y; } } + library Lib { function m(uint x, uint y) public returns (uint) { return x * y; } } contract Test { - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { return Lib.m(x, 9); } } @@ -7291,9 +7704,9 @@ BOOST_AUTO_TEST_CASE(library_function_external) BOOST_AUTO_TEST_CASE(library_stray_values) { char const* sourceCode = R"( - library Lib { function m(uint x, uint y) returns (uint) { return x * y; } } + library Lib { function m(uint x, uint y) public returns (uint) { return x * y; } } contract Test { - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { Lib; Lib.m; return x + 9; @@ -7310,8 +7723,8 @@ BOOST_AUTO_TEST_CASE(cross_contract_types) char const* sourceCode = R"( contract Lib { struct S {uint a; uint b; } } contract Test { - function f() returns (uint r) { - var x = Lib.S({a: 2, b: 3}); + function f() public returns (uint r) { + Lib.S memory x = Lib.S({a: 2, b: 3}); r = x.b; } } @@ -7324,7 +7737,7 @@ BOOST_AUTO_TEST_CASE(simple_throw) { char const* sourceCode = R"( contract Test { - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { if (x > 10) return x + 10; else @@ -7351,22 +7764,22 @@ BOOST_AUTO_TEST_CASE(strings_in_struct) string last; } - function buggystruct(){ + constructor(){ bug = Buggy(10, 20, 30, "asdfghjkl"); } - function getFirst() returns (uint) + function getFirst() public returns (uint) { return bug.first; } - function getSecond() returns (uint) + function getSecond() public returns (uint) { return bug.second; } - function getThird() returns (uint) + function getThird() public returns (uint) { return bug.third; } - function getLast() returns (string) + function getLast() public returns (string) { return bug.last; } @@ -7384,7 +7797,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_as_return_type) { char const* sourceCode = R"( contract A { - function f(uint16 input) pure returns (uint16[5] arr) + function f(uint16 input) public pure returns (uint16[5] arr) { arr[0] = input; arr[1] = ++input; @@ -7394,9 +7807,9 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_as_return_type) } } contract B { - function f() returns (uint16[5] res, uint16[5] res2) + function f() public returns (uint16[5] res, uint16[5] res2) { - var a = new A(); + A a = new A(); res = a.f(2); res2 = a.f(1000); } @@ -7413,7 +7826,7 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) { char const* sourceCode = R"( library Lib { - function find(uint16[] storage _haystack, uint16 _needle) view returns (uint) + function find(uint16[] storage _haystack, uint16 _needle) public view returns (uint) { for (uint i = 0; i < _haystack.length; ++i) if (_haystack[i] == _needle) @@ -7423,7 +7836,7 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) } contract Test { mapping(string => uint16[]) data; - function f() returns (uint a, uint b) + function f() public returns (uint a, uint b) { data["abc"].length = 20; data["abc"][4] = 9; @@ -7452,7 +7865,7 @@ BOOST_AUTO_TEST_CASE(using_library_structs) } contract Test { mapping(string => Lib.Data) data; - function f() returns (uint a, uint b) + function f() public returns (uint a, uint b) { Lib.set(data["abc"]); a = data["abc"].a; @@ -7476,7 +7889,7 @@ BOOST_AUTO_TEST_CASE(library_struct_as_an_expression) } contract Tsra { - function f() returns(uint) { + function f() public returns(uint) { Arst.Foo; return 1; } @@ -7497,7 +7910,7 @@ BOOST_AUTO_TEST_CASE(library_enum_as_an_expression) } contract Tsra { - function f() returns(uint) { + function f() public returns(uint) { Arst.Foo; return 1; } @@ -7515,7 +7928,7 @@ BOOST_AUTO_TEST_CASE(short_strings) contract A { bytes public data1 = "123"; bytes data2; - function lengthChange() returns (uint) + function lengthChange() public returns (uint) { // store constant in short and long string data1 = "123"; @@ -7557,7 +7970,7 @@ BOOST_AUTO_TEST_CASE(short_strings) data1.length = 0; data2.length = 0; } - function copy() returns (uint) { + function copy() public returns (uint) { bytes memory x = "123"; bytes memory y = "012345678901234567890123456789012345678901234567890123456789"; bytes memory z = "1234567"; @@ -7590,7 +8003,7 @@ BOOST_AUTO_TEST_CASE(short_strings) data1 = ""; data2 = ""; } - function deleteElements() returns (uint) { + function deleteElements() public returns (uint) { data1 = "01234"; delete data1[2]; if (data1[2] != 0) return 1; @@ -7626,7 +8039,7 @@ BOOST_AUTO_TEST_CASE(calldata_offset) { address[] _arr; string public last = "nd"; - function CB(address[] guardians) + constructor(address[] guardians) { _arr = guardians; } @@ -7639,9 +8052,9 @@ BOOST_AUTO_TEST_CASE(calldata_offset) BOOST_AUTO_TEST_CASE(contract_binary_dependencies) { char const* sourceCode = R"( - contract A { function f() { new B(); } } - contract B { function f() { } } - contract C { function f() { new B(); } } + contract A { function f() public { new B(); } } + contract B { function f() public { } } + contract C { function f() public { new B(); } } )"; compileAndRun(sourceCode); } @@ -7651,11 +8064,11 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library) char const* sourceCode = R"( library lib {} contract c { - function c() payable {} - function f(address x) returns (bool) { + constructor() public payable {} + function f(address x) public returns (bool) { return x.send(1); } - function () payable {} + function () external payable {} } )"; compileAndRun(sourceCode, 0, "lib"); @@ -7675,20 +8088,39 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration) { char const* sourceCode = R"( contract C { - function g() returns (uint a, uint b, uint c) { + function g() public returns (uint a, uint b, uint c) { a = 1; b = 2; c = 3; } - function f() returns (bool) { - var (x, y, z) = g(); + function h() public returns (uint a, uint b, uint c, uint d) { + a = 1; b = 2; c = 3; d = 4; + } + function f1() public returns (bool) { + (uint x, uint y, uint z) = g(); if (x != 1 || y != 2 || z != 3) return false; - var (, a,) = g(); + (, uint a,) = g(); if (a != 2) return false; - var (b,) = g(); + (uint b, , ) = g(); if (b != 1) return false; - var (,c) = g(); + (, , uint c) = g(); if (c != 3) return false; return true; } + function f2() public returns (bool) { + (uint a1, , uint a3, ) = h(); + if (a1 != 1 || a3 != 3) return false; + (uint b1, uint b2, , ) = h(); + if (b1 != 1 || b2 != 2) return false; + (, uint c2, uint c3, ) = h(); + if (c2 != 2 || c3 != 3) return false; + (, , uint d3, uint d4) = h(); + if (d3 != 3 || d4 != 4) return false; + (uint e1, , uint e3, uint e4) = h(); + if (e1 != 1 || e3 != 3 || e4 != 4) return false; + return true; + } + function f() public returns (bool) { + return f1() && f2(); + } } )"; compileAndRun(sourceCode); @@ -7705,7 +8137,7 @@ BOOST_AUTO_TEST_CASE(typed_multi_variable_declaration) s.x = 7; return (1, s, 2); } - function f() returns (bool) { + function f() public returns (bool) { (uint x1, S storage y1, uint z1) = g(); if (x1 != 1 || y1.x != 7 || z1 != 2) return false; (, S storage y2,) = g(); @@ -7727,24 +8159,25 @@ BOOST_AUTO_TEST_CASE(tuples) char const* sourceCode = R"( contract C { uint[] data; + uint[] m_c; function g() internal returns (uint a, uint b, uint[] storage c) { return (1, 2, data); } function h() external returns (uint a, uint b) { return (5, 6); } - function f() returns (uint) { + function f() public returns (uint) { data.length = 1; data[0] = 3; uint a; uint b; (a, b) = this.h(); if (a != 5 || b != 6) return 1; - uint[] storage c; + uint[] storage c = m_c; (a, b, c) = g(); if (a != 1 || b != 2 || c[0] != 3) return 2; (a, b) = (b, a); if (a != 2 || b != 1) return 3; - (a, , b, ) = (8, 9, 10, 11, 12); + (a, , b, , ) = (8, 9, 10, 11, 12); if (a != 8 || b != 10) return 4; } } @@ -7757,14 +8190,14 @@ BOOST_AUTO_TEST_CASE(string_tuples) { char const* sourceCode = R"( contract C { - function f() returns (string, uint) { + function f() public returns (string, uint) { return ("abc", 8); } - function g() returns (string, string) { + function g() public returns (string, string) { return (h(), "def"); } - function h() returns (string) { - return ("abc",); + function h() public returns (string) { + return ("abc"); } } )"; @@ -7777,7 +8210,7 @@ BOOST_AUTO_TEST_CASE(decayed_tuple) { char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { uint x = 1; (x) = 2; return x; @@ -7792,7 +8225,7 @@ BOOST_AUTO_TEST_CASE(inline_tuple_with_rational_numbers) { char const* sourceCode = R"( contract c { - function f() returns (int8) { + function f() public returns (int8) { int8[5] memory foo3 = [int8(1), -1, 0, 0, 0]; return foo3[0]; } @@ -7810,13 +8243,13 @@ BOOST_AUTO_TEST_CASE(destructuring_assignment) bytes data; uint[] y; uint[] arrayData; - function returnsArray() returns (uint[]) { + function returnsArray() public returns (uint[]) { arrayData.length = 9; arrayData[2] = 5; arrayData[7] = 4; return arrayData; } - function f(bytes s) returns (uint) { + function f(bytes s) public returns (uint) { uint loc; uint[] memory memArray; (loc, x, y, data, arrayData[3]) = (8, 4, returnsArray(), s, 2); @@ -7832,7 +8265,7 @@ BOOST_AUTO_TEST_CASE(destructuring_assignment) if (loc != 3) return 9; if (memArray.length != arrayData.length) return 10; bytes memory memBytes; - (x, memBytes, y[2], ) = (456, s, 789, 101112, 131415); + (x, memBytes, y[2], , ) = (456, s, 789, 101112, 131415); if (x != 456 || memBytes.length != s.length || y[2] != 789) return 11; } } @@ -7841,37 +8274,12 @@ BOOST_AUTO_TEST_CASE(destructuring_assignment) ABI_CHECK(callContractFunction("f(bytes)", u256(0x20), u256(5), string("abcde")), encodeArgs(u256(0))); } -BOOST_AUTO_TEST_CASE(destructuring_assignment_wildcard) -{ - char const* sourceCode = R"( - contract C { - function f() returns (uint) { - uint a; - uint b; - uint c; - (a,) = (1,); - if (a != 1) return 1; - (,b) = (2,3,4); - if (b != 4) return 2; - (, c,) = (5,6,7); - if (c != 6) return 3; - (a, b,) = (11, 12, 13); - if (a != 11 || b != 12) return 4; - (, a, b) = (11, 12, 13); - if (a != 12 || b != 13) return 5; - } - } - )"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0))); -} - BOOST_AUTO_TEST_CASE(lone_struct_array_type) { char const* sourceCode = R"( contract C { struct s { uint a; uint b;} - function f() returns (uint) { + function f() public returns (uint) { s[7][]; // This is only the type, should not have any effect return 3; } @@ -7886,12 +8294,12 @@ BOOST_AUTO_TEST_CASE(create_memory_array) char const* sourceCode = R"( contract C { struct S { uint[2] a; bytes b; } - function f() returns (byte, uint, uint, byte) { - var x = new bytes(200); + function f() public returns (byte, uint, uint, byte) { + bytes memory x = new bytes(200); x[199] = 'A'; - var y = new uint[2][](300); + uint[2][] memory y = new uint[2][](300); y[203][1] = 8; - var z = new S[](180); + S[] memory z = new S[](180); z[170].a[1] = 4; z[170].b = new bytes(102); z[170].b[99] = 'B'; @@ -7909,7 +8317,7 @@ BOOST_AUTO_TEST_CASE(create_memory_array_allocation_size) // multiple of 32 char const* sourceCode = R"( contract C { - function f() pure returns (uint d1, uint d2, uint d3) { + function f() public pure returns (uint d1, uint d2, uint d3, uint memsize) { bytes memory b1 = new bytes(31); bytes memory b2 = new bytes(32); bytes memory b3 = new bytes(256); @@ -7918,12 +8326,13 @@ BOOST_AUTO_TEST_CASE(create_memory_array_allocation_size) d1 := sub(b2, b1) d2 := sub(b3, b2) d3 := sub(b4, b3) + memsize := msize() } } } )"; compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f()"), encodeArgs(0x40, 0x40, 0x20 + 256)); + ABI_CHECK(callContractFunction("f()"), encodeArgs(0x40, 0x40, 0x20 + 256, 0x260)); } BOOST_AUTO_TEST_CASE(memory_arrays_of_various_sizes) @@ -7931,7 +8340,7 @@ BOOST_AUTO_TEST_CASE(memory_arrays_of_various_sizes) // Computes binomial coefficients the chinese way char const* sourceCode = R"( contract C { - function f(uint n, uint k) returns (uint) { + function f(uint n, uint k) public returns (uint) { uint[][] memory rows = new uint[][](n + 1); for (uint i = 1; i <= n; i++) { rows[i] = new uint[](i); @@ -7952,7 +8361,7 @@ BOOST_AUTO_TEST_CASE(create_multiple_dynamic_arrays) { char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { uint[][] memory x = new uint[][](42); assert(x[0].length == 0); x[0] = new uint[](1); @@ -7987,7 +8396,7 @@ BOOST_AUTO_TEST_CASE(memory_overwrite) { char const* sourceCode = R"( contract C { - function f() returns (bytes x) { + function f() public returns (bytes x) { x = "12345"; x[3] = 0x61; x[0] = 0x62; @@ -8002,7 +8411,7 @@ BOOST_AUTO_TEST_CASE(addmod_mulmod) { char const* sourceCode = R"( contract C { - function test() returns (uint) { + function test() public returns (uint) { // Note that this only works because computation on literals is done using // unbounded integers. if ((2**255 + 2**255) % 7 != addmod(2**255, 2**255, 7)) @@ -8021,15 +8430,15 @@ BOOST_AUTO_TEST_CASE(addmod_mulmod_zero) { char const* sourceCode = R"( contract C { - function f(uint d) pure returns (uint) { + function f(uint d) public pure returns (uint) { addmod(1, 2, d); return 2; } - function g(uint d) pure returns (uint) { + function g(uint d) public pure returns (uint) { mulmod(1, 2, d); return 2; } - function h() pure returns (uint) { + function h() public pure returns (uint) { mulmod(0, 1, 2); mulmod(1, 0, 2); addmod(0, 1, 2); @@ -8048,10 +8457,10 @@ BOOST_AUTO_TEST_CASE(divisiod_by_zero) { char const* sourceCode = R"( contract C { - function div(uint a, uint b) returns (uint) { + function div(uint a, uint b) public returns (uint) { return a / b; } - function mod(uint a, uint b) returns (uint) { + function mod(uint a, uint b) public returns (uint) { return a % b; } } @@ -8072,7 +8481,7 @@ BOOST_AUTO_TEST_CASE(string_allocation_bug) { struct s { uint16 x; uint16 y; string a; string b;} s[2] public p; - function Sample() { + constructor() public { s memory m; m.x = 0xbbbb; m.y = 0xcccc; @@ -8098,10 +8507,10 @@ BOOST_AUTO_TEST_CASE(string_allocation_bug) BOOST_AUTO_TEST_CASE(using_for_function_on_int) { char const* sourceCode = R"( - library D { function double(uint self) returns (uint) { return 2*self; } } + library D { function double(uint self) public returns (uint) { return 2*self; } } contract C { using D for uint; - function f(uint a) returns (uint) { + function f(uint a) public returns (uint) { return a.double(); } } @@ -8114,11 +8523,11 @@ BOOST_AUTO_TEST_CASE(using_for_function_on_int) BOOST_AUTO_TEST_CASE(using_for_function_on_struct) { char const* sourceCode = R"( - library D { struct s { uint a; } function mul(s storage self, uint x) returns (uint) { return self.a *= x; } } + library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } contract C { using D for D.s; D.s public x; - function f(uint a) returns (uint) { + function f(uint a) public returns (uint) { x.a = 3; return x.mul(a); } @@ -8135,13 +8544,13 @@ BOOST_AUTO_TEST_CASE(using_for_overload) char const* sourceCode = R"( library D { struct s { uint a; } - function mul(s storage self, uint x) returns (uint) { return self.a *= x; } - function mul(s storage self, bytes32 x) returns (bytes32) { } + function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } + function mul(s storage self, bytes32 x) public returns (bytes32) { } } contract C { using D for D.s; D.s public x; - function f(uint a) returns (uint) { + function f(uint a) public returns (uint) { x.a = 6; return x.mul(a); } @@ -8156,11 +8565,11 @@ BOOST_AUTO_TEST_CASE(using_for_overload) BOOST_AUTO_TEST_CASE(using_for_by_name) { char const* sourceCode = R"( - library D { struct s { uint a; } function mul(s storage self, uint x) returns (uint) { return self.a *= x; } } + library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } contract C { using D for D.s; D.s public x; - function f(uint a) returns (uint) { + function f(uint a) public returns (uint) { x.a = 6; return x.mul({x: a}); } @@ -8175,14 +8584,13 @@ BOOST_AUTO_TEST_CASE(using_for_by_name) BOOST_AUTO_TEST_CASE(bound_function_in_var) { char const* sourceCode = R"( - library D { struct s { uint a; } function mul(s storage self, uint x) returns (uint) { return self.a *= x; } } + library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } contract C { using D for D.s; D.s public x; - function f(uint a) returns (uint) { + function f(uint a) public returns (uint) { x.a = 6; - var g = x.mul; - return g({x: a}); + return (x.mul)({x: a}); } } )"; @@ -8195,15 +8603,15 @@ BOOST_AUTO_TEST_CASE(bound_function_in_var) BOOST_AUTO_TEST_CASE(bound_function_to_string) { char const* sourceCode = R"( - library D { function length(string memory self) returns (uint) { return bytes(self).length; } } + library D { function length(string memory self) public returns (uint) { return bytes(self).length; } } contract C { using D for string; string x; - function f() returns (uint) { + function f() public returns (uint) { x = "abc"; return x.length(); } - function g() returns (uint) { + function g() public returns (uint) { string memory s = "abc"; return s.length(); } @@ -8220,7 +8628,7 @@ BOOST_AUTO_TEST_CASE(inline_array_storage_to_memory_conversion_strings) char const* sourceCode = R"( contract C { string s = "doh"; - function f() returns (string, string) { + function f() public returns (string, string) { string memory t = "ray"; string[3] memory x = [s, t, "mi"]; return (x[1], x[2]); @@ -8235,7 +8643,7 @@ BOOST_AUTO_TEST_CASE(inline_array_strings_from_document) { char const* sourceCode = R"( contract C { - function f(uint i) returns (string) { + function f(uint i) public returns (string) { string[4] memory x = ["This", "is", "an", "array"]; return (x[i]); } @@ -8252,7 +8660,7 @@ BOOST_AUTO_TEST_CASE(inline_array_storage_to_memory_conversion_ints) { char const* sourceCode = R"( contract C { - function f() returns (uint x, uint y) { + function f() public returns (uint x, uint y) { x = 3; y = 6; uint[2] memory z = [x, y]; @@ -8268,7 +8676,7 @@ BOOST_AUTO_TEST_CASE(inline_array_index_access_ints) { char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { return ([1, 2, 3, 4][2]); } } @@ -8282,10 +8690,10 @@ BOOST_AUTO_TEST_CASE(inline_array_index_access_strings) char const* sourceCode = R"( contract C { string public tester; - function f() returns (string) { + function f() public returns (string) { return (["abc", "def", "g"][0]); } - function test() { + function test() public { tester = f(); } } @@ -8299,15 +8707,15 @@ BOOST_AUTO_TEST_CASE(inline_array_return) { char const* sourceCode = R"( contract C { - uint8[] tester; - function f() returns (uint8[5]) { + uint8[] tester; + function f() public returns (uint8[5]) { return ([1,2,3,4,5]); } - function test() returns (uint8, uint8, uint8, uint8, uint8) { - tester = f(); + function test() public returns (uint8, uint8, uint8, uint8, uint8) { + tester = f(); return (tester[0], tester[1], tester[2], tester[3], tester[4]); } - + } )"; compileAndRun(sourceCode, 0, "C"); @@ -8319,7 +8727,7 @@ BOOST_AUTO_TEST_CASE(inline_array_singleton) // This caused a failure since the type was not converted to its mobile type. char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { return [4][0]; } } @@ -8331,13 +8739,13 @@ BOOST_AUTO_TEST_CASE(inline_array_singleton) BOOST_AUTO_TEST_CASE(inline_long_string_return) { char const* sourceCode = R"( - contract C { - function f() returns (string) { + contract C { + function f() public returns (string) { return (["somethingShort", "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"][1]); } } )"; - + string strLong = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), encodeDyn(strLong)); @@ -8348,10 +8756,10 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_index_access) char const* sourceCode = R"( contract C { bytes16[] public data; - function f(bytes32 x) returns (byte) { + function f(bytes32 x) public returns (byte) { return x[2]; } - function g(bytes32 x) returns (uint) { + function g(bytes32 x) public returns (uint) { data = [x[0], x[1], x[2]]; data[0] = "12345"; return uint(uint8(data[0][4])); @@ -8369,7 +8777,7 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_length_access) char const* sourceCode = R"( contract C { byte a; - function f(bytes32 x) returns (uint, uint, uint) { + function f(bytes32 x) public returns (uint, uint, uint) { return (x.length, bytes16(2).length, a.length + 7); } } @@ -8382,7 +8790,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_write_to_stack) { char const* sourceCode = R"( contract C { - function f() returns (uint r, bytes32 r2) { + function f() public returns (uint r, bytes32 r2) { assembly { r := 7 r2 := "abcdef" } } } @@ -8395,7 +8803,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_read_and_write_stack) { char const* sourceCode = R"( contract C { - function f() returns (uint r) { + function f() public returns (uint r) { for (uint x = 0; x < 10; ++x) assembly { r := add(r, x) } } @@ -8409,7 +8817,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_memory_access) { char const* sourceCode = R"( contract C { - function test() returns (bytes) { + function test() public returns (bytes) { bytes memory x = new bytes(5); for (uint i = 0; i < x.length; ++i) x[i] = byte(uint8(i + 1)); @@ -8429,7 +8837,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_access) uint16 x; uint16 public y; uint public z; - function f() returns (bool) { + function f() public returns (bool) { uint off1; uint off2; assembly { @@ -8455,7 +8863,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_access_inside_function) uint16 x; uint16 public y; uint public z; - function f() returns (bool) { + function f() public returns (bool) { uint off1; uint off2; assembly { @@ -8483,8 +8891,8 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_access_via_pointer) uint public separator; Data public a; uint public separator2; - function f() returns (bool) { - Data x = a; + function f() public returns (bool) { + Data storage x = a; uint off; assembly { sstore(x_slot, 7) @@ -8506,7 +8914,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_jumps) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { let n := calldataload(4) let a := 1 @@ -8552,7 +8960,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_call) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { function asmfun(a, b, c) -> x, y, z { x := a @@ -8576,7 +8984,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_call_assignment) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { let a1, b1, c1 function asmfun(a, b, c) -> x, y, z { @@ -8601,7 +9009,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_call2) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { let d := 0x10 function asmfun(a, b, c) -> x, y, z { @@ -8627,7 +9035,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_embedded_function_call) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { let d := 0x10 function asmfun(a, b, c) -> x, y, z { @@ -8654,7 +9062,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_if) { char const* sourceCode = R"( contract C { - function f(uint a) returns (uint b) { + function f(uint a) public returns (uint b) { assembly { if gt(a, 1) { b := 2 } } @@ -8672,7 +9080,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_switch) { char const* sourceCode = R"( contract C { - function f(uint a) returns (uint b) { + function f(uint a) public returns (uint b) { assembly { switch a case 1 { b := 8 } @@ -8693,7 +9101,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_recursion) { char const* sourceCode = R"( contract C { - function f(uint a) returns (uint b) { + function f(uint a) public returns (uint b) { assembly { function fac(n) -> nf { switch n @@ -8718,7 +9126,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_for) { char const* sourceCode = R"( contract C { - function f(uint a) returns (uint b) { + function f(uint a) public returns (uint b) { assembly { function fac(n) -> nf { nf := 1 @@ -8744,7 +9152,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_for2) char const* sourceCode = R"( contract C { uint st; - function f(uint a) returns (uint b, uint c, uint d) { + function f(uint a) public returns (uint b, uint c, uint d) { st = 0; assembly { function sideeffect(r) -> x { sstore(0, add(sload(0), r)) x := 1} @@ -8768,7 +9176,7 @@ BOOST_AUTO_TEST_CASE(index_access_with_type_conversion) // Test for a bug where higher order bits cleanup was not done for array index access. char const* sourceCode = R"( contract C { - function f(uint x) returns (uint[256] r){ + function f(uint x) public returns (uint[256] r){ r[uint8(x)] = 2; } } @@ -8786,7 +9194,7 @@ BOOST_AUTO_TEST_CASE(delete_on_array_of_structs) contract C { struct S { uint x; uint[] y; } S[] data; - function f() returns (bool) { + function f() public returns (bool) { data.length = 2; data[0].x = 2**200; data[1].x = 2**200; @@ -8813,7 +9221,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function) } } contract C { - function f() returns (uint) { + function f() public returns (uint) { uint[] memory x = new uint[](7); x[3] = 8; L.f(x); @@ -8841,7 +9249,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function_calling_private) } } contract C { - function f() returns (uint) { + function f() public returns (uint) { uint[] memory x = new uint[](7); x[3] = 8; L.f(x); @@ -8865,7 +9273,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function_bound) } contract C { using L for L.S; - function f() returns (uint) { + function f() public returns (uint) { L.S memory x; x.data = new uint[](7); x.data[3] = 8; @@ -8891,7 +9299,7 @@ BOOST_AUTO_TEST_CASE(internal_library_function_return_var_size) } contract C { using L for L.S; - function f() returns (uint) { + function f() public returns (uint) { L.S memory x; x.data = new uint[](7); x.data[3] = 8; @@ -8910,7 +9318,7 @@ BOOST_AUTO_TEST_CASE(iszero_bnot_correct) // "iszero" and "not". char const* sourceCode = R"( contract C { - function f() returns (bool) { + function f() public returns (bool) { bytes32 x = 1; assembly { x := not(x) } if (x != ~bytes32(1)) return false; @@ -8929,7 +9337,7 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types) // Checks that bytesXX types are properly cleaned before they are compared. char const* sourceCode = R"( contract C { - function f(bytes2 a, uint16 x) returns (uint) { + function f(bytes2 a, uint16 x) public returns (uint) { if (a != "ab") return 1; if (x != 0x0102) return 2; if (bytes3(uint24(x)) != 0x0102) return 3; @@ -8946,7 +9354,7 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types_shortening) { char const* sourceCode = R"( contract C { - function f() pure returns (bytes32 r) { + function f() public pure returns (bytes32 r) { bytes4 x = 0xffffffff; bytes2 y = bytes2(x); assembly { r := y } @@ -8965,12 +9373,12 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types) // The EVM cannot provide access to dynamically-sized return values, so we have to skip them. char const* sourceCode = R"( contract C { - function f() returns (uint, uint[], uint) { + function f() public returns (uint, uint[], uint) { return (7, new uint[](2), 8); } - function g() returns (uint, uint) { + function g() public returns (uint, uint) { // Previous implementation "moved" b to the second place and did not skip. - var (a, _, b) = this.f(); + (uint a,, uint b) = this.f(); return (a, b); } } @@ -8991,12 +9399,12 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types_for_structs) uint y; } S public s; - function g() returns (uint, uint) { + function g() public returns (uint, uint) { s.x = 2; s.a = "abc"; s.b = [7, 8, 9]; s.y = 6; - var (x, a, y) = this.s(); + (uint x,, uint y) = this.s(); return (x, y); } } @@ -9008,15 +9416,15 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types_for_structs) BOOST_AUTO_TEST_CASE(failed_create) { char const* sourceCode = R"( - contract D { function D() payable {} } + contract D { constructor() payable {} } contract C { uint public x; - function C() payable {} - function f(uint amount) returns (address) { + constructor() public payable {} + function f(uint amount) public returns (address) { x++; return (new D).value(amount)(); } - function stack(uint depth) returns (address) { + function stack(uint depth) public returns (address) { if (depth < 1024) return this.stack(depth - 1); else @@ -9037,8 +9445,8 @@ BOOST_AUTO_TEST_CASE(create_dynamic_array_with_zero_length) { char const* sourceCode = R"( contract C { - function f() returns (uint) { - var a = new uint[][](0); + function f() public returns (uint) { + uint[][] memory a = new uint[][](0); return 7; } } @@ -9054,7 +9462,7 @@ BOOST_AUTO_TEST_CASE(correctly_initialize_memory_array_in_constructor) char const* sourceCode = R"( contract C { bool public success; - function C() public { + constructor() public { // Make memory dirty. assembly { for { let i := 0 } lt(i, 64) { i := add(i, 1) } { @@ -9082,7 +9490,7 @@ BOOST_AUTO_TEST_CASE(return_does_not_skip_modifier) _; x = 9; } - function f() setsx returns (uint) { + function f() setsx public returns (uint) { return 2; } } @@ -9105,7 +9513,9 @@ BOOST_AUTO_TEST_CASE(break_in_modifier) } } function f() run { - x++; + uint k = x; + uint t = k + 1; + x = t; } } )"; @@ -9115,6 +9525,54 @@ BOOST_AUTO_TEST_CASE(break_in_modifier) ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(1))); } +BOOST_AUTO_TEST_CASE(continue_in_modifier) +{ + char const* sourceCode = R"( + contract C { + uint public x; + modifier run() { + for (uint i = 0; i < 10; i++) { + if (i % 2 == 1) continue; + _; + } + } + function f() run { + uint k = x; + uint t = k + 1; + x = t; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f()"), encodeArgs()); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(5))); +} + +BOOST_AUTO_TEST_CASE(return_in_modifier) +{ + char const* sourceCode = R"( + contract C { + uint public x; + modifier run() { + for (uint i = 1; i < 10; i++) { + if (i == 5) return; + _; + } + } + function f() run { + uint k = x; + uint t = k + 1; + x = t; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f()"), encodeArgs()); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(4))); +} + BOOST_AUTO_TEST_CASE(stacked_return_with_modifiers) { char const* sourceCode = R"( @@ -9127,7 +9585,9 @@ BOOST_AUTO_TEST_CASE(stacked_return_with_modifiers) } } function f() run { - x++; + uint k = x; + uint t = k + 1; + x = t; } } )"; @@ -9151,20 +9611,20 @@ BOOST_AUTO_TEST_CASE(mutex) } contract Fund is mutexed { uint shares; - function Fund() payable { shares = msg.value; } + constructor() payable { shares = msg.value; } function withdraw(uint amount) protected returns (uint) { // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. if (amount > shares) throw; - if (!msg.sender.call.value(amount)()) throw; + if (!msg.sender.call.value(amount)("")) throw; shares -= amount; return shares; } - function withdrawUnprotected(uint amount) returns (uint) { + function withdrawUnprotected(uint amount) public returns (uint) { // NOTE: It is very bad practice to write this function this way. // Please refer to the documentation of how to do this properly. if (amount > shares) throw; - if (!msg.sender.call.value(amount)()) throw; + if (!msg.sender.call.value(amount)("")) throw; shares -= amount; return shares; } @@ -9174,8 +9634,8 @@ BOOST_AUTO_TEST_CASE(mutex) uint callDepth; bool protected; function setProtected(bool _protected) { protected = _protected; } - function Attacker(Fund _fund) { fund = _fund; } - function attack() returns (uint) { + constructor(Fund _fund) public { fund = _fund; } + function attack() public returns (uint) { callDepth = 0; return attackInternal(); } @@ -9185,7 +9645,7 @@ BOOST_AUTO_TEST_CASE(mutex) else return fund.withdrawUnprotected(10); } - function() payable { + function() external payable { callDepth++; if (callDepth < 4) attackInternal(); @@ -9211,7 +9671,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input) // Note that the precompile does not return zero but returns nothing. char const* sourceCode = R"( contract C { - function f() returns (address) { + function f() public returns (address) { return ecrecover(bytes32(uint(-1)), 1, 2, 3); } } @@ -9224,20 +9684,20 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_proper) { char const* sourceCode = R"( contract C { - function f() returns (address) { + function f() public returns (address) { return recover( 0x77e5189111eb6557e8a637b27ef8fbb15bc61d61c2f00cc48878f3a296e5e0ca, 0, // invalid v value 0x6944c77849b18048f6abe0db8084b0d0d0689cdddb53d2671c36967b58691ad4, 0xef4f06ba4f78319baafd0424365777241af4dfd3da840471b4b4b087b7750d0d, - 0xca35b7d915458ef540ade6068dfe2f44e8fa733c, - 0xca35b7d915458ef540ade6068dfe2f44e8fa733c + 0x00ca35b7d915458ef540ade6068dfe2f44e8fa733c, + 0x00ca35b7d915458ef540ade6068dfe2f44e8fa733c ); } function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s, uint blockExpired, bytes32 salt) - returns (address) + public returns (address) { - require(hash == keccak256(blockExpired, salt)); + require(hash == keccak256(abi.encodePacked(blockExpired, salt))); return ecrecover(hash, v, r, s); } } @@ -9250,7 +9710,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_asm) { char const* sourceCode = R"( contract C { - function f() returns (address) { + function f() public returns (address) { assembly { mstore(mload(0x40), 0xca35b7d915458ef540ade6068dfe2f44e8fa733c) } @@ -9269,24 +9729,24 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_asm) BOOST_AUTO_TEST_CASE(calling_nonexisting_contract_throws) { - char const* sourceCode = R"( + char const* sourceCode = R"YY( contract D { function g(); } contract C { D d = D(0x1212); - function f() returns (uint) { + function f() public returns (uint) { d.g(); return 7; } - function g() returns (uint) { + function g() public returns (uint) { d.g.gas(200)(); return 7; } - function h() returns (uint) { - d.call(); // this does not throw (low-level) + function h() public returns (uint) { + d.call(""); // this does not throw (low-level) return 7; } } - )"; + )YY"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), encodeArgs()); ABI_CHECK(callContractFunction("g()"), encodeArgs()); @@ -9297,7 +9757,7 @@ BOOST_AUTO_TEST_CASE(payable_constructor) { char const* sourceCode = R"( contract C { - function C() payable { } + constructor() payable { } } )"; compileAndRun(sourceCode, 27, "C"); @@ -9308,10 +9768,10 @@ BOOST_AUTO_TEST_CASE(payable_function) char const* sourceCode = R"( contract C { uint public a; - function f() payable returns (uint) { + function f() payable public returns (uint) { return msg.value; } - function() payable { + function() external payable { a = msg.value + 1; } } @@ -9329,10 +9789,10 @@ BOOST_AUTO_TEST_CASE(payable_function_calls_library) { char const* sourceCode = R"( library L { - function f() returns (uint) { return 7; } + function f() public returns (uint) { return 7; } } contract C { - function f() payable returns (uint) { + function f() payable public returns (uint) { return L.f(); } } @@ -9347,10 +9807,10 @@ BOOST_AUTO_TEST_CASE(non_payable_throw) char const* sourceCode = R"( contract C { uint public a; - function f() returns (uint) { + function f() public returns (uint) { return msg.value; } - function() { + function() external { a = msg.value + 1; } } @@ -9374,7 +9834,7 @@ BOOST_AUTO_TEST_CASE(no_nonpayable_circumvention_by_modifier) modifier tryCircumvent { if (false) _; // avoid the function, we should still not accept ether } - function f() tryCircumvent returns (uint) { + function f() tryCircumvent public returns (uint) { return msg.value; } } @@ -9392,10 +9852,10 @@ BOOST_AUTO_TEST_CASE(mem_resize_is_not_paid_at_call) // Tests that this also survives the optimizer. char const* sourceCode = R"( contract C { - function f() returns (uint[200]) {} + function f() public returns (uint[200]) {} } contract D { - function f(C c) returns (uint) { c.f(); return 7; } + function f(C c) public returns (uint) { c.f(); return 7; } } )"; @@ -9409,12 +9869,12 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function) { char const* sourceCode = R"( contract C { - function intern() returns (uint) { + function intern() public returns (uint) { function (uint) internal returns (uint) x; x(2); return 7; } - function extern() returns (uint) { + function extern() public returns (uint) { function (uint) external returns (uint) x; x(2); return 7; @@ -9434,7 +9894,7 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function_in_detail) contract C { function() internal returns (uint) x; int mutex; - function t() returns (uint) { + function t() public returns (uint) { if (mutex > 0) { assembly { mstore(0, 7) return(0, 0x20) } } mutex = 1; @@ -9454,12 +9914,12 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function_through_array) char const* sourceCode = R"( contract C { int mutex; - function t() returns (uint) { + function t() public returns (uint) { if (mutex > 0) { assembly { mstore(0, 7) return(0, 0x20) } } mutex = 1; // Avoid re-executing this function if we jump somewhere. - function() internal returns (uint)[200] x; + function() internal returns (uint)[200] memory x; x[0](); return 2; } @@ -9474,13 +9934,13 @@ BOOST_AUTO_TEST_CASE(pass_function_types_internally) { char const* sourceCode = R"( contract C { - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { return eval(g, x); } - function eval(function(uint) returns (uint) x, uint a) internal returns (uint) { + function eval(function(uint) internal returns (uint) x, uint a) internal returns (uint) { return x(a); } - function g(uint x) returns (uint) { return x + 1; } + function g(uint x) public returns (uint) { return x + 1; } } )"; @@ -9492,16 +9952,16 @@ BOOST_AUTO_TEST_CASE(pass_function_types_externally) { char const* sourceCode = R"( contract C { - function f(uint x) returns (uint) { + function f(uint x) public returns (uint) { return this.eval(this.g, x); } - function f2(uint x) returns (uint) { + function f2(uint x) public returns (uint) { return eval(this.g, x); } - function eval(function(uint) external returns (uint) x, uint a) returns (uint) { + function eval(function(uint) external returns (uint) x, uint a) public returns (uint) { return x(a); } - function g(uint x) returns (uint) { return x + 1; } + function g(uint x) public returns (uint) { return x + 1; } } )"; @@ -9514,8 +9974,8 @@ BOOST_AUTO_TEST_CASE(receive_external_function_type) { char const* sourceCode = R"( contract C { - function g() returns (uint) { return 7; } - function f(function() external returns (uint) g) returns (uint) { + function g() public returns (uint) { return 7; } + function f(function() external returns (uint) g) public returns (uint) { return g(); } } @@ -9532,8 +9992,8 @@ BOOST_AUTO_TEST_CASE(return_external_function_type) { char const* sourceCode = R"( contract C { - function g() {} - function f() returns (function() external) { + function g() public {} + function f() public returns (function() external) { return this.g; } } @@ -9550,18 +10010,18 @@ BOOST_AUTO_TEST_CASE(store_function) { char const* sourceCode = R"( contract Other { - function addTwo(uint x) returns (uint) { return x + 2; } + function addTwo(uint x) public returns (uint) { return x + 2; } } contract C { - function (function (uint) external returns (uint)) returns (uint) ev; + function (function (uint) external returns (uint)) internal returns (uint) ev; function (uint) external returns (uint) x; function store(function(uint) external returns (uint) y) { x = y; } - function eval(function(uint) external returns (uint) y) returns (uint) { + function eval(function(uint) external returns (uint) y) public returns (uint) { return y(7); } - function t() returns (uint) { + function t() public returns (uint) { ev = eval; this.store((new Other()).addTwo); return ev(x); @@ -9579,14 +10039,14 @@ BOOST_AUTO_TEST_CASE(store_function_in_constructor) contract C { uint public result_in_constructor; function (uint) internal returns (uint) x; - function C () { + constructor() public { x = double; result_in_constructor = use(2); } - function double(uint _arg) returns (uint _ret) { + function double(uint _arg) public returns (uint _ret) { _ret = _arg * 2; } - function use(uint _arg) returns (uint) { + function use(uint _arg) public returns (uint) { return x(_arg); } } @@ -9604,13 +10064,13 @@ BOOST_AUTO_TEST_CASE(store_internal_unused_function_in_constructor) char const* sourceCode = R"( contract C { function () internal returns (uint) x; - function C () { + constructor() public { x = unused; } function unused() internal returns (uint) { return 7; } - function t() returns (uint) { + function t() public returns (uint) { return x(); } } @@ -9626,10 +10086,10 @@ BOOST_AUTO_TEST_CASE(store_internal_unused_library_function_in_constructor) library L { function x() internal returns (uint) { return 7; } } contract C { function () internal returns (uint) x; - function C () { + constructor() public { x = L.x; } - function t() returns (uint) { + function t() public returns (uint) { return x(); } } @@ -9644,13 +10104,13 @@ BOOST_AUTO_TEST_CASE(same_function_in_construction_and_runtime) char const* sourceCode = R"( contract C { uint public initial; - function C() { + constructor() public { initial = double(2); } - function double(uint _arg) returns (uint _ret) { + function double(uint _arg) public returns (uint _ret) { _ret = _arg * 2; } - function runtime(uint _arg) returns (uint) { + function runtime(uint _arg) public returns (uint) { return double(_arg); } } @@ -9666,13 +10126,13 @@ BOOST_AUTO_TEST_CASE(same_function_in_construction_and_runtime_equality_check) char const* sourceCode = R"( contract C { function (uint) internal returns (uint) x; - function C() { + constructor() public { x = double; } - function test() returns (bool) { + function test() public returns (bool) { return x == double; } - function double(uint _arg) returns (uint _ret) { + function double(uint _arg) public returns (uint _ret) { _ret = _arg * 2; } } @@ -9686,7 +10146,7 @@ BOOST_AUTO_TEST_CASE(function_type_library_internal) { char const* sourceCode = R"( library Utils { - function reduce(uint[] memory array, function(uint, uint) returns (uint) f, uint init) internal returns (uint) { + function reduce(uint[] memory array, function(uint, uint) internal returns (uint) f, uint init) internal returns (uint) { for (uint i = 0; i < array.length; i++) { init = f(array[i], init); } @@ -9697,7 +10157,7 @@ BOOST_AUTO_TEST_CASE(function_type_library_internal) } } contract C { - function f(uint[] x) returns (uint) { + function f(uint[] x) public returns (uint) { return Utils.reduce(x, Utils.sum, 0); } } @@ -9712,21 +10172,21 @@ BOOST_AUTO_TEST_CASE(call_function_returning_function) { char const* sourceCode = R"( contract test { - function f0() returns (uint) { + function f0() public returns (uint) { return 2; } - function f1() internal returns (function() returns (uint)) { + function f1() internal returns (function() internal returns (uint)) { return f0; } - function f2() internal returns (function() returns (function () returns (uint))) { + function f2() internal returns (function() internal returns (function () internal returns (uint))) { return f1; } - function f3() internal returns (function() returns (function () returns (function () returns (uint)))) + function f3() internal returns (function() internal returns (function () internal returns (function () internal returns (uint)))) { return f2; } - function f() returns (uint) { - function() returns(function() returns(function() returns(function() returns(uint)))) x; + function f() public returns (uint) { + function() internal returns(function() internal returns(function() internal returns(function() internal returns(uint)))) x; x = f3; return x()()()(); } @@ -9757,11 +10217,11 @@ BOOST_AUTO_TEST_CASE(mapping_of_functions) success = true; } - function Flow() { + constructor() public { stages[msg.sender] = stage0; } - function f() returns (uint) { + function f() public returns (uint) { stages[msg.sender](); return 7; } @@ -9782,35 +10242,35 @@ BOOST_AUTO_TEST_CASE(packed_functions) char const* sourceCode = R"( contract C { // these should take the same slot - function() returns (uint) a; + function() internal returns (uint) a; function() external returns (uint) b; function() external returns (uint) c; - function() returns (uint) d; + function() internal returns (uint) d; uint8 public x; - function set() { + function set() public { x = 2; d = g; c = this.h; b = this.h; a = g; } - function t1() returns (uint) { + function t1() public returns (uint) { return a(); } - function t2() returns (uint) { + function t2() public returns (uint) { return b(); } - function t3() returns (uint) { + function t3() public returns (uint) { return a(); } - function t4() returns (uint) { + function t4() public returns (uint) { return b(); } - function g() returns (uint) { + function g() public returns (uint) { return 7; } - function h() returns (uint) { + function h() public returns (uint) { return 8; } } @@ -9829,12 +10289,12 @@ BOOST_AUTO_TEST_CASE(function_memory_array) { char const* sourceCode = R"( contract C { - function a(uint x) returns (uint) { return x + 1; } - function b(uint x) returns (uint) { return x + 2; } - function c(uint x) returns (uint) { return x + 3; } - function d(uint x) returns (uint) { return x + 5; } - function e(uint x) returns (uint) { return x + 8; } - function test(uint x, uint i) returns (uint) { + function a(uint x) public returns (uint) { return x + 1; } + function b(uint x) public returns (uint) { return x + 2; } + function c(uint x) public returns (uint) { return x + 3; } + function d(uint x) public returns (uint) { return x + 5; } + function e(uint x) public returns (uint) { return x + 8; } + function test(uint x, uint i) public returns (uint) { function(uint) internal returns (uint)[] memory arr = new function(uint) internal returns (uint)[](10); arr[0] = a; @@ -9860,17 +10320,17 @@ BOOST_AUTO_TEST_CASE(function_delete_storage) { char const* sourceCode = R"( contract C { - function a() returns (uint) { return 7; } + function a() public returns (uint) { return 7; } function() internal returns (uint) y; - function set() returns (uint) { + function set() public returns (uint) { y = a; return y(); } - function d() returns (uint) { + function d() public returns (uint) { delete y; return 1; } - function ca() returns (uint) { + function ca() public returns (uint) { return y(); } } @@ -9887,9 +10347,9 @@ BOOST_AUTO_TEST_CASE(function_delete_stack) { char const* sourceCode = R"( contract C { - function a() returns (uint) { return 7; } - function test() returns (uint) { - var y = a; + function a() public returns (uint) { return 7; } + function test() public returns (uint) { + function () returns (uint) y = a; delete y; y(); } @@ -9906,13 +10366,13 @@ BOOST_AUTO_TEST_CASE(copy_function_storage_array) contract C { function() internal returns (uint)[] x; function() internal returns (uint)[] y; - function test() returns (uint) { + function test() public returns (uint) { x.length = 10; x[9] = a; y = x; return y[9](); } - function a() returns (uint) { + function a() public returns (uint) { return 7; } } @@ -9927,7 +10387,7 @@ BOOST_AUTO_TEST_CASE(function_array_cross_calls) char const* sourceCode = R"( contract D { function f(function() external returns (function() external returns (uint))[] x) - returns (function() external returns (uint)[3] r) + public returns (function() external returns (uint)[3] r) { r[0] = x[0](); r[1] = x[1](); @@ -9935,23 +10395,23 @@ BOOST_AUTO_TEST_CASE(function_array_cross_calls) } } contract C { - function test() returns (uint, uint, uint) { + function test() public returns (uint, uint, uint) { function() external returns (function() external returns (uint))[] memory x = new function() external returns (function() external returns (uint))[](10); for (uint i = 0; i < x.length; i ++) x[i] = this.h; x[0] = this.htwo; - var y = (new D()).f(x); + function() external returns (uint)[3] memory y = (new D()).f(x); return (y[0](), y[1](), y[2]()); } - function e() returns (uint) { return 5; } - function f() returns (uint) { return 6; } - function g() returns (uint) { return 7; } + function e() public returns (uint) { return 5; } + function f() public returns (uint) { return 6; } + function g() public returns (uint) { return 7; } uint counter; - function h() returns (function() external returns (uint)) { + function h() public returns (function() external returns (uint)) { return counter++ == 0 ? this.f : this.g; } - function htwo() returns (function() external returns (uint)) { + function htwo() public returns (function() external returns (uint)) { return this.e; } } @@ -9965,10 +10425,10 @@ BOOST_AUTO_TEST_CASE(external_function_to_address) { char const* sourceCode = R"( contract C { - function f() returns (bool) { + function f() public returns (bool) { return address(this.f) == address(this); } - function g(function() external cb) returns (address) { + function g(function() external cb) public returns (address) { return address(cb); } } @@ -9986,12 +10446,12 @@ BOOST_AUTO_TEST_CASE(copy_internal_function_array_to_storage) contract C { function() internal returns (uint)[20] x; int mutex; - function one() returns (uint) { - function() internal returns (uint)[20] xmem; + function one() public returns (uint) { + function() internal returns (uint)[20] memory xmem; x = xmem; return 3; } - function two() returns (uint) { + function two() public returns (uint) { if (mutex > 0) return 7; mutex = 1; @@ -10055,7 +10515,7 @@ BOOST_AUTO_TEST_CASE(shift_left) { char const* sourceCode = R"( contract C { - function f(uint a, uint b) returns (uint) { + function f(uint a, uint b) public returns (uint) { return a << b; } } @@ -10073,7 +10533,7 @@ BOOST_AUTO_TEST_CASE(shift_left_uint32) { char const* sourceCode = R"( contract C { - function f(uint32 a, uint32 b) returns (uint) { + function f(uint32 a, uint32 b) public returns (uint) { return a << b; } } @@ -10090,7 +10550,7 @@ BOOST_AUTO_TEST_CASE(shift_left_uint8) { char const* sourceCode = R"( contract C { - function f(uint8 a, uint8 b) returns (uint) { + function f(uint8 a, uint8 b) public returns (uint) { return a << b; } } @@ -10105,7 +10565,7 @@ BOOST_AUTO_TEST_CASE(shift_left_larger_type) // This basically tests proper cleanup and conversion. It should not convert x to int8. char const* sourceCode = R"( contract C { - function f() returns (int8) { + function f() public returns (int8) { uint8 x = 254; int8 y = 1; return y << x; @@ -10120,7 +10580,7 @@ BOOST_AUTO_TEST_CASE(shift_left_assignment) { char const* sourceCode = R"( contract C { - function f(uint a, uint b) returns (uint) { + function f(uint a, uint b) public returns (uint) { a <<= b; return a; } @@ -10139,7 +10599,7 @@ BOOST_AUTO_TEST_CASE(shift_left_assignment_different_type) { char const* sourceCode = R"( contract C { - function f(uint a, uint8 b) returns (uint) { + function f(uint a, uint8 b) public returns (uint) { a <<= b; return a; } @@ -10157,7 +10617,7 @@ BOOST_AUTO_TEST_CASE(shift_right) { char const* sourceCode = R"( contract C { - function f(uint a, uint b) returns (uint) { + function f(uint a, uint b) public returns (uint) { return a >> b; } } @@ -10167,13 +10627,14 @@ BOOST_AUTO_TEST_CASE(shift_right) ABI_CHECK(callContractFunction("f(uint256,uint256)", u256(0x4266), u256(8)), encodeArgs(u256(0x42))); ABI_CHECK(callContractFunction("f(uint256,uint256)", u256(0x4266), u256(16)), encodeArgs(u256(0))); ABI_CHECK(callContractFunction("f(uint256,uint256)", u256(0x4266), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(uint256,uint256)", u256(1)<<255, u256(5)), encodeArgs(u256(1)<<250)); } BOOST_AUTO_TEST_CASE(shift_right_garbled) { char const* sourceCode = R"( contract C { - function f(uint8 a, uint8 b) returns (uint) { + function f(uint8 a, uint8 b) public returns (uint) { assembly { a := 0xffffffff } @@ -10187,11 +10648,44 @@ BOOST_AUTO_TEST_CASE(shift_right_garbled) ABI_CHECK(callContractFunction("f(uint8,uint8)", u256(0x0), u256(0x1004)), encodeArgs(u256(0xf))); } +BOOST_AUTO_TEST_CASE(shift_right_garbled_signed) +{ + char const* sourceCode = R"( + contract C { + function f(int8 a, uint8 b) public returns (int) { + assembly { + a := 0xfffffff0 + } + // Higher bits should be signextended before the shift + return a >> b; + } + function g(int8 a, uint8 b) public returns (int) { + assembly { + a := 0xf0 + } + // Higher bits should be signextended before the shift + return a >> b; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(3)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(4)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0xFF)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0x1003)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0x1004)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(3)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(4)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0xFF)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0x1003)), encodeArgs(u256(-2))); + ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0x1004)), encodeArgs(u256(-1))); +} + BOOST_AUTO_TEST_CASE(shift_right_uint32) { char const* sourceCode = R"( contract C { - function f(uint32 a, uint32 b) returns (uint) { + function f(uint32 a, uint32 b) public returns (uint) { return a >> b; } } @@ -10207,7 +10701,7 @@ BOOST_AUTO_TEST_CASE(shift_right_uint8) { char const* sourceCode = R"( contract C { - function f(uint8 a, uint8 b) returns (uint) { + function f(uint8 a, uint8 b) public returns (uint) { return a >> b; } } @@ -10221,7 +10715,7 @@ BOOST_AUTO_TEST_CASE(shift_right_assignment) { char const* sourceCode = R"( contract C { - function f(uint a, uint b) returns (uint) { + function f(uint a, uint b) public returns (uint) { a >>= b; return a; } @@ -10238,7 +10732,7 @@ BOOST_AUTO_TEST_CASE(shift_right_assignment_signed) { char const* sourceCode = R"( contract C { - function f(int a, int b) returns (int) { + function f(int a, int b) public returns (int) { a >>= b; return a; } @@ -10255,7 +10749,7 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue) { char const* sourceCode = R"( contract C { - function f(int a, int b) returns (int) { + function f(int a, int b) public returns (int) { return a >> b; } } @@ -10263,23 +10757,80 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(0)), encodeArgs(u256(-4266))); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(17)), encodeArgs(u256(-1))); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(0)), encodeArgs(u256(-4267))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(1)), encodeArgs(u256(-2134))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(17)), encodeArgs(u256(-1))); +} + +BOOST_AUTO_TEST_CASE(shift_right_negative_literal) +{ + char const* sourceCode = R"( + contract C { + function f1() public pure returns (bool) { + return (-4266 >> 0) == -4266; + } + function f2() public pure returns (bool) { + return (-4266 >> 1) == -2133; + } + function f3() public pure returns (bool) { + return (-4266 >> 4) == -267; + } + function f4() public pure returns (bool) { + return (-4266 >> 8) == -17; + } + function f5() public pure returns (bool) { + return (-4266 >> 16) == -1; + } + function f6() public pure returns (bool) { + return (-4266 >> 17) == -1; + } + function g1() public pure returns (bool) { + return (-4267 >> 0) == -4267; + } + function g2() public pure returns (bool) { + return (-4267 >> 1) == -2134; + } + function g3() public pure returns (bool) { + return (-4267 >> 4) == -267; + } + function g4() public pure returns (bool) { + return (-4267 >> 8) == -17; + } + function g5() public pure returns (bool) { + return (-4267 >> 16) == -1; + } + function g6() public pure returns (bool) { + return (-4267 >> 17) == -1; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f1()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("f2()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("f3()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("f4()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("f5()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("f6()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g1()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g2()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g3()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g4()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g5()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("g6()"), encodeArgs(true)); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int8) { char const* sourceCode = R"( contract C { - function f(int8 a, int8 b) returns (int) { + function f(int8 a, int8 b) public returns (int) { return a >> b; } } @@ -10287,67 +10838,67 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int8) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(0)), encodeArgs(u256(-66))); ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(1)), encodeArgs(u256(-33))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(4)), encodeArgs(u256(-4))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(8)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(4)), encodeArgs(u256(-5))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(8)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-66), u256(17)), encodeArgs(u256(-1))); ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(0)), encodeArgs(u256(-67))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(1)), encodeArgs(u256(-33))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(4)), encodeArgs(u256(-4))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(8)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(1)), encodeArgs(u256(-34))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(4)), encodeArgs(u256(-5))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(8)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(-67), u256(17)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int8) { char const* sourceCode = R"( contract C { - function f(int8 a, int8 b) returns (int8) { + function f(int8 a, int8 b) public returns (int8) { return a >> b; } } )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(0)), encodeArgs(u256(-103))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(1)), encodeArgs(u256(-51))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(2)), encodeArgs(u256(-25))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(4)), encodeArgs(u256(-6))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(8)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(1)), encodeArgs(u256(-52))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(2)), encodeArgs(u256(-26))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(4)), encodeArgs(u256(-7))); + ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(8)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int16) { char const* sourceCode = R"( contract C { - function f(int16 a, int16 b) returns (int16) { + function f(int16 a, int16 b) public returns (int16) { return a >> b; } } )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(0)), encodeArgs(u256(-103))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(1)), encodeArgs(u256(-51))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(2)), encodeArgs(u256(-25))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(4)), encodeArgs(u256(-6))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(8)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(1)), encodeArgs(u256(-52))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(2)), encodeArgs(u256(-26))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(4)), encodeArgs(u256(-7))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(8)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int32) { char const* sourceCode = R"( contract C { - function f(int32 a, int32 b) returns (int32) { + function f(int32 a, int32 b) public returns (int32) { return a >> b; } } )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(0)), encodeArgs(u256(-103))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(1)), encodeArgs(u256(-51))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(2)), encodeArgs(u256(-25))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(4)), encodeArgs(u256(-6))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(8)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(1)), encodeArgs(u256(-52))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(2)), encodeArgs(u256(-26))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(4)), encodeArgs(u256(-7))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(8)), encodeArgs(u256(-1))); } @@ -10355,7 +10906,7 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int16) { char const* sourceCode = R"( contract C { - function f(int16 a, int16 b) returns (int) { + function f(int16 a, int16 b) public returns (int) { return a >> b; } } @@ -10363,23 +10914,23 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int16) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(0)), encodeArgs(u256(-4266))); ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4266), u256(17)), encodeArgs(u256(-1))); ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(0)), encodeArgs(u256(-4267))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(1)), encodeArgs(u256(-2134))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int16,int16)", u256(-4267), u256(17)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int32) { char const* sourceCode = R"( contract C { - function f(int32 a, int32 b) returns (int) { + function f(int32 a, int32 b) public returns (int) { return a >> b; } } @@ -10387,23 +10938,23 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_int32) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(0)), encodeArgs(u256(-4266))); ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4266), u256(17)), encodeArgs(u256(-1))); ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(0)), encodeArgs(u256(-4267))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(1)), encodeArgs(u256(-2134))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int32,int32)", u256(-4267), u256(17)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_assignment) { char const* sourceCode = R"( contract C { - function f(int a, int b) returns (int) { + function f(int a, int b) public returns (int) { a >>= b; return a; } @@ -10412,26 +10963,26 @@ BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_assignment) compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(0)), encodeArgs(u256(-4266))); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4266), u256(17)), encodeArgs(u256(-1))); ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(0)), encodeArgs(u256(-4267))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(1)), encodeArgs(u256(-2133))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(4)), encodeArgs(u256(-266))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(8)), encodeArgs(u256(-16))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(16)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(17)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(1)), encodeArgs(u256(-2134))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(4)), encodeArgs(u256(-267))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(8)), encodeArgs(u256(-17))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(16)), encodeArgs(u256(-1))); + ABI_CHECK(callContractFunction("f(int256,int256)", u256(-4267), u256(17)), encodeArgs(u256(-1))); } BOOST_AUTO_TEST_CASE(shift_negative_rvalue) { char const* sourceCode = R"( contract C { - function f(int a, int b) returns (int) { + function f(int a, int b) public returns (int) { return a << b; } - function g(int a, int b) returns (int) { + function g(int a, int b) public returns (int) { return a >> b; } } @@ -10445,11 +10996,11 @@ BOOST_AUTO_TEST_CASE(shift_negative_rvalue_assignment) { char const* sourceCode = R"( contract C { - function f(int a, int b) returns (int) { + function f(int a, int b) public returns (int) { a <<= b; return a; } - function g(int a, int b) returns (int) { + function g(int a, int b) public returns (int) { a >>= b; return a; } @@ -10464,7 +11015,7 @@ BOOST_AUTO_TEST_CASE(shift_constant_left_assignment) { char const* sourceCode = R"( contract C { - function f() returns (uint a) { + function f() public returns (uint a) { a = 0x42; a <<= 8; } @@ -10478,7 +11029,7 @@ BOOST_AUTO_TEST_CASE(shift_constant_right_assignment) { char const* sourceCode = R"( contract C { - function f() returns (uint a) { + function f() public returns (uint a) { a = 0x4200; a >>= 8; } @@ -10492,7 +11043,7 @@ BOOST_AUTO_TEST_CASE(shift_cleanup) { char const* sourceCode = R"( contract C { - function f() returns (uint16 x) { + function f() public returns (uint16 x) { x = 0xffff; x += 32; x <<= 8; @@ -10508,7 +11059,7 @@ BOOST_AUTO_TEST_CASE(shift_cleanup_garbled) { char const* sourceCode = R"( contract C { - function f() returns (uint8 x) { + function f() public returns (uint8 x) { assembly { x := 0xffff } @@ -10524,10 +11075,10 @@ BOOST_AUTO_TEST_CASE(shift_overflow) { char const* sourceCode = R"( contract C { - function leftU(uint8 x, uint8 y) returns (uint8) { + function leftU(uint8 x, uint8 y) public returns (uint8) { return x << y; } - function leftS(int8 x, int8 y) returns (int8) { + function leftS(int8 x, int8 y) public returns (int8) { return x << y; } } @@ -10546,10 +11097,10 @@ BOOST_AUTO_TEST_CASE(shift_bytes) { char const* sourceCode = R"( contract C { - function left(bytes20 x, uint8 y) returns (bytes20) { + function left(bytes20 x, uint8 y) public returns (bytes20) { return x << y; } - function right(bytes20 x, uint8 y) returns (bytes20) { + function right(bytes20 x, uint8 y) public returns (bytes20) { return x >> y; } } @@ -10563,12 +11114,12 @@ BOOST_AUTO_TEST_CASE(shift_bytes_cleanup) { char const* sourceCode = R"( contract C { - function left(uint8 y) returns (bytes20) { + function left(uint8 y) public returns (bytes20) { bytes20 x; assembly { x := "12345678901234567890abcde" } return x << y; } - function right(uint8 y) returns (bytes20) { + function right(uint8 y) public returns (bytes20) { bytes20 x; assembly { x := "12345678901234567890abcde" } return x >> y; @@ -10584,7 +11135,7 @@ BOOST_AUTO_TEST_CASE(cleanup_in_compound_assign) { char const* sourceCode = R"( contract C { - function test() returns (uint, uint) { + function test() public returns (uint, uint) { uint32 a = 0xffffffff; uint16 x = uint16(a); uint16 y = x; @@ -10611,7 +11162,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_in_modifiers) throw; _; } - function f() m returns (bool) { + function f() m public returns (bool) { return true; } } @@ -10627,7 +11178,7 @@ BOOST_AUTO_TEST_CASE(packed_storage_overflow) uint16 x = 0x1234; uint16 a = 0xffff; uint16 b; - function f() returns (uint, uint, uint, uint) { + function f() public returns (uint, uint, uint, uint) { a++; uint c = b; delete b; @@ -10659,18 +11210,18 @@ BOOST_AUTO_TEST_CASE(include_creation_bytecode_only_once) contract D { bytes a = hex"1237651237125387136581271652831736512837126583171583712358126123765123712538713658127165283173651283712658317158371235812612376512371253871365812716528317365128371265831715837123581261237651237125387136581271652831736512837126583171583712358126"; bytes b = hex"1237651237125327136581271252831736512837126583171383712358126123765125712538713658127165253173651283712658357158371235812612376512371a5387136581271652a317365128371265a317158371235812612a765123712538a13658127165a83173651283712a58317158371235a126"; - function D(uint) {} + constructor(uint) public {} } contract Double { - function f() { + function f() public { new D(2); } - function g() { + function g() public { new D(3); } } contract Single { - function f() { + function f() public { new D(2); } } @@ -10690,7 +11241,7 @@ BOOST_AUTO_TEST_CASE(recursive_structs) S[] x; } S sstorage; - function f() returns (uint) { + function f() public returns (uint) { S memory s; s.x = new S[](10); delete s; @@ -10708,7 +11259,7 @@ BOOST_AUTO_TEST_CASE(invalid_instruction) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assembly { invalid } @@ -10723,14 +11274,14 @@ BOOST_AUTO_TEST_CASE(assert_require) { char const* sourceCode = R"( contract C { - function f() { + function f() public { assert(false); } - function g(bool val) returns (bool) { + function g(bool val) public returns (bool) { assert(val == true); return true; } - function h(bool val) returns (bool) { + function h(bool val) public returns (bool) { require(val); return true; } @@ -10749,11 +11300,11 @@ BOOST_AUTO_TEST_CASE(revert) char const* sourceCode = R"( contract C { uint public a = 42; - function f() { + function f() public { a = 1; revert(); } - function g() { + function g() public { a = 1; assembly { revert(0, 0) @@ -10848,7 +11399,7 @@ BOOST_AUTO_TEST_CASE(require_with_message) bool flagCopy = flag; require(flagCopy == false, internalFun()); } - function internalFun() returns (string) { + function internalFun() public returns (string) { flag = true; return "only on second run"; } @@ -10948,7 +11499,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_transfer) { char const* sourceCode = R"( contract D { - function() public payable { + function() external payable { revert("message"); } function f() public { @@ -10983,13 +11534,13 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_create) { char const* sourceCode = R"( contract E { - function E() { + constructor() public { revert("message"); } } contract D { function f() public { - var x = new E(); + E x = new E(); } } contract C { @@ -11047,7 +11598,7 @@ BOOST_AUTO_TEST_CASE(literal_empty_string) x = _x; a = _a; } - function g() { + function g() public { this.f("", 2); } } @@ -11064,22 +11615,22 @@ BOOST_AUTO_TEST_CASE(scientific_notation) { char const* sourceCode = R"( contract C { - function f() returns (uint) { + function f() public returns (uint) { return 2e10 wei; } - function g() returns (uint) { + function g() public returns (uint) { return 200e-2 wei; } - function h() returns (uint) { + function h() public returns (uint) { return 2.5e1; } - function i() returns (int) { + function i() public returns (int) { return -2e10; } - function j() returns (int) { + function j() public returns (int) { return -200e-2; } - function k() returns (int) { + function k() public returns (int) { return -2.5e1; } } @@ -11098,25 +11649,25 @@ BOOST_AUTO_TEST_CASE(interface_contract) char const* sourceCode = R"( interface I { event A(); - function f() returns (bool); - function() payable; + function f() public returns (bool); + function() external payable; } contract A is I { - function f() returns (bool) { + function f() public returns (bool) { return g(); } - function g() returns (bool) { + function g() public returns (bool) { return true; } - function() payable { + function() external payable { } } contract C { - function f(address _interfaceAddress) returns (bool) { + function f(address _interfaceAddress) public returns (bool) { I i = I(_interfaceAddress); return i.f(); } @@ -11132,12 +11683,12 @@ BOOST_AUTO_TEST_CASE(keccak256_assembly) { char const* sourceCode = R"( contract C { - function f() pure returns (bytes32 ret) { + function f() public pure returns (bytes32 ret) { assembly { ret := keccak256(0, 0) } } - function g() pure returns (bytes32 ret) { + function g() public pure returns (bytes32 ret) { assembly { 0 0 @@ -11145,26 +11696,11 @@ BOOST_AUTO_TEST_CASE(keccak256_assembly) =: ret } } - function h() pure returns (bytes32 ret) { - assembly { - ret := sha3(0, 0) - } - } - function i() pure returns (bytes32 ret) { - assembly { - 0 - 0 - sha3 - =: ret - } - } } )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); ABI_CHECK(callContractFunction("g()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); - ABI_CHECK(callContractFunction("h()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); - ABI_CHECK(callContractFunction("i()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); } BOOST_AUTO_TEST_CASE(multi_modifiers) @@ -11179,10 +11715,10 @@ BOOST_AUTO_TEST_CASE(multi_modifiers) x++; _; } - function f1() m1() { + function f1() m1() public { x += 7; } - function f2() m1() { + function f2() m1() public { x += 3; } } @@ -11198,7 +11734,7 @@ BOOST_AUTO_TEST_CASE(inlineasm_empty_let) { char const* sourceCode = R"( contract C { - function f() pure returns (uint a, uint b) { + function f() public pure returns (uint a, uint b) { assembly { let x let y, z @@ -11214,23 +11750,19 @@ BOOST_AUTO_TEST_CASE(inlineasm_empty_let) BOOST_AUTO_TEST_CASE(bare_call_invalid_address) { - char const* sourceCode = R"( + char const* sourceCode = R"YY( contract C { /// Calling into non-existant account is successful (creates the account) function f() external returns (bool) { - return address(0x4242).call(); - } - function g() external returns (bool) { - return address(0x4242).callcode(); + return address(0x4242).call(""); } function h() external returns (bool) { - return address(0x4242).delegatecall(); + return address(0x4242).delegatecall(""); } } - )"; + )YY"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(1))); ABI_CHECK(callContractFunction("h()"), encodeArgs(u256(1))); } @@ -11246,13 +11778,13 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value) return value; } function get_delegated() external returns (bool) { - return this.delegatecall(bytes4(sha3("get()"))); + return this.delegatecall(abi.encodeWithSignature("get()")); } function assert0() external view { assert(value == 0); } function assert0_delegated() external returns (bool) { - return this.delegatecall(bytes4(sha3("assert0()"))); + return this.delegatecall(abi.encodeWithSignature("assert0()")); } } )DELIMITER"; @@ -11275,19 +11807,18 @@ BOOST_AUTO_TEST_CASE(function_types_sig) char const* sourceCode = R"( contract C { uint public x; - function f() pure returns (bytes4) { + function f() public pure returns (bytes4) { return this.f.selector; } - function g() returns (bytes4) { + function g() public returns (bytes4) { function () pure external returns (bytes4) fun = this.f; return fun.selector; } - function h() returns (bytes4) { + function h() public returns (bytes4) { function () pure external returns (bytes4) fun = this.f; - var funvar = fun; - return funvar.selector; + return fun.selector; } - function i() pure returns (bytes4) { + function i() public pure returns (bytes4) { return this.x.selector; } } @@ -11306,13 +11837,13 @@ BOOST_AUTO_TEST_CASE(constant_string) bytes constant a = "\x03\x01\x02"; bytes constant b = hex"030102"; string constant c = "hello"; - function f() returns (bytes) { + function f() public returns (bytes) { return a; } - function g() returns (bytes) { + function g() public returns (bytes) { return b; } - function h() returns (bytes) { + function h() public returns (bytes) { return bytes(c); } } @@ -11327,18 +11858,18 @@ BOOST_AUTO_TEST_CASE(address_overload_resolution) { char const* sourceCode = R"( contract C { - function balance() returns (uint) { + function balance() public returns (uint) { return 1; } - function transfer(uint amount) returns (uint) { + function transfer(uint amount) public returns (uint) { return amount; } } contract D { - function f() returns (uint) { + function f() public returns (uint) { return (new C()).balance(); } - function g() returns (uint) { + function g() public returns (uint) { return (new C()).transfer(5); } } @@ -11512,22 +12043,22 @@ BOOST_AUTO_TEST_CASE(snark) Pairing.G1Point K; Pairing.G1Point H; } - function f() returns (bool) { + function f() public returns (bool) { Pairing.G1Point memory p1; Pairing.G1Point memory p2; p1.X = 1; p1.Y = 2; p2.X = 1; p2.Y = 2; - var explict_sum = Pairing.add(p1, p2); - var scalar_prod = Pairing.mul(p1, 2); + Pairing.G1Point memory explict_sum = Pairing.add(p1, p2); + Pairing.G1Point memory scalar_prod = Pairing.mul(p1, 2); return (explict_sum.X == scalar_prod.X && explict_sum.Y == scalar_prod.Y); } - function g() returns (bool) { + function g() public returns (bool) { Pairing.G1Point memory x = Pairing.add(Pairing.P1(), Pairing.negate(Pairing.P1())); // should be zero return (x.X == 0 && x.Y == 0); } - function testMul() returns (bool) { + function testMul() public returns (bool) { Pairing.G1Point memory p; // @TODO The points here are reported to be not well-formed p.X = 14125296762497065001182820090155008161146766663259912659363835465243039841726; @@ -11537,7 +12068,7 @@ BOOST_AUTO_TEST_CASE(snark) p.X == 18256332256630856740336504687838346961237861778318632856900758565550522381207 && p.Y == 6976682127058094634733239494758371323697222088503263230319702770853579280803; } - function pair() returns (bool) { + function pair() public returns (bool) { Pairing.G2Point memory fiveTimesP2 = Pairing.G2Point( [4540444681147253467785307942530223364530218361853237193970751657229138047649, 20954117799226682825035885491234530437475518021362091509513177301640194298072], [11631839690097995216017572651900167465857396346217730511548857041925508482915, 21508930868448350162258892668132814424284302804699005394342512102884055673846] @@ -11607,7 +12138,7 @@ BOOST_AUTO_TEST_CASE(snark) return 0; } event Verified(string); - function verifyTx() returns (bool) { + function verifyTx() public returns (bool) { uint[] memory input = new uint[](9); Proof memory proof; proof.A = Pairing.G1Point(12873740738727497448187997291915224677121726020054032516825496230827252793177, 21804419174137094775122804775419507726154084057848719988004616848382402162497); @@ -11630,7 +12161,7 @@ BOOST_AUTO_TEST_CASE(snark) input[7] = 9643208548031422463313148630985736896287522941726746581856185889848792022807; input[8] = 18066496933330839731877828156604; if (verify(input, proof) == 0) { - Verified("Transaction successfully verified."); + emit Verified("Transaction successfully verified."); return true; } else { return false; @@ -11653,17 +12184,17 @@ BOOST_AUTO_TEST_CASE(abi_encode) { char const* sourceCode = R"( contract C { - function f0() returns (bytes) { + function f0() public returns (bytes) { return abi.encode(); } - function f1() returns (bytes) { + function f1() public returns (bytes) { return abi.encode(1, 2); } - function f2() returns (bytes) { + function f2() public returns (bytes) { string memory x = "abc"; return abi.encode(1, x, 2); } - function f3() returns (bytes r) { + function f3() public returns (bytes r) { // test that memory is properly allocated string memory x = "abc"; r = abi.encode(1, x, 2); @@ -11672,7 +12203,7 @@ BOOST_AUTO_TEST_CASE(abi_encode) y[0] = "e"; require(y[0] == "e"); } - function f4() returns (bytes) { + function f4() public returns (bytes) { bytes4 x = "abcd"; return abi.encode(bytes2(x)); } @@ -11975,7 +12506,6 @@ BOOST_AUTO_TEST_CASE(abi_encode_call) BOOST_AUTO_TEST_CASE(staticcall_for_view_and_pure) { char const* sourceCode = R"( - pragma experimental "v0.5.0"; contract C { uint x; function f() public returns (uint) { @@ -12021,7 +12551,7 @@ BOOST_AUTO_TEST_CASE(swap_peephole_optimisation) { char const* sourceCode = R"( contract C { - function lt(uint a, uint b) returns (bool c) { + function lt(uint a, uint b) public returns (bool c) { assembly { a b @@ -12030,7 +12560,7 @@ BOOST_AUTO_TEST_CASE(swap_peephole_optimisation) =: c } } - function add(uint a, uint b) returns (uint c) { + function add(uint a, uint b) public returns (uint c) { assembly { a b @@ -12039,7 +12569,7 @@ BOOST_AUTO_TEST_CASE(swap_peephole_optimisation) =: c } } - function div(uint a, uint b) returns (uint c) { + function div(uint a, uint b) public returns (uint c) { assembly { a b @@ -12067,7 +12597,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople) return; char const* sourceCode = R"( contract C { - function shl(uint a, uint b) returns (uint c) { + function shl(uint a, uint b) public returns (uint c) { assembly { a b @@ -12075,7 +12605,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople) =: c } } - function shr(uint a, uint b) returns (uint c) { + function shr(uint a, uint b) public returns (uint c) { assembly { a b @@ -12083,7 +12613,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople) =: c } } - function sar(uint a, uint b) returns (uint c) { + function sar(uint a, uint b) public returns (uint c) { assembly { a b @@ -12113,7 +12643,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) return; char const* sourceCode = R"( contract C { - function shl_1() returns (bool) { + function shl_1() public returns (bool) { uint c; assembly { 1 @@ -12124,7 +12654,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) assert(c == 4); return true; } - function shl_2() returns (bool) { + function shl_2() public returns (bool) { uint c; assembly { 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff @@ -12135,7 +12665,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) assert(c == 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe); return true; } - function shl_3() returns (bool) { + function shl_3() public returns (bool) { uint c; assembly { 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff @@ -12146,7 +12676,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) assert(c == 0); return true; } - function shr_1() returns (bool) { + function shr_1() public returns (bool) { uint c; assembly { 3 @@ -12157,7 +12687,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) assert(c == 1); return true; } - function shr_2() returns (bool) { + function shr_2() public returns (bool) { uint c; assembly { 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff @@ -12168,7 +12698,7 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) assert(c == 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); return true; } - function shr_3() returns (bool) { + function shr_3() public returns (bool) { uint c; assembly { 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff @@ -12210,6 +12740,43 @@ BOOST_AUTO_TEST_CASE(senders_balance) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(27))); } +BOOST_AUTO_TEST_CASE(write_storage_external) +{ + char const* sourceCode = R"( + contract C { + uint public x; + function f(uint y) public payable { + x = y; + } + function g(uint y) external { + x = y; + } + function h() public { + this.g(12); + } + } + contract D { + C c = new C(); + function f() public payable returns (uint) { + c.g(3); + return c.x(); + } + function g() public returns (uint) { + c.g(8); + return c.x(); + } + function h() public returns (uint) { + c.h(); + return c.x(); + } + } + )"; + compileAndRun(sourceCode, 0, "D"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(3)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(8)); + ABI_CHECK(callContractFunction("h()"), encodeArgs(12)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index ad26ce6b..26b7914f 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -77,7 +77,7 @@ Declaration const& resolveDeclaration( ) { ASTNode const* scope = &_sourceUnit; - // bracers are required, cause msvc couldnt handle this macro in for statement + // bracers are required, cause msvc couldn't handle this macro in for statement for (string const& namePart: _namespacedName) { auto declarations = _resolver.resolveName(namePart, scope); @@ -175,7 +175,7 @@ BOOST_AUTO_TEST_CASE(literal_true) { char const* sourceCode = R"( contract test { - function f() { var x = true; } + function f() public { bool x = true; } } )"; bytes code = compileFirstExpression(sourceCode); @@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE(literal_false) { char const* sourceCode = R"( contract test { - function f() { var x = false; } + function f() { bool x = false; } } )"; bytes code = compileFirstExpression(sourceCode); @@ -201,7 +201,7 @@ BOOST_AUTO_TEST_CASE(int_literal) { char const* sourceCode = R"( contract test { - function f() { var x = 0x12345678901234567890; } + function f() { uint x = 0x12345678901234567890; } } )"; bytes code = compileFirstExpression(sourceCode); @@ -215,8 +215,8 @@ BOOST_AUTO_TEST_CASE(int_with_wei_ether_subdenomination) { char const* sourceCode = R"( contract test { - function test () { - var x = 1 wei; + constructor() { + uint x = 1 wei; } } )"; @@ -231,7 +231,7 @@ BOOST_AUTO_TEST_CASE(int_with_szabo_ether_subdenomination) char const* sourceCode = R"( contract test { function test () { - var x = 1 szabo; + uint x = 1 szabo; } } )"; @@ -245,9 +245,9 @@ BOOST_AUTO_TEST_CASE(int_with_finney_ether_subdenomination) { char const* sourceCode = R"( contract test { - function test () + constructor() { - var x = 1 finney; + uint x = 1 finney; } } )"; @@ -261,8 +261,8 @@ BOOST_AUTO_TEST_CASE(int_with_ether_ether_subdenomination) { char const* sourceCode = R"( contract test { - function test () { - var x = 1 ether; + constructor() { + uint x = 1 ether; } } )"; @@ -276,7 +276,7 @@ BOOST_AUTO_TEST_CASE(comparison) { char const* sourceCode = R"( contract test { - function f() { var x = (0x10aa < 0x11aa) != true; } + function f() { bool x = (0x10aa < 0x11aa) != true; } } )"; bytes code = compileFirstExpression(sourceCode); @@ -294,7 +294,7 @@ BOOST_AUTO_TEST_CASE(short_circuiting) { char const* sourceCode = R"( contract test { - function f() { var x = true != (4 <= 8 + 10 || 9 != 2); } + function f() { bool x = true != (4 <= 8 + 10 || 9 != 2); } } )"; bytes code = compileFirstExpression(sourceCode); @@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(short_circuiting) BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } -BOOST_AUTO_TEST_CASE(arithmetics) +BOOST_AUTO_TEST_CASE(arithmetic) { char const* sourceCode = R"( contract test { @@ -384,7 +384,7 @@ BOOST_AUTO_TEST_CASE(unary_inc_dec) { char const* sourceCode = R"( contract test { - function f(uint a) returns (uint x) { x = --a ^ (a-- ^ (++a ^ a++)); } + function f(uint a) public returns (uint x) { x = --a ^ (a-- ^ (++a ^ a++)); } } )"; bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "x"}}); @@ -490,7 +490,7 @@ BOOST_AUTO_TEST_CASE(intermediately_overflowing_literals) // have been applied char const* sourceCode = R"( contract test { - function f() { var x = (0xffffffffffffffffffffffffffffffffffffffff * 0xffffffffffffffffffffffffff01) & 0xbf; } + function f() { uint8 x = (0x00ffffffffffffffffffffffffffffffffffffffff * 0xffffffffffffffffffffffffff01) & 0xbf; } } )"; bytes code = compileFirstExpression(sourceCode); @@ -509,9 +509,9 @@ BOOST_AUTO_TEST_CASE(blockhash) } )"; - auto blockhashFun = make_shared<FunctionType>(strings{"uint256"}, strings{"bytes32"}, + auto blockhashFun = make_shared<FunctionType>(strings{"uint256"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View); - + bytes code = compileFirstExpression(sourceCode, {}, {}, {make_shared<MagicVariableDeclaration>("blockhash", blockhashFun)}); bytes expectation({byte(Instruction::PUSH1), 0x03, @@ -523,32 +523,17 @@ BOOST_AUTO_TEST_CASE(gas_left) { char const* sourceCode = R"( contract test { - function f() returns (uint256 val) { - return msg.gas; - } - } - )"; - bytes code = compileFirstExpression( - sourceCode, {}, {}, - {make_shared<MagicVariableDeclaration>("msg", make_shared<MagicType>(MagicType::Kind::Message))} - ); - - bytes expectation({byte(Instruction::GAS)}); - BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); - - sourceCode = R"( - contract test { - function f() returns (uint256 val) { + function f() public returns (uint256 val) { return gasleft(); } } )"; - code = compileFirstExpression( + bytes code = compileFirstExpression( sourceCode, {}, {}, {make_shared<MagicVariableDeclaration>("gasleft", make_shared<FunctionType>(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft))} ); - expectation = bytes({byte(Instruction::GAS)}); + bytes expectation = bytes({byte(Instruction::GAS)}); BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index ab7cfb12..6ae9d8f9 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -43,280 +43,6 @@ namespace test BOOST_FIXTURE_TEST_SUITE(SolidityNameAndTypeResolution, AnalysisFramework) -BOOST_AUTO_TEST_CASE(name_references) -{ - char const* text = R"( - contract test { - uint256 variable; - function f(uint256) public returns (uint out) { f(variable); test; out; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(undeclared_name) -{ - char const* text = R"( - contract test { - uint256 variable; - function f(uint256 arg) public { - f(notfound); - } - } - )"; - CHECK_ERROR(text, DeclarationError, "Undeclared identifier."); -} - -BOOST_AUTO_TEST_CASE(undeclared_name_is_not_fatal) -{ - char const* text = R"( - contract test { - uint256 variable; - function f(uint256 arg) public { - f(notfound); - f(notfound); - } - } - )"; - CHECK_ERROR_ALLOW_MULTI(text, DeclarationError, (vector<string>{"Undeclared identifier", "Undeclared identifier"})); -} - -BOOST_AUTO_TEST_CASE(reference_to_later_declaration) -{ - char const* text = R"( - contract test { - function g() public { f(); } - function f() public {} - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(type_inference_smoke_test) -{ - char const* text = R"( - contract test { - function f(uint256 arg1, uint32 arg2) public returns (bool ret) { - var x = arg1 + arg2 == 8; ret = x; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(type_checking_return) -{ - char const* text = R"( - contract test { - function f() public returns (bool r) { return 1 >= 2; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(type_checking_return_wrong_number) -{ - char const* text = R"( - contract test { - function f() public returns (bool r1, bool r2) { return 1 >= 2; } - } - )"; - CHECK_ERROR(text, TypeError, "Different number of arguments in return statement than in returns declaration."); -} - -BOOST_AUTO_TEST_CASE(type_checking_return_wrong_type) -{ - char const* text = R"( - contract test { - function f() public returns (uint256 r) { return 1 >= 2; } - } - )"; - CHECK_ERROR(text, TypeError, "Return argument type bool is not implicitly convertible to expected type (type of first return variable) uint256."); -} - -BOOST_AUTO_TEST_CASE(type_checking_function_call) -{ - char const* text = R"( - contract test { - function f() public returns (bool) { return g(12, true) == 3; } - function g(uint256, bool) public returns (uint256) { } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(type_conversion_for_comparison) -{ - char const* text = R"( - contract test { - function f() public { uint32(2) == int64(2); } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(type_conversion_for_comparison_invalid) -{ - char const* text = R"( - contract test { - function f() public { int32(2) == uint64(2); } - } - )"; - CHECK_ERROR(text, TypeError, "Operator == not compatible with types int32 and uint64"); -} - -BOOST_AUTO_TEST_CASE(type_inference_explicit_conversion) -{ - char const* text = R"( - contract test { - function f() public returns (int256 r) { var x = int256(uint32(2)); return x; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(large_string_literal) -{ - char const* text = R"( - contract test { - function f() public { var x = "123456789012345678901234567890123"; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(balance) -{ - char const* text = R"( - contract test { - function fun() public { - uint256 x = address(0).balance; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(balance_invalid) -{ - char const* text = R"( - contract test { - function fun() public { - address(0).balance = 7; - } - } - )"; - CHECK_ERROR(text, TypeError, "Expression has to be an lvalue."); -} - -BOOST_AUTO_TEST_CASE(assignment_to_mapping) -{ - char const* text = R"( - contract test { - struct str { - mapping(uint=>uint) map; - } - str data; - function fun() public { - var a = data.map; - data.map = a; - } - } - )"; - CHECK_ERROR(text, TypeError, "Mappings cannot be assigned to."); -} - -BOOST_AUTO_TEST_CASE(assignment_to_struct) -{ - char const* text = R"( - contract test { - struct str { - mapping(uint=>uint) map; - } - str data; - function fun() public { - var a = data; - data = a; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(forward_function_reference) -{ - char const* text = R"( - contract First { - function fun() public returns (bool) { - return Second(1).fun(1, true, 3) > 0; - } - } - contract Second { - function fun(uint, bool, uint) public returns (uint) { - if (First(2).fun() == true) return 1; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(comparison_bitop_precedence) -{ - char const* text = R"( - contract First { - function fun() public returns (bool ret) { - return 1 & 2 == 8 & 9 && 1 ^ 2 < 4 | 6; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(comparison_of_function_types) -{ - char const* text = R"( - contract C { - function f() public returns (bool ret) { - return this.f < this.f; - } - } - )"; - CHECK_ERROR(text, TypeError, "Operator < not compatible"); - text = R"( - contract C { - function f() public returns (bool ret) { - return f < f; - } - } - )"; - CHECK_ERROR(text, TypeError, "Operator < not compatible"); - text = R"( - contract C { - function f() public returns (bool ret) { - return f == f; - } - function g() public returns (bool ret) { - return f != f; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(comparison_of_mapping_types) -{ - char const* text = R"( - contract C { - mapping(uint => uint) x; - function f() public returns (bool ret) { - var y = x; - return x == y; - } - } - )"; - CHECK_ERROR(text, TypeError, "Operator == not compatible"); -} - BOOST_AUTO_TEST_CASE(function_no_implementation) { SourceUnit const* sourceUnit = nullptr; @@ -337,7 +63,7 @@ BOOST_AUTO_TEST_CASE(abstract_contract) { SourceUnit const* sourceUnit = nullptr; char const* text = R"( - contract base { function foo(); } + contract base { function foo() public; } contract derived is base { function foo() public {} } )"; sourceUnit = parseAndAnalyse(text); @@ -356,7 +82,7 @@ BOOST_AUTO_TEST_CASE(abstract_contract_with_overload) { SourceUnit const* sourceUnit = nullptr; char const* text = R"( - contract base { function foo(bool); } + contract base { function foo(bool) public; } contract derived is base { function foo(uint) public {} } )"; sourceUnit = parseAndAnalyse(text); @@ -369,34 +95,12 @@ BOOST_AUTO_TEST_CASE(abstract_contract_with_overload) BOOST_CHECK(!derived->annotation().unimplementedFunctions.empty()); } -BOOST_AUTO_TEST_CASE(create_abstract_contract) -{ - char const* text = R"( - contract base { function foo(); } - contract derived { - base b; - function foo() public { b = new base(); } - } - )"; - CHECK_ERROR(text, TypeError, "Trying to create an instance of an abstract contract."); -} - -BOOST_AUTO_TEST_CASE(redeclare_implemented_abstract_function_as_abstract) -{ - char const* text = R"( - contract base { function foo(); } - contract derived is base { function foo() public {} } - contract wrong is derived { function foo(); } - )"; - CHECK_ERROR(text, TypeError, "Redeclaring an already implemented function as abstract"); -} - BOOST_AUTO_TEST_CASE(implement_abstract_via_constructor) { SourceUnit const* sourceUnit = nullptr; char const* text = R"( - contract base { function foo(); } - contract foo is base { function foo() public {} } + contract base { function foo() public; } + contract foo is base { constructor() public {} } )"; sourceUnit = parseAndAnalyse(text); std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->nodes(); @@ -499,12 +203,12 @@ BOOST_AUTO_TEST_CASE(external_structs) pragma experimental ABIEncoderV2; contract Test { enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - struct Empty {} + struct Simple { uint i; } struct Nested { X[2][] a; uint y; } - struct X { bytes32 x; Test t; Empty[] e; } - function f(ActionChoices, uint, Empty) external {} + struct X { bytes32 x; Test t; Simple[] s; } + function f(ActionChoices, uint, Simple) external {} function g(Test, Nested) external {} - function h(function(Nested) external returns (uint)[]) external {} + function h(function(Nested memory) external returns (uint)[]) external {} function i(Nested[]) external {} } )"; @@ -514,10 +218,10 @@ BOOST_AUTO_TEST_CASE(external_structs) { auto functions = contract->definedFunctions(); BOOST_REQUIRE(!functions.empty()); - BOOST_CHECK_EQUAL("f(uint8,uint256,())", functions[0]->externalSignature()); - BOOST_CHECK_EQUAL("g(address,((bytes32,address,()[])[2][],uint256))", functions[1]->externalSignature()); + BOOST_CHECK_EQUAL("f(uint8,uint256,(uint256))", functions[0]->externalSignature()); + BOOST_CHECK_EQUAL("g(address,((bytes32,address,(uint256)[])[2][],uint256))", functions[1]->externalSignature()); BOOST_CHECK_EQUAL("h(function[])", functions[2]->externalSignature()); - BOOST_CHECK_EQUAL("i(((bytes32,address,()[])[2][],uint256)[])", functions[3]->externalSignature()); + BOOST_CHECK_EQUAL("i(((bytes32,address,(uint256)[])[2][],uint256)[])", functions[3]->externalSignature()); } } @@ -527,12 +231,12 @@ BOOST_AUTO_TEST_CASE(external_structs_in_libraries) pragma experimental ABIEncoderV2; library Test { enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - struct Empty {} + struct Simple { uint i; } struct Nested { X[2][] a; uint y; } - struct X { bytes32 x; Test t; Empty[] e; } - function f(ActionChoices, uint, Empty) external {} + struct X { bytes32 x; Test t; Simple[] s; } + function f(ActionChoices, uint, Simple) external {} function g(Test, Nested) external {} - function h(function(Nested) external returns (uint)[]) external {} + function h(function(Nested memory) external returns (uint)[]) external {} function i(Nested[]) external {} } )"; @@ -542,7 +246,7 @@ BOOST_AUTO_TEST_CASE(external_structs_in_libraries) { auto functions = contract->definedFunctions(); BOOST_REQUIRE(!functions.empty()); - BOOST_CHECK_EQUAL("f(Test.ActionChoices,uint256,Test.Empty)", functions[0]->externalSignature()); + BOOST_CHECK_EQUAL("f(Test.ActionChoices,uint256,Test.Simple)", functions[0]->externalSignature()); BOOST_CHECK_EQUAL("g(Test,Test.Nested)", functions[1]->externalSignature()); BOOST_CHECK_EQUAL("h(function[])", functions[2]->externalSignature()); BOOST_CHECK_EQUAL("i(Test.Nested[])", functions[3]->externalSignature()); @@ -568,336 +272,6 @@ BOOST_AUTO_TEST_CASE(struct_with_mapping_in_library) } } -BOOST_AUTO_TEST_CASE(functions_with_identical_structs_in_interface) -{ - char const* text = R"( - pragma experimental ABIEncoderV2; - - contract C { - struct S1 { } - struct S2 { } - function f(S1) pure {} - function f(S2) pure {} - } - )"; - CHECK_ERROR(text, TypeError, "Function overload clash during conversion to external types for arguments"); -} - -BOOST_AUTO_TEST_CASE(functions_with_different_structs_in_interface) -{ - char const* text = R"( - pragma experimental ABIEncoderV2; - - contract C { - struct S1 { function() external a; } - struct S2 { bytes24 a; } - function f(S1) pure {} - function f(S2) pure {} - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(functions_with_stucts_of_non_external_types_in_interface) -{ - char const* text = R"( - pragma experimental ABIEncoderV2; - - contract C { - struct S { function() internal a; } - function f(S) {} - } - )"; - CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions."); -} - -BOOST_AUTO_TEST_CASE(functions_with_stucts_of_non_external_types_in_interface_2) -{ - char const* text = R"( - pragma experimental ABIEncoderV2; - - contract C { - struct S { mapping(uint => uint) a; } - function f(S) {} - } - )"; - CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions."); -} - -BOOST_AUTO_TEST_CASE(functions_with_stucts_of_non_external_types_in_interface_nested) -{ - char const* text = R"( - pragma experimental ABIEncoderV2; - - contract C { - struct T { mapping(uint => uint) a; } - struct S { T[][2] b; } - function f(S) {} - } - )"; - CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions."); -} - -BOOST_AUTO_TEST_CASE(returning_multi_dimensional_arrays_new_abi) -{ - char const* text = R"( - pragma experimental ABIEncoderV2; - - contract C { - function f() public pure returns (string[][]) {} - } - )"; - CHECK_WARNING(text, "Experimental features"); -} - -BOOST_AUTO_TEST_CASE(returning_multi_dimensional_arrays) -{ - char const* text = R"( - contract C { - function f() public pure returns (string[][]) {} - } - )"; - CHECK_ERROR(text, TypeError, "only supported in the new experimental ABI encoder"); -} - -BOOST_AUTO_TEST_CASE(returning_multi_dimensional_static_arrays) -{ - char const* text = R"( - contract C { - function f() public pure returns (uint[][2]) {} - } - )"; - CHECK_ERROR(text, TypeError, "only supported in the new experimental ABI encoder"); -} - -BOOST_AUTO_TEST_CASE(returning_arrays_in_structs_new_abi) -{ - char const* text = R"( - pragma experimental ABIEncoderV2; - - contract C { - struct S { string[] s; } - function f() public pure returns (S) {} - } - )"; - CHECK_WARNING(text, "Experimental features"); -} - -BOOST_AUTO_TEST_CASE(returning_arrays_in_structs_arrays) -{ - char const* text = R"( - contract C { - struct S { string[] s; } - function f() public pure returns (S x) {} - } - )"; - CHECK_ERROR(text, TypeError, "only supported in the new experimental ABI encoder"); -} - -BOOST_AUTO_TEST_CASE(function_external_call_allowed_conversion) -{ - char const* text = R"( - contract C {} - contract Test { - function externalCall() public { - C arg; - this.g(arg); - } - function g (C c) external {} - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(function_external_call_not_allowed_conversion) -{ - char const* text = R"( - contract C {} - contract Test { - function externalCall() public { - address arg; - this.g(arg); - } - function g (C c) external {} - } - )"; - CHECK_ERROR(text, TypeError, "Invalid type for argument in function call. Invalid implicit conversion from address to contract C requested."); -} - -BOOST_AUTO_TEST_CASE(function_internal_allowed_conversion) -{ - char const* text = R"( - contract C { - uint a; - } - contract Test { - C a; - function g (C c) public {} - function internalCall() public { - g(a); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(function_internal_not_allowed_conversion) -{ - char const* text = R"( - contract C { - uint a; - } - contract Test { - address a; - function g (C c) public {} - function internalCall() public { - g(a); - } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid type for argument in function call. Invalid implicit conversion from address to contract C requested."); -} - -BOOST_AUTO_TEST_CASE(hash_collision_in_interface) -{ - char const* text = R"( - contract test { - function gsf() public { } - function tgeo() public { } - } - )"; - CHECK_ERROR(text, TypeError, "Function signature hash collision for tgeo()"); -} - -BOOST_AUTO_TEST_CASE(inheritance_basic) -{ - char const* text = R"( - contract base { uint baseMember; struct BaseType { uint element; } } - contract derived is base { - BaseType data; - function f() public { baseMember = 7; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inheritance_diamond_basic) -{ - char const* text = R"( - contract root { function rootFunction() public {} } - contract inter1 is root { function f() public {} } - contract inter2 is root { function f() public {} } - contract derived is root, inter2, inter1 { - function g() public { f(); rootFunction(); } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(cyclic_inheritance) -{ - char const* text = R"( - contract A is B { } - contract B is A { } - )"; - CHECK_ERROR_ALLOW_MULTI(text, TypeError, (vector<string>{"Definition of base has to precede definition of derived contract"})); -} - -BOOST_AUTO_TEST_CASE(legal_override_direct) -{ - char const* text = R"( - contract B { function f() public {} } - contract C is B { function f(uint i) public {} } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(legal_override_indirect) -{ - char const* text = R"( - contract A { function f(uint a) public {} } - contract B { function f() public {} } - contract C is A, B { } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(illegal_override_visibility) -{ - char const* text = R"( - contract B { function f() internal {} } - contract C is B { function f() public {} } - )"; - CHECK_ERROR(text, TypeError, "Overriding function visibility differs"); -} - -BOOST_AUTO_TEST_CASE(complex_inheritance) -{ - char const* text = R"( - contract A { function f() public { uint8 x = C(0).g(); } } - contract B { function f() public {} function g() public returns (uint8) {} } - contract C is A, B { } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(missing_base_constructor_arguments) -{ - char const* text = R"( - contract A { function A(uint a) public { } } - contract B is A { } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(base_constructor_arguments_override) -{ - char const* text = R"( - contract A { function A(uint a) public { } } - contract B is A { } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(implicit_derived_to_base_conversion) -{ - char const* text = R"( - contract A { } - contract B is A { - function f() public { A a = B(1); } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(implicit_base_to_derived_conversion) -{ - char const* text = R"( - contract A { } - contract B is A { - function f() public { B b = A(1); } - } - )"; - CHECK_ERROR(text, TypeError, "Type contract A is not implicitly convertible to expected type contract B."); -} - -BOOST_AUTO_TEST_CASE(super_excludes_current_contract) -{ - char const* text = R"( - contract A { - function b() public {} - } - - contract B is A { - function f() public { - super.f(); - } - } - )"; - - CHECK_ERROR(text, TypeError, "Member \"f\" not found or not visible after argument-dependent lookup in contract super B"); -} - BOOST_AUTO_TEST_CASE(state_variable_accessors) { char const* text = R"( @@ -939,20 +313,6 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) BOOST_CHECK(function->stateMutability() == StateMutability::View); } -BOOST_AUTO_TEST_CASE(function_clash_with_state_variable_accessor) -{ - char const* text = R"( - contract test { - function fun() public { - uint64(2); - } - uint256 foo; - function foo() public {} - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier already declared."); -} - BOOST_AUTO_TEST_CASE(private_state_variable) { char const* text = R"( @@ -975,1388 +335,6 @@ BOOST_AUTO_TEST_CASE(private_state_variable) BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of an internal variable should not exist"); } -BOOST_AUTO_TEST_CASE(base_class_state_variable_accessor) -{ - char const* text = R"( - // test for issue #1126 https://github.com/ethereum/cpp-ethereum/issues/1126 - contract Parent { - uint256 public m_aMember; - } - contract Child is Parent { - function foo() public returns (uint256) { return Parent.m_aMember; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(struct_accessor_one_array_only) -{ - char const* sourceCode = R"( - contract test { - struct Data { uint[15] m_array; } - Data public data; - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Internal or recursive type is not allowed for public state variables."); -} - -BOOST_AUTO_TEST_CASE(base_class_state_variable_internal_member) -{ - char const* text = R"( - contract Parent { - uint256 internal m_aMember; - } - contract Child is Parent { - function foo() public returns (uint256) { return Parent.m_aMember; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(state_variable_member_of_wrong_class1) -{ - char const* text = R"( - contract Parent1 { - uint256 internal m_aMember1; - } - contract Parent2 is Parent1 { - uint256 internal m_aMember2; - } - contract Child is Parent2 { - function foo() public returns (uint256) { return Parent2.m_aMember1; } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"m_aMember1\" not found or not visible after argument-dependent lookup in type(contract Parent2)"); -} - -BOOST_AUTO_TEST_CASE(state_variable_member_of_wrong_class2) -{ - char const* text = R"( - contract Parent1 { - uint256 internal m_aMember1; - } - contract Parent2 is Parent1 { - uint256 internal m_aMember2; - } - contract Child is Parent2 { - function foo() public returns (uint256) { return Child.m_aMember2; } - uint256 public m_aMember3; - } - )"; - CHECK_ERROR(text, TypeError, "Member \"m_aMember2\" not found or not visible after argument-dependent lookup in type(contract Child)"); -} - -BOOST_AUTO_TEST_CASE(fallback_function) -{ - char const* text = R"( - contract C { - uint x; - function() public { x = 2; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(fallback_function_with_arguments) -{ - char const* text = R"( - contract C { - uint x; - function(uint a) public { x = 2; } - } - )"; - CHECK_ERROR(text, TypeError, "Fallback function cannot take parameters."); -} - -BOOST_AUTO_TEST_CASE(fallback_function_in_library) -{ - char const* text = R"( - library C { - function() public {} - } - )"; - CHECK_ERROR(text, TypeError, "Libraries cannot have fallback functions."); -} - -BOOST_AUTO_TEST_CASE(fallback_function_with_return_parameters) -{ - char const* text = R"( - contract C { - function() public returns (uint) { } - } - )"; - CHECK_ERROR(text, TypeError, "Fallback function cannot return values."); -} - -BOOST_AUTO_TEST_CASE(fallback_function_twice) -{ - char const* text = R"( - contract C { - uint x; - function() public { x = 2; } - function() public { x = 3; } - } - )"; - CHECK_ERROR_ALLOW_MULTI(text, DeclarationError, (vector<string>{ - "Only one fallback function is" - })); -} - -BOOST_AUTO_TEST_CASE(fallback_function_inheritance) -{ - char const* text = R"( - contract A { - uint x; - function() public { x = 1; } - } - contract C is A { - function() public { x = 2; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(event) -{ - char const* text = R"( - contract c { - event e(uint indexed a, bytes3 indexed s, bool indexed b); - function f() public { e(2, "abc", true); } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(event_too_many_indexed) -{ - char const* text = R"( - contract c { - event e(uint indexed a, bytes3 indexed b, bool indexed c, uint indexed d); - } - )"; - CHECK_ERROR(text, TypeError, "More than 3 indexed arguments for event."); -} - -BOOST_AUTO_TEST_CASE(anonymous_event_four_indexed) -{ - char const* text = R"( - contract c { - event e(uint indexed a, bytes3 indexed b, bool indexed c, uint indexed d) anonymous; - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(anonymous_event_too_many_indexed) -{ - char const* text = R"( - contract c { - event e(uint indexed a, bytes3 indexed b, bool indexed c, uint indexed d, uint indexed e) anonymous; - } - )"; - CHECK_ERROR(text, TypeError, "More than 4 indexed arguments for anonymous event."); -} - -BOOST_AUTO_TEST_CASE(events_with_same_name) -{ - char const* text = R"( - contract TestIt { - event A(); - event A(uint i); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(events_with_same_name_unnamed_arguments) -{ - char const* text = R"( - contract test { - event A(uint); - event A(uint, uint); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(events_with_same_name_different_types) -{ - char const* text = R"( - contract test { - event A(uint); - event A(bytes); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(double_event_declaration) -{ - char const* text = R"( - contract test { - event A(uint i); - event A(uint i); - } - )"; - CHECK_ERROR(text, DeclarationError, "Event with same name and arguments defined twice."); -} - -BOOST_AUTO_TEST_CASE(double_event_declaration_ignores_anonymous) -{ - char const* text = R"( - contract test { - event A(uint i); - event A(uint i) anonymous; - } - )"; - CHECK_ERROR(text, DeclarationError, "Event with same name and arguments defined twice."); -} - -BOOST_AUTO_TEST_CASE(double_event_declaration_ignores_indexed) -{ - char const* text = R"( - contract test { - event A(uint i); - event A(uint indexed i); - } - )"; - CHECK_ERROR(text, DeclarationError, "Event with same name and arguments defined twice."); -} - -BOOST_AUTO_TEST_CASE(event_call) -{ - char const* text = R"( - contract c { - event e(uint a, bytes3 indexed s, bool indexed b); - function f() public { e(2, "abc", true); } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(event_function_inheritance_clash) -{ - char const* text = R"( - contract A { - function dup() public returns (uint) { - return 1; - } - } - contract B { - event dup(); - } - contract C is A, B { - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier already declared."); -} - -BOOST_AUTO_TEST_CASE(function_event_inheritance_clash) -{ - char const* text = R"( - contract B { - event dup(); - } - contract A { - function dup() public returns (uint) { - return 1; - } - } - contract C is B, A { - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier already declared."); -} - -BOOST_AUTO_TEST_CASE(function_event_in_contract_clash) -{ - char const* text = R"( - contract A { - event dup(); - function dup() public returns (uint) { - return 1; - } - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier already declared."); -} - -BOOST_AUTO_TEST_CASE(event_inheritance) -{ - char const* text = R"( - contract base { - event e(uint a, bytes3 indexed s, bool indexed b); - } - contract c is base { - function f() public { e(2, "abc", true); } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(multiple_events_argument_clash) -{ - char const* text = R"( - contract c { - event e1(uint a, uint e1, uint e2); - event e2(uint a, uint e1, uint e2); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(access_to_default_function_visibility) -{ - char const* text = R"( - contract c { - function f() public {} - } - contract d { - function g() public { c(0).f(); } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(access_to_internal_function) -{ - char const* text = R"( - contract c { - function f() internal {} - } - contract d { - function g() public { c(0).f(); } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"f\" not found or not visible after argument-dependent lookup in contract c"); -} - -BOOST_AUTO_TEST_CASE(access_to_default_state_variable_visibility) -{ - char const* text = R"( - contract c { - uint a; - } - contract d { - function g() public { c(0).a(); } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"a\" not found or not visible after argument-dependent lookup in contract c"); -} - -BOOST_AUTO_TEST_CASE(access_to_internal_state_variable) -{ - char const* text = R"( - contract c { - uint public a; - } - contract d { - function g() public { c(0).a(); } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(error_count_in_named_args) -{ - char const* sourceCode = R"( - contract test { - function a(uint a, uint b) public returns (uint r) { - r = a + b; - } - function b() public returns (uint r) { - r = a({a: 1}); - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Wrong argument count for function call: 1 arguments given but expected 2."); -} - -BOOST_AUTO_TEST_CASE(empty_in_named_args) -{ - char const* sourceCode = R"( - contract test { - function a(uint a, uint b) public returns (uint r) { - r = a + b; - } - function b() public returns (uint r) { - r = a({}); - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Wrong argument count for function call: 0 arguments given but expected 2."); -} - -BOOST_AUTO_TEST_CASE(duplicate_parameter_names_in_named_args) -{ - char const* sourceCode = R"( - contract test { - function a(uint a, uint b) public returns (uint r) { - r = a + b; - } - function b() public returns (uint r) { - r = a({a: 1, a: 2}); - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Duplicate named argument."); -} - -BOOST_AUTO_TEST_CASE(invalid_parameter_names_in_named_args) -{ - char const* sourceCode = R"( - contract test { - function a(uint a, uint b) public returns (uint r) { - r = a + b; - } - function b() public returns (uint r) { - r = a({a: 1, c: 2}); - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Named argument does not match function declaration."); -} - -BOOST_AUTO_TEST_CASE(empty_name_input_parameter) -{ - char const* text = R"( - contract test { - function f(uint) public { } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(constant_input_parameter) -{ - char const* text = R"( - contract test { - function f(uint[] constant a) public { } - } - )"; - CHECK_ERROR_ALLOW_MULTI(text, TypeError, (vector<string>{ - "Illegal use of \"constant\" specifier", - "Constants of non-value type not yet implemented", - "Uninitialized \"constant\" variable" - })); -} - -BOOST_AUTO_TEST_CASE(empty_name_return_parameter) -{ - char const* text = R"( - contract test { - function f() public returns (bool) { } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one) -{ - char const* text = R"( - contract test { - function f(uint, uint k) public returns (uint ret_k) { - return k; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(empty_name_return_parameter_with_named_one) -{ - char const* text = R"( - contract test { - function f() public returns (uint ret_k, uint) { - return 5; - } - } - )"; - CHECK_ERROR(text, TypeError, "Different number of arguments in return statement than in returns declaration."); -} - -BOOST_AUTO_TEST_CASE(disallow_declaration_of_void_type) -{ - char const* sourceCode = R"( - contract c { - function f() public { var (x) = f(); } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Not enough components (0) in value to assign all variables (1)."); -} - -BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units) -{ - char const* sourceCodeFine = R"( - contract c { - function c () public { - a = 115792089237316195423570985008687907853269984665640564039458; - } - uint256 a; - } - )"; - CHECK_SUCCESS(sourceCodeFine); - char const* sourceCode = R"( - contract c { - function c () public { - a = 115792089237316195423570985008687907853269984665640564039458 ether; - } - uint256 a; - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Type int_const 1157...(70 digits omitted)...0000 is not implicitly convertible to expected type uint256."); -} - -BOOST_AUTO_TEST_CASE(exp_operator_exponent_too_big) -{ - char const* sourceCode = R"( - contract test { - function f() public returns (uint d) { return 2 ** 10000000000; } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Operator ** not compatible with types int_const 2 and int_const 10000000000"); -} - -BOOST_AUTO_TEST_CASE(exp_warn_literal_base) -{ - char const* sourceCode = R"( - contract test { - function f() pure public returns(uint) { - uint8 x = 100; - return 10**x; - } - } - )"; - CHECK_WARNING(sourceCode, "might overflow"); - sourceCode = R"( - contract test { - function f() pure public returns(uint) { - uint8 x = 100; - return uint8(10)**x; - } - } - )"; - CHECK_SUCCESS(sourceCode); - sourceCode = R"( - contract test { - function f() pure public returns(uint) { - return 2**80; - } - } - )"; - CHECK_SUCCESS(sourceCode); -} - -BOOST_AUTO_TEST_CASE(shift_warn_literal_base) -{ - char const* sourceCode = R"( - contract test { - function f() pure public returns(uint) { - uint8 x = 100; - return 10 << x; - } - } - )"; - CHECK_WARNING(sourceCode, "might overflow"); - sourceCode = R"( - contract test { - function f() pure public returns(uint) { - uint8 x = 100; - return uint8(10) << x; - } - } - )"; - CHECK_SUCCESS(sourceCode); - sourceCode = R"( - contract test { - function f() pure public returns(uint) { - return 2 << 80; - } - } - )"; - CHECK_SUCCESS(sourceCode); - sourceCode = R"( - contract test { - function f() pure public returns(uint) { - uint8 x = 100; - return 10 >> x; - } - } - )"; - CHECK_SUCCESS(sourceCode); -} - -BOOST_AUTO_TEST_CASE(warn_var_from_zero) -{ - char const* sourceCode = R"( - contract test { - function f() pure public returns (uint) { - var i = 1; - return i; - } - } - )"; - CHECK_WARNING_ALLOW_MULTI(sourceCode, (std::vector<std::string>{ - "uint8, which can hold values between 0 and 255", - "Use of the \"var\" keyword is deprecated." - })); - sourceCode = R"( - contract test { - function f() pure public { - var i = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; - i; - } - } - )"; - CHECK_WARNING_ALLOW_MULTI(sourceCode, (std::vector<std::string>{ - "uint256, which can hold values between 0 and 115792089237316195423570985008687907853269984665640564039457584007913129639935", - "Use of the \"var\" keyword is deprecated." - })); - sourceCode = R"( - contract test { - function f() pure public { - var i = -2; - i; - } - } - )"; - CHECK_WARNING_ALLOW_MULTI(sourceCode, (std::vector<std::string>{ - "int8, which can hold values between -128 and 127", - "Use of the \"var\" keyword is deprecated." - })); - sourceCode = R"( - contract test { - function f() pure public { - for (var i = 0; i < msg.data.length; i++) { } - } - } - )"; - CHECK_WARNING_ALLOW_MULTI(sourceCode, (std::vector<std::string>{ - "uint8, which can hold", - "Use of the \"var\" keyword is deprecated." - })); -} - -BOOST_AUTO_TEST_CASE(enum_member_access) -{ - char const* text = R"( - contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test() - { - choices = ActionChoices.GoStraight; - } - ActionChoices choices; - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(enum_member_access_accross_contracts) -{ - char const* text = R"( - contract Interface { - enum MyEnum { One, Two } - } - contract Impl { - function test() public returns (Interface.MyEnum) { - return Interface.MyEnum.One; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(enum_invalid_member_access) -{ - char const* text = R"( - contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test() public { - choices = ActionChoices.RunAroundWavingYourHands; - } - ActionChoices choices; - } - )"; - CHECK_ERROR(text, TypeError, "Member \"RunAroundWavingYourHands\" not found or not visible after argument-dependent lookup in type(enum test.ActionChoices)"); -} - -BOOST_AUTO_TEST_CASE(enum_invalid_direct_member_access) -{ - char const* text = R"( - contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test() public { - choices = Sit; - } - ActionChoices choices; - } - )"; - CHECK_ERROR(text, DeclarationError, "Undeclared identifier."); -} - -BOOST_AUTO_TEST_CASE(enum_explicit_conversion_is_okay) -{ - char const* text = R"( - contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test() public { - a = uint256(ActionChoices.GoStraight); - b = uint64(ActionChoices.Sit); - } - uint256 a; - uint64 b; - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(int_to_enum_explicit_conversion_is_okay) -{ - char const* text = R"( - contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test() public { - a = 2; - b = ActionChoices(a); - } - uint256 a; - ActionChoices b; - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(enum_implicit_conversion_is_not_okay_256) -{ - char const* text = R"( - contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test() public { - a = ActionChoices.GoStraight; - } - uint256 a; - } - )"; - CHECK_ERROR(text, TypeError, "Type enum test.ActionChoices is not implicitly convertible to expected type uint256."); -} - -BOOST_AUTO_TEST_CASE(enum_implicit_conversion_is_not_okay_64) -{ - char const* text = R"( - contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test() public { - b = ActionChoices.Sit; - } - uint64 b; - } - )"; - CHECK_ERROR(text, TypeError, "Type enum test.ActionChoices is not implicitly convertible to expected type uint64."); -} - -BOOST_AUTO_TEST_CASE(enum_to_enum_conversion_is_not_okay) -{ - char const* text = R"( - contract test { - enum Paper { Up, Down, Left, Right } - enum Ground { North, South, West, East } - function test() public { - Ground(Paper.Up); - } - } - )"; - CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed from \"enum test.Paper\" to \"enum test.Ground\"."); -} - -BOOST_AUTO_TEST_CASE(enum_duplicate_values) -{ - char const* text = R"( - contract test { - enum ActionChoices { GoLeft, GoRight, GoLeft, Sit } - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier already declared."); -} - -BOOST_AUTO_TEST_CASE(enum_name_resolution_under_current_contract_name) -{ - char const* text = R"( - contract A { - enum Foo { - First, - Second - } - - function a() public { - A.Foo; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(private_visibility) -{ - char const* sourceCode = R"( - contract base { - function f() private {} - } - contract derived is base { - function g() public { f(); } - } - )"; - CHECK_ERROR(sourceCode, DeclarationError, "Undeclared identifier."); -} - -BOOST_AUTO_TEST_CASE(private_visibility_via_explicit_base_access) -{ - char const* sourceCode = R"( - contract base { - function f() private {} - } - contract derived is base { - function g() public { base.f(); } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Member \"f\" not found or not visible after argument-dependent lookup in type(contract base)"); -} - -BOOST_AUTO_TEST_CASE(external_visibility) -{ - char const* sourceCode = R"( - contract c { - function f() external {} - function g() public { f(); } - } - )"; - CHECK_ERROR(sourceCode, DeclarationError, "Undeclared identifier."); -} - -BOOST_AUTO_TEST_CASE(similar_name_suggestions_expected) -{ - char const* sourceCode = R"( - contract c { - function func() {} - function g() public { fun(); } - } - )"; - CHECK_ERROR(sourceCode, DeclarationError, "Undeclared identifier. Did you mean \"func\"?"); -} - -BOOST_AUTO_TEST_CASE(no_name_suggestion) -{ - char const* sourceCode = R"( - contract c { - function g() public { fun(); } - } - )"; - CHECK_ERROR(sourceCode, DeclarationError, "Undeclared identifier."); -} - -BOOST_AUTO_TEST_CASE(multiple_similar_suggestions) -{ - char const* sourceCode = R"( - contract c { - function g() public { - uint var1 = 1; - uint var2 = 1; - uint var3 = 1; - uint var4 = 1; - uint var5 = varx; - } - } - )"; - CHECK_ERROR(sourceCode, DeclarationError, "Undeclared identifier. Did you mean \"var1\", \"var2\", \"var3\", \"var4\" or \"var5\"?"); -} - -BOOST_AUTO_TEST_CASE(multiple_scopes_suggestions) -{ - char const* sourceCode = R"( - contract c { - uint log9 = 2; - function g() public { - uint log8 = 3; - uint var1 = lgox; - } - } - )"; - CHECK_ERROR(sourceCode, DeclarationError, "Undeclared identifier. Did you mean \"log8\", \"log9\", \"log0\", \"log1\", \"log2\", \"log3\" or \"log4\"?"); -} - -BOOST_AUTO_TEST_CASE(inheritence_suggestions) -{ - char const* sourceCode = R"( - contract a { function func() public {} } - contract c is a { - function g() public { - uint var1 = fun(); - } - } - )"; - CHECK_ERROR(sourceCode, DeclarationError, "Undeclared identifier. Did you mean \"func\"?"); -} - -BOOST_AUTO_TEST_CASE(no_spurious_suggestions) -{ - char const* sourceCode = R"( - contract c { - function g() public { - uint va = 1; - uint vb = vaxyz; - } - } - )"; - CHECK_ERROR(sourceCode, DeclarationError, "Undeclared identifier."); - - sourceCode = R"( - contract c { - function g() public { - uint va = 1; - uint vb = x; - } - } - )"; - CHECK_ERROR(sourceCode, DeclarationError, "Undeclared identifier."); -} - -BOOST_AUTO_TEST_CASE(external_base_visibility) -{ - char const* sourceCode = R"( - contract base { - function f() external {} - } - contract derived is base { - function g() public { base.f(); } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Member \"f\" not found or not visible after argument-dependent lookup in type(contract base)"); -} - -BOOST_AUTO_TEST_CASE(external_argument_assign) -{ - char const* sourceCode = R"( - contract c { - function f(uint a) external { a = 1; } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Expression has to be an lvalue."); -} - -BOOST_AUTO_TEST_CASE(external_argument_increment) -{ - char const* sourceCode = R"( - contract c { - function f(uint a) external { a++; } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Expression has to be an lvalue."); -} - -BOOST_AUTO_TEST_CASE(external_argument_delete) -{ - char const* sourceCode = R"( - contract c { - function f(uint a) external { delete a; } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Expression has to be an lvalue."); -} - -BOOST_AUTO_TEST_CASE(test_for_bug_override_function_with_bytearray_type) -{ - char const* sourceCode = R"( - contract Vehicle { - function f(bytes) external returns (uint256 r) {r = 1;} - } - contract Bike is Vehicle { - function f(bytes) external returns (uint256 r) {r = 42;} - } - )"; - CHECK_SUCCESS(sourceCode); -} - -BOOST_AUTO_TEST_CASE(array_with_nonconstant_length) -{ - char const* text = R"( - contract c { - function f(uint a) public { uint8[a] x; } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression."); -} - -BOOST_AUTO_TEST_CASE(array_with_negative_length) -{ - char const* text = R"( - contract c { - function f(uint a) public { uint8[-1] x; } - } - )"; - CHECK_ERROR(text, TypeError, "Array with negative length specified"); -} - -BOOST_AUTO_TEST_CASE(array_copy_with_different_types1) -{ - char const* text = R"( - contract c { - bytes a; - uint[] b; - function f() public { b = a; } - } - )"; - CHECK_ERROR(text, TypeError, "Type bytes storage ref is not implicitly convertible to expected type uint256[] storage ref."); -} - -BOOST_AUTO_TEST_CASE(array_copy_with_different_types2) -{ - char const* text = R"( - contract c { - uint32[] a; - uint8[] b; - function f() public { b = a; } - } - )"; - CHECK_ERROR(text, TypeError, "Type uint32[] storage ref is not implicitly convertible to expected type uint8[] storage ref."); -} - -BOOST_AUTO_TEST_CASE(array_copy_with_different_types_conversion_possible) -{ - char const* text = R"( - contract c { - uint32[] a; - uint8[] b; - function f() public { a = b; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(array_copy_with_different_types_static_dynamic) -{ - char const* text = R"( - contract c { - uint32[] a; - uint8[80] b; - function f() public { a = b; } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(array_copy_with_different_types_dynamic_static) -{ - char const* text = R"( - contract c { - uint[] a; - uint[80] b; - function f() public { b = a; } - } - )"; - CHECK_ERROR(text, TypeError, "Type uint256[] storage ref is not implicitly convertible to expected type uint256[80] storage ref."); -} - -BOOST_AUTO_TEST_CASE(array_of_undeclared_type) -{ - char const* text = R"( - contract c { - a[] public foo; - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier not found or not unique."); -} - -BOOST_AUTO_TEST_CASE(storage_variable_initialization_with_incorrect_type_int) -{ - char const* text = R"( - contract c { - uint8 a = 1000; - } - )"; - CHECK_ERROR(text, TypeError, "Type int_const 1000 is not implicitly convertible to expected type uint8."); -} - -BOOST_AUTO_TEST_CASE(storage_variable_initialization_with_incorrect_type_string) -{ - char const* text = R"( - contract c { - uint a = "abc"; - } - )"; - CHECK_ERROR(text, TypeError, "Type literal_string \"abc\" is not implicitly convertible to expected type uint256."); -} - -BOOST_AUTO_TEST_CASE(test_byte_is_alias_of_byte1) -{ - char const* text = R"( - contract c { - bytes arr; - function f() public { byte a = arr[0];} - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(warns_assigning_decimal_to_bytesxx) -{ - char const* text = R"( - contract Foo { - bytes32 a = 7; - } - )"; - CHECK_WARNING(text, "Decimal literal assigned to bytesXX variable will be left-aligned."); -} - -BOOST_AUTO_TEST_CASE(does_not_warn_assigning_hex_number_to_bytesxx) -{ - char const* text = R"( - contract Foo { - bytes32 a = 0x1234; - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(explicit_conversion_from_decimal_to_bytesxx) -{ - char const* text = R"( - contract Foo { - bytes32 a = bytes32(7); - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(assigning_value_to_const_variable) -{ - char const* text = R"( - contract Foo { - function changeIt() public { x = 9; } - uint constant x = 56; - } - )"; - CHECK_ERROR(text, TypeError, "Cannot assign to a constant variable."); -} - -BOOST_AUTO_TEST_CASE(assigning_state_to_const_variable_0_4_x) -{ - char const* text = R"( - contract C { - address constant x = msg.sender; - } - )"; - CHECK_WARNING(text, "Initial value for constant variable has to be compile-time constant."); -} - -BOOST_AUTO_TEST_CASE(assigning_state_to_const_variable) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - - contract C { - address constant x = msg.sender; - } - )"; - CHECK_ERROR(text, TypeError, "Initial value for constant variable has to be compile-time constant."); -} - -BOOST_AUTO_TEST_CASE(constant_string_literal_disallows_assignment) -{ - char const* text = R"( - contract Test { - string constant x = "abefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabca"; - function f() public { - // Even if this is made possible in the future, we should not allow assignment - // to elements of constant arrays. - x[0] = "f"; - } - } - )"; - CHECK_ERROR(text, TypeError, "Index access for string is not possible."); -} - -BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_conversion) -{ - char const* text = R"( - contract C { - C constant x = C(0x123); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_expression) -{ - char const* text = R"( - contract C { - uint constant x = 0x123 + 0x456; - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak) -{ - char const* text = R"( - contract C { - bytes32 constant x = keccak256("abc"); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(assignment_to_const_array_vars) -{ - char const* text = R"( - contract C { - uint[3] constant x = [uint(1), 2, 3]; - } - )"; - CHECK_ERROR(text, TypeError, "implemented"); -} - -BOOST_AUTO_TEST_CASE(assignment_to_const_string_bytes) -{ - char const* text = R"( - contract C { - bytes constant a = "\x00\x01\x02"; - bytes constant b = hex"000102"; - string constant c = "hello"; - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(constant_struct) -{ - char const* text = R"( - contract C { - struct S { uint x; uint[] y; } - S constant x = S(5, new uint[](4)); - } - )"; - CHECK_ERROR(text, TypeError, "implemented"); -} - -BOOST_AUTO_TEST_CASE(address_is_constant) -{ - char const* text = R"( - contract C { - address constant x = 0x1212121212121212121212121212121212121212; - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(uninitialized_const_variable) -{ - char const* text = R"( - contract Foo { - uint constant y; - } - )"; - CHECK_ERROR(text, TypeError, "Uninitialized \"constant\" variable."); -} - -BOOST_AUTO_TEST_CASE(overloaded_function_cannot_resolve) -{ - char const* sourceCode = R"( - contract test { - function f() public returns (uint) { return 1; } - function f(uint a) public returns (uint) { return a; } - function g() public returns (uint) { return f(3, 5); } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "No matching declaration found after argument-dependent lookup."); -} - -BOOST_AUTO_TEST_CASE(ambiguous_overloaded_function) -{ - char const* sourceCode = R"( - contract test { - function f(uint8 a) public returns (uint) { return a; } - function f(uint a) public returns (uint) { return 2 * a; } - // literal 1 can be both converted to uint and uint8, so the call is ambiguous. - function g() public returns (uint) { return f(1); } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "No unique declaration found after argument-dependent lookup."); -} - -BOOST_AUTO_TEST_CASE(assignment_of_nonoverloaded_function) -{ - char const* sourceCode = R"( - contract test { - function f(uint a) public returns (uint) { return 2 * a; } - function g() public returns (uint) { var x = f; return x(7); } - } - )"; - CHECK_SUCCESS(sourceCode); -} - -BOOST_AUTO_TEST_CASE(assignment_of_overloaded_function) -{ - char const* sourceCode = R"( - contract test { - function f() public returns (uint) { return 1; } - function f(uint a) public returns (uint) { return 2 * a; } - function g() public returns (uint) { var x = f; return x(7); } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "No matching declaration found after variable lookup."); -} - -BOOST_AUTO_TEST_CASE(external_types_clash) -{ - char const* sourceCode = R"( - contract base { - enum a { X } - function f(a) public { } - } - contract test is base { - function f(uint8 a) public { } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Function overload clash during conversion to external types for arguments."); -} - -BOOST_AUTO_TEST_CASE(override_changes_return_types) -{ - char const* sourceCode = R"( - contract base { - function f(uint a) public returns (uint) { } - } - contract test is base { - function f(uint a) public returns (uint8) { } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Overriding function return types differ"); -} - -BOOST_AUTO_TEST_CASE(equal_overload) -{ - char const* sourceCode = R"( - contract C { - function test(uint a) public returns (uint b) { } - function test(uint a) external {} - } - )"; - CHECK_ALLOW_MULTI(sourceCode, (vector<pair<Error::Type, string>>{ - {Error::Type::DeclarationError, "Function with same name and arguments defined twice."}, - {Error::Type::TypeError, "Overriding function visibility differs"} - })); -} - -BOOST_AUTO_TEST_CASE(uninitialized_var) -{ - char const* sourceCode = R"( - contract C { - function f() public returns (uint) { var x; return 2; } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Assignment necessary for type detection."); -} - BOOST_AUTO_TEST_CASE(string) { char const* sourceCode = R"( @@ -2368,2342 +346,29 @@ BOOST_AUTO_TEST_CASE(string) BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); } -BOOST_AUTO_TEST_CASE(invalid_utf8_implicit) -{ - char const* sourceCode = R"( - contract C { - string s = "\xa0\x00"; - } - )"; - CHECK_ERROR(sourceCode, TypeError, "invalid UTF-8"); -} - -BOOST_AUTO_TEST_CASE(invalid_utf8_explicit) -{ - char const* sourceCode = R"( - contract C { - string s = string("\xa0\x00"); - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Explicit type conversion not allowed"); -} - -BOOST_AUTO_TEST_CASE(large_utf8_codepoint) -{ - char const* sourceCode = R"( - contract C { - string s = "\xf0\x9f\xa6\x84"; - } - )"; - CHECK_SUCCESS(sourceCode); -} - -BOOST_AUTO_TEST_CASE(string_index) -{ - char const* sourceCode = R"( - contract C { - string s; - function f() public { var a = s[2]; } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Index access for string is not possible."); -} - -BOOST_AUTO_TEST_CASE(string_length) -{ - char const* sourceCode = R"( - contract C { - string s; - function f() public { var a = s.length; } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Member \"length\" not found or not visible after argument-dependent lookup in string storage ref"); -} - -BOOST_AUTO_TEST_CASE(negative_integers_to_signed_out_of_bound) -{ - char const* sourceCode = R"( - contract test { - int8 public i = -129; - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Type int_const -129 is not implicitly convertible to expected type int8."); -} - -BOOST_AUTO_TEST_CASE(negative_integers_to_signed_min) -{ - char const* sourceCode = R"( - contract test { - int8 public i = -128; - } - )"; - BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); -} - -BOOST_AUTO_TEST_CASE(positive_integers_to_signed_out_of_bound) -{ - char const* sourceCode = R"( - contract test { - int8 public j = 128; - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Type int_const 128 is not implicitly convertible to expected type int8."); -} - -BOOST_AUTO_TEST_CASE(positive_integers_to_signed_out_of_bound_max) -{ - char const* sourceCode = R"( - contract test { - int8 public j = 127; - } - )"; - BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); -} - -BOOST_AUTO_TEST_CASE(negative_integers_to_unsigned) -{ - char const* sourceCode = R"( - contract test { - uint8 public x = -1; - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Type int_const -1 is not implicitly convertible to expected type uint8."); -} - -BOOST_AUTO_TEST_CASE(positive_integers_to_unsigned_out_of_bound) -{ - char const* sourceCode = R"( - contract test { - uint8 public x = 700; - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Type int_const 700 is not implicitly convertible to expected type uint8."); -} - -BOOST_AUTO_TEST_CASE(integer_boolean_operators) -{ - char const* sourceCode1 = R"( - contract test { function() public { uint x = 1; uint y = 2; x || y; } } - )"; - CHECK_ERROR(sourceCode1, TypeError, "Operator || not compatible with types uint256 and uint256"); - char const* sourceCode2 = R"( - contract test { function() public { uint x = 1; uint y = 2; x && y; } } - )"; - CHECK_ERROR(sourceCode2, TypeError, "Operator && not compatible with types uint256 and uint256"); - char const* sourceCode3 = R"( - contract test { function() public { uint x = 1; !x; } } - )"; - CHECK_ERROR(sourceCode3, TypeError, "Unary operator ! cannot be applied to type uint256"); -} - -BOOST_AUTO_TEST_CASE(exp_signed_variable) -{ - char const* sourceCode1 = R"( - contract test { function() public { uint x = 3; int y = -4; x ** y; } } - )"; - CHECK_ERROR(sourceCode1, TypeError, "Operator ** not compatible with types uint256 and int256"); - char const* sourceCode2 = R"( - contract test { function() public { uint x = 3; int y = -4; y ** x; } } - )"; - CHECK_ERROR(sourceCode2, TypeError, "Operator ** not compatible with types int256 and uint256"); - char const* sourceCode3 = R"( - contract test { function() public { int x = -3; int y = -4; x ** y; } } - )"; - CHECK_ERROR(sourceCode3, TypeError, "Operator ** not compatible with types int256 and int256"); -} - -BOOST_AUTO_TEST_CASE(reference_compare_operators) -{ - char const* sourceCode1 = R"( - contract test { bytes a; bytes b; function() public { a == b; } } - )"; - CHECK_ERROR(sourceCode1, TypeError, "Operator == not compatible with types bytes storage ref and bytes storage ref"); - char const* sourceCode2 = R"( - contract test { struct s {uint a;} s x; s y; function() public { x == y; } } - )"; - CHECK_ERROR(sourceCode2, TypeError, "Operator == not compatible with types struct test.s storage ref and struct test.s storage ref"); -} - -BOOST_AUTO_TEST_CASE(overwrite_memory_location_external) -{ - char const* sourceCode = R"( - contract C { - function f(uint[] memory a) external {} - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Location has to be calldata for external functions (remove the \"memory\" or \"storage\" keyword)."); -} - -BOOST_AUTO_TEST_CASE(overwrite_storage_location_external) -{ - char const* sourceCode = R"( - contract C { - function f(uint[] storage a) external {} - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Location has to be calldata for external functions (remove the \"memory\" or \"storage\" keyword)."); -} - -BOOST_AUTO_TEST_CASE(storage_location_local_variables) -{ - char const* sourceCode = R"( - contract C { - function f() public { - uint[] storage x; - uint[] memory y; - uint[] memory z; - x;y;z; - } - } - )"; - BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); -} - -BOOST_AUTO_TEST_CASE(no_mappings_in_memory_array) -{ - char const* sourceCode = R"( - contract C { - function f() public { - mapping(uint=>uint)[] memory x; - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Type mapping(uint256 => uint256)[] memory is only valid in storage."); -} - -BOOST_AUTO_TEST_CASE(assignment_mem_to_local_storage_variable) -{ - char const* sourceCode = R"( - contract C { - uint[] data; - function f(uint[] x) public { - var dataRef = data; - dataRef = x; - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Type uint256[] memory is not implicitly convertible to expected type uint256[] storage pointer."); -} - -BOOST_AUTO_TEST_CASE(storage_assign_to_different_local_variable) -{ - char const* sourceCode = R"( - contract C { - uint[] data; - uint8[] otherData; - function f() public { - uint8[] storage x = otherData; - uint[] storage y = data; - y = x; - // note that data = otherData works - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Type uint8[] storage pointer is not implicitly convertible to expected type uint256[] storage pointer."); -} - -BOOST_AUTO_TEST_CASE(uninitialized_mapping_variable) -{ - char const* sourceCode = R"( - contract C { - function f() public { - mapping(uint => uint) x; - x; - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Uninitialized mapping. Mappings cannot be created dynamically, you have to assign them from a state variable"); -} - -BOOST_AUTO_TEST_CASE(uninitialized_mapping_array_variable) -{ - char const* sourceCode = R"( - contract C { - function f() pure public { - mapping(uint => uint)[] storage x; - x; - } - } - )"; - CHECK_WARNING(sourceCode, "Uninitialized storage pointer"); -} - -BOOST_AUTO_TEST_CASE(uninitialized_mapping_array_variable_050) -{ - char const* sourceCode = R"( - pragma experimental "v0.5.0"; - contract C { - function f() pure public { - mapping(uint => uint)[] storage x; - x; - } - } - )"; - CHECK_ERROR(sourceCode, DeclarationError, "Uninitialized storage pointer"); -} - -BOOST_AUTO_TEST_CASE(no_delete_on_storage_pointers) -{ - char const* sourceCode = R"( - contract C { - uint[] data; - function f() public { - var x = data; - delete x; - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Unary operator delete cannot be applied to type uint256[] storage pointer"); -} - -BOOST_AUTO_TEST_CASE(assignment_mem_storage_variable_directly) -{ - char const* sourceCode = R"( - contract C { - uint[] data; - function f(uint[] x) public { - data = x; - } - } - )"; - BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); -} - -BOOST_AUTO_TEST_CASE(function_argument_mem_to_storage) -{ - char const* sourceCode = R"( - contract C { - function f(uint[] storage x) private { - } - function g(uint[] x) public { - f(x); - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Invalid type for argument in function call. Invalid implicit conversion from uint256[] memory to uint256[] storage pointer requested."); -} - -BOOST_AUTO_TEST_CASE(function_argument_storage_to_mem) -{ - char const* sourceCode = R"( - contract C { - function f(uint[] storage x) private { - g(x); - } - function g(uint[] x) public { - } - } - )"; - BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); -} - -BOOST_AUTO_TEST_CASE(mem_array_assignment_changes_base_type) -{ - char const* sourceCode = R"( - contract C { - function f(uint8[] memory x) private { - // Such an assignment is possible in storage, but not in memory - // (because it would incur an otherwise unnecessary copy). - // This requirement might be lifted, though. - uint[] memory y = x; - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Type uint8[] memory is not implicitly convertible to expected type uint256[] memory."); -} - BOOST_AUTO_TEST_CASE(dynamic_return_types_not_possible) { char const* sourceCode = R"( contract C { function f(uint) public returns (string); function g() public { - var x = this.f(2); + string memory x = this.f(2); // we can assign to x but it is not usable. bytes(x).length; } } )"; if (dev::test::Options::get().evmVersion() == EVMVersion::homestead()) - CHECK_ERROR(sourceCode, TypeError, "Explicit type conversion not allowed from \"inaccessible dynamic type\" to \"bytes storage pointer\"."); + CHECK_ERROR(sourceCode, TypeError, "Type inaccessible dynamic type is not implicitly convertible to expected type string memory."); else - CHECK_WARNING(sourceCode, "Use of the \"var\" keyword is deprecated"); -} - -BOOST_AUTO_TEST_CASE(memory_arrays_not_resizeable) -{ - char const* sourceCode = R"( - contract C { - function f() public { - uint[] memory x; - x.length = 2; - } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Expression has to be an lvalue."); -} - -BOOST_AUTO_TEST_CASE(struct_constructor) -{ - char const* sourceCode = R"( - contract C { - struct S { uint a; bool x; } - function f() public { - S memory s = S(1, true); - } - } - )"; - BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); -} - -BOOST_AUTO_TEST_CASE(struct_constructor_nested) -{ - char const* sourceCode = R"( - contract C { - struct X { uint x1; uint x2; } - struct S { uint s1; uint[3] s2; X s3; } - function f() public { - uint[3] memory s2; - S memory s = S(1, s2, X(4, 5)); - } - } - )"; - BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); -} - -BOOST_AUTO_TEST_CASE(struct_named_constructor) -{ - char const* sourceCode = R"( - contract C { - struct S { uint a; bool x; } - function f() public { - S memory s = S({a: 1, x: true}); - } - } - )"; - BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); -} - -BOOST_AUTO_TEST_CASE(literal_strings) -{ - char const* text = R"( - contract Foo { - function f() public { - string memory long = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; - string memory short = "123"; - long; short; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(string_bytes_conversion) -{ - char const* text = R"( - contract Test { - string s; - bytes b; - function h(string _s) external { bytes(_s).length; } - function i(string _s) internal { bytes(_s).length; } - function j() internal { bytes(s).length; } - function k(bytes _b) external { string(_b); } - function l(bytes _b) internal { string(_b); } - function m() internal { string(b); } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inheriting_from_library) -{ - char const* text = R"( - library Lib {} - contract Test is Lib {} - )"; - CHECK_ERROR(text, TypeError, "Libraries cannot be inherited from."); -} - -BOOST_AUTO_TEST_CASE(inheriting_library) -{ - char const* text = R"( - contract Test {} - library Lib is Test {} - )"; - CHECK_ERROR(text, TypeError, "Library is not allowed to inherit."); -} - -BOOST_AUTO_TEST_CASE(library_having_variables) -{ - char const* text = R"( - library Lib { uint x; } - )"; - CHECK_ERROR(text, TypeError, "Library cannot have non-constant state variables"); -} - -BOOST_AUTO_TEST_CASE(valid_library) -{ - char const* text = R"( - library Lib { uint constant x = 9; } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(call_to_library_function) -{ - char const* text = R"( - library Lib { - function min(uint, uint) public returns (uint); - } - contract Test { - function f() public { - uint t = Lib.min(12, 7); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(creating_contract_within_the_contract) -{ - char const* sourceCode = R"( - contract Test { - function f() public { var x = new Test(); } - } - )"; - CHECK_ERROR(sourceCode, TypeError, "Circular reference for contract creation (cannot create instance of derived or same contract)."); -} - -BOOST_AUTO_TEST_CASE(array_out_of_bound_access) -{ - char const* text = R"( - contract c { - uint[2] dataArray; - function set5th() public returns (bool) { - dataArray[5] = 2; - return true; - } - } - )"; - CHECK_ERROR(text, TypeError, "Out of bounds array access."); -} - -BOOST_AUTO_TEST_CASE(literal_string_to_storage_pointer) -{ - char const* text = R"( - contract C { - function f() public { string x = "abc"; } - } - )"; - CHECK_ERROR(text, TypeError, "Type literal_string \"abc\" is not implicitly convertible to expected type string storage pointer."); -} - -BOOST_AUTO_TEST_CASE(non_initialized_references) -{ - char const* text = R"( - contract c - { - struct s { - uint a; - } - function f() public { - s storage x; - x.a = 2; - } - } - )"; - - CHECK_WARNING(text, "Uninitialized storage pointer"); -} - -BOOST_AUTO_TEST_CASE(non_initialized_references_050) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract c - { - struct s { - uint a; - } - function f() public { - s storage x; - } - } - )"; - - CHECK_ERROR(text, DeclarationError, "Uninitialized storage pointer"); -} - -BOOST_AUTO_TEST_CASE(keccak256_with_large_integer_constant) -{ - char const* text = R"( - contract c - { - function f() public { keccak256(2**500); } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid rational number (too large or division by zero)."); -} - -BOOST_AUTO_TEST_CASE(cyclic_binary_dependency) -{ - char const* text = R"( - contract A { function f() public { new B(); } } - contract B { function f() public { new C(); } } - contract C { function f() public { new A(); } } - )"; - CHECK_ERROR(text, TypeError, "Circular reference for contract creation (cannot create instance of derived or same contract)."); -} - -BOOST_AUTO_TEST_CASE(cyclic_binary_dependency_via_inheritance) -{ - char const* text = R"( - contract A is B { } - contract B { function f() public { new C(); } } - contract C { function f() public { new A(); } } - )"; - CHECK_ERROR(text, TypeError, "Definition of base has to precede definition of derived contract"); -} - -BOOST_AUTO_TEST_CASE(multi_variable_declaration_fail) -{ - char const* text = R"( - contract C { function f() public { var (x,y); x = 1; y = 1;} } - )"; - CHECK_ERROR(text, TypeError, "Assignment necessary for type detection."); -} - -BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fine) -{ - char const* text = R"( - contract C { - function three() public returns (uint, uint, uint); - function two() public returns (uint, uint); - function none(); - function f() public { - var (a,) = three(); - var (b,c,) = two(); - var (,d) = three(); - var (,e,g) = two(); - var (,,) = three(); - var () = none(); - a;b;c;d;e;g; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_1) -{ - char const* text = R"( - contract C { - function one() public returns (uint); - function f() public { var (a, b, ) = one(); } - } - )"; - CHECK_ERROR(text, TypeError, "Not enough components (1) in value to assign all variables (2)."); -} -BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_2) -{ - char const* text = R"( - contract C { - function one() public returns (uint); - function f() public { var (a, , ) = one(); } - } - )"; - CHECK_ERROR(text, TypeError, "Not enough components (1) in value to assign all variables (2)."); -} - -BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_3) -{ - char const* text = R"( - contract C { - function one() public returns (uint); - function f() public { var (, , a) = one(); } - } - )"; - CHECK_ERROR(text, TypeError, "Not enough components (1) in value to assign all variables (2)."); -} - -BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_4) -{ - char const* text = R"( - contract C { - function one() public returns (uint); - function f() public { var (, a, b) = one(); } - } - )"; - CHECK_ERROR(text, TypeError, "Not enough components (1) in value to assign all variables (2)."); -} - -BOOST_AUTO_TEST_CASE(tuples) -{ - char const* text = R"( - contract C { - function f() public { - uint a = (1); - var (b,) = (uint8(1),); - var (c,d) = (uint32(1), 2 + a); - var (e,) = (uint64(1), 2, b); - a;b;c;d;e; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(tuples_empty_components) -{ - char const* text = R"( - contract C { - function f() public { - (1,,2); - } - } - )"; - CHECK_ERROR(text, TypeError, "Tuple component cannot be empty."); -} - -BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_5) -{ - char const* text = R"( - contract C { - function one() public returns (uint); - function f() public { var (,) = one(); } - } - )"; - CHECK_ERROR(text, TypeError, "Wildcard both at beginning and end of variable declaration list is only allowed if the number of components is equal."); -} - -BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_6) -{ - char const* text = R"( - contract C { - function two() public returns (uint, uint); - function f() public { var (a, b, c) = two(); } - } - )"; - CHECK_ERROR(text, TypeError, "Not enough components (2) in value to assign all variables (3)"); -} - -BOOST_AUTO_TEST_CASE(tuple_assignment_from_void_function) -{ - char const* text = R"( - contract C { - function f() public { } - function g() public { - var (x,) = (f(), f()); - } - } - )"; - CHECK_ERROR(text, TypeError, "Cannot declare variable with void (empty tuple) type."); -} - -BOOST_AUTO_TEST_CASE(tuple_compound_assignment) -{ - char const* text = R"( - contract C { - function f() public returns (uint a, uint b) { - (a, b) += (1, 1); - } - } - )"; - CHECK_ERROR(text, TypeError, "Compound assignment is not allowed for tuple types."); -} - -BOOST_AUTO_TEST_CASE(member_access_parser_ambiguity) -{ - char const* text = R"( - contract C { - struct R { uint[10][10] y; } - struct S { uint a; uint b; uint[20][20][20] c; R d; } - S data; - function f() public { - C.S x = data; - C.S memory y; - C.S[10] memory z; - C.S[10]; - y.a = 2; - x.c[1][2][3] = 9; - x.d.y[2][2] = 3; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(using_for_library) -{ - char const* text = R"( - library D { } - contract C { - using D for uint; - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(using_for_not_library) -{ - char const* text = R"( - contract D { } - contract C { - using D for uint; - } - )"; - CHECK_ERROR(text, TypeError, "Library name expected."); -} - -BOOST_AUTO_TEST_CASE(using_for_function_exists) -{ - char const* text = R"( - library D { function double(uint self) public returns (uint) { return 2*self; } } - contract C { - using D for uint; - function f(uint a) public { - a.double; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(using_for_function_on_int) -{ - char const* text = R"( - library D { function double(uint self) public returns (uint) { return 2*self; } } - contract C { - using D for uint; - function f(uint a) public returns (uint) { - return a.double(); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(using_for_function_on_struct) -{ - char const* text = R"( - library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } - contract C { - using D for D.s; - D.s x; - function f(uint a) public returns (uint) { - return x.mul(a); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(using_for_overload) -{ - char const* text = R"( - library D { - struct s { uint a; } - function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } - function mul(s storage, bytes32) public returns (bytes32) { } - } - contract C { - using D for D.s; - D.s x; - function f(uint a) public returns (uint) { - return x.mul(a); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(using_for_by_name) -{ - char const* text = R"( - library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } - contract C { - using D for D.s; - D.s x; - function f(uint a) public returns (uint) { - return x.mul({x: a}); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(using_for_mismatch) -{ - char const* text = R"( - library D { function double(bytes32 self) public returns (uint) { return 2; } } - contract C { - using D for uint; - function f(uint a) public returns (uint) { - return a.double(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"double\" not found or not visible after argument-dependent lookup in uint256"); -} - -BOOST_AUTO_TEST_CASE(using_for_not_used) -{ - char const* text = R"( - library D { function double(uint self) public returns (uint) { return 2; } } - contract C { - using D for uint; - function f(uint16 a) public returns (uint) { - // This is an error because the function is only bound to uint. - // Had it been bound to *, it would have worked. - return a.double(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"double\" not found or not visible after argument-dependent lookup in uint16"); -} - -BOOST_AUTO_TEST_CASE(library_memory_struct) -{ - char const* text = R"( - pragma experimental ABIEncoderV2; - library c { - struct S { uint x; } - function f() public returns (S ) {} - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(using_for_arbitrary_mismatch) -{ - char const* text = R"( - library D { function double(bytes32 self) public returns (uint) { return 2; } } - contract C { - using D for *; - function f(uint a) public returns (uint) { - // Bound to a, but self type does not match. - return a.double(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"double\" not found or not visible after argument-dependent lookup in uint256"); -} - -BOOST_AUTO_TEST_CASE(bound_function_in_var) -{ - char const* text = R"( - library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } - contract C { - using D for D.s; - D.s x; - function f(uint a) public returns (uint) { - var g = x.mul; - return g({x: a}); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(create_memory_arrays) -{ - char const* text = R"( - library L { - struct R { uint[10][10] y; } - struct S { uint a; uint b; uint[20][20][20] c; R d; } - } - contract C { - function f(uint size) public { - L.S[][] memory x = new L.S[][](10); - var y = new uint[](20); - var z = new bytes(size); - x;y;z; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(mapping_in_memory_array) -{ - char const* text = R"( - contract C { - function f(uint size) public { - var x = new mapping(uint => uint)[](4); - } - } - )"; - CHECK_ERROR(text, TypeError, "Type cannot live outside storage."); -} - -BOOST_AUTO_TEST_CASE(new_for_non_array) -{ - char const* text = R"( - contract C { - function f(uint size) public { - var x = new uint(7); - } - } - )"; - CHECK_ERROR(text, TypeError, "Contract or array type expected."); -} - -BOOST_AUTO_TEST_CASE(invalid_args_creating_memory_array) -{ - char const* text = R"( - contract C { - function f(uint size) public { - var x = new uint[](); - } - } - )"; - CHECK_ERROR(text, TypeError, "Wrong argument count for function call: 0 arguments given but expected 1."); -} - -BOOST_AUTO_TEST_CASE(invalid_args_creating_struct) -{ - char const* text = R"( - contract C { - struct S { uint a; uint b; } - - function f() public { - var s = S({a: 1}); - } - } - )"; - CHECK_ERROR(text, TypeError, "Wrong argument count for struct constructor: 1 arguments given but expected 2."); -} - -BOOST_AUTO_TEST_CASE(function_overload_array_type) -{ - char const* text = R"( - contract M { - function f(uint[]); - function f(int[]); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inline_array_declaration_and_passing_implicit_conversion) -{ - char const* text = R"( - contract C { - function f() public returns (uint) { - uint8 x = 7; - uint16 y = 8; - uint32 z = 9; - uint32[3] memory ending = [x, y, z]; - return (ending[1]); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inline_array_declaration_and_passing_implicit_conversion_strings) -{ - char const* text = R"( - contract C { - function f() public returns (string) { - string memory x = "Hello"; - string memory y = "World"; - string[2] memory z = [x, y]; - return (z[0]); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inline_array_declaration_const_int_conversion) -{ - char const* text = R"( - contract C { - function f() public returns (uint) { - uint8[4] memory z = [1,2,3,5]; - return (z[0]); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inline_array_declaration_const_string_conversion) -{ - char const* text = R"( - contract C { - function f() public returns (string) { - string[2] memory z = ["Hello", "World"]; - return (z[0]); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inline_array_declaration_no_type) -{ - char const* text = R"( - contract C { - function f() public returns (uint) { - return ([4,5,6][1]); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inline_array_declaration_no_type_strings) -{ - char const* text = R"( - contract C { - function f() public returns (string) { - return (["foo", "man", "choo"][1]); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inline_struct_declaration_arrays) -{ - char const* text = R"( - contract C { - struct S { - uint a; - string b; - } - function f() { - S[2] memory x = [S({a: 1, b: "fish"}), S({a: 2, b: "fish"})]; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(invalid_types_in_inline_array) -{ - char const* text = R"( - contract C { - function f() public { - uint[3] x = [45, 'foo', true]; - } - } - )"; - CHECK_ERROR(text, TypeError, "Unable to deduce common type for array elements."); -} - -BOOST_AUTO_TEST_CASE(dynamic_inline_array) -{ - char const* text = R"( - contract C { - function f() public { - uint8[4][4] memory dyn = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(lvalues_as_inline_array) -{ - char const* text = R"( - contract C { - function f() public { - [1, 2, 3]++; - [1, 2, 3] = [4, 5, 6]; - } - } - )"; - CHECK_ERROR(text, TypeError, "Inline array type cannot be declared as LValue."); -} - -BOOST_AUTO_TEST_CASE(break_not_in_loop) -{ - char const* text = R"( - contract C { - function f() public { - if (true) - break; - } - } - )"; - CHECK_ERROR(text, SyntaxError, "\"break\" has to be in a \"for\" or \"while\" loop."); -} - -BOOST_AUTO_TEST_CASE(continue_not_in_loop) -{ - char const* text = R"( - contract C { - function f() public { - if (true) - continue; - } - } - )"; - CHECK_ERROR(text, SyntaxError, "\"continue\" has to be in a \"for\" or \"while\" loop."); -} - -BOOST_AUTO_TEST_CASE(continue_not_in_loop_2) -{ - char const* text = R"( - contract C { - function f() public { - while (true) - { - } - continue; - } - } - )"; - CHECK_ERROR(text, SyntaxError, "\"continue\" has to be in a \"for\" or \"while\" loop."); -} - -BOOST_AUTO_TEST_CASE(invalid_different_types_for_conditional_expression) -{ - char const* text = R"( - contract C { - function f() public { - true ? true : 2; - } - } - )"; - CHECK_ERROR(text, TypeError, "True expression's type bool doesn't match false expression's type uint8."); -} - -BOOST_AUTO_TEST_CASE(left_value_in_conditional_expression_not_supported_yet) -{ - char const* text = R"( - contract C { - function f() public { - uint x; - uint y; - (true ? x : y) = 1; - } - } - )"; - CHECK_ERROR_ALLOW_MULTI(text, TypeError, (std::vector<std::string>{ - "Conditional expression as left value is not supported yet.", - "Expression has to be an lvalue" - })); -} - -BOOST_AUTO_TEST_CASE(conditional_expression_with_different_struct) -{ - char const* text = R"( - contract C { - struct s1 { - uint x; - } - struct s2 { - uint x; - } - function f() public { - s1 memory x; - s2 memory y; - true ? x : y; - } - } - )"; - CHECK_ERROR(text, TypeError, "True expression's type struct C.s1 memory doesn't match false expression's type struct C.s2 memory."); -} - -BOOST_AUTO_TEST_CASE(conditional_expression_with_different_function_type) -{ - char const* text = R"( - contract C { - function x(bool) public {} - function y() public {} - - function f() public { - true ? x : y; - } - } - )"; - CHECK_ERROR(text, TypeError, "True expression's type function (bool) doesn't match false expression's type function ()."); -} - -BOOST_AUTO_TEST_CASE(conditional_expression_with_different_enum) -{ - char const* text = R"( - contract C { - enum small { A, B, C, D } - enum big { A, B, C, D } - - function f() public { - small x; - big y; - - true ? x : y; - } - } - )"; - CHECK_ERROR(text, TypeError, "True expression's type enum C.small doesn't match false expression's type enum C.big."); -} - -BOOST_AUTO_TEST_CASE(conditional_expression_with_different_mapping) -{ - char const* text = R"( - contract C { - mapping(uint8 => uint8) table1; - mapping(uint32 => uint8) table2; - - function f() public { - true ? table1 : table2; - } - } - )"; - CHECK_ERROR(text, TypeError, "True expression's type mapping(uint8 => uint8) doesn't match false expression's type mapping(uint32 => uint8)."); + CHECK_SUCCESS_NO_WARNINGS(sourceCode); } -BOOST_AUTO_TEST_CASE(conditional_with_all_types) -{ - char const* text = R"( - contract C { - struct s1 { - uint x; - } - s1 struct_x; - s1 struct_y; - - function fun_x() public {} - function fun_y() public {} - - enum small { A, B, C, D } - - mapping(uint8 => uint8) table1; - mapping(uint8 => uint8) table2; - - function f() public { - // integers - uint x; - uint y; - uint g = true ? x : y; - g += 1; // Avoid unused var warning - - // integer constants - uint h = true ? 1 : 3; - h += 1; // Avoid unused var warning - - // string literal - var i = true ? "hello" : "world"; - i = "used"; //Avoid unused var warning - } - function f2() public { - // bool - bool j = true ? true : false; - j = j && true; // Avoid unused var warning - - // real is not there yet. - - // array - byte[2] memory a; - byte[2] memory b; - var k = true ? a : b; - k[0] = byte(0); //Avoid unused var warning - - bytes memory e; - bytes memory f; - var l = true ? e : f; - l[0] = byte(0); // Avoid unused var warning - - // fixed bytes - bytes2 c; - bytes2 d; - var m = true ? c : d; - m &= m; - - } - function f3() public { - // contract doesn't fit in here - - // struct - struct_x = true ? struct_x : struct_y; - - // function - var r = true ? fun_x : fun_y; - r(); // Avoid unused var warning - // enum - small enum_x; - small enum_y; - enum_x = true ? enum_x : enum_y; - - // tuple - var (n, o) = true ? (1, 2) : (3, 4); - (n, o) = (o, n); // Avoid unused var warning - // mapping - var p = true ? table1 : table2; - p[0] = 0; // Avoid unused var warning - // typetype - var q = true ? uint32(1) : uint32(2); - q += 1; // Avoid unused var warning - // modifier doesn't fit in here - - // magic doesn't fit in here - - // module doesn't fit in here - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(uint7_and_uintM_as_identifier) -{ - char const* text = R"( - contract test { - string uintM = "Hello 4 you"; - function f() public { - uint8 uint7 = 3; - uint7 = 5; - string memory intM; - uint bytesM = 21; - intM; bytesM; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(varM_disqualified_as_keyword) -{ - char const* text = R"( - contract test { - function f() public { - uintM something = 3; - intM should = 4; - bytesM fail = "now"; - } - } - )"; - CHECK_ERROR_ALLOW_MULTI(text, DeclarationError, (std::vector<std::string>{ - "Identifier not found or not unique.", - "Identifier not found or not unique.", - "Identifier not found or not unique." - })); -} - -BOOST_AUTO_TEST_CASE(modifier_is_not_a_valid_typename) -{ - char const* text = R"( - contract test { - modifier mod() { _; } - - function f() public { - mod g; - } - } - )"; - CHECK_ERROR(text, TypeError, "Name has to refer to a struct, enum or contract."); -} - -BOOST_AUTO_TEST_CASE(modifier_is_not_a_valid_typename_is_not_fatal) -{ - char const* text = R"( - contract test { - modifier mod() { _; } - - function f() public { - mod g; - g = f; - } - } - )"; - CHECK_ERROR_ALLOW_MULTI(text, TypeError, (std::vector<std::string>{"Name has to refer to a struct, enum or contract."})); -} - -BOOST_AUTO_TEST_CASE(function_is_not_a_valid_typename) -{ - char const* text = R"( - contract test { - function foo() public { - } - - function f() public { - foo g; - } - } - )"; - CHECK_ERROR(text, TypeError, "Name has to refer to a struct, enum or contract."); -} - -BOOST_AUTO_TEST_CASE(long_uint_variable_fails) -{ - char const* text = R"( - contract test { - function f() public { - uint99999999999999999999999999 something = 3; - } - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier not found or not unique."); -} - -BOOST_AUTO_TEST_CASE(bytes10abc_is_identifier) -{ - char const* text = R"( - contract test { - function f() public { - bytes32 bytes10abc = "abc"; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(int10abc_is_identifier) -{ - char const* text = R"( - contract test { - function f() public { - uint uint10abc = 3; - int int10abc = 4; - uint10abc; int10abc; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(library_functions_do_not_have_value) -{ - char const* text = R"( - library L { function l() public {} } - contract test { - function f() public { - L.l.value; - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup in function ()"); -} - -BOOST_AUTO_TEST_CASE(invalid_fixed_types_0x7_mxn) -{ - char const* text = R"( - contract test { - fixed0x7 a = .3; - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier not found"); -} - -BOOST_AUTO_TEST_CASE(invalid_fixed_types_long_invalid_identifier) -{ - char const* text = R"( - contract test { - fixed99999999999999999999999999999999999999x7 b = 9.5; - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier not found"); -} - -BOOST_AUTO_TEST_CASE(invalid_fixed_types_7x8_mxn) -{ - char const* text = R"( - contract test { - fixed7x8 c = 3.12345678; - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier not found"); -} - -BOOST_AUTO_TEST_CASE(library_instances_cannot_be_used) -{ - char const* text = R"( - library L { function l() public {} } - contract test { - function f() public { - L x; - x.l(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"l\" not found or not visible after argument-dependent lookup in library L"); -} - -BOOST_AUTO_TEST_CASE(invalid_fixed_type_long) -{ - char const* text = R"( - contract test { - function f() public { - fixed8x888888888888888888888888888888888888888888888888888 b; - } - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier not found"); -} - -BOOST_AUTO_TEST_CASE(fixed_type_int_conversion) -{ - char const* text = R"( - contract test { - function f() public { - uint64 a = 3; - int64 b = 4; - fixed c = b; - ufixed d = a; - c; d; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(fixed_type_rational_int_conversion) -{ - char const* text = R"( - contract test { - function f() public { - fixed c = 3; - ufixed d = 4; - c; d; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(fixed_type_rational_fraction_conversion) -{ - char const* text = R"( - contract test { - function f() public { - fixed a = 4.5; - ufixed d = 2.5; - a; d; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(invalid_int_implicit_conversion_from_fixed) -{ - char const* text = R"( - contract test { - function f() public { - fixed a = 4.5; - int b = a; - a; b; - } - } - )"; - CHECK_ERROR(text, TypeError, "Type fixed128x18 is not implicitly convertible to expected type int256"); -} - -BOOST_AUTO_TEST_CASE(rational_unary_operation) -{ - char const* text = R"( - contract test { - function f() pure public { - ufixed16x2 a = 3.25; - fixed16x2 b = -3.25; - a; b; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - - // Test deprecation warning under < 0.5.0 - text = R"( - contract test { - function f() pure public { - ufixed16x2 a = +3.25; - fixed16x2 b = -3.25; - a; b; - } - } - )"; - CHECK_WARNING(text, "Use of unary + is deprecated"); - text = R"( - contract test { - function f(uint x) pure public { - uint y = +x; - y; - } - } - )"; - CHECK_WARNING(text,"Use of unary + is deprecated"); - - // Test syntax error under 0.5.0 - text = R"( - pragma experimental "v0.5.0"; - contract test { - function f() pure public { - ufixed16x2 a = +3.25; - fixed16x2 b = -3.25; - a; b; - } - } - )"; - CHECK_ERROR(text, SyntaxError, "Use of unary + is deprecated"); - text = R"( - pragma experimental "v0.5.0"; - contract test { - function f(uint x) pure public { - uint y = +x; - y; - } - } - )"; - CHECK_ERROR(text, SyntaxError, "Use of unary + is deprecated"); -} - -BOOST_AUTO_TEST_CASE(leading_zero_rationals_convert) -{ - char const* text = R"( - contract A { - function f() pure public { - ufixed16x2 a = 0.5; - ufixed256x52 b = 0.0000000000000006661338147750939242541790008544921875; - fixed16x2 c = -0.5; - fixed256x52 d = -0.0000000000000006661338147750939242541790008544921875; - a; b; c; d; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(size_capabilities_of_fixed_point_types) -{ - char const* text = R"( - contract test { - function f() public { - ufixed256x1 a = 123456781234567979695948382928485849359686494864095409282048094275023098123.5; - ufixed256x77 b = 0.920890746623327805482905058466021565416131529487595827354393978494366605267637; - ufixed224x78 c = 0.000000000001519884736399797998492268541131529487595827354393978494366605267646; - fixed256x1 d = -123456781234567979695948382928485849359686494864095409282048094275023098123.5; - fixed256x76 e = -0.93322335481643744342575580035176794825198893968114429702091846411734101080123; - fixed256x79 g = -0.0001178860664374434257558003517679482519889396811442970209184641173410108012309; - a; b; c; d; e; g; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(zero_handling) -{ - char const* text = R"( - contract test { - function f() public { - fixed16x2 a = 0; a; - ufixed32x1 b = 0; b; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(fixed_type_invalid_implicit_conversion_size) -{ - char const* text = R"( - contract test { - function f() public { - ufixed a = 11/4; - ufixed248x8 b = a; b; - } - } - )"; - CHECK_ERROR(text, TypeError, "Type ufixed128x18 is not implicitly convertible to expected type ufixed248x8"); -} - -BOOST_AUTO_TEST_CASE(fixed_type_invalid_implicit_conversion_lost_data) -{ - char const* text = R"( - contract test { - function f() public { - ufixed256x1 a = 1/3; a; - } - } - )"; - CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type ufixed256x1"); -} - -BOOST_AUTO_TEST_CASE(fixed_type_valid_explicit_conversions) -{ - char const* text = R"( - contract test { - function f() public { - ufixed256x80 a = ufixed256x80(1/3); a; - ufixed248x80 b = ufixed248x80(1/3); b; - ufixed8x1 c = ufixed8x1(1/3); c; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_rational) -{ - char const* text = R"( - contract test { - function f() public { - uint[3.5] a; a; - } - } - )"; - CHECK_ERROR(text, TypeError, "Array with fractional length specified."); -} - -BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_signed_fixed_type) -{ - char const* text = R"( - contract test { - function f() public { - uint[fixed(3.5)] a; a; - } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression."); -} - -BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_unsigned_fixed_type) -{ - char const* text = R"( - contract test { - function f() public { - uint[ufixed(3.5)] a; a; - } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression."); -} - -BOOST_AUTO_TEST_CASE(rational_to_bytes_implicit_conversion) -{ - char const* text = R"( - contract test { - function f() public { - bytes32 c = 3.2; c; - } - } - )"; - CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type bytes32"); -} - -BOOST_AUTO_TEST_CASE(fixed_to_bytes_implicit_conversion) -{ - char const* text = R"( - contract test { - function f() public { - fixed a = 3.25; - bytes32 c = a; c; - } - } - )"; - CHECK_ERROR(text, TypeError, "fixed128x18 is not implicitly convertible to expected type bytes32"); -} - -BOOST_AUTO_TEST_CASE(mapping_with_fixed_literal) -{ - char const* text = R"( - contract test { - mapping(ufixed8x1 => string) fixedString; - function f() public { - fixedString[0.5] = "Half"; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(fixed_points_inside_structs) -{ - char const* text = R"( - contract test { - struct myStruct { - ufixed a; - int b; - } - myStruct a = myStruct(3.125, 3); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inline_array_fixed_types) -{ - char const* text = R"( - contract test { - function f() public { - fixed[3] memory a = [fixed(3.5), fixed(-4.25), fixed(967.125)]; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inline_array_rationals) -{ - char const* text = R"( - contract test { - function f() public { - ufixed128x3[4] memory a = [ufixed128x3(3.5), 4.125, 2.5, 4.0]; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(rational_index_access) -{ - char const* text = R"( - contract test { - function f() public { - uint[] memory a; - a[.5]; - } - } - )"; - CHECK_ERROR(text, TypeError, "rational_const 1 / 2 is not implicitly convertible to expected type uint256"); -} - -BOOST_AUTO_TEST_CASE(rational_to_fixed_literal_expression) -{ - char const* text = R"( - contract test { - function f() public { - ufixed64x8 a = 3.5 * 3; - ufixed64x8 b = 4 - 2.5; - ufixed64x8 c = 11 / 4; - ufixed240x5 d = 599 + 0.21875; - ufixed256x80 e = ufixed256x80(35.245 % 12.9); - ufixed256x80 f = ufixed256x80(1.2 % 2); - fixed g = 2 ** -2; - a; b; c; d; e; f; g; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(rational_as_exponent_value_signed) -{ - char const* text = R"( - contract test { - function f() public { - fixed g = 2 ** -2.2; - } - } - )"; - CHECK_ERROR(text, TypeError, "not compatible with types"); -} - -BOOST_AUTO_TEST_CASE(rational_as_exponent_value_unsigned) -{ - char const* text = R"( - contract test { - function f() public { - ufixed b = 3 ** 2.5; - } - } - )"; - CHECK_ERROR(text, TypeError, "not compatible with types"); -} - -BOOST_AUTO_TEST_CASE(rational_as_exponent_half) -{ - char const* text = R"( - contract test { - function f() public { - 2 ** (1/2); - } - } - )"; - CHECK_ERROR(text, TypeError, "not compatible with types"); -} - -BOOST_AUTO_TEST_CASE(rational_as_exponent_value_neg_quarter) -{ - char const* text = R"( - contract test { - function f() public { - 42 ** (-1/4); - } - } - )"; - CHECK_ERROR(text, TypeError, "not compatible with types"); -} - -BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_15) -{ - char const* text = R"( - contract test { - function f() public { - var a = 3 ** ufixed(1.5); - } - } - )"; - CHECK_ERROR(text, TypeError, "not compatible with types"); -} - -BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents_neg) -{ - char const* text = R"( - contract test { - function f() public { - var c = 42 ** fixed(-1/4); - } - } - )"; - CHECK_ERROR(text, TypeError, "not compatible with types"); -} - -BOOST_AUTO_TEST_CASE(var_capable_of_holding_constant_rationals) -{ - char const* text = R"( - contract test { - function f() public { - var a = 0.12345678; - var b = 12345678.352; - var c = 0.00000009; - a; b; c; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(var_and_rational_with_tuple) -{ - char const* text = R"( - contract test { - function f() public { - var (a, b) = (.5, 1/3); - a; b; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(var_handle_divided_integers) -{ - char const* text = R"( - contract test { - function f() public { - var x = 1/3; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(rational_bitnot_unary_operation) -{ - char const* text = R"( - contract test { - function f() public { - ~fixed(3.5); - } - } - )"; - CHECK_ERROR(text, TypeError, "cannot be applied"); -} - -BOOST_AUTO_TEST_CASE(rational_bitor_binary_operation) -{ - char const* text = R"( - contract test { - function f() public { - fixed(1.5) | 3; - } - } - )"; - CHECK_ERROR(text, TypeError, "not compatible with types"); -} - -BOOST_AUTO_TEST_CASE(rational_bitxor_binary_operation) -{ - char const* text = R"( - contract test { - function f() public { - fixed(1.75) ^ 3; - } - } - )"; - CHECK_ERROR(text, TypeError, "not compatible with types"); -} - -BOOST_AUTO_TEST_CASE(rational_bitand_binary_operation) -{ - char const* text = R"( - contract test { - function f() public { - fixed(1.75) & 3; - } - } - )"; - CHECK_ERROR(text, TypeError, "not compatible with types"); -} - -BOOST_AUTO_TEST_CASE(missing_bool_conversion) -{ - char const* text = R"( - contract test { - function b(uint a) public { - bool(a == 1); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(integer_and_fixed_interaction) -{ - char const* text = R"( - contract test { - function f() public { - ufixed a = uint64(1) + ufixed(2); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(one_divided_by_three_integer_conversion) -{ - char const* text = R"( - contract test { - function f() public { - uint a = 1/3; - } - } - )"; - CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type uint256. Try converting to type ufixed256x77"); -} - -BOOST_AUTO_TEST_CASE(unused_return_value) -{ - char const* text = R"( - contract test { - function g() public returns (uint) {} - function f() public { - g(); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(unused_return_value_send) -{ - char const* text = R"( - contract test { - function f() public { - address(0x12).send(1); - } - } - )"; - CHECK_WARNING(text, "Failure condition of 'send' ignored. Consider using 'transfer' instead."); -} - -BOOST_AUTO_TEST_CASE(unused_return_value_call) -{ - char const* text = R"( - contract test { - function f() public { - address(0x12).call("abc"); - } - } - )"; - CHECK_WARNING(text, "Return value of low-level calls not used"); -} - -BOOST_AUTO_TEST_CASE(unused_return_value_call_value) -{ - char const* text = R"( - contract test { - function f() public { - address(0x12).call.value(2)("abc"); - } - } - )"; - CHECK_WARNING(text, "Return value of low-level calls not used"); -} - -BOOST_AUTO_TEST_CASE(unused_return_value_callcode) -{ - char const* text = R"( - contract test { - function f() public { - address(0x12).callcode("abc"); - } - } - )"; - CHECK_WARNING_ALLOW_MULTI(text, (std::vector<std::string>{ - "Return value of low-level calls not used", - "\"callcode\" has been deprecated" - })); -} - -BOOST_AUTO_TEST_CASE(unused_return_value_delegatecall) -{ - char const* text = R"( - contract test { - function f() public { - address(0x12).delegatecall("abc"); - } - } - )"; - CHECK_WARNING(text, "Return value of low-level calls not used"); -} - -BOOST_AUTO_TEST_CASE(warn_about_callcode) -{ - char const* text = R"( - contract test { - function f() pure public { - address(0x12).callcode; - } - } - )"; - CHECK_WARNING(text, "\"callcode\" has been deprecated in favour of \"delegatecall\""); - text = R"( - pragma experimental "v0.5.0"; - contract test { - function f() pure public { - address(0x12).callcode; - } - } - )"; - CHECK_ERROR(text, TypeError, "\"callcode\" has been deprecated in favour of \"delegatecall\""); -} - -BOOST_AUTO_TEST_CASE(no_warn_about_callcode_as_function) -{ - char const* text = R"( - contract test { - function callcode() pure public { - test.callcode(); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(payable_in_library) -{ - char const* text = R"( - library test { - function f() payable public {} - } - )"; - CHECK_ERROR(text, TypeError, "Library functions cannot be payable."); -} - -BOOST_AUTO_TEST_CASE(payable_external) -{ - char const* text = R"( - contract test { - function f() payable external {} - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(payable_internal) -{ - char const* text = R"( - contract test { - function f() payable internal {} - } - )"; - CHECK_ERROR(text, TypeError, "Internal functions cannot be payable."); -} - -BOOST_AUTO_TEST_CASE(payable_private) -{ - char const* text = R"( - contract test { - function f() payable private {} - } - )"; - CHECK_ERROR(text, TypeError, "Internal functions cannot be payable."); -} - -BOOST_AUTO_TEST_CASE(illegal_override_payable) -{ - char const* text = R"( - contract B { function f() payable public {} } - contract C is B { function f() public {} } - )"; - CHECK_ERROR(text, TypeError, "Overriding function changes state mutability from \"payable\" to \"nonpayable\"."); -} - -BOOST_AUTO_TEST_CASE(illegal_override_payable_nonpayable) -{ - char const* text = R"( - contract B { function f() public {} } - contract C is B { function f() payable public {} } - )"; - CHECK_ERROR(text, TypeError, "Overriding function changes state mutability from \"nonpayable\" to \"payable\"."); -} - -BOOST_AUTO_TEST_CASE(function_variable_mixin) -{ - char const* text = R"( - // bug #1798 (cpp-ethereum), related to #1286 (solidity) - contract attribute { - bool ok = false; - } - contract func { - function ok() public returns (bool) { return true; } - } - contract attr_func is attribute, func { - function checkOk() public returns (bool) { return ok(); } - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier already declared."); -} - -BOOST_AUTO_TEST_CASE(calling_payable) -{ - char const* text = R"( - contract receiver { function pay() payable public {} } - contract test { - function f() public { (new receiver()).pay.value(10)(); } - receiver r = new receiver(); - function g() public { r.pay.value(10)(); } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(calling_nonpayable) -{ - char const* text = R"( - contract receiver { function nopay() public {} } - contract test { - function f() public { (new receiver()).nopay.value(10)(); } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup in function () external - did you forget the \"payable\" modifier?"); -} - -BOOST_AUTO_TEST_CASE(non_payable_constructor) +BOOST_AUTO_TEST_CASE(warn_nonpresent_pragma) { char const* text = R"( - contract C { - function C() { } - } - contract D { - function f() public returns (uint) { - (new C).value(2)(); - return 2; - } - } + contract C {} )"; - CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup in function () returns (contract C) - did you forget the \"payable\" modifier?"); -} - -BOOST_AUTO_TEST_CASE(warn_nonpresent_pragma) -{ - char const* text = "contract C {}"; auto sourceAndError = parseAnalyseAndReturnError(text, true, false); BOOST_REQUIRE(!sourceAndError.second.empty()); BOOST_REQUIRE(!!sourceAndError.first); @@ -4722,1327 +387,6 @@ BOOST_AUTO_TEST_CASE(unsatisfied_version) BOOST_CHECK(searchErrorMessage(*sourceAndError.second.front(), "Source file requires different compiler version")); } -BOOST_AUTO_TEST_CASE(invalid_array_as_statement) -{ - char const* text = R"( - contract test { - struct S { uint x; } - function test(uint k) public { S[k]; } - } - )"; - CHECK_ERROR(text, TypeError, "Integer constant expected."); -} - -BOOST_AUTO_TEST_CASE(using_directive_for_missing_selftype) -{ - char const* text = R"( - library B { - function b() public {} - } - - contract A { - using B for bytes; - - function a() public { - bytes memory x; - x.b(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"b\" not found or not visible after argument-dependent lookup in bytes memory"); -} - -BOOST_AUTO_TEST_CASE(shift_constant_left_negative_rvalue) -{ - char const* text = R"( - contract C { - uint public a = 0x42 << -8; - } - )"; - CHECK_ERROR(text, TypeError, "Operator << not compatible with types int_const 66 and int_const -8"); -} - -BOOST_AUTO_TEST_CASE(shift_constant_right_negative_rvalue) -{ - char const* text = R"( - contract C { - uint public a = 0x42 >> -8; - } - )"; - CHECK_ERROR(text, TypeError, "Operator >> not compatible with types int_const 66 and int_const -8"); -} - -BOOST_AUTO_TEST_CASE(shift_constant_left_excessive_rvalue) -{ - char const* text = R"( - contract C { - uint public a = 0x42 << 0x100000000; - } - )"; - CHECK_ERROR(text, TypeError, "Operator << not compatible with types int_const 66 and int_const 4294967296"); -} - -BOOST_AUTO_TEST_CASE(shift_constant_right_excessive_rvalue) -{ - char const* text = R"( - contract C { - uint public a = 0x42 >> 0x100000000; - } - )"; - CHECK_ERROR(text, TypeError, "Operator >> not compatible with types int_const 66 and int_const 4294967296"); -} - -BOOST_AUTO_TEST_CASE(shift_constant_right_fractional) -{ - char const* text = R"( - contract C { - uint public a = 0x42 >> (1 / 2); - } - )"; - CHECK_ERROR(text, TypeError, "Operator >> not compatible with types int_const 66 and rational_const 1 / 2"); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_unbalanced_positive_stack) -{ - char const* text = R"( - contract test { - function f() public { - assembly { - 1 - } - } - } - )"; - CHECK_ERROR(text, DeclarationError, "Unbalanced stack at the end of a block: 1 surplus item(s)."); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_unbalanced_negative_stack) -{ - char const* text = R"( - contract test { - function f() public { - assembly { - pop - } - } - } - )"; - CHECK_ERROR(text, DeclarationError, "Unbalanced stack at the end of a block: 1 missing item(s)."); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_unbalanced_two_stack_load) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract c { - uint8 x; - function f() public { - assembly { pop(x) } - } - } - )"; - CHECK_ERROR(text, TypeError, "Only local variables are supported. To access storage variables,"); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_in_modifier) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract test { - modifier m { - uint a = 1; - assembly { - a := 2 - } - _; - } - function f() public m { - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_storage) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract test { - uint x = 1; - function f() public { - assembly { - x := 2 - } - } - } - )"; - CHECK_ERROR(text, TypeError, "Only local variables are supported. To access storage variables,"); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_storage_in_modifiers) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract test { - uint x = 1; - modifier m { - assembly { - x := 2 - } - _; - } - function f() public m { - } - } - )"; - CHECK_ERROR(text, TypeError, "Only local variables are supported. To access storage variables,"); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_constant_assign) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract test { - uint constant x = 1; - function f() public { - assembly { - x := 2 - } - } - } - )"; - CHECK_ERROR(text, TypeError, "Constant variables not supported by inline assembly"); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_constant_access) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract test { - uint constant x = 1; - function f() public { - assembly { - let y := x - } - } - } - )"; - CHECK_ERROR(text, TypeError, "Constant variables not supported by inline assembly"); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_local_variable_access_out_of_functions) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract test { - function f() public { - uint a; - assembly { - function g() -> x { x := a } - } - } - } - )"; - CHECK_ERROR(text, DeclarationError, "Cannot access local Solidity variables from inside an inline assembly function."); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_local_variable_access_out_of_functions_storage_ptr) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract test { - uint[] r; - function f() public { - uint[] storage a = r; - assembly { - function g() -> x { x := a_offset } - } - } - } - )"; - CHECK_ERROR(text, DeclarationError, "Cannot access local Solidity variables from inside an inline assembly function."); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_storage_variable_access_out_of_functions) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract test { - uint a; - function f() pure public { - assembly { - function g() -> x { x := a_slot } - } - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_constant_variable_via_offset) -{ - char const* text = R"( - contract test { - uint constant x = 2; - function f() pure public { - assembly { - let r := x_offset - } - } - } - )"; - CHECK_ERROR(text, TypeError, "Constant variables not supported by inline assembly."); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_calldata_variables) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract C { - function f(bytes bytesAsCalldata) external { - assembly { - let x := bytesAsCalldata - } - } - } - )"; - CHECK_ERROR(text, TypeError, "Call data elements cannot be accessed directly."); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_050_literals_on_stack) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() pure public { - assembly { - 1 - } - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::SyntaxError, "are not supposed to return"}, - {Error::Type::DeclarationError, "Unbalanced stack"}, - })); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_literals_on_stack) -{ - char const* text = R"( - contract C { - function f() pure public { - assembly { - 1 - } - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::Warning, "are not supposed to return"}, - {Error::Type::DeclarationError, "Unbalanced stack"}, - })); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_050_bare_instructions) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() view public { - assembly { - address - pop - } - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::SyntaxError, "The use of non-functional"}, - {Error::Type::SyntaxError, "The use of non-functional"} - })); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_bare_instructions) -{ - char const* text = R"( - contract C { - function f() view public { - assembly { - address - pop - } - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::Warning, "The use of non-functional"}, - {Error::Type::Warning, "The use of non-functional"} - })); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_050_labels) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() pure public { - assembly { - label: - } - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::SyntaxError, "Jump instructions and labels are low-level"}, - {Error::Type::SyntaxError, "The use of labels is deprecated"} - })); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_labels) -{ - char const* text = R"( - contract C { - function f() pure public { - assembly { - label: - } - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::Warning, "Jump instructions and labels are low-level"}, - {Error::Type::Warning, "The use of labels is deprecated"} - })); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_050_jump) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() pure public { - assembly { - jump(2) - } - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::SyntaxError, "Jump instructions and labels are low-level"} - })); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_jump) -{ - char const* text = R"( - contract C { - function f() pure public { - assembly { - jump(2) - } - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::TypeError, "Function declared as pure"}, - {Error::Type::Warning, "Jump instructions and labels are low-level"} - })); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_050_leave_items_on_stack) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() pure public { - assembly { - mload(0) - } - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::SyntaxError, "are not supposed to return"}, - {Error::Type::DeclarationError, "Unbalanced stack"}, - })); -} - -BOOST_AUTO_TEST_CASE(inline_assembly_leave_items_on_stack) -{ - char const* text = R"( - contract C { - function f() pure public { - assembly { - mload(0) - } - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::Warning, "are not supposed to return"}, - {Error::Type::DeclarationError, "Unbalanced stack"}, - })); -} - -BOOST_AUTO_TEST_CASE(invalid_mobile_type) -{ - char const* text = R"( - contract C { - function f() public { - // Invalid number - [1, 78901234567890123456789012345678901234567890123456789345678901234567890012345678012345678901234567]; - } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid rational number."); -} - -BOOST_AUTO_TEST_CASE(warns_msg_value_in_non_payable_public_function) -{ - char const* text = R"( - contract C { - function f() view public { - msg.value; - } - } - )"; - CHECK_WARNING(text, "\"msg.value\" used in non-payable function. Do you want to add the \"payable\" modifier to this function?"); -} - -BOOST_AUTO_TEST_CASE(does_not_warn_msg_value_in_payable_function) -{ - char const* text = R"( - contract C { - function f() payable public { - msg.value; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(does_not_warn_msg_value_in_internal_function) -{ - char const* text = R"( - contract C { - function f() view internal { - msg.value; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(does_not_warn_msg_value_in_library) -{ - char const* text = R"( - library C { - function f() view public { - msg.value; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(does_not_warn_msg_value_in_modifier_following_non_payable_public_function) -{ - char const* text = R"( - contract c { - function f() pure public { } - modifier m() { msg.value; _; } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(assignment_to_constant) -{ - char const* text = R"( - contract c { - uint constant a = 1; - function f() public { a = 2; } - } - )"; - CHECK_ERROR(text, TypeError, "Cannot assign to a constant variable."); -} - -BOOST_AUTO_TEST_CASE(return_structs) -{ - char const* text = R"( - pragma experimental ABIEncoderV2; - contract C { - struct S { uint a; T[] sub; } - struct T { uint[] x; } - function f() returns (uint, S) { - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(read_returned_struct) -{ - char const* text = R"( - pragma experimental ABIEncoderV2; - contract A { - struct T { - int x; - int y; - } - function g() public returns (T) { - return this.g(); - } - } - )"; - CHECK_WARNING(text, "Experimental features"); -} -BOOST_AUTO_TEST_CASE(address_checksum_type_deduction) -{ - char const* text = R"( - contract C { - function f() public { - var x = 0xfA0bFc97E48458494Ccd857e1A85DC91F7F0046E; - x.send(2); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(invalid_address_checksum) -{ - char const* text = R"( - contract C { - function f() pure public { - address x = 0xFA0bFc97E48458494Ccd857e1A85DC91F7F0046E; - x; - } - } - )"; - CHECK_WARNING(text, "This looks like an address but has an invalid checksum."); -} - -BOOST_AUTO_TEST_CASE(invalid_address_no_checksum) -{ - char const* text = R"( - contract C { - function f() pure public { - address x = 0xfa0bfc97e48458494ccd857e1a85dc91f7f0046e; - x; - } - } - )"; - CHECK_WARNING(text, "This looks like an address but has an invalid checksum."); -} - -BOOST_AUTO_TEST_CASE(invalid_address_length_short) -{ - char const* text = R"( - contract C { - function f() pure public { - address x = 0xA0bFc97E48458494Ccd857e1A85DC91F7F0046E; - x; - } - } - )"; - CHECK_WARNING(text, "This looks like an address but has an invalid checksum."); -} - -BOOST_AUTO_TEST_CASE(invalid_address_length_long) -{ - char const* text = R"( - contract C { - function f() pure public { - address x = 0xFA0bFc97E48458494Ccd857e1A85DC91F7F0046E0; - x; - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::Warning, "This looks like an address but has an invalid checksum."}, - {Error::Type::TypeError, "not implicitly convertible"} - })); -} - -BOOST_AUTO_TEST_CASE(address_test_for_bug_in_implementation) -{ - char const* text = R"( - // A previous implementation claimed the string would be an address - contract AddrString { - address public test = "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c"; - } - )"; - CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type address"); - text = R"( - // A previous implementation claimed the string would be an address - contract AddrString { - function f() public returns (address) { - return "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c"; - } - } - )"; - CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type"); -} - -BOOST_AUTO_TEST_CASE(early_exit_on_fatal_errors) -{ - char const* text = R"( - // This tests a crash that occured because we did not stop for fatal errors. - contract C { - struct S { - ftring a; - } - S public s; - function s() s { - } - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier not found or not unique"); -} - -BOOST_AUTO_TEST_CASE(address_methods) -{ - char const* text = R"( - contract C { - function f() public { - address addr; - uint balance = addr.balance; - bool callRet = addr.call(); - bool callcodeRet = addr.callcode(); - bool delegatecallRet = addr.delegatecall(); - bool sendRet = addr.send(1); - addr.transfer(1); - callRet; callcodeRet; delegatecallRet; sendRet; - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(interface) -{ - char const* text = R"( - interface I { - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(interface_functions) -{ - char const* text = R"( - interface I { - function(); - function f(); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(interface_function_bodies) -{ - char const* text = R"( - interface I { - function f() public { - } - } - )"; - CHECK_ERROR(text, TypeError, "Functions in interfaces cannot have an implementation"); -} - -BOOST_AUTO_TEST_CASE(interface_events) -{ - char const* text = R"( - interface I { - event E(); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(interface_inheritance) -{ - char const* text = R"( - interface A { - } - interface I is A { - } - )"; - CHECK_ERROR(text, TypeError, "Interfaces cannot inherit"); -} - - -BOOST_AUTO_TEST_CASE(interface_structs) -{ - char const* text = R"( - interface I { - struct A { - } - } - )"; - CHECK_ERROR(text, TypeError, "Structs cannot be defined in interfaces"); -} - -BOOST_AUTO_TEST_CASE(interface_variables) -{ - char const* text = R"( - interface I { - uint a; - } - )"; - CHECK_ERROR(text, TypeError, "Variables cannot be declared in interfaces"); -} - -BOOST_AUTO_TEST_CASE(interface_function_parameters) -{ - char const* text = R"( - interface I { - function f(uint a) public returns (bool); - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(interface_enums) -{ - char const* text = R"( - interface I { - enum A { B, C } - } - )"; - CHECK_ERROR(text, TypeError, "Enumerable cannot be declared in interfaces"); -} - -BOOST_AUTO_TEST_CASE(using_interface) -{ - char const* text = R"( - interface I { - function f(); - } - contract C is I { - function f() public { - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(using_interface_complex) -{ - char const* text = R"( - interface I { - event A(); - function f(); - function g(); - function(); - } - contract C is I { - function f() public { - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(interface_implement_public_contract) -{ - char const* text = R"( - interface I { - function f() external; - } - contract C is I { - function f() public { - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(warn_about_throw) -{ - char const* text = R"( - contract C { - function f() pure public { - throw; - } - } - )"; - CHECK_WARNING(text, "\"throw\" is deprecated in favour of \"revert()\", \"require()\" and \"assert()\""); - text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() pure public { - throw; - } - } - )"; - CHECK_ERROR(text, SyntaxError, "\"throw\" is deprecated in favour of \"revert()\", \"require()\" and \"assert()\""); -} - -BOOST_AUTO_TEST_CASE(bare_revert) -{ - char const* text = R"( - contract C { - function f(uint x) pure public { - if (x > 7) - revert; - } - } - )"; - CHECK_ERROR(text, TypeError, "No matching declaration found"); -} - -BOOST_AUTO_TEST_CASE(revert_with_reason) -{ - char const* text = R"( - contract C { - function f(uint x) pure public { - if (x > 7) - revert("abc"); - else - revert(); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(bare_others) -{ - CHECK_WARNING("contract C { function f() pure public { selfdestruct; } }", "Statement has no effect."); - CHECK_WARNING("contract C { function f() pure public { assert; } }", "Statement has no effect."); - // This is different because it does have overloads. - CHECK_ERROR("contract C { function f() pure public { require; } }", TypeError, "No matching declaration found after variable lookup."); - CHECK_WARNING("contract C { function f() pure public { selfdestruct; } }", "Statement has no effect."); -} - -BOOST_AUTO_TEST_CASE(pure_statement_in_for_loop) -{ - char const* text = R"( - contract C { - function f() pure public { - for (uint x = 0; x < 10; true) - x++; - } - } - )"; - CHECK_WARNING(text, "Statement has no effect."); -} - -BOOST_AUTO_TEST_CASE(pure_statement_check_for_regular_for_loop) -{ - char const* text = R"( - contract C { - function f() pure public { - for (uint x = 0; true; x++) - {} - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(warn_unused_local) -{ - char const* text = R"( - contract C { - function f() pure public { - uint a; - } - } - )"; - CHECK_WARNING(text, "Unused local variable."); -} - -BOOST_AUTO_TEST_CASE(warn_unused_local_assigned) -{ - char const* text = R"( - contract C { - function f() pure public { - uint a = 1; - } - } - )"; - CHECK_WARNING(text, "Unused local variable."); -} - -BOOST_AUTO_TEST_CASE(warn_unused_function_parameter) -{ - char const* text = R"( - contract C { - function f(uint a) pure public { - } - } - )"; - CHECK_WARNING(text, "Unused function parameter. Remove or comment out the variable name to silence this warning."); - text = R"( - contract C { - function f(uint a) pure public { - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(warn_unused_return_parameter) -{ - char const* text = R"( - contract C { - function f() pure public returns (uint a) { - } - } - )"; - CHECK_WARNING(text, "Unused function parameter. Remove or comment out the variable name to silence this warning."); - text = R"( - contract C { - function f() pure public returns (uint a) { - return; - } - } - )"; - CHECK_WARNING(text, "Unused function parameter. Remove or comment out the variable name to silence this warning."); - text = R"( - contract C { - function f() pure public returns (uint) { - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - function f() pure public returns (uint a) { - a = 1; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - function f() pure public returns (uint a) { - return 1; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(no_unused_warning_interface_arguments) -{ - char const* text = R"( - interface I { - function f(uint a) pure external returns (uint b); - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(no_unused_warning_abstract_arguments) -{ - char const* text = R"( - contract C { - function f(uint a) pure public returns (uint b); - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(no_unused_warnings) -{ - char const* text = R"( - contract C { - function f(uint a) pure public returns (uint b) { - uint c = 1; - b = a + c; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(no_unused_dec_after_use) -{ - char const* text = R"( - contract C { - function f() pure public { - a = 7; - uint a; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(no_unused_inline_asm) -{ - char const* text = R"( - contract C { - function f() pure public { - uint a; - assembly { - a := 1 - } - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(shadowing_builtins_with_functions) -{ - char const* text = R"( - contract C { - function keccak256() pure public {} - } - )"; - CHECK_WARNING(text, "shadows a builtin symbol"); -} - -BOOST_AUTO_TEST_CASE(shadowing_builtins_with_variables) -{ - char const* text = R"( - contract C { - function f() pure public { - uint msg; - msg; - } - } - )"; - CHECK_WARNING(text, "shadows a builtin symbol"); -} - -BOOST_AUTO_TEST_CASE(shadowing_builtins_with_storage_variables) -{ - char const* text = R"( - contract C { - uint msg; - } - )"; - CHECK_WARNING(text, "shadows a builtin symbol"); -} - -BOOST_AUTO_TEST_CASE(shadowing_builtin_at_global_scope) -{ - char const* text = R"( - contract msg { - } - )"; - CHECK_WARNING(text, "shadows a builtin symbol"); -} - -BOOST_AUTO_TEST_CASE(shadowing_builtins_with_parameters) -{ - char const* text = R"( - contract C { - function f(uint require) pure public { - require = 2; - } - } - )"; - CHECK_WARNING(text, "shadows a builtin symbol"); -} - -BOOST_AUTO_TEST_CASE(shadowing_builtins_with_return_parameters) -{ - char const* text = R"( - contract C { - function f() pure public returns (uint require) { - require = 2; - } - } - )"; - CHECK_WARNING(text, "shadows a builtin symbol"); -} - -BOOST_AUTO_TEST_CASE(shadowing_builtins_with_events) -{ - char const* text = R"( - contract C { - event keccak256(); - } - )"; - CHECK_WARNING(text, "shadows a builtin symbol"); -} - -BOOST_AUTO_TEST_CASE(shadowing_builtins_ignores_struct) -{ - char const* text = R"( - contract C { - struct a { - uint msg; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(shadowing_builtins_ignores_constructor) -{ - char const* text = R"( - contract C { - constructor() public {} - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(function_overload_is_not_shadowing) -{ - char const* text = R"( - contract C { - function f() pure public {} - function f(uint) pure public {} - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(function_override_is_not_shadowing) -{ - char const* text = R"( - contract D { function f() pure public {} } - contract C is D { - function f(uint) pure public {} - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(event_parameter_cannot_shadow_state_variable) -{ - char const* text = R"( - contract C { - address a; - event E(address a); - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(callable_crash) -{ - char const* text = R"( - contract C { - struct S { uint a; bool x; } - S public s; - function C() public { - 3({a: 1, x: true}); - } - } - )"; - CHECK_ERROR(text, TypeError, "Type is not callable"); -} - -BOOST_AUTO_TEST_CASE(error_transfer_non_payable_fallback) -{ - char const* text = R"( - // This used to be a test for a.transfer to generate a warning - // because A's fallback function is not payable. - - contract A { - function() public {} - } - - contract B { - A a; - - function() public { - a.transfer(100); - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::Warning, "Using contract member \"transfer\" inherited from the address type is deprecated"}, - {Error::Type::TypeError, "Value transfer to a contract without a payable fallback function"} - })); -} - -BOOST_AUTO_TEST_CASE(error_transfer_no_fallback) -{ - char const* text = R"( - // This used to be a test for a.transfer to generate a warning - // because A does not have a payable fallback function. - - contract A {} - - contract B { - A a; - - function() public { - a.transfer(100); - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::Warning, "Using contract member \"transfer\" inherited from the address type is deprecated"}, - {Error::Type::TypeError, "Value transfer to a contract without a payable fallback function"} - })); -} - -BOOST_AUTO_TEST_CASE(error_send_non_payable_fallback) -{ - char const* text = R"( - // This used to be a test for a.send to generate a warning - // because A does not have a payable fallback function. - - contract A { - function() public {} - } - - contract B { - A a; - - function() public { - require(a.send(100)); - } - } - )"; - CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ - {Error::Type::Warning, "Using contract member \"send\" inherited from the address type is deprecated"}, - {Error::Type::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"( - // This used to be a test for a.transfer to generate a warning - // because A does not have a payable fallback function. - - contract A { - function() payable public {} - } - - contract B { - A a; - - function() public { - a.transfer(100); - } - } - )"; - CHECK_WARNING(text, "Using contract member \"transfer\" inherited from the address type is deprecated."); -} - -BOOST_AUTO_TEST_CASE(does_not_error_transfer_regular_function) -{ - char const* text = R"( - contract A { - function transfer() pure public {} - } - - contract B { - A a; - - function() public { - a.transfer(); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - BOOST_AUTO_TEST_CASE(returndatasize_as_variable) { char const* text = R"( @@ -6063,6 +407,8 @@ BOOST_AUTO_TEST_CASE(create2_as_variable) char const* text = R"( contract c { function f() public { uint create2; assembly { create2(0, 0, 0, 0) } }} )"; + // This needs special treatment, because the message mentions the EVM version, + // so cannot be run via isoltest. CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ {Error::Type::Warning, "Variable is shadowed in inline assembly by an instruction of the same name"}, {Error::Type::Warning, "The \"create2\" instruction is not supported by the VM version"}, @@ -6071,928 +417,6 @@ BOOST_AUTO_TEST_CASE(create2_as_variable) })); } -BOOST_AUTO_TEST_CASE(warn_unspecified_storage) -{ - char const* text = R"( - contract C { - struct S { uint a; string b; } - S x; - function f() view public { - S storage y = x; - y; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - struct S { uint a; } - S x; - function f() view public { - S y = x; - y; - } - } - )"; - CHECK_WARNING(text, "Variable is declared as a storage pointer. Use an explicit \"storage\" keyword to silence this warning"); - text = R"( - pragma experimental "v0.5.0"; - contract C { - struct S { uint a; } - S x; - function f() view public { - S y = x; - y; - } - } - )"; - CHECK_ERROR(text, TypeError, "Storage location must be specified as either \"memory\" or \"storage\"."); -} - -BOOST_AUTO_TEST_CASE(storage_location_non_array_or_struct_disallowed) -{ - char const* text = R"( - contract C { - function f(uint storage a) public { } - } - )"; - CHECK_ERROR(text, TypeError, "Storage location can only be given for array or struct types."); -} - -BOOST_AUTO_TEST_CASE(storage_location_non_array_or_struct_disallowed_is_not_fatal) -{ - char const* text = R"( - contract C { - function f(uint storage a) public { - a = f; - } - } - )"; - CHECK_ERROR_ALLOW_MULTI(text, TypeError, (std::vector<std::string>{"Storage location can only be given for array or struct types."})); -} - -BOOST_AUTO_TEST_CASE(implicit_conversion_disallowed) -{ - char const* text = R"( - contract C { - function f() public returns (bytes4) { - uint32 tmp = 1; - return tmp; - } - } - )"; - CHECK_ERROR(text, TypeError, "Return argument type uint32 is not implicitly convertible to expected type (type of first return variable) bytes4."); -} - -BOOST_AUTO_TEST_CASE(too_large_arrays_for_calldata) -{ - char const* text = R"( - contract C { - function f(uint[85678901234] a) pure external { - } - } - )"; - CHECK_ERROR(text, TypeError, "Array is too large to be encoded."); - text = R"( - contract C { - function f(uint[85678901234] a) pure internal { - } - } - )"; - CHECK_ERROR(text, TypeError, "Array is too large to be encoded."); - text = R"( - contract C { - function f(uint[85678901234] a) pure public { - } - } - )"; - CHECK_ERROR(text, TypeError, "Array is too large to be encoded."); -} - -BOOST_AUTO_TEST_CASE(explicit_literal_to_storage_string) -{ - char const* text = R"( - contract C { - function f() pure public { - string memory x = "abc"; - x; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - function f() pure public { - string storage x = "abc"; - } - } - )"; - CHECK_ERROR(text, TypeError, "Type literal_string \"abc\" is not implicitly convertible to expected type string storage pointer."); - text = R"( - contract C { - function f() pure public { - string x = "abc"; - } - } - )"; - CHECK_ERROR(text, TypeError, "Type literal_string \"abc\" is not implicitly convertible to expected type string storage pointer."); - text = R"( - contract C { - function f() pure public { - string("abc"); - } - } - )"; - CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed from \"literal_string \"abc\"\" to \"string storage pointer\""); -} - -BOOST_AUTO_TEST_CASE(modifiers_access_storage_pointer) -{ - char const* text = R"( - contract C { - struct S { uint a; } - modifier m(S storage x) { - x; - _; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(function_types_sig) -{ - char const* text = R"( - contract C { - function f() view returns (bytes4) { - return f.selector; - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"selector\" not found"); - text = R"( - contract C { - function g() pure internal { - } - function f() view returns (bytes4) { - return g.selector; - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"selector\" not found"); - text = R"( - contract C { - function f() view returns (bytes4) { - function () g; - return g.selector; - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"selector\" not found"); - text = R"( - contract C { - function f() pure external returns (bytes4) { - return this.f.selector; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - function h() pure external { - } - function f() view external returns (bytes4) { - var g = this.h; - return g.selector; - } - } - )"; - CHECK_WARNING(text, "Use of the \"var\" keyword is deprecated."); - text = R"( - contract C { - function h() pure external { - } - function f() view external returns (bytes4) { - function () pure external g = this.h; - return g.selector; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - function h() pure external { - } - function f() view external returns (bytes4) { - function () pure external g = this.h; - var i = g; - return i.selector; - } - } - )"; - CHECK_WARNING(text, "Use of the \"var\" keyword is deprecated."); -} - -BOOST_AUTO_TEST_CASE(using_this_in_constructor) -{ - char const* text = R"( - contract C { - constructor() public { - this.f(); - } - function f() pure public { - } - } - )"; - CHECK_WARNING(text, "\"this\" used in constructor"); -} - -BOOST_AUTO_TEST_CASE(do_not_crash_on_not_lvalue) -{ - char const* text = R"( - // This checks for a bug that caused a crash because of continued analysis. - contract C { - mapping (uint => uint) m; - function f() public { - m(1) = 2; - } - } - )"; - CHECK_ERROR_ALLOW_MULTI(text, TypeError, (std::vector<std::string>{ - "is not callable", - "Expression has to be an lvalue", - "Type int_const 2 is not implicitly" - })); -} - -BOOST_AUTO_TEST_CASE(builtin_reject_gas) -{ - char const* text = R"( - contract C { - function f() public { - keccak256.gas(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"gas\" not found or not visible after argument-dependent lookup"); - text = R"( - contract C { - function f() public { - sha256.gas(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"gas\" not found or not visible after argument-dependent lookup"); - text = R"( - contract C { - function f() public { - ripemd160.gas(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"gas\" not found or not visible after argument-dependent lookup"); - text = R"( - contract C { - function f() public { - ecrecover.gas(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"gas\" not found or not visible after argument-dependent lookup"); -} - -BOOST_AUTO_TEST_CASE(gasleft) -{ - char const* text = R"( - contract C { - function f() public view returns (uint256 val) { return msg.gas; } - } - )"; - CHECK_WARNING(text, "\"msg.gas\" has been deprecated in favor of \"gasleft()\""); - - text = R"( - contract C { - function f() public view returns (uint256 val) { return gasleft(); } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - - text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() public returns (uint256 val) { return msg.gas; } - } - )"; - CHECK_ERROR(text, TypeError, "\"msg.gas\" has been deprecated in favor of \"gasleft()\""); -} - -BOOST_AUTO_TEST_CASE(gasleft_shadowing) -{ - char const* text = R"( - contract C { - function gasleft() public pure returns (bytes32 val) { return "abc"; } - function f() public pure returns (bytes32 val) { return gasleft(); } - } - )"; - CHECK_WARNING(text, "This declaration shadows a builtin symbol."); - - text = R"( - contract C { - uint gasleft; - function f() public { gasleft = 42; } - } - )"; - CHECK_WARNING(text, "This declaration shadows a builtin symbol."); -} - -BOOST_AUTO_TEST_CASE(builtin_reject_value) -{ - char const* text = R"( - contract C { - function f() public { - keccak256.value(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup"); - text = R"( - contract C { - function f() public { - sha256.value(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup"); - text = R"( - contract C { - function f() public { - ripemd160.value(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup"); - text = R"( - contract C { - function f() public { - ecrecover.value(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup"); -} - -BOOST_AUTO_TEST_CASE(large_storage_array_fine) -{ - char const* text = R"( - contract C { - uint[2**64 - 1] x; - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(large_storage_array_simple) -{ - char const* text = R"( - contract C { - uint[2**64] x; - } - )"; - CHECK_WARNING(text, "covers a large part of storage and thus makes collisions likely"); -} - -BOOST_AUTO_TEST_CASE(large_storage_arrays_combined) -{ - char const* text = R"( - contract C { - uint[200][200][2**30][][2**30] x; - } - )"; - CHECK_WARNING(text, "covers a large part of storage and thus makes collisions likely"); -} - -BOOST_AUTO_TEST_CASE(large_storage_arrays_struct) -{ - char const* text = R"( - contract C { - struct S { uint[2**30] x; uint[2**50] y; } - S[2**20] x; - } - )"; - CHECK_WARNING(text, "covers a large part of storage and thus makes collisions likely"); -} - -BOOST_AUTO_TEST_CASE(large_storage_array_mapping) -{ - char const* text = R"( - contract C { - mapping(uint => uint[2**100]) x; - } - )"; - CHECK_WARNING(text, "covers a large part of storage and thus makes collisions likely"); -} - -BOOST_AUTO_TEST_CASE(library_function_without_implementation) -{ - char const* text = R"( - library L { - function f() public; - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - library L { - function f() internal; - } - )"; - CHECK_ERROR(text, TypeError, "Internal library function must be implemented if declared."); - text = R"( - library L { - function f() private; - } - )"; - CHECK_ERROR(text, TypeError, "Internal library function must be implemented if declared."); -} - -BOOST_AUTO_TEST_CASE(using_for_with_non_library) -{ - char const* text = R"( - // This tests a crash that was resolved by making the first error fatal. - library L { - struct S { uint d; } - using S for S; - function f(S _s) internal { - _s.d = 1; - } - } - )"; - CHECK_ERROR(text, TypeError, "Library name expected."); -} - -BOOST_AUTO_TEST_CASE(experimental_pragma) -{ - char const* text = R"( - pragma experimental; - )"; - CHECK_ERROR(text, SyntaxError, "Experimental feature name is missing."); - text = R"( - pragma experimental 123; - )"; - CHECK_ERROR(text, SyntaxError, "Unsupported experimental feature name."); - text = R"( - pragma experimental unsupportedName; - )"; - CHECK_ERROR(text, SyntaxError, "Unsupported experimental feature name."); - text = R"( - pragma experimental "unsupportedName"; - )"; - CHECK_ERROR(text, SyntaxError, "Unsupported experimental feature name."); - text = R"( - pragma experimental ""; - )"; - CHECK_ERROR(text, SyntaxError, "Empty experimental feature name is invalid."); - text = R"( - pragma experimental unsupportedName unsupportedName; - )"; - CHECK_ERROR(text, SyntaxError, "Stray arguments."); - text = R"( - pragma experimental __test; - )"; - CHECK_WARNING(text, "Experimental features are turned on. Do not use experimental features on live deployments."); - text = R"( - pragma experimental __test; - pragma experimental __test; - )"; - CHECK_ERROR_ALLOW_MULTI(text, SyntaxError, (std::vector<std::string>{"Duplicate experimental feature name."})); -} - -BOOST_AUTO_TEST_CASE(reject_interface_creation) -{ - char const* text = R"( - interface I {} - contract C { - function f() public { - new I(); - } - } - )"; - CHECK_ERROR(text, TypeError, "Cannot instantiate an interface."); -} - -BOOST_AUTO_TEST_CASE(accept_library_creation) -{ - char const* text = R"( - library L {} - contract C { - function f() public { - new L(); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(reject_interface_constructors) -{ - char const* text = R"( - interface I {} - contract C is I(2) {} - )"; - CHECK_ERROR(text, TypeError, "Wrong argument count for constructor call: 1 arguments given but expected 0."); -} - -BOOST_AUTO_TEST_CASE(non_external_fallback) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract C { - function () external { } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - pragma experimental "v0.5.0"; - contract C { - function () internal { } - } - )"; - CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\"."); - text = R"( - pragma experimental "v0.5.0"; - contract C { - function () private { } - } - )"; - CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\"."); - text = R"( - pragma experimental "v0.5.0"; - contract C { - function () public { } - } - )"; - CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\"."); -} - -BOOST_AUTO_TEST_CASE(invalid_literal_in_tuple) -{ - char const* text = R"( - contract C { - function f() pure public { - uint x; - (x, ) = (1E111); - } - } - )"; - CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type"); - text = R"( - contract C { - function f() pure public { - uint x; - (x, ) = (1, 1E111); - } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid rational number."); - text = R"( - contract C { - function f() pure public { - uint x; - (x, ) = (1E111, 1); - } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid rational number."); - text = R"( - contract C { - function f() pure public { - (2**270, 1); - } - } - )"; - CHECK_ERROR(text, TypeError, "Invalid rational number."); - text = R"( - contract C { - function f() pure public { - ((2**270) / 2**100, 1); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(address_overload_resolution) -{ - char const* text = R"( - contract C { - function balance() returns (uint) { - this.balance; // to avoid pureness warning - return 1; - } - function transfer(uint amount) { - address(this).transfer(amount); // to avoid pureness warning - } - } - contract D { - function f() { - var x = (new C()).balance(); - x; - (new C()).transfer(5); - } - } - )"; - CHECK_SUCCESS(text); -} - -BOOST_AUTO_TEST_CASE(array_length_invalid_expression) -{ - char const* text = R"( - contract C { - uint[-true] ids; - } - )"; - CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression."); - text = R"( - contract C { - uint[true/1] ids; - } - )"; - CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression."); - text = R"( - contract C { - uint[1/true] ids; - } - )"; - CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression."); - text = R"( - contract C { - uint[1.111111E1111111111111] ids; - } - )"; - CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression."); - text = R"( - contract C { - uint[3/0] ids; - } - )"; - CHECK_ERROR(text, TypeError, "Operator / not compatible with types int_const 3 and int_const 0"); -} - -BOOST_AUTO_TEST_CASE(warn_about_address_members_on_contract) -{ - char const* text = R"( - contract C { - function f() view public { - this.balance; - } - } - )"; - CHECK_WARNING(text, "Using contract member \"balance\" inherited from the address type is deprecated."); - text = R"( - contract C { - function f() view public { - this.transfer; - } - } - )"; - CHECK_ALLOW_MULTI(text, (vector<pair<Error::Type, std::string>>{ - {Error::Type::Warning, "Using contract member \"transfer\" inherited from the address type is deprecated"}, - {Error::Type::TypeError, "Value transfer to a contract without a payable fallback function"} - })); - text = R"( - contract C { - function f() view public { - this.send; - } - } - )"; - CHECK_ALLOW_MULTI(text, (vector<pair<Error::Type, std::string>>{ - {Error::Type::Warning, "Using contract member \"send\" inherited from the address type is deprecated"}, - {Error::Type::TypeError, "Value transfer to a contract without a payable fallback function"} - })); - text = R"( - contract C { - function f() view public { - this.call; - } - } - )"; - CHECK_WARNING(text, "Using contract member \"call\" inherited from the address type is deprecated."); - text = R"( - contract C { - function f() view public { - this.callcode; - } - } - )"; - CHECK_ALLOW_MULTI(text, (vector<pair<Error::Type, std::string>>{ - {Error::Type::Warning, "Using contract member \"callcode\" inherited from the address type is deprecated"}, - {Error::Type::Warning, "\"callcode\" has been deprecated in favour of \"delegatecall\""} - })); - text = R"( - contract C { - function f() view public { - this.delegatecall; - } - } - )"; - CHECK_WARNING(text, "Using contract member \"delegatecall\" inherited from the address type is deprecated."); -} - -BOOST_AUTO_TEST_CASE(warn_about_address_members_on_non_this_contract) -{ - char const* text = R"( - contract C { - function f() view public { - C c; - c.balance; - } - } - )"; - CHECK_WARNING(text, "Using contract member \"balance\" inherited from the address type is deprecated"); - text = R"( - contract C { - function f() view public { - C c; - c.transfer; - } - } - )"; - CHECK_ALLOW_MULTI(text, (vector<pair<Error::Type, std::string>>{ - {Error::Type::Warning, "Using contract member \"transfer\" inherited from the address type is deprecated"}, - {Error::Type::TypeError, "Value transfer to a contract without a payable fallback function"} - })); - text = R"( - contract C { - function f() view public { - C c; - c.send; - } - } - )"; - CHECK_ALLOW_MULTI(text, (vector<pair<Error::Type, std::string>>{ - {Error::Type::Warning, "Using contract member \"send\" inherited from the address type is deprecated"}, - {Error::Type::TypeError, "Value transfer to a contract without a payable fallback function"} - })); - text = R"( - contract C { - function f() pure public { - C c; - c.call; - } - } - )"; - CHECK_WARNING(text, "Using contract member \"call\" inherited from the address type is deprecated"); - text = R"( - contract C { - function f() pure public { - C c; - c.callcode; - } - } - )"; - CHECK_WARNING_ALLOW_MULTI(text, (std::vector<std::string>{ - "Using contract member \"callcode\" inherited from the address type is deprecated", - "\"callcode\" has been deprecated in favour of \"delegatecall\"" - })); - text = R"( - contract C { - function f() pure public { - C c; - c.delegatecall; - } - } - )"; - CHECK_WARNING(text, "Using contract member \"delegatecall\" inherited from the address type is deprecated"); -} - -BOOST_AUTO_TEST_CASE(no_address_members_on_contract) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() public { - this.balance; - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"balance\" not found or not visible after argument-dependent lookup in contract"); - text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() public { - this.transfer; - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"transfer\" not found or not visible after argument-dependent lookup in contract"); - text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() public { - this.send; - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"send\" not found or not visible after argument-dependent lookup in contract"); - text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() public { - this.call; - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"call\" not found or not visible after argument-dependent lookup in contract"); - text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() public { - this.callcode; - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"callcode\" not found or not visible after argument-dependent lookup in contract"); - text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() public { - this.delegatecall; - } - } - )"; - CHECK_ERROR(text, TypeError, "Member \"delegatecall\" not found or not visible after argument-dependent lookup in contract"); -} - -BOOST_AUTO_TEST_CASE(no_warning_for_using_members_that_look_like_address_members) -{ - char const* text = R"( - pragma experimental "v0.5.0"; - contract C { - function transfer(uint) public; - function f() public { - this.transfer(10); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(emit_events) -{ - char const* text = R"( - contract C { - event e(); - function f() public { - emit e(); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - event e(uint a, string b); - function f() public { - emit e(2, "abc"); - emit e({b: "abc", a: 8}); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract A { event e(uint a, string b); } - contract C is A { - function f() public { - emit A.e(2, "abc"); - emit A.e({b: "abc", a: 8}); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(old_style_events_050) -{ - char const* text = R"( - contract C { - event e(); - function f() public { - e(); - } - } - )"; - CHECK_WARNING(text, "without \"emit\" prefix"); - text = R"( - pragma experimental "v0.5.0"; - contract C { - event e(); - function f() public { - e(); - } - } - )"; - CHECK_ERROR(text, TypeError, "have to be prefixed"); -} - BOOST_AUTO_TEST_CASE(getter_is_memory_type) { char const* text = R"( @@ -7013,50 +437,6 @@ BOOST_AUTO_TEST_CASE(getter_is_memory_type) } } -BOOST_AUTO_TEST_CASE(require_visibility_specifiers) -{ - char const* text = R"( - contract C { - function f() pure { } - } - )"; - CHECK_WARNING(text, "No visibility specified. Defaulting to"); - text = R"( - pragma experimental "v0.5.0"; - contract C { - function f() pure { } - } - )"; - CHECK_ERROR(text, SyntaxError, "No visibility specified."); -} - -BOOST_AUTO_TEST_CASE(blockhash) -{ - char const* code = R"( - contract C { - function f() public view returns (bytes32) { - return block.blockhash(3); - } - } - )"; - CHECK_WARNING(code, "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\""); - - code = R"( - contract C { - function f() public view returns (bytes32) { return blockhash(3); } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(code); - - code = R"( - pragma experimental "v0.5.0"; - contract C { - function f() public returns (bytes32) { return block.blockhash(3); } - } - )"; - CHECK_ERROR(code, TypeError, "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\""); -} - BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNatspecJSON.cpp b/test/libsolidity/SolidityNatspecJSON.cpp index eeebeb74..98a3bba9 100644 --- a/test/libsolidity/SolidityNatspecJSON.cpp +++ b/test/libsolidity/SolidityNatspecJSON.cpp @@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(user_basic_test) char const* sourceCode = R"( contract test { /// @notice Multiplies `a` by 7 - function mul(uint a) returns(uint d) { return a * 7; } + function mul(uint a) public returns(uint d) { return a * 7; } } )"; @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(dev_and_user_basic_test) contract test { /// @notice Multiplies `a` by 7 /// @dev Multiplies a number by 7 - function mul(uint a) returns(uint d) { return a * 7; } + function mul(uint a) public returns (uint d) { return a * 7; } } )"; @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(user_multiline_comment) contract test { /// @notice Multiplies `a` by 7 /// and then adds `b` - function mul_and_add(uint a, uint256 b) returns(uint256 d) { + function mul_and_add(uint a, uint256 b) public returns (uint256 d) { return (a * 7) + b; } } @@ -148,17 +148,17 @@ BOOST_AUTO_TEST_CASE(user_multiple_functions) char const* sourceCode = R"( contract test { /// @notice Multiplies `a` by 7 and then adds `b` - function mul_and_add(uint a, uint256 b) returns(uint256 d) { + function mul_and_add(uint a, uint256 b) public returns (uint256 d) { return (a * 7) + b; } /// @notice Divides `input` by `div` - function divide(uint input, uint div) returns(uint d) { + function divide(uint input, uint div) public returns (uint d) { return input / div; } /// @notice Subtracts 3 from `input` - function sub(int input) returns(int d) { + function sub(int input) public returns (int d) { return input - 3; } } @@ -189,10 +189,10 @@ BOOST_AUTO_TEST_CASE(dev_and_user_no_doc) { char const* sourceCode = R"( contract test { - function mul(uint a) returns(uint d) { + function mul(uint a) public returns (uint d) { return a * 7; } - function sub(int input) returns(int d) { + function sub(int input) public returns (int d) { return input - 3; } } @@ -213,7 +213,7 @@ BOOST_AUTO_TEST_CASE(dev_desc_after_nl) /// Multiplies a number by 7 and adds second parameter /// @param a Documentation for the first parameter /// @param second Documentation for the second parameter - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(dev_multiple_params) /// @dev Multiplies a number by 7 and adds second parameter /// @param a Documentation for the first parameter /// @param second Documentation for the second parameter - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE(dev_multiple_params_mixed_whitespace) " /// @dev Multiplies a number by 7 and adds second parameter\n" " /// @param a Documentation for the first parameter\n" " /// @param second Documentation for the second parameter\n" - " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n" + " function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; }\n" "}\n"; char const* natspec = "{" @@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE(dev_mutiline_param_description) /// @param a Documentation for the first parameter starts here. /// Since it's a really complicated parameter we need 2 lines /// @param second Documentation for the second parameter - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -312,18 +312,18 @@ BOOST_AUTO_TEST_CASE(dev_multiple_functions) /// @dev Multiplies a number by 7 and adds second parameter /// @param a Documentation for the first parameter /// @param second Documentation for the second parameter - function mul(uint a, uint second) returns(uint d) { + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } /// @dev Divides 2 numbers /// @param input Documentation for the input parameter /// @param div Documentation for the div parameter - function divide(uint input, uint div) returns(uint d) { + function divide(uint input, uint div) public returns (uint d) { return input / div; } /// @dev Subtracts 3 from `input` /// @param input Documentation for the input parameter - function sub(int input) returns(int d) { + function sub(int input) public returns (int d) { return input - 3; } } @@ -365,7 +365,7 @@ BOOST_AUTO_TEST_CASE(dev_return) /// Since it's a really complicated parameter we need 2 lines /// @param second Documentation for the second parameter /// @return The result of the multiplication - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -393,7 +393,7 @@ BOOST_AUTO_TEST_CASE(dev_return_desc_after_nl) /// @param second Documentation for the second parameter /// @return /// The result of the multiplication - function mul(uint a, uint second) returns(uint d) { + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } @@ -425,7 +425,7 @@ BOOST_AUTO_TEST_CASE(dev_multiline_return) /// @param second Documentation for the second parameter /// @return The result of the multiplication /// and cookies with nutella - function mul(uint a, uint second) returns(uint d) { + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } @@ -458,7 +458,7 @@ BOOST_AUTO_TEST_CASE(dev_multiline_comment) * @return The result of the multiplication * and cookies with nutella */ - function mul(uint a, uint second) returns(uint d) { + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } @@ -484,7 +484,7 @@ BOOST_AUTO_TEST_CASE(dev_contract_no_doc) char const* sourceCode = R"( contract test { /// @dev Mul function - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -506,7 +506,7 @@ BOOST_AUTO_TEST_CASE(dev_contract_doc) /// @title Just a test contract contract test { /// @dev Mul function - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -531,7 +531,7 @@ BOOST_AUTO_TEST_CASE(dev_author_at_function) contract test { /// @dev Mul function /// @author John Doe - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -554,7 +554,7 @@ BOOST_AUTO_TEST_CASE(natspec_notice_without_tag) char const* sourceCode = R"( contract test { /// I do something awesome - function mul(uint a) returns(uint d) { return a * 7; } + function mul(uint a) public returns (uint d) { return a * 7; } } )"; @@ -578,7 +578,7 @@ BOOST_AUTO_TEST_CASE(natspec_multiline_notice_without_tag) contract test { /// I do something awesome /// which requires two lines to explain - function mul(uint a) returns(uint d) { return a * 7; } + function mul(uint a) public returns (uint d) { return a * 7; } } )"; @@ -619,7 +619,7 @@ BOOST_AUTO_TEST_CASE(dev_title_at_function_error) contract test { /// @dev Mul function /// @title I really should not be here - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -633,7 +633,7 @@ BOOST_AUTO_TEST_CASE(dev_documenting_nonexistent_param) /// @dev Multiplies a number by 7 and adds second parameter /// @param a Documentation for the first parameter /// @param not_existing Documentation for the second parameter - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -647,7 +647,7 @@ BOOST_AUTO_TEST_CASE(dev_documenting_no_paramname) /// @dev Multiplies a number by 7 and adds second parameter /// @param a Documentation for the first parameter /// @param - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -661,7 +661,7 @@ BOOST_AUTO_TEST_CASE(dev_documenting_no_paramname_end) /// @dev Multiplies a number by 7 and adds second parameter /// @param a Documentation for the first parameter /// @param se - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; @@ -675,7 +675,7 @@ BOOST_AUTO_TEST_CASE(dev_documenting_no_param_description) /// @dev Multiplies a number by 7 and adds second parameter /// @param a Documentation for the first parameter /// @param second - function mul(uint a, uint second) returns(uint d) { return a * 7 + second; } + function mul(uint a, uint second) public returns (uint d) { return a * 7 + second; } } )"; diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index 3a8585f7..764550eb 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -104,7 +104,7 @@ public: "\nOptimized: " + toHex(optimizedOutput)); } - /// @returns the number of intructions in the given bytecode, not taking the metadata hash + /// @returns the number of instructions in the given bytecode, not taking the metadata hash /// into account. size_t numInstructions(bytes const& _bytecode, boost::optional<Instruction> _which = boost::optional<Instruction>{}) { @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(smoke_test) { char const* sourceCode = R"( contract test { - function f(uint a) returns (uint b) { + function f(uint a) public returns (uint b) { return a; } } @@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE(identities) { char const* sourceCode = R"( contract test { - function f(int a) returns (int b) { + function f(int a) public returns (int b) { return int(0) | (int(1) * (int(0) ^ (0 + a))); } } @@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(unused_expressions) char const* sourceCode = R"( contract test { uint data; - function f() returns (uint a, uint b) { + function f() public returns (uint a, uint b) { 10 + 20; data; } @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(constant_folding_both_sides) // literals as late as possible char const* sourceCode = R"( contract test { - function f(uint x) returns (uint y) { + function f(uint x) public returns (uint y) { return 98 ^ (7 * ((1 | (x | 1000)) * 40) ^ 102); } } @@ -194,7 +194,7 @@ BOOST_AUTO_TEST_CASE(storage_access) char const* sourceCode = R"( contract test { uint8[40] data; - function f(uint x) returns (uint y) { + function f(uint x) public returns (uint y) { data[2] = data[7] = uint8(x); data[4] = data[2] * 10 + data[3]; } @@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(array_copy) contract test { bytes2[] data1; bytes5[] data2; - function f(uint x) returns (uint l, uint y) { + function f(uint x) public returns (uint l, uint y) { data1.length = msg.data.length; for (uint i = 0; i < msg.data.length; ++i) data1[i] = msg.data[i]; @@ -230,8 +230,8 @@ BOOST_AUTO_TEST_CASE(function_calls) { char const* sourceCode = R"( contract test { - function f1(uint x) returns (uint) { return x*x; } - function f(uint x) returns (uint) { return f1(7+x) - this.f1(x**9); } + function f1(uint x) public returns (uint) { return x*x; } + function f(uint x) public returns (uint) { return f1(7+x) - this.f1(x**9); } } )"; compileBothVersions(sourceCode); @@ -245,8 +245,8 @@ BOOST_AUTO_TEST_CASE(storage_write_in_loops) char const* sourceCode = R"( contract test { uint d; - function f(uint a) returns (uint r) { - var x = d; + function f(uint a) public returns (uint r) { + uint x = d; for (uint i = 1; i < a * a; i++) { r = d; d = i; @@ -265,18 +265,18 @@ BOOST_AUTO_TEST_CASE(storage_write_in_loops) // Information in joining branches is not retained anymore. BOOST_AUTO_TEST_CASE(retain_information_in_branches) { - // This tests that the optimizer knows that we already have "z == keccak256(y)" inside both branches. + // This tests that the optimizer knows that we already have "z == keccak256(abi.encodePacked(y))" inside both branches. char const* sourceCode = R"( contract c { bytes32 d; uint a; - function f(uint x, bytes32 y) returns (uint r_a, bytes32 r_d) { - bytes32 z = keccak256(y); + function f(uint x, bytes32 y) public returns (uint r_a, bytes32 r_d) { + bytes32 z = keccak256(abi.encodePacked(y)); if (x > 8) { - z = keccak256(y); + z = keccak256(abi.encodePacked(y)); a = x; } else { - z = keccak256(y); + z = keccak256(abi.encodePacked(y)); a = x; } r_a = a; @@ -313,19 +313,19 @@ BOOST_AUTO_TEST_CASE(store_tags_as_unions) contract test { bytes32 data; function f(uint x, bytes32 y) external returns (uint r_a, bytes32 r_d) { - r_d = keccak256(y); + r_d = keccak256(abi.encodePacked(y)); shared(y); - r_d = keccak256(y); + r_d = keccak256(abi.encodePacked(y)); r_a = 5; } function g(uint x, bytes32 y) external returns (uint r_a, bytes32 r_d) { - r_d = keccak256(y); + r_d = keccak256(abi.encodePacked(y)); shared(y); - r_d = bytes32(uint(keccak256(y)) + 2); + r_d = bytes32(uint(keccak256(abi.encodePacked(y))) + 2); r_a = 7; } function shared(bytes32 y) internal { - data = keccak256(y); + data = keccak256(abi.encodePacked(y)); } } )"; @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(incorrect_storage_access_bug) contract C { mapping(uint => uint) data; - function f() returns (uint) + function f() public returns (uint) { if(data[now] == 0) data[uint(-7)] = 5; @@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE(sequence_number_for_calls) // to storage), so the sequence number should be incremented. char const* sourceCode = R"( contract test { - function f(string a, string b) returns (bool) { return sha256(a) == sha256(b); } + function f(string a, string b) public returns (bool) { return sha256(bytes(a)) == sha256(bytes(b)); } } )"; compileBothVersions(sourceCode); @@ -385,10 +385,10 @@ BOOST_AUTO_TEST_CASE(computing_constants) uint m_b; uint m_c; uint m_d; - function C() { + constructor() public { set(); } - function set() returns (uint) { + function set() public returns (uint) { m_a = 0x77abc0000000000000000000000000000000000000000000000000000000001; m_b = 0x817416927846239487123469187231298734162934871263941234127518276; g(); @@ -402,7 +402,7 @@ BOOST_AUTO_TEST_CASE(computing_constants) function h() { m_d = 0xff05694900000000000000000000000000000000000000000000000000000000; } - function get() returns (uint ra, uint rb, uint rc, uint rd) { + function get() public returns (uint ra, uint rb, uint rc, uint rd) { ra = m_a; rb = m_b; rc = m_c; @@ -444,7 +444,7 @@ BOOST_AUTO_TEST_CASE(constant_optimization_early_exit) pragma solidity ^0.4.0; contract HexEncoding { - function hexEncodeTest(address addr) returns (bytes32 ret) { + function hexEncodeTest(address addr) public returns (bytes32 ret) { uint x = uint(addr) / 2**32; // Nibble interleave @@ -518,8 +518,8 @@ BOOST_AUTO_TEST_CASE(inconsistency) // Called with params: containerIndex=0, valueIndex=0 function levelIII(uint containerIndex, uint valueIndex) private { - Container container = containers[containerIndex]; - Value value = container.values[valueIndex]; + Container storage container = containers[containerIndex]; + Value storage value = container.values[valueIndex]; debug = container.valueIndices[value.number]; } function levelII() private { @@ -530,7 +530,7 @@ BOOST_AUTO_TEST_CASE(inconsistency) function trigger() public returns (uint) { containers.length++; - Container container = containers[0]; + Container storage container = containers[0]; container.values.push(Value({ badnum: 9000, @@ -561,11 +561,11 @@ BOOST_AUTO_TEST_CASE(dead_code_elimination_across_assemblies) char const* sourceCode = R"( contract DCE { function () internal returns (uint) stored; - function DCE() { + constructor() public { stored = f; } function f() internal returns (uint) { return 7; } - function test() returns (uint) { return stored(); } + function test() public returns (uint) { return stored(); } } )"; compileBothVersions(sourceCode); @@ -577,12 +577,12 @@ BOOST_AUTO_TEST_CASE(invalid_state_at_control_flow_join) char const* sourceCode = R"( contract Test { uint256 public totalSupply = 100; - function f() returns (uint r) { + function f() public returns (uint r) { if (false) r = totalSupply; totalSupply -= 10; } - function test() returns (uint) { + function test() public returns (uint) { f(); return this.totalSupply(); } diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 0797b53b..5432e9b5 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation) contract test { uint256 stateVar; /// This is a test function - function functionName(bytes32 input) returns (bytes32 out) {} + function functionName(bytes32 input) public returns (bytes32 out) {} } )"; BOOST_CHECK(successParse(text)); @@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE(function_normal_comments) contract test { uint256 stateVar; // We won't see this comment - function functionName(bytes32 input) returns (bytes32 out) {} + function functionName(bytes32 input) public returns (bytes32 out) {} } )"; BOOST_CHECK(successParse(text)); @@ -157,13 +157,13 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) contract test { uint256 stateVar; /// This is test function 1 - function functionName1(bytes32 input) returns (bytes32 out) {} + function functionName1(bytes32 input) public returns (bytes32 out) {} /// This is test function 2 - function functionName2(bytes32 input) returns (bytes32 out) {} + function functionName2(bytes32 input) public returns (bytes32 out) {} // nothing to see here - function functionName3(bytes32 input) returns (bytes32 out) {} + function functionName3(bytes32 input) public returns (bytes32 out) {} /// This is test function 4 - function functionName4(bytes32 input) returns (bytes32 out) {} + function functionName4(bytes32 input) public returns (bytes32 out) {} } )"; BOOST_CHECK(successParse(text)); @@ -193,7 +193,7 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation) uint256 stateVar; /// This is a test function /// and it has 2 lines - function functionName1(bytes32 input) returns (bytes32 out) {} + function functionName1(bytes32 input) public returns (bytes32 out) {} } )"; BOOST_CHECK(successParse(text)); @@ -220,7 +220,7 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) } /// This is a test function /// and it has 2 lines - function fun(bytes32 input) returns (bytes32 out) {} + function fun(bytes32 input) public returns (bytes32 out) {} } )"; BOOST_CHECK(successParse(text)); @@ -491,28 +491,46 @@ BOOST_AUTO_TEST_CASE(keyword_is_reserved) auto keywords = { "abstract", "after", + "alias", + "apply", + "auto", "case", "catch", + "copyof", "default", + "define", "final", + "immutable", + "implements", "in", "inline", "let", + "macro", "match", + "mutable", "null", "of", + "override", + "partial", + "promise", + "reference", "relocatable", + "sealed", + "sizeof", "static", + "supports", "switch", "try", "type", - "typeof" + "typedef", + "typeof", + "unchecked" }; for (const auto& keyword: keywords) { auto text = std::string("contract ") + keyword + " {}"; - CHECK_PARSE_ERROR(text.c_str(), "Expected identifier but got reserved keyword"); + CHECK_PARSE_ERROR(text.c_str(), string("Expected identifier but got reserved keyword '") + keyword + "'"); } } diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp index 020bce7f..f455c5eb 100644 --- a/test/libsolidity/SolidityScanner.cpp +++ b/test/libsolidity/SolidityScanner.cpp @@ -127,6 +127,26 @@ BOOST_AUTO_TEST_CASE(scientific_notation) BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); } +BOOST_AUTO_TEST_CASE(trailing_dot) +{ + Scanner scanner(CharStream("2.5")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); + scanner.reset(CharStream("2.5e10"), ""); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); + scanner.reset(CharStream(".5"), ""); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); + scanner.reset(CharStream(".5e10"), ""); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); + scanner.reset(CharStream("2."), ""); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number); + BOOST_CHECK_EQUAL(scanner.next(), Token::Period); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); +} + BOOST_AUTO_TEST_CASE(negative_numbers) { Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9 + 2e-2;")); diff --git a/test/libsolidity/SolidityTypes.cpp b/test/libsolidity/SolidityTypes.cpp index e6928bb8..b8b537e5 100644 --- a/test/libsolidity/SolidityTypes.cpp +++ b/test/libsolidity/SolidityTypes.cpp @@ -60,7 +60,21 @@ BOOST_AUTO_TEST_CASE(byte_types) BOOST_AUTO_TEST_CASE(fixed_types) { BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::Fixed, 0, 0)) == *make_shared<FixedPointType>(128, 18, FixedPointType::Modifier::Signed)); + for (unsigned i = 8; i <= 256; i += 8) + { + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::FixedMxN, i, 0)) == *make_shared<FixedPointType>(i, 0, FixedPointType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::FixedMxN, i, 2)) == *make_shared<FixedPointType>(i, 2, FixedPointType::Modifier::Signed)); + } +} + +BOOST_AUTO_TEST_CASE(ufixed_types) +{ BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixed, 0, 0)) == *make_shared<FixedPointType>(128, 18, FixedPointType::Modifier::Unsigned)); + for (unsigned i = 8; i <= 256; i += 8) + { + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixedMxN, i, 0)) == *make_shared<FixedPointType>(i, 0, FixedPointType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixedMxN, i, 2)) == *make_shared<FixedPointType>(i, 2, FixedPointType::Modifier::Unsigned)); + } } BOOST_AUTO_TEST_CASE(storage_layout_simple) @@ -115,12 +129,13 @@ BOOST_AUTO_TEST_CASE(storage_layout_arrays) BOOST_CHECK(ArrayType(DataLocation::Storage, make_shared<FixedBytesType>(32), 9).storageSize() == 9); } -BOOST_AUTO_TEST_CASE(type_escaping) +BOOST_AUTO_TEST_CASE(type_identifier_escaping) { BOOST_CHECK_EQUAL(Type::escapeIdentifier("("), "$_"); BOOST_CHECK_EQUAL(Type::escapeIdentifier(")"), "_$"); BOOST_CHECK_EQUAL(Type::escapeIdentifier(","), "_$_"); BOOST_CHECK_EQUAL(Type::escapeIdentifier("$"), "$$$"); + BOOST_CHECK_EQUAL(Type::escapeIdentifier(")$("), "_$$$$$_"); BOOST_CHECK_EQUAL(Type::escapeIdentifier("()"), "$__$"); BOOST_CHECK_EQUAL(Type::escapeIdentifier("(,)"), "$__$__$"); BOOST_CHECK_EQUAL(Type::escapeIdentifier("(,$,)"), "$__$_$$$_$__$"); @@ -137,7 +152,7 @@ BOOST_AUTO_TEST_CASE(type_identifiers) BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("int128")->identifier(), "t_int128"); BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("address")->identifier(), "t_address"); BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("uint8")->identifier(), "t_uint8"); - BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("ufixed8x64")->identifier(), "t_ufixed8x64"); + BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("ufixed64x2")->identifier(), "t_ufixed64x2"); BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("fixed128x8")->identifier(), "t_fixed128x8"); BOOST_CHECK_EQUAL(RationalNumberType(rational(7, 1)).identifier(), "t_rational_7_by_1"); BOOST_CHECK_EQUAL(RationalNumberType(rational(200, 77)).identifier(), "t_rational_200_by_77"); @@ -146,12 +161,18 @@ BOOST_AUTO_TEST_CASE(type_identifiers) StringLiteralType(Literal(SourceLocation{}, Token::StringLiteral, make_shared<string>("abc - def"))).identifier(), "t_stringliteral_196a9142ee0d40e274a6482393c762b16dd8315713207365e1e13d8d85b74fc4" ); + BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("byte")->identifier(), "t_bytes1"); BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bytes8")->identifier(), "t_bytes8"); BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bytes32")->identifier(), "t_bytes32"); BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bool")->identifier(), "t_bool"); BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bytes")->identifier(), "t_bytes_storage_ptr"); BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bytes memory")->identifier(), "t_bytes_memory_ptr"); + BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bytes storage")->identifier(), "t_bytes_storage_ptr"); + BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bytes calldata")->identifier(), "t_bytes_calldata_ptr"); BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("string")->identifier(), "t_string_storage_ptr"); + BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("string memory")->identifier(), "t_string_memory_ptr"); + BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("string storage")->identifier(), "t_string_storage_ptr"); + BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("string calldata")->identifier(), "t_string_calldata_ptr"); ArrayType largeintArray(DataLocation::Memory, Type::fromElementaryTypeName("int128"), u256("2535301200456458802993406410752")); BOOST_CHECK_EQUAL(largeintArray.identifier(), "t_array$_t_int128_$2535301200456458802993406410752_memory_ptr"); TypePointer stringArray = make_shared<ArrayType>(DataLocation::Storage, Type::fromElementaryTypeName("string"), u256("20")); diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index 63c03881..bfb0d739 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -556,10 +556,10 @@ BOOST_AUTO_TEST_CASE(library_filename_with_colon) }, "sources": { "fileA": { - "content": "import \"git:library.sol\"; contract A { function f() returns (uint) { return L.g(); } }" + "content": "import \"git:library.sol\"; contract A { function f() public returns (uint) { return L.g(); } }" }, "git:library.sol": { - "content": "library L { function g() returns (uint) { return 1; } }" + "content": "library L { function g() public returns (uint) { return 1; } }" } } } @@ -706,10 +706,10 @@ BOOST_AUTO_TEST_CASE(library_linking) }, "sources": { "fileA": { - "content": "import \"library.sol\"; import \"library2.sol\"; contract A { function f() returns (uint) { L2.g(); return L.g(); } }" + "content": "import \"library.sol\"; import \"library2.sol\"; contract A { function f() public returns (uint) { L2.g(); return L.g(); } }" }, "library.sol": { - "content": "library L { function g() returns (uint) { return 1; } }" + "content": "library L { function g() public returns (uint) { return 1; } }" }, "library2.sol": { "content": "library L2 { function g() { } }" diff --git a/test/libsolidity/SyntaxTest.cpp b/test/libsolidity/SyntaxTest.cpp index 1c2355d5..1de42300 100644 --- a/test/libsolidity/SyntaxTest.cpp +++ b/test/libsolidity/SyntaxTest.cpp @@ -33,28 +33,10 @@ using namespace std; namespace fs = boost::filesystem; using namespace boost::unit_test; -template<typename IteratorType> -void skipWhitespace(IteratorType& _it, IteratorType _end) +namespace { - while (_it != _end && isspace(*_it)) - ++_it; -} -template<typename IteratorType> -void skipSlashes(IteratorType& _it, IteratorType _end) -{ - while (_it != _end && *_it == '/') - ++_it; -} - -void expect(string::iterator& _it, string::iterator _end, string::value_type _c) -{ - if (_it == _end || *_it != _c) - throw runtime_error(string("Invalid test expectation. Expected: \"") + _c + "\"."); - ++_it; -} - -int parseUnsignedInteger(string::iterator &_it, string::iterator _end) +int parseUnsignedInteger(string::iterator& _it, string::iterator _end) { if (_it == _end || !isdigit(*_it)) throw runtime_error("Invalid test expectation. Source location expected."); @@ -68,6 +50,8 @@ int parseUnsignedInteger(string::iterator &_it, string::iterator _end) return result; } +} + SyntaxTest::SyntaxTest(string const& _filename) { ifstream file(_filename); @@ -120,6 +104,55 @@ bool SyntaxTest::run(ostream& _stream, string const& _linePrefix, bool const _fo return true; } +void SyntaxTest::printSource(ostream& _stream, string const& _linePrefix, bool const _formatted) const +{ + if (_formatted) + { + if (m_source.empty()) + return; + + vector<char const*> sourceFormatting(m_source.length(), formatting::RESET); + for (auto const& error: m_errorList) + if (error.locationStart >= 0 && error.locationEnd >= 0) + { + assert(static_cast<size_t>(error.locationStart) <= m_source.length()); + assert(static_cast<size_t>(error.locationEnd) <= m_source.length()); + bool isWarning = error.type == "Warning"; + for (int i = error.locationStart; i < error.locationEnd; i++) + if (isWarning) + { + if (sourceFormatting[i] == formatting::RESET) + sourceFormatting[i] = formatting::ORANGE_BACKGROUND; + } + else + sourceFormatting[i] = formatting::RED_BACKGROUND; + } + + _stream << _linePrefix << sourceFormatting.front() << m_source.front(); + for (size_t i = 1; i < m_source.length(); i++) + { + if (sourceFormatting[i] != sourceFormatting[i - 1]) + _stream << sourceFormatting[i]; + if (m_source[i] != '\n') + _stream << m_source[i]; + else + { + _stream << formatting::RESET << endl; + if (i + 1 < m_source.length()) + _stream << _linePrefix << sourceFormatting[i]; + } + } + _stream << formatting::RESET; + } + else + { + stringstream stream(m_source); + string line; + while (getline(stream, line)) + _stream << _linePrefix << line << endl; + } +} + void SyntaxTest::printErrorList( ostream& _stream, vector<SyntaxTestError> const& _errorList, @@ -159,19 +192,6 @@ string SyntaxTest::errorMessage(Exception const& _e) return "NONE"; } -string SyntaxTest::parseSource(istream& _stream) -{ - string source; - string line; - string const delimiter("// ----"); - while (getline(_stream, line)) - if (boost::algorithm::starts_with(line, delimiter)) - break; - else - source += line + "\n"; - return source; -} - vector<SyntaxTestError> SyntaxTest::parseExpectations(istream& _stream) { vector<SyntaxTestError> expectations; @@ -220,64 +240,3 @@ vector<SyntaxTestError> SyntaxTest::parseExpectations(istream& _stream) } return expectations; } - -#if BOOST_VERSION < 105900 -test_case *make_test_case( - function<void()> const& _fn, - string const& _name, - string const& /* _filename */, - size_t /* _line */ -) -{ - return make_test_case(_fn, _name); -} -#endif - -bool SyntaxTest::isTestFilename(boost::filesystem::path const& _filename) -{ - return _filename.extension().string() == ".sol" && - !boost::starts_with(_filename.string(), "~") && - !boost::starts_with(_filename.string(), "."); -} - -int SyntaxTest::registerTests( - boost::unit_test::test_suite& _suite, - boost::filesystem::path const& _basepath, - boost::filesystem::path const& _path -) -{ - int numTestsAdded = 0; - fs::path fullpath = _basepath / _path; - if (fs::is_directory(fullpath)) - { - test_suite* sub_suite = BOOST_TEST_SUITE(_path.filename().string()); - for (auto const& entry: boost::iterator_range<fs::directory_iterator>( - fs::directory_iterator(fullpath), - fs::directory_iterator() - )) - if (fs::is_directory(entry.path()) || isTestFilename(entry.path().filename())) - numTestsAdded += registerTests(*sub_suite, _basepath, _path / entry.path().filename()); - _suite.add(sub_suite); - } - else - { - static vector<unique_ptr<string>> filenames; - - filenames.emplace_back(new string(_path.string())); - _suite.add(make_test_case( - [fullpath] - { - BOOST_REQUIRE_NO_THROW({ - stringstream errorStream; - if (!SyntaxTest(fullpath.string()).run(errorStream)) - BOOST_ERROR("Test expectation mismatch.\n" + errorStream.str()); - }); - }, - _path.stem().string(), - *filenames.back(), - 0 - )); - numTestsAdded = 1; - } - return numTestsAdded; -} diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h index 6159e789..e9e36aa6 100644 --- a/test/libsolidity/SyntaxTest.h +++ b/test/libsolidity/SyntaxTest.h @@ -19,11 +19,9 @@ #include <test/libsolidity/AnalysisFramework.h> #include <test/libsolidity/FormattedScope.h> +#include <test/libsolidity/TestCase.h> #include <libsolidity/interface/Exceptions.h> -#include <boost/noncopyable.hpp> -#include <boost/test/unit_test.hpp> - #include <iosfwd> #include <string> #include <vector> @@ -52,17 +50,24 @@ struct SyntaxTestError }; -class SyntaxTest: AnalysisFramework +class SyntaxTest: AnalysisFramework, public TestCase { public: + static std::unique_ptr<TestCase> create(std::string const& _filename) + { return std::unique_ptr<TestCase>(new SyntaxTest(_filename)); } SyntaxTest(std::string const& _filename); - bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false); + virtual bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override; - std::vector<SyntaxTestError> const& expectations() const { return m_expectations; } - std::string const& source() const { return m_source; } - std::vector<SyntaxTestError> const& errorList() const { return m_errorList; } + virtual void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false) const override; + virtual void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const override + { + if (!m_errorList.empty()) + printErrorList(_stream, m_errorList, _linePrefix, false); + } + static std::string errorMessage(Exception const& _e); +private: static void printErrorList( std::ostream& _stream, std::vector<SyntaxTestError> const& _errors, @@ -70,15 +75,6 @@ public: bool const _formatted = false ); - static int registerTests( - boost::unit_test::test_suite& _suite, - boost::filesystem::path const& _basepath, - boost::filesystem::path const& _path - ); - static bool isTestFilename(boost::filesystem::path const& _filename); - static std::string errorMessage(Exception const& _e); -private: - static std::string parseSource(std::istream& _stream); static std::vector<SyntaxTestError> parseExpectations(std::istream& _stream); std::string m_source; diff --git a/test/libsolidity/TestCase.cpp b/test/libsolidity/TestCase.cpp new file mode 100644 index 00000000..6c4e0aea --- /dev/null +++ b/test/libsolidity/TestCase.cpp @@ -0,0 +1,55 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <test/libsolidity/TestCase.h> + +#include <boost/algorithm/string.hpp> +#include <boost/algorithm/string/predicate.hpp> + +#include <stdexcept> + +using namespace dev; +using namespace solidity; +using namespace dev::solidity::test; +using namespace std; + +bool TestCase::isTestFilename(boost::filesystem::path const& _filename) +{ + return _filename.extension().string() == ".sol" && + !boost::starts_with(_filename.string(), "~") && + !boost::starts_with(_filename.string(), "."); +} + +string TestCase::parseSource(istream& _stream) +{ + string source; + string line; + string const delimiter("// ----"); + while (getline(_stream, line)) + if (boost::algorithm::starts_with(line, delimiter)) + break; + else + source += line + "\n"; + return source; +} + +void TestCase::expect(string::iterator& _it, string::iterator _end, string::value_type _c) +{ + if (_it == _end || *_it != _c) + throw runtime_error(string("Invalid test expectation. Expected: \"") + _c + "\"."); + ++_it; +} diff --git a/test/libsolidity/TestCase.h b/test/libsolidity/TestCase.h new file mode 100644 index 00000000..3c05ae4e --- /dev/null +++ b/test/libsolidity/TestCase.h @@ -0,0 +1,80 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include <boost/filesystem.hpp> + +#include <iosfwd> +#include <memory> +#include <string> + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +/** Common superclass of SyntaxTest and SemanticsTest. */ +class TestCase +{ +public: + using TestCaseCreator = std::unique_ptr<TestCase>(*)(std::string const&); + + virtual ~TestCase() {} + + /// Runs the test case. + /// Outputs error messages to @arg _stream. Each line of output is prefixed with @arg _linePrefix. + /// Optionally, color-coding can be enabled (if @arg _formatted is set to true). + /// @returns true, if the test case succeeds, false otherwise + virtual bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) = 0; + + /// Outputs the test contract to @arg _stream. + /// Each line of output is prefixed with @arg _linePrefix. + /// If @arg _formatted is true, color-coding may be used to indicate + /// error locations in the contract, if applicable. + virtual void printSource(std::ostream &_stream, std::string const &_linePrefix = "", bool const _formatted = false) const = 0; + /// Outputs test expectations to @arg _stream that match the actual results of the test. + /// Each line of output is prefixed with @arg _linePrefix. + virtual void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const = 0; + + static bool isTestFilename(boost::filesystem::path const& _filename); + +protected: + static std::string parseSource(std::istream& _file); + static void expect(std::string::iterator& _it, std::string::iterator _end, std::string::value_type _c); + + template<typename IteratorType> + static void skipWhitespace(IteratorType& _it, IteratorType _end) + { + while (_it != _end && isspace(*_it)) + ++_it; + } + + template<typename IteratorType> + static void skipSlashes(IteratorType& _it, IteratorType _end) + { + while (_it != _end && *_it == '/') + ++_it; + } + +}; + +} +} +} diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index cd0a0b01..299cd084 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -38,83 +38,16 @@ namespace test BOOST_FIXTURE_TEST_SUITE(ViewPureChecker, AnalysisFramework) -BOOST_AUTO_TEST_CASE(smoke_test) -{ - char const* text = R"( - contract C { - uint x; - function g() pure public {} - function f() view public returns (uint) { return now; } - function h() public { x = 2; } - function i() payable public { x = 2; } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(call_internal_functions_success) -{ - char const* text = R"( - contract C { - function g() pure public { g(); } - function f() view public returns (uint) { f(); g(); } - function h() public { h(); g(); f(); } - function i() payable public { i(); h(); g(); f(); } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(suggest_pure) -{ - char const* text = R"( - contract C { - function g() view public { } - } - )"; - CHECK_WARNING(text, "can be restricted to pure"); -} - -BOOST_AUTO_TEST_CASE(suggest_view) -{ - char const* text = R"( - contract C { - uint x; - function g() public returns (uint) { return x; } - } - )"; - CHECK_WARNING(text, "can be restricted to view"); -} - -BOOST_AUTO_TEST_CASE(call_internal_functions_fail) -{ - CHECK_ERROR( - "contract C{ function f() pure public { g(); } function g() view public {} }", - TypeError, - "Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires \"view\"" - ); -} - -BOOST_AUTO_TEST_CASE(write_storage_fail) -{ - CHECK_WARNING( - "contract C{ uint x; function f() view public { x = 2; } }", - "Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable." - ); -} - BOOST_AUTO_TEST_CASE(environment_access) { vector<string> view{ "block.coinbase", "block.timestamp", - "block.blockhash(7)", "block.difficulty", "block.number", "block.gaslimit", "blockhash(7)", "gasleft()", - "msg.gas", "msg.value", "msg.sender", "tx.origin", @@ -122,7 +55,7 @@ BOOST_AUTO_TEST_CASE(environment_access) "this", "address(1).balance" }; - // ``block.blockhash`` and ``blockhash`` are tested seperately below because their usage will + // ``block.blockhash`` and ``blockhash`` are tested separately below because their usage will // produce warnings that can't be handled in a generic way. vector<string> pure{ "msg.data", @@ -155,281 +88,11 @@ BOOST_AUTO_TEST_CASE(environment_access) "Statement has no effect." })); - CHECK_WARNING_ALLOW_MULTI( - "contract C { function f() view public { block.blockhash; } }", - (std::vector<std::string>{ - "Function state mutability can be restricted to pure", - "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\"" - })); -} - -BOOST_AUTO_TEST_CASE(view_error_for_050) -{ CHECK_ERROR( - "pragma experimental \"v0.5.0\"; contract C { uint x; function f() view public { x = 2; } }", + "contract C { function f() view public { block.blockhash; } }", TypeError, - "Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable." + "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\"" ); - -} - -BOOST_AUTO_TEST_CASE(modifiers) -{ - string text = R"( - contract D { - uint x; - modifier purem(uint) { _; } - modifier viewm(uint) { uint a = x; _; a; } - modifier nonpayablem(uint) { x = 2; _; } - } - contract C is D { - function f() purem(0) pure public {} - function g() viewm(0) view public {} - function h() nonpayablem(0) public {} - function i() purem(x) view public {} - function j() viewm(x) view public {} - function k() nonpayablem(x) public {} - function l() purem(x = 2) public {} - function m() viewm(x = 2) public {} - function n() nonpayablem(x = 2) public {} - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(interface) -{ - string text = R"( - interface D { - function f() view external; - } - contract C is D { - function f() view external {} - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(overriding) -{ - string text = R"( - contract D { - uint x; - function f() public { x = 2; } - } - contract C is D { - function f() public {} - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(returning_structs) -{ - string text = R"( - contract C { - struct S { uint x; } - S s; - function f() view internal returns (S storage) { - return s; - } - function g() public { - f().x = 2; - } - function h() view public { - f(); - f().x; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(mappings) -{ - string text = R"( - contract C { - mapping(uint => uint) a; - function f() view public { - a; - } - function g() view public { - a[2]; - } - function h() public { - a[2] = 3; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(local_storage_variables) -{ - string text = R"( - contract C { - struct S { uint a; } - S s; - function f() view public { - S storage x = s; - x; - } - function g() view public { - S storage x = s; - x = s; - } - function i() public { - s.a = 2; - } - function h() public { - S storage x = s; - x.a = 2; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(builtin_functions) -{ - string text = R"( - contract C { - function f() public { - address(this).transfer(1); - require(address(this).send(2)); - selfdestruct(address(this)); - require(address(this).delegatecall()); - require(address(this).call()); - } - function g() pure public { - bytes32 x = keccak256("abc"); - bytes32 y = sha256("abc"); - address z = ecrecover(1, 2, 3, 4); - require(true); - assert(true); - x; y; z; - } - function() payable public {} - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(function_types) -{ - string text = R"( - contract C { - function f() pure public { - function () external nonpayFun; - function () external view viewFun; - function () external pure pureFun; - - nonpayFun; - viewFun; - pureFun; - pureFun(); - } - function g() view public { - function () external view viewFun; - - viewFun(); - } - function h() public { - function () external nonpayFun; - - nonpayFun(); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(selector) -{ - string text = R"( - contract C { - uint public x; - function f() payable public { - } - function g() pure public returns (bytes4) { - return this.f.selector ^ this.x.selector; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(selector_complex) -{ - string text = R"( - contract C { - function f(C c) pure public returns (C) { - return c; - } - function g() pure public returns (bytes4) { - // By passing `this`, we read from the state, even if f itself is pure. - return f(this).f.selector; - } - } - )"; - CHECK_ERROR(text, TypeError, "reads from the environment or state and thus requires \"view\""); -} - -BOOST_AUTO_TEST_CASE(selector_complex2) -{ - string text = R"( - contract C { - function f() payable public returns (C) { - return this; - } - function g() pure public returns (bytes4) { - C x = C(0x123); - return x.f.selector; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(creation) -{ - string text = R"( - contract D {} - contract C { - function f() public { new D(); } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - -BOOST_AUTO_TEST_CASE(assembly) -{ - string text = R"( - contract C { - struct S { uint x; } - S s; - function e() pure public { - assembly { mstore(keccak256(0, 20), mul(s_slot, 2)) } - } - function f() pure public { - uint x; - assembly { x := 7 } - } - function g() view public { - assembly { for {} 1 { pop(sload(0)) } { } pop(gas) } - } - function h() view public { - assembly { function g() { pop(blockhash(20)) } } - } - function j() public { - assembly { pop(call(0, 1, 2, 3, 4, 5, 6)) } - } - function k() public { - assembly { pop(call(gas, 1, 2, 3, 4, 5, 6)) } - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); } BOOST_AUTO_TEST_CASE(assembly_staticcall) @@ -447,31 +110,6 @@ BOOST_AUTO_TEST_CASE(assembly_staticcall) CHECK_SUCCESS_NO_WARNINGS(text); } -BOOST_AUTO_TEST_CASE(assembly_jump) -{ - string text = R"( - contract C { - function k() public { - assembly { jump(2) } - } - } - )"; - CHECK_WARNING(text, "low-level EVM features"); -} - -BOOST_AUTO_TEST_CASE(constant) -{ - string text = R"( - contract C { - uint constant x = 2; - function k() pure public returns (uint) { - return x; - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); -} - BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/syntaxTests/array/array_pop.sol b/test/libsolidity/syntaxTests/array/array_pop.sol new file mode 100644 index 00000000..3804f911 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/array_pop.sol @@ -0,0 +1,7 @@ +contract C { + uint[] data; + function test() public { + data.pop(); + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/array/array_pop_arg.sol b/test/libsolidity/syntaxTests/array/array_pop_arg.sol new file mode 100644 index 00000000..bb7803e2 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/array_pop_arg.sol @@ -0,0 +1,8 @@ +contract C { + uint[] data; + function test() public { + data.pop(5); + } +} +// ---- +// TypeError: (65-76): Wrong argument count for function call: 1 arguments given but expected 0. diff --git a/test/libsolidity/syntaxTests/array/bytes_pop.sol b/test/libsolidity/syntaxTests/array/bytes_pop.sol new file mode 100644 index 00000000..cd5aa0eb --- /dev/null +++ b/test/libsolidity/syntaxTests/array/bytes_pop.sol @@ -0,0 +1,7 @@ +contract C { + bytes data; + function test() public { + data.pop(); + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/array/dynamic_memory_array_pop.sol b/test/libsolidity/syntaxTests/array/dynamic_memory_array_pop.sol new file mode 100644 index 00000000..5a79afc9 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/dynamic_memory_array_pop.sol @@ -0,0 +1,8 @@ +contract C { + function test() public { + uint[] memory data; + data.pop(); + } +} +// ---- +// TypeError: (74-82): Member "pop" is not available in uint256[] memory outside of storage. diff --git a/test/libsolidity/syntaxTests/array/length/array_length_cannot_be_constant_function_parameter.sol b/test/libsolidity/syntaxTests/array/length/array_length_cannot_be_constant_function_parameter.sol new file mode 100644 index 00000000..5add9106 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/array_length_cannot_be_constant_function_parameter.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint constant LEN) public { + uint[LEN] a; + } +} +// ---- +// TypeError: (69-72): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol b/test/libsolidity/syntaxTests/array/length/can_be_constant_in_function.sol index 92536dd5..92536dd5 100644 --- a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol +++ b/test/libsolidity/syntaxTests/array/length/can_be_constant_in_function.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol b/test/libsolidity/syntaxTests/array/length/can_be_constant_in_struct.sol index 89e174f2..89e174f2 100644 --- a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol +++ b/test/libsolidity/syntaxTests/array/length/can_be_constant_in_struct.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol b/test/libsolidity/syntaxTests/array/length/can_be_recursive_constant.sol index 6810a9d6..6810a9d6 100644 --- a/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol +++ b/test/libsolidity/syntaxTests/array/length/can_be_recursive_constant.sol diff --git a/test/libsolidity/syntaxTests/array/length/cannot_be_function.sol b/test/libsolidity/syntaxTests/array/length/cannot_be_function.sol new file mode 100644 index 00000000..2ad97d27 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/cannot_be_function.sol @@ -0,0 +1,6 @@ +contract C { + function f() public {} + uint[f] ids; +} +// ---- +// TypeError: (49-50): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol b/test/libsolidity/syntaxTests/array/length/cannot_be_function_call.sol index a6863955..bb8cc599 100644 --- a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol +++ b/test/libsolidity/syntaxTests/array/length/cannot_be_function_call.sol @@ -1,7 +1,7 @@ contract C { - function f(uint x) {} + function f(uint x) public {} uint constant LEN = f(); uint[LEN] ids; } // ---- -// TypeError: (77-80): Invalid array length, expected integer literal or constant expression. +// TypeError: (84-87): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol b/test/libsolidity/syntaxTests/array/length/complex_cyclic_constant.sol index 254f9f02..ee107078 100644 --- a/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol +++ b/test/libsolidity/syntaxTests/array/length/complex_cyclic_constant.sol @@ -2,7 +2,7 @@ contract C { uint constant L2 = LEN - 10; uint constant L1 = L2 / 10; uint constant LEN = 10 + L1 * 5; - function f() { + function f() public { uint[LEN] a; } } diff --git a/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol b/test/libsolidity/syntaxTests/array/length/const_cannot_be_fractional.sol index 397bbbcd..397bbbcd 100644 --- a/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol +++ b/test/libsolidity/syntaxTests/array/length/const_cannot_be_fractional.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/constant_var.sol b/test/libsolidity/syntaxTests/array/length/constant_var.sol index 41750250..41750250 100644 --- a/test/libsolidity/syntaxTests/arrayLength/constant_var.sol +++ b/test/libsolidity/syntaxTests/array/length/constant_var.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol b/test/libsolidity/syntaxTests/array/length/cyclic_constant.sol index 91ba9045..3adc0e9b 100644 --- a/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol +++ b/test/libsolidity/syntaxTests/array/length/cyclic_constant.sol @@ -1,6 +1,6 @@ contract C { uint constant LEN = LEN; - function f() { + function f() public { uint[LEN] a; } } diff --git a/test/libsolidity/syntaxTests/arrayLength/inline_array.sol b/test/libsolidity/syntaxTests/array/length/inline_array.sol index a30745d3..a30745d3 100644 --- a/test/libsolidity/syntaxTests/arrayLength/inline_array.sol +++ b/test/libsolidity/syntaxTests/array/length/inline_array.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol b/test/libsolidity/syntaxTests/array/length/invalid_expression_1.sol index c92861eb..c92861eb 100644 --- a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol +++ b/test/libsolidity/syntaxTests/array/length/invalid_expression_1.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol b/test/libsolidity/syntaxTests/array/length/invalid_expression_2.sol index 92e3c3cf..92e3c3cf 100644 --- a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol +++ b/test/libsolidity/syntaxTests/array/length/invalid_expression_2.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol b/test/libsolidity/syntaxTests/array/length/invalid_expression_3.sol index 26add45c..26add45c 100644 --- a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol +++ b/test/libsolidity/syntaxTests/array/length/invalid_expression_3.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol b/test/libsolidity/syntaxTests/array/length/invalid_expression_4.sol index a0d58f4a..a0d58f4a 100644 --- a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol +++ b/test/libsolidity/syntaxTests/array/length/invalid_expression_4.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol b/test/libsolidity/syntaxTests/array/length/invalid_expression_5.sol index 38a80867..38a80867 100644 --- a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol +++ b/test/libsolidity/syntaxTests/array/length/invalid_expression_5.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol b/test/libsolidity/syntaxTests/array/length/non_integer_constant_var.sol index 7a853a34..7a853a34 100644 --- a/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol +++ b/test/libsolidity/syntaxTests/array/length/non_integer_constant_var.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol b/test/libsolidity/syntaxTests/array/length/not_convertible_to_integer.sol index b44ccfe9..b44ccfe9 100644 --- a/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol +++ b/test/libsolidity/syntaxTests/array/length/not_convertible_to_integer.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/parentheses.sol b/test/libsolidity/syntaxTests/array/length/parentheses.sol index 40f55ad6..40f55ad6 100644 --- a/test/libsolidity/syntaxTests/arrayLength/parentheses.sol +++ b/test/libsolidity/syntaxTests/array/length/parentheses.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol b/test/libsolidity/syntaxTests/array/length/pure_functions.sol index b620db76..b620db76 100644 --- a/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol +++ b/test/libsolidity/syntaxTests/array/length/pure_functions.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/too_large.sol b/test/libsolidity/syntaxTests/array/length/too_large.sol index c90a7494..c90a7494 100644 --- a/test/libsolidity/syntaxTests/arrayLength/too_large.sol +++ b/test/libsolidity/syntaxTests/array/length/too_large.sol diff --git a/test/libsolidity/syntaxTests/arrayLength/tuples.sol b/test/libsolidity/syntaxTests/array/length/tuples.sol index bc10b3b5..bc10b3b5 100644 --- a/test/libsolidity/syntaxTests/arrayLength/tuples.sol +++ b/test/libsolidity/syntaxTests/array/length/tuples.sol diff --git a/test/libsolidity/syntaxTests/array/no_array_pop.sol b/test/libsolidity/syntaxTests/array/no_array_pop.sol new file mode 100644 index 00000000..44e54ad2 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/no_array_pop.sol @@ -0,0 +1,8 @@ +contract C { + uint data; + function test() public { + data.pop(); + } +} +// ---- +// TypeError: (63-71): Member "pop" not found or not visible after argument-dependent lookup in uint256 diff --git a/test/libsolidity/syntaxTests/array/static_storage_array_pop.sol b/test/libsolidity/syntaxTests/array/static_storage_array_pop.sol new file mode 100644 index 00000000..0af171ad --- /dev/null +++ b/test/libsolidity/syntaxTests/array/static_storage_array_pop.sol @@ -0,0 +1,8 @@ +contract C { + uint[3] data; + function test() public { + data.pop(); + } +} +// ---- +// TypeError: (66-74): Member "pop" not found or not visible after argument-dependent lookup in uint256[3] storage ref diff --git a/test/libsolidity/syntaxTests/array/string_pop.sol b/test/libsolidity/syntaxTests/array/string_pop.sol new file mode 100644 index 00000000..2a46d0c3 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/string_pop.sol @@ -0,0 +1,8 @@ +contract C { + string data; + function test() public { + data.pop(); + } +} +// ---- +// TypeError: (65-73): Member "pop" not found or not visible after argument-dependent lookup in string storage ref diff --git a/test/libsolidity/syntaxTests/array/uninitialized_storage_var.sol b/test/libsolidity/syntaxTests/array/uninitialized_storage_var.sol new file mode 100644 index 00000000..363d8147 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/uninitialized_storage_var.sol @@ -0,0 +1,9 @@ +contract C { + function f() { + uint[] storage x; + uint[10] storage y; + } +} +// ---- +// DeclarationError: (31-47): Uninitialized storage pointer. +// DeclarationError: (51-69): Uninitialized storage pointer. diff --git a/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol b/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol deleted file mode 100644 index 11d40f26..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol +++ /dev/null @@ -1,7 +0,0 @@ -contract C { - function f(uint constant LEN) { - uint[LEN] a; - } -} -// ---- -// TypeError: (62-65): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol deleted file mode 100644 index ac3abc4c..00000000 --- a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol +++ /dev/null @@ -1,6 +0,0 @@ -contract C { - function f() {} - uint[f] ids; -} -// ---- -// TypeError: (42-43): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol b/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol index 88e94e29..0e242b30 100644 --- a/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol +++ b/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol @@ -3,4 +3,4 @@ contract C { uint constant y = x(); } // ---- -// Warning: (74-77): Initial value for constant variable has to be compile-time constant. This will fail to compile with the next breaking version change. +// TypeError: (74-77): Initial value for constant variable has to be compile-time constant. diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol index 08d20c3a..9f1d9722 100644 --- a/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol +++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol @@ -1,12 +1,10 @@ contract C { uint constant a = b * c; uint constant b = 7; - uint constant c = b + uint(keccak256(d)); + uint constant c = b + uint(keccak256(abi.encodePacked(d))); uint constant d = 2 + a; } // ---- -// Warning: (98-110): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (98-110): The provided argument of type uint256 is not implicitly convertible to expected type bytes memory. // TypeError: (17-40): The value of the constant a has a cyclic dependency via c. -// TypeError: (71-111): The value of the constant c has a cyclic dependency via d. -// TypeError: (117-140): The value of the constant d has a cyclic dependency via a. +// TypeError: (71-129): The value of the constant c has a cyclic dependency via d. +// TypeError: (135-158): The value of the constant d has a cyclic dependency via a. diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol index df5cd969..cc34fad2 100644 --- a/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol +++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol @@ -1,9 +1,7 @@ contract C { uint constant a = b * c; uint constant b = 7; - uint constant c = 4 + uint(keccak256(d)); + uint constant c = 4 + uint(keccak256(abi.encode(d))); uint constant d = 2 + b; } // ---- -// Warning: (98-110): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (98-110): The provided argument of type uint256 is not implicitly convertible to expected type bytes memory. diff --git a/test/libsolidity/syntaxTests/constructor/constructor_no_visibility.sol b/test/libsolidity/syntaxTests/constructor/constructor_no_visibility.sol new file mode 100644 index 00000000..88553084 --- /dev/null +++ b/test/libsolidity/syntaxTests/constructor/constructor_no_visibility.sol @@ -0,0 +1,3 @@ +contract A { constructor() {} } +// ---- +// Warning: (13-29): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/constructor/constructor_no_visibility_050.sol b/test/libsolidity/syntaxTests/constructor/constructor_no_visibility_050.sol new file mode 100644 index 00000000..0f57a41f --- /dev/null +++ b/test/libsolidity/syntaxTests/constructor/constructor_no_visibility_050.sol @@ -0,0 +1,4 @@ +pragma experimental "v0.5.0"; +contract A { constructor() {} } +// ---- +// SyntaxError: (43-59): No visibility specified. diff --git a/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_new.sol b/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_new.sol index 15ed0e1e..39bf6384 100644 --- a/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_new.sol +++ b/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_new.sol @@ -1,13 +1,9 @@ contract test1 { - constructor() constant {} + constructor() public view {} } contract test2 { - constructor() view {} -} -contract test3 { - constructor() pure {} + constructor() public pure {} } // ---- -// TypeError: (19-44): Constructor must be payable or non-payable, but is "view". -// TypeError: (66-87): Constructor must be payable or non-payable, but is "view". -// TypeError: (109-130): Constructor must be payable or non-payable, but is "pure". +// TypeError: (19-47): Constructor must be payable or non-payable, but is "view". +// TypeError: (69-97): Constructor must be payable or non-payable, but is "pure". diff --git a/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_old.sol b/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_old.sol index 6dbcbc97..b9f2a4bb 100644 --- a/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_old.sol +++ b/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_old.sol @@ -1,16 +1,11 @@ contract test1 { - function test1() constant {} + function test1() public view {} } contract test2 { - function test2() view {} -} -contract test3 { - function test3() pure {} + function test2() public pure {} } // ---- -// Warning: (21-49): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. -// Warning: (73-97): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. -// Warning: (121-145): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. -// TypeError: (21-49): Constructor must be payable or non-payable, but is "view". -// TypeError: (73-97): Constructor must be payable or non-payable, but is "view". -// TypeError: (121-145): Constructor must be payable or non-payable, but is "pure". +// Warning: (21-52): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. +// Warning: (76-107): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. +// TypeError: (21-52): Constructor must be payable or non-payable, but is "view". +// TypeError: (76-107): Constructor must be payable or non-payable, but is "pure". diff --git a/test/libsolidity/syntaxTests/constructor/constructor_visibility_new.sol b/test/libsolidity/syntaxTests/constructor/constructor_visibility_new.sol index 502dc029..f9c4b9b9 100644 --- a/test/libsolidity/syntaxTests/constructor/constructor_visibility_new.sol +++ b/test/libsolidity/syntaxTests/constructor/constructor_visibility_new.sol @@ -1,5 +1,5 @@ // The constructor of a base class should not be visible in the derived class -contract A { constructor(string) public { } } +contract A { constructor(string memory) public { } } contract B is A { function f() pure public { A x = A(0); // convert from address @@ -9,4 +9,4 @@ contract B is A { } } // ---- -// TypeError: (243-247): Explicit type conversion not allowed from "string memory" to "contract A". +// TypeError: (250-254): Explicit type conversion not allowed from "string memory" to "contract A". diff --git a/test/libsolidity/syntaxTests/constructor/constructor_visibility_old.sol b/test/libsolidity/syntaxTests/constructor/constructor_visibility_old.sol index 847ea27b..65f989b0 100644 --- a/test/libsolidity/syntaxTests/constructor/constructor_visibility_old.sol +++ b/test/libsolidity/syntaxTests/constructor/constructor_visibility_old.sol @@ -1,5 +1,5 @@ // The constructor of a base class should not be visible in the derived class -contract A { function A(string s) public { } } +contract A { function A(string memory s) public { } } contract B is A { function f() pure public { A x = A(0); // convert from address @@ -9,5 +9,5 @@ contract B is A { } } // ---- -// Warning: (91-122): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. -// TypeError: (244-248): Explicit type conversion not allowed from "string memory" to "contract A". +// Warning: (91-129): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. +// TypeError: (251-255): Explicit type conversion not allowed from "string memory" to "contract A". diff --git a/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_new.sol b/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_new.sol index 5e619143..6bbb83ce 100644 --- a/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_new.sol +++ b/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_new.sol @@ -1,5 +1,5 @@ contract C { - constructor(); + constructor() public; } // ---- -// TypeError: (14-28): Constructor must be implemented if declared. +// TypeError: (14-35): Constructor must be implemented if declared. diff --git a/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_old.sol b/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_old.sol index 72458703..12bf6315 100644 --- a/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_old.sol +++ b/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_old.sol @@ -1,6 +1,6 @@ contract C { - function C(); + function C() public; } // ---- -// Warning: (14-27): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. -// TypeError: (14-27): Constructor must be implemented if declared. +// Warning: (14-34): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. +// TypeError: (14-34): Constructor must be implemented if declared. diff --git a/test/libsolidity/syntaxTests/constructor/interface_constructor_new.sol b/test/libsolidity/syntaxTests/constructor/interface_constructor_new.sol index fa5d54c4..2cab1851 100644 --- a/test/libsolidity/syntaxTests/constructor/interface_constructor_new.sol +++ b/test/libsolidity/syntaxTests/constructor/interface_constructor_new.sol @@ -1,7 +1,7 @@ interface I { - constructor(); + constructor() public; } // ---- -// Warning: (15-29): Functions in interfaces should be declared external. -// TypeError: (15-29): Constructor cannot be defined in interfaces. -// TypeError: (15-29): Constructor must be implemented if declared. +// Warning: (15-36): Functions in interfaces should be declared external. +// TypeError: (15-36): Constructor cannot be defined in interfaces. +// TypeError: (15-36): Constructor must be implemented if declared. diff --git a/test/libsolidity/syntaxTests/constructor/interface_constructor_old.sol b/test/libsolidity/syntaxTests/constructor/interface_constructor_old.sol index ddf54977..313d4345 100644 --- a/test/libsolidity/syntaxTests/constructor/interface_constructor_old.sol +++ b/test/libsolidity/syntaxTests/constructor/interface_constructor_old.sol @@ -1,8 +1,8 @@ interface I { - function I(); + function I() public; } // ---- -// Warning: (15-28): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. -// Warning: (15-28): Functions in interfaces should be declared external. -// TypeError: (15-28): Constructor cannot be defined in interfaces. -// TypeError: (15-28): Constructor must be implemented if declared. +// Warning: (15-35): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. +// Warning: (15-35): Functions in interfaces should be declared external. +// TypeError: (15-35): Constructor cannot be defined in interfaces. +// TypeError: (15-35): Constructor must be implemented if declared. diff --git a/test/libsolidity/syntaxTests/constructor/library_constructor_new.sol b/test/libsolidity/syntaxTests/constructor/library_constructor_new.sol index 8db7e62a..38934f8d 100644 --- a/test/libsolidity/syntaxTests/constructor/library_constructor_new.sol +++ b/test/libsolidity/syntaxTests/constructor/library_constructor_new.sol @@ -1,6 +1,6 @@ library Lib { - constructor(); + constructor() public; } // ---- -// TypeError: (15-29): Constructor cannot be defined in libraries. -// TypeError: (15-29): Constructor must be implemented if declared. +// TypeError: (15-36): Constructor cannot be defined in libraries. +// TypeError: (15-36): Constructor must be implemented if declared. diff --git a/test/libsolidity/syntaxTests/constructor/library_constructor_old.sol b/test/libsolidity/syntaxTests/constructor/library_constructor_old.sol index d4499049..271cc790 100644 --- a/test/libsolidity/syntaxTests/constructor/library_constructor_old.sol +++ b/test/libsolidity/syntaxTests/constructor/library_constructor_old.sol @@ -1,7 +1,7 @@ library Lib { - function Lib(); + function Lib() public; } // ---- -// Warning: (15-30): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. -// TypeError: (15-30): Constructor cannot be defined in libraries. -// TypeError: (15-30): Constructor must be implemented if declared. +// Warning: (15-37): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. +// TypeError: (15-37): Constructor cannot be defined in libraries. +// TypeError: (15-37): Constructor must be implemented if declared. diff --git a/test/libsolidity/syntaxTests/constructor/overriding_constructor.sol b/test/libsolidity/syntaxTests/constructor/overriding_constructor.sol index 3290a33b..5fb3a189 100644 --- a/test/libsolidity/syntaxTests/constructor/overriding_constructor.sol +++ b/test/libsolidity/syntaxTests/constructor/overriding_constructor.sol @@ -1,6 +1,10 @@ -// It is fine to "override" constructor of a base class since it is invisible -contract A { function A() public { } } +contract A { constructor() public {} } contract B is A { function A() public pure returns (uint8) {} } +contract C is A { function A() public pure returns (uint8) {} } +contract D is B { function B() public pure returns (uint8) {} } +contract E is D { function B() public pure returns (uint8) {} } // ---- -// Warning: (91-114): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. -// Warning: (135-178): This declaration shadows an existing declaration. +// Warning: (57-100): This declaration shadows an existing declaration. +// Warning: (121-164): This declaration shadows an existing declaration. +// Warning: (185-228): This declaration shadows an existing declaration. +// Warning: (249-292): This declaration shadows an existing declaration. diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol index 9a42192d..ec83c596 100644 --- a/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol +++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol @@ -1,18 +1,18 @@ contract C { struct S { bool f; } S s; - function f() internal view returns (S c) { + function f() internal view returns (S memory c) { c = s; } - function g() internal view returns (S) { + function g() internal view returns (S memory) { return s; } - function h() internal pure returns (S) { + function h() internal pure returns (S memory) { } - function i(bool flag) internal view returns (S c) { + function i(bool flag) internal view returns (S memory c) { if (flag) c = s; } - function j(bool flag) internal view returns (S) { + function j(bool flag) internal view returns (S memory) { if (flag) return s; } } diff --git a/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_calldata.sol b/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_calldata.sol new file mode 100644 index 00000000..781c645a --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_calldata.sol @@ -0,0 +1,4 @@ +contract test { + function f(bytes calldata) external; +} +// ---- diff --git a/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_memory.sol b/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_memory.sol new file mode 100644 index 00000000..807cc064 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_memory.sol @@ -0,0 +1,5 @@ +contract test { + function f(bytes memory) external; +} +// ---- +// TypeError: (31-36): Location has to be calldata for external functions (remove the "memory" or "storage" keyword). diff --git a/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_storage.sol b/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_storage.sol new file mode 100644 index 00000000..2664dbab --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/externalFunction/function_argument_location_specifier_test_external_storage.sol @@ -0,0 +1,5 @@ +contract test { + function f(bytes storage) external; +} +// ---- +// TypeError: (31-36): Location has to be calldata for external functions (remove the "memory" or "storage" keyword). diff --git a/test/libsolidity/syntaxTests/dataLocations/function_argument_location_specifier_test_library.sol b/test/libsolidity/syntaxTests/dataLocations/function_argument_location_specifier_test_library.sol new file mode 100644 index 00000000..4348482a --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/function_argument_location_specifier_test_library.sol @@ -0,0 +1,5 @@ +library test { + function f(bytes calldata) public; +} +// ---- +// TypeError: (30-35): Location cannot be calldata for non-external functions (remove the "calldata" keyword). diff --git a/test/libsolidity/syntaxTests/dataLocations/function_argument_location_specifier_test_non_reference_type.sol b/test/libsolidity/syntaxTests/dataLocations/function_argument_location_specifier_test_non_reference_type.sol new file mode 100644 index 00000000..70f6c5eb --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/function_argument_location_specifier_test_non_reference_type.sol @@ -0,0 +1,5 @@ +contract test { + function f(bytes4 memory) public; +} +// ---- +// TypeError: (31-37): Data location can only be given for array or struct types. diff --git a/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_calldata.sol b/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_calldata.sol new file mode 100644 index 00000000..f2740946 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_calldata.sol @@ -0,0 +1,5 @@ +contract test { + function f(bytes calldata) internal; +} +// ---- +// TypeError: (31-36): Variable cannot be declared as "calldata" (remove the "calldata" keyword). diff --git a/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_memory.sol b/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_memory.sol new file mode 100644 index 00000000..1e5971c4 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_memory.sol @@ -0,0 +1,4 @@ +contract test { + function f(bytes memory) internal; +} +// ---- diff --git a/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_storage.sol b/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_storage.sol new file mode 100644 index 00000000..56f0fe99 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/internalFunction/function_argument_location_specifier_test_internal_storage.sol @@ -0,0 +1,4 @@ +contract test { + function f(bytes storage) internal; +} +// ---- diff --git a/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_calldata.sol b/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_calldata.sol new file mode 100644 index 00000000..cb00199f --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_calldata.sol @@ -0,0 +1,5 @@ +contract test { + function f(bytes calldata) public; +} +// ---- +// TypeError: (31-36): Location has to be memory for publicly visible functions (remove the "storage" or "calldata" keyword). diff --git a/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_memory.sol b/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_memory.sol new file mode 100644 index 00000000..4eebf016 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_memory.sol @@ -0,0 +1,4 @@ +contract test { + function f(bytes memory) public; +} +// ---- diff --git a/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_storage.sol b/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_storage.sol new file mode 100644 index 00000000..9380d9df --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/publicFunction/function_argument_location_specifier_test_public_storage.sol @@ -0,0 +1,5 @@ +contract test { + function f(bytes storage) public; +} +// ---- +// TypeError: (31-36): Location has to be memory for publicly visible functions (remove the "storage" or "calldata" keyword). diff --git a/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_non_reference_type.sol b/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_non_reference_type.sol new file mode 100644 index 00000000..ac312685 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_non_reference_type.sol @@ -0,0 +1,13 @@ +contract test { + function f() public { + uint storage a1; + bytes16 storage b1; + uint memory a2; + bytes16 memory b2; + } +} +// ---- +// TypeError: (48-63): Data location can only be given for array or struct types. +// TypeError: (71-89): Data location can only be given for array or struct types. +// TypeError: (97-111): Data location can only be given for array or struct types. +// TypeError: (119-136): Data location can only be given for array or struct types. diff --git a/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_reference_type.sol b/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_reference_type.sol new file mode 100644 index 00000000..0fbad155 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_reference_type.sol @@ -0,0 +1,13 @@ +contract test { + uint[] a; + uint[] b; + function f() public { + uint[] storage s1 = a; + uint[] memory s2 = new uint[](42); + uint[] storage s3 = b; + s1.push(42); + s2[3] = 12; + s3.push(42); + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol b/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol index 3571e8a9..f115ac60 100644 --- a/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol +++ b/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol @@ -2,4 +2,4 @@ contract C { uint constant x = 0x01 wei; } // ---- -// Warning: (32-40): Hexadecimal numbers with unit denominations are deprecated. You can use an expression of the form "0x1234 * 1 day" instead. +// TypeError: (32-40): Hexadecimal numbers cannot be used with unit denominations. You can use an expression of the form "0x1234 * 1 day" instead. diff --git a/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination_050.sol b/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination_050.sol deleted file mode 100644 index 98865999..00000000 --- a/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination_050.sol +++ /dev/null @@ -1,6 +0,0 @@ -pragma experimental "v0.5.0"; -contract C { - uint constant x = 0x01 wei; -} -// ---- -// TypeError: (62-70): Hexadecimal numbers cannot be used with unit denominations. You can use an expression of the form "0x1234 * 1 day" instead. diff --git a/test/libsolidity/syntaxTests/denominations/denominations.sol b/test/libsolidity/syntaxTests/denominations/denominations.sol index 6d1aa2f3..43049a14 100644 --- a/test/libsolidity/syntaxTests/denominations/denominations.sol +++ b/test/libsolidity/syntaxTests/denominations/denominations.sol @@ -1,7 +1,6 @@ contract C { uint constant a = 1 wei + 2 szabo + 3 finney + 4 ether; - uint constant b = 1 seconds + 2 minutes + 3 hours + 4 days + 5 weeks + 6 years; + uint constant b = 1 seconds + 2 minutes + 3 hours + 4 days + 5 weeks; uint constant c = 2 szabo / 1 seconds + 3 finney * 3 hours; } // ---- -// Warning: (142-149): Using "years" as a unit denomination is deprecated. diff --git a/test/libsolidity/syntaxTests/denominations/deprecated_year.sol b/test/libsolidity/syntaxTests/denominations/deprecated_year.sol index 30e86535..691c0cb0 100644 --- a/test/libsolidity/syntaxTests/denominations/deprecated_year.sol +++ b/test/libsolidity/syntaxTests/denominations/deprecated_year.sol @@ -2,4 +2,4 @@ contract C { uint constant a = 3 years; } // ---- -// Warning: (32-39): Using "years" as a unit denomination is deprecated. +// TypeError: (32-39): Using "years" as a unit denomination is deprecated. diff --git a/test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol b/test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol deleted file mode 100644 index 4baaeaa3..00000000 --- a/test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol +++ /dev/null @@ -1,6 +0,0 @@ -pragma experimental "v0.5.0"; -contract C { - uint constant a = 3 years; -} -// ---- -// TypeError: (62-69): Using "years" as a unit denomination is deprecated. diff --git a/test/libsolidity/syntaxTests/deprecated_functions.sol b/test/libsolidity/syntaxTests/deprecated_functions.sol index 9df2b43c..62dfcff9 100644 --- a/test/libsolidity/syntaxTests/deprecated_functions.sol +++ b/test/libsolidity/syntaxTests/deprecated_functions.sol @@ -1,12 +1,12 @@ contract test { function f() pure public { - bytes32 x = sha3(); + bytes32 x = sha3(""); x; } function g() public { - suicide(1); + suicide(0x0000000000000000000000000000000000000001); } } // ---- -// Warning: (58-64): "sha3" has been deprecated in favour of "keccak256" -// Warning: (99-109): "suicide" has been deprecated in favour of "selfdestruct" +// TypeError: (58-66): "sha3" has been deprecated in favour of "keccak256" +// TypeError: (101-152): "suicide" has been deprecated in favour of "selfdestruct" diff --git a/test/libsolidity/syntaxTests/deprecated_functions_050.sol b/test/libsolidity/syntaxTests/deprecated_functions_050.sol deleted file mode 100644 index b28e5abb..00000000 --- a/test/libsolidity/syntaxTests/deprecated_functions_050.sol +++ /dev/null @@ -1,15 +0,0 @@ -pragma experimental "v0.5.0"; -contract test { - function f() pure public { - bytes32 x = sha3(uint8(1)); - x; - } - function g() public { - suicide(1); - } -} -// ---- -// TypeError: (88-102): "sha3" has been deprecated in favour of "keccak256" -// TypeError: (88-102): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// TypeError: (88-102): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory. -// TypeError: (137-147): "suicide" has been deprecated in favour of "selfdestruct" diff --git a/test/libsolidity/syntaxTests/double_variable_declaration.sol b/test/libsolidity/syntaxTests/double_variable_declaration.sol index 9ab87959..53c5c9be 100644 --- a/test/libsolidity/syntaxTests/double_variable_declaration.sol +++ b/test/libsolidity/syntaxTests/double_variable_declaration.sol @@ -1,8 +1,9 @@ contract test { function f() pure public { uint256 x; - if (true) { uint256 x; } + x = 1; + if (true) { uint256 x; x = 2; } } } // ---- -// DeclarationError: (71-80): Identifier already declared. +// Warning: (80-89): This declaration shadows an existing declaration. diff --git a/test/libsolidity/syntaxTests/double_variable_declaration_050.sol b/test/libsolidity/syntaxTests/double_variable_declaration_050.sol deleted file mode 100644 index 2f47e6dc..00000000 --- a/test/libsolidity/syntaxTests/double_variable_declaration_050.sol +++ /dev/null @@ -1,11 +0,0 @@ -pragma experimental "v0.5.0"; -contract test { - function f() pure public { - uint256 x; - if (true) { uint256 x; } - } -} -// ---- -// Warning: (101-110): This declaration shadows an existing declaration. -// Warning: (76-85): Unused local variable. -// Warning: (101-110): Unused local variable. diff --git a/test/libsolidity/syntaxTests/emit_non_event.sol b/test/libsolidity/syntaxTests/emit_non_event.sol index 1df6990d..d5045ddf 100644 --- a/test/libsolidity/syntaxTests/emit_non_event.sol +++ b/test/libsolidity/syntaxTests/emit_non_event.sol @@ -1,10 +1,10 @@ contract C { uint256 Test; - function f() { + function f() public { emit Test(); } } // ---- -// TypeError: (56-62): Type is not callable -// TypeError: (56-60): Expression has to be an event invocation. +// TypeError: (63-69): Type is not callable +// TypeError: (63-67): Expression has to be an event invocation. diff --git a/test/libsolidity/syntaxTests/empty_string_var.sol b/test/libsolidity/syntaxTests/empty_string_var.sol deleted file mode 100644 index e9837590..00000000 --- a/test/libsolidity/syntaxTests/empty_string_var.sol +++ /dev/null @@ -1,11 +0,0 @@ -contract C { - function f() { - var a = ""; - bytes1 b = bytes1(a); - bytes memory c = bytes(a); - string memory d = string(a); - } -} -// ---- -// Warning: (34-39): Use of the "var" keyword is deprecated. -// TypeError: (61-70): Explicit type conversion not allowed from "string memory" to "bytes1". diff --git a/test/libsolidity/syntaxTests/empty_struct.sol b/test/libsolidity/syntaxTests/empty_struct.sol index 12655309..0a52fb72 100644 --- a/test/libsolidity/syntaxTests/empty_struct.sol +++ b/test/libsolidity/syntaxTests/empty_struct.sol @@ -2,4 +2,4 @@ contract test { struct A {} } // ---- -// Warning: (17-28): Defining empty structs is deprecated. +// SyntaxError: (17-28): Defining empty structs is disallowed. diff --git a/test/libsolidity/syntaxTests/empty_struct_050.sol b/test/libsolidity/syntaxTests/empty_struct_050.sol deleted file mode 100644 index 886f1f83..00000000 --- a/test/libsolidity/syntaxTests/empty_struct_050.sol +++ /dev/null @@ -1,6 +0,0 @@ -pragma experimental "v0.5.0"; -contract test { - struct A {} -} -// ---- -// SyntaxError: (47-58): Defining empty structs is disallowed. diff --git a/test/libsolidity/syntaxTests/fallback/default_visibility.sol b/test/libsolidity/syntaxTests/fallback/default_visibility.sol new file mode 100644 index 00000000..31123d59 --- /dev/null +++ b/test/libsolidity/syntaxTests/fallback/default_visibility.sol @@ -0,0 +1,6 @@ +contract C { + // Check that visibility is also enforced for the fallback function. + function() {} +} +// ---- +// TypeError: (90-103): Fallback function must be defined as "external". diff --git a/test/libsolidity/syntaxTests/fallback/pure_modifier.sol b/test/libsolidity/syntaxTests/fallback/pure_modifier.sol index 20d5b0ac..12d790d1 100644 --- a/test/libsolidity/syntaxTests/fallback/pure_modifier.sol +++ b/test/libsolidity/syntaxTests/fallback/pure_modifier.sol @@ -1,6 +1,6 @@ contract C { uint x; - function() pure { x = 2; } + function() external pure { x = 2; } } // ---- -// TypeError: (29-55): Fallback function must be payable or non-payable, but is "pure". +// TypeError: (29-64): Fallback function must be payable or non-payable, but is "pure". diff --git a/test/libsolidity/syntaxTests/fallback/view_modifier.sol b/test/libsolidity/syntaxTests/fallback/view_modifier.sol index 44c5d204..2497e9fa 100644 --- a/test/libsolidity/syntaxTests/fallback/view_modifier.sol +++ b/test/libsolidity/syntaxTests/fallback/view_modifier.sol @@ -1,6 +1,6 @@ contract C { uint x; - function() view { x = 2; } + function() external view { x = 2; } } // ---- -// TypeError: (29-55): Fallback function must be payable or non-payable, but is "view". +// TypeError: (29-64): Fallback function must be payable or non-payable, but is "view". diff --git a/test/libsolidity/syntaxTests/functionCalls/named_arguments_for_functions_that_take_arbitrary_parameters.sol b/test/libsolidity/syntaxTests/functionCalls/named_arguments_for_functions_that_take_arbitrary_parameters.sol new file mode 100644 index 00000000..089e1dbf --- /dev/null +++ b/test/libsolidity/syntaxTests/functionCalls/named_arguments_for_functions_that_take_arbitrary_parameters.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public { + abi.encodeWithSelector({selector:"abc"}); + } +} +// ---- +// TypeError: (52-92): Named arguments cannot be used for functions that take arbitrary parameters. diff --git a/test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol index a6fe6c22..2481c455 100644 --- a/test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol +++ b/test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol @@ -3,15 +3,13 @@ contract C { function(uint) internal returns (uint) y; function f() public { delete x; - var a = y; + function(uint) internal returns (uint) a = y; delete a; delete y; - var c = f; + function() internal c = f; delete c; function(uint) internal returns (uint) g; delete g; } } // ---- -// Warning: (157-162): Use of the "var" keyword is deprecated. -// Warning: (212-217): Use of the "var" keyword is deprecated. diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol index 95ebc179..6549eb48 100644 --- a/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol +++ b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol @@ -1,7 +1,7 @@ contract C { // Fool parser into parsing a constructor as a function type. - constructor() x; + constructor() public x; } // ---- -// Warning: (83-99): Modifiers of functions without implementation are ignored. -// DeclarationError: (97-98): Undeclared identifier. +// Warning: (83-106): Modifiers of functions without implementation are ignored. +// DeclarationError: (104-105): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_return_parameters_with_names.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_return_parameters_with_names.sol new file mode 100644 index 00000000..12191530 --- /dev/null +++ b/test/libsolidity/syntaxTests/functionTypes/function_type_return_parameters_with_names.sol @@ -0,0 +1,5 @@ +contract C { + function(uint) returns (bool ret) f; +} +// ---- +// SyntaxError: (41-49): Return parameters in function types may not be named. diff --git a/test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol b/test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol index 10c6767c..e7d2c9a9 100644 --- a/test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol +++ b/test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol @@ -1,5 +1,5 @@ contract test { - function fa(uint) {} + function fa(uint) public {} function fb(uint) internal {} function fc(uint) internal {} function fd(uint) external {} @@ -13,11 +13,14 @@ contract test { function(uint) internal internal c = fc; function(uint) external d = this.fd; function(uint) external internal e = this.fe; - function(uint) internal public f = ff; - function(uint) internal pure public g = fg; - function(uint) pure internal public h = fh; + function(uint) internal f = ff; + function(uint) internal pure g = fg; + function(uint) pure internal h = fh; } // ---- -// TypeError: (545-582): Internal or recursive type is not allowed for public state variables. -// TypeError: (588-630): Internal or recursive type is not allowed for public state variables. -// TypeError: (636-678): Internal or recursive type is not allowed for public state variables. +// Warning: (20-47): Function state mutability can be restricted to pure +// Warning: (52-81): Function state mutability can be restricted to pure +// Warning: (86-115): Function state mutability can be restricted to pure +// Warning: (120-149): Function state mutability can be restricted to pure +// Warning: (154-183): Function state mutability can be restricted to pure +// Warning: (188-217): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol b/test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol deleted file mode 100644 index 67a74e54..00000000 --- a/test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol +++ /dev/null @@ -1,5 +0,0 @@ -contract C { - function(uint) returns (bool ret) f; -} -// ---- -// Warning: (41-49): Naming function type return parameters is deprecated. diff --git a/test/libsolidity/syntaxTests/globalFunctions/call_with_wrong_arg_count.sol b/test/libsolidity/syntaxTests/globalFunctions/call_with_wrong_arg_count.sol new file mode 100644 index 00000000..e8134539 --- /dev/null +++ b/test/libsolidity/syntaxTests/globalFunctions/call_with_wrong_arg_count.sol @@ -0,0 +1,13 @@ +contract C { + function f() public { + require(address(this).call()); + require(address(this).call(bytes4(0x12345678))); + require(address(this).call(uint(1))); + require(address(this).call(uint(1), uint(2))); + } +} +// ---- +// TypeError: (55-75): Wrong argument count for function call: 0 arguments given but expected 1. This function requires a single bytes argument. Use "" as argument to provide empty calldata. +// TypeError: (113-131): Invalid type for argument in function call. Invalid implicit conversion from bytes4 to bytes memory requested. This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it. +// TypeError: (170-177): Invalid type for argument in function call. Invalid implicit conversion from uint256 to bytes memory requested. This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it. +// TypeError: (197-233): Wrong argument count for function call: 2 arguments given but expected 1. This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it. diff --git a/test/libsolidity/syntaxTests/globalFunctions/callcode_with_wrong_arg_count.sol b/test/libsolidity/syntaxTests/globalFunctions/callcode_with_wrong_arg_count.sol new file mode 100644 index 00000000..2b424d53 --- /dev/null +++ b/test/libsolidity/syntaxTests/globalFunctions/callcode_with_wrong_arg_count.sol @@ -0,0 +1,11 @@ +contract C { + function f() public { + require(address(this).callcode()); + require(address(this).callcode(uint(1))); + require(address(this).callcode(uint(1), uint(2))); + } +} +// ---- +// TypeError: (55-79): Wrong argument count for function call: 0 arguments given but expected 1. This function requires a single bytes argument. Use "" as argument to provide empty calldata. +// TypeError: (121-128): Invalid type for argument in function call. Invalid implicit conversion from uint256 to bytes memory requested. This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it. +// TypeError: (148-188): Wrong argument count for function call: 2 arguments given but expected 1. This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it. diff --git a/test/libsolidity/syntaxTests/globalFunctions/delegatecall_with_wrong_arg_count.sol b/test/libsolidity/syntaxTests/globalFunctions/delegatecall_with_wrong_arg_count.sol new file mode 100644 index 00000000..be0347de --- /dev/null +++ b/test/libsolidity/syntaxTests/globalFunctions/delegatecall_with_wrong_arg_count.sol @@ -0,0 +1,11 @@ +contract C { + function f() public { + require(address(this).delegatecall()); + require(address(this).delegatecall(uint(1))); + require(address(this).delegatecall(uint(1), uint(2))); + } +} +// ---- +// TypeError: (55-83): Wrong argument count for function call: 0 arguments given but expected 1. This function requires a single bytes argument. Use "" as argument to provide empty calldata. +// TypeError: (129-136): Invalid type for argument in function call. Invalid implicit conversion from uint256 to bytes memory requested. This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it. +// TypeError: (156-200): Wrong argument count for function call: 2 arguments given but expected 1. This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it. diff --git a/test/libsolidity/syntaxTests/globalFunctions/keccak256_with_wrong_arg_count.sol b/test/libsolidity/syntaxTests/globalFunctions/keccak256_with_wrong_arg_count.sol new file mode 100644 index 00000000..4857bc2e --- /dev/null +++ b/test/libsolidity/syntaxTests/globalFunctions/keccak256_with_wrong_arg_count.sol @@ -0,0 +1,11 @@ +contract C { + function f() public { + require(keccak256() != 0); + require(keccak256(uint(1)) != 0); + require(keccak256(uint(1), uint(2)) != 0); + } +} +// ---- +// TypeError: (55-66): Wrong argument count for function call: 0 arguments given but expected 1. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. +// TypeError: (100-107): Invalid type for argument in function call. Invalid implicit conversion from uint256 to bytes memory requested. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. +// TypeError: (132-159): Wrong argument count for function call: 2 arguments given but expected 1. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. diff --git a/test/libsolidity/syntaxTests/globalFunctions/ripemd160_with_wrong_arg_count.sol b/test/libsolidity/syntaxTests/globalFunctions/ripemd160_with_wrong_arg_count.sol new file mode 100644 index 00000000..da41fccd --- /dev/null +++ b/test/libsolidity/syntaxTests/globalFunctions/ripemd160_with_wrong_arg_count.sol @@ -0,0 +1,11 @@ +contract C { + function f() public { + require(ripemd160() != 0); + require(ripemd160(uint(1)) != 0); + require(ripemd160(uint(1), uint(2)) != 0); + } +} +// ---- +// TypeError: (55-66): Wrong argument count for function call: 0 arguments given but expected 1. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. +// TypeError: (100-107): Invalid type for argument in function call. Invalid implicit conversion from uint256 to bytes memory requested. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. +// TypeError: (132-159): Wrong argument count for function call: 2 arguments given but expected 1. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. diff --git a/test/libsolidity/syntaxTests/globalFunctions/sha256_with_wrong_arg_count.sol b/test/libsolidity/syntaxTests/globalFunctions/sha256_with_wrong_arg_count.sol new file mode 100644 index 00000000..2939e7fc --- /dev/null +++ b/test/libsolidity/syntaxTests/globalFunctions/sha256_with_wrong_arg_count.sol @@ -0,0 +1,11 @@ +contract C { + function f() public { + require(sha256() != 0); + require(sha256(uint(1)) != 0); + require(sha256(uint(1), uint(2)) != 0); + } +} +// ---- +// TypeError: (55-63): Wrong argument count for function call: 0 arguments given but expected 1. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. +// TypeError: (94-101): Invalid type for argument in function call. Invalid implicit conversion from uint256 to bytes memory requested. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. +// TypeError: (126-150): Wrong argument count for function call: 2 arguments given but expected 1. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol index 0b18b995..692b1827 100644 --- a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol +++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol @@ -4,4 +4,4 @@ contract Base { contract Derived is Base(2) { } contract Derived2 is Base(), Derived() { } // ---- -// Warning: (101-107): Wrong argument count for constructor call: 0 arguments given but expected 1. +// TypeError: (101-107): Wrong argument count for constructor call: 0 arguments given but expected 1. Remove parentheses if you do not want to provide arguments here. diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol deleted file mode 100644 index db04ab8c..00000000 --- a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol +++ /dev/null @@ -1,9 +0,0 @@ -pragma experimental "v0.5.0"; - -contract Base { - constructor(uint) public {} -} -contract Derived is Base(2) { } -contract Derived2 is Base(), Derived() { } -// ---- -// TypeError: (132-138): Wrong argument count for constructor call: 0 arguments given but expected 1. diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol index 015b33e5..96be62f2 100644 --- a/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol +++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol @@ -6,4 +6,4 @@ contract Derived is Base, Base1 { constructor(uint i) Base(i) public {} } // ---- -// Warning: (138-145): Base constructor arguments given twice. +// DeclarationError: (138-145): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol index 24cff54d..76cc937b 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol @@ -2,4 +2,4 @@ contract A { constructor(uint) public { } } contract B is A(2) { constructor() public { } } contract C is B { constructor() A(3) public { } } // ---- -// Warning: (125-129): Base constructor arguments given twice. +// DeclarationError: (125-129): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol index 9ceaea5e..4c7a684f 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol @@ -1,4 +1,4 @@ contract A { constructor(uint) public { } } contract B is A(2) { constructor() A(3) public { } } // ---- -// Warning: (79-83): Base constructor arguments given twice. +// DeclarationError: (79-83): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol index e5c2aa36..2e77e077 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol @@ -3,5 +3,5 @@ contract A is C(2) {} contract B is C(2) {} contract D is A, B { constructor() C(3) public {} } // ---- -// Warning: (122-126): Base constructor arguments given twice. -// Warning: (122-126): Base constructor arguments given twice. +// DeclarationError: (122-126): Base constructor arguments given twice. +// DeclarationError: (122-126): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol index 1abf2992..0beb1552 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol @@ -3,4 +3,4 @@ contract A is C(2) {} contract B is C(2) {} contract D is A, B {} // ---- -// Warning: (87-108): Base constructor arguments given twice. +// DeclarationError: (87-108): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol index e15242db..7142840e 100644 --- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol +++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol @@ -3,4 +3,4 @@ contract A is C { constructor() C(2) public {} } contract B is C { constructor() C(2) public {} } contract D is A, B { } // ---- -// Warning: (141-163): Base constructor arguments given twice. +// DeclarationError: (141-163): Base constructor arguments given twice. diff --git a/test/libsolidity/syntaxTests/inheritance/override/add_view.sol b/test/libsolidity/syntaxTests/inheritance/override/add_view.sol index 9973b23e..21e43792 100644 --- a/test/libsolidity/syntaxTests/inheritance/override/add_view.sol +++ b/test/libsolidity/syntaxTests/inheritance/override/add_view.sol @@ -1,4 +1,4 @@ contract B { function f() public {} } -contract C is B { function f() view {} } +contract C is B { function f() public view {} } // ---- -// TypeError: (56-76): Overriding function changes state mutability from "nonpayable" to "view". +// TypeError: (56-83): Overriding function changes state mutability from "nonpayable" to "view". diff --git a/test/libsolidity/syntaxTests/inheritance/override/remove_view.sol b/test/libsolidity/syntaxTests/inheritance/override/remove_view.sol index e58f6b20..cc785858 100644 --- a/test/libsolidity/syntaxTests/inheritance/override/remove_view.sol +++ b/test/libsolidity/syntaxTests/inheritance/override/remove_view.sol @@ -1,4 +1,4 @@ -contract B { function f() view {} } +contract B { function f() public view {} } contract C is B { function f() public {} } // ---- -// TypeError: (54-76): Overriding function changes state mutability from "view" to "nonpayable". +// TypeError: (61-83): Overriding function changes state mutability from "view" to "nonpayable". diff --git a/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol b/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol index c55c41f2..1ce48200 100644 --- a/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol +++ b/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol @@ -6,5 +6,5 @@ contract Derived2 is Base { constructor() Base(2) public { } } // ---- -// TypeError: (74-81): Wrong argument count for constructor call: 1 arguments given but expected 2. +// TypeError: (74-81): Wrong argument count for constructor call: 1 arguments given but expected 2. Remove parentheses if you do not want to provide arguments here. // TypeError: (130-137): Wrong argument count for modifier invocation: 1 arguments given but expected 2. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/storage_reference.sol b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference.sol new file mode 100644 index 00000000..b6dd12b8 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference.sol @@ -0,0 +1,11 @@ +contract C { + uint[] x; + function() external { + uint[] storage y = x; + assembly { + pop(y) + } + } +} +// ---- +// TypeError: (119-120): You have to use the _slot or _offset suffix to access storage reference variables. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_fine.sol b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_fine.sol new file mode 100644 index 00000000..84f98ed9 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_fine.sol @@ -0,0 +1,11 @@ +contract C { + uint[] x; + function() external { + uint[] storage y = x; + assembly { + pop(y_slot) + pop(y_offset) + } + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/memberLookup/failed_function_lookup.sol b/test/libsolidity/syntaxTests/memberLookup/failed_function_lookup.sol index c23992e9..119df5d3 100644 --- a/test/libsolidity/syntaxTests/memberLookup/failed_function_lookup.sol +++ b/test/libsolidity/syntaxTests/memberLookup/failed_function_lookup.sol @@ -1,7 +1,7 @@ contract C { - function f(uint, uint) {} - function f(uint) {} - function g() { f(1, 2, 3); } + function f(uint, uint) public {} + function f(uint) public {} + function g() public { f(1, 2, 3); } } // ---- -// TypeError: (80-81): No matching declaration found after argument-dependent lookup. +// TypeError: (101-102): No matching declaration found after argument-dependent lookup. diff --git a/test/libsolidity/syntaxTests/memberLookup/failed_function_lookup_in_library.sol b/test/libsolidity/syntaxTests/memberLookup/failed_function_lookup_in_library.sol index 310c4a10..df0cba3f 100644 --- a/test/libsolidity/syntaxTests/memberLookup/failed_function_lookup_in_library.sol +++ b/test/libsolidity/syntaxTests/memberLookup/failed_function_lookup_in_library.sol @@ -1,9 +1,9 @@ library L { - function f(uint, uint) {} - function f(uint) {} + function f(uint, uint) public {} + function f(uint) public {} } contract C { - function g() { L.f(1, 2, 3); } + function g() public { L.f(1, 2, 3); } } // ---- -// TypeError: (94-97): Member "f" not found or not visible after argument-dependent lookup in type(library L) +// TypeError: (115-118): Member "f" not found or not visible after argument-dependent lookup in type(library L) diff --git a/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol b/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol index bdbab5d8..49d0d7bf 100644 --- a/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol +++ b/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol @@ -3,5 +3,5 @@ contract B is C { constructor() C(2) C(2) public {} } // ---- -// Warning: (81-85): Base constructor arguments given twice. +// DeclarationError: (81-85): Base constructor arguments given twice. // DeclarationError: (86-90): Base constructor already provided. diff --git a/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables.sol b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables.sol index 00031924..76bb6fc0 100644 --- a/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables.sol +++ b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables.sol @@ -2,3 +2,5 @@ contract B { function f() mod(x) pure public { uint x = 7; } modifier mod(uint a) { if (a > 0) _; } } +// ---- +// DeclarationError: (34-35): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables050.sol b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables050.sol deleted file mode 100644 index c19ccf2c..00000000 --- a/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables050.sol +++ /dev/null @@ -1,7 +0,0 @@ -pragma experimental "v0.5.0"; -contract B { - function f() mod(x) pure public { uint x = 7; } - modifier mod(uint a) { if (a > 0) _; } -} -// ---- -// DeclarationError: (64-65): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/more_than_256_declarationerrors.sol b/test/libsolidity/syntaxTests/more_than_256_declarationerrors.sol index 2d75f29b..307b728d 100644 --- a/test/libsolidity/syntaxTests/more_than_256_declarationerrors.sol +++ b/test/libsolidity/syntaxTests/more_than_256_declarationerrors.sol @@ -1,5 +1,5 @@ contract C { - function f() { + function f() public { b = 5; b = 5; b = 5; @@ -265,260 +265,260 @@ contract C { } } // ---- -// DeclarationError: (34-35): Undeclared identifier. -// DeclarationError: (45-46): Undeclared identifier. -// DeclarationError: (56-57): Undeclared identifier. -// DeclarationError: (67-68): Undeclared identifier. -// DeclarationError: (78-79): Undeclared identifier. -// DeclarationError: (89-90): Undeclared identifier. -// DeclarationError: (100-101): Undeclared identifier. -// DeclarationError: (111-112): Undeclared identifier. -// DeclarationError: (122-123): Undeclared identifier. -// DeclarationError: (133-134): Undeclared identifier. -// DeclarationError: (144-145): Undeclared identifier. -// DeclarationError: (155-156): Undeclared identifier. -// DeclarationError: (166-167): Undeclared identifier. -// DeclarationError: (177-178): Undeclared identifier. -// DeclarationError: (188-189): Undeclared identifier. -// DeclarationError: (199-200): Undeclared identifier. -// DeclarationError: (210-211): Undeclared identifier. -// DeclarationError: (221-222): Undeclared identifier. -// DeclarationError: (232-233): Undeclared identifier. -// DeclarationError: (243-244): Undeclared identifier. -// DeclarationError: (254-255): Undeclared identifier. -// DeclarationError: (265-266): Undeclared identifier. -// DeclarationError: (276-277): Undeclared identifier. -// DeclarationError: (287-288): Undeclared identifier. -// DeclarationError: (298-299): Undeclared identifier. -// DeclarationError: (309-310): Undeclared identifier. -// DeclarationError: (320-321): Undeclared identifier. -// DeclarationError: (331-332): Undeclared identifier. -// DeclarationError: (342-343): Undeclared identifier. -// DeclarationError: (353-354): Undeclared identifier. -// DeclarationError: (364-365): Undeclared identifier. -// DeclarationError: (375-376): Undeclared identifier. -// DeclarationError: (386-387): Undeclared identifier. -// DeclarationError: (397-398): Undeclared identifier. -// DeclarationError: (408-409): Undeclared identifier. -// DeclarationError: (419-420): Undeclared identifier. -// DeclarationError: (430-431): Undeclared identifier. -// DeclarationError: (441-442): Undeclared identifier. -// DeclarationError: (452-453): Undeclared identifier. -// DeclarationError: (463-464): Undeclared identifier. -// DeclarationError: (474-475): Undeclared identifier. -// DeclarationError: (485-486): Undeclared identifier. -// DeclarationError: (496-497): Undeclared identifier. -// DeclarationError: (507-508): Undeclared identifier. -// DeclarationError: (518-519): Undeclared identifier. -// DeclarationError: (529-530): Undeclared identifier. -// DeclarationError: (540-541): Undeclared identifier. -// DeclarationError: (551-552): Undeclared identifier. -// DeclarationError: (562-563): Undeclared identifier. -// DeclarationError: (573-574): Undeclared identifier. -// DeclarationError: (584-585): Undeclared identifier. -// DeclarationError: (595-596): Undeclared identifier. -// DeclarationError: (606-607): Undeclared identifier. -// DeclarationError: (617-618): Undeclared identifier. -// DeclarationError: (628-629): Undeclared identifier. -// DeclarationError: (639-640): Undeclared identifier. -// DeclarationError: (650-651): Undeclared identifier. -// DeclarationError: (661-662): Undeclared identifier. -// DeclarationError: (672-673): Undeclared identifier. -// DeclarationError: (683-684): Undeclared identifier. -// DeclarationError: (694-695): Undeclared identifier. -// DeclarationError: (705-706): Undeclared identifier. -// DeclarationError: (716-717): Undeclared identifier. -// DeclarationError: (727-728): Undeclared identifier. -// DeclarationError: (738-739): Undeclared identifier. -// DeclarationError: (749-750): Undeclared identifier. -// DeclarationError: (760-761): Undeclared identifier. -// DeclarationError: (771-772): Undeclared identifier. -// DeclarationError: (782-783): Undeclared identifier. -// DeclarationError: (793-794): Undeclared identifier. -// DeclarationError: (804-805): Undeclared identifier. -// DeclarationError: (815-816): Undeclared identifier. -// DeclarationError: (826-827): Undeclared identifier. -// DeclarationError: (837-838): Undeclared identifier. -// DeclarationError: (848-849): Undeclared identifier. -// DeclarationError: (859-860): Undeclared identifier. -// DeclarationError: (870-871): Undeclared identifier. -// DeclarationError: (881-882): Undeclared identifier. -// DeclarationError: (892-893): Undeclared identifier. -// DeclarationError: (903-904): Undeclared identifier. -// DeclarationError: (914-915): Undeclared identifier. -// DeclarationError: (925-926): Undeclared identifier. -// DeclarationError: (936-937): Undeclared identifier. -// DeclarationError: (947-948): Undeclared identifier. -// DeclarationError: (958-959): Undeclared identifier. -// DeclarationError: (969-970): Undeclared identifier. -// DeclarationError: (980-981): Undeclared identifier. -// DeclarationError: (991-992): Undeclared identifier. -// DeclarationError: (1002-1003): Undeclared identifier. -// DeclarationError: (1013-1014): Undeclared identifier. -// DeclarationError: (1024-1025): Undeclared identifier. -// DeclarationError: (1035-1036): Undeclared identifier. -// DeclarationError: (1046-1047): Undeclared identifier. -// DeclarationError: (1057-1058): Undeclared identifier. -// DeclarationError: (1068-1069): Undeclared identifier. -// DeclarationError: (1079-1080): Undeclared identifier. -// DeclarationError: (1090-1091): Undeclared identifier. -// DeclarationError: (1101-1102): Undeclared identifier. -// DeclarationError: (1112-1113): Undeclared identifier. -// DeclarationError: (1123-1124): Undeclared identifier. -// DeclarationError: (1134-1135): Undeclared identifier. -// DeclarationError: (1145-1146): Undeclared identifier. -// DeclarationError: (1156-1157): Undeclared identifier. -// DeclarationError: (1167-1168): Undeclared identifier. -// DeclarationError: (1178-1179): Undeclared identifier. -// DeclarationError: (1189-1190): Undeclared identifier. -// DeclarationError: (1200-1201): Undeclared identifier. -// DeclarationError: (1211-1212): Undeclared identifier. -// DeclarationError: (1222-1223): Undeclared identifier. -// DeclarationError: (1233-1234): Undeclared identifier. -// DeclarationError: (1244-1245): Undeclared identifier. -// DeclarationError: (1255-1256): Undeclared identifier. -// DeclarationError: (1266-1267): Undeclared identifier. -// DeclarationError: (1277-1278): Undeclared identifier. -// DeclarationError: (1288-1289): Undeclared identifier. -// DeclarationError: (1299-1300): Undeclared identifier. -// DeclarationError: (1310-1311): Undeclared identifier. -// DeclarationError: (1321-1322): Undeclared identifier. -// DeclarationError: (1332-1333): Undeclared identifier. -// DeclarationError: (1343-1344): Undeclared identifier. -// DeclarationError: (1354-1355): Undeclared identifier. -// DeclarationError: (1365-1366): Undeclared identifier. -// DeclarationError: (1376-1377): Undeclared identifier. -// DeclarationError: (1387-1388): Undeclared identifier. -// DeclarationError: (1398-1399): Undeclared identifier. -// DeclarationError: (1409-1410): Undeclared identifier. -// DeclarationError: (1420-1421): Undeclared identifier. -// DeclarationError: (1431-1432): Undeclared identifier. -// DeclarationError: (1442-1443): Undeclared identifier. -// DeclarationError: (1453-1454): Undeclared identifier. -// DeclarationError: (1464-1465): Undeclared identifier. -// DeclarationError: (1475-1476): Undeclared identifier. -// DeclarationError: (1486-1487): Undeclared identifier. -// DeclarationError: (1497-1498): Undeclared identifier. -// DeclarationError: (1508-1509): Undeclared identifier. -// DeclarationError: (1519-1520): Undeclared identifier. -// DeclarationError: (1530-1531): Undeclared identifier. -// DeclarationError: (1541-1542): Undeclared identifier. -// DeclarationError: (1552-1553): Undeclared identifier. -// DeclarationError: (1563-1564): Undeclared identifier. -// DeclarationError: (1574-1575): Undeclared identifier. -// DeclarationError: (1585-1586): Undeclared identifier. -// DeclarationError: (1596-1597): Undeclared identifier. -// DeclarationError: (1607-1608): Undeclared identifier. -// DeclarationError: (1618-1619): Undeclared identifier. -// DeclarationError: (1629-1630): Undeclared identifier. -// DeclarationError: (1640-1641): Undeclared identifier. -// DeclarationError: (1651-1652): Undeclared identifier. -// DeclarationError: (1662-1663): Undeclared identifier. -// DeclarationError: (1673-1674): Undeclared identifier. -// DeclarationError: (1684-1685): Undeclared identifier. -// DeclarationError: (1695-1696): Undeclared identifier. -// DeclarationError: (1706-1707): Undeclared identifier. -// DeclarationError: (1717-1718): Undeclared identifier. -// DeclarationError: (1728-1729): Undeclared identifier. -// DeclarationError: (1739-1740): Undeclared identifier. -// DeclarationError: (1750-1751): Undeclared identifier. -// DeclarationError: (1761-1762): Undeclared identifier. -// DeclarationError: (1772-1773): Undeclared identifier. -// DeclarationError: (1783-1784): Undeclared identifier. -// DeclarationError: (1794-1795): Undeclared identifier. -// DeclarationError: (1805-1806): Undeclared identifier. -// DeclarationError: (1816-1817): Undeclared identifier. -// DeclarationError: (1827-1828): Undeclared identifier. -// DeclarationError: (1838-1839): Undeclared identifier. -// DeclarationError: (1849-1850): Undeclared identifier. -// DeclarationError: (1860-1861): Undeclared identifier. -// DeclarationError: (1871-1872): Undeclared identifier. -// DeclarationError: (1882-1883): Undeclared identifier. -// DeclarationError: (1893-1894): Undeclared identifier. -// DeclarationError: (1904-1905): Undeclared identifier. -// DeclarationError: (1915-1916): Undeclared identifier. -// DeclarationError: (1926-1927): Undeclared identifier. -// DeclarationError: (1937-1938): Undeclared identifier. -// DeclarationError: (1948-1949): Undeclared identifier. -// DeclarationError: (1959-1960): Undeclared identifier. -// DeclarationError: (1970-1971): Undeclared identifier. -// DeclarationError: (1981-1982): Undeclared identifier. -// DeclarationError: (1992-1993): Undeclared identifier. -// DeclarationError: (2003-2004): Undeclared identifier. -// DeclarationError: (2014-2015): Undeclared identifier. -// DeclarationError: (2025-2026): Undeclared identifier. -// DeclarationError: (2036-2037): Undeclared identifier. -// DeclarationError: (2047-2048): Undeclared identifier. -// DeclarationError: (2058-2059): Undeclared identifier. -// DeclarationError: (2069-2070): Undeclared identifier. -// DeclarationError: (2080-2081): Undeclared identifier. -// DeclarationError: (2091-2092): Undeclared identifier. -// DeclarationError: (2102-2103): Undeclared identifier. -// DeclarationError: (2113-2114): Undeclared identifier. -// DeclarationError: (2124-2125): Undeclared identifier. -// DeclarationError: (2135-2136): Undeclared identifier. -// DeclarationError: (2146-2147): Undeclared identifier. -// DeclarationError: (2157-2158): Undeclared identifier. -// DeclarationError: (2168-2169): Undeclared identifier. -// DeclarationError: (2179-2180): Undeclared identifier. -// DeclarationError: (2190-2191): Undeclared identifier. -// DeclarationError: (2201-2202): Undeclared identifier. -// DeclarationError: (2212-2213): Undeclared identifier. -// DeclarationError: (2223-2224): Undeclared identifier. -// DeclarationError: (2234-2235): Undeclared identifier. -// DeclarationError: (2245-2246): Undeclared identifier. -// DeclarationError: (2256-2257): Undeclared identifier. -// DeclarationError: (2267-2268): Undeclared identifier. -// DeclarationError: (2278-2279): Undeclared identifier. -// DeclarationError: (2289-2290): Undeclared identifier. -// DeclarationError: (2300-2301): Undeclared identifier. -// DeclarationError: (2311-2312): Undeclared identifier. -// DeclarationError: (2322-2323): Undeclared identifier. -// DeclarationError: (2333-2334): Undeclared identifier. -// DeclarationError: (2344-2345): Undeclared identifier. -// DeclarationError: (2355-2356): Undeclared identifier. -// DeclarationError: (2366-2367): Undeclared identifier. -// DeclarationError: (2377-2378): Undeclared identifier. -// DeclarationError: (2388-2389): Undeclared identifier. -// DeclarationError: (2399-2400): Undeclared identifier. -// DeclarationError: (2410-2411): Undeclared identifier. -// DeclarationError: (2421-2422): Undeclared identifier. -// DeclarationError: (2432-2433): Undeclared identifier. -// DeclarationError: (2443-2444): Undeclared identifier. -// DeclarationError: (2454-2455): Undeclared identifier. -// DeclarationError: (2465-2466): Undeclared identifier. -// DeclarationError: (2476-2477): Undeclared identifier. -// DeclarationError: (2487-2488): Undeclared identifier. -// DeclarationError: (2498-2499): Undeclared identifier. -// DeclarationError: (2509-2510): Undeclared identifier. -// DeclarationError: (2520-2521): Undeclared identifier. -// DeclarationError: (2531-2532): Undeclared identifier. -// DeclarationError: (2542-2543): Undeclared identifier. -// DeclarationError: (2553-2554): Undeclared identifier. -// DeclarationError: (2564-2565): Undeclared identifier. -// DeclarationError: (2575-2576): Undeclared identifier. -// DeclarationError: (2586-2587): Undeclared identifier. -// DeclarationError: (2597-2598): Undeclared identifier. -// DeclarationError: (2608-2609): Undeclared identifier. -// DeclarationError: (2619-2620): Undeclared identifier. -// DeclarationError: (2630-2631): Undeclared identifier. -// DeclarationError: (2641-2642): Undeclared identifier. -// DeclarationError: (2652-2653): Undeclared identifier. -// DeclarationError: (2663-2664): Undeclared identifier. -// DeclarationError: (2674-2675): Undeclared identifier. -// DeclarationError: (2685-2686): Undeclared identifier. -// DeclarationError: (2696-2697): Undeclared identifier. -// DeclarationError: (2707-2708): Undeclared identifier. -// DeclarationError: (2718-2719): Undeclared identifier. -// DeclarationError: (2729-2730): Undeclared identifier. -// DeclarationError: (2740-2741): Undeclared identifier. -// DeclarationError: (2751-2752): Undeclared identifier. -// DeclarationError: (2762-2763): Undeclared identifier. -// DeclarationError: (2773-2774): Undeclared identifier. -// DeclarationError: (2784-2785): Undeclared identifier. -// DeclarationError: (2795-2796): Undeclared identifier. -// DeclarationError: (2806-2807): Undeclared identifier. -// DeclarationError: (2817-2818): Undeclared identifier. -// DeclarationError: (2828-2829): Undeclared identifier. -// DeclarationError: (2839-2840): Undeclared identifier. +// DeclarationError: (41-42): Undeclared identifier. +// DeclarationError: (52-53): Undeclared identifier. +// DeclarationError: (63-64): Undeclared identifier. +// DeclarationError: (74-75): Undeclared identifier. +// DeclarationError: (85-86): Undeclared identifier. +// DeclarationError: (96-97): Undeclared identifier. +// DeclarationError: (107-108): Undeclared identifier. +// DeclarationError: (118-119): Undeclared identifier. +// DeclarationError: (129-130): Undeclared identifier. +// DeclarationError: (140-141): Undeclared identifier. +// DeclarationError: (151-152): Undeclared identifier. +// DeclarationError: (162-163): Undeclared identifier. +// DeclarationError: (173-174): Undeclared identifier. +// DeclarationError: (184-185): Undeclared identifier. +// DeclarationError: (195-196): Undeclared identifier. +// DeclarationError: (206-207): Undeclared identifier. +// DeclarationError: (217-218): Undeclared identifier. +// DeclarationError: (228-229): Undeclared identifier. +// DeclarationError: (239-240): Undeclared identifier. +// DeclarationError: (250-251): Undeclared identifier. +// DeclarationError: (261-262): Undeclared identifier. +// DeclarationError: (272-273): Undeclared identifier. +// DeclarationError: (283-284): Undeclared identifier. +// DeclarationError: (294-295): Undeclared identifier. +// DeclarationError: (305-306): Undeclared identifier. +// DeclarationError: (316-317): Undeclared identifier. +// DeclarationError: (327-328): Undeclared identifier. +// DeclarationError: (338-339): Undeclared identifier. +// DeclarationError: (349-350): Undeclared identifier. +// DeclarationError: (360-361): Undeclared identifier. +// DeclarationError: (371-372): Undeclared identifier. +// DeclarationError: (382-383): Undeclared identifier. +// DeclarationError: (393-394): Undeclared identifier. +// DeclarationError: (404-405): Undeclared identifier. +// DeclarationError: (415-416): Undeclared identifier. +// DeclarationError: (426-427): Undeclared identifier. +// DeclarationError: (437-438): Undeclared identifier. +// DeclarationError: (448-449): Undeclared identifier. +// DeclarationError: (459-460): Undeclared identifier. +// DeclarationError: (470-471): Undeclared identifier. +// DeclarationError: (481-482): Undeclared identifier. +// DeclarationError: (492-493): Undeclared identifier. +// DeclarationError: (503-504): Undeclared identifier. +// DeclarationError: (514-515): Undeclared identifier. +// DeclarationError: (525-526): Undeclared identifier. +// DeclarationError: (536-537): Undeclared identifier. +// DeclarationError: (547-548): Undeclared identifier. +// DeclarationError: (558-559): Undeclared identifier. +// DeclarationError: (569-570): Undeclared identifier. +// DeclarationError: (580-581): Undeclared identifier. +// DeclarationError: (591-592): Undeclared identifier. +// DeclarationError: (602-603): Undeclared identifier. +// DeclarationError: (613-614): Undeclared identifier. +// DeclarationError: (624-625): Undeclared identifier. +// DeclarationError: (635-636): Undeclared identifier. +// DeclarationError: (646-647): Undeclared identifier. +// DeclarationError: (657-658): Undeclared identifier. +// DeclarationError: (668-669): Undeclared identifier. +// DeclarationError: (679-680): Undeclared identifier. +// DeclarationError: (690-691): Undeclared identifier. +// DeclarationError: (701-702): Undeclared identifier. +// DeclarationError: (712-713): Undeclared identifier. +// DeclarationError: (723-724): Undeclared identifier. +// DeclarationError: (734-735): Undeclared identifier. +// DeclarationError: (745-746): Undeclared identifier. +// DeclarationError: (756-757): Undeclared identifier. +// DeclarationError: (767-768): Undeclared identifier. +// DeclarationError: (778-779): Undeclared identifier. +// DeclarationError: (789-790): Undeclared identifier. +// DeclarationError: (800-801): Undeclared identifier. +// DeclarationError: (811-812): Undeclared identifier. +// DeclarationError: (822-823): Undeclared identifier. +// DeclarationError: (833-834): Undeclared identifier. +// DeclarationError: (844-845): Undeclared identifier. +// DeclarationError: (855-856): Undeclared identifier. +// DeclarationError: (866-867): Undeclared identifier. +// DeclarationError: (877-878): Undeclared identifier. +// DeclarationError: (888-889): Undeclared identifier. +// DeclarationError: (899-900): Undeclared identifier. +// DeclarationError: (910-911): Undeclared identifier. +// DeclarationError: (921-922): Undeclared identifier. +// DeclarationError: (932-933): Undeclared identifier. +// DeclarationError: (943-944): Undeclared identifier. +// DeclarationError: (954-955): Undeclared identifier. +// DeclarationError: (965-966): Undeclared identifier. +// DeclarationError: (976-977): Undeclared identifier. +// DeclarationError: (987-988): Undeclared identifier. +// DeclarationError: (998-999): Undeclared identifier. +// DeclarationError: (1009-1010): Undeclared identifier. +// DeclarationError: (1020-1021): Undeclared identifier. +// DeclarationError: (1031-1032): Undeclared identifier. +// DeclarationError: (1042-1043): Undeclared identifier. +// DeclarationError: (1053-1054): Undeclared identifier. +// DeclarationError: (1064-1065): Undeclared identifier. +// DeclarationError: (1075-1076): Undeclared identifier. +// DeclarationError: (1086-1087): Undeclared identifier. +// DeclarationError: (1097-1098): Undeclared identifier. +// DeclarationError: (1108-1109): Undeclared identifier. +// DeclarationError: (1119-1120): Undeclared identifier. +// DeclarationError: (1130-1131): Undeclared identifier. +// DeclarationError: (1141-1142): Undeclared identifier. +// DeclarationError: (1152-1153): Undeclared identifier. +// DeclarationError: (1163-1164): Undeclared identifier. +// DeclarationError: (1174-1175): Undeclared identifier. +// DeclarationError: (1185-1186): Undeclared identifier. +// DeclarationError: (1196-1197): Undeclared identifier. +// DeclarationError: (1207-1208): Undeclared identifier. +// DeclarationError: (1218-1219): Undeclared identifier. +// DeclarationError: (1229-1230): Undeclared identifier. +// DeclarationError: (1240-1241): Undeclared identifier. +// DeclarationError: (1251-1252): Undeclared identifier. +// DeclarationError: (1262-1263): Undeclared identifier. +// DeclarationError: (1273-1274): Undeclared identifier. +// DeclarationError: (1284-1285): Undeclared identifier. +// DeclarationError: (1295-1296): Undeclared identifier. +// DeclarationError: (1306-1307): Undeclared identifier. +// DeclarationError: (1317-1318): Undeclared identifier. +// DeclarationError: (1328-1329): Undeclared identifier. +// DeclarationError: (1339-1340): Undeclared identifier. +// DeclarationError: (1350-1351): Undeclared identifier. +// DeclarationError: (1361-1362): Undeclared identifier. +// DeclarationError: (1372-1373): Undeclared identifier. +// DeclarationError: (1383-1384): Undeclared identifier. +// DeclarationError: (1394-1395): Undeclared identifier. +// DeclarationError: (1405-1406): Undeclared identifier. +// DeclarationError: (1416-1417): Undeclared identifier. +// DeclarationError: (1427-1428): Undeclared identifier. +// DeclarationError: (1438-1439): Undeclared identifier. +// DeclarationError: (1449-1450): Undeclared identifier. +// DeclarationError: (1460-1461): Undeclared identifier. +// DeclarationError: (1471-1472): Undeclared identifier. +// DeclarationError: (1482-1483): Undeclared identifier. +// DeclarationError: (1493-1494): Undeclared identifier. +// DeclarationError: (1504-1505): Undeclared identifier. +// DeclarationError: (1515-1516): Undeclared identifier. +// DeclarationError: (1526-1527): Undeclared identifier. +// DeclarationError: (1537-1538): Undeclared identifier. +// DeclarationError: (1548-1549): Undeclared identifier. +// DeclarationError: (1559-1560): Undeclared identifier. +// DeclarationError: (1570-1571): Undeclared identifier. +// DeclarationError: (1581-1582): Undeclared identifier. +// DeclarationError: (1592-1593): Undeclared identifier. +// DeclarationError: (1603-1604): Undeclared identifier. +// DeclarationError: (1614-1615): Undeclared identifier. +// DeclarationError: (1625-1626): Undeclared identifier. +// DeclarationError: (1636-1637): Undeclared identifier. +// DeclarationError: (1647-1648): Undeclared identifier. +// DeclarationError: (1658-1659): Undeclared identifier. +// DeclarationError: (1669-1670): Undeclared identifier. +// DeclarationError: (1680-1681): Undeclared identifier. +// DeclarationError: (1691-1692): Undeclared identifier. +// DeclarationError: (1702-1703): Undeclared identifier. +// DeclarationError: (1713-1714): Undeclared identifier. +// DeclarationError: (1724-1725): Undeclared identifier. +// DeclarationError: (1735-1736): Undeclared identifier. +// DeclarationError: (1746-1747): Undeclared identifier. +// DeclarationError: (1757-1758): Undeclared identifier. +// DeclarationError: (1768-1769): Undeclared identifier. +// DeclarationError: (1779-1780): Undeclared identifier. +// DeclarationError: (1790-1791): Undeclared identifier. +// DeclarationError: (1801-1802): Undeclared identifier. +// DeclarationError: (1812-1813): Undeclared identifier. +// DeclarationError: (1823-1824): Undeclared identifier. +// DeclarationError: (1834-1835): Undeclared identifier. +// DeclarationError: (1845-1846): Undeclared identifier. +// DeclarationError: (1856-1857): Undeclared identifier. +// DeclarationError: (1867-1868): Undeclared identifier. +// DeclarationError: (1878-1879): Undeclared identifier. +// DeclarationError: (1889-1890): Undeclared identifier. +// DeclarationError: (1900-1901): Undeclared identifier. +// DeclarationError: (1911-1912): Undeclared identifier. +// DeclarationError: (1922-1923): Undeclared identifier. +// DeclarationError: (1933-1934): Undeclared identifier. +// DeclarationError: (1944-1945): Undeclared identifier. +// DeclarationError: (1955-1956): Undeclared identifier. +// DeclarationError: (1966-1967): Undeclared identifier. +// DeclarationError: (1977-1978): Undeclared identifier. +// DeclarationError: (1988-1989): Undeclared identifier. +// DeclarationError: (1999-2000): Undeclared identifier. +// DeclarationError: (2010-2011): Undeclared identifier. +// DeclarationError: (2021-2022): Undeclared identifier. +// DeclarationError: (2032-2033): Undeclared identifier. +// DeclarationError: (2043-2044): Undeclared identifier. +// DeclarationError: (2054-2055): Undeclared identifier. +// DeclarationError: (2065-2066): Undeclared identifier. +// DeclarationError: (2076-2077): Undeclared identifier. +// DeclarationError: (2087-2088): Undeclared identifier. +// DeclarationError: (2098-2099): Undeclared identifier. +// DeclarationError: (2109-2110): Undeclared identifier. +// DeclarationError: (2120-2121): Undeclared identifier. +// DeclarationError: (2131-2132): Undeclared identifier. +// DeclarationError: (2142-2143): Undeclared identifier. +// DeclarationError: (2153-2154): Undeclared identifier. +// DeclarationError: (2164-2165): Undeclared identifier. +// DeclarationError: (2175-2176): Undeclared identifier. +// DeclarationError: (2186-2187): Undeclared identifier. +// DeclarationError: (2197-2198): Undeclared identifier. +// DeclarationError: (2208-2209): Undeclared identifier. +// DeclarationError: (2219-2220): Undeclared identifier. +// DeclarationError: (2230-2231): Undeclared identifier. +// DeclarationError: (2241-2242): Undeclared identifier. +// DeclarationError: (2252-2253): Undeclared identifier. +// DeclarationError: (2263-2264): Undeclared identifier. +// DeclarationError: (2274-2275): Undeclared identifier. +// DeclarationError: (2285-2286): Undeclared identifier. +// DeclarationError: (2296-2297): Undeclared identifier. +// DeclarationError: (2307-2308): Undeclared identifier. +// DeclarationError: (2318-2319): Undeclared identifier. +// DeclarationError: (2329-2330): Undeclared identifier. +// DeclarationError: (2340-2341): Undeclared identifier. +// DeclarationError: (2351-2352): Undeclared identifier. +// DeclarationError: (2362-2363): Undeclared identifier. +// DeclarationError: (2373-2374): Undeclared identifier. +// DeclarationError: (2384-2385): Undeclared identifier. +// DeclarationError: (2395-2396): Undeclared identifier. +// DeclarationError: (2406-2407): Undeclared identifier. +// DeclarationError: (2417-2418): Undeclared identifier. +// DeclarationError: (2428-2429): Undeclared identifier. +// DeclarationError: (2439-2440): Undeclared identifier. +// DeclarationError: (2450-2451): Undeclared identifier. +// DeclarationError: (2461-2462): Undeclared identifier. +// DeclarationError: (2472-2473): Undeclared identifier. +// DeclarationError: (2483-2484): Undeclared identifier. +// DeclarationError: (2494-2495): Undeclared identifier. +// DeclarationError: (2505-2506): Undeclared identifier. +// DeclarationError: (2516-2517): Undeclared identifier. +// DeclarationError: (2527-2528): Undeclared identifier. +// DeclarationError: (2538-2539): Undeclared identifier. +// DeclarationError: (2549-2550): Undeclared identifier. +// DeclarationError: (2560-2561): Undeclared identifier. +// DeclarationError: (2571-2572): Undeclared identifier. +// DeclarationError: (2582-2583): Undeclared identifier. +// DeclarationError: (2593-2594): Undeclared identifier. +// DeclarationError: (2604-2605): Undeclared identifier. +// DeclarationError: (2615-2616): Undeclared identifier. +// DeclarationError: (2626-2627): Undeclared identifier. +// DeclarationError: (2637-2638): Undeclared identifier. +// DeclarationError: (2648-2649): Undeclared identifier. +// DeclarationError: (2659-2660): Undeclared identifier. +// DeclarationError: (2670-2671): Undeclared identifier. +// DeclarationError: (2681-2682): Undeclared identifier. +// DeclarationError: (2692-2693): Undeclared identifier. +// DeclarationError: (2703-2704): Undeclared identifier. +// DeclarationError: (2714-2715): Undeclared identifier. +// DeclarationError: (2725-2726): Undeclared identifier. +// DeclarationError: (2736-2737): Undeclared identifier. +// DeclarationError: (2747-2748): Undeclared identifier. +// DeclarationError: (2758-2759): Undeclared identifier. +// DeclarationError: (2769-2770): Undeclared identifier. +// DeclarationError: (2780-2781): Undeclared identifier. +// DeclarationError: (2791-2792): Undeclared identifier. +// DeclarationError: (2802-2803): Undeclared identifier. +// DeclarationError: (2813-2814): Undeclared identifier. +// DeclarationError: (2824-2825): Undeclared identifier. +// DeclarationError: (2835-2836): Undeclared identifier. +// DeclarationError: (2846-2847): Undeclared identifier. // Warning: There are more than 256 errors. Aborting. diff --git a/test/libsolidity/syntaxTests/more_than_256_syntaxerrors.sol b/test/libsolidity/syntaxTests/more_than_256_syntaxerrors.sol index 2c9b8a42..fe877396 100644 --- a/test/libsolidity/syntaxTests/more_than_256_syntaxerrors.sol +++ b/test/libsolidity/syntaxTests/more_than_256_syntaxerrors.sol @@ -1,5 +1,5 @@ contract C { - function f() { + function f() public { continue; continue; continue; @@ -265,260 +265,260 @@ contract C { } } // ---- -// SyntaxError: (34-42): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (48-56): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (62-70): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (76-84): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (90-98): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (104-112): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (118-126): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (132-140): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (146-154): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (160-168): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (174-182): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (188-196): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (202-210): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (216-224): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (230-238): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (244-252): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (258-266): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (272-280): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (286-294): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (300-308): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (314-322): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (328-336): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (342-350): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (356-364): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (370-378): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (384-392): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (398-406): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (412-420): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (426-434): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (440-448): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (454-462): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (468-476): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (482-490): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (496-504): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (510-518): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (524-532): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (538-546): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (552-560): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (566-574): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (580-588): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (594-602): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (608-616): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (622-630): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (636-644): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (650-658): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (664-672): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (678-686): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (692-700): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (706-714): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (720-728): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (734-742): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (748-756): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (762-770): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (776-784): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (790-798): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (804-812): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (818-826): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (832-840): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (846-854): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (860-868): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (874-882): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (888-896): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (902-910): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (916-924): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (930-938): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (944-952): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (958-966): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (972-980): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (986-994): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1000-1008): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1014-1022): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1028-1036): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1042-1050): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1056-1064): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1070-1078): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1084-1092): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1098-1106): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1112-1120): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1126-1134): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1140-1148): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1154-1162): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1168-1176): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1182-1190): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1196-1204): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1210-1218): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1224-1232): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1238-1246): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1252-1260): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1266-1274): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1280-1288): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1294-1302): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1308-1316): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1322-1330): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1336-1344): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1350-1358): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1364-1372): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1378-1386): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1392-1400): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1406-1414): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1420-1428): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1434-1442): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1448-1456): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1462-1470): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1476-1484): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1490-1498): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1504-1512): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1518-1526): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1532-1540): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1546-1554): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1560-1568): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1574-1582): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1588-1596): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1602-1610): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1616-1624): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1630-1638): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1644-1652): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1658-1666): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1672-1680): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1686-1694): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1700-1708): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1714-1722): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1728-1736): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1742-1750): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1756-1764): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1770-1778): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1784-1792): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1798-1806): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1812-1820): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1826-1834): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1840-1848): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1854-1862): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1868-1876): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1882-1890): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1896-1904): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1910-1918): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1924-1932): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1938-1946): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1952-1960): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1966-1974): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1980-1988): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (1994-2002): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2008-2016): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2022-2030): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2036-2044): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2050-2058): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2064-2072): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2078-2086): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2092-2100): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2106-2114): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2120-2128): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2134-2142): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2148-2156): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2162-2170): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2176-2184): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2190-2198): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2204-2212): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2218-2226): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2232-2240): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2246-2254): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2260-2268): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2274-2282): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2288-2296): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2302-2310): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2316-2324): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2330-2338): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2344-2352): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2358-2366): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2372-2380): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2386-2394): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2400-2408): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2414-2422): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2428-2436): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2442-2450): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2456-2464): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2470-2478): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2484-2492): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2498-2506): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2512-2520): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2526-2534): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2540-2548): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2554-2562): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2568-2576): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2582-2590): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2596-2604): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2610-2618): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2624-2632): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2638-2646): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2652-2660): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2666-2674): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2680-2688): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2694-2702): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2708-2716): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2722-2730): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2736-2744): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2750-2758): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2764-2772): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2778-2786): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2792-2800): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2806-2814): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2820-2828): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2834-2842): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2848-2856): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2862-2870): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2876-2884): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2890-2898): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2904-2912): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2918-2926): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2932-2940): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2946-2954): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2960-2968): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2974-2982): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (2988-2996): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3002-3010): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3016-3024): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3030-3038): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3044-3052): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3058-3066): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3072-3080): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3086-3094): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3100-3108): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3114-3122): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3128-3136): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3142-3150): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3156-3164): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3170-3178): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3184-3192): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3198-3206): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3212-3220): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3226-3234): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3240-3248): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3254-3262): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3268-3276): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3282-3290): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3296-3304): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3310-3318): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3324-3332): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3338-3346): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3352-3360): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3366-3374): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3380-3388): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3394-3402): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3408-3416): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3422-3430): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3436-3444): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3450-3458): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3464-3472): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3478-3486): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3492-3500): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3506-3514): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3520-3528): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3534-3542): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3548-3556): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3562-3570): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3576-3584): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3590-3598): "continue" has to be in a "for" or "while" loop. -// SyntaxError: (3604-3612): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (41-49): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (55-63): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (69-77): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (83-91): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (97-105): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (111-119): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (125-133): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (139-147): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (153-161): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (167-175): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (181-189): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (195-203): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (209-217): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (223-231): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (237-245): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (251-259): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (265-273): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (279-287): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (293-301): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (307-315): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (321-329): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (335-343): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (349-357): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (363-371): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (377-385): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (391-399): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (405-413): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (419-427): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (433-441): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (447-455): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (461-469): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (475-483): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (489-497): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (503-511): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (517-525): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (531-539): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (545-553): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (559-567): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (573-581): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (587-595): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (601-609): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (615-623): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (629-637): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (643-651): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (657-665): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (671-679): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (685-693): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (699-707): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (713-721): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (727-735): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (741-749): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (755-763): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (769-777): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (783-791): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (797-805): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (811-819): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (825-833): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (839-847): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (853-861): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (867-875): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (881-889): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (895-903): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (909-917): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (923-931): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (937-945): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (951-959): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (965-973): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (979-987): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (993-1001): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1007-1015): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1021-1029): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1035-1043): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1049-1057): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1063-1071): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1077-1085): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1091-1099): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1105-1113): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1119-1127): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1133-1141): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1147-1155): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1161-1169): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1175-1183): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1189-1197): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1203-1211): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1217-1225): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1231-1239): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1245-1253): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1259-1267): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1273-1281): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1287-1295): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1301-1309): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1315-1323): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1329-1337): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1343-1351): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1357-1365): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1371-1379): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1385-1393): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1399-1407): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1413-1421): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1427-1435): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1441-1449): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1455-1463): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1469-1477): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1483-1491): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1497-1505): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1511-1519): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1525-1533): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1539-1547): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1553-1561): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1567-1575): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1581-1589): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1595-1603): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1609-1617): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1623-1631): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1637-1645): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1651-1659): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1665-1673): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1679-1687): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1693-1701): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1707-1715): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1721-1729): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1735-1743): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1749-1757): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1763-1771): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1777-1785): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1791-1799): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1805-1813): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1819-1827): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1833-1841): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1847-1855): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1861-1869): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1875-1883): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1889-1897): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1903-1911): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1917-1925): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1931-1939): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1945-1953): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1959-1967): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1973-1981): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (1987-1995): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2001-2009): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2015-2023): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2029-2037): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2043-2051): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2057-2065): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2071-2079): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2085-2093): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2099-2107): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2113-2121): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2127-2135): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2141-2149): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2155-2163): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2169-2177): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2183-2191): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2197-2205): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2211-2219): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2225-2233): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2239-2247): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2253-2261): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2267-2275): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2281-2289): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2295-2303): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2309-2317): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2323-2331): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2337-2345): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2351-2359): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2365-2373): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2379-2387): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2393-2401): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2407-2415): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2421-2429): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2435-2443): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2449-2457): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2463-2471): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2477-2485): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2491-2499): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2505-2513): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2519-2527): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2533-2541): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2547-2555): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2561-2569): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2575-2583): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2589-2597): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2603-2611): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2617-2625): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2631-2639): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2645-2653): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2659-2667): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2673-2681): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2687-2695): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2701-2709): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2715-2723): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2729-2737): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2743-2751): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2757-2765): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2771-2779): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2785-2793): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2799-2807): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2813-2821): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2827-2835): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2841-2849): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2855-2863): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2869-2877): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2883-2891): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2897-2905): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2911-2919): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2925-2933): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2939-2947): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2953-2961): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2967-2975): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2981-2989): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (2995-3003): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3009-3017): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3023-3031): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3037-3045): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3051-3059): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3065-3073): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3079-3087): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3093-3101): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3107-3115): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3121-3129): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3135-3143): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3149-3157): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3163-3171): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3177-3185): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3191-3199): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3205-3213): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3219-3227): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3233-3241): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3247-3255): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3261-3269): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3275-3283): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3289-3297): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3303-3311): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3317-3325): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3331-3339): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3345-3353): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3359-3367): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3373-3381): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3387-3395): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3401-3409): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3415-3423): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3429-3437): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3443-3451): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3457-3465): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3471-3479): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3485-3493): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3499-3507): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3513-3521): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3527-3535): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3541-3549): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3555-3563): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3569-3577): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3583-3591): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3597-3605): "continue" has to be in a "for" or "while" loop. +// SyntaxError: (3611-3619): "continue" has to be in a "for" or "while" loop. // Warning: There are more than 256 errors. Aborting. diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponents.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponents.sol new file mode 100644 index 00000000..3b05a54c --- /dev/null +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponents.sol @@ -0,0 +1,25 @@ +contract C { + function f() public { + uint a = (1,2); + uint b = (1,2,3); + uint c = (1,2,3,4); + } + function g() public { + (uint a1, uint b1, uint c1, uint d1) = 1; + (uint a2, uint b2, uint c2) = 1; + (uint a3, uint b3) = 1; + } + function h() public { + (uint a1, uint b1, uint c1, uint d1) = (1,2,3); + (uint a2, uint b2, uint c2) = (1,2,3,4); + } +} +// ---- +// TypeError: (47-61): Different number of components on the left hand side (1) than on the right hand side (2). +// TypeError: (71-87): Different number of components on the left hand side (1) than on the right hand side (3). +// TypeError: (97-115): Different number of components on the left hand side (1) than on the right hand side (4). +// TypeError: (157-197): Different number of components on the left hand side (4) than on the right hand side (1). +// TypeError: (207-238): Different number of components on the left hand side (3) than on the right hand side (1). +// TypeError: (248-270): Different number of components on the left hand side (2) than on the right hand side (1). +// TypeError: (312-358): Different number of components on the left hand side (4) than on the right hand side (3). +// TypeError: (368-407): Different number of components on the left hand side (3) than on the right hand side (4). diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponentsFromReturn.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponentsFromReturn.sol new file mode 100644 index 00000000..7b556350 --- /dev/null +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponentsFromReturn.sol @@ -0,0 +1,29 @@ +contract C { + function f() public { + uint a = two(); + uint b = three(); + uint c = four(); + } + function g() public { + (uint a1, uint b1, uint c1, uint d1) = one(); + (uint a2, uint b2, uint c2) = one(); + (uint a3, uint b3) = one(); + } + function h() public { + (uint a1, uint b1, uint c1, uint d1) = three(); + (uint a2, uint b2, uint c2) = four(); + } + function one() public pure returns (uint); + function two() public pure returns (uint, uint); + function three() public pure returns (uint, uint, uint); + function four() public pure returns (uint, uint, uint, uint); +} +// ---- +// TypeError: (47-61): Different number of components on the left hand side (1) than on the right hand side (2). +// TypeError: (71-87): Different number of components on the left hand side (1) than on the right hand side (3). +// TypeError: (97-112): Different number of components on the left hand side (1) than on the right hand side (4). +// TypeError: (154-198): Different number of components on the left hand side (4) than on the right hand side (1). +// TypeError: (208-243): Different number of components on the left hand side (3) than on the right hand side (1). +// TypeError: (253-279): Different number of components on the left hand side (2) than on the right hand side (1). +// TypeError: (321-367): Different number of components on the left hand side (4) than on the right hand side (3). +// TypeError: (377-413): Different number of components on the left hand side (3) than on the right hand side (4). diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcards.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcards.sol new file mode 100644 index 00000000..b500823d --- /dev/null +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcards.sol @@ -0,0 +1,24 @@ +contract C { + function fn() public pure { + (uint a,) = (1,2,3); + (,uint b) = (1,2,3); + (,uint c,) = (1,2,3,4,5); + (uint d, uint e,) = (1,2,3,4); + (,uint f, uint g) = (1,2,3,4); + (,uint h, uint i,) = (1,2,3); + (uint j,) = 1; + (,uint k) = 1; + (,uint l,) = 1; + a;b;c;d;e;f;g;h;i;j;k;l; + } +} +// ---- +// TypeError: (53-72): Different number of components on the left hand side (2) than on the right hand side (3). +// TypeError: (82-101): Different number of components on the left hand side (2) than on the right hand side (3). +// TypeError: (111-135): Different number of components on the left hand side (3) than on the right hand side (5). +// TypeError: (145-174): Different number of components on the left hand side (3) than on the right hand side (4). +// TypeError: (184-213): Different number of components on the left hand side (3) than on the right hand side (4). +// TypeError: (223-251): Different number of components on the left hand side (4) than on the right hand side (3). +// TypeError: (261-274): Different number of components on the left hand side (2) than on the right hand side (1). +// TypeError: (284-297): Different number of components on the left hand side (2) than on the right hand side (1). +// TypeError: (307-321): Different number of components on the left hand side (3) than on the right hand side (1). diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcardsFromReturn.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcardsFromReturn.sol new file mode 100644 index 00000000..3224a182 --- /dev/null +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcardsFromReturn.sol @@ -0,0 +1,31 @@ +contract C { + function fn() public pure { + (uint a,) = three(); + (,uint b) = three(); + (,uint c,) = five(); + (uint d, uint e,) = four(); + (,uint f, uint g) = four(); + (,uint h, uint i,) = three(); + (uint j,) = one(); + (,uint k) = one(); + (,uint l,) = one(); + (,uint m, uint n,) = five(); + a;b;c;d;e;f;g;h;i;j;k;l;m;n; + } + function one() public pure returns (uint); + function two() public pure returns (uint, uint); + function three() public pure returns (uint, uint, uint); + function four() public pure returns (uint, uint, uint, uint); + function five() public pure returns (uint, uint, uint, uint, uint); +} +// ---- +// TypeError: (53-72): Different number of components on the left hand side (2) than on the right hand side (3). +// TypeError: (82-101): Different number of components on the left hand side (2) than on the right hand side (3). +// TypeError: (111-130): Different number of components on the left hand side (3) than on the right hand side (5). +// TypeError: (140-166): Different number of components on the left hand side (3) than on the right hand side (4). +// TypeError: (176-202): Different number of components on the left hand side (3) than on the right hand side (4). +// TypeError: (212-240): Different number of components on the left hand side (4) than on the right hand side (3). +// TypeError: (250-267): Different number of components on the left hand side (2) than on the right hand side (1). +// TypeError: (277-294): Different number of components on the left hand side (2) than on the right hand side (1). +// TypeError: (304-322): Different number of components on the left hand side (3) than on the right hand side (1). +// TypeError: (332-359): Different number of components on the left hand side (4) than on the right hand side (5). diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol index a3ce6a74..ba6e9916 100644 --- a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol @@ -2,10 +2,10 @@ contract D { struct S { uint a; uint b; } } contract C { - function f() internal returns (uint, uint, uint, D.S[20] storage, uint) { - (,,,D.S[10*2] storage x,) = f(); + function f() internal pure { + (,,,D.S[10*2] storage x,) = g(); x; } -} + function g() internal pure returns (uint, uint, uint, D.S[20] storage x, uint) { x = x; } +} // ---- -// Warning: (110-117): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning. diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationEmpty.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationEmpty.sol new file mode 100644 index 00000000..9618958e --- /dev/null +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationEmpty.sol @@ -0,0 +1,11 @@ +contract C { + function f() public pure { + (uint a, uint b) = f(); + (uint c) = f(); + uint d = f(); + } +} +// ---- +// TypeError: (52-74): Different number of components on the left hand side (2) than on the right hand side (0). +// TypeError: (84-98): Different number of components on the left hand side (1) than on the right hand side (0). +// TypeError: (108-120): Different number of components on the left hand side (1) than on the right hand side (0). diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalid.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalid.sol deleted file mode 100644 index c8686ae8..00000000 --- a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalid.sol +++ /dev/null @@ -1,8 +0,0 @@ -contract C { - function f() internal returns (uint, uint, uint, uint) { - var (uint a, uint b,,) = f(); - a; b; - } -} -// ---- -// ParserError: (81-85): Expected identifier but got 'uint' diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping.sol index 3ba85f69..224d9614 100644 --- a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping.sol +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping.sol @@ -1,5 +1,3 @@ -pragma experimental "v0.5.0"; - contract C { function f() internal { { @@ -9,4 +7,4 @@ contract C { } } // ---- -// DeclarationError: (130-131): Undeclared identifier. +// DeclarationError: (99-100): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping2.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping2.sol index e21181de..242a1f39 100644 --- a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping2.sol +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping2.sol @@ -1,5 +1,3 @@ -pragma experimental "v0.5.0"; - contract C { function f() internal { { @@ -8,6 +6,6 @@ contract C { } } // ---- -// DeclarationError: (110-111): Undeclared identifier. Did you mean "a"? -// DeclarationError: (113-114): Undeclared identifier. Did you mean "b"? -// DeclarationError: (116-117): Undeclared identifier. Did you mean "c"? +// DeclarationError: (79-80): Undeclared identifier. "a" is not (or not yet) visible at this point. +// DeclarationError: (82-83): Undeclared identifier. "b" is not (or not yet) visible at this point. +// DeclarationError: (85-86): Undeclared identifier. "c" is not (or not yet) visible at this point. diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol index 8e06322c..a2fcce18 100644 --- a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol @@ -1,12 +1,12 @@ contract C { - function f() internal returns (uint, uint, uint, uint) { + function f() internal pure returns (uint, uint, uint, uint) { (uint a, uint b,,) = f(); a; b; } - function g() internal returns (bytes memory, string storage) { - (bytes memory a, string storage b) = g(); + function g() internal pure { + (bytes memory a, string storage b) = h(); a; b; } -} + function h() internal pure returns (bytes memory, string storage s) { s = s; } +} // ---- -// Warning: (163-169): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning. diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/oneElementTuple.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/oneElementTuple.sol new file mode 100644 index 00000000..562c7c0b --- /dev/null +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/oneElementTuple.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + (uint a,) = (1,); + a; + } +} +// ---- +// TypeError: (59-63): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/sameNumberOfComponents.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/sameNumberOfComponents.sol new file mode 100644 index 00000000..59eb34af --- /dev/null +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/sameNumberOfComponents.sol @@ -0,0 +1,9 @@ +contract C { + function f() public pure { + (uint a1, uint b1, uint c1, uint d1) = (1,2,3,4); + (uint a2, uint b2, uint c2) = (1,2,3); + (uint a3, uint b3) = (1,2); + a1; b1; c1; d1; a2; b2; c2; a3; b3; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/001_name_references.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/001_name_references.sol new file mode 100644 index 00000000..dc304a1d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/001_name_references.sol @@ -0,0 +1,4 @@ +contract test { + uint256 variable; + function f(uint256) public returns (uint out) { f(variable); test; out; } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/002_undeclared_name.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/002_undeclared_name.sol new file mode 100644 index 00000000..afe9483f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/002_undeclared_name.sol @@ -0,0 +1,8 @@ +contract test { + uint256 variable; + function f(uint256 arg) public { + f(notfound); + } +} +// ---- +// DeclarationError: (85-93): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/003_undeclared_name_is_not_fatal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/003_undeclared_name_is_not_fatal.sol new file mode 100644 index 00000000..0f2a1526 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/003_undeclared_name_is_not_fatal.sol @@ -0,0 +1,10 @@ +contract test { + uint256 variable; + function f(uint256 arg) public { + f(notfound); + f(notfound); + } +} +// ---- +// DeclarationError: (85-93): Undeclared identifier. +// DeclarationError: (106-114): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/004_reference_to_later_declaration.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/004_reference_to_later_declaration.sol new file mode 100644 index 00000000..e112e16c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/004_reference_to_later_declaration.sol @@ -0,0 +1,6 @@ +contract test { + function g() public { f(); } + function f() public {} +} +// ---- +// Warning: (53-75): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/006_type_checking_return.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/006_type_checking_return.sol new file mode 100644 index 00000000..d0e87139 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/006_type_checking_return.sol @@ -0,0 +1,5 @@ +contract test { + function f() public returns (bool r) { return 1 >= 2; } +} +// ---- +// Warning: (20-75): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/007_type_checking_return_wrong_number.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/007_type_checking_return_wrong_number.sol new file mode 100644 index 00000000..13c70ad9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/007_type_checking_return_wrong_number.sol @@ -0,0 +1,5 @@ +contract test { + function f() public returns (bool r1, bool r2) { return 1 >= 2; } +} +// ---- +// TypeError: (69-82): Different number of arguments in return statement than in returns declaration. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/008_type_checking_return_wrong_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/008_type_checking_return_wrong_type.sol new file mode 100644 index 00000000..a7459ae8 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/008_type_checking_return_wrong_type.sol @@ -0,0 +1,5 @@ +contract test { + function f() public returns (uint256 r) { return 1 >= 2; } +} +// ---- +// TypeError: (69-75): Return argument type bool is not implicitly convertible to expected type (type of first return variable) uint256. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/009_type_checking_function_call.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/009_type_checking_function_call.sol new file mode 100644 index 00000000..abe2beac --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/009_type_checking_function_call.sol @@ -0,0 +1,6 @@ +contract test { + function f() public returns (bool) { return g(12, true) == 3; } + function g(uint256, bool) public returns (uint256) { } +} +// ---- +// Warning: (88-142): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/010_type_conversion_for_comparison.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/010_type_conversion_for_comparison.sol new file mode 100644 index 00000000..c0cd87d4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/010_type_conversion_for_comparison.sol @@ -0,0 +1,6 @@ +contract test { + function f() public { uint32(2) == int64(2); } +} +// ---- +// Warning: (42-63): Statement has no effect. +// Warning: (20-66): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/011_type_conversion_for_comparison_invalid.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/011_type_conversion_for_comparison_invalid.sol new file mode 100644 index 00000000..9cbce0d0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/011_type_conversion_for_comparison_invalid.sol @@ -0,0 +1,5 @@ +contract test { + function f() public { int32(2) == uint64(2); } +} +// ---- +// TypeError: (42-63): Operator == not compatible with types int32 and uint64 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/013_large_string_literal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/013_large_string_literal.sol new file mode 100644 index 00000000..7f858a4d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/013_large_string_literal.sol @@ -0,0 +1,6 @@ +contract test { + function f() public { string memory x = "123456789012345678901234567890123"; } +} +// ---- +// Warning: (42-57): Unused local variable. +// Warning: (20-98): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/014_balance.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/014_balance.sol new file mode 100644 index 00000000..e2c9a8bf --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/014_balance.sol @@ -0,0 +1,8 @@ +contract test { + function fun() public { + uint256 x = address(0).balance; + } +} +// ---- +// Warning: (52-61): Unused local variable. +// Warning: (20-89): Function state mutability can be restricted to view diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/015_balance_invalid.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/015_balance_invalid.sol new file mode 100644 index 00000000..18658fbe --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/015_balance_invalid.sol @@ -0,0 +1,7 @@ +contract test { + function fun() public { + address(0).balance = 7; + } +} +// ---- +// TypeError: (52-70): Expression has to be an lvalue. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol new file mode 100644 index 00000000..8bf45c3f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol @@ -0,0 +1,12 @@ +contract test { + struct str { + mapping(uint=>uint) map; + } + str data; + function fun() public { + mapping(uint=>uint) a = data.map; + data.map = a; + } +} +// ---- +// TypeError: (164-176): Mappings cannot be assigned to. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/017_assignment_to_struct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/017_assignment_to_struct.sol new file mode 100644 index 00000000..6fbd09ae --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/017_assignment_to_struct.sol @@ -0,0 +1,11 @@ +contract test { + struct str { + mapping(uint=>uint) map; + } + str data; + function fun() public { + str storage a = data; + data = a; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/018_forward_function_reference.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/018_forward_function_reference.sol new file mode 100644 index 00000000..fd9ab7ed --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/018_forward_function_reference.sol @@ -0,0 +1,10 @@ +contract First { + function fun() public returns (bool) { + return Second(1).fun(1, true, 3) > 0; + } +} +contract Second { + function fun(uint, bool, uint) public returns (uint) { + if (First(2).fun() == true) return 1; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/019_comparison_bitop_precedence.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/019_comparison_bitop_precedence.sol new file mode 100644 index 00000000..eab272df --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/019_comparison_bitop_precedence.sol @@ -0,0 +1,7 @@ +contract First { + function fun() public returns (bool ret) { + return 1 & 2 == 8 & 9 && 1 ^ 2 < 4 | 6; + } +} +// ---- +// Warning: (21-117): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/020_comparison_of_function_types_lt_1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/020_comparison_of_function_types_lt_1.sol new file mode 100644 index 00000000..1f288ff7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/020_comparison_of_function_types_lt_1.sol @@ -0,0 +1,7 @@ +contract C { + function f() public returns (bool ret) { + return this.f < this.f; + } +} +// ---- +// TypeError: (73-88): Operator < not compatible with types function () external returns (bool) and function () external returns (bool) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/021_comparison_of_function_types_lt_2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/021_comparison_of_function_types_lt_2.sol new file mode 100644 index 00000000..a6422d38 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/021_comparison_of_function_types_lt_2.sol @@ -0,0 +1,7 @@ +contract C { + function f() public returns (bool ret) { + return f < f; + } +} +// ---- +// TypeError: (73-78): Operator < not compatible with types function () returns (bool) and function () returns (bool) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/022_comparison_of_function_types_gt_1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/022_comparison_of_function_types_gt_1.sol new file mode 100644 index 00000000..ee865912 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/022_comparison_of_function_types_gt_1.sol @@ -0,0 +1,7 @@ +contract C { + function f() public returns (bool ret) { + return this.f > this.f; + } +} +// ---- +// TypeError: (73-88): Operator > not compatible with types function () external returns (bool) and function () external returns (bool) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/023_comparison_of_function_types_gt_2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/023_comparison_of_function_types_gt_2.sol new file mode 100644 index 00000000..590cc98b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/023_comparison_of_function_types_gt_2.sol @@ -0,0 +1,7 @@ +contract C { + function f() public returns (bool ret) { + return f > f; + } +} +// ---- +// TypeError: (73-78): Operator > not compatible with types function () returns (bool) and function () returns (bool) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/024_comparison_of_function_types_eq.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/024_comparison_of_function_types_eq.sol new file mode 100644 index 00000000..71dbec6b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/024_comparison_of_function_types_eq.sol @@ -0,0 +1,11 @@ +contract C { + function f() public returns (bool ret) { + return f == f; + } + function g() public returns (bool ret) { + return f != f; + } +} +// ---- +// Warning: (17-86): Function state mutability can be restricted to pure +// Warning: (91-160): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/025_comparison_of_mapping_types.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/025_comparison_of_mapping_types.sol new file mode 100644 index 00000000..27651d63 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/025_comparison_of_mapping_types.sol @@ -0,0 +1,9 @@ +contract C { + mapping(uint => uint) x; + function f() public returns (bool ret) { + mapping(uint => uint) y = x; + return x == y; + } +} +// ---- +// TypeError: (139-145): Operator == not compatible with types mapping(uint256 => uint256) and mapping(uint256 => uint256) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/029_create_abstract_contract.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/029_create_abstract_contract.sol new file mode 100644 index 00000000..455f4189 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/029_create_abstract_contract.sol @@ -0,0 +1,7 @@ +contract base { function foo() public; } +contract derived { + base b; + function foo() public { b = new base(); } +} +// ---- +// TypeError: (104-112): Trying to create an instance of an abstract contract. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/030_redeclare_implemented_abstract_function_as_abstract.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/030_redeclare_implemented_abstract_function_as_abstract.sol new file mode 100644 index 00000000..55bdea89 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/030_redeclare_implemented_abstract_function_as_abstract.sol @@ -0,0 +1,5 @@ +contract base { function foo() public; } +contract derived is base { function foo() public {} } +contract wrong is derived { function foo() public; } +// ---- +// TypeError: (123-145): Redeclaring an already implemented function as abstract diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/039_functions_with_identical_structs_in_interface.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/039_functions_with_identical_structs_in_interface.sol new file mode 100644 index 00000000..3389ffe4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/039_functions_with_identical_structs_in_interface.sol @@ -0,0 +1,11 @@ +pragma experimental ABIEncoderV2; + +contract C { + struct S1 { int i; } + struct S2 { int i; } + function f(S1 memory) public pure {} + function f(S2 memory) public pure {} +} +// ---- +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. +// TypeError: (143-179): Function overload clash during conversion to external types for arguments. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/040_functions_with_different_structs_in_interface.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/040_functions_with_different_structs_in_interface.sol new file mode 100644 index 00000000..6ff8fd6e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/040_functions_with_different_structs_in_interface.sol @@ -0,0 +1,10 @@ +pragma experimental ABIEncoderV2; + +contract C { + struct S1 { function() external a; } + struct S2 { bytes24 a; } + function f(S1 memory) public pure {} + function f(S2 memory) public pure {} +} +// ---- +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
\ No newline at end of file diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/041_functions_with_stucts_of_non_external_types_in_interface.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/041_functions_with_stucts_of_non_external_types_in_interface.sol new file mode 100644 index 00000000..9fd09dd7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/041_functions_with_stucts_of_non_external_types_in_interface.sol @@ -0,0 +1,9 @@ +pragma experimental ABIEncoderV2; + +contract C { + struct S { function() internal a; } + function f(S memory) public {} +} +// ---- +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. +// TypeError: (103-104): Internal or recursive type is not allowed for public or external functions. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/042_functions_with_stucts_of_non_external_types_in_interface_2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/042_functions_with_stucts_of_non_external_types_in_interface_2.sol new file mode 100644 index 00000000..435a02ef --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/042_functions_with_stucts_of_non_external_types_in_interface_2.sol @@ -0,0 +1,9 @@ +pragma experimental ABIEncoderV2; + +contract C { + struct S { mapping(uint => uint) a; } + function f(S memory) public {} +} +// ---- +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. +// TypeError: (105-106): Internal or recursive type is not allowed for public or external functions. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/043_functions_with_stucts_of_non_external_types_in_interface_nested.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/043_functions_with_stucts_of_non_external_types_in_interface_nested.sol new file mode 100644 index 00000000..b9dc7c2e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/043_functions_with_stucts_of_non_external_types_in_interface_nested.sol @@ -0,0 +1,10 @@ +pragma experimental ABIEncoderV2; + +contract C { + struct T { mapping(uint => uint) a; } + struct S { T[][2] b; } + function f(S memory) public {} +} +// ---- +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. +// TypeError: (132-133): Internal or recursive type is not allowed for public or external functions. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/044_returning_multi_dimensional_arrays_new_abi.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/044_returning_multi_dimensional_arrays_new_abi.sol new file mode 100644 index 00000000..ae9416e5 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/044_returning_multi_dimensional_arrays_new_abi.sol @@ -0,0 +1,7 @@ +pragma experimental ABIEncoderV2; + +contract C { + function f() public pure returns (string[][] memory) {} +} +// ---- +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/045_returning_multi_dimensional_arrays.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/045_returning_multi_dimensional_arrays.sol new file mode 100644 index 00000000..221e5fa4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/045_returning_multi_dimensional_arrays.sol @@ -0,0 +1,5 @@ +contract C { + function f() public pure returns (string[][] memory) {} +} +// ---- +// TypeError: (51-61): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/046_returning_multi_dimensional_static_arrays.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/046_returning_multi_dimensional_static_arrays.sol new file mode 100644 index 00000000..75423bc9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/046_returning_multi_dimensional_static_arrays.sol @@ -0,0 +1,5 @@ +contract C { + function f() public pure returns (uint[][2] memory) {} +} +// ---- +// TypeError: (51-60): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/047_returning_arrays_in_structs_new_abi.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/047_returning_arrays_in_structs_new_abi.sol new file mode 100644 index 00000000..8ca3a53d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/047_returning_arrays_in_structs_new_abi.sol @@ -0,0 +1,8 @@ +pragma experimental ABIEncoderV2; + +contract C { + struct S { string[] s; } + function f() public pure returns (S memory) {} +} +// ---- +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/048_returning_arrays_in_structs_arrays.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/048_returning_arrays_in_structs_arrays.sol new file mode 100644 index 00000000..48e80fcf --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/048_returning_arrays_in_structs_arrays.sol @@ -0,0 +1,6 @@ +contract C { + struct S { string[] s; } + function f() public pure returns (S memory x) {} +} +// ---- +// TypeError: (80-90): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/049_function_external_call_allowed_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/049_function_external_call_allowed_conversion.sol new file mode 100644 index 00000000..ec72adeb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/049_function_external_call_allowed_conversion.sol @@ -0,0 +1,11 @@ +contract C {} +contract Test { + function externalCall() public { + C arg; + this.g(arg); + } + function g (C c) external {} +} +// ---- +// Warning: (125-128): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (113-141): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/050_function_external_call_not_allowed_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/050_function_external_call_not_allowed_conversion.sol new file mode 100644 index 00000000..18d75948 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/050_function_external_call_not_allowed_conversion.sol @@ -0,0 +1,10 @@ +contract C {} +contract Test { + function externalCall() public { + address arg; + this.g(arg); + } + function g (C c) external {} +} +// ---- +// TypeError: (103-106): Invalid type for argument in function call. Invalid implicit conversion from address to contract C requested. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/051_function_internal_allowed_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/051_function_internal_allowed_conversion.sol new file mode 100644 index 00000000..aedc7b0b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/051_function_internal_allowed_conversion.sol @@ -0,0 +1,13 @@ +contract C { + uint a; +} +contract Test { + C a; + function g (C c) public {} + function internalCall() public { + g(a); + } +} +// ---- +// Warning: (68-71): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (56-82): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/052_function_internal_not_allowed_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/052_function_internal_not_allowed_conversion.sol new file mode 100644 index 00000000..c16d35eb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/052_function_internal_not_allowed_conversion.sol @@ -0,0 +1,12 @@ +contract C { + uint a; +} +contract Test { + address a; + function g (C c) public {} + function internalCall() public { + g(a); + } +} +// ---- +// TypeError: (136-137): Invalid type for argument in function call. Invalid implicit conversion from address to contract C requested. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/053_hash_collision_in_interface.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/053_hash_collision_in_interface.sol new file mode 100644 index 00000000..fe690e16 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/053_hash_collision_in_interface.sol @@ -0,0 +1,6 @@ +contract test { + function gsf() public { } + function tgeo() public { } +} +// ---- +// TypeError: (0-78): Function signature hash collision for tgeo() diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/054_inheritance_basic.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/054_inheritance_basic.sol new file mode 100644 index 00000000..6229a1dc --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/054_inheritance_basic.sol @@ -0,0 +1,5 @@ +contract base { uint baseMember; struct BaseType { uint element; } } +contract derived is base { + BaseType data; + function f() public { baseMember = 7; } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/055_inheritance_diamond_basic.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/055_inheritance_diamond_basic.sol new file mode 100644 index 00000000..c07e59e2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/055_inheritance_diamond_basic.sol @@ -0,0 +1,9 @@ +contract root { function rootFunction() public {} } +contract inter1 is root { function f() public {} } +contract inter2 is root { function f() public {} } +contract derived is root, inter2, inter1 { + function g() public { f(); rootFunction(); } +} +// ---- +// Warning: (16-49): Function state mutability can be restricted to pure +// Warning: (129-151): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/056_cyclic_inheritance.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/056_cyclic_inheritance.sol new file mode 100644 index 00000000..0e1ec4cb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/056_cyclic_inheritance.sol @@ -0,0 +1,4 @@ +contract A is B { } +contract B is A { } +// ---- +// TypeError: (14-15): Definition of base has to precede definition of derived contract diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/057_legal_override_direct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/057_legal_override_direct.sol new file mode 100644 index 00000000..062507ee --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/057_legal_override_direct.sol @@ -0,0 +1,6 @@ +contract B { function f() public {} } +contract C is B { function f(uint i) public {} } +// ---- +// Warning: (67-73): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (13-35): Function state mutability can be restricted to pure +// Warning: (56-84): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/058_legal_override_indirect.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/058_legal_override_indirect.sol new file mode 100644 index 00000000..f59da472 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/058_legal_override_indirect.sol @@ -0,0 +1,7 @@ +contract A { function f(uint a) public {} } +contract B { function f() public {} } +contract C is A, B { } +// ---- +// Warning: (24-30): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (13-41): Function state mutability can be restricted to pure +// Warning: (57-79): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/059_illegal_override_visibility.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/059_illegal_override_visibility.sol new file mode 100644 index 00000000..8c13a478 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/059_illegal_override_visibility.sol @@ -0,0 +1,4 @@ +contract B { function f() internal {} } +contract C is B { function f() public {} } +// ---- +// TypeError: (58-80): Overriding function visibility differs. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/060_complex_inheritance.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/060_complex_inheritance.sol new file mode 100644 index 00000000..c7e42238 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/060_complex_inheritance.sol @@ -0,0 +1,6 @@ +contract A { function f() public { uint8 x = C(0).g(); } } +contract B { function f() public {} function g() public returns (uint8) {} } +contract C is A, B { } +// ---- +// Warning: (35-42): Unused local variable. +// Warning: (95-133): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/061_missing_base_constructor_arguments.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/061_missing_base_constructor_arguments.sol new file mode 100644 index 00000000..8ebb46aa --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/061_missing_base_constructor_arguments.sol @@ -0,0 +1,4 @@ +contract A { constructor(uint a) public { } } +contract B is A { } +// ---- +// Warning: (25-31): Unused function parameter. Remove or comment out the variable name to silence this warning. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/062_base_constructor_arguments_override.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/062_base_constructor_arguments_override.sol new file mode 100644 index 00000000..8ebb46aa --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/062_base_constructor_arguments_override.sol @@ -0,0 +1,4 @@ +contract A { constructor(uint a) public { } } +contract B is A { } +// ---- +// Warning: (25-31): Unused function parameter. Remove or comment out the variable name to silence this warning. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/063_implicit_derived_to_base_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/063_implicit_derived_to_base_conversion.sol new file mode 100644 index 00000000..f4667996 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/063_implicit_derived_to_base_conversion.sol @@ -0,0 +1,7 @@ +contract A { } +contract B is A { + function f() public { A a = B(1); } +} +// ---- +// Warning: (59-62): Unused local variable. +// Warning: (37-72): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/064_implicit_base_to_derived_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/064_implicit_base_to_derived_conversion.sol new file mode 100644 index 00000000..0d23ea87 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/064_implicit_base_to_derived_conversion.sol @@ -0,0 +1,6 @@ +contract A { } +contract B is A { + function f() public { B b = A(1); } +} +// ---- +// TypeError: (59-69): Type contract A is not implicitly convertible to expected type contract B. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/065_super_excludes_current_contract.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/065_super_excludes_current_contract.sol new file mode 100644 index 00000000..6fa92a6a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/065_super_excludes_current_contract.sol @@ -0,0 +1,11 @@ +contract A { + function b() public {} +} + +contract B is A { + function f() public { + super.f(); + } +} +// ---- +// TypeError: (95-102): Member "f" not found or not visible after argument-dependent lookup in contract super B diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/067_function_clash_with_state_variable_accessor.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/067_function_clash_with_state_variable_accessor.sol new file mode 100644 index 00000000..a99682c0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/067_function_clash_with_state_variable_accessor.sol @@ -0,0 +1,9 @@ +contract test { + function fun() public { + uint64(2); + } + uint256 foo; + function foo() public {} +} +// ---- +// DeclarationError: (90-114): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/069_base_class_state_variable_accessor.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/069_base_class_state_variable_accessor.sol new file mode 100644 index 00000000..8f2c6438 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/069_base_class_state_variable_accessor.sol @@ -0,0 +1,9 @@ +// test for issue #1126 https://github.com/ethereum/cpp-ethereum/issues/1126 +contract Parent { + uint256 public m_aMember; +} +contract Child is Parent { + function foo() public returns (uint256) { return Parent.m_aMember; } +} +// ---- +// Warning: (158-226): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/070_struct_accessor_one_array_only.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/070_struct_accessor_one_array_only.sol new file mode 100644 index 00000000..6741a7fa --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/070_struct_accessor_one_array_only.sol @@ -0,0 +1,6 @@ +contract test { + struct Data { uint[15] m_array; } + Data public data; +} +// ---- +// TypeError: (58-74): Internal or recursive type is not allowed for public state variables. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/071_base_class_state_variable_internal_member.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/071_base_class_state_variable_internal_member.sol new file mode 100644 index 00000000..774ea38e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/071_base_class_state_variable_internal_member.sol @@ -0,0 +1,8 @@ +contract Parent { + uint256 internal m_aMember; +} +contract Child is Parent { + function foo() public returns (uint256) { return Parent.m_aMember; } +} +// ---- +// Warning: (83-151): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/072_state_variable_member_of_wrong_class1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/072_state_variable_member_of_wrong_class1.sol new file mode 100644 index 00000000..949761b6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/072_state_variable_member_of_wrong_class1.sol @@ -0,0 +1,11 @@ +contract Parent1 { + uint256 internal m_aMember1; +} +contract Parent2 is Parent1 { + uint256 internal m_aMember2; +} +contract Child is Parent2 { + function foo() public returns (uint256) { return Parent2.m_aMember1; } +} +// ---- +// TypeError: (200-218): Member "m_aMember1" not found or not visible after argument-dependent lookup in type(contract Parent2) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/073_state_variable_member_of_wrong_class2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/073_state_variable_member_of_wrong_class2.sol new file mode 100644 index 00000000..9a0ee8a3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/073_state_variable_member_of_wrong_class2.sol @@ -0,0 +1,12 @@ +contract Parent1 { + uint256 internal m_aMember1; +} +contract Parent2 is Parent1 { + uint256 internal m_aMember2; +} +contract Child is Parent2 { + function foo() public returns (uint256) { return Child.m_aMember2; } + uint256 public m_aMember3; +} +// ---- +// TypeError: (200-216): Member "m_aMember2" not found or not visible after argument-dependent lookup in type(contract Child) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/074_fallback_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/074_fallback_function.sol new file mode 100644 index 00000000..466e80cb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/074_fallback_function.sol @@ -0,0 +1,4 @@ +contract C { + uint x; + function() external { x = 2; } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/075_fallback_function_with_arguments.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/075_fallback_function_with_arguments.sol new file mode 100644 index 00000000..68d40952 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/075_fallback_function_with_arguments.sol @@ -0,0 +1,6 @@ +contract C { + uint x; + function(uint a) external { x = 2; } +} +// ---- +// TypeError: (37-45): Fallback function cannot take parameters. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/076_fallback_function_in_library.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/076_fallback_function_in_library.sol new file mode 100644 index 00000000..25878a61 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/076_fallback_function_in_library.sol @@ -0,0 +1,5 @@ +library C { + function() external {} +} +// ---- +// TypeError: (16-38): Libraries cannot have fallback functions. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/077_fallback_function_with_return_parameters.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/077_fallback_function_with_return_parameters.sol new file mode 100644 index 00000000..3ff7a1c4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/077_fallback_function_with_return_parameters.sol @@ -0,0 +1,5 @@ +contract C { + function() external returns (uint) { } +} +// ---- +// TypeError: (45-51): Fallback function cannot return values. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/078_fallback_function_twice.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/078_fallback_function_twice.sol new file mode 100644 index 00000000..e5746c63 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/078_fallback_function_twice.sol @@ -0,0 +1,7 @@ +contract C { + uint x; + function() external { x = 2; } + function() external { x = 3; } +} +// ---- +// DeclarationError: (64-94): Only one fallback function is allowed. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/079_fallback_function_inheritance.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/079_fallback_function_inheritance.sol new file mode 100644 index 00000000..c8c06c6e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/079_fallback_function_inheritance.sol @@ -0,0 +1,7 @@ +contract A { + uint x; + function() external { x = 1; } +} +contract C is A { + function() external { x = 2; } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/080_event.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/080_event.sol new file mode 100644 index 00000000..c5f9e4d0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/080_event.sol @@ -0,0 +1,5 @@ +contract c { + event e(uint indexed a, bytes3 indexed s, bool indexed b); + function f() public { emit e(2, "abc", true); } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/081_event_too_many_indexed.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/081_event_too_many_indexed.sol new file mode 100644 index 00000000..ee0af605 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/081_event_too_many_indexed.sol @@ -0,0 +1,5 @@ +contract c { + event e(uint indexed a, bytes3 indexed b, bool indexed c, uint indexed d); +} +// ---- +// TypeError: (17-91): More than 3 indexed arguments for event. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/082_anonymous_event_four_indexed.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/082_anonymous_event_four_indexed.sol new file mode 100644 index 00000000..e8b36906 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/082_anonymous_event_four_indexed.sol @@ -0,0 +1,3 @@ +contract c { + event e(uint indexed a, bytes3 indexed b, bool indexed c, uint indexed d) anonymous; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/083_anonymous_event_too_many_indexed.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/083_anonymous_event_too_many_indexed.sol new file mode 100644 index 00000000..d439c5b9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/083_anonymous_event_too_many_indexed.sol @@ -0,0 +1,5 @@ +contract c { + event e(uint indexed a, bytes3 indexed b, bool indexed c, uint indexed d, uint indexed e) anonymous; +} +// ---- +// TypeError: (17-117): More than 4 indexed arguments for anonymous event. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/084_events_with_same_name.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/084_events_with_same_name.sol new file mode 100644 index 00000000..24f633b3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/084_events_with_same_name.sol @@ -0,0 +1,4 @@ +contract TestIt { + event A(); + event A(uint i); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/085_events_with_same_name_unnamed_arguments.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/085_events_with_same_name_unnamed_arguments.sol new file mode 100644 index 00000000..cccd9d57 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/085_events_with_same_name_unnamed_arguments.sol @@ -0,0 +1,4 @@ +contract test { + event A(uint); + event A(uint, uint); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/086_events_with_same_name_different_types.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/086_events_with_same_name_different_types.sol new file mode 100644 index 00000000..fbeab711 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/086_events_with_same_name_different_types.sol @@ -0,0 +1,4 @@ +contract test { + event A(uint); + event A(bytes); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/087_double_event_declaration.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/087_double_event_declaration.sol new file mode 100644 index 00000000..af0280c5 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/087_double_event_declaration.sol @@ -0,0 +1,6 @@ +contract test { + event A(uint i); + event A(uint i); +} +// ---- +// DeclarationError: (20-36): Event with same name and arguments defined twice. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/088_double_event_declaration_ignores_anonymous.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/088_double_event_declaration_ignores_anonymous.sol new file mode 100644 index 00000000..7d4b0ac9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/088_double_event_declaration_ignores_anonymous.sol @@ -0,0 +1,6 @@ +contract test { + event A(uint i); + event A(uint i) anonymous; +} +// ---- +// DeclarationError: (20-36): Event with same name and arguments defined twice. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/089_double_event_declaration_ignores_indexed.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/089_double_event_declaration_ignores_indexed.sol new file mode 100644 index 00000000..e6aa3e5f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/089_double_event_declaration_ignores_indexed.sol @@ -0,0 +1,6 @@ +contract test { + event A(uint i); + event A(uint indexed i); +} +// ---- +// DeclarationError: (20-36): Event with same name and arguments defined twice. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/090_event_call.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/090_event_call.sol new file mode 100644 index 00000000..8cf50597 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/090_event_call.sol @@ -0,0 +1,5 @@ +contract c { + event e(uint a, bytes3 indexed s, bool indexed b); + function f() public { emit e(2, "abc", true); } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/091_event_function_inheritance_clash.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/091_event_function_inheritance_clash.sol new file mode 100644 index 00000000..5e0f58ea --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/091_event_function_inheritance_clash.sol @@ -0,0 +1,12 @@ +contract A { + function dup() public returns (uint) { + return 1; + } +} +contract B { + event dup(); +} +contract C is A, B { +} +// ---- +// DeclarationError: (99-111): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/092_function_event_inheritance_clash.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/092_function_event_inheritance_clash.sol new file mode 100644 index 00000000..c567f992 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/092_function_event_inheritance_clash.sol @@ -0,0 +1,12 @@ +contract B { + event dup(); +} +contract A { + function dup() public returns (uint) { + return 1; + } +} +contract C is B, A { +} +// ---- +// DeclarationError: (49-111): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/093_function_event_in_contract_clash.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/093_function_event_in_contract_clash.sol new file mode 100644 index 00000000..7b4fcde9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/093_function_event_in_contract_clash.sol @@ -0,0 +1,8 @@ +contract A { + event dup(); + function dup() public returns (uint) { + return 1; + } +} +// ---- +// DeclarationError: (34-96): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/094_event_inheritance.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/094_event_inheritance.sol new file mode 100644 index 00000000..b13d5755 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/094_event_inheritance.sol @@ -0,0 +1,7 @@ +contract base { + event e(uint a, bytes3 indexed s, bool indexed b); +} +contract c is base { + function f() public { emit e(2, "abc", true); } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/095_multiple_events_argument_clash.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/095_multiple_events_argument_clash.sol new file mode 100644 index 00000000..79127119 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/095_multiple_events_argument_clash.sol @@ -0,0 +1,4 @@ +contract c { + event e1(uint a, uint e1, uint e2); + event e2(uint a, uint e1, uint e2); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/096_access_to_default_function_visibility.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/096_access_to_default_function_visibility.sol new file mode 100644 index 00000000..9251df73 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/096_access_to_default_function_visibility.sol @@ -0,0 +1,8 @@ +contract c { + function f() public {} +} +contract d { + function g() public { c(0).f(); } +} +// ---- +// Warning: (17-39): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/097_access_to_internal_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/097_access_to_internal_function.sol new file mode 100644 index 00000000..e13e1531 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/097_access_to_internal_function.sol @@ -0,0 +1,8 @@ +contract c { + function f() internal {} +} +contract d { + function g() public { c(0).f(); } +} +// ---- +// TypeError: (83-89): Member "f" not found or not visible after argument-dependent lookup in contract c diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/098_access_to_default_state_variable_visibility.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/098_access_to_default_state_variable_visibility.sol new file mode 100644 index 00000000..ab7546c6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/098_access_to_default_state_variable_visibility.sol @@ -0,0 +1,8 @@ +contract c { + uint a; +} +contract d { + function g() public { c(0).a(); } +} +// ---- +// TypeError: (66-72): Member "a" not found or not visible after argument-dependent lookup in contract c diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/099_access_to_internal_state_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/099_access_to_internal_state_variable.sol new file mode 100644 index 00000000..60aba574 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/099_access_to_internal_state_variable.sol @@ -0,0 +1,8 @@ +contract c { + uint public a; +} +contract d { + function g() public { c(0).a(); } +} +// ---- +// Warning: (51-84): Function state mutability can be restricted to view diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/100_error_count_in_named_args.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/100_error_count_in_named_args.sol new file mode 100644 index 00000000..a679c25a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/100_error_count_in_named_args.sol @@ -0,0 +1,11 @@ +contract test { + function a(uint a, uint b) public returns (uint r) { + r = a + b; + } + function b() public returns (uint r) { + r = a({a: 1}); + } +} +// ---- +// Warning: (31-37): This declaration shadows an existing declaration. +// TypeError: (153-162): Wrong argument count for function call: 1 arguments given but expected 2. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/101_empty_in_named_args.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/101_empty_in_named_args.sol new file mode 100644 index 00000000..9da11d6f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/101_empty_in_named_args.sol @@ -0,0 +1,11 @@ +contract test { + function a(uint a, uint b) public returns (uint r) { + r = a + b; + } + function b() public returns (uint r) { + r = a({}); + } +} +// ---- +// Warning: (31-37): This declaration shadows an existing declaration. +// TypeError: (153-158): Wrong argument count for function call: 0 arguments given but expected 2. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/102_duplicate_parameter_names_in_named_args.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/102_duplicate_parameter_names_in_named_args.sol new file mode 100644 index 00000000..fab4beff --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/102_duplicate_parameter_names_in_named_args.sol @@ -0,0 +1,11 @@ +contract test { + function a(uint a, uint b) public returns (uint r) { + r = a + b; + } + function b() public returns (uint r) { + r = a({a: 1, a: 2}); + } +} +// ---- +// Warning: (31-37): This declaration shadows an existing declaration. +// TypeError: (159-160): Duplicate named argument. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/103_invalid_parameter_names_in_named_args.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/103_invalid_parameter_names_in_named_args.sol new file mode 100644 index 00000000..bed15186 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/103_invalid_parameter_names_in_named_args.sol @@ -0,0 +1,11 @@ +contract test { + function a(uint a, uint b) public returns (uint r) { + r = a + b; + } + function b() public returns (uint r) { + r = a({a: 1, c: 2}); + } +} +// ---- +// Warning: (31-37): This declaration shadows an existing declaration. +// TypeError: (153-168): Named argument "c" does not match function declaration. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/104_empty_name_input_parameter.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/104_empty_name_input_parameter.sol new file mode 100644 index 00000000..824543ef --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/104_empty_name_input_parameter.sol @@ -0,0 +1,5 @@ +contract test { + function f(uint) public { } +} +// ---- +// Warning: (20-47): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/105_constant_input_parameter.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/105_constant_input_parameter.sol new file mode 100644 index 00000000..df47aa6b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/105_constant_input_parameter.sol @@ -0,0 +1,7 @@ +contract test { + function f(uint[] memory constant a) public { } +} +// ---- +// TypeError: (31-55): Illegal use of "constant" specifier. +// TypeError: (31-55): Constants of non-value type not yet implemented. +// TypeError: (31-55): Uninitialized "constant" variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/106_empty_name_return_parameter.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/106_empty_name_return_parameter.sol new file mode 100644 index 00000000..a2ffc6e1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/106_empty_name_return_parameter.sol @@ -0,0 +1,5 @@ +contract test { + function f() public returns (bool) { } +} +// ---- +// Warning: (20-58): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/107_empty_name_input_parameter_with_named_one.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/107_empty_name_input_parameter_with_named_one.sol new file mode 100644 index 00000000..e0efa0a0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/107_empty_name_input_parameter_with_named_one.sol @@ -0,0 +1,7 @@ +contract test { + function f(uint, uint k) public returns (uint ret_k) { + return k; + } +} +// ---- +// Warning: (20-98): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/108_empty_name_return_parameter_with_named_one.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/108_empty_name_return_parameter_with_named_one.sol new file mode 100644 index 00000000..39ae7877 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/108_empty_name_return_parameter_with_named_one.sol @@ -0,0 +1,7 @@ +contract test { + function f() public returns (uint ret_k, uint) { + return 5; + } +} +// ---- +// TypeError: (77-85): Different number of arguments in return statement than in returns declaration. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/110_no_overflow_with_large_literal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/110_no_overflow_with_large_literal.sol new file mode 100644 index 00000000..9b36fa70 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/110_no_overflow_with_large_literal.sol @@ -0,0 +1,7 @@ +contract c { + constructor() public { + a = 115792089237316195423570985008687907853269984665640564039458; + } + uint256 a; +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/111_overflow_caused_by_ether_units.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/111_overflow_caused_by_ether_units.sol new file mode 100644 index 00000000..dc4cab8a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/111_overflow_caused_by_ether_units.sol @@ -0,0 +1,8 @@ +contract c { + constructor() public { + a = 115792089237316195423570985008687907853269984665640564039458 ether; + } + uint256 a; +} +// ---- +// TypeError: (52-118): Type int_const 1157...(70 digits omitted)...0000 is not implicitly convertible to expected type uint256. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/112_exp_operator_exponent_too_big.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/112_exp_operator_exponent_too_big.sol new file mode 100644 index 00000000..2a9e6204 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/112_exp_operator_exponent_too_big.sol @@ -0,0 +1,5 @@ +contract test { + function f() public returns (uint d) { return 2 ** 10000000000; } +} +// ---- +// TypeError: (66-82): Operator ** not compatible with types int_const 2 and int_const 10000000000 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/113_exp_warn_literal_base_1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/113_exp_warn_literal_base_1.sol new file mode 100644 index 00000000..0d91fcab --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/113_exp_warn_literal_base_1.sol @@ -0,0 +1,8 @@ +contract test { + function f() pure public returns(uint) { + uint8 x = 100; + return 10**x; + } +} +// ---- +// Warning: (99-104): Result of exponentiation has type uint8 and thus might overflow. Silence this warning by converting the literal to the expected type. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/114_exp_warn_literal_base_2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/114_exp_warn_literal_base_2.sol new file mode 100644 index 00000000..eb430b9a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/114_exp_warn_literal_base_2.sol @@ -0,0 +1,6 @@ +contract test { + function f() pure public returns(uint) { + uint8 x = 100; + return uint8(10)**x; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/115_exp_warn_literal_base_3.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/115_exp_warn_literal_base_3.sol new file mode 100644 index 00000000..01c0fc06 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/115_exp_warn_literal_base_3.sol @@ -0,0 +1,5 @@ +contract test { + function f() pure public returns(uint) { + return 2**80; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/116_shift_warn_literal_base_1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/116_shift_warn_literal_base_1.sol new file mode 100644 index 00000000..c6a4052e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/116_shift_warn_literal_base_1.sol @@ -0,0 +1,8 @@ +contract test { + function f() pure public returns(uint) { + uint8 x = 100; + return 10 << x; + } +} +// ---- +// Warning: (99-106): Result of shift has type uint8 and thus might overflow. Silence this warning by converting the literal to the expected type. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/117_shift_warn_literal_base_2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/117_shift_warn_literal_base_2.sol new file mode 100644 index 00000000..954d1943 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/117_shift_warn_literal_base_2.sol @@ -0,0 +1,6 @@ +contract test { + function f() pure public returns(uint) { + uint8 x = 100; + return uint8(10) << x; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/118_shift_warn_literal_base_3.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/118_shift_warn_literal_base_3.sol new file mode 100644 index 00000000..5fbaa806 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/118_shift_warn_literal_base_3.sol @@ -0,0 +1,5 @@ +contract test { + function f() pure public returns(uint) { + return 2 << 80; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/119_shift_warn_literal_base_4.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/119_shift_warn_literal_base_4.sol new file mode 100644 index 00000000..19869157 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/119_shift_warn_literal_base_4.sol @@ -0,0 +1,6 @@ +contract test { + function f() pure public returns(uint) { + uint8 x = 100; + return 10 >> x; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/124_enum_member_access.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/124_enum_member_access.sol new file mode 100644 index 00000000..98bc8e66 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/124_enum_member_access.sol @@ -0,0 +1,8 @@ +contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + constructor() public + { + choices = ActionChoices.GoStraight; + } + ActionChoices choices; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/125_enum_member_access_accross_contracts.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/125_enum_member_access_accross_contracts.sol new file mode 100644 index 00000000..3bed62d6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/125_enum_member_access_accross_contracts.sol @@ -0,0 +1,10 @@ +contract Interface { + enum MyEnum { One, Two } +} +contract Impl { + function test() public returns (Interface.MyEnum) { + return Interface.MyEnum.One; + } +} +// ---- +// Warning: (72-166): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/126_enum_invalid_member_access.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/126_enum_invalid_member_access.sol new file mode 100644 index 00000000..079bf0c8 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/126_enum_invalid_member_access.sol @@ -0,0 +1,9 @@ +contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + constructor() public { + choices = ActionChoices.RunAroundWavingYourHands; + } + ActionChoices choices; +} +// ---- +// TypeError: (121-159): Member "RunAroundWavingYourHands" not found or not visible after argument-dependent lookup in type(enum test.ActionChoices) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/127_enum_invalid_direct_member_access.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/127_enum_invalid_direct_member_access.sol new file mode 100644 index 00000000..68510a0a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/127_enum_invalid_direct_member_access.sol @@ -0,0 +1,9 @@ +contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + constructor() public { + choices = Sit; + } + ActionChoices choices; +} +// ---- +// DeclarationError: (121-124): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/128_enum_explicit_conversion_is_okay.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/128_enum_explicit_conversion_is_okay.sol new file mode 100644 index 00000000..0948d550 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/128_enum_explicit_conversion_is_okay.sol @@ -0,0 +1,10 @@ +contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + constructor() public { + a = uint256(ActionChoices.GoStraight); + b = uint64(ActionChoices.Sit); + } + uint256 a; + uint64 b; +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/129_int_to_enum_explicit_conversion_is_okay.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/129_int_to_enum_explicit_conversion_is_okay.sol new file mode 100644 index 00000000..2639decf --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/129_int_to_enum_explicit_conversion_is_okay.sol @@ -0,0 +1,10 @@ +contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + constructor() public { + a = 2; + b = ActionChoices(a); + } + uint256 a; + ActionChoices b; +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/130_enum_implicit_conversion_is_not_okay_256.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/130_enum_implicit_conversion_is_not_okay_256.sol new file mode 100644 index 00000000..01c5e93f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/130_enum_implicit_conversion_is_not_okay_256.sol @@ -0,0 +1,9 @@ +contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + constructor() public { + a = ActionChoices.GoStraight; + } + uint256 a; +} +// ---- +// TypeError: (115-139): Type enum test.ActionChoices is not implicitly convertible to expected type uint256. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/131_enum_implicit_conversion_is_not_okay_64.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/131_enum_implicit_conversion_is_not_okay_64.sol new file mode 100644 index 00000000..4e21b9aa --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/131_enum_implicit_conversion_is_not_okay_64.sol @@ -0,0 +1,9 @@ +contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + constructor() public { + b = ActionChoices.Sit; + } + uint64 b; +} +// ---- +// TypeError: (115-132): Type enum test.ActionChoices is not implicitly convertible to expected type uint64. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/132_enum_to_enum_conversion_is_not_okay.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/132_enum_to_enum_conversion_is_not_okay.sol new file mode 100644 index 00000000..5b9ba813 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/132_enum_to_enum_conversion_is_not_okay.sol @@ -0,0 +1,9 @@ +contract test { + enum Paper { Up, Down, Left, Right } + enum Ground { North, South, West, East } + constructor() public { + Ground(Paper.Up); + } +} +// ---- +// TypeError: (137-153): Explicit type conversion not allowed from "enum test.Paper" to "enum test.Ground". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/133_enum_duplicate_values.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/133_enum_duplicate_values.sol new file mode 100644 index 00000000..996a9b78 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/133_enum_duplicate_values.sol @@ -0,0 +1,5 @@ + contract test { + enum ActionChoices { GoLeft, GoRight, GoLeft, Sit } + } +// ---- +// DeclarationError: (66-72): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/134_enum_name_resolution_under_current_contract_name.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/134_enum_name_resolution_under_current_contract_name.sol new file mode 100644 index 00000000..4a16eee1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/134_enum_name_resolution_under_current_contract_name.sol @@ -0,0 +1,12 @@ +contract A { + enum Foo { + First, + Second + } + + function a() public { + A.Foo; + } +} +// ---- +// Warning: (69-111): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/135_private_visibility.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/135_private_visibility.sol new file mode 100644 index 00000000..faafc631 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/135_private_visibility.sol @@ -0,0 +1,8 @@ +contract base { + function f() private {} +} +contract derived is base { + function g() public { f(); } +} +// ---- +// DeclarationError: (99-100): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/136_private_visibility_via_explicit_base_access.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/136_private_visibility_via_explicit_base_access.sol new file mode 100644 index 00000000..fc89c033 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/136_private_visibility_via_explicit_base_access.sol @@ -0,0 +1,8 @@ +contract base { + function f() private {} +} +contract derived is base { + function g() public { base.f(); } +} +// ---- +// TypeError: (99-105): Member "f" not found or not visible after argument-dependent lookup in type(contract base) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/137_external_visibility.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/137_external_visibility.sol new file mode 100644 index 00000000..214ad60a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/137_external_visibility.sol @@ -0,0 +1,6 @@ +contract c { + function f() external {} + function g() public { f(); } +} +// ---- +// DeclarationError: (68-69): Undeclared identifier. "f" is not (or not yet) visible at this point. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/138_similar_name_suggestions_expected.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/138_similar_name_suggestions_expected.sol new file mode 100644 index 00000000..ef6e933a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/138_similar_name_suggestions_expected.sol @@ -0,0 +1,6 @@ +contract c { + function func() public {} + function g() public { fun(); } +} +// ---- +// DeclarationError: (69-72): Undeclared identifier. Did you mean "func"? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/139_no_name_suggestion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/139_no_name_suggestion.sol new file mode 100644 index 00000000..40827dca --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/139_no_name_suggestion.sol @@ -0,0 +1,5 @@ +contract c { + function g() public { fun(); } +} +// ---- +// DeclarationError: (39-42): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/140_multiple_similar_suggestions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/140_multiple_similar_suggestions.sol new file mode 100644 index 00000000..34b4604d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/140_multiple_similar_suggestions.sol @@ -0,0 +1,11 @@ +contract c { + function g() public { + uint var1 = 1; + uint var2 = 1; + uint var3 = 1; + uint var4 = 1; + uint var5 = varx; + } +} +// ---- +// DeclarationError: (151-155): Undeclared identifier. Did you mean "var1", "var2", "var3", "var4" or "var5"? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/141_multiple_scopes_suggestions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/141_multiple_scopes_suggestions.sol new file mode 100644 index 00000000..f9471146 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/141_multiple_scopes_suggestions.sol @@ -0,0 +1,9 @@ +contract c { + uint log9 = 2; + function g() public { + uint log8 = 3; + uint var1 = lgox; + } +} +// ---- +// DeclarationError: (101-105): Undeclared identifier. Did you mean "log8", "log9", "log0", "log1", "log2", "log3" or "log4"? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/142_inheritence_suggestions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/142_inheritence_suggestions.sol new file mode 100644 index 00000000..4231e1bd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/142_inheritence_suggestions.sol @@ -0,0 +1,8 @@ +contract a { function func() public {} } +contract c is a { + function g() public { + uint var1 = fun(); + } +} +// ---- +// DeclarationError: (105-108): Undeclared identifier. Did you mean "func"? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/143_no_spurious_identifier_suggestions_with_submatch.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/143_no_spurious_identifier_suggestions_with_submatch.sol new file mode 100644 index 00000000..db9f07c6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/143_no_spurious_identifier_suggestions_with_submatch.sol @@ -0,0 +1,8 @@ +contract c { + function g() public { + uint va = 1; + uint vb = vaxyz; + } +} +// ---- +// DeclarationError: (78-83): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/144_no_spurious_identifier_suggestions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/144_no_spurious_identifier_suggestions.sol new file mode 100644 index 00000000..2316cb3d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/144_no_spurious_identifier_suggestions.sol @@ -0,0 +1,8 @@ +contract c { + function g() public { + uint va = 1; + uint vb = x; + } +} +// ---- +// DeclarationError: (78-79): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/145_external_base_visibility.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/145_external_base_visibility.sol new file mode 100644 index 00000000..2d1baa20 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/145_external_base_visibility.sol @@ -0,0 +1,8 @@ +contract base { + function f() external {} +} +contract derived is base { + function g() public { base.f(); } +} +// ---- +// TypeError: (100-106): Member "f" not found or not visible after argument-dependent lookup in type(contract base) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/146_external_argument_assign.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/146_external_argument_assign.sol new file mode 100644 index 00000000..d2c0245c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/146_external_argument_assign.sol @@ -0,0 +1,5 @@ +contract c { + function f(uint a) external { a = 1; } +} +// ---- +// TypeError: (47-48): Expression has to be an lvalue. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/147_external_argument_increment.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/147_external_argument_increment.sol new file mode 100644 index 00000000..2bfba42b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/147_external_argument_increment.sol @@ -0,0 +1,5 @@ +contract c { + function f(uint a) external { a++; } +} +// ---- +// TypeError: (47-48): Expression has to be an lvalue. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/148_external_argument_delete.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/148_external_argument_delete.sol new file mode 100644 index 00000000..30eb204e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/148_external_argument_delete.sol @@ -0,0 +1,5 @@ +contract c { + function f(uint a) external { delete a; } +} +// ---- +// TypeError: (54-55): Expression has to be an lvalue. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/149_test_for_bug_override_function_with_bytearray_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/149_test_for_bug_override_function_with_bytearray_type.sol new file mode 100644 index 00000000..871af310 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/149_test_for_bug_override_function_with_bytearray_type.sol @@ -0,0 +1,8 @@ +contract Vehicle { + function f(bytes) external returns (uint256 r) {r = 1;} +} +contract Bike is Vehicle { + function f(bytes) external returns (uint256 r) {r = 42;} +} +// ---- +// Warning: (23-78): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/150_array_with_nonconstant_length.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/150_array_with_nonconstant_length.sol new file mode 100644 index 00000000..49a1851c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/150_array_with_nonconstant_length.sol @@ -0,0 +1,5 @@ +contract c { + function f(uint a) public { uint8[a] x; } +} +// ---- +// TypeError: (51-52): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/151_array_with_negative_length.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/151_array_with_negative_length.sol new file mode 100644 index 00000000..b87160b0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/151_array_with_negative_length.sol @@ -0,0 +1,5 @@ +contract c { + function f(uint a) public { uint8[-1] x; } +} +// ---- +// TypeError: (51-53): Array with negative length specified. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/152_array_copy_with_different_types1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/152_array_copy_with_different_types1.sol new file mode 100644 index 00000000..a0e71847 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/152_array_copy_with_different_types1.sol @@ -0,0 +1,7 @@ +contract c { + bytes a; + uint[] b; + function f() public { b = a; } +} +// ---- +// TypeError: (70-71): Type bytes storage ref is not implicitly convertible to expected type uint256[] storage ref. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/153_array_copy_with_different_types2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/153_array_copy_with_different_types2.sol new file mode 100644 index 00000000..8d1cb1ef --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/153_array_copy_with_different_types2.sol @@ -0,0 +1,7 @@ +contract c { + uint32[] a; + uint8[] b; + function f() public { b = a; } +} +// ---- +// TypeError: (74-75): Type uint32[] storage ref is not implicitly convertible to expected type uint8[] storage ref. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/154_array_copy_with_different_types_conversion_possible.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/154_array_copy_with_different_types_conversion_possible.sol new file mode 100644 index 00000000..b15a9350 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/154_array_copy_with_different_types_conversion_possible.sol @@ -0,0 +1,5 @@ +contract c { + uint32[] a; + uint8[] b; + function f() public { a = b; } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/155_array_copy_with_different_types_static_dynamic.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/155_array_copy_with_different_types_static_dynamic.sol new file mode 100644 index 00000000..025593a5 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/155_array_copy_with_different_types_static_dynamic.sol @@ -0,0 +1,5 @@ +contract c { + uint32[] a; + uint8[80] b; + function f() public { a = b; } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/156_array_copy_with_different_types_dynamic_static.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/156_array_copy_with_different_types_dynamic_static.sol new file mode 100644 index 00000000..90aa53a0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/156_array_copy_with_different_types_dynamic_static.sol @@ -0,0 +1,7 @@ +contract c { + uint[] a; + uint[80] b; + function f() public { b = a; } +} +// ---- +// TypeError: (73-74): Type uint256[] storage ref is not implicitly convertible to expected type uint256[80] storage ref. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/157_array_of_undeclared_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/157_array_of_undeclared_type.sol new file mode 100644 index 00000000..1409db5e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/157_array_of_undeclared_type.sol @@ -0,0 +1,5 @@ +contract c { + a[] public foo; +} +// ---- +// DeclarationError: (17-18): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/158_storage_variable_initialization_with_incorrect_type_int.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/158_storage_variable_initialization_with_incorrect_type_int.sol new file mode 100644 index 00000000..b1ef153e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/158_storage_variable_initialization_with_incorrect_type_int.sol @@ -0,0 +1,5 @@ +contract c { + uint8 a = 1000; +} +// ---- +// TypeError: (27-31): Type int_const 1000 is not implicitly convertible to expected type uint8. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/159_storage_variable_initialization_with_incorrect_type_string.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/159_storage_variable_initialization_with_incorrect_type_string.sol new file mode 100644 index 00000000..75736d98 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/159_storage_variable_initialization_with_incorrect_type_string.sol @@ -0,0 +1,5 @@ +contract c { + uint a = "abc"; +} +// ---- +// TypeError: (26-31): Type literal_string "abc" is not implicitly convertible to expected type uint256. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/160_test_byte_is_alias_of_byte1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/160_test_byte_is_alias_of_byte1.sol new file mode 100644 index 00000000..9977c839 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/160_test_byte_is_alias_of_byte1.sol @@ -0,0 +1,7 @@ +contract c { + bytes arr; + function f() public { byte a = arr[0];} +} +// ---- +// Warning: (54-60): Unused local variable. +// Warning: (32-71): Function state mutability can be restricted to view diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/161_warns_assigning_decimal_to_bytesxx.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/161_warns_assigning_decimal_to_bytesxx.sol new file mode 100644 index 00000000..957322af --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/161_warns_assigning_decimal_to_bytesxx.sol @@ -0,0 +1,5 @@ +contract Foo { + bytes32 a = 7; +} +// ---- +// Warning: (31-32): Decimal literal assigned to bytesXX variable will be left-aligned. Use an explicit conversion to silence this warning. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/162_does_not_warn_assigning_hex_number_to_bytesxx.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/162_does_not_warn_assigning_hex_number_to_bytesxx.sol new file mode 100644 index 00000000..bc32580a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/162_does_not_warn_assigning_hex_number_to_bytesxx.sol @@ -0,0 +1,3 @@ +contract Foo { + bytes32 a = 0x1234; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/163_explicit_conversion_from_decimal_to_bytesxx.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/163_explicit_conversion_from_decimal_to_bytesxx.sol new file mode 100644 index 00000000..af921869 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/163_explicit_conversion_from_decimal_to_bytesxx.sol @@ -0,0 +1,3 @@ +contract Foo { + bytes32 a = bytes32(7); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/164_assigning_value_to_const_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/164_assigning_value_to_const_variable.sol new file mode 100644 index 00000000..4e543e70 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/164_assigning_value_to_const_variable.sol @@ -0,0 +1,6 @@ +contract Foo { + function changeIt() public { x = 9; } + uint constant x = 56; +} +// ---- +// TypeError: (48-49): Cannot assign to a constant variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/165_assigning_state_to_const_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/165_assigning_state_to_const_variable.sol new file mode 100644 index 00000000..0de15dfb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/165_assigning_state_to_const_variable.sol @@ -0,0 +1,5 @@ +contract C { + address constant x = msg.sender; +} +// ---- +// TypeError: (38-48): Initial value for constant variable has to be compile-time constant. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/166_assigning_state_to_const_variable_050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/166_assigning_state_to_const_variable_050.sol new file mode 100644 index 00000000..dc0a6e63 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/166_assigning_state_to_const_variable_050.sol @@ -0,0 +1,7 @@ +pragma experimental "v0.5.0"; + +contract C { + address constant x = msg.sender; +} +// ---- +// TypeError: (69-79): Initial value for constant variable has to be compile-time constant. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/167_constant_string_literal_disallows_assignment.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/167_constant_string_literal_disallows_assignment.sol new file mode 100644 index 00000000..3f19ea3b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/167_constant_string_literal_disallows_assignment.sol @@ -0,0 +1,10 @@ +contract Test { + string constant x = "abefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabca"; + function f() public { + // Even if this is made possible in the future, we should not allow assignment + // to elements of constant arrays. + x[0] = "f"; + } +} +// ---- +// TypeError: (261-265): Index access for string is not possible. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/168_assignment_to_const_var_involving_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/168_assignment_to_const_var_involving_conversion.sol new file mode 100644 index 00000000..fb31e199 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/168_assignment_to_const_var_involving_conversion.sol @@ -0,0 +1,3 @@ +contract C { + C constant x = C(0x123); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/169_assignment_to_const_var_involving_expression.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/169_assignment_to_const_var_involving_expression.sol new file mode 100644 index 00000000..692aad9f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/169_assignment_to_const_var_involving_expression.sol @@ -0,0 +1,3 @@ +contract C { + uint constant x = 0x123 + 0x456; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/170_assignment_to_const_var_involving_keccak.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/170_assignment_to_const_var_involving_keccak.sol new file mode 100644 index 00000000..54f022bb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/170_assignment_to_const_var_involving_keccak.sol @@ -0,0 +1,3 @@ +contract C { + bytes32 constant x = keccak256("abc"); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/171_assignment_to_const_array_vars.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/171_assignment_to_const_array_vars.sol new file mode 100644 index 00000000..b9e9aa7a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/171_assignment_to_const_array_vars.sol @@ -0,0 +1,5 @@ +contract C { + uint[3] constant x = [uint(1), 2, 3]; +} +// ---- +// TypeError: (17-53): Constants of non-value type not yet implemented. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/172_assignment_to_const_string_bytes.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/172_assignment_to_const_string_bytes.sol new file mode 100644 index 00000000..f0e1528c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/172_assignment_to_const_string_bytes.sol @@ -0,0 +1,5 @@ +contract C { + bytes constant a = "\x00\x01\x02"; + bytes constant b = hex"000102"; + string constant c = "hello"; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/173_constant_struct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/173_constant_struct.sol new file mode 100644 index 00000000..07bf0439 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/173_constant_struct.sol @@ -0,0 +1,6 @@ +contract C { + struct S { uint x; uint[] y; } + S constant x = S(5, new uint[](4)); +} +// ---- +// TypeError: (52-86): Constants of non-value type not yet implemented. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/174_address_is_constant.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/174_address_is_constant.sol new file mode 100644 index 00000000..10850e16 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/174_address_is_constant.sol @@ -0,0 +1,3 @@ +contract C { + address constant x = 0x1212121212121212121212121212121212121212; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/175_uninitialized_const_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/175_uninitialized_const_variable.sol new file mode 100644 index 00000000..13496d8b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/175_uninitialized_const_variable.sol @@ -0,0 +1,5 @@ +contract Foo { + uint constant y; +} +// ---- +// TypeError: (19-34): Uninitialized "constant" variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/176_overloaded_function_cannot_resolve.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/176_overloaded_function_cannot_resolve.sol new file mode 100644 index 00000000..bcf25948 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/176_overloaded_function_cannot_resolve.sol @@ -0,0 +1,7 @@ +contract test { + function f() public returns (uint) { return 1; } + function f(uint a) public returns (uint) { return a; } + function g() public returns (uint) { return f(3, 5); } +} +// ---- +// TypeError: (176-177): No matching declaration found after argument-dependent lookup. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/177_ambiguous_overloaded_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/177_ambiguous_overloaded_function.sol new file mode 100644 index 00000000..759e02f2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/177_ambiguous_overloaded_function.sol @@ -0,0 +1,8 @@ +contract test { + function f(uint8 a) public returns (uint) { return a; } + function f(uint a) public returns (uint) { return 2 * a; } + // literal 1 can be both converted to uint and uint8, so the call is ambiguous. + function g() public returns (uint) { return f(1); } +} +// ---- +// TypeError: (271-272): No unique declaration found after argument-dependent lookup. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/178_assignment_of_nonoverloaded_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/178_assignment_of_nonoverloaded_function.sol new file mode 100644 index 00000000..07fc1c43 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/178_assignment_of_nonoverloaded_function.sol @@ -0,0 +1,6 @@ +contract test { + function f(uint a) public returns (uint) { return 2 * a; } + function g() public returns (uint) { function (uint) returns (uint) x = f; return x(7); } +} +// ---- +// Warning: (20-78): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/179_assignment_of_overloaded_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/179_assignment_of_overloaded_function.sol new file mode 100644 index 00000000..9ed864f1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/179_assignment_of_overloaded_function.sol @@ -0,0 +1,7 @@ +contract test { + function f() public returns (uint) { return 1; } + function f(uint a) public returns (uint) { return 2 * a; } + function g() public returns (uint) { function (uint) returns (uint) x = f; return x(7); } +} +// ---- +// TypeError: (208-209): No matching declaration found after variable lookup. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/180_external_types_clash.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/180_external_types_clash.sol new file mode 100644 index 00000000..91ddcd9b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/180_external_types_clash.sol @@ -0,0 +1,9 @@ +contract base { + enum a { X } + function f(a) public { } +} +contract test is base { + function f(uint8 a) public { } +} +// ---- +// TypeError: (37-61): Function overload clash during conversion to external types for arguments. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/181_override_changes_return_types.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/181_override_changes_return_types.sol new file mode 100644 index 00000000..c887f259 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/181_override_changes_return_types.sol @@ -0,0 +1,8 @@ +contract base { + function f(uint a) public returns (uint) { } +} +contract test is base { + function f(uint a) public returns (uint8) { } +} +// ---- +// TypeError: (95-140): Overriding function return types differ. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/182_equal_overload.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/182_equal_overload.sol new file mode 100644 index 00000000..cb9eb3fa --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/182_equal_overload.sol @@ -0,0 +1,7 @@ +contract C { + function test(uint a) public returns (uint b) { } + function test(uint a) external {} +} +// ---- +// DeclarationError: (17-66): Function with same name and arguments defined twice. +// TypeError: (17-66): Overriding function visibility differs. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/185_invalid_utf8_implicit.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/185_invalid_utf8_implicit.sol new file mode 100644 index 00000000..5440b425 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/185_invalid_utf8_implicit.sol @@ -0,0 +1,5 @@ +contract C { + string s = "\xa0\x00"; +} +// ---- +// TypeError: (28-38): Type literal_string (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type string storage ref. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/186_invalid_utf8_explicit.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/186_invalid_utf8_explicit.sol new file mode 100644 index 00000000..401c46e2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/186_invalid_utf8_explicit.sol @@ -0,0 +1,5 @@ +contract C { + string s = string("\xa0\x00"); +} +// ---- +// TypeError: (28-46): Explicit type conversion not allowed from "literal_string (contains invalid UTF-8 sequence at position 0)" to "string storage pointer". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/187_large_utf8_codepoint.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/187_large_utf8_codepoint.sol new file mode 100644 index 00000000..5e406d0c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/187_large_utf8_codepoint.sol @@ -0,0 +1,3 @@ +contract C { + string s = "\xf0\x9f\xa6\x84"; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/188_string_index.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/188_string_index.sol new file mode 100644 index 00000000..9d51e06b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/188_string_index.sol @@ -0,0 +1,6 @@ +contract C { + string s; + function f() public { bytes1 a = s[2]; } +} +// ---- +// TypeError: (64-68): Index access for string is not possible. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/189_string_length.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/189_string_length.sol new file mode 100644 index 00000000..9e714d68 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/189_string_length.sol @@ -0,0 +1,6 @@ +contract C { + string s; + function f() public { uint a = s.length; } +} +// ---- +// TypeError: (62-70): Member "length" not found or not visible after argument-dependent lookup in string storage ref diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/190_negative_integers_to_signed_out_of_bound.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/190_negative_integers_to_signed_out_of_bound.sol new file mode 100644 index 00000000..2e8503af --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/190_negative_integers_to_signed_out_of_bound.sol @@ -0,0 +1,5 @@ +contract test { + int8 public i = -129; +} +// ---- +// TypeError: (36-40): Type int_const -129 is not implicitly convertible to expected type int8. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/191_negative_integers_to_signed_min.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/191_negative_integers_to_signed_min.sol new file mode 100644 index 00000000..211cfee2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/191_negative_integers_to_signed_min.sol @@ -0,0 +1,3 @@ +contract test { + int8 public i = -128; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/192_positive_integers_to_signed_out_of_bound.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/192_positive_integers_to_signed_out_of_bound.sol new file mode 100644 index 00000000..d56045c2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/192_positive_integers_to_signed_out_of_bound.sol @@ -0,0 +1,5 @@ +contract test { + int8 public j = 128; +} +// ---- +// TypeError: (36-39): Type int_const 128 is not implicitly convertible to expected type int8. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/193_positive_integers_to_signed_out_of_bound_max.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/193_positive_integers_to_signed_out_of_bound_max.sol new file mode 100644 index 00000000..66701339 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/193_positive_integers_to_signed_out_of_bound_max.sol @@ -0,0 +1,3 @@ +contract test { + int8 public j = 127; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/194_negative_integers_to_unsigned.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/194_negative_integers_to_unsigned.sol new file mode 100644 index 00000000..3702f09b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/194_negative_integers_to_unsigned.sol @@ -0,0 +1,5 @@ +contract test { + uint8 public x = -1; +} +// ---- +// TypeError: (37-39): Type int_const -1 is not implicitly convertible to expected type uint8. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/195_positive_integers_to_unsigned_out_of_bound.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/195_positive_integers_to_unsigned_out_of_bound.sol new file mode 100644 index 00000000..81216229 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/195_positive_integers_to_unsigned_out_of_bound.sol @@ -0,0 +1,5 @@ +contract test { + uint8 public x = 700; +} +// ---- +// TypeError: (37-40): Type int_const 700 is not implicitly convertible to expected type uint8. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/196_integer_boolean_or.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/196_integer_boolean_or.sol new file mode 100644 index 00000000..db42786d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/196_integer_boolean_or.sol @@ -0,0 +1,3 @@ +contract test { function() external { uint x = 1; uint y = 2; x || y; } } +// ---- +// TypeError: (62-68): Operator || not compatible with types uint256 and uint256 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/197_integer_boolean_and.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/197_integer_boolean_and.sol new file mode 100644 index 00000000..94d1c691 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/197_integer_boolean_and.sol @@ -0,0 +1,3 @@ +contract test { function() external { uint x = 1; uint y = 2; x && y; } } +// ---- +// TypeError: (62-68): Operator && not compatible with types uint256 and uint256 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/198_integer_boolean_not.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/198_integer_boolean_not.sol new file mode 100644 index 00000000..68fe6e94 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/198_integer_boolean_not.sol @@ -0,0 +1,3 @@ +contract test { function() external { uint x = 1; !x; } } +// ---- +// TypeError: (50-52): Unary operator ! cannot be applied to type uint256 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/199_integer_unsigned_exp_signed.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/199_integer_unsigned_exp_signed.sol new file mode 100644 index 00000000..fbeadfb6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/199_integer_unsigned_exp_signed.sol @@ -0,0 +1,3 @@ +contract test { function() external { uint x = 3; int y = -4; x ** y; } } +// ---- +// TypeError: (62-68): Operator ** not compatible with types uint256 and int256 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/200_integer_signed_exp_unsigned.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/200_integer_signed_exp_unsigned.sol new file mode 100644 index 00000000..75e92085 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/200_integer_signed_exp_unsigned.sol @@ -0,0 +1,3 @@ +contract test { function() external { uint x = 3; int y = -4; y ** x; } } +// ---- +// TypeError: (62-68): Operator ** not compatible with types int256 and uint256 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/201_integer_signed_exp_signed.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/201_integer_signed_exp_signed.sol new file mode 100644 index 00000000..93e5f065 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/201_integer_signed_exp_signed.sol @@ -0,0 +1,3 @@ +contract test { function() external { int x = -3; int y = -4; x ** y; } } +// ---- +// TypeError: (62-68): Operator ** not compatible with types int256 and int256 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/202_bytes_reference_compare_operators.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/202_bytes_reference_compare_operators.sol new file mode 100644 index 00000000..711b794c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/202_bytes_reference_compare_operators.sol @@ -0,0 +1,3 @@ +contract test { bytes a; bytes b; function() external { a == b; } } +// ---- +// TypeError: (56-62): Operator == not compatible with types bytes storage ref and bytes storage ref diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/203_struct_reference_compare_operators.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/203_struct_reference_compare_operators.sol new file mode 100644 index 00000000..a74850b3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/203_struct_reference_compare_operators.sol @@ -0,0 +1,10 @@ +contract test { + struct s {uint a;} + s x; + s y; + function() external { + x == y; + } +} +// ---- +// TypeError: (79-85): Operator == not compatible with types struct test.s storage ref and struct test.s storage ref diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/204_overwrite_memory_location_external.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/204_overwrite_memory_location_external.sol new file mode 100644 index 00000000..16d71ca4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/204_overwrite_memory_location_external.sol @@ -0,0 +1,5 @@ +contract C { + function f(uint[] memory a) external {} +} +// ---- +// TypeError: (28-43): Location has to be calldata for external functions (remove the "memory" or "storage" keyword). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/205_overwrite_storage_location_external.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/205_overwrite_storage_location_external.sol new file mode 100644 index 00000000..99c9827d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/205_overwrite_storage_location_external.sol @@ -0,0 +1,5 @@ +contract C { + function f(uint[] storage a) external {} +} +// ---- +// TypeError: (28-44): Location has to be calldata for external functions (remove the "memory" or "storage" keyword). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/206_storage_location_local_variables.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/206_storage_location_local_variables.sol new file mode 100644 index 00000000..868d7bc8 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/206_storage_location_local_variables.sol @@ -0,0 +1,9 @@ +contract C { + uint[] m_x; + function f() public view { + uint[] storage x = m_x; + uint[] memory y; + x;y; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/207_no_mappings_in_memory_array.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/207_no_mappings_in_memory_array.sol new file mode 100644 index 00000000..5220ee22 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/207_no_mappings_in_memory_array.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + mapping(uint=>uint)[] memory x; + } +} +// ---- +// TypeError: (47-77): Type mapping(uint256 => uint256)[] memory is only valid in storage. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/208_assignment_mem_to_local_storage_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/208_assignment_mem_to_local_storage_variable.sol new file mode 100644 index 00000000..cf303772 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/208_assignment_mem_to_local_storage_variable.sol @@ -0,0 +1,9 @@ +contract C { + uint[] data; + function f(uint[] memory x) public { + uint[] storage dataRef = data; + dataRef = x; + } +} +// ---- +// TypeError: (128-129): Type uint256[] memory is not implicitly convertible to expected type uint256[] storage pointer. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/209_storage_assign_to_different_local_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/209_storage_assign_to_different_local_variable.sol new file mode 100644 index 00000000..aabdcd88 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/209_storage_assign_to_different_local_variable.sol @@ -0,0 +1,12 @@ +contract C { + uint[] data; + uint8[] otherData; + function f() public { + uint8[] storage x = otherData; + uint[] storage y = data; + y = x; + // note that data = otherData works + } +} +// ---- +// TypeError: (163-164): Type uint8[] storage pointer is not implicitly convertible to expected type uint256[] storage pointer. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/210_uninitialized_mapping_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/210_uninitialized_mapping_variable.sol new file mode 100644 index 00000000..6b25cdfe --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/210_uninitialized_mapping_variable.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + mapping(uint => uint) x; + x; + } +} +// ---- +// TypeError: (47-70): Uninitialized mapping. Mappings cannot be created dynamically, you have to assign them from a state variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/211_uninitialized_mapping_array_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/211_uninitialized_mapping_array_variable.sol new file mode 100644 index 00000000..edae7549 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/211_uninitialized_mapping_array_variable.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + mapping(uint => uint)[] storage x; + x; + } +} +// ---- +// DeclarationError: (52-85): Uninitialized storage pointer. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/213_no_delete_on_storage_pointers.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/213_no_delete_on_storage_pointers.sol new file mode 100644 index 00000000..7a6fb1c7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/213_no_delete_on_storage_pointers.sol @@ -0,0 +1,9 @@ +contract C { + uint[] data; + function f() public { + uint[] storage x = data; + delete x; + } +} +// ---- +// TypeError: (97-105): Unary operator delete cannot be applied to type uint256[] storage pointer diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/214_assignment_mem_storage_variable_directly.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/214_assignment_mem_storage_variable_directly.sol new file mode 100644 index 00000000..801eb275 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/214_assignment_mem_storage_variable_directly.sol @@ -0,0 +1,6 @@ +contract C { + uint[] data; + function f(uint[] memory x) public { + data = x; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/215_function_argument_mem_to_storage.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/215_function_argument_mem_to_storage.sol new file mode 100644 index 00000000..984b81b1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/215_function_argument_mem_to_storage.sol @@ -0,0 +1,9 @@ +contract C { + function f(uint[] storage x) private { + } + function g(uint[] memory x) public { + f(x); + } +} +// ---- +// TypeError: (113-114): Invalid type for argument in function call. Invalid implicit conversion from uint256[] memory to uint256[] storage pointer requested. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/216_function_argument_storage_to_mem.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/216_function_argument_storage_to_mem.sol new file mode 100644 index 00000000..c5175a41 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/216_function_argument_storage_to_mem.sol @@ -0,0 +1,10 @@ +contract C { + function f(uint[] storage x) private { + g(x); + } + function g(uint[] memory x) public { + } +} +// ---- +// Warning: (91-106): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (80-122): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/217_mem_array_assignment_changes_base_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/217_mem_array_assignment_changes_base_type.sol new file mode 100644 index 00000000..3755b935 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/217_mem_array_assignment_changes_base_type.sol @@ -0,0 +1,10 @@ +contract C { + function f(uint8[] memory x) private { + // Such an assignment is possible in storage, but not in memory + // (because it would incur an otherwise unnecessary copy). + // This requirement might be lifted, though. + uint[] memory y = x; + } +} +// ---- +// TypeError: (256-275): Type uint8[] memory is not implicitly convertible to expected type uint256[] memory. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/219_memory_arrays_not_resizeable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/219_memory_arrays_not_resizeable.sol new file mode 100644 index 00000000..93d8cd42 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/219_memory_arrays_not_resizeable.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + uint[] memory x; + x.length = 2; + } +} +// ---- +// TypeError: (72-80): Expression has to be an lvalue. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/220_struct_constructor.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/220_struct_constructor.sol new file mode 100644 index 00000000..50585c11 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/220_struct_constructor.sol @@ -0,0 +1,9 @@ +contract C { + struct S { uint a; bool x; } + function f() public { + S memory s = S(1, true); + } +} +// ---- +// Warning: (80-90): Unused local variable. +// Warning: (50-110): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/221_struct_constructor_nested.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/221_struct_constructor_nested.sol new file mode 100644 index 00000000..00222682 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/221_struct_constructor_nested.sol @@ -0,0 +1,11 @@ +contract C { + struct X { uint x1; uint x2; } + struct S { uint s1; uint[3] s2; X s3; } + function f() public { + uint[3] memory s2; + S memory s = S(1, s2, X(4, 5)); + } +} +// ---- +// Warning: (153-163): Unused local variable. +// Warning: (96-190): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/222_struct_named_constructor.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/222_struct_named_constructor.sol new file mode 100644 index 00000000..8ab8ee46 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/222_struct_named_constructor.sol @@ -0,0 +1,9 @@ +contract C { + struct S { uint a; bool x; } + function f() public { + S memory s = S({a: 1, x: true}); + } +} +// ---- +// Warning: (80-90): Unused local variable. +// Warning: (50-118): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/223_literal_strings.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/223_literal_strings.sol new file mode 100644 index 00000000..1dadcc4d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/223_literal_strings.sol @@ -0,0 +1,9 @@ +contract Foo { + function f() public { + string memory long = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; + string memory short = "123"; + long; short; + } +} +// ---- +// Warning: (19-238): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/224_string_bytes_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/224_string_bytes_conversion.sol new file mode 100644 index 00000000..7b953abb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/224_string_bytes_conversion.sol @@ -0,0 +1,17 @@ +contract Test { + string s; + bytes b; + function h(string _s) external { bytes(_s).length; } + function i(string memory _s) internal { bytes(_s).length; } + function j() internal { bytes(s).length; } + function k(bytes _b) external { string(_b); } + function l(bytes memory _b) internal { string(_b); } + function m() internal { string(b); } +} +// ---- +// Warning: (47-99): Function state mutability can be restricted to pure +// Warning: (104-163): Function state mutability can be restricted to pure +// Warning: (168-210): Function state mutability can be restricted to view +// Warning: (215-260): Function state mutability can be restricted to pure +// Warning: (265-317): Function state mutability can be restricted to pure +// Warning: (322-358): Function state mutability can be restricted to view diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/225_inheriting_from_library.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/225_inheriting_from_library.sol new file mode 100644 index 00000000..eff7bf86 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/225_inheriting_from_library.sol @@ -0,0 +1,4 @@ +library Lib {} +contract Test is Lib {} +// ---- +// TypeError: (32-35): Libraries cannot be inherited from. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/226_inheriting_library.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/226_inheriting_library.sol new file mode 100644 index 00000000..2d601c1c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/226_inheriting_library.sol @@ -0,0 +1,4 @@ +contract Test {} +library Lib is Test {} +// ---- +// TypeError: (17-39): Library is not allowed to inherit. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/227_library_having_variables.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/227_library_having_variables.sol new file mode 100644 index 00000000..804ef3d3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/227_library_having_variables.sol @@ -0,0 +1,3 @@ +library Lib { uint x; } +// ---- +// TypeError: (14-20): Library cannot have non-constant state variables diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/228_valid_library.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/228_valid_library.sol new file mode 100644 index 00000000..de6b0b3e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/228_valid_library.sol @@ -0,0 +1 @@ +library Lib { uint constant x = 9; } diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/229_call_to_library_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/229_call_to_library_function.sol new file mode 100644 index 00000000..c007d9a1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/229_call_to_library_function.sol @@ -0,0 +1,10 @@ +library Lib { + function min(uint, uint) public returns (uint); +} +contract Test { + function f() public { + uint t = Lib.min(12, 7); + } +} +// ---- +// Warning: (118-124): Unused local variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/230_creating_contract_within_the_contract.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/230_creating_contract_within_the_contract.sol new file mode 100644 index 00000000..8624b0b0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/230_creating_contract_within_the_contract.sol @@ -0,0 +1,5 @@ +contract Test { + function f() public { Test x = new Test(); } +} +// ---- +// TypeError: (51-59): Circular reference for contract creation (cannot create instance of derived or same contract). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/231_array_out_of_bound_access.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/231_array_out_of_bound_access.sol new file mode 100644 index 00000000..7230a0a6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/231_array_out_of_bound_access.sol @@ -0,0 +1,9 @@ +contract c { + uint[2] dataArray; + function set5th() public returns (bool) { + dataArray[5] = 2; + return true; + } +} +// ---- +// TypeError: (90-102): Out of bounds array access. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/232_literal_string_to_storage_pointer.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/232_literal_string_to_storage_pointer.sol new file mode 100644 index 00000000..be57144e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/232_literal_string_to_storage_pointer.sol @@ -0,0 +1,5 @@ +contract C { + function f() public { string storage x = "abc"; } +} +// ---- +// TypeError: (39-63): Type literal_string "abc" is not implicitly convertible to expected type string storage pointer. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/233_non_initialized_references.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/233_non_initialized_references.sol new file mode 100644 index 00000000..a0b6f71e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/233_non_initialized_references.sol @@ -0,0 +1,11 @@ +contract C { + struct s { + uint a; + } + function f() public { + s storage x; + x.a = 2; + } +} +// ---- +// DeclarationError: (84-95): Uninitialized storage pointer. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/235_abi_encode_with_large_integer_constant.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/235_abi_encode_with_large_integer_constant.sol new file mode 100644 index 00000000..fd9717f1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/235_abi_encode_with_large_integer_constant.sol @@ -0,0 +1,5 @@ +contract C { + function f() pure public { abi.encode(2**500); } +} +// ---- +// TypeError: (55-61): Invalid rational number (too large or division by zero). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/236_cyclic_binary_dependency.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/236_cyclic_binary_dependency.sol new file mode 100644 index 00000000..c287507d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/236_cyclic_binary_dependency.sol @@ -0,0 +1,5 @@ +contract A { function f() public { new B(); } } +contract B { function f() public { new C(); } } +contract C { function f() public { new A(); } } +// ---- +// TypeError: (131-136): Circular reference for contract creation (cannot create instance of derived or same contract). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/237_cyclic_binary_dependency_via_inheritance.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/237_cyclic_binary_dependency_via_inheritance.sol new file mode 100644 index 00000000..00ee536e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/237_cyclic_binary_dependency_via_inheritance.sol @@ -0,0 +1,5 @@ +contract A is B { } +contract B { function f() public { new C(); } } +contract C { function f() public { new A(); } } +// ---- +// TypeError: (14-15): Definition of base has to precede definition of derived contract diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/244_tuples.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/244_tuples.sol new file mode 100644 index 00000000..d18c115d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/244_tuples.sol @@ -0,0 +1,10 @@ +contract C { + function f() public pure { + uint a = (1); + (uint b,) = (uint8(1),2); + (uint c, uint d) = (uint32(1), 2 + a); + (uint e, ,) = (uint64(1), 2, b); + a;b;c;d;e; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/245_tuples_empty_components.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/245_tuples_empty_components.sol new file mode 100644 index 00000000..7815edea --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/245_tuples_empty_components.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + (1,,2); + } +} +// ---- +// TypeError: (47-53): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/249_tuple_compound_assignment.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/249_tuple_compound_assignment.sol new file mode 100644 index 00000000..bcdbde02 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/249_tuple_compound_assignment.sol @@ -0,0 +1,7 @@ +contract C { + function f() public returns (uint a, uint b) { + (a, b) += (1, 1); + } +} +// ---- +// TypeError: (72-88): Compound assignment is not allowed for tuple types. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/250_member_access_parser_ambiguity.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/250_member_access_parser_ambiguity.sol new file mode 100644 index 00000000..0ab3c198 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/250_member_access_parser_ambiguity.sol @@ -0,0 +1,16 @@ +contract C { + struct R { uint[10][10] y; } + struct S { uint a; uint b; uint[20][20][20] c; R d; } + S data; + function f() public { + C.S storage x = data; + C.S memory y; + C.S[10] memory z; + C.S[10]; + y.a = 2; + x.c[1][2][3] = 9; + x.d.y[2][2] = 3; + z; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/251_using_for_library.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/251_using_for_library.sol new file mode 100644 index 00000000..c7dcdbcd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/251_using_for_library.sol @@ -0,0 +1,4 @@ +library D { } +contract C { + using D for uint; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/252_using_for_not_library.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/252_using_for_not_library.sol new file mode 100644 index 00000000..4693b27f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/252_using_for_not_library.sol @@ -0,0 +1,6 @@ +contract D { } +contract C { + using D for uint; +} +// ---- +// TypeError: (38-39): Library name expected. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/253_using_for_function_exists.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/253_using_for_function_exists.sol new file mode 100644 index 00000000..9e570805 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/253_using_for_function_exists.sol @@ -0,0 +1,10 @@ +library D { function double(uint self) public returns (uint) { return 2*self; } } +contract C { + using D for uint; + function f(uint a) public { + a.double; + } +} +// ---- +// Warning: (12-79): Function state mutability can be restricted to pure +// Warning: (121-172): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/254_using_for_function_on_int.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/254_using_for_function_on_int.sol new file mode 100644 index 00000000..a8e23d0f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/254_using_for_function_on_int.sol @@ -0,0 +1,9 @@ +library D { function double(uint self) public returns (uint) { return 2*self; } } +contract C { + using D for uint; + function f(uint a) public returns (uint) { + return a.double(); + } +} +// ---- +// Warning: (12-79): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/255_using_for_function_on_struct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/255_using_for_function_on_struct.sol new file mode 100644 index 00000000..2c3deb4c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/255_using_for_function_on_struct.sol @@ -0,0 +1,8 @@ +library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } +contract C { + using D for D.s; + D.s x; + function f(uint a) public returns (uint) { + return x.mul(a); + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/256_using_for_overload.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/256_using_for_overload.sol new file mode 100644 index 00000000..155281f5 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/256_using_for_overload.sol @@ -0,0 +1,14 @@ +library D { + struct s { uint a; } + function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } + function mul(s storage, bytes32) public returns (bytes32) { } +} +contract C { + using D for D.s; + D.s x; + function f(uint a) public returns (uint) { + return x.mul(a); + } +} +// ---- +// Warning: (128-189): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/257_using_for_by_name.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/257_using_for_by_name.sol new file mode 100644 index 00000000..b3eab987 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/257_using_for_by_name.sol @@ -0,0 +1,8 @@ +library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } +contract C { + using D for D.s; + D.s x; + function f(uint a) public returns (uint) { + return x.mul({x: a}); + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/258_using_for_mismatch.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/258_using_for_mismatch.sol new file mode 100644 index 00000000..84e42072 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/258_using_for_mismatch.sol @@ -0,0 +1,9 @@ +library D { function double(bytes32 self) public returns (uint) { return 2; } } +contract C { + using D for uint; + function f(uint a) public returns (uint) { + return a.double(); + } +} +// ---- +// TypeError: (177-185): Member "double" not found or not visible after argument-dependent lookup in uint256 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/259_using_for_not_used.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/259_using_for_not_used.sol new file mode 100644 index 00000000..fae918b7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/259_using_for_not_used.sol @@ -0,0 +1,11 @@ +library D { function double(uint self) public returns (uint) { return 2; } } +contract C { + using D for uint; + function f(uint16 a) public returns (uint) { + // This is an error because the function is only bound to uint. + // Had it been bound to *, it would have worked. + return a.double(); + } +} +// ---- +// TypeError: (305-313): Member "double" not found or not visible after argument-dependent lookup in uint16 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/260_library_memory_struct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/260_library_memory_struct.sol new file mode 100644 index 00000000..20d8afa5 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/260_library_memory_struct.sol @@ -0,0 +1,8 @@ +pragma experimental ABIEncoderV2; +library c { + struct S { uint x; } + function f() public returns (S memory) {} +} +// ---- +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. +// Warning: (75-116): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/261_using_for_arbitrary_mismatch.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/261_using_for_arbitrary_mismatch.sol new file mode 100644 index 00000000..ced4705f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/261_using_for_arbitrary_mismatch.sol @@ -0,0 +1,10 @@ +library D { function double(bytes32 self) public returns (uint) { return 2; } } +contract C { + using D for *; + function f(uint a) public returns (uint) { + // Bound to a, but self type does not match. + return a.double(); + } +} +// ---- +// TypeError: (227-235): Member "double" not found or not visible after argument-dependent lookup in uint256 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/262_bound_function_in_var.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/262_bound_function_in_var.sol new file mode 100644 index 00000000..c3cc5232 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/262_bound_function_in_var.sol @@ -0,0 +1,13 @@ +library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } } +contract C { + using D for D.s; + D.s x; + function f(uint a) public returns (uint) { + function (D.s storage, uint) returns (uint) g = x.mul; + g(x, a); + g(a); + } +} +// ---- +// TypeError: (218-271): Type function (struct D.s storage pointer,uint256) returns (uint256) is not implicitly convertible to expected type function (struct D.s storage pointer,uint256) returns (uint256). +// TypeError: (298-302): Wrong argument count for function call: 1 arguments given but expected 2. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/263_create_memory_arrays.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/263_create_memory_arrays.sol new file mode 100644 index 00000000..71f43992 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/263_create_memory_arrays.sol @@ -0,0 +1,14 @@ +library L { + struct R { uint[10][10] y; } + struct S { uint a; uint b; uint[20][20][20] c; R d; } +} +contract C { + function f(uint size) public { + L.S[][] memory x = new L.S[][](10); + uint[] memory y = new uint[](20); + bytes memory z = new bytes(size); + x;y;z; + } +} +// ---- +// Warning: (122-301): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/264_mapping_in_memory_array.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/264_mapping_in_memory_array.sol new file mode 100644 index 00000000..f0bb557b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/264_mapping_in_memory_array.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint size) public { + mapping(uint => uint) x = new mapping(uint => uint)[](4); + } +} +// ---- +// TypeError: (86-109): Type cannot live outside storage. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/265_new_for_non_array.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/265_new_for_non_array.sol new file mode 100644 index 00000000..c4b2c692 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/265_new_for_non_array.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint size) public { + uint x = new uint(7); + } +} +// ---- +// TypeError: (65-73): Contract or array type expected. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/266_invalid_args_creating_memory_array.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/266_invalid_args_creating_memory_array.sol new file mode 100644 index 00000000..078255e3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/266_invalid_args_creating_memory_array.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint size) public { + uint[] memory x = new uint[](); + } +} +// ---- +// TypeError: (74-86): Wrong argument count for function call: 0 arguments given but expected 1. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/267_invalid_args_creating_struct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/267_invalid_args_creating_struct.sol new file mode 100644 index 00000000..35671e6f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/267_invalid_args_creating_struct.sol @@ -0,0 +1,9 @@ +contract C { + struct S { uint a; uint b; } + + function f() public { + S memory s = S({a: 1}); + } +} +// ---- +// TypeError: (94-103): Wrong argument count for struct constructor: 1 arguments given but expected 2. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/268_function_overload_array_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/268_function_overload_array_type.sol new file mode 100644 index 00000000..4fc9d46e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/268_function_overload_array_type.sol @@ -0,0 +1,4 @@ +contract M { + function f(uint[] memory) public; + function f(int[] memory) public; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/269_inline_array_declaration_and_passing_implicit_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/269_inline_array_declaration_and_passing_implicit_conversion.sol new file mode 100644 index 00000000..023404f7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/269_inline_array_declaration_and_passing_implicit_conversion.sol @@ -0,0 +1,11 @@ + contract C { + function f() public returns (uint) { + uint8 x = 7; + uint16 y = 8; + uint32 z = 9; + uint32[3] memory ending = [x, y, z]; + return (ending[1]); + } + } +// ---- +// Warning: (25-229): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/270_inline_array_declaration_and_passing_implicit_conversion_strings.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/270_inline_array_declaration_and_passing_implicit_conversion_strings.sol new file mode 100644 index 00000000..025244d3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/270_inline_array_declaration_and_passing_implicit_conversion_strings.sol @@ -0,0 +1,10 @@ +contract C { + function f() public returns (string memory) { + string memory x = "Hello"; + string memory y = "World"; + string[2] memory z = [x, y]; + return (z[0]); + } +} +// ---- +// Warning: (17-198): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/271_inline_array_declaration_const_int_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/271_inline_array_declaration_const_int_conversion.sol new file mode 100644 index 00000000..e7036bdf --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/271_inline_array_declaration_const_int_conversion.sol @@ -0,0 +1,8 @@ +contract C { + function f() public returns (uint) { + uint8[4] memory z = [1,2,3,5]; + return (z[0]); + } +} +// ---- +// Warning: (17-121): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/272_inline_array_declaration_const_string_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/272_inline_array_declaration_const_string_conversion.sol new file mode 100644 index 00000000..4e92f6e1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/272_inline_array_declaration_const_string_conversion.sol @@ -0,0 +1,8 @@ +contract C { + function f() public returns (string memory) { + string[2] memory z = ["Hello", "World"]; + return (z[0]); + } +} +// ---- +// Warning: (17-140): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/273_inline_array_declaration_no_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/273_inline_array_declaration_no_type.sol new file mode 100644 index 00000000..4d3e6aed --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/273_inline_array_declaration_no_type.sol @@ -0,0 +1,7 @@ +contract C { + function f() public returns (uint) { + return ([4,5,6][1]); + } +} +// ---- +// Warning: (17-88): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/274_inline_array_declaration_no_type_strings.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/274_inline_array_declaration_no_type_strings.sol new file mode 100644 index 00000000..6d36942d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/274_inline_array_declaration_no_type_strings.sol @@ -0,0 +1,7 @@ +contract C { + function f() public returns (string memory) { + return (["foo", "man", "choo"][1]); + } +} +// ---- +// Warning: (17-112): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/275_inline_struct_declaration_arrays.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/275_inline_struct_declaration_arrays.sol new file mode 100644 index 00000000..bdf033a3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/275_inline_struct_declaration_arrays.sol @@ -0,0 +1,12 @@ +contract C { + struct S { + uint a; + string b; + } + function f() public { + S[2] memory x = [S({a: 1, b: "fish"}), S({a: 2, b: "fish"})]; + } +} +// ---- +// Warning: (102-115): Unused local variable. +// Warning: (72-169): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/276_invalid_types_in_inline_array.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/276_invalid_types_in_inline_array.sol new file mode 100644 index 00000000..03d7266a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/276_invalid_types_in_inline_array.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + uint[3] memory x = [45, 'foo', true]; + } +} +// ---- +// TypeError: (66-83): Unable to deduce common type for array elements. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/277_dynamic_inline_array.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/277_dynamic_inline_array.sol new file mode 100644 index 00000000..e613758b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/277_dynamic_inline_array.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + uint8[4][4] memory dyn = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]; + } +} +// ---- +// Warning: (47-69): Unused local variable. +// Warning: (17-135): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/278_lvalues_as_inline_array.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/278_lvalues_as_inline_array.sol new file mode 100644 index 00000000..5a39f550 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/278_lvalues_as_inline_array.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + [1, 2, 3]++; + [1, 2, 3] = [4, 5, 6]; + } +} +// ---- +// TypeError: (47-56): Inline array type cannot be declared as LValue. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/279_break_not_in_loop.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/279_break_not_in_loop.sol new file mode 100644 index 00000000..6b88da44 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/279_break_not_in_loop.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + if (true) + break; + } +} +// ---- +// SyntaxError: (69-74): "break" has to be in a "for" or "while" loop. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/280_continue_not_in_loop.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/280_continue_not_in_loop.sol new file mode 100644 index 00000000..b0e8cda9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/280_continue_not_in_loop.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + if (true) + continue; + } +} +// ---- +// SyntaxError: (69-77): "continue" has to be in a "for" or "while" loop. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/281_continue_not_in_loop_2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/281_continue_not_in_loop_2.sol new file mode 100644 index 00000000..845faf86 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/281_continue_not_in_loop_2.sol @@ -0,0 +1,10 @@ +contract C { + function f() public { + while (true) + { + } + continue; + } +} +// ---- +// SyntaxError: (88-96): "continue" has to be in a "for" or "while" loop. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/282_invalid_different_types_for_conditional_expression.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/282_invalid_different_types_for_conditional_expression.sol new file mode 100644 index 00000000..e4e75e3f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/282_invalid_different_types_for_conditional_expression.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + true ? true : 2; + } +} +// ---- +// TypeError: (47-62): True expression's type bool doesn't match false expression's type uint8. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/283_left_value_in_conditional_expression_not_supported_yet.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/283_left_value_in_conditional_expression_not_supported_yet.sol new file mode 100644 index 00000000..ef8f9930 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/283_left_value_in_conditional_expression_not_supported_yet.sol @@ -0,0 +1,10 @@ +contract C { + function f() public { + uint x; + uint y; + (true ? x : y) = 1; + } +} +// ---- +// TypeError: (80-92): Conditional expression as left value is not supported yet. +// TypeError: (80-92): Expression has to be an lvalue. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/284_conditional_expression_with_different_struct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/284_conditional_expression_with_different_struct.sol new file mode 100644 index 00000000..049d9e21 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/284_conditional_expression_with_different_struct.sol @@ -0,0 +1,15 @@ +contract C { + struct s1 { + uint x; + } + struct s2 { + uint x; + } + function f() public { + s1 memory x; + s2 memory y; + true ? x : y; + } +} +// ---- +// TypeError: (165-177): True expression's type struct C.s1 memory doesn't match false expression's type struct C.s2 memory. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/285_conditional_expression_with_different_function_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/285_conditional_expression_with_different_function_type.sol new file mode 100644 index 00000000..963fb7da --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/285_conditional_expression_with_different_function_type.sol @@ -0,0 +1,10 @@ +contract C { + function x(bool) public {} + function y() public {} + + function f() public { + true ? x : y; + } +} +// ---- +// TypeError: (106-118): True expression's type function (bool) doesn't match false expression's type function (). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/286_conditional_expression_with_different_enum.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/286_conditional_expression_with_different_enum.sol new file mode 100644 index 00000000..8c312624 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/286_conditional_expression_with_different_enum.sol @@ -0,0 +1,13 @@ +contract C { + enum small { A, B, C, D } + enum big { A, B, C, D } + + function f() public { + small x; + big y; + + true ? x : y; + } +} +// ---- +// TypeError: (139-151): True expression's type enum C.small doesn't match false expression's type enum C.big. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/287_conditional_expression_with_different_mapping.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/287_conditional_expression_with_different_mapping.sol new file mode 100644 index 00000000..8139f3ed --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/287_conditional_expression_with_different_mapping.sol @@ -0,0 +1,10 @@ +contract C { + mapping(uint8 => uint8) table1; + mapping(uint32 => uint8) table2; + + function f() public { + true ? table1 : table2; + } +} +// ---- +// TypeError: (121-143): True expression's type mapping(uint8 => uint8) doesn't match false expression's type mapping(uint32 => uint8). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/288_conditional_with_all_types.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/288_conditional_with_all_types.sol new file mode 100644 index 00000000..41e72d60 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/288_conditional_with_all_types.sol @@ -0,0 +1,91 @@ +contract C { + struct s1 { + uint x; + } + s1 struct_x; + s1 struct_y; + + function fun_x() public {} + function fun_y() public {} + + enum small { A, B, C, D } + + mapping(uint8 => uint8) table1; + mapping(uint8 => uint8) table2; + + function f() public { + // integers + uint x; + uint y; + uint g = true ? x : y; + g += 1; // Avoid unused var warning + + // integer constants + uint h = true ? 1 : 3; + h += 1; // Avoid unused var warning + + // string literal + string memory i = true ? "hello" : "world"; + i = "used"; //Avoid unused var warning + } + function f2() public { + // bool + bool j = true ? true : false; + j = j && true; // Avoid unused var warning + + // real is not there yet. + + // array + byte[2] memory a; + byte[2] memory b; + byte[2] memory k = true ? a : b; + k[0] = byte(0); //Avoid unused var warning + + bytes memory e; + bytes memory f; + bytes memory l = true ? e : f; + l[0] = byte(0); // Avoid unused var warning + + // fixed bytes + bytes2 c; + bytes2 d; + bytes2 m = true ? c : d; + m &= m; + + } + function f3() public { + // contract doesn't fit in here + + // struct + struct_x = true ? struct_x : struct_y; + + // function + function () r = true ? fun_x : fun_y; + r(); // Avoid unused var warning + // enum + small enum_x; + small enum_y; + enum_x = true ? enum_x : enum_y; + + // tuple + (uint n, uint o) = true ? (1, 2) : (3, 4); + (n, o) = (o, n); // Avoid unused var warning + // mapping + mapping(uint8 => uint8) p = true ? table1 : table2; + p[0] = 0; // Avoid unused var warning + // typetype + uint32 q = true ? uint32(1) : uint32(2); + q += 1; // Avoid unused var warning + // modifier doesn't fit in here + + // magic doesn't fit in here + + // module doesn't fit in here + } +} +// ---- +// Warning: (1005-1019): This declaration shadows an existing declaration. +// Warning: (90-116): Function state mutability can be restricted to pure +// Warning: (121-147): Function state mutability can be restricted to pure +// Warning: (257-642): Function state mutability can be restricted to pure +// Warning: (647-1227): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/289_uint7_and_uintM_as_identifier.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/289_uint7_and_uintM_as_identifier.sol new file mode 100644 index 00000000..58e84090 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/289_uint7_and_uintM_as_identifier.sol @@ -0,0 +1,12 @@ +contract test { +string uintM = "Hello 4 you"; + function f() public { + uint8 uint7 = 3; + uint7 = 5; + string memory intM; + uint bytesM = 21; + intM; bytesM; + } +} +// ---- +// Warning: (50-197): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword.sol new file mode 100644 index 00000000..1b6bbae7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/290_varM_disqualified_as_keyword.sol @@ -0,0 +1,11 @@ +contract test { + function f() public { + uintM something = 3; + intM should = 4; + bytesM fail = "now"; + } +} +// ---- +// DeclarationError: (50-55): Identifier not found or not unique. +// DeclarationError: (79-83): Identifier not found or not unique. +// DeclarationError: (104-110): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/291_modifier_is_not_a_valid_typename.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/291_modifier_is_not_a_valid_typename.sol new file mode 100644 index 00000000..2f3143d5 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/291_modifier_is_not_a_valid_typename.sol @@ -0,0 +1,9 @@ +contract test { + modifier mod() { _; } + + function f() public { + mod g; + } +} +// ---- +// TypeError: (77-80): Name has to refer to a struct, enum or contract. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/292_modifier_is_not_a_valid_typename_is_not_fatal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/292_modifier_is_not_a_valid_typename_is_not_fatal.sol new file mode 100644 index 00000000..9187c19d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/292_modifier_is_not_a_valid_typename_is_not_fatal.sol @@ -0,0 +1,10 @@ +contract test { + modifier mod() { _; } + + function f() public { + mod g; + g = f; + } +} +// ---- +// TypeError: (77-80): Name has to refer to a struct, enum or contract. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/293_function_is_not_a_valid_typename.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/293_function_is_not_a_valid_typename.sol new file mode 100644 index 00000000..390eccd9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/293_function_is_not_a_valid_typename.sol @@ -0,0 +1,10 @@ +contract test { + function foo() public { + } + + function f() public { + foo g; + } +} +// ---- +// TypeError: (85-88): Name has to refer to a struct, enum or contract. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/294_long_uint_variable_fails.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/294_long_uint_variable_fails.sol new file mode 100644 index 00000000..1e608320 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/294_long_uint_variable_fails.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + uint99999999999999999999999999 something = 3; + } +} +// ---- +// DeclarationError: (50-80): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/295_bytes10abc_is_identifier.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/295_bytes10abc_is_identifier.sol new file mode 100644 index 00000000..8b65fc65 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/295_bytes10abc_is_identifier.sol @@ -0,0 +1,8 @@ +contract test { + function f() public { + bytes32 bytes10abc = "abc"; + } +} +// ---- +// Warning: (50-68): Unused local variable. +// Warning: (20-83): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/296_int10abc_is_identifier.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/296_int10abc_is_identifier.sol new file mode 100644 index 00000000..2678cfb9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/296_int10abc_is_identifier.sol @@ -0,0 +1,9 @@ +contract test { + function f() public { + uint uint10abc = 3; + int int10abc = 4; + uint10abc; int10abc; + } +} +// ---- +// Warning: (20-130): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/297_library_functions_do_not_have_value.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/297_library_functions_do_not_have_value.sol new file mode 100644 index 00000000..918544cc --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/297_library_functions_do_not_have_value.sol @@ -0,0 +1,8 @@ +library L { function l() public {} } +contract test { + function f() public { + L.l.value; + } +} +// ---- +// TypeError: (87-96): Member "value" not found or not visible after argument-dependent lookup in function () - did you forget the "payable" modifier? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/298_invalid_fixed_types_0x7_mxn.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/298_invalid_fixed_types_0x7_mxn.sol new file mode 100644 index 00000000..ea9e5d0f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/298_invalid_fixed_types_0x7_mxn.sol @@ -0,0 +1,5 @@ +contract test { + fixed0x7 a = .3; +} +// ---- +// DeclarationError: (20-28): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/299_invalid_fixed_types_long_invalid_identifier.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/299_invalid_fixed_types_long_invalid_identifier.sol new file mode 100644 index 00000000..9ce2b106 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/299_invalid_fixed_types_long_invalid_identifier.sol @@ -0,0 +1,5 @@ +contract test { + fixed99999999999999999999999999999999999999x7 b = 9.5; +} +// ---- +// DeclarationError: (20-65): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/300_invalid_fixed_types_7x8_mxn.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/300_invalid_fixed_types_7x8_mxn.sol new file mode 100644 index 00000000..7c511d2f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/300_invalid_fixed_types_7x8_mxn.sol @@ -0,0 +1,5 @@ +contract test { + fixed7x8 c = 3.12345678; +} +// ---- +// DeclarationError: (20-28): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/301_library_instances_cannot_be_used.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/301_library_instances_cannot_be_used.sol new file mode 100644 index 00000000..82e4a0d1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/301_library_instances_cannot_be_used.sol @@ -0,0 +1,9 @@ +library L { function l() public {} } +contract test { + function f() public { + L x; + x.l(); + } +} +// ---- +// TypeError: (100-103): Member "l" not found or not visible after argument-dependent lookup in library L diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/302_invalid_fixed_type_long.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/302_invalid_fixed_type_long.sol new file mode 100644 index 00000000..12679631 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/302_invalid_fixed_type_long.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + fixed8x888888888888888888888888888888888888888888888888888 b; + } +} +// ---- +// DeclarationError: (50-108): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/303_fixed_type_int_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/303_fixed_type_int_conversion.sol new file mode 100644 index 00000000..ddf1e5fb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/303_fixed_type_int_conversion.sol @@ -0,0 +1,11 @@ +contract test { + function f() public { + uint64 a = 3; + int64 b = 4; + fixed c = b; + ufixed d = a; + c; d; + } +} +// ---- +// Warning: (20-147): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/304_fixed_type_rational_int_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/304_fixed_type_rational_int_conversion.sol new file mode 100644 index 00000000..16d2cbad --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/304_fixed_type_rational_int_conversion.sol @@ -0,0 +1,9 @@ +contract test { + function f() public { + fixed c = 3; + ufixed d = 4; + c; d; + } +} +// ---- +// Warning: (20-104): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/305_fixed_type_rational_fraction_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/305_fixed_type_rational_fraction_conversion.sol new file mode 100644 index 00000000..27029860 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/305_fixed_type_rational_fraction_conversion.sol @@ -0,0 +1,9 @@ +contract test { + function f() public { + fixed a = 4.5; + ufixed d = 2.5; + a; d; + } +} +// ---- +// Warning: (20-108): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/306_invalid_int_implicit_conversion_from_fixed.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/306_invalid_int_implicit_conversion_from_fixed.sol new file mode 100644 index 00000000..c0a56314 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/306_invalid_int_implicit_conversion_from_fixed.sol @@ -0,0 +1,9 @@ +contract test { + function f() public { + fixed a = 4.5; + int b = a; + a; b; + } +} +// ---- +// TypeError: (73-82): Type fixed128x18 is not implicitly convertible to expected type int256. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/307_rational_unary_minus_operation.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/307_rational_unary_minus_operation.sol new file mode 100644 index 00000000..7827e57b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/307_rational_unary_minus_operation.sol @@ -0,0 +1,7 @@ +contract test { + function f() pure public { + ufixed16x2 a = 3.25; + fixed16x2 b = -3.25; + a; b; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/308_rational_unary_plus_operation.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/308_rational_unary_plus_operation.sol new file mode 100644 index 00000000..f635a214 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/308_rational_unary_plus_operation.sol @@ -0,0 +1,9 @@ +contract test { + function f() pure public { + ufixed16x2 a = +3.25; + fixed16x2 b = -3.25; + a; b; + } +} +// ---- +// SyntaxError: (70-75): Use of unary + is disallowed. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/312_leading_zero_rationals_convert.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/312_leading_zero_rationals_convert.sol new file mode 100644 index 00000000..9fe7c6f7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/312_leading_zero_rationals_convert.sol @@ -0,0 +1,9 @@ +contract A { + function f() pure public { + ufixed16x2 a = 0.5; + ufixed256x52 b = 0.0000000000000006661338147750939242541790008544921875; + fixed16x2 c = -0.5; + fixed256x52 d = -0.0000000000000006661338147750939242541790008544921875; + a; b; c; d; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/313_fixed_type_size_capabilities.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/313_fixed_type_size_capabilities.sol new file mode 100644 index 00000000..441cf81e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/313_fixed_type_size_capabilities.sol @@ -0,0 +1,13 @@ +contract test { + function f() public { + ufixed256x1 a = 123456781234567979695948382928485849359686494864095409282048094275023098123.5; + ufixed256x77 b = 0.920890746623327805482905058466021565416131529487595827354393978494366605267637; + ufixed224x78 c = 0.000000000001519884736399797998492268541131529487595827354393978494366605267646; + fixed256x1 d = -123456781234567979695948382928485849359686494864095409282048094275023098123.5; + fixed256x76 e = -0.93322335481643744342575580035176794825198893968114429702091846411734101080123; + fixed256x79 g = -0.0001178860664374434257558003517679482519889396811442970209184641173410108012309; + a; b; c; d; e; g; + } +} +// ---- +// Warning: (20-707): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/314_fixed_type_zero_handling.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/314_fixed_type_zero_handling.sol new file mode 100644 index 00000000..5f0d2909 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/314_fixed_type_zero_handling.sol @@ -0,0 +1,8 @@ +contract test { + function f() public { + fixed16x2 a = 0; a; + ufixed32x1 b = 0; b; + } +} +// ---- +// Warning: (20-104): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/315_fixed_type_invalid_implicit_conversion_size.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/315_fixed_type_invalid_implicit_conversion_size.sol new file mode 100644 index 00000000..79698228 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/315_fixed_type_invalid_implicit_conversion_size.sol @@ -0,0 +1,8 @@ +contract test { + function f() public { + ufixed a = 11/4; + ufixed248x8 b = a; b; + } +} +// ---- +// TypeError: (75-92): Type ufixed128x18 is not implicitly convertible to expected type ufixed248x8. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/316_fixed_type_invalid_implicit_conversion_lost_data.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/316_fixed_type_invalid_implicit_conversion_lost_data.sol new file mode 100644 index 00000000..76c0284e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/316_fixed_type_invalid_implicit_conversion_lost_data.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + ufixed256x1 a = 1/3; a; + } +} +// ---- +// TypeError: (50-69): Type rational_const 1 / 3 is not implicitly convertible to expected type ufixed256x1. Try converting to type ufixed256x77 or use an explicit conversion. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/317_fixed_type_valid_explicit_conversions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/317_fixed_type_valid_explicit_conversions.sol new file mode 100644 index 00000000..38801457 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/317_fixed_type_valid_explicit_conversions.sol @@ -0,0 +1,9 @@ +contract test { + function f() public { + ufixed256x80 a = ufixed256x80(1/3); a; + ufixed248x80 b = ufixed248x80(1/3); b; + ufixed8x1 c = ufixed8x1(1/3); c; + } +} +// ---- +// Warning: (20-182): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/318_invalid_array_declaration_with_rational.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/318_invalid_array_declaration_with_rational.sol new file mode 100644 index 00000000..3dd779ec --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/318_invalid_array_declaration_with_rational.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + uint[3.5] a; a; + } +} +// ---- +// TypeError: (55-58): Array with fractional length specified. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/319_invalid_array_declaration_with_signed_fixed_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/319_invalid_array_declaration_with_signed_fixed_type.sol new file mode 100644 index 00000000..83f0950d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/319_invalid_array_declaration_with_signed_fixed_type.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + uint[fixed(3.5)] a; a; + } +} +// ---- +// TypeError: (55-65): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/320_invalid_array_declaration_with_unsigned_fixed_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/320_invalid_array_declaration_with_unsigned_fixed_type.sol new file mode 100644 index 00000000..26d5a85e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/320_invalid_array_declaration_with_unsigned_fixed_type.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + uint[ufixed(3.5)] a; a; + } +} +// ---- +// TypeError: (55-66): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/321_rational_to_bytes_implicit_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/321_rational_to_bytes_implicit_conversion.sol new file mode 100644 index 00000000..d209eb76 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/321_rational_to_bytes_implicit_conversion.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + bytes32 c = 3.2; c; + } +} +// ---- +// TypeError: (50-65): Type rational_const 16 / 5 is not implicitly convertible to expected type bytes32. Try converting to type ufixed8x1 or use an explicit conversion. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/322_fixed_to_bytes_implicit_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/322_fixed_to_bytes_implicit_conversion.sol new file mode 100644 index 00000000..86736481 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/322_fixed_to_bytes_implicit_conversion.sol @@ -0,0 +1,8 @@ +contract test { + function f() public { + fixed a = 3.25; + bytes32 c = a; c; + } +} +// ---- +// TypeError: (74-87): Type fixed128x18 is not implicitly convertible to expected type bytes32. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/323_mapping_with_fixed_literal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/323_mapping_with_fixed_literal.sol new file mode 100644 index 00000000..8e28d4e1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/323_mapping_with_fixed_literal.sol @@ -0,0 +1,6 @@ +contract test { + mapping(ufixed8x1 => string) fixedString; + function f() public { + fixedString[0.5] = "Half"; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/324_fixed_points_inside_structs.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/324_fixed_points_inside_structs.sol new file mode 100644 index 00000000..8aa0abc2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/324_fixed_points_inside_structs.sol @@ -0,0 +1,7 @@ +contract test { + struct myStruct { + ufixed a; + int b; + } + myStruct a = myStruct(3.125, 3); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/325_inline_array_fixed_types.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/325_inline_array_fixed_types.sol new file mode 100644 index 00000000..c46297c3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/325_inline_array_fixed_types.sol @@ -0,0 +1,8 @@ +contract test { + function f() public { + fixed[3] memory a = [fixed(3.5), fixed(-4.25), fixed(967.125)]; + } +} +// ---- +// Warning: (50-67): Unused local variable. +// Warning: (20-119): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/326_inline_array_rationals.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/326_inline_array_rationals.sol new file mode 100644 index 00000000..bdc3c2c1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/326_inline_array_rationals.sol @@ -0,0 +1,8 @@ +contract test { + function f() public { + ufixed128x3[4] memory a = [ufixed128x3(3.5), 4.125, 2.5, 4.0]; + } +} +// ---- +// Warning: (50-73): Unused local variable. +// Warning: (20-118): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/327_rational_index_access.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/327_rational_index_access.sol new file mode 100644 index 00000000..46e58521 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/327_rational_index_access.sol @@ -0,0 +1,8 @@ +contract test { + function f() public { + uint[] memory a; + a[.5]; + } +} +// ---- +// TypeError: (77-79): Type rational_const 1 / 2 is not implicitly convertible to expected type uint256. Try converting to type ufixed8x1 or use an explicit conversion. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/328_rational_to_fixed_literal_expression.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/328_rational_to_fixed_literal_expression.sol new file mode 100644 index 00000000..35456fa6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/328_rational_to_fixed_literal_expression.sol @@ -0,0 +1,15 @@ +contract test { + function f() public { + ufixed64x8 a = 3.5 * 3; + ufixed64x8 b = 4 - 2.5; + ufixed64x8 c = 11 / 4; + ufixed240x5 d = 599 + 0.21875; + ufixed256x80 e = ufixed256x80(35.245 % 12.9); + ufixed256x80 f = ufixed256x80(1.2 % 2); + fixed g = 2 ** -2; + a; b; c; d; e; f; g; + } +} +// ---- +// Warning: (238-252): This declaration shadows an existing declaration. +// Warning: (20-339): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/329_rational_as_exponent_value_signed.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/329_rational_as_exponent_value_signed.sol new file mode 100644 index 00000000..b835e309 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/329_rational_as_exponent_value_signed.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + fixed g = 2 ** -2.2; + } +} +// ---- +// TypeError: (60-69): Operator ** not compatible with types int_const 2 and rational_const -11 / 5 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/330_rational_as_exponent_value_unsigned.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/330_rational_as_exponent_value_unsigned.sol new file mode 100644 index 00000000..04ddf0fd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/330_rational_as_exponent_value_unsigned.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + ufixed b = 3 ** 2.5; + } +} +// ---- +// TypeError: (61-69): Operator ** not compatible with types int_const 3 and rational_const 5 / 2 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/331_rational_as_exponent_half.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/331_rational_as_exponent_half.sol new file mode 100644 index 00000000..4e0894c5 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/331_rational_as_exponent_half.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + 2 ** (1/2); + } +} +// ---- +// TypeError: (50-60): Operator ** not compatible with types int_const 2 and rational_const 1 / 2 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/332_rational_as_exponent_value_neg_quarter.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/332_rational_as_exponent_value_neg_quarter.sol new file mode 100644 index 00000000..bc127bf5 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/332_rational_as_exponent_value_neg_quarter.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + 42 ** (-1/4); + } +} +// ---- +// TypeError: (50-62): Operator ** not compatible with types int_const 42 and rational_const -1 / 4 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/333_fixed_point_casting_exponents_15.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/333_fixed_point_casting_exponents_15.sol new file mode 100644 index 00000000..0fd5f331 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/333_fixed_point_casting_exponents_15.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + ufixed a = 3 ** ufixed(1.5); + } +} +// ---- +// TypeError: (61-77): Operator ** not compatible with types int_const 3 and ufixed128x18 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/334_fixed_point_casting_exponents_neg.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/334_fixed_point_casting_exponents_neg.sol new file mode 100644 index 00000000..03d10f7c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/334_fixed_point_casting_exponents_neg.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + ufixed c = 42 ** fixed(-1/4); + } +} +// ---- +// TypeError: (61-78): Operator ** not compatible with types int_const 42 and fixed128x18 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/338_rational_bitnot_unary_operation.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/338_rational_bitnot_unary_operation.sol new file mode 100644 index 00000000..44a6ab5e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/338_rational_bitnot_unary_operation.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + ~fixed(3.5); + } +} +// ---- +// TypeError: (50-61): Unary operator ~ cannot be applied to type fixed128x18 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/339_rational_bitor_binary_operation.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/339_rational_bitor_binary_operation.sol new file mode 100644 index 00000000..29871b04 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/339_rational_bitor_binary_operation.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + fixed(1.5) | 3; + } +} +// ---- +// TypeError: (50-64): Operator | not compatible with types fixed128x18 and int_const 3 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/340_rational_bitxor_binary_operation.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/340_rational_bitxor_binary_operation.sol new file mode 100644 index 00000000..1fa7f38f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/340_rational_bitxor_binary_operation.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + fixed(1.75) ^ 3; + } +} +// ---- +// TypeError: (50-65): Operator ^ not compatible with types fixed128x18 and int_const 3 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/341_rational_bitand_binary_operation.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/341_rational_bitand_binary_operation.sol new file mode 100644 index 00000000..5a433a61 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/341_rational_bitand_binary_operation.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + fixed(1.75) & 3; + } +} +// ---- +// TypeError: (50-65): Operator & not compatible with types fixed128x18 and int_const 3 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/342_missing_bool_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/342_missing_bool_conversion.sol new file mode 100644 index 00000000..5546a099 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/342_missing_bool_conversion.sol @@ -0,0 +1,7 @@ +contract test { + function b(uint a) public { + bool(a == 1); + } +} +// ---- +// Warning: (20-75): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/343_integer_and_fixed_interaction.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/343_integer_and_fixed_interaction.sol new file mode 100644 index 00000000..af4d048b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/343_integer_and_fixed_interaction.sol @@ -0,0 +1,8 @@ +contract test { + function f() public { + ufixed a = uint64(1) + ufixed(2); + } +} +// ---- +// Warning: (50-58): Unused local variable. +// Warning: (20-89): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/344_one_divided_by_three_integer_conversion.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/344_one_divided_by_three_integer_conversion.sol new file mode 100644 index 00000000..ffc168eb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/344_one_divided_by_three_integer_conversion.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + uint a = 1/3; + } +} +// ---- +// TypeError: (50-62): Type rational_const 1 / 3 is not implicitly convertible to expected type uint256. Try converting to type ufixed256x77 or use an explicit conversion. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/345_unused_return_value.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/345_unused_return_value.sol new file mode 100644 index 00000000..7f640505 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/345_unused_return_value.sol @@ -0,0 +1,8 @@ +contract test { + function g() public returns (uint) {} + function f() public { + g(); + } +} +// ---- +// Warning: (20-57): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/346_unused_return_value_send.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/346_unused_return_value_send.sol new file mode 100644 index 00000000..929e54b2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/346_unused_return_value_send.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + address(0x12).send(1); + } +} +// ---- +// Warning: (50-71): Failure condition of 'send' ignored. Consider using 'transfer' instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/347_unused_return_value_call.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/347_unused_return_value_call.sol new file mode 100644 index 00000000..994a5bdf --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/347_unused_return_value_call.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + address(0x12).call("abc"); + } +} +// ---- +// Warning: (50-75): Return value of low-level calls not used. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/348_unused_return_value_call_value.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/348_unused_return_value_call_value.sol new file mode 100644 index 00000000..1ac7c6f3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/348_unused_return_value_call_value.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + address(0x12).call.value(2)("abc"); + } +} +// ---- +// Warning: (50-84): Return value of low-level calls not used. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/350_unused_return_value_delegatecall.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/350_unused_return_value_delegatecall.sol new file mode 100644 index 00000000..701b6e7d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/350_unused_return_value_delegatecall.sol @@ -0,0 +1,7 @@ +contract test { + function f() public { + address(0x12).delegatecall("abc"); + } +} +// ---- +// Warning: (50-83): Return value of low-level calls not used. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/351_callcode_deprecated.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/351_callcode_deprecated.sol new file mode 100644 index 00000000..554f2e11 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/351_callcode_deprecated.sol @@ -0,0 +1,7 @@ +contract test { + function f() pure public { + address(0x12).callcode; + } +} +// ---- +// TypeError: (55-77): "callcode" has been deprecated in favour of "delegatecall". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/352_callcode_deprecated_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/352_callcode_deprecated_v050.sol new file mode 100644 index 00000000..c0e29b38 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/352_callcode_deprecated_v050.sol @@ -0,0 +1,8 @@ +pragma experimental "v0.5.0"; +contract test { + function f() pure public { + address(0x12).callcode; + } +} +// ---- +// TypeError: (85-107): "callcode" has been deprecated in favour of "delegatecall". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/353_callcode_not_deprecated_as_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/353_callcode_not_deprecated_as_function.sol new file mode 100644 index 00000000..714014f8 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/353_callcode_not_deprecated_as_function.sol @@ -0,0 +1,5 @@ +contract test { + function callcode() pure public { + test.callcode(); + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/354_payable_in_library.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/354_payable_in_library.sol new file mode 100644 index 00000000..410842cb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/354_payable_in_library.sol @@ -0,0 +1,5 @@ +library test { + function f() payable public {} +} +// ---- +// TypeError: (19-49): Library functions cannot be payable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/355_payable_external.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/355_payable_external.sol new file mode 100644 index 00000000..3b75e1b7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/355_payable_external.sol @@ -0,0 +1,3 @@ +contract test { + function f() payable external {} +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/356_payable_internal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/356_payable_internal.sol new file mode 100644 index 00000000..f6ccf6b6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/356_payable_internal.sol @@ -0,0 +1,5 @@ +contract test { + function f() payable internal {} +} +// ---- +// TypeError: (20-52): Internal functions cannot be payable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/357_payable_private.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/357_payable_private.sol new file mode 100644 index 00000000..7b00ea6c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/357_payable_private.sol @@ -0,0 +1,5 @@ +contract test { + function f() payable private {} +} +// ---- +// TypeError: (20-51): Internal functions cannot be payable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/358_illegal_override_payable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/358_illegal_override_payable.sol new file mode 100644 index 00000000..6696772e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/358_illegal_override_payable.sol @@ -0,0 +1,4 @@ +contract B { function f() payable public {} } +contract C is B { function f() public {} } +// ---- +// TypeError: (64-86): Overriding function changes state mutability from "payable" to "nonpayable". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/359_illegal_override_payable_nonpayable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/359_illegal_override_payable_nonpayable.sol new file mode 100644 index 00000000..99b45fdd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/359_illegal_override_payable_nonpayable.sol @@ -0,0 +1,4 @@ +contract B { function f() public {} } +contract C is B { function f() payable public {} } +// ---- +// TypeError: (56-86): Overriding function changes state mutability from "nonpayable" to "payable". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/360_function_variable_mixin.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/360_function_variable_mixin.sol new file mode 100644 index 00000000..583e0d46 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/360_function_variable_mixin.sol @@ -0,0 +1,12 @@ +// bug #1798 (cpp-ethereum), related to #1286 (solidity) +contract attribute { + bool ok = false; +} +contract func { + function ok() public returns (bool) { return true; } +} +contract attr_func is attribute, func { + function checkOk() public returns (bool) { return ok(); } +} +// ---- +// DeclarationError: (121-173): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/361_calling_payable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/361_calling_payable.sol new file mode 100644 index 00000000..8ef4d579 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/361_calling_payable.sol @@ -0,0 +1,6 @@ +contract receiver { function pay() payable public {} } +contract test { + function f() public { (new receiver()).pay.value(10)(); } + receiver r = new receiver(); + function g() public { r.pay.value(10)(); } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/362_calling_nonpayable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/362_calling_nonpayable.sol new file mode 100644 index 00000000..d47ea2bd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/362_calling_nonpayable.sol @@ -0,0 +1,6 @@ +contract receiver { function nopay() public {} } +contract test { + function f() public { (new receiver()).nopay.value(10)(); } +} +// ---- +// TypeError: (91-119): Member "value" not found or not visible after argument-dependent lookup in function () external - did you forget the "payable" modifier? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/363_non_payable_constructor.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/363_non_payable_constructor.sol new file mode 100644 index 00000000..27381904 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/363_non_payable_constructor.sol @@ -0,0 +1,11 @@ +contract C { + constructor() public { } +} +contract D { + function f() public returns (uint) { + (new C).value(2)(); + return 2; + } +} +// ---- +// TypeError: (106-119): Member "value" not found or not visible after argument-dependent lookup in function () returns (contract C) - did you forget the "payable" modifier? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/366_invalid_array_as_statement.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/366_invalid_array_as_statement.sol new file mode 100644 index 00000000..cc2839cd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/366_invalid_array_as_statement.sol @@ -0,0 +1,6 @@ +contract test { + struct S { uint x; } + constructor(uint k) public { S[k]; } +} +// ---- +// TypeError: (76-77): Integer constant expected. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/367_using_directive_for_missing_selftype.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/367_using_directive_for_missing_selftype.sol new file mode 100644 index 00000000..415acb3c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/367_using_directive_for_missing_selftype.sol @@ -0,0 +1,14 @@ +library B { + function b() public {} +} + +contract A { + using B for bytes; + + function a() public { + bytes memory x; + x.b(); + } +} +// ---- +// TypeError: (137-140): Member "b" not found or not visible after argument-dependent lookup in bytes memory diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/368_shift_constant_left_negative_rvalue.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/368_shift_constant_left_negative_rvalue.sol new file mode 100644 index 00000000..9c941a68 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/368_shift_constant_left_negative_rvalue.sol @@ -0,0 +1,5 @@ +contract C { + uint public a = 0x42 << -8; +} +// ---- +// TypeError: (33-43): Operator << not compatible with types int_const 66 and int_const -8 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/369_shift_constant_right_negative_rvalue.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/369_shift_constant_right_negative_rvalue.sol new file mode 100644 index 00000000..55f385c6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/369_shift_constant_right_negative_rvalue.sol @@ -0,0 +1,5 @@ +contract C { + uint public a = 0x42 >> -8; +} +// ---- +// TypeError: (33-43): Operator >> not compatible with types int_const 66 and int_const -8 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/370_shift_constant_left_excessive_rvalue.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/370_shift_constant_left_excessive_rvalue.sol new file mode 100644 index 00000000..e23c7a84 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/370_shift_constant_left_excessive_rvalue.sol @@ -0,0 +1,5 @@ +contract C { + uint public a = 0x42 << 0x100000000; +} +// ---- +// TypeError: (33-52): Operator << not compatible with types int_const 66 and int_const 4294967296 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/371_shift_constant_right_excessive_rvalue.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/371_shift_constant_right_excessive_rvalue.sol new file mode 100644 index 00000000..5533644f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/371_shift_constant_right_excessive_rvalue.sol @@ -0,0 +1,5 @@ +contract C { + uint public a = 0x42 >> 0x100000000; +} +// ---- +// TypeError: (33-52): Operator >> not compatible with types int_const 66 and int_const 4294967296 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/372_shift_constant_right_fractional.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/372_shift_constant_right_fractional.sol new file mode 100644 index 00000000..38d9b051 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/372_shift_constant_right_fractional.sol @@ -0,0 +1,5 @@ +contract C { + uint public a = 0x42 >> (1 / 2); +} +// ---- +// TypeError: (33-48): Operator >> not compatible with types int_const 66 and rational_const 1 / 2 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/373_inline_assembly_unbalanced_positive_stack.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/373_inline_assembly_unbalanced_positive_stack.sol new file mode 100644 index 00000000..273e1844 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/373_inline_assembly_unbalanced_positive_stack.sol @@ -0,0 +1,10 @@ +contract test { + function f() public { + assembly { + 1 + } + } +} +// ---- +// Warning: (73-74): Top-level expressions are not supposed to return values (this expression returns 1 value). Use ``pop()`` or assign them. +// DeclarationError: (59-84): Unbalanced stack at the end of a block: 1 surplus item(s). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/374_inline_assembly_unbalanced_negative_stack.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/374_inline_assembly_unbalanced_negative_stack.sol new file mode 100644 index 00000000..bda090b4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/374_inline_assembly_unbalanced_negative_stack.sol @@ -0,0 +1,10 @@ +contract test { + function f() public { + assembly { + pop + } + } +} +// ---- +// Warning: (73-76): The use of non-functional instructions is deprecated. Please use functional notation instead. +// DeclarationError: (59-86): Unbalanced stack at the end of a block: 1 missing item(s). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/375_inline_assembly_unbalanced_two_stack_load.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/375_inline_assembly_unbalanced_two_stack_load.sol new file mode 100644 index 00000000..4cda64e7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/375_inline_assembly_unbalanced_two_stack_load.sol @@ -0,0 +1,9 @@ +pragma experimental "v0.5.0"; +contract c { + uint8 x; + function f() public { + assembly { pop(x) } + } +} +// ---- +// TypeError: (105-106): Only local variables are supported. To access storage variables, use the _slot and _offset suffixes. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/376_inline_assembly_in_modifier.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/376_inline_assembly_in_modifier.sol new file mode 100644 index 00000000..d6dcc4d0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/376_inline_assembly_in_modifier.sol @@ -0,0 +1,14 @@ +pragma experimental "v0.5.0"; +contract test { + modifier m { + uint a = 1; + assembly { + a := 2 + } + _; + } + function f() public m { + } +} +// ---- +// Warning: (152-181): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/377_inline_assembly_storage.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/377_inline_assembly_storage.sol new file mode 100644 index 00000000..9a2065e2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/377_inline_assembly_storage.sol @@ -0,0 +1,11 @@ +pragma experimental "v0.5.0"; +contract test { + uint x = 1; + function f() public { + assembly { + x := 2 + } + } +} +// ---- +// TypeError: (119-120): Only local variables are supported. To access storage variables, use the _slot and _offset suffixes. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/378_inline_assembly_storage_in_modifiers.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/378_inline_assembly_storage_in_modifiers.sol new file mode 100644 index 00000000..b99179ef --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/378_inline_assembly_storage_in_modifiers.sol @@ -0,0 +1,14 @@ +pragma experimental "v0.5.0"; +contract test { + uint x = 1; + modifier m { + assembly { + x := 2 + } + _; + } + function f() public m { + } +} +// ---- +// TypeError: (110-111): Only local variables are supported. To access storage variables, use the _slot and _offset suffixes. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/379_inline_assembly_constant_assign.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/379_inline_assembly_constant_assign.sol new file mode 100644 index 00000000..866232dd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/379_inline_assembly_constant_assign.sol @@ -0,0 +1,11 @@ +pragma experimental "v0.5.0"; +contract test { + uint constant x = 1; + function f() public { + assembly { + x := 2 + } + } +} +// ---- +// TypeError: (128-129): Constant variables not supported by inline assembly. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/380_inline_assembly_constant_access.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/380_inline_assembly_constant_access.sol new file mode 100644 index 00000000..a41858a0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/380_inline_assembly_constant_access.sol @@ -0,0 +1,11 @@ +pragma experimental "v0.5.0"; +contract test { + uint constant x = 1; + function f() public { + assembly { + let y := x + } + } +} +// ---- +// TypeError: (137-138): Constant variables not supported by inline assembly. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/381_inline_assembly_local_variable_access_out_of_functions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/381_inline_assembly_local_variable_access_out_of_functions.sol new file mode 100644 index 00000000..93004ef6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/381_inline_assembly_local_variable_access_out_of_functions.sol @@ -0,0 +1,11 @@ +pragma experimental "v0.5.0"; +contract test { + function f() public { + uint a; + assembly { + function g() -> x { x := a } + } + } +} +// ---- +// DeclarationError: (144-145): Cannot access local Solidity variables from inside an inline assembly function. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/382_inline_assembly_local_variable_access_out_of_functions_storage_ptr.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/382_inline_assembly_local_variable_access_out_of_functions_storage_ptr.sol new file mode 100644 index 00000000..913ea725 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/382_inline_assembly_local_variable_access_out_of_functions_storage_ptr.sol @@ -0,0 +1,12 @@ +pragma experimental "v0.5.0"; +contract test { + uint[] r; + function f() public { + uint[] storage a = r; + assembly { + function g() -> x { x := a_offset } + } + } +} +// ---- +// DeclarationError: (172-180): Cannot access local Solidity variables from inside an inline assembly function. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/383_inline_assembly_storage_variable_access_out_of_functions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/383_inline_assembly_storage_variable_access_out_of_functions.sol new file mode 100644 index 00000000..7528f355 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/383_inline_assembly_storage_variable_access_out_of_functions.sol @@ -0,0 +1,9 @@ +pragma experimental "v0.5.0"; +contract test { + uint a; + function f() pure public { + assembly { + function g() -> x { x := a_slot } + } + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/384_inline_assembly_constant_variable_via_offset.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/384_inline_assembly_constant_variable_via_offset.sol new file mode 100644 index 00000000..6470a210 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/384_inline_assembly_constant_variable_via_offset.sol @@ -0,0 +1,10 @@ +contract test { + uint constant x = 2; + function f() pure public { + assembly { + let r := x_offset + } + } +} +// ---- +// TypeError: (112-120): Constant variables not supported by inline assembly. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/385_inline_assembly_calldata_variables.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/385_inline_assembly_calldata_variables.sol new file mode 100644 index 00000000..d95fd978 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/385_inline_assembly_calldata_variables.sol @@ -0,0 +1,10 @@ +pragma experimental "v0.5.0"; +contract C { + function f(bytes bytesAsCalldata) external { + assembly { + let x := bytesAsCalldata + } + } +} +// ---- +// TypeError: (132-147): Call data elements cannot be accessed directly. Copy to a local variable first or use "calldataload" or "calldatacopy" with manually determined offsets and sizes. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/386_inline_assembly_050_literals_on_stack.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/386_inline_assembly_050_literals_on_stack.sol new file mode 100644 index 00000000..a5f0f96c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/386_inline_assembly_050_literals_on_stack.sol @@ -0,0 +1,11 @@ +pragma experimental "v0.5.0"; +contract C { + function f() pure public { + assembly { + 1 + } + } +} +// ---- +// SyntaxError: (105-106): Top-level expressions are not supposed to return values (this expression returns 1 value). Use ``pop()`` or assign them. +// DeclarationError: (91-116): Unbalanced stack at the end of a block: 1 surplus item(s). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/387_inline_assembly_literals_on_stack.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/387_inline_assembly_literals_on_stack.sol new file mode 100644 index 00000000..7b68c60b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/387_inline_assembly_literals_on_stack.sol @@ -0,0 +1,10 @@ +contract C { + function f() pure public { + assembly { + 1 + } + } +} +// ---- +// Warning: (75-76): Top-level expressions are not supposed to return values (this expression returns 1 value). Use ``pop()`` or assign them. +// DeclarationError: (61-86): Unbalanced stack at the end of a block: 1 surplus item(s). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/388_inline_assembly_050_bare_instructions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/388_inline_assembly_050_bare_instructions.sol new file mode 100644 index 00000000..4a7aca8a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/388_inline_assembly_050_bare_instructions.sol @@ -0,0 +1,12 @@ +pragma experimental "v0.5.0"; +contract C { + function f() view public { + assembly { + address + pop + } + } +} +// ---- +// SyntaxError: (105-112): The use of non-functional instructions is deprecated. Please use functional notation instead. +// SyntaxError: (125-128): The use of non-functional instructions is deprecated. Please use functional notation instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/389_inline_assembly_bare_instructions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/389_inline_assembly_bare_instructions.sol new file mode 100644 index 00000000..c44412cf --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/389_inline_assembly_bare_instructions.sol @@ -0,0 +1,11 @@ +contract C { + function f() view public { + assembly { + address + pop + } + } +} +// ---- +// Warning: (75-82): The use of non-functional instructions is deprecated. Please use functional notation instead. +// Warning: (95-98): The use of non-functional instructions is deprecated. Please use functional notation instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/390_inline_assembly_050_labels.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/390_inline_assembly_050_labels.sol new file mode 100644 index 00000000..77a73ebc --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/390_inline_assembly_050_labels.sol @@ -0,0 +1,11 @@ +pragma experimental "v0.5.0"; +contract C { + function f() pure public { + assembly { + label: + } + } +} +// ---- +// SyntaxError: (105-110): The use of labels is deprecated. Please use "if", "switch", "for" or function calls instead. +// SyntaxError: (105-110): Jump instructions and labels are low-level EVM features that can lead to incorrect stack access. Because of that they are discouraged. Please consider using "switch", "if" or "for" statements instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/391_inline_assembly_labels.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/391_inline_assembly_labels.sol new file mode 100644 index 00000000..15bd6660 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/391_inline_assembly_labels.sol @@ -0,0 +1,10 @@ +contract C { + function f() pure public { + assembly { + label: + } + } +} +// ---- +// Warning: (75-80): The use of labels is deprecated. Please use "if", "switch", "for" or function calls instead. +// Warning: (75-80): Jump instructions and labels are low-level EVM features that can lead to incorrect stack access. Because of that they are discouraged. Please consider using "switch", "if" or "for" statements instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/392_inline_assembly_050_jump.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/392_inline_assembly_050_jump.sol new file mode 100644 index 00000000..0c98ada1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/392_inline_assembly_050_jump.sol @@ -0,0 +1,10 @@ +pragma experimental "v0.5.0"; +contract C { + function f() pure public { + assembly { + jump(2) + } + } +} +// ---- +// SyntaxError: (105-112): Jump instructions and labels are low-level EVM features that can lead to incorrect stack access. Because of that they are discouraged. Please consider using "switch", "if" or "for" statements instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/393_inline_assembly_jump.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/393_inline_assembly_jump.sol new file mode 100644 index 00000000..c3c82ce8 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/393_inline_assembly_jump.sol @@ -0,0 +1,10 @@ +contract C { + function f() pure public { + assembly { + jump(2) + } + } +} +// ---- +// Warning: (75-82): Jump instructions and labels are low-level EVM features that can lead to incorrect stack access. Because of that they are discouraged. Please consider using "switch", "if" or "for" statements instead. +// TypeError: (75-82): Function declared as pure, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/394_inline_assembly_050_leave_items_on_stack.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/394_inline_assembly_050_leave_items_on_stack.sol new file mode 100644 index 00000000..f72fe741 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/394_inline_assembly_050_leave_items_on_stack.sol @@ -0,0 +1,11 @@ +pragma experimental "v0.5.0"; +contract C { + function f() pure public { + assembly { + mload(0) + } + } +} +// ---- +// SyntaxError: (105-113): Top-level expressions are not supposed to return values (this expression returns 1 value). Use ``pop()`` or assign them. +// DeclarationError: (91-123): Unbalanced stack at the end of a block: 1 surplus item(s). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/395_inline_assembly_leave_items_on_stack.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/395_inline_assembly_leave_items_on_stack.sol new file mode 100644 index 00000000..56043ccf --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/395_inline_assembly_leave_items_on_stack.sol @@ -0,0 +1,10 @@ +contract C { + function f() pure public { + assembly { + mload(0) + } + } +} +// ---- +// Warning: (75-83): Top-level expressions are not supposed to return values (this expression returns 1 value). Use ``pop()`` or assign them. +// DeclarationError: (61-93): Unbalanced stack at the end of a block: 1 surplus item(s). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/396_invalid_mobile_type.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/396_invalid_mobile_type.sol new file mode 100644 index 00000000..536dd317 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/396_invalid_mobile_type.sol @@ -0,0 +1,8 @@ + contract C { + function f() public { + // Invalid number + [1, 78901234567890123456789012345678901234567890123456789345678901234567890012345678012345678901234567]; + } + } +// ---- +// TypeError: (93-191): Invalid rational number. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/397_warns_msg_value_in_non_payable_public_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/397_warns_msg_value_in_non_payable_public_function.sol new file mode 100644 index 00000000..4e1f62e1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/397_warns_msg_value_in_non_payable_public_function.sol @@ -0,0 +1,7 @@ +contract C { + function f() view public { + msg.value; + } +} +// ---- +// Warning: (52-61): "msg.value" used in non-payable function. Do you want to add the "payable" modifier to this function? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/398_does_not_warn_msg_value_in_payable_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/398_does_not_warn_msg_value_in_payable_function.sol new file mode 100644 index 00000000..f14e86ed --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/398_does_not_warn_msg_value_in_payable_function.sol @@ -0,0 +1,5 @@ +contract C { + function f() payable public { + msg.value; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/399_does_not_warn_msg_value_in_internal_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/399_does_not_warn_msg_value_in_internal_function.sol new file mode 100644 index 00000000..8492e691 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/399_does_not_warn_msg_value_in_internal_function.sol @@ -0,0 +1,5 @@ +contract C { + function f() view internal { + msg.value; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/400_does_not_warn_msg_value_in_library.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/400_does_not_warn_msg_value_in_library.sol new file mode 100644 index 00000000..ce59047e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/400_does_not_warn_msg_value_in_library.sol @@ -0,0 +1,5 @@ +library C { + function f() view public { + msg.value; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/401_does_not_warn_msg_value_in_modifier_following_non_payable_public_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/401_does_not_warn_msg_value_in_modifier_following_non_payable_public_function.sol new file mode 100644 index 00000000..dc1da7c4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/401_does_not_warn_msg_value_in_modifier_following_non_payable_public_function.sol @@ -0,0 +1,4 @@ +contract c { + function f() pure public { } + modifier m() { msg.value; _; } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/402_assignment_to_constant.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/402_assignment_to_constant.sol new file mode 100644 index 00000000..7433bdea --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/402_assignment_to_constant.sol @@ -0,0 +1,6 @@ +contract c { + uint constant a = 1; + function f() public { a = 2; } +} +// ---- +// TypeError: (64-65): Cannot assign to a constant variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/403_return_structs.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/403_return_structs.sol new file mode 100644 index 00000000..2575954e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/403_return_structs.sol @@ -0,0 +1,10 @@ +pragma experimental ABIEncoderV2; +contract C { + struct S { uint a; T[] sub; } + struct T { uint[] x; } + function f() public returns (uint, S memory) { + } +} +// ---- +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. +// Warning: (112-164): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/404_read_returned_struct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/404_read_returned_struct.sol new file mode 100644 index 00000000..52d1bd13 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/404_read_returned_struct.sol @@ -0,0 +1,12 @@ +pragma experimental ABIEncoderV2; +contract A { + struct T { + int x; + int y; + } + function g() public returns (T memory) { + return this.g(); + } +} +// ---- +// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/405_address_checksum_type_deduction.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/405_address_checksum_type_deduction.sol new file mode 100644 index 00000000..81cc7d0d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/405_address_checksum_type_deduction.sol @@ -0,0 +1,6 @@ +contract C { + function f() public { + (0xfA0bFc97E48458494Ccd857e1A85DC91F7F0046E).transfer(2); + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/406_invalid_address_checksum.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/406_invalid_address_checksum.sol new file mode 100644 index 00000000..fe4691c2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/406_invalid_address_checksum.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + address x = 0xFA0bFc97E48458494Ccd857e1A85DC91F7F0046E; + x; + } +} +// ---- +// SyntaxError: (64-106): This looks like an address but has an invalid checksum. Correct checksummed address: "0xfA0bFc97E48458494Ccd857e1A85DC91F7F0046E". If this is not used as an address, please prepend '00'. For more information please see https://solidity.readthedocs.io/en/develop/types.html#address-literals diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/407_invalid_address_no_checksum.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/407_invalid_address_no_checksum.sol new file mode 100644 index 00000000..6f4ac730 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/407_invalid_address_no_checksum.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + address x = 0xfa0bfc97e48458494ccd857e1a85dc91f7f0046e; + x; + } +} +// ---- +// SyntaxError: (64-106): This looks like an address but has an invalid checksum. Correct checksummed address: "0xfA0bFc97E48458494Ccd857e1A85DC91F7F0046E". If this is not used as an address, please prepend '00'. For more information please see https://solidity.readthedocs.io/en/develop/types.html#address-literals diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/408_invalid_address_length_short.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/408_invalid_address_length_short.sol new file mode 100644 index 00000000..da5dc380 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/408_invalid_address_length_short.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + address x = 0xA0bFc97E48458494Ccd857e1A85DC91F7F0046E; + x; + } +} +// ---- +// SyntaxError: (64-105): This looks like an address but is not exactly 40 hex digits. It is 39 hex digits. If this is not used as an address, please prepend '00'. For more information please see https://solidity.readthedocs.io/en/develop/types.html#address-literals diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/409_invalid_address_length_long.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/409_invalid_address_length_long.sol new file mode 100644 index 00000000..749612c9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/409_invalid_address_length_long.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + address x = 0xFA0bFc97E48458494Ccd857e1A85DC91F7F0046E0; + x; + } +} +// ---- +// SyntaxError: (64-107): This looks like an address but is not exactly 40 hex digits. It is 41 hex digits. If this is not used as an address, please prepend '00'. For more information please see https://solidity.readthedocs.io/en/develop/types.html#address-literals diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/410_string_literal_not_convertible_to_address_as_assignment.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/410_string_literal_not_convertible_to_address_as_assignment.sol new file mode 100644 index 00000000..13bd1a8f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/410_string_literal_not_convertible_to_address_as_assignment.sol @@ -0,0 +1,6 @@ +// A previous implementation claimed the string would be an address +contract AddrString { + address public test = "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c"; +} +// ---- +// TypeError: (116-160): Type literal_string "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c" is not implicitly convertible to expected type address. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/411_string_literal_not_convertible_to_address_as_return_value.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/411_string_literal_not_convertible_to_address_as_return_value.sol new file mode 100644 index 00000000..d6b7b987 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/411_string_literal_not_convertible_to_address_as_return_value.sol @@ -0,0 +1,8 @@ +// A previous implementation claimed the string would be an address +contract AddrString { + function f() public returns (address) { + return "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c"; + } +} +// ---- +// TypeError: (149-193): Return argument type literal_string "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c" is not implicitly convertible to expected type (type of first return variable) address. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/412_early_exit_on_fatal_errors.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/412_early_exit_on_fatal_errors.sol new file mode 100644 index 00000000..56fc4051 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/412_early_exit_on_fatal_errors.sol @@ -0,0 +1,11 @@ +// This tests a crash that occurred because we did not stop for fatal errors. +contract C { + struct S { + ftring a; + } + S public s; + function s() public s { + } +} +// ---- +// DeclarationError: (114-120): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol new file mode 100644 index 00000000..9c42bc8f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol @@ -0,0 +1,12 @@ +contract C { + function f() public { + address addr; + uint balance = addr.balance; + bool callRet = addr.call(""); + bool delegatecallRet = addr.delegatecall(""); + bool sendRet = addr.send(1); + addr.transfer(1); + balance; callRet; delegatecallRet; sendRet; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/414_interface.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/414_interface.sol new file mode 100644 index 00000000..77baf7bf --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/414_interface.sol @@ -0,0 +1,2 @@ +interface I { +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/415_interface_functions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/415_interface_functions.sol new file mode 100644 index 00000000..a5d6561e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/415_interface_functions.sol @@ -0,0 +1,5 @@ +interface I { + function() external; + function f() external; +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/416_interface_function_bodies.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/416_interface_function_bodies.sol new file mode 100644 index 00000000..24b26c04 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/416_interface_function_bodies.sol @@ -0,0 +1,7 @@ +interface I { + function f() public { + } +} +// ---- +// TypeError: (18-45): Functions in interfaces cannot have an implementation. +// Warning: (18-45): Functions in interfaces should be declared external. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/417_interface_events.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/417_interface_events.sol new file mode 100644 index 00000000..5959f50d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/417_interface_events.sol @@ -0,0 +1,3 @@ +interface I { + event E(); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/418_interface_inheritance.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/418_interface_inheritance.sol new file mode 100644 index 00000000..92683cda --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/418_interface_inheritance.sol @@ -0,0 +1,6 @@ +interface A { +} +interface I is A { +} +// ---- +// TypeError: (31-32): Interfaces cannot inherit. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/419_interface_structs.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/419_interface_structs.sol new file mode 100644 index 00000000..c74d52d3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/419_interface_structs.sol @@ -0,0 +1,9 @@ +interface I { + struct A { + // This is currently expected to break, but it *may* change in the future. + int dummy; + } +} +// ---- +// TypeError: (18-136): Structs cannot be defined in interfaces. +// TypeError: (120-129): Variables cannot be declared in interfaces. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/420_interface_variables.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/420_interface_variables.sol new file mode 100644 index 00000000..a4292c41 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/420_interface_variables.sol @@ -0,0 +1,5 @@ +interface I { + uint a; +} +// ---- +// TypeError: (18-24): Variables cannot be declared in interfaces. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/421_interface_function_parameters.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/421_interface_function_parameters.sol new file mode 100644 index 00000000..05e2dcfd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/421_interface_function_parameters.sol @@ -0,0 +1,5 @@ +interface I { + function f(uint a) public returns (bool); +} +// ---- +// Warning: (18-59): Functions in interfaces should be declared external. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/422_interface_enums.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/422_interface_enums.sol new file mode 100644 index 00000000..5513817d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/422_interface_enums.sol @@ -0,0 +1,5 @@ +interface I { + enum A { B, C } +} +// ---- +// TypeError: (18-33): Enumerable cannot be declared in interfaces. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/423_using_interface.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/423_using_interface.sol new file mode 100644 index 00000000..d576bb60 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/423_using_interface.sol @@ -0,0 +1,8 @@ +interface I { + function f() external; +} +contract C is I { + function f() public { + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/424_using_interface_complex.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/424_using_interface_complex.sol new file mode 100644 index 00000000..a3dca996 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/424_using_interface_complex.sol @@ -0,0 +1,11 @@ +interface I { + event A(); + function f() external; + function g() external; + function() external; +} +contract C is I { + function f() public { + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/425_interface_implement_public_contract.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/425_interface_implement_public_contract.sol new file mode 100644 index 00000000..d8540288 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/425_interface_implement_public_contract.sol @@ -0,0 +1,7 @@ +interface I { + function f() external; +} +contract C is I { + function f() public { + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/426_throw_is_deprecated.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/426_throw_is_deprecated.sol new file mode 100644 index 00000000..510c0d01 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/426_throw_is_deprecated.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public { + throw; + } +} +// ---- +// Warning: (52-57): "throw" is deprecated in favour of "revert()", "require()" and "assert()". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/427_throw_is_deprecated_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/427_throw_is_deprecated_v050.sol new file mode 100644 index 00000000..170d47d9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/427_throw_is_deprecated_v050.sol @@ -0,0 +1,8 @@ +pragma experimental "v0.5.0"; +contract C { + function f() pure public { + throw; + } +} +// ---- +// SyntaxError: (82-87): "throw" is deprecated in favour of "revert()", "require()" and "assert()". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/428_bare_revert.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/428_bare_revert.sol new file mode 100644 index 00000000..8e7817ff --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/428_bare_revert.sol @@ -0,0 +1,8 @@ +contract C { + function f(uint x) pure public { + if (x > 7) + revert; + } +} +// ---- +// TypeError: (81-87): No matching declaration found after variable lookup. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/429_revert_with_reason.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/429_revert_with_reason.sol new file mode 100644 index 00000000..36c238be --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/429_revert_with_reason.sol @@ -0,0 +1,8 @@ +contract C { + function f(uint x) pure public { + if (x > 7) + revert("abc"); + else + revert(); + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/430_bare_selfdestruct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/430_bare_selfdestruct.sol new file mode 100644 index 00000000..9adc3d39 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/430_bare_selfdestruct.sol @@ -0,0 +1,5 @@ +contract C { + function f() pure public { selfdestruct; } +} +// ---- +// Warning: (44-56): Statement has no effect. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/431_bare_assert.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/431_bare_assert.sol new file mode 100644 index 00000000..38cea057 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/431_bare_assert.sol @@ -0,0 +1,5 @@ +contract C { + function f() pure public { assert; } +} +// ---- +// Warning: (44-50): Statement has no effect. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/432_bare_require.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/432_bare_require.sol new file mode 100644 index 00000000..62fe8baf --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/432_bare_require.sol @@ -0,0 +1,6 @@ +contract C { + // This is different because it does have overloads. + function f() pure public { require; } +} +// ---- +// TypeError: (101-108): No matching declaration found after variable lookup. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/433_pure_statement_in_for_loop.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/433_pure_statement_in_for_loop.sol new file mode 100644 index 00000000..8cb090bb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/433_pure_statement_in_for_loop.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + for (uint x = 0; x < 10; true) + x++; + } +} +// ---- +// Warning: (77-81): Statement has no effect. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/434_pure_statement_check_for_regular_for_loop.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/434_pure_statement_check_for_regular_for_loop.sol new file mode 100644 index 00000000..319e4202 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/434_pure_statement_check_for_regular_for_loop.sol @@ -0,0 +1,6 @@ +contract C { + function f() pure public { + for (uint x = 0; true; x++) + {} + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/435_warn_unused_local.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/435_warn_unused_local.sol new file mode 100644 index 00000000..7d7f5728 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/435_warn_unused_local.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public { + uint a; + } +} +// ---- +// Warning: (52-58): Unused local variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/436_warn_unused_local_assigned.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/436_warn_unused_local_assigned.sol new file mode 100644 index 00000000..b3d28374 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/436_warn_unused_local_assigned.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public { + uint a = 1; + } +} +// ---- +// Warning: (52-58): Unused local variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/437_warn_unused_function_parameter.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/437_warn_unused_function_parameter.sol new file mode 100644 index 00000000..8a36eaad --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/437_warn_unused_function_parameter.sol @@ -0,0 +1,6 @@ +contract C { + function f(uint a) pure public { + } +} +// ---- +// Warning: (28-34): Unused function parameter. Remove or comment out the variable name to silence this warning. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/438_unused_unnamed_function_parameter.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/438_unused_unnamed_function_parameter.sol new file mode 100644 index 00000000..5d059b93 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/438_unused_unnamed_function_parameter.sol @@ -0,0 +1,4 @@ +contract C { + function f(uint) pure public { + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/439_warn_unused_return_parameter.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/439_warn_unused_return_parameter.sol new file mode 100644 index 00000000..b1422c4f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/439_warn_unused_return_parameter.sol @@ -0,0 +1,6 @@ +contract C { + function f() pure public returns (uint a) { + } +} +// ---- +// Warning: (51-57): Unused function parameter. Remove or comment out the variable name to silence this warning. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/440_warn_unused_return_parameter_with_explicit_return.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/440_warn_unused_return_parameter_with_explicit_return.sol new file mode 100644 index 00000000..af67f491 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/440_warn_unused_return_parameter_with_explicit_return.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public returns (uint a) { + return; + } +} +// ---- +// Warning: (51-57): Unused function parameter. Remove or comment out the variable name to silence this warning. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/441_unused_unnamed_return_parameter.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/441_unused_unnamed_return_parameter.sol new file mode 100644 index 00000000..8c47484b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/441_unused_unnamed_return_parameter.sol @@ -0,0 +1,4 @@ +contract C { + function f() pure public returns (uint) { + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/442_named_return_parameter.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/442_named_return_parameter.sol new file mode 100644 index 00000000..a2faf06a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/442_named_return_parameter.sol @@ -0,0 +1,5 @@ +contract C { + function f() pure public returns (uint a) { + a = 1; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/443_named_return_parameter_with_explicit_return.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/443_named_return_parameter_with_explicit_return.sol new file mode 100644 index 00000000..93851e7c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/443_named_return_parameter_with_explicit_return.sol @@ -0,0 +1,5 @@ +contract C { + function f() pure public returns (uint a) { + return 1; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/444_unnamed_return_parameter_with_explicit_return.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/444_unnamed_return_parameter_with_explicit_return.sol new file mode 100644 index 00000000..b552a745 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/444_unnamed_return_parameter_with_explicit_return.sol @@ -0,0 +1,5 @@ +contract C { + function f() pure public returns (uint) { + return 1; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/445_no_unused_warning_interface_arguments.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/445_no_unused_warning_interface_arguments.sol new file mode 100644 index 00000000..203217ce --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/445_no_unused_warning_interface_arguments.sol @@ -0,0 +1,3 @@ +interface I { + function f(uint a) pure external returns (uint b); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/446_no_unused_warning_abstract_arguments.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/446_no_unused_warning_abstract_arguments.sol new file mode 100644 index 00000000..fbb6e079 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/446_no_unused_warning_abstract_arguments.sol @@ -0,0 +1,3 @@ +contract C { + function f(uint a) pure public returns (uint b); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/447_no_unused_warnings.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/447_no_unused_warnings.sol new file mode 100644 index 00000000..f549308a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/447_no_unused_warnings.sol @@ -0,0 +1,6 @@ +contract C { + function f(uint a) pure public returns (uint b) { + uint c = 1; + b = a + c; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/449_no_unused_inline_asm.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/449_no_unused_inline_asm.sol new file mode 100644 index 00000000..2b39b9fd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/449_no_unused_inline_asm.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + uint a; + assembly { + a := 1 + } + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/450_shadowing_builtins_with_functions.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/450_shadowing_builtins_with_functions.sol new file mode 100644 index 00000000..33ccb356 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/450_shadowing_builtins_with_functions.sol @@ -0,0 +1,5 @@ +contract C { + function keccak256() pure public {} +} +// ---- +// Warning: (17-52): This declaration shadows a builtin symbol. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/451_shadowing_builtins_with_variables.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/451_shadowing_builtins_with_variables.sol new file mode 100644 index 00000000..1d6f098e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/451_shadowing_builtins_with_variables.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + uint msg; + msg; + } +} +// ---- +// Warning: (52-60): This declaration shadows a builtin symbol. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/452_shadowing_builtins_with_storage_variables.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/452_shadowing_builtins_with_storage_variables.sol new file mode 100644 index 00000000..d5635887 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/452_shadowing_builtins_with_storage_variables.sol @@ -0,0 +1,5 @@ +contract C { + uint msg; +} +// ---- +// Warning: (17-25): This declaration shadows a builtin symbol. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/453_shadowing_builtin_at_global_scope.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/453_shadowing_builtin_at_global_scope.sol new file mode 100644 index 00000000..0946dc57 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/453_shadowing_builtin_at_global_scope.sol @@ -0,0 +1,4 @@ +contract msg { +} +// ---- +// Warning: (0-16): This declaration shadows a builtin symbol. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/454_shadowing_builtins_with_parameters.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/454_shadowing_builtins_with_parameters.sol new file mode 100644 index 00000000..454929d1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/454_shadowing_builtins_with_parameters.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint require) pure public { + require = 2; + } +} +// ---- +// Warning: (28-40): This declaration shadows a builtin symbol. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/455_shadowing_builtins_with_return_parameters.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/455_shadowing_builtins_with_return_parameters.sol new file mode 100644 index 00000000..7931053f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/455_shadowing_builtins_with_return_parameters.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public returns (uint require) { + require = 2; + } +} +// ---- +// Warning: (51-63): This declaration shadows a builtin symbol. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/456_shadowing_builtins_with_events.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/456_shadowing_builtins_with_events.sol new file mode 100644 index 00000000..e5b635df --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/456_shadowing_builtins_with_events.sol @@ -0,0 +1,5 @@ +contract C { + event keccak256(); +} +// ---- +// Warning: (17-35): This declaration shadows a builtin symbol. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/457_shadowing_builtins_ignores_struct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/457_shadowing_builtins_ignores_struct.sol new file mode 100644 index 00000000..4c70b4ce --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/457_shadowing_builtins_ignores_struct.sol @@ -0,0 +1,5 @@ +contract C { + struct a { + uint msg; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/458_shadowing_builtins_ignores_constructor.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/458_shadowing_builtins_ignores_constructor.sol new file mode 100644 index 00000000..86c0b4f0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/458_shadowing_builtins_ignores_constructor.sol @@ -0,0 +1,3 @@ +contract C { + constructor() public {} +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/459_function_overload_is_not_shadowing.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/459_function_overload_is_not_shadowing.sol new file mode 100644 index 00000000..1b44b5c6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/459_function_overload_is_not_shadowing.sol @@ -0,0 +1,4 @@ +contract C { + function f() pure public {} + function f(uint) pure public {} +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/460_function_override_is_not_shadowing.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/460_function_override_is_not_shadowing.sol new file mode 100644 index 00000000..c765ff00 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/460_function_override_is_not_shadowing.sol @@ -0,0 +1,4 @@ +contract D { function f() pure public {} } +contract C is D { + function f(uint) pure public {} +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/461_event_parameter_cannot_shadow_state_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/461_event_parameter_cannot_shadow_state_variable.sol new file mode 100644 index 00000000..6e1f654d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/461_event_parameter_cannot_shadow_state_variable.sol @@ -0,0 +1,4 @@ +contract C { + address a; + event E(address a); +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/462_callable_crash.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/462_callable_crash.sol new file mode 100644 index 00000000..188d00e0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/462_callable_crash.sol @@ -0,0 +1,9 @@ +contract C { + struct S { uint a; bool x; } + S public s; + constructor() public { + 3({a: 1, x: true}); + } +} +// ---- +// TypeError: (97-115): Type is not callable diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/463_error_transfer_non_payable_fallback.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/463_error_transfer_non_payable_fallback.sol new file mode 100644 index 00000000..2b2ef39e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/463_error_transfer_non_payable_fallback.sol @@ -0,0 +1,17 @@ +// This used to be a test for a.transfer to generate a warning +// because A's fallback function is not payable. + +contract A { + function() external {} +} + +contract B { + A a; + + function() external { + a.transfer(100); + } +} +// ---- +// Warning: (213-223): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead. +// TypeError: (213-223): Value transfer to a contract without a payable fallback function. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/464_error_transfer_no_fallback.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/464_error_transfer_no_fallback.sol new file mode 100644 index 00000000..67398de7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/464_error_transfer_no_fallback.sol @@ -0,0 +1,15 @@ +// This used to be a test for a.transfer to generate a warning +// because A does not have a payable fallback function. + +contract A {} + +contract B { + A a; + + function() external { + a.transfer(100); + } +} +// ---- +// Warning: (192-202): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead. +// TypeError: (192-202): Value transfer to a contract without a payable fallback function. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/465_error_send_non_payable_fallback.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/465_error_send_non_payable_fallback.sol new file mode 100644 index 00000000..1a4b2e81 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/465_error_send_non_payable_fallback.sol @@ -0,0 +1,17 @@ +// This used to be a test for a.send to generate a warning +// because A does not have a payable fallback function. + +contract A { + function() external {} +} + +contract B { + A a; + + function() external { + require(a.send(100)); + } +} +// ---- +// Warning: (224-230): Using contract member "send" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).send" instead. +// TypeError: (224-230): Value transfer to a contract without a payable fallback function. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/466_does_not_error_transfer_payable_fallback.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/466_does_not_error_transfer_payable_fallback.sol new file mode 100644 index 00000000..2b7f8dae --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/466_does_not_error_transfer_payable_fallback.sol @@ -0,0 +1,16 @@ +// This used to be a test for a.transfer to generate a warning +// because A does not have a payable fallback function. + +contract A { + function() payable external {} +} + +contract B { + A a; + + function() external { + a.transfer(100); + } +} +// ---- +// Warning: (228-238): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/467_does_not_error_transfer_regular_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/467_does_not_error_transfer_regular_function.sol new file mode 100644 index 00000000..65b4a236 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/467_does_not_error_transfer_regular_function.sol @@ -0,0 +1,11 @@ +contract A { + function transfer() pure public {} +} + +contract B { + A a; + + function() external { + a.transfer(); + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/470_specified_storage_no_warn.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/470_specified_storage_no_warn.sol new file mode 100644 index 00000000..490a0032 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/470_specified_storage_no_warn.sol @@ -0,0 +1,8 @@ +contract C { + struct S { uint a; string b; } + S x; + function f() view public { + S storage y = x; + y; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_fail.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_fail.sol new file mode 100644 index 00000000..6e401920 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_fail.sol @@ -0,0 +1,13 @@ +contract C { + struct S { uint a; } + S m_x; + uint[] m_y; + function f() view public { + S x = m_x; + uint[] y = m_y; + x; y; + } +} +// ---- +// TypeError: (104-107): Data location must be specified as either "memory" or "storage". +// TypeError: (123-131): Data location must be specified as either "memory" or "storage". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/473_storage_location_non_array_or_struct_disallowed.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/473_storage_location_non_array_or_struct_disallowed.sol new file mode 100644 index 00000000..6c9f50af --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/473_storage_location_non_array_or_struct_disallowed.sol @@ -0,0 +1,5 @@ +contract C { + function f(uint storage a) public { } +} +// ---- +// TypeError: (28-42): Data location can only be given for array or struct types. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/474_storage_location_non_array_or_struct_disallowed_is_not_fatal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/474_storage_location_non_array_or_struct_disallowed_is_not_fatal.sol new file mode 100644 index 00000000..a2f47407 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/474_storage_location_non_array_or_struct_disallowed_is_not_fatal.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint storage a) public { + a = f; + } +} +// ---- +// TypeError: (28-42): Data location can only be given for array or struct types. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/475_implicit_conversion_disallowed.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/475_implicit_conversion_disallowed.sol new file mode 100644 index 00000000..232e701d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/475_implicit_conversion_disallowed.sol @@ -0,0 +1,8 @@ +contract C { + function f() public returns (bytes4) { + uint32 tmp = 1; + return tmp; + } +} +// ---- +// TypeError: (95-98): Return argument type uint32 is not implicitly convertible to expected type (type of first return variable) bytes4. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/476_too_large_arrays_for_calldata_external.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/476_too_large_arrays_for_calldata_external.sol new file mode 100644 index 00000000..de8b7501 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/476_too_large_arrays_for_calldata_external.sol @@ -0,0 +1,6 @@ +contract C { + function f(uint[85678901234] a) pure external { + } +} +// ---- +// TypeError: (28-47): Array is too large to be encoded. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/477_too_large_arrays_for_calldata_internal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/477_too_large_arrays_for_calldata_internal.sol new file mode 100644 index 00000000..7578246e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/477_too_large_arrays_for_calldata_internal.sol @@ -0,0 +1,6 @@ +contract C { + function f(uint[85678901234] memory a) pure internal { + } +} +// ---- +// TypeError: (28-54): Array is too large to be encoded. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/478_too_large_arrays_for_calldata_public.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/478_too_large_arrays_for_calldata_public.sol new file mode 100644 index 00000000..2831b6fb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/478_too_large_arrays_for_calldata_public.sol @@ -0,0 +1,6 @@ +contract C { + function f(uint[85678901234] memory a) pure public { + } +} +// ---- +// TypeError: (28-54): Array is too large to be encoded. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/479_explicit_literal_to_memory_string_assignment.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/479_explicit_literal_to_memory_string_assignment.sol new file mode 100644 index 00000000..508a9439 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/479_explicit_literal_to_memory_string_assignment.sol @@ -0,0 +1,6 @@ +contract C { + function f() pure public { + string memory x = "abc"; + x; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/480_explicit_literal_to_storage_string_assignment.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/480_explicit_literal_to_storage_string_assignment.sol new file mode 100644 index 00000000..ee56204a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/480_explicit_literal_to_storage_string_assignment.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public { + string storage x = "abc"; + } +} +// ---- +// TypeError: (52-76): Type literal_string "abc" is not implicitly convertible to expected type string storage pointer. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/481_explicit_literal_to_unspecified_string_assignment.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/481_explicit_literal_to_unspecified_string_assignment.sol new file mode 100644 index 00000000..ee56204a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/481_explicit_literal_to_unspecified_string_assignment.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public { + string storage x = "abc"; + } +} +// ---- +// TypeError: (52-76): Type literal_string "abc" is not implicitly convertible to expected type string storage pointer. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/482_explicit_literal_to_unspecified_string.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/482_explicit_literal_to_unspecified_string.sol new file mode 100644 index 00000000..a83eee72 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/482_explicit_literal_to_unspecified_string.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public { + string("abc"); + } +} +// ---- +// TypeError: (52-65): Explicit type conversion not allowed from "literal_string "abc"" to "string storage pointer". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/483_modifiers_access_storage_pointer.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/483_modifiers_access_storage_pointer.sol new file mode 100644 index 00000000..be1920e9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/483_modifiers_access_storage_pointer.sol @@ -0,0 +1,7 @@ +contract C { + struct S { uint a; } + modifier m(S storage x) { + x; + _; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/484_function_types_selector_1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/484_function_types_selector_1.sol new file mode 100644 index 00000000..9ed2b70f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/484_function_types_selector_1.sol @@ -0,0 +1,7 @@ +contract C { + function f() public view returns (bytes4) { + return f.selector; + } +} +// ---- +// TypeError: (76-86): Member "selector" not found or not visible after argument-dependent lookup in function () view returns (bytes4) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/485_function_types_selector_2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/485_function_types_selector_2.sol new file mode 100644 index 00000000..0876a4f7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/485_function_types_selector_2.sol @@ -0,0 +1,9 @@ +contract C { + function g() pure internal { + } + function f() public view returns (bytes4) { + return g.selector; + } +} +// ---- +// TypeError: (115-125): Member "selector" not found or not visible after argument-dependent lookup in function () pure diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/486_function_types_selector_3.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/486_function_types_selector_3.sol new file mode 100644 index 00000000..d0ccc724 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/486_function_types_selector_3.sol @@ -0,0 +1,8 @@ +contract C { + function f() public view returns (bytes4) { + function () g; + return g.selector; + } +} +// ---- +// TypeError: (99-109): Member "selector" not found or not visible after argument-dependent lookup in function () diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/487_function_types_selector_4.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/487_function_types_selector_4.sol new file mode 100644 index 00000000..4c3c72e8 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/487_function_types_selector_4.sol @@ -0,0 +1,5 @@ +contract C { + function f() pure external returns (bytes4) { + return this.f.selector; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/488_function_types_selector_5.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/488_function_types_selector_5.sol new file mode 100644 index 00000000..5f601db2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/488_function_types_selector_5.sol @@ -0,0 +1,8 @@ +contract C { + function h() pure external { + } + function f() pure external returns (bytes4) { + return this.h.selector; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/489_function_types_selector_6.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/489_function_types_selector_6.sol new file mode 100644 index 00000000..0114e282 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/489_function_types_selector_6.sol @@ -0,0 +1,8 @@ +contract C { + function h() pure external { + } + function f() view external returns (bytes4) { + function () pure external g = this.h; + return g.selector; + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/490_function_types_selector_7.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/490_function_types_selector_7.sol new file mode 100644 index 00000000..9ee7d9bb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/490_function_types_selector_7.sol @@ -0,0 +1,9 @@ +contract C { + function h() pure external { + } + function f() view external returns (bytes4) { + function () pure external g = this.h; + return g.selector; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/491_using_this_in_constructor.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/491_using_this_in_constructor.sol new file mode 100644 index 00000000..7921a1fa --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/491_using_this_in_constructor.sol @@ -0,0 +1,9 @@ +contract C { + constructor() public { + this.f(); + } + function f() pure public { + } +} +// ---- +// Warning: (48-52): "this" used in constructor. Note that external functions of a contract cannot be called while it is being constructed. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/492_do_not_crash_on_not_lvalue.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/492_do_not_crash_on_not_lvalue.sol new file mode 100644 index 00000000..90275804 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/492_do_not_crash_on_not_lvalue.sol @@ -0,0 +1,11 @@ +// This checks for a bug that caused a crash because of continued analysis. +contract C { + mapping (uint => uint) m; + function f() public { + m(1) = 2; + } +} +// ---- +// TypeError: (153-157): Type is not callable +// TypeError: (153-157): Expression has to be an lvalue. +// TypeError: (160-161): Type int_const 2 is not implicitly convertible to expected type tuple(). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/493_builtin_keccak256_reject_gas.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/493_builtin_keccak256_reject_gas.sol new file mode 100644 index 00000000..b99431f9 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/493_builtin_keccak256_reject_gas.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + keccak256.gas(); + } +} +// ---- +// TypeError: (47-60): Member "gas" not found or not visible after argument-dependent lookup in function (bytes memory) pure returns (bytes32) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/494_builtin_sha256_reject_gas.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/494_builtin_sha256_reject_gas.sol new file mode 100644 index 00000000..23c90acb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/494_builtin_sha256_reject_gas.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + sha256.gas(); + } +} +// ---- +// TypeError: (47-57): Member "gas" not found or not visible after argument-dependent lookup in function (bytes memory) pure returns (bytes32) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/495_builtin_ripemd160_reject_gas.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/495_builtin_ripemd160_reject_gas.sol new file mode 100644 index 00000000..5884e212 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/495_builtin_ripemd160_reject_gas.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + ripemd160.gas(); + } +} +// ---- +// TypeError: (47-60): Member "gas" not found or not visible after argument-dependent lookup in function (bytes memory) pure returns (bytes20) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/496_builtin_ecrecover_reject_gas.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/496_builtin_ecrecover_reject_gas.sol new file mode 100644 index 00000000..0a874f5d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/496_builtin_ecrecover_reject_gas.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + ecrecover.gas(); + } +} +// ---- +// TypeError: (47-60): Member "gas" not found or not visible after argument-dependent lookup in function (bytes32,uint8,bytes32,bytes32) pure returns (address) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/497_gasleft.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/497_gasleft.sol new file mode 100644 index 00000000..20f33887 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/497_gasleft.sol @@ -0,0 +1,3 @@ +contract C { + function f() public view returns (uint256 val) { return gasleft(); } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/498_msg_gas_deprecated.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/498_msg_gas_deprecated.sol new file mode 100644 index 00000000..5efecd22 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/498_msg_gas_deprecated.sol @@ -0,0 +1,5 @@ +contract C { + function f() public view returns (uint256 val) { return msg.gas; } +} +// ---- +// TypeError: (73-80): "msg.gas" has been deprecated in favor of "gasleft()" diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/500_gasleft_shadowing_1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/500_gasleft_shadowing_1.sol new file mode 100644 index 00000000..66b88c49 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/500_gasleft_shadowing_1.sol @@ -0,0 +1,6 @@ +contract C { + function gasleft() public pure returns (bytes32 val) { return "abc"; } + function f() public pure returns (bytes32 val) { return gasleft(); } +} +// ---- +// Warning: (17-87): This declaration shadows a builtin symbol. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/501_gasleft_shadowing_2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/501_gasleft_shadowing_2.sol new file mode 100644 index 00000000..2679c89d --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/501_gasleft_shadowing_2.sol @@ -0,0 +1,6 @@ +contract C { + uint gasleft; + function f() public { gasleft = 42; } +} +// ---- +// Warning: (17-29): This declaration shadows a builtin symbol. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/502_builtin_keccak256_reject_value.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/502_builtin_keccak256_reject_value.sol new file mode 100644 index 00000000..61e51eff --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/502_builtin_keccak256_reject_value.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + keccak256.value(); + } +} +// ---- +// TypeError: (47-62): Member "value" not found or not visible after argument-dependent lookup in function (bytes memory) pure returns (bytes32) - did you forget the "payable" modifier? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/503_builtin_sha256_reject_value.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/503_builtin_sha256_reject_value.sol new file mode 100644 index 00000000..11141a9b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/503_builtin_sha256_reject_value.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + sha256.value(); + } +} +// ---- +// TypeError: (47-59): Member "value" not found or not visible after argument-dependent lookup in function (bytes memory) pure returns (bytes32) - did you forget the "payable" modifier? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/504_builtin_ripemd160_reject_value.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/504_builtin_ripemd160_reject_value.sol new file mode 100644 index 00000000..d120f3dd --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/504_builtin_ripemd160_reject_value.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + ripemd160.value(); + } +} +// ---- +// TypeError: (47-62): Member "value" not found or not visible after argument-dependent lookup in function (bytes memory) pure returns (bytes20) - did you forget the "payable" modifier? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/505_builtin_ecrecover_reject_value.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/505_builtin_ecrecover_reject_value.sol new file mode 100644 index 00000000..e0215901 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/505_builtin_ecrecover_reject_value.sol @@ -0,0 +1,7 @@ +contract C { + function f() public { + ecrecover.value(); + } +} +// ---- +// TypeError: (47-62): Member "value" not found or not visible after argument-dependent lookup in function (bytes32,uint8,bytes32,bytes32) pure returns (address) - did you forget the "payable" modifier? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/506_large_storage_array_fine.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/506_large_storage_array_fine.sol new file mode 100644 index 00000000..13e6dd80 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/506_large_storage_array_fine.sol @@ -0,0 +1,3 @@ +contract C { + uint[2**64 - 1] x; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/507_large_storage_array_simple.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/507_large_storage_array_simple.sol new file mode 100644 index 00000000..3f8ee996 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/507_large_storage_array_simple.sol @@ -0,0 +1,5 @@ +contract C { + uint[2**64] x; +} +// ---- +// Warning: (17-30): Variable covers a large part of storage and thus makes collisions likely. Either use mappings or dynamic arrays and allow their size to be increased only in small quantities per transaction. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/508_large_storage_arrays_combined.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/508_large_storage_arrays_combined.sol new file mode 100644 index 00000000..917dcec1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/508_large_storage_arrays_combined.sol @@ -0,0 +1,5 @@ +contract C { + uint[200][200][2**30][][2**30] x; +} +// ---- +// Warning: (17-49): Variable covers a large part of storage and thus makes collisions likely. Either use mappings or dynamic arrays and allow their size to be increased only in small quantities per transaction. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/509_large_storage_arrays_struct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/509_large_storage_arrays_struct.sol new file mode 100644 index 00000000..656201f4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/509_large_storage_arrays_struct.sol @@ -0,0 +1,6 @@ +contract C { + struct S { uint[2**30] x; uint[2**50] y; } + S[2**20] x; +} +// ---- +// Warning: (64-74): Variable covers a large part of storage and thus makes collisions likely. Either use mappings or dynamic arrays and allow their size to be increased only in small quantities per transaction. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/510_large_storage_array_mapping.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/510_large_storage_array_mapping.sol new file mode 100644 index 00000000..046a27f7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/510_large_storage_array_mapping.sol @@ -0,0 +1,5 @@ +contract C { + mapping(uint => uint[2**100]) x; +} +// ---- +// Warning: (17-48): Variable covers a large part of storage and thus makes collisions likely. Either use mappings or dynamic arrays and allow their size to be increased only in small quantities per transaction. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/511_library_function_without_implementation_public.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/511_library_function_without_implementation_public.sol new file mode 100644 index 00000000..fe5e4955 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/511_library_function_without_implementation_public.sol @@ -0,0 +1,4 @@ +library L { + // This can be used as an "interface", hence it is allowed. + function f() public; +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/512_library_function_without_implementation_internal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/512_library_function_without_implementation_internal.sol new file mode 100644 index 00000000..d5dfb260 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/512_library_function_without_implementation_internal.sol @@ -0,0 +1,5 @@ +library L { + function f() internal; +} +// ---- +// TypeError: (16-38): Internal library function must be implemented if declared. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/513_library_function_without_implementation_private.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/513_library_function_without_implementation_private.sol new file mode 100644 index 00000000..70585e8c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/513_library_function_without_implementation_private.sol @@ -0,0 +1,5 @@ +library L { + function f() private; +} +// ---- +// TypeError: (16-37): Internal library function must be implemented if declared. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/514_using_for_with_non_library.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/514_using_for_with_non_library.sol new file mode 100644 index 00000000..7e9612d0 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/514_using_for_with_non_library.sol @@ -0,0 +1,10 @@ +// This tests a crash that was resolved by making the first error fatal. +library L { + struct S { uint d; } + using S for S; + function f(S memory _s) internal { + _s.d = 1; + } +} +// ---- +// TypeError: (120-121): Library name expected. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/515_experimental_pragma_empty.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/515_experimental_pragma_empty.sol new file mode 100644 index 00000000..66afb7a2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/515_experimental_pragma_empty.sol @@ -0,0 +1,3 @@ +pragma experimental; +// ---- +// SyntaxError: (0-20): Experimental feature name is missing. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/516_experimental_pragma_unknown_number_literal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/516_experimental_pragma_unknown_number_literal.sol new file mode 100644 index 00000000..445c6f54 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/516_experimental_pragma_unknown_number_literal.sol @@ -0,0 +1,3 @@ +pragma experimental 123; +// ---- +// SyntaxError: (0-24): Unsupported experimental feature name. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/517_experimental_pragma_unknown_string_literal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/517_experimental_pragma_unknown_string_literal.sol new file mode 100644 index 00000000..48d8b968 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/517_experimental_pragma_unknown_string_literal.sol @@ -0,0 +1,3 @@ +pragma experimental unsupportedName; +// ---- +// SyntaxError: (0-36): Unsupported experimental feature name. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/518_experimental_pragma_unknown_quoted_string_literal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/518_experimental_pragma_unknown_quoted_string_literal.sol new file mode 100644 index 00000000..6405f062 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/518_experimental_pragma_unknown_quoted_string_literal.sol @@ -0,0 +1,3 @@ +pragma experimental "unsupportedName"; +// ---- +// SyntaxError: (0-38): Unsupported experimental feature name. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/519_experimental_pragma_empy_string_literal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/519_experimental_pragma_empy_string_literal.sol new file mode 100644 index 00000000..1a1fde9c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/519_experimental_pragma_empy_string_literal.sol @@ -0,0 +1,3 @@ +pragma experimental ""; +// ---- +// SyntaxError: (0-23): Empty experimental feature name is invalid. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/520_experimental_pragma_multiple_same_line.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/520_experimental_pragma_multiple_same_line.sol new file mode 100644 index 00000000..2eb2bf2a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/520_experimental_pragma_multiple_same_line.sol @@ -0,0 +1,3 @@ +pragma experimental unsupportedName unsupportedName; +// ---- +// SyntaxError: (0-52): Stray arguments. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/521_experimental_pragma_test_warning.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/521_experimental_pragma_test_warning.sol new file mode 100644 index 00000000..5f6962f4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/521_experimental_pragma_test_warning.sol @@ -0,0 +1,3 @@ +pragma experimental __test; +// ---- +// Warning: (0-27): Experimental features are turned on. Do not use experimental features on live deployments. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/522_experimental_pragma_duplicate.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/522_experimental_pragma_duplicate.sol new file mode 100644 index 00000000..ba772a21 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/522_experimental_pragma_duplicate.sol @@ -0,0 +1,5 @@ +pragma experimental __test; +pragma experimental __test; +// ---- +// Warning: (0-27): Experimental features are turned on. Do not use experimental features on live deployments. +// SyntaxError: (28-55): Duplicate experimental feature name. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/523_reject_interface_creation.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/523_reject_interface_creation.sol new file mode 100644 index 00000000..35bba5b3 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/523_reject_interface_creation.sol @@ -0,0 +1,8 @@ +interface I {} +contract C { + function f() public { + new I(); + } +} +// ---- +// TypeError: (62-67): Cannot instantiate an interface. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/524_accept_library_creation.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/524_accept_library_creation.sol new file mode 100644 index 00000000..6a5e97af --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/524_accept_library_creation.sol @@ -0,0 +1,6 @@ +library L {} +contract C { + function f() public { + new L(); + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/525_reject_interface_constructors.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/525_reject_interface_constructors.sol new file mode 100644 index 00000000..ad08eca6 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/525_reject_interface_constructors.sol @@ -0,0 +1,4 @@ +interface I {} +contract C is I(2) {} +// ---- +// TypeError: (29-33): Wrong argument count for constructor call: 1 arguments given but expected 0. Remove parentheses if you do not want to provide arguments here. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/526_fallback_marked_external.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/526_fallback_marked_external.sol new file mode 100644 index 00000000..6ac551e1 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/526_fallback_marked_external.sol @@ -0,0 +1,3 @@ +contract C { + function () external { } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/527_fallback_marked_internal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/527_fallback_marked_internal.sol new file mode 100644 index 00000000..b8e1c654 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/527_fallback_marked_internal.sol @@ -0,0 +1,5 @@ +contract C { + function () internal { } +} +// ---- +// TypeError: (17-41): Fallback function must be defined as "external". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/528_fallback_marked_private.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/528_fallback_marked_private.sol new file mode 100644 index 00000000..6038a99f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/528_fallback_marked_private.sol @@ -0,0 +1,5 @@ +contract C { + function () private { } +} +// ---- +// TypeError: (17-40): Fallback function must be defined as "external". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/529_fallback_marked_public.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/529_fallback_marked_public.sol new file mode 100644 index 00000000..d9c1580f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/529_fallback_marked_public.sol @@ -0,0 +1,5 @@ +contract C { + function () public { } +} +// ---- +// TypeError: (17-39): Fallback function must be defined as "external". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/530_tuple_invalid_literal_too_large_for_uint.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/530_tuple_invalid_literal_too_large_for_uint.sol new file mode 100644 index 00000000..bbfe2206 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/530_tuple_invalid_literal_too_large_for_uint.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + uint x; + (x, ) = (1E111); + } +} +// ---- +// TypeError: (76-83): Type int_const 1000...(104 digits omitted)...0000 is not implicitly convertible to expected type tuple(uint256,). diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/531_tuple_invalid_literal_too_large_unassigned.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/531_tuple_invalid_literal_too_large_unassigned.sol new file mode 100644 index 00000000..6b9cbf79 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/531_tuple_invalid_literal_too_large_unassigned.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + uint x; + (x, ) = (1, 1E111); + } +} +// ---- +// TypeError: (80-85): Invalid rational number. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/532_tuple_invalid_literal_too_large_for_uint_multi.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/532_tuple_invalid_literal_too_large_for_uint_multi.sol new file mode 100644 index 00000000..a26f9c04 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/532_tuple_invalid_literal_too_large_for_uint_multi.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + uint x; + (x, ) = (1E111, 1); + } +} +// ---- +// TypeError: (77-82): Invalid rational number. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/533_tuple_invalid_literal_too_large_exp.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/533_tuple_invalid_literal_too_large_exp.sol new file mode 100644 index 00000000..9384ec53 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/533_tuple_invalid_literal_too_large_exp.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public { + (2**270, 1); + } +} +// ---- +// TypeError: (53-59): Invalid rational number. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/534_tuple_invalid_literal_too_large_expression.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/534_tuple_invalid_literal_too_large_expression.sol new file mode 100644 index 00000000..3c322444 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/534_tuple_invalid_literal_too_large_expression.sol @@ -0,0 +1,7 @@ +contract C { + function f() pure public { + ((2**270) / 2**100, 1); + } +} +// ---- +// Warning: (52-74): Statement has no effect. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol new file mode 100644 index 00000000..157ea36b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol @@ -0,0 +1,18 @@ +contract C { + function balance() public returns (uint) { + this.balance; // to avoid pureness warning + return 1; + } + function transfer(uint amount) public { + address(this).transfer(amount); // to avoid pureness warning + } +} +contract D { + function f() public { + uint x = (new C()).balance(); + x; + (new C()).transfer(5); + } +} +// ---- +// Warning: (17-134): Function state mutability can be restricted to view diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/536_array_length_invalid_expression_negative_bool.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/536_array_length_invalid_expression_negative_bool.sol new file mode 100644 index 00000000..c92861eb --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/536_array_length_invalid_expression_negative_bool.sol @@ -0,0 +1,5 @@ +contract C { + uint[-true] ids; +} +// ---- +// TypeError: (22-27): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/537_array_length_invalid_expression_int_divides_bool.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/537_array_length_invalid_expression_int_divides_bool.sol new file mode 100644 index 00000000..92e3c3cf --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/537_array_length_invalid_expression_int_divides_bool.sol @@ -0,0 +1,5 @@ +contract C { + uint[true/1] ids; +} +// ---- +// TypeError: (22-28): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/538_array_length_invalid_expression_bool_divides_int.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/538_array_length_invalid_expression_bool_divides_int.sol new file mode 100644 index 00000000..26add45c --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/538_array_length_invalid_expression_bool_divides_int.sol @@ -0,0 +1,5 @@ +contract C { + uint[1/true] ids; +} +// ---- +// TypeError: (22-28): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/539_array_length_invalid_expression_scientific_literal.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/539_array_length_invalid_expression_scientific_literal.sol new file mode 100644 index 00000000..a0d58f4a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/539_array_length_invalid_expression_scientific_literal.sol @@ -0,0 +1,5 @@ +contract C { + uint[1.111111E1111111111111] ids; +} +// ---- +// TypeError: (22-44): Invalid array length, expected integer literal or constant expression. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/540_array_length_invalid_expression_division_by_zero.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/540_array_length_invalid_expression_division_by_zero.sol new file mode 100644 index 00000000..38a80867 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/540_array_length_invalid_expression_division_by_zero.sol @@ -0,0 +1,5 @@ +contract C { + uint[3/0] ids; +} +// ---- +// TypeError: (22-25): Operator / not compatible with types int_const 3 and int_const 0 diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/541_warn_about_address_members_on_contract_balance.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/541_warn_about_address_members_on_contract_balance.sol new file mode 100644 index 00000000..4acb0dc2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/541_warn_about_address_members_on_contract_balance.sol @@ -0,0 +1,7 @@ +contract C { + function f() view public { + this.balance; + } +} +// ---- +// Warning: (52-64): Using contract member "balance" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).balance" instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/542_warn_about_address_members_on_contract_transfer.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/542_warn_about_address_members_on_contract_transfer.sol new file mode 100644 index 00000000..45ee1f5b --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/542_warn_about_address_members_on_contract_transfer.sol @@ -0,0 +1,8 @@ +contract C { + function f() view public { + this.transfer; + } +} +// ---- +// Warning: (52-65): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead. +// TypeError: (52-65): Value transfer to a contract without a payable fallback function. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/543_warn_about_address_members_on_contract_send.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/543_warn_about_address_members_on_contract_send.sol new file mode 100644 index 00000000..99b7b8b2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/543_warn_about_address_members_on_contract_send.sol @@ -0,0 +1,8 @@ +contract C { + function f() view public { + this.send; + } +} +// ---- +// Warning: (52-61): Using contract member "send" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).send" instead. +// TypeError: (52-61): Value transfer to a contract without a payable fallback function. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/544_warn_about_address_members_on_contract_call.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/544_warn_about_address_members_on_contract_call.sol new file mode 100644 index 00000000..446410ba --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/544_warn_about_address_members_on_contract_call.sol @@ -0,0 +1,7 @@ +contract C { + function f() view public { + this.call; + } +} +// ---- +// Warning: (52-61): Using contract member "call" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).call" instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/545_warn_about_address_members_on_contract_callcode.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/545_warn_about_address_members_on_contract_callcode.sol new file mode 100644 index 00000000..43ee4d88 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/545_warn_about_address_members_on_contract_callcode.sol @@ -0,0 +1,8 @@ +contract C { + function f() view public { + this.callcode; + } +} +// ---- +// Warning: (52-65): Using contract member "callcode" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).callcode" instead. +// TypeError: (52-65): "callcode" has been deprecated in favour of "delegatecall". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/546_warn_about_address_members_on_contract_delegatecall.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/546_warn_about_address_members_on_contract_delegatecall.sol new file mode 100644 index 00000000..7cbd832a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/546_warn_about_address_members_on_contract_delegatecall.sol @@ -0,0 +1,7 @@ +contract C { + function f() view public { + this.delegatecall; + } +} +// ---- +// Warning: (52-69): Using contract member "delegatecall" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).delegatecall" instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/547_warn_about_address_members_on_non_this_contract_balance.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/547_warn_about_address_members_on_non_this_contract_balance.sol new file mode 100644 index 00000000..3ba59a9f --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/547_warn_about_address_members_on_non_this_contract_balance.sol @@ -0,0 +1,8 @@ +contract C { + function f() view public { + C c; + c.balance; + } +} +// ---- +// Warning: (65-74): Using contract member "balance" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).balance" instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/548_warn_about_address_members_on_non_this_contract_transfer.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/548_warn_about_address_members_on_non_this_contract_transfer.sol new file mode 100644 index 00000000..17455124 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/548_warn_about_address_members_on_non_this_contract_transfer.sol @@ -0,0 +1,9 @@ +contract C { + function f() view public { + C c; + c.transfer; + } +} +// ---- +// Warning: (65-75): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead. +// TypeError: (65-75): Value transfer to a contract without a payable fallback function. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/549_warn_about_address_members_on_non_this_contract_send.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/549_warn_about_address_members_on_non_this_contract_send.sol new file mode 100644 index 00000000..ca0630c4 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/549_warn_about_address_members_on_non_this_contract_send.sol @@ -0,0 +1,9 @@ +contract C { + function f() view public { + C c; + c.send; + } +} +// ---- +// Warning: (65-71): Using contract member "send" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).send" instead. +// TypeError: (65-71): Value transfer to a contract without a payable fallback function. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/550_warn_about_address_members_on_non_this_contract_call.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/550_warn_about_address_members_on_non_this_contract_call.sol new file mode 100644 index 00000000..c06e0f61 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/550_warn_about_address_members_on_non_this_contract_call.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + C c; + c.call; + } +} +// ---- +// Warning: (65-71): Using contract member "call" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).call" instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/551_warn_about_address_members_on_non_this_contract_callcode.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/551_warn_about_address_members_on_non_this_contract_callcode.sol new file mode 100644 index 00000000..3c1e0280 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/551_warn_about_address_members_on_non_this_contract_callcode.sol @@ -0,0 +1,9 @@ +contract C { + function f() pure public { + C c; + c.callcode; + } +} +// ---- +// Warning: (65-75): Using contract member "callcode" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).callcode" instead. +// TypeError: (65-75): "callcode" has been deprecated in favour of "delegatecall". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/552_warn_about_address_members_on_non_this_contract_delegatecall.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/552_warn_about_address_members_on_non_this_contract_delegatecall.sol new file mode 100644 index 00000000..8e286945 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/552_warn_about_address_members_on_non_this_contract_delegatecall.sol @@ -0,0 +1,8 @@ +contract C { + function f() pure public { + C c; + c.delegatecall; + } +} +// ---- +// Warning: (65-79): Using contract member "delegatecall" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).delegatecall" instead. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/553_no_address_members_on_contract_balance_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/553_no_address_members_on_contract_balance_v050.sol new file mode 100644 index 00000000..7c4ad16a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/553_no_address_members_on_contract_balance_v050.sol @@ -0,0 +1,8 @@ +pragma experimental "v0.5.0"; +contract C { + function f() public { + this.balance; + } +} +// ---- +// TypeError: (77-89): Member "balance" not found or not visible after argument-dependent lookup in contract C diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/554_no_address_members_on_contract_transfer_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/554_no_address_members_on_contract_transfer_v050.sol new file mode 100644 index 00000000..74bdabd2 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/554_no_address_members_on_contract_transfer_v050.sol @@ -0,0 +1,8 @@ +pragma experimental "v0.5.0"; +contract C { + function f() public { + this.transfer; + } +} +// ---- +// TypeError: (77-90): Member "transfer" not found or not visible after argument-dependent lookup in contract C diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/555_no_address_members_on_contract_send_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/555_no_address_members_on_contract_send_v050.sol new file mode 100644 index 00000000..0852e47e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/555_no_address_members_on_contract_send_v050.sol @@ -0,0 +1,8 @@ +pragma experimental "v0.5.0"; +contract C { + function f() public { + this.send; + } +} +// ---- +// TypeError: (77-86): Member "send" not found or not visible after argument-dependent lookup in contract C diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/556_no_address_members_on_contract_call_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/556_no_address_members_on_contract_call_v050.sol new file mode 100644 index 00000000..b9a226ad --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/556_no_address_members_on_contract_call_v050.sol @@ -0,0 +1,8 @@ +pragma experimental "v0.5.0"; +contract C { + function f() public { + this.call; + } +} +// ---- +// TypeError: (77-86): Member "call" not found or not visible after argument-dependent lookup in contract C diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/557_no_address_members_on_contract_callcode_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/557_no_address_members_on_contract_callcode_v050.sol new file mode 100644 index 00000000..95198a94 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/557_no_address_members_on_contract_callcode_v050.sol @@ -0,0 +1,8 @@ +pragma experimental "v0.5.0"; +contract C { + function f() public { + this.callcode; + } +} +// ---- +// TypeError: (77-90): Member "callcode" not found or not visible after argument-dependent lookup in contract C diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/558_no_address_members_on_contract_delegatecall_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/558_no_address_members_on_contract_delegatecall_v050.sol new file mode 100644 index 00000000..b7a7053e --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/558_no_address_members_on_contract_delegatecall_v050.sol @@ -0,0 +1,8 @@ +pragma experimental "v0.5.0"; +contract C { + function f() public { + this.delegatecall; + } +} +// ---- +// TypeError: (77-94): Member "delegatecall" not found or not visible after argument-dependent lookup in contract C diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/559_no_warning_for_using_members_that_look_like_address_members.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/559_no_warning_for_using_members_that_look_like_address_members.sol new file mode 100644 index 00000000..9355853a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/559_no_warning_for_using_members_that_look_like_address_members.sol @@ -0,0 +1,7 @@ +pragma experimental "v0.5.0"; +contract C { + function transfer(uint) public; + function f() public { + this.transfer(10); + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/560_event_emit_simple.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/560_event_emit_simple.sol new file mode 100644 index 00000000..445c9949 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/560_event_emit_simple.sol @@ -0,0 +1,6 @@ +contract C { + event e(); + function f() public { + emit e(); + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/561_event_emit_complex.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/561_event_emit_complex.sol new file mode 100644 index 00000000..19448615 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/561_event_emit_complex.sol @@ -0,0 +1,7 @@ +contract C { + event e(uint a, string b); + function f() public { + emit e(2, "abc"); + emit e({b: "abc", a: 8}); + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/562_event_emit_foreign_class.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/562_event_emit_foreign_class.sol new file mode 100644 index 00000000..afac609a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/562_event_emit_foreign_class.sol @@ -0,0 +1,7 @@ +contract A { event e(uint a, string b); } +contract C is A { + function f() public { + emit A.e(2, "abc"); + emit A.e({b: "abc", a: 8}); + } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/563_event_without_emit_deprecated.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/563_event_without_emit_deprecated.sol new file mode 100644 index 00000000..e9a56671 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/563_event_without_emit_deprecated.sol @@ -0,0 +1,8 @@ +contract C { + event e(); + function f() public { + e(); + } +} +// ---- +// TypeError: (62-65): Event invocations have to be prefixed by "emit". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/564_events_without_emit_deprecated_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/564_events_without_emit_deprecated_v050.sol new file mode 100644 index 00000000..e148d65a --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/564_events_without_emit_deprecated_v050.sol @@ -0,0 +1,9 @@ +pragma experimental "v0.5.0"; +contract C { + event e(); + function f() public { + e(); + } +} +// ---- +// TypeError: (92-95): Event invocations have to be prefixed by "emit". diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/567_require_visibility_specifiers_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/567_require_visibility_specifiers_v050.sol new file mode 100644 index 00000000..ec7c0937 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/567_require_visibility_specifiers_v050.sol @@ -0,0 +1,6 @@ +pragma experimental "v0.5.0"; +contract C { + function f() pure { } +} +// ---- +// SyntaxError: (47-68): No visibility specified. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/568_blockhash.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/568_blockhash.sol new file mode 100644 index 00000000..f6cc63a5 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/568_blockhash.sol @@ -0,0 +1,3 @@ +contract C { + function f() public view returns (bytes32) { return blockhash(3); } +} diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/569_block_blockhash_deprecated.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/569_block_blockhash_deprecated.sol new file mode 100644 index 00000000..b8f5d6a8 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/569_block_blockhash_deprecated.sol @@ -0,0 +1,7 @@ +contract C { + function f() public view returns (bytes32) { + return block.blockhash(3); + } +} +// ---- +// TypeError: (77-92): "block.blockhash()" has been deprecated in favor of "blockhash()" diff --git a/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol b/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol index 626e865e..4c1f96e6 100644 --- a/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol +++ b/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol @@ -1,8 +1,6 @@ contract c { - function f() { c[10] a = 7; uint8[10 * 2] x; } + function f() public { c[10] storage a = 7; uint8[10 * 2] storage x; } } // ---- -// Warning: (32-39): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning. -// Warning: (45-60): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning. -// TypeError: (32-43): Type int_const 7 is not implicitly convertible to expected type contract c[10] storage pointer. -// Warning: (45-60): Uninitialized storage pointer. Did you mean '<type> memory x'? +// TypeError: (39-58): Type int_const 7 is not implicitly convertible to expected type contract c[10] storage pointer. +// DeclarationError: (60-83): Uninitialized storage pointer. diff --git a/test/libsolidity/syntaxTests/parsing/calling_function.sol b/test/libsolidity/syntaxTests/parsing/calling_function.sol index 4c4fc1fc..9e88c451 100644 --- a/test/libsolidity/syntaxTests/parsing/calling_function.sol +++ b/test/libsolidity/syntaxTests/parsing/calling_function.sol @@ -1,9 +1,7 @@ contract test { - function f() { + function f() public { function() returns(function() returns(function() returns(function() returns(uint)))) x; uint y; y = x()()()(); } } -// ---- -// Warning: (20-175): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/conditional_multiple.sol b/test/libsolidity/syntaxTests/parsing/conditional_multiple.sol index c7d11ed6..0e348f5b 100644 --- a/test/libsolidity/syntaxTests/parsing/conditional_multiple.sol +++ b/test/libsolidity/syntaxTests/parsing/conditional_multiple.sol @@ -1,9 +1,8 @@ contract A { - function f() { + function f() public { uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6; } } // ---- -// Warning: (17-93): No visibility specified. Defaulting to "public". -// Warning: (40-46): Unused local variable. -// Warning: (17-93): Function state mutability can be restricted to pure +// Warning: (47-53): Unused local variable. +// Warning: (17-100): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/conditional_true_false_literal.sol b/test/libsolidity/syntaxTests/parsing/conditional_true_false_literal.sol index 90974e96..40aaa917 100644 --- a/test/libsolidity/syntaxTests/parsing/conditional_true_false_literal.sol +++ b/test/libsolidity/syntaxTests/parsing/conditional_true_false_literal.sol @@ -1,11 +1,10 @@ contract A { - function f() { + function f() public { uint x = true ? 1 : 0; uint y = false ? 0 : 1; } } // ---- -// Warning: (17-100): No visibility specified. Defaulting to "public". -// Warning: (40-46): Unused local variable. -// Warning: (71-77): Unused local variable. -// Warning: (17-100): Function state mutability can be restricted to pure +// Warning: (47-53): Unused local variable. +// Warning: (78-84): Unused local variable. +// Warning: (17-107): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/conditional_with_assignment.sol b/test/libsolidity/syntaxTests/parsing/conditional_with_assignment.sol index 6f8040d6..7489aaf9 100644 --- a/test/libsolidity/syntaxTests/parsing/conditional_with_assignment.sol +++ b/test/libsolidity/syntaxTests/parsing/conditional_with_assignment.sol @@ -1,11 +1,8 @@ contract A { - function f() { + function f() public pure { uint y = 1; - uint x = 3 < 0 ? x = 3 : 6; + uint x = 3 < 0 ? y = 3 : 6; true ? x = 3 : 4; } } // ---- -// Warning: (17-119): No visibility specified. Defaulting to "public". -// Warning: (40-46): Unused local variable. -// Warning: (17-119): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/conditional_with_constants.sol b/test/libsolidity/syntaxTests/parsing/conditional_with_constants.sol index 35da69c6..705fbadf 100644 --- a/test/libsolidity/syntaxTests/parsing/conditional_with_constants.sol +++ b/test/libsolidity/syntaxTests/parsing/conditional_with_constants.sol @@ -1,11 +1,10 @@ contract A { - function f() { + function f() public { uint x = 3 > 0 ? 3 : 0; uint y = (3 > 0) ? 3 : 0; } } // ---- -// Warning: (17-103): No visibility specified. Defaulting to "public". -// Warning: (40-46): Unused local variable. -// Warning: (72-78): Unused local variable. -// Warning: (17-103): Function state mutability can be restricted to pure +// Warning: (47-53): Unused local variable. +// Warning: (79-85): Unused local variable. +// Warning: (17-110): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/conditional_with_variables.sol b/test/libsolidity/syntaxTests/parsing/conditional_with_variables.sol index eb4c7091..bbabf957 100644 --- a/test/libsolidity/syntaxTests/parsing/conditional_with_variables.sol +++ b/test/libsolidity/syntaxTests/parsing/conditional_with_variables.sol @@ -1,5 +1,5 @@ contract A { - function f() { + function f() public { uint x = 3; uint y = 1; uint z = (x > y) ? x : y; @@ -7,7 +7,6 @@ contract A { } } // ---- -// Warning: (17-143): No visibility specified. Defaulting to "public". -// Warning: (80-86): Unused local variable. -// Warning: (114-120): Unused local variable. -// Warning: (17-143): Function state mutability can be restricted to pure +// Warning: (87-93): Unused local variable. +// Warning: (121-127): Unused local variable. +// Warning: (17-150): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/constant_state_modifier.sol b/test/libsolidity/syntaxTests/parsing/constant_state_modifier.sol index da068351..8fddc988 100644 --- a/test/libsolidity/syntaxTests/parsing/constant_state_modifier.sol +++ b/test/libsolidity/syntaxTests/parsing/constant_state_modifier.sol @@ -1,7 +1,8 @@ contract C { uint s; - // this test should fail starting from 0.5.0 function f() public constant returns (uint) { return s; } } +// ---- +// ParserError: (43-51): The state mutability modifier "constant" was removed in version 0.5.0. Use "view" or "pure" instead. diff --git a/test/libsolidity/syntaxTests/parsing/declaring_fixed_and_ufixed_variables.sol b/test/libsolidity/syntaxTests/parsing/declaring_fixed_and_ufixed_variables.sol index 8be9667a..6d88669a 100644 --- a/test/libsolidity/syntaxTests/parsing/declaring_fixed_and_ufixed_variables.sol +++ b/test/libsolidity/syntaxTests/parsing/declaring_fixed_and_ufixed_variables.sol @@ -1,14 +1,13 @@ contract A { fixed40x40 storeMe; - function f(ufixed x, fixed32x32 y) { + function f(ufixed x, fixed32x32 y) public { ufixed8x8 a; fixed b; } } // ---- -// Warning: (41-121): No visibility specified. Defaulting to "public". // Warning: (52-60): Unused function parameter. Remove or comment out the variable name to silence this warning. // Warning: (62-74): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (86-97): Unused local variable. -// Warning: (107-114): Unused local variable. -// Warning: (41-121): Function state mutability can be restricted to pure +// Warning: (93-104): Unused local variable. +// Warning: (114-121): Unused local variable. +// Warning: (41-128): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/else_if_statement.sol b/test/libsolidity/syntaxTests/parsing/else_if_statement.sol index 727e6115..c2a1aaeb 100644 --- a/test/libsolidity/syntaxTests/parsing/else_if_statement.sol +++ b/test/libsolidity/syntaxTests/parsing/else_if_statement.sol @@ -1,8 +1,7 @@ contract test { - function fun(uint256 a) returns (address b) { + function fun(uint256 a) public returns (uint8 b) { if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78; } } // ---- -// Warning: (20-142): No visibility specified. Defaulting to "public". -// Warning: (20-142): Function state mutability can be restricted to pure +// Warning: (20-147): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/empty_function.sol b/test/libsolidity/syntaxTests/parsing/empty_function.sol index 218fd9a7..320a0bcc 100644 --- a/test/libsolidity/syntaxTests/parsing/empty_function.sol +++ b/test/libsolidity/syntaxTests/parsing/empty_function.sol @@ -1,10 +1,9 @@ contract test { uint256 stateVar; - function functionName(bytes20 arg1, address addr) view returns (int id) { } + function functionName(bytes20 arg1, address addr) public view returns (int id) { } } // ---- -// Warning: (36-111): No visibility specified. Defaulting to "public". // Warning: (58-70): Unused function parameter. Remove or comment out the variable name to silence this warning. // Warning: (72-84): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (100-106): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (36-111): Function state mutability can be restricted to pure +// Warning: (107-113): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (36-118): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/enum_valid_declaration.sol b/test/libsolidity/syntaxTests/parsing/enum_valid_declaration.sol index 4c4a1217..606f59d7 100644 --- a/test/libsolidity/syntaxTests/parsing/enum_valid_declaration.sol +++ b/test/libsolidity/syntaxTests/parsing/enum_valid_declaration.sol @@ -1,10 +1,7 @@ contract c { enum validEnum { Value1, Value2, Value3, Value4 } - function c() { + constructor() public { a = validEnum.Value3; } validEnum a; } -// ---- -// Warning: (71-121): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. -// Warning: (71-121): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/exp_expression.sol b/test/libsolidity/syntaxTests/parsing/exp_expression.sol index cdabb996..6b307ea0 100644 --- a/test/libsolidity/syntaxTests/parsing/exp_expression.sol +++ b/test/libsolidity/syntaxTests/parsing/exp_expression.sol @@ -1,9 +1,8 @@ contract test { - function fun(uint256 a) { + function fun(uint256 a) public { uint256 x = 3 ** a; } } // ---- -// Warning: (20-79): No visibility specified. Defaulting to "public". -// Warning: (54-63): Unused local variable. -// Warning: (20-79): Function state mutability can be restricted to pure +// Warning: (61-70): Unused local variable. +// Warning: (20-86): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/fallback_function.sol b/test/libsolidity/syntaxTests/parsing/fallback_function.sol index de32b030..054f57de 100644 --- a/test/libsolidity/syntaxTests/parsing/fallback_function.sol +++ b/test/libsolidity/syntaxTests/parsing/fallback_function.sol @@ -1,5 +1,4 @@ contract c { - function() { } + function() external { } } // ---- -// Warning: (17-31): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol b/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol index bd86f2f5..fce669dd 100644 --- a/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol +++ b/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol @@ -1,5 +1,5 @@ contract test { - function fun(uint256 a) { + function fun(uint256 a) public { uint256 i =0; for (i = 0; i < 10; i++) { uint256 x = i; break; continue; @@ -7,7 +7,6 @@ contract test { } } // ---- -// Warning: (20-162): No visibility specified. Defaulting to "public". // Warning: (33-42): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (115-124): Unused local variable. -// Warning: (20-162): Function state mutability can be restricted to pure +// Warning: (122-131): Unused local variable. +// Warning: (20-169): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol b/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol index 4a27e0fb..4adf0948 100644 --- a/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol +++ b/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol @@ -1,5 +1,5 @@ contract test { - function fun(uint256 a) { + function fun(uint256 a) public { uint256 i =0; for (;;) { uint256 x = i; break; continue; @@ -7,7 +7,6 @@ contract test { } } // ---- -// Warning: (24-170): No visibility specified. Defaulting to "public". // Warning: (37-46): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (115-124): Unused local variable. -// Warning: (24-170): Function state mutability can be restricted to pure +// Warning: (122-131): Unused local variable. +// Warning: (24-177): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_single_stmt_body.sol b/test/libsolidity/syntaxTests/parsing/for_loop_single_stmt_body.sol index 3df88ef5..c6af519c 100644 --- a/test/libsolidity/syntaxTests/parsing/for_loop_single_stmt_body.sol +++ b/test/libsolidity/syntaxTests/parsing/for_loop_single_stmt_body.sol @@ -1,11 +1,10 @@ contract test { - function fun(uint256 a) { + function fun(uint256 a) public { uint256 i = 0; for (i = 0; i < 10; i++) continue; } } // ---- -// Warning: (20-129): No visibility specified. Defaulting to "public". // Warning: (33-42): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (20-129): Function state mutability can be restricted to pure +// Warning: (20-136): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol b/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol index a7c5e8bb..c22ae42f 100644 --- a/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol +++ b/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol @@ -1,12 +1,11 @@ contract test { - function fun(uint256 a) { + function fun(uint256 a) public { for (uint256 i = 0; i < 10; i++) { uint256 x = i; break; continue; } } } // ---- -// Warning: (20-148): No visibility specified. Defaulting to "public". // Warning: (33-42): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (101-110): Unused local variable. -// Warning: (20-148): Function state mutability can be restricted to pure +// Warning: (108-117): Unused local variable. +// Warning: (20-155): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/function_no_body.sol b/test/libsolidity/syntaxTests/parsing/function_no_body.sol index 0424ebd8..c4a686dc 100644 --- a/test/libsolidity/syntaxTests/parsing/function_no_body.sol +++ b/test/libsolidity/syntaxTests/parsing/function_no_body.sol @@ -1,5 +1,3 @@ contract test { - function functionName(bytes32 input) returns (bytes32 out); + function functionName(bytes32 input) public returns (bytes32 out); } -// ---- -// Warning: (17-76): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/function_normal_comments.sol b/test/libsolidity/syntaxTests/parsing/function_normal_comments.sol index c7a023ac..94e1e60a 100644 --- a/test/libsolidity/syntaxTests/parsing/function_normal_comments.sol +++ b/test/libsolidity/syntaxTests/parsing/function_normal_comments.sol @@ -1,10 +1,9 @@ contract test { uint256 stateVar; // We won't see this comment - function functionName(bytes32 input) returns (bytes32 out) {} + function functionName(bytes32 input) public returns (bytes32 out) {} } // ---- -// Warning: (75-136): No visibility specified. Defaulting to "public". // Warning: (97-110): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (121-132): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (75-136): Function state mutability can be restricted to pure +// Warning: (128-139): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (75-143): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/function_type_as_storage_variable_with_assignment.sol b/test/libsolidity/syntaxTests/parsing/function_type_as_storage_variable_with_assignment.sol index 3b784733..11e77f25 100644 --- a/test/libsolidity/syntaxTests/parsing/function_type_as_storage_variable_with_assignment.sol +++ b/test/libsolidity/syntaxTests/parsing/function_type_as_storage_variable_with_assignment.sol @@ -1,10 +1,9 @@ contract test { - function f(uint x, uint y) returns (uint a) {} + function f(uint x, uint y) public returns (uint a) {} function (uint, uint) internal returns (uint) f1 = f; } // ---- -// Warning: (20-66): No visibility specified. Defaulting to "public". // Warning: (31-37): Unused function parameter. Remove or comment out the variable name to silence this warning. // Warning: (39-45): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (56-62): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (20-66): Function state mutability can be restricted to pure +// Warning: (63-69): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (20-73): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/function_type_in_expression.sol b/test/libsolidity/syntaxTests/parsing/function_type_in_expression.sol index fd6447c7..3defb5ea 100644 --- a/test/libsolidity/syntaxTests/parsing/function_type_in_expression.sol +++ b/test/libsolidity/syntaxTests/parsing/function_type_in_expression.sol @@ -1,15 +1,13 @@ contract test { - function f(uint x, uint y) returns (uint a) {} - function g() { + function f(uint x, uint y) public returns (uint a) {} + function g() public { function (uint, uint) internal returns (uint) f1 = f; } } // ---- -// Warning: (20-66): No visibility specified. Defaulting to "public". // Warning: (31-37): Unused function parameter. Remove or comment out the variable name to silence this warning. // Warning: (39-45): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (56-62): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (71-153): No visibility specified. Defaulting to "public". -// Warning: (94-142): Unused local variable. -// Warning: (20-66): Function state mutability can be restricted to pure -// Warning: (71-153): Function state mutability can be restricted to pure +// Warning: (63-69): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (108-156): Unused local variable. +// Warning: (20-73): Function state mutability can be restricted to pure +// Warning: (78-167): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/function_type_in_struct.sol b/test/libsolidity/syntaxTests/parsing/function_type_in_struct.sol index d3c84678..c7703b47 100644 --- a/test/libsolidity/syntaxTests/parsing/function_type_in_struct.sol +++ b/test/libsolidity/syntaxTests/parsing/function_type_in_struct.sol @@ -1,6 +1,6 @@ contract test { struct S { - function (uint x, uint y) internal returns (uint a) f; + function (uint x, uint y) internal returns (uint) f; function (uint, uint) external returns (uint) g; uint d; } @@ -8,4 +8,3 @@ contract test { // ---- // Warning: (49-55): Naming function type parameters is deprecated. // Warning: (57-63): Naming function type parameters is deprecated. -// Warning: (83-89): Naming function type return parameters is deprecated. diff --git a/test/libsolidity/syntaxTests/parsing/if_statement.sol b/test/libsolidity/syntaxTests/parsing/if_statement.sol index 0819cb9f..b3269785 100644 --- a/test/libsolidity/syntaxTests/parsing/if_statement.sol +++ b/test/libsolidity/syntaxTests/parsing/if_statement.sol @@ -1,11 +1,8 @@ contract test { - function fun(uint256 a) returns (uint) { - if (a >= 8) { return 2; } else { var b = 7; } + function fun(uint256 a) public returns (uint) { + if (a >= 8) { return 2; } else { uint b = 7; } } } // ---- -// Warning: (102-107): Use of the "var" keyword is deprecated. -// Warning: (102-111): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (20-120): No visibility specified. Defaulting to "public". -// Warning: (102-107): Unused local variable. -// Warning: (20-120): Function state mutability can be restricted to pure +// Warning: (109-115): Unused local variable. +// Warning: (20-128): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/inline_array_declaration.sol b/test/libsolidity/syntaxTests/parsing/inline_array_declaration.sol index f42f8f16..4730f950 100644 --- a/test/libsolidity/syntaxTests/parsing/inline_array_declaration.sol +++ b/test/libsolidity/syntaxTests/parsing/inline_array_declaration.sol @@ -1,9 +1,8 @@ contract c { uint[] a; - function f() returns (uint, uint) { + function f() public returns (uint, uint) { a = [1,2,3]; return (a[3], [2,3,4][0]); } } // ---- -// Warning: (31-128): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/interface_basic.sol b/test/libsolidity/syntaxTests/parsing/interface_basic.sol index c25b48ba..2363eaa8 100644 --- a/test/libsolidity/syntaxTests/parsing/interface_basic.sol +++ b/test/libsolidity/syntaxTests/parsing/interface_basic.sol @@ -1,6 +1,5 @@ interface Interface { - function f(); + function f() public; } // ---- -// Warning: (23-36): Functions in interfaces should be declared external. -// Warning: (23-36): No visibility specified. Defaulting to "public". In interfaces it defaults to external. +// Warning: (23-43): Functions in interfaces should be declared external. diff --git a/test/libsolidity/syntaxTests/parsing/library_simple.sol b/test/libsolidity/syntaxTests/parsing/library_simple.sol index fcf2638e..006ff307 100644 --- a/test/libsolidity/syntaxTests/parsing/library_simple.sol +++ b/test/libsolidity/syntaxTests/parsing/library_simple.sol @@ -1,6 +1,5 @@ library Lib { - function f() { } + function f() public { } } // ---- -// Warning: (18-34): No visibility specified. Defaulting to "public". -// Warning: (18-34): Function state mutability can be restricted to pure +// Warning: (18-41): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol index 452b52c7..64116b88 100644 --- a/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol +++ b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol @@ -1,5 +1,5 @@ contract c { - function f() + function f() public { a = 1 wei; b = 2 szabo; @@ -12,5 +12,4 @@ contract c { uint256 d; } // ---- -// Warning: (163-172): This declaration shadows an existing declaration. -// Warning: (17-128): No visibility specified. Defaulting to "public". +// Warning: (170-179): This declaration shadows an existing declaration. diff --git a/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol index d2cdc875..2f2302ed 100644 --- a/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol +++ b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol @@ -1,10 +1,7 @@ contract c { - function c () + constructor() public { a = 1 wei * 100 wei + 7 szabo - 3; } uint256 a; } -// ---- -// Warning: (17-86): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. -// Warning: (17-86): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/location_specifiers_for_locals.sol b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_locals.sol index 5d6c8dc5..38de7b1c 100644 --- a/test/libsolidity/syntaxTests/parsing/location_specifiers_for_locals.sol +++ b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_locals.sol @@ -1,12 +1,9 @@ contract Foo { - function f() { - uint[] storage x; + uint[] m_x; + function f() public view { + uint[] storage x = m_x; uint[] memory y; + x; y; } } // ---- -// Warning: (42-58): Uninitialized storage pointer. -// Warning: (19-90): No visibility specified. Defaulting to "public". -// Warning: (42-58): Unused local variable. -// Warning: (68-83): Unused local variable. -// Warning: (19-90): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/location_specifiers_for_params.sol b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_params.sol index e021182a..72b6ce84 100644 --- a/test/libsolidity/syntaxTests/parsing/location_specifiers_for_params.sol +++ b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_params.sol @@ -2,4 +2,4 @@ contract Foo { function f(uint[] storage constant x, uint[] memory y) internal { } } // ---- -// TypeError: (30-55): Storage location has to be "memory" (or unspecified) for constants. +// TypeError: (30-55): Data location has to be "memory" (or unspecified) for constants. diff --git a/test/libsolidity/syntaxTests/parsing/modifier.sol b/test/libsolidity/syntaxTests/parsing/modifier.sol index 3e659dcf..b995ce89 100644 --- a/test/libsolidity/syntaxTests/parsing/modifier.sol +++ b/test/libsolidity/syntaxTests/parsing/modifier.sol @@ -1,3 +1,3 @@ contract c { - modifier mod { if (msg.sender == 0) _; } + modifier mod { if (msg.sender == 0x0000000000000000000000000000000000000000) _; } } diff --git a/test/libsolidity/syntaxTests/parsing/modifier_invocation.sol b/test/libsolidity/syntaxTests/parsing/modifier_invocation.sol index cb2f2985..cf986efe 100644 --- a/test/libsolidity/syntaxTests/parsing/modifier_invocation.sol +++ b/test/libsolidity/syntaxTests/parsing/modifier_invocation.sol @@ -1,8 +1,7 @@ contract c { modifier mod1(uint a) { if (msg.sender == address(a)) _; } modifier mod2 { if (msg.sender == address(2)) _; } - function f() mod1(7) mod2 { } + function f() public mod1(7) mod2 { } } // ---- -// Warning: (135-164): No visibility specified. Defaulting to "public". -// Warning: (135-164): Function state mutability can be restricted to view +// Warning: (135-171): Function state mutability can be restricted to view diff --git a/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol b/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol index 818999df..56c2e280 100644 --- a/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol +++ b/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol @@ -1,29 +1,13 @@ contract C { - function f() { - var (a,b,c) = g(); - var (d) = 2; - var (,e) = 3; - var (f,) = 4; - var (x,,) = g(); - var (,y,) = g(); - var () = g(); - var (,,) = g(); + function f() pure public { + (uint a, uint b, uint c) = g(); + (uint d) = 2; + (, uint e) = (3,4); + (uint h,) = (4,5); + (uint x,,) = g(); + (, uint y,) = g(); + a; b; c; d; e; h; x; y; } - function g() returns (uint, uint, uint) {} + function g() pure public returns (uint, uint, uint) {} } // ---- -// Warning: (36-37): Use of the "var" keyword is deprecated. -// Warning: (38-39): Use of the "var" keyword is deprecated. -// Warning: (40-41): Use of the "var" keyword is deprecated. -// Warning: (57-58): Use of the "var" keyword is deprecated. -// Warning: (73-74): Use of the "var" keyword is deprecated. -// Warning: (88-89): Use of the "var" keyword is deprecated. -// Warning: (104-105): Use of the "var" keyword is deprecated. -// Warning: (124-125): Use of the "var" keyword is deprecated. -// Warning: (88-89): This declaration shadows an existing declaration. -// Warning: (52-63): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (67-79): Different number of components on the left hand side (2) than on the right hand side (1). -// Warning: (67-79): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (83-95): Different number of components on the left hand side (2) than on the right hand side (1). -// Warning: (83-95): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. -// TypeError: (137-149): Too many components (3) in value for variable assignment (0) needed diff --git a/test/libsolidity/syntaxTests/parsing/multiple_functions_natspec_documentation.sol b/test/libsolidity/syntaxTests/parsing/multiple_functions_natspec_documentation.sol index 95a4d1e7..85d9e6a8 100644 --- a/test/libsolidity/syntaxTests/parsing/multiple_functions_natspec_documentation.sol +++ b/test/libsolidity/syntaxTests/parsing/multiple_functions_natspec_documentation.sol @@ -1,28 +1,24 @@ contract test { uint256 stateVar; /// This is test function 1 - function functionName1(bytes32 input) returns (bytes32 out) {} + function functionName1(bytes32 input) public returns (bytes32 out) {} /// This is test function 2 - function functionName2(bytes32 input) returns (bytes32 out) {} + function functionName2(bytes32 input) public returns (bytes32 out) {} // nothing to see here - function functionName3(bytes32 input) returns (bytes32 out) {} + function functionName3(bytes32 input) public returns (bytes32 out) {} /// This is test function 4 - function functionName4(bytes32 input) returns (bytes32 out) {} + function functionName4(bytes32 input) public returns (bytes32 out) {} } // ---- -// Warning: (74-136): No visibility specified. Defaulting to "public". // Warning: (97-110): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (121-132): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (173-235): No visibility specified. Defaulting to "public". -// Warning: (196-209): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (220-231): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (267-329): No visibility specified. Defaulting to "public". -// Warning: (290-303): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (314-325): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (366-428): No visibility specified. Defaulting to "public". -// Warning: (389-402): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (413-424): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (74-136): Function state mutability can be restricted to pure -// Warning: (173-235): Function state mutability can be restricted to pure -// Warning: (267-329): Function state mutability can be restricted to pure -// Warning: (366-428): Function state mutability can be restricted to pure +// Warning: (128-139): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (203-216): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (234-245): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (304-317): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (335-346): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (410-423): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (441-452): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (74-143): Function state mutability can be restricted to pure +// Warning: (180-249): Function state mutability can be restricted to pure +// Warning: (281-350): Function state mutability can be restricted to pure +// Warning: (387-456): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/no_function_params.sol b/test/libsolidity/syntaxTests/parsing/no_function_params.sol index 020f1233..5a024bdb 100644 --- a/test/libsolidity/syntaxTests/parsing/no_function_params.sol +++ b/test/libsolidity/syntaxTests/parsing/no_function_params.sol @@ -1,7 +1,6 @@ contract test { uint256 stateVar; - function functionName() {} + function functionName() public {} } // ---- -// Warning: (36-62): No visibility specified. Defaulting to "public". -// Warning: (36-62): Function state mutability can be restricted to pure +// Warning: (36-69): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/overloaded_functions.sol b/test/libsolidity/syntaxTests/parsing/overloaded_functions.sol index 1a78d155..fe050d1b 100644 --- a/test/libsolidity/syntaxTests/parsing/overloaded_functions.sol +++ b/test/libsolidity/syntaxTests/parsing/overloaded_functions.sol @@ -1,9 +1,7 @@ contract test { - function fun(uint a) returns(uint r) { return a; } - function fun(uint a, uint b) returns(uint r) { return a + b; } + function fun(uint a) public returns(uint r) { return a; } + function fun(uint a, uint b) public returns(uint r) { return a + b; } } // ---- -// Warning: (17-67): No visibility specified. Defaulting to "public". -// Warning: (69-131): No visibility specified. Defaulting to "public". -// Warning: (17-67): Function state mutability can be restricted to pure -// Warning: (69-131): Function state mutability can be restricted to pure +// Warning: (17-74): Function state mutability can be restricted to pure +// Warning: (76-145): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/placeholder_in_function_context.sol b/test/libsolidity/syntaxTests/parsing/placeholder_in_function_context.sol index 72546dc0..a50855c0 100644 --- a/test/libsolidity/syntaxTests/parsing/placeholder_in_function_context.sol +++ b/test/libsolidity/syntaxTests/parsing/placeholder_in_function_context.sol @@ -1,11 +1,8 @@ contract c { - function fun() returns (uint r) { - var _ = 8; + function fun() public returns (uint r) { + uint _ = 8; return _ + 1; } } // ---- -// Warning: (59-64): Use of the "var" keyword is deprecated. -// Warning: (59-68): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (17-97): No visibility specified. Defaulting to "public". -// Warning: (17-97): Function state mutability can be restricted to pure +// Warning: (17-105): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/single_function_param.sol b/test/libsolidity/syntaxTests/parsing/single_function_param.sol index 08e531f1..955f20f0 100644 --- a/test/libsolidity/syntaxTests/parsing/single_function_param.sol +++ b/test/libsolidity/syntaxTests/parsing/single_function_param.sol @@ -1,9 +1,8 @@ contract test { uint256 stateVar; - function functionName(bytes32 input) returns (bytes32 out) {} + function functionName(bytes32 input) public returns (bytes32 out) {} } // ---- -// Warning: (36-97): No visibility specified. Defaulting to "public". // Warning: (58-71): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (82-93): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (36-97): Function state mutability can be restricted to pure +// Warning: (89-100): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (36-104): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/trailing_dot1.sol b/test/libsolidity/syntaxTests/parsing/trailing_dot1.sol new file mode 100644 index 00000000..7f26242c --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/trailing_dot1.sol @@ -0,0 +1,7 @@ +contract test { + uint256 a = 2.2e10; + uint256 b = .5E10; + uint256 c = 4.e-2; +} +// ---- +// TypeError: (70-73): Member "e" not found or not visible after argument-dependent lookup in int_const 4 diff --git a/test/libsolidity/syntaxTests/parsing/trailing_dot2.sol b/test/libsolidity/syntaxTests/parsing/trailing_dot2.sol new file mode 100644 index 00000000..38a7ab2d --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/trailing_dot2.sol @@ -0,0 +1,7 @@ +contract test { + uint256 a = 2.2e10; + uint256 b = .5E10; + uint256 c = 2 + 2.; +} +// ---- +// ParserError: (76-77): Expected identifier but got ';' diff --git a/test/libsolidity/syntaxTests/parsing/trailing_dot3.sol b/test/libsolidity/syntaxTests/parsing/trailing_dot3.sol new file mode 100644 index 00000000..6a126cb3 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/trailing_dot3.sol @@ -0,0 +1,4 @@ +contract test { + uint a = 2. +// ---- +// ParserError: (29-29): Expected identifier but got end of source diff --git a/test/libsolidity/syntaxTests/parsing/tuples.sol b/test/libsolidity/syntaxTests/parsing/tuples.sol index 6f739740..875556e9 100644 --- a/test/libsolidity/syntaxTests/parsing/tuples.sol +++ b/test/libsolidity/syntaxTests/parsing/tuples.sol @@ -1,24 +1,11 @@ contract C { - function f() { + function f() public pure { uint a = (1); - var (b,) = (1,); - var (c,d) = (1, 2 + a); - var (e,) = (1, 2, b); + (uint b,) = (1,2); + (uint c, uint d) = (1, 2 + a); + (uint e,) = (1, b); (a) = 3; + a;b;c;d;e; } } // ---- -// Warning: (52-53): Use of the "var" keyword is deprecated. -// Warning: (71-72): Use of the "var" keyword is deprecated. -// Warning: (73-74): Use of the "var" keyword is deprecated. -// Warning: (97-98): Use of the "var" keyword is deprecated. -// Warning: (47-62): Different number of components on the left hand side (2) than on the right hand side (1). -// Warning: (47-62): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (66-88): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (92-112): Different number of components on the left hand side (2) than on the right hand side (3). -// Warning: (92-112): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (14-127): No visibility specified. Defaulting to "public". -// Warning: (71-72): Unused local variable. -// Warning: (73-74): Unused local variable. -// Warning: (97-98): Unused local variable. -// Warning: (14-127): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/two_exact_functions.sol b/test/libsolidity/syntaxTests/parsing/two_exact_functions.sol index 0b3dda56..957740d0 100644 --- a/test/libsolidity/syntaxTests/parsing/two_exact_functions.sol +++ b/test/libsolidity/syntaxTests/parsing/two_exact_functions.sol @@ -2,8 +2,8 @@ // we can't determine whether they match exactly, however // it will throw DeclarationError in following stage. contract test { - function fun(uint a) returns(uint r) { return a; } - function fun(uint a) returns(uint r) { return a; } + function fun(uint a) public returns(uint r) { return a; } + function fun(uint a) public returns(uint r) { return a; } } // ---- -// DeclarationError: (189-239): Function with same name and arguments defined twice. +// DeclarationError: (189-246): Function with same name and arguments defined twice. diff --git a/test/libsolidity/syntaxTests/parsing/unary_plus_expression.sol b/test/libsolidity/syntaxTests/parsing/unary_plus_expression.sol new file mode 100644 index 00000000..5646c43b --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/unary_plus_expression.sol @@ -0,0 +1,8 @@ +contract test { + function f(uint x) pure public { + uint y = +x; + y; + } +} +// ---- +// SyntaxError: (70-72): Use of unary + is disallowed. diff --git a/test/libsolidity/syntaxTests/parsing/visibility_specifiers.sol b/test/libsolidity/syntaxTests/parsing/visibility_specifiers.sol index 4706a26d..db890b37 100644 --- a/test/libsolidity/syntaxTests/parsing/visibility_specifiers.sol +++ b/test/libsolidity/syntaxTests/parsing/visibility_specifiers.sol @@ -3,15 +3,12 @@ contract c { uint internal b; uint public c; uint d; - function f() {} + function f() public {} function f_priv() private {} - function f_public() public {} function f_internal() internal {} } // ---- // Warning: (58-71): This declaration shadows an existing declaration. -// Warning: (89-104): No visibility specified. Defaulting to "public". -// Warning: (89-104): Function state mutability can be restricted to pure -// Warning: (109-137): Function state mutability can be restricted to pure -// Warning: (142-171): Function state mutability can be restricted to pure -// Warning: (176-209): Function state mutability can be restricted to pure +// Warning: (89-111): Function state mutability can be restricted to pure +// Warning: (116-144): Function state mutability can be restricted to pure +// Warning: (149-182): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/while_loop.sol b/test/libsolidity/syntaxTests/parsing/while_loop.sol index 129b52e1..dbb00a69 100644 --- a/test/libsolidity/syntaxTests/parsing/while_loop.sol +++ b/test/libsolidity/syntaxTests/parsing/while_loop.sol @@ -1,9 +1,7 @@ contract test { - function fun(uint256 a) { - while (true) { uint256 x = 1; break; continue; } x = 9; + function fun() public pure { + uint256 x; + while (true) { x = 1; break; continue; } x = 9; } } // ---- -// Warning: (20-115): No visibility specified. Defaulting to "public". -// Warning: (33-42): Unused function parameter. Remove or comment out the variable name to silence this warning. -// Warning: (20-115): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol index d90ec2d7..36bae6a8 100644 --- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol +++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol @@ -5,4 +5,5 @@ contract test { } } // ---- -// DeclarationError: (77-83): Identifier already declared. +// Warning: (57-63): Unused local variable. +// Warning: (77-83): Unused local variable. diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol deleted file mode 100644 index 06bfe7be..00000000 --- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol +++ /dev/null @@ -1,10 +0,0 @@ -pragma experimental "v0.5.0"; -contract test { - function f() pure public { - { uint x; } - { uint x; } - } -} -// ---- -// Warning: (87-93): Unused local variable. -// Warning: (107-113): Unused local variable. diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol index 1a5ff2f9..0c03ec3e 100644 --- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol +++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol @@ -5,4 +5,5 @@ contract test { } } // ---- -// DeclarationError: (75-81): Identifier already declared. +// Warning: (57-63): Unused local variable. +// Warning: (75-81): Unused local variable. diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol deleted file mode 100644 index 20ea0349..00000000 --- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol +++ /dev/null @@ -1,10 +0,0 @@ -pragma experimental "v0.5.0"; -contract test { - function f() pure public { - { uint x; } - uint x; - } -} -// ---- -// Warning: (87-93): Unused local variable. -// Warning: (105-111): Unused local variable. diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_same_and_disjoint_scope.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_same_and_disjoint_scope.sol new file mode 100644 index 00000000..45c5ff2d --- /dev/null +++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_same_and_disjoint_scope.sol @@ -0,0 +1,10 @@ +contract test { + function f() pure public { + uint x; + { uint x; } + uint x; + } +} +// ---- +// Warning: (73-79): This declaration shadows an existing declaration. +// DeclarationError: (91-97): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_same_scope.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_same_scope.sol new file mode 100644 index 00000000..72c31f73 --- /dev/null +++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_same_scope.sol @@ -0,0 +1,8 @@ +contract test { + function f() pure public { + uint x; + uint x; + } +} +// ---- +// DeclarationError: (71-77): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/scoping/poly_variable_declaration_same_scope.sol b/test/libsolidity/syntaxTests/scoping/poly_variable_declaration_same_scope.sol new file mode 100644 index 00000000..e414f611 --- /dev/null +++ b/test/libsolidity/syntaxTests/scoping/poly_variable_declaration_same_scope.sol @@ -0,0 +1,16 @@ +contract test { + function f() pure public { + uint x; + uint x; + uint x; + uint x; + uint x; + uint x; + } +} +// ---- +// DeclarationError: (71-77): Identifier already declared. +// DeclarationError: (87-93): Identifier already declared. +// DeclarationError: (103-109): Identifier already declared. +// DeclarationError: (119-125): Identifier already declared. +// DeclarationError: (135-141): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/scoping/scoping.sol b/test/libsolidity/syntaxTests/scoping/scoping.sol index 34b055d9..dae5a42d 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping.sol @@ -1,4 +1,3 @@ -pragma experimental "v0.5.0"; contract test { function f() public { { @@ -8,4 +7,4 @@ contract test { } } // ---- -// DeclarationError: (123-124): Undeclared identifier. +// DeclarationError: (93-94): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/scoping/scoping_activation.sol b/test/libsolidity/syntaxTests/scoping/scoping_activation.sol index 7334bc49..8522a0e3 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_activation.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_activation.sol @@ -1,4 +1,3 @@ -pragma experimental "v0.5.0"; contract test { function f() pure public { x = 3; @@ -6,4 +5,4 @@ contract test { } } // ---- -// DeclarationError: (85-86): Undeclared identifier. Did you mean "x"? +// DeclarationError: (55-56): Undeclared identifier. "x" is not (or not yet) visible at this point. diff --git a/test/libsolidity/syntaxTests/scoping/scoping_activation_old.sol b/test/libsolidity/syntaxTests/scoping/scoping_activation_old.sol index d893a889..8522a0e3 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_activation_old.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_activation_old.sol @@ -4,3 +4,5 @@ contract test { uint x; } } +// ---- +// DeclarationError: (55-56): Undeclared identifier. "x" is not (or not yet) visible at this point. diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for.sol b/test/libsolidity/syntaxTests/scoping/scoping_for.sol index 6e5b7095..a882d1ca 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_for.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_for.sol @@ -1,4 +1,3 @@ -pragma experimental "v0.5.0"; contract test { function f() pure public { for (uint x = 0; x < 10; x ++){ diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for2.sol b/test/libsolidity/syntaxTests/scoping/scoping_for2.sol index eb74b8ab..f8c5c19b 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_for2.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_for2.sol @@ -1,4 +1,3 @@ -pragma experimental "v0.5.0"; contract test { function f() pure public { for (uint x = 0; x < 10; x ++) diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for3.sol b/test/libsolidity/syntaxTests/scoping/scoping_for3.sol index 1814cb47..81e34562 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_for3.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_for3.sol @@ -1,4 +1,3 @@ -pragma experimental "v0.5.0"; contract test { function f() pure public { for (uint x = 0; x < 10; x ++){ @@ -8,4 +7,4 @@ contract test { } } // ---- -// DeclarationError: (154-155): Undeclared identifier. +// DeclarationError: (124-125): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol b/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol index 3e80b385..28b88525 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol @@ -1,4 +1,3 @@ -pragma experimental "v0.5.0"; contract test { function f() pure public { for (;; y++){ @@ -7,4 +6,4 @@ contract test { } } // ---- -// DeclarationError: (93-94): Undeclared identifier. +// DeclarationError: (63-64): Undeclared identifier. diff --git a/test/libsolidity/syntaxTests/scoping/scoping_old.sol b/test/libsolidity/syntaxTests/scoping/scoping_old.sol index 83f6b60b..70e5ee0c 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_old.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_old.sol @@ -4,3 +4,5 @@ contract test { uint256 x = 2; } } +// ---- +// DeclarationError: (55-56): Undeclared identifier. "x" is not (or not yet) visible at this point. diff --git a/test/libsolidity/syntaxTests/scoping/scoping_self_use.sol b/test/libsolidity/syntaxTests/scoping/scoping_self_use.sol index 9e2c0171..a5087c57 100644 --- a/test/libsolidity/syntaxTests/scoping/scoping_self_use.sol +++ b/test/libsolidity/syntaxTests/scoping/scoping_self_use.sol @@ -3,3 +3,5 @@ contract test { uint a = a; } } +// ---- +// DeclarationError: (64-65): Undeclared identifier. "a" is not (or not yet) visible at this point. diff --git a/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol b/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol deleted file mode 100644 index ab3dcefb..00000000 --- a/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol +++ /dev/null @@ -1,8 +0,0 @@ -pragma experimental "v0.5.0"; -contract test { - function f() pure public { - uint a = a; - } -} -// ---- -// DeclarationError: (94-95): Undeclared identifier. Did you mean "a"? diff --git a/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol b/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol index a6ee4bf1..c17d0849 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol @@ -7,9 +7,6 @@ contract C { function g(bytes32) pure internal {} } // ---- -// Warning: (54-72): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (54-72): The provided argument of type uint256 is not implicitly convertible to expected type bytes memory. -// Warning: (85-100): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (85-100): The provided argument of type uint256 is not implicitly convertible to expected type bytes memory. -// Warning: (113-131): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (113-131): The provided argument of type uint256 is not implicitly convertible to expected type bytes memory. +// TypeError: (64-71): Invalid type for argument in function call. Invalid implicit conversion from uint256 to bytes memory requested. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. +// TypeError: (92-99): Invalid type for argument in function call. Invalid implicit conversion from uint256 to bytes memory requested. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. +// TypeError: (123-130): Invalid type for argument in function call. Invalid implicit conversion from uint256 to bytes memory requested. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol index b94a4391..a30e428a 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol @@ -1,6 +1,6 @@ contract C { function f() public pure { - bytes32 h = keccak256(abi.encodePacked(keccak256, f, this.f.gas, block.blockhash)); + bytes32 h = keccak256(abi.encodePacked(keccak256, f, this.f.gas, blockhash)); h; } } @@ -8,4 +8,4 @@ contract C { // TypeError: (91-100): This type cannot be encoded. // TypeError: (102-103): This type cannot be encoded. // TypeError: (105-115): This type cannot be encoded. -// TypeError: (117-132): This type cannot be encoded. +// TypeError: (117-126): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol index f1b5606e..c97f588e 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol @@ -1,13 +1,13 @@ contract C { function f() public pure { - bool a = address(this).call(address(this).delegatecall, super); - bool b = address(this).delegatecall(log0, tx, mulmod); + bool a = address(this).call(abi.encode(address(this).delegatecall, super)); + bool b = address(this).delegatecall(abi.encode(log0, tx, mulmod)); a; b; } } // ---- -// TypeError: (80-106): This type cannot be encoded. -// TypeError: (108-113): This type cannot be encoded. -// TypeError: (160-164): This type cannot be encoded. -// TypeError: (166-168): This type cannot be encoded. -// TypeError: (170-176): This type cannot be encoded. +// TypeError: (91-117): This type cannot be encoded. +// TypeError: (119-124): This type cannot be encoded. +// TypeError: (183-187): This type cannot be encoded. +// TypeError: (189-191): This type cannot be encoded. +// TypeError: (193-199): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol index 05f5db0b..a1d3f5af 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol @@ -4,11 +4,10 @@ contract C { struct T { uint y; } T t; function f() public view { - bytes32 a = sha256(s, t); + bytes32 a = sha256(abi.encodePacked(s, t)); a; } } // ---- -// Warning: (132-144): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// TypeError: (139-140): This type cannot be encoded. -// TypeError: (142-143): This type cannot be encoded. +// TypeError: (156-157): This type cannot be encoded. +// TypeError: (159-160): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol index 977a7d73..38702825 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol @@ -6,12 +6,11 @@ contract C { struct T { uint y; } T t; function f() public view { - bytes32 a = sha256(s, t); + bytes32 a = sha256(abi.encodePacked(s, t)); a; } } // ---- // Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. -// Warning: (167-179): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// TypeError: (174-175): This type cannot be encoded. -// TypeError: (177-178): This type cannot be encoded. +// TypeError: (191-192): This type cannot be encoded. +// TypeError: (194-195): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol index d10c1718..b50d4449 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol @@ -1,17 +1,17 @@ contract C { struct S { uint x; } S s; - struct T { } + struct T { uint y; } T t; enum A { X, Y } function f() public pure { - bool a = address(this).delegatecall(S, A, A.X, T, uint, uint[]); + bytes memory a = abi.encodePacked(S, A, A.X, T, uint, uint[]); + a; } } // ---- -// Warning: (51-63): Defining empty structs is deprecated. -// TypeError: (168-169): This type cannot be encoded. -// TypeError: (171-172): This type cannot be encoded. -// TypeError: (179-180): This type cannot be encoded. -// TypeError: (182-186): This type cannot be encoded. -// TypeError: (188-194): This type cannot be encoded. +// TypeError: (174-175): This type cannot be encoded. +// TypeError: (177-178): This type cannot be encoded. +// TypeError: (185-186): This type cannot be encoded. +// TypeError: (188-192): This type cannot be encoded. +// TypeError: (194-200): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol b/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol index 895bb6c5..e8ece3bc 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol @@ -9,7 +9,7 @@ contract C { struct W { uint x; } - function f(T) public pure { } + function f(T memory) public pure { } } // ---- // Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. diff --git a/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol b/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol index 96362ef0..e9b25453 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol @@ -9,7 +9,7 @@ contract TestContract SubStruct subStruct1; SubStruct subStruct2; } - function addTestStruct(TestStruct) public pure {} + function addTestStruct(TestStruct memory) public pure {} } // ---- // Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. diff --git a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol index 4966a731..89d1ddd9 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol @@ -1,6 +1,6 @@ contract C { struct S { uint a; S[] sub; } - function f() public pure returns (uint, S) { + function f() public pure returns (uint, S memory) { } } // ---- diff --git a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol index 68113924..1c31e180 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol @@ -1,6 +1,6 @@ contract C { struct S { uint a; S[2][] sub; } - function f() public pure returns (uint, S) { + function f() public pure returns (uint, S memory) { } } // ---- diff --git a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol index 47690d9b..0a5b1bc8 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol @@ -1,8 +1,8 @@ contract C { struct S { uint a; S[][][] sub; } struct T { S s; } - function f() public pure returns (uint x, T t) { + function f() public pure returns (uint x, T memory t) { } } // ---- -// TypeError: (119-122): Internal or recursive type is not allowed for public or external functions. +// TypeError: (119-129): Internal or recursive type is not allowed for public or external functions. diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_dynamic_array.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_dynamic_array.sol new file mode 100644 index 00000000..d847f17c --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_dynamic_array.sol @@ -0,0 +1,7 @@ +contract Test { + struct MyStructName { + address addr; + MyStructName[] x; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_fixed_array.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_fixed_array.sol new file mode 100644 index 00000000..126dda4f --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_fixed_array.sol @@ -0,0 +1,8 @@ +contract Test { + struct MyStructName { + address addr; + MyStructName[1] x; + } +} +// ---- +// TypeError: (20-96): Recursive struct definition. diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_complex.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_complex.sol new file mode 100644 index 00000000..6d35a5d3 --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_complex.sol @@ -0,0 +1,18 @@ +contract Test { + struct MyStructName1 { + address addr; + uint256 count; + MyStructName4[1] x; + } + struct MyStructName2 { + MyStructName1 x; + } + struct MyStructName3 { + MyStructName2[1] x; + } + struct MyStructName4 { + MyStructName3 x; + } +} +// ---- +// TypeError: (20-121): Recursive struct definition. diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array1.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array1.sol new file mode 100644 index 00000000..10d7de2c --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array1.sol @@ -0,0 +1,11 @@ +contract Test { + struct MyStructName1 { + address addr; + uint256 count; + MyStructName2[] x; + } + struct MyStructName2 { + MyStructName1 x; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array2.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array2.sol new file mode 100644 index 00000000..f20510ca --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array2.sol @@ -0,0 +1,11 @@ +contract Test { + struct MyStructName1 { + address addr; + uint256 count; + MyStructName2 x; + } + struct MyStructName2 { + MyStructName1[] x; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array3.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array3.sol new file mode 100644 index 00000000..69747e71 --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array3.sol @@ -0,0 +1,11 @@ +contract Test { + struct MyStructName1 { + address addr; + uint256 count; + MyStructName2[] x; + } + struct MyStructName2 { + MyStructName1[] x; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_multi_array.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_multi_array.sol new file mode 100644 index 00000000..b3507828 --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_multi_array.sol @@ -0,0 +1,21 @@ +contract Test { + struct S1 { + S2[1][] x; + } + struct S2 { + S1 x; + } + struct T1 { + T2[][1] x; + } + struct T2 { + T1 x; + } + struct R1 { + R2[][] x; + } + struct R2 { + R1 x; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array1.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array1.sol new file mode 100644 index 00000000..2c0b90ec --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array1.sol @@ -0,0 +1,12 @@ +contract Test { + struct MyStructName1 { + address addr; + uint256 count; + MyStructName2[1] x; + } + struct MyStructName2 { + MyStructName1 x; + } +} +// ---- +// TypeError: (20-121): Recursive struct definition. diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array2.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array2.sol new file mode 100644 index 00000000..3178e569 --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array2.sol @@ -0,0 +1,12 @@ +contract Test { + struct MyStructName1 { + address addr; + uint256 count; + MyStructName2 x; + } + struct MyStructName2 { + MyStructName1[1] x; + } +} +// ---- +// TypeError: (20-118): Recursive struct definition. diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array3.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array3.sol new file mode 100644 index 00000000..e34cf9bc --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array3.sol @@ -0,0 +1,12 @@ +contract Test { + struct MyStructName1 { + address addr; + uint256 count; + MyStructName2[1] x; + } + struct MyStructName2 { + MyStructName1[1] x; + } +} +// ---- +// TypeError: (20-121): Recursive struct definition. diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_multi_array.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_multi_array.sol new file mode 100644 index 00000000..ed659b6e --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_multi_array.sol @@ -0,0 +1,12 @@ +contract Test { + struct MyStructName1 { + address addr; + uint256 count; + MyStructName2[1][1] x; + } + struct MyStructName2 { + MyStructName1 x; + } +} +// ---- +// TypeError: (20-124): Recursive struct definition. diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive_array.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive_array.sol new file mode 100644 index 00000000..b2053b8a --- /dev/null +++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive_array.sol @@ -0,0 +1,4 @@ +contract Test { + struct S1 { uint a; } + struct S2 { S1[1] x; S1[1] y; } +} diff --git a/test/libsolidity/syntaxTests/tight_packing_literals.sol b/test/libsolidity/syntaxTests/tight_packing_literals.sol index a190adc3..0fc1fc08 100644 --- a/test/libsolidity/syntaxTests/tight_packing_literals.sol +++ b/test/libsolidity/syntaxTests/tight_packing_literals.sol @@ -1,33 +1,8 @@ contract C { - function f() pure public returns (bytes32) { - return keccak256(1); - } - function g() pure public returns (bytes32) { - return sha3(1); - } - function h() pure public returns (bytes32) { - return sha256(1); - } - function j() pure public returns (bytes32) { - return ripemd160(1); - } - function k() pure public returns (bytes) { + function k() pure public returns (bytes memory) { return abi.encodePacked(1); } } // ---- -// Warning: (87-88): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (77-89): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (77-89): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory. -// Warning: (161-168): "sha3" has been deprecated in favour of "keccak256" -// Warning: (166-167): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (161-168): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (161-168): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory. -// Warning: (247-248): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (240-249): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (240-249): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory. -// Warning: (331-332): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning. -// Warning: (321-333): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (321-333): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory. -// Warning: (420-421): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning. +// TypeError: (99-100): Cannot perform packed encoding for a literal. Please convert it to an explicit type first. diff --git a/test/libsolidity/syntaxTests/tight_packing_literals_050.sol b/test/libsolidity/syntaxTests/tight_packing_literals_050.sol deleted file mode 100644 index b7557d2a..00000000 --- a/test/libsolidity/syntaxTests/tight_packing_literals_050.sol +++ /dev/null @@ -1,34 +0,0 @@ -pragma experimental "v0.5.0"; -contract C { - function f() pure public returns (bytes32) { - return keccak256(1); - } - function g() pure public returns (bytes32) { - return sha3(1); - } - function h() pure public returns (bytes32) { - return sha256(1); - } - function j() pure public returns (bytes32) { - return ripemd160(1); - } - function k() pure public returns (bytes) { - return abi.encodePacked(1); - } -} - -// ---- -// TypeError: (117-118): Cannot perform packed encoding for a literal. Please convert it to an explicit type first. -// TypeError: (107-119): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// TypeError: (107-119): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory. -// TypeError: (191-198): "sha3" has been deprecated in favour of "keccak256" -// TypeError: (196-197): Cannot perform packed encoding for a literal. Please convert it to an explicit type first. -// TypeError: (191-198): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// TypeError: (191-198): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory. -// TypeError: (277-278): Cannot perform packed encoding for a literal. Please convert it to an explicit type first. -// TypeError: (270-279): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// TypeError: (270-279): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory. -// TypeError: (361-362): Cannot perform packed encoding for a literal. Please convert it to an explicit type first. -// TypeError: (351-363): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// TypeError: (351-363): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory. -// TypeError: (450-451): Cannot perform packed encoding for a literal. Please convert it to an explicit type first. diff --git a/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol b/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol index 2b9b688a..45fc1f72 100644 --- a/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol +++ b/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol @@ -1,30 +1,9 @@ contract C { - function f() pure public returns (bytes32) { - return keccak256(uint8(1)); - } - function g() pure public returns (bytes32) { - return sha3(uint8(1)); - } - function h() pure public returns (bytes32) { - return sha256(uint8(1)); - } - function j() pure public returns (bytes32) { - return ripemd160(uint8(1)); - } - function k() pure public returns (bytes) { + function k() pure public returns (bytes memory) { return abi.encodePacked(uint8(1)); } - function l() pure public returns (bytes) { + function l() pure public returns (bytes memory) { return abi.encode(1); } } // ---- -// Warning: (77-96): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (77-96): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory. -// Warning: (168-182): "sha3" has been deprecated in favour of "keccak256" -// Warning: (168-182): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (168-182): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory. -// Warning: (254-270): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (254-270): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory. -// Warning: (342-361): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. -// Warning: (342-361): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory. diff --git a/test/libsolidity/syntaxTests/tupleAssignments/err_fill_assignment.sol b/test/libsolidity/syntaxTests/tupleAssignments/err_fill_assignment.sol new file mode 100644 index 00000000..32b381bb --- /dev/null +++ b/test/libsolidity/syntaxTests/tupleAssignments/err_fill_assignment.sol @@ -0,0 +1,11 @@ +contract C { + function f() public pure returns (uint, uint, bytes32) { + uint a; + bytes32 b; + (a,) = f(); + (,b) = f(); + } +} +// ---- +// TypeError: (103-106): Type tuple(uint256,uint256,bytes32) is not implicitly convertible to expected type tuple(uint256,). +// TypeError: (117-120): Type tuple(uint256,uint256,bytes32) is not implicitly convertible to expected type tuple(,bytes32). diff --git a/test/libsolidity/syntaxTests/tupleAssignments/warn_multiple_storage_storage_copies_fill_left.sol b/test/libsolidity/syntaxTests/tupleAssignments/err_multiple_storage_storage_copies_fill_left.sol index b2979804..902d8b98 100644 --- a/test/libsolidity/syntaxTests/tupleAssignments/warn_multiple_storage_storage_copies_fill_left.sol +++ b/test/libsolidity/syntaxTests/tupleAssignments/err_multiple_storage_storage_copies_fill_left.sol @@ -6,5 +6,5 @@ contract C { } } // ---- +// TypeError: (89-101): Type tuple(int_const 1,int_const 2,struct C.S storage ref,struct C.S storage ref) is not implicitly convertible to expected type tuple(,struct C.S storage ref,struct C.S storage ref). // Warning: (79-101): This assignment performs two copies to storage. Since storage copies do not first copy to a temporary location, one of them might be overwritten before the second is executed and thus may have unexpected effects. It is safer to perform the copies separately or assign to storage pointers first. -// Warning: (79-101): Different number of components on the left hand side (3) than on the right hand side (4). diff --git a/test/libsolidity/syntaxTests/tupleAssignments/warn_multiple_storage_storage_copies_fill_right.sol b/test/libsolidity/syntaxTests/tupleAssignments/err_multiple_storage_storage_copies_fill_right.sol index aa35d7d4..51556aab 100644 --- a/test/libsolidity/syntaxTests/tupleAssignments/warn_multiple_storage_storage_copies_fill_right.sol +++ b/test/libsolidity/syntaxTests/tupleAssignments/err_multiple_storage_storage_copies_fill_right.sol @@ -6,5 +6,5 @@ contract C { } } // ---- +// TypeError: (90-102): Type tuple(struct C.S storage ref,struct C.S storage ref,int_const 1,int_const 2) is not implicitly convertible to expected type tuple(struct C.S storage ref,struct C.S storage ref,). // Warning: (79-102): This assignment performs two copies to storage. Since storage copies do not first copy to a temporary location, one of them might be overwritten before the second is executed and thus may have unexpected effects. It is safer to perform the copies separately or assign to storage pointers first. -// Warning: (79-102): Different number of components on the left hand side (3) than on the right hand side (4). diff --git a/test/libsolidity/syntaxTests/tupleAssignments/error_fill.sol b/test/libsolidity/syntaxTests/tupleAssignments/error_fill.sol index 5b7f870b..ae722391 100644 --- a/test/libsolidity/syntaxTests/tupleAssignments/error_fill.sol +++ b/test/libsolidity/syntaxTests/tupleAssignments/error_fill.sol @@ -8,5 +8,5 @@ contract C { } } // ---- -// TypeError: (126-136): Different number of components on the left hand side (2) than on the right hand side (3). -// TypeError: (140-150): Different number of components on the left hand side (2) than on the right hand side (3). +// TypeError: (133-136): Type tuple(uint256,uint256,bytes32) is not implicitly convertible to expected type tuple(uint256,). +// TypeError: (147-150): Type tuple(uint256,uint256,bytes32) is not implicitly convertible to expected type tuple(,bytes32). diff --git a/test/libsolidity/syntaxTests/tupleAssignments/nowarn_explicit_singleton_token_expression.sol b/test/libsolidity/syntaxTests/tupleAssignments/nowarn_explicit_singleton_token_expression.sol deleted file mode 100644 index 3262781b..00000000 --- a/test/libsolidity/syntaxTests/tupleAssignments/nowarn_explicit_singleton_token_expression.sol +++ /dev/null @@ -1,8 +0,0 @@ -contract C { - function f() public pure { - uint a; - (a,) = (uint(1),); - } -} -// ---- -// Warning: (53-70): Different number of components on the left hand side (2) than on the right hand side (1). diff --git a/test/libsolidity/syntaxTests/tupleAssignments/warn_fill_assignment.sol b/test/libsolidity/syntaxTests/tupleAssignments/warn_fill_assignment.sol deleted file mode 100644 index a079a509..00000000 --- a/test/libsolidity/syntaxTests/tupleAssignments/warn_fill_assignment.sol +++ /dev/null @@ -1,11 +0,0 @@ -contract C { - function f() public pure returns (uint, uint, bytes32) { - uint a; - bytes32 b; - (a,) = f(); - (,b) = f(); - } -} -// ---- -// Warning: (96-106): Different number of components on the left hand side (2) than on the right hand side (3). -// Warning: (110-120): Different number of components on the left hand side (2) than on the right hand side (3). diff --git a/test/libsolidity/syntaxTests/tupleAssignments/warn_fill_vardecl.sol b/test/libsolidity/syntaxTests/tupleAssignments/warn_fill_vardecl.sol deleted file mode 100644 index 1d243c7c..00000000 --- a/test/libsolidity/syntaxTests/tupleAssignments/warn_fill_vardecl.sol +++ /dev/null @@ -1,11 +0,0 @@ -contract C { - function f() public pure returns (uint, uint, uint, uint) { - // Can later be replaced by (uint a, uint b,) = f(); - var (a,b,) = f(); - a; b; - } -} -// ---- -// Warning: (136-137): Use of the "var" keyword is deprecated. -// Warning: (138-139): Use of the "var" keyword is deprecated. -// Warning: (131-147): Different number of components on the left hand side (3) than on the right hand side (4). diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_event.sol b/test/libsolidity/syntaxTests/types/empty_tuple_event.sol index 3e40b155..24327db0 100644 --- a/test/libsolidity/syntaxTests/types/empty_tuple_event.sol +++ b/test/libsolidity/syntaxTests/types/empty_tuple_event.sol @@ -2,9 +2,8 @@ pragma solidity ^0.4.3; contract C { event SomeEvent(); function a() public { - (SomeEvent(), 7); + (emit SomeEvent(), 7); } } // ---- -// Warning: (95-106): Invoking events without "emit" prefix is deprecated. -// Warning: (95-106): Tuple component cannot be empty. +// ParserError: (95-99): Expected primary expression. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol b/test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol deleted file mode 100644 index aec5ff2a..00000000 --- a/test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol +++ /dev/null @@ -1,10 +0,0 @@ -pragma experimental "v0.5.0"; -contract C { - event SomeEvent(); - function a() public { - (SomeEvent(), 7); - } -} -// ---- -// TypeError: (101-112): Event invocations have to be prefixed by "emit". -// TypeError: (101-112): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_function.sol b/test/libsolidity/syntaxTests/types/empty_tuple_function.sol index 05b54442..ff31d440 100644 --- a/test/libsolidity/syntaxTests/types/empty_tuple_function.sol +++ b/test/libsolidity/syntaxTests/types/empty_tuple_function.sol @@ -8,5 +8,5 @@ contract C { } } // ---- -// Warning: (162-165): Tuple component cannot be empty. -// Warning: (181-184): Tuple component cannot be empty. +// TypeError: (162-165): Tuple component cannot be empty. +// TypeError: (181-184): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol b/test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol deleted file mode 100644 index c4b9e03f..00000000 --- a/test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol +++ /dev/null @@ -1,11 +0,0 @@ -pragma experimental "v0.5.0"; -contract C { - function f() private pure {} - function a() public pure { - bool x = true; - bool y = true; - (x) ? (f(), y = false) : (f(), y = false); - } -} -// ---- -// TypeError: (168-171): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol index cba30c1b..3d252f0b 100644 --- a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol +++ b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol @@ -8,6 +8,6 @@ contract C { } } // ---- -// Warning: (146-149): Tuple component cannot be empty. -// Warning: (151-154): Tuple component cannot be empty. +// TypeError: (146-149): Tuple component cannot be empty. +// TypeError: (151-154): Tuple component cannot be empty. // TypeError: (145-155): Type tuple(tuple(),tuple()) is not implicitly convertible to expected type tuple(uint256,uint256). diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol deleted file mode 100644 index b0691778..00000000 --- a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol +++ /dev/null @@ -1,11 +0,0 @@ -pragma experimental "v0.5.0"; -contract C { - function f() private pure {} - function a() public { - uint x; - uint y; - (x, y) = (f(), f()); - } -} -// ---- -// TypeError: (152-155): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/no_singleton_tuple.sol b/test/libsolidity/syntaxTests/types/no_singleton_tuple.sol new file mode 100644 index 00000000..62a58f83 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/no_singleton_tuple.sol @@ -0,0 +1,8 @@ +contract C { + function f() public pure { + uint a; + (a,) = (uint(1),); + } +} +// ---- +// TypeError: (60-70): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol b/test/libsolidity/syntaxTests/types/rational_number_exp_limit_fail.sol index 6785f580..058db2e9 100644 --- a/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol +++ b/test/libsolidity/syntaxTests/types/rational_number_exp_limit_fail.sol @@ -4,9 +4,6 @@ contract c { a = 4 ** 4 ** 2 ** 4 ** 4 ** 4 ** 4; a = -4 ** 4 ** 2 ** 4 ** 4 ** 4 ** 4 ** 4; a = 4 ** (-(2 ** 4 ** 4 ** 4 ** 4 ** 4)); - a = 0 ** 1E1233; // fine - a = 1 ** 1E1233; // fine - a = -1 ** 1E1233; // fine a = 2 ** 1E1233; a = -2 ** 1E1233; a = 2 ** -1E1233; @@ -28,23 +25,23 @@ contract c { // TypeError: (116-153): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4 // TypeError: (116-153): Type int_const 1797...(301 digits omitted)...7216 is not implicitly convertible to expected type int256. // TypeError: (167-203): Operator ** not compatible with types int_const 4 and int_const -179...(302 digits omitted)...7216 -// TypeError: (317-328): Operator ** not compatible with types int_const 2 and int_const 1000...(1226 digits omitted)...0000 -// TypeError: (342-354): Operator ** not compatible with types int_const -2 and int_const 1000...(1226 digits omitted)...0000 -// TypeError: (368-380): Operator ** not compatible with types int_const 2 and int_const -100...(1227 digits omitted)...0000 -// TypeError: (394-407): Operator ** not compatible with types int_const -2 and int_const -100...(1227 digits omitted)...0000 -// TypeError: (421-432): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 2 -// TypeError: (421-432): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256. -// TypeError: (446-458): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const 2 -// TypeError: (446-458): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256. -// TypeError: (472-484): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const -2 -// TypeError: (472-484): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256. -// TypeError: (498-511): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const -2 -// TypeError: (498-511): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256. -// TypeError: (525-541): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 1000...(1226 digits omitted)...0000 -// TypeError: (525-541): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256. -// TypeError: (555-572): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const -100...(1227 digits omitted)...0000 -// TypeError: (555-572): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256. -// TypeError: (586-603): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const 1000...(1226 digits omitted)...0000 -// TypeError: (586-603): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256. -// TypeError: (617-635): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const -100...(1227 digits omitted)...0000 -// TypeError: (617-635): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256. +// TypeError: (217-228): Operator ** not compatible with types int_const 2 and int_const 1000...(1226 digits omitted)...0000 +// TypeError: (242-254): Operator ** not compatible with types int_const -2 and int_const 1000...(1226 digits omitted)...0000 +// TypeError: (268-280): Operator ** not compatible with types int_const 2 and int_const -100...(1227 digits omitted)...0000 +// TypeError: (294-307): Operator ** not compatible with types int_const -2 and int_const -100...(1227 digits omitted)...0000 +// TypeError: (321-332): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 2 +// TypeError: (321-332): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256. +// TypeError: (346-358): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const 2 +// TypeError: (346-358): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256. +// TypeError: (372-384): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const -2 +// TypeError: (372-384): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256. +// TypeError: (398-411): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const -2 +// TypeError: (398-411): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256. +// TypeError: (425-441): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 1000...(1226 digits omitted)...0000 +// TypeError: (425-441): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256. +// TypeError: (455-472): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const -100...(1227 digits omitted)...0000 +// TypeError: (455-472): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256. +// TypeError: (486-503): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const 1000...(1226 digits omitted)...0000 +// TypeError: (486-503): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256. +// TypeError: (517-535): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const -100...(1227 digits omitted)...0000 +// TypeError: (517-535): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256. diff --git a/test/libsolidity/syntaxTests/types/rational_number_exp_limit_fine.sol b/test/libsolidity/syntaxTests/types/rational_number_exp_limit_fine.sol new file mode 100644 index 00000000..66d02eb9 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/rational_number_exp_limit_fine.sol @@ -0,0 +1,9 @@ +contract c { + function f() public pure { + int a; + a = 0 ** 1E1233; + a = 1 ** 1E1233; + a = -1 ** 1E1233; + a = 0E123456789; + } +} diff --git a/test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol b/test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol new file mode 100644 index 00000000..7ed92b58 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol @@ -0,0 +1,18 @@ +pragma solidity ^0.4.20; + +contract C { + function f() internal pure {} + function g() internal pure returns (uint) { return 1; } + function h() internal pure returns (uint, uint) { return (1, 2); } + + function test() internal pure { + var () = f(); + var () = g(); + var (,) = h(); + } +} + +// ---- +// SyntaxError: (249-261): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty. +// SyntaxError: (271-283): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty. +// SyntaxError: (293-306): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty. diff --git a/test/libsolidity/syntaxTests/types/var_type_suggest.sol b/test/libsolidity/syntaxTests/types/var_type_suggest.sol new file mode 100644 index 00000000..176fab96 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/var_type_suggest.sol @@ -0,0 +1,23 @@ +contract C { + function h() internal pure returns (uint, uint, uint) { + return (1, 2, 4); + } + function g(uint x) internal pure returns (uint) { + return x; + } + function f() internal pure { + var i = 31415; + var t = "string"; + var g2 = g; + var myblockhash = block.blockhash; + var (a, b) = (2, "troi"); + var (x,, z) = h(); + } +} +// ---- +// SyntaxError: (224-237): Use of the "var" keyword is disallowed. Use explicit declaration `uint16 i = ...´ instead. +// SyntaxError: (247-263): Use of the "var" keyword is disallowed. Use explicit declaration `string memory t = ...´ instead. +// SyntaxError: (273-283): Use of the "var" keyword is disallowed. Use explicit declaration `function (uint256) pure returns (uint256) g2 = ...´ instead. +// SyntaxError: (293-326): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax. +// SyntaxError: (336-360): Use of the "var" keyword is disallowed. Use explicit declaration `(uint8 a, string memory b) = ...´ instead. +// SyntaxError: (370-387): Use of the "var" keyword is disallowed. Use explicit declaration `(uint256 x, , uint256 z) = ...´ instead. diff --git a/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol index ca7db42e..e0e031c2 100644 --- a/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol +++ b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol @@ -1,5 +1,5 @@ contract C { - function f() pure public returns (bytes r) { + function f() pure public returns (bytes memory r) { r = abi.encode(1, 2); r = abi.encodePacked(f()); r = abi.encodeWithSelector(0x12345678, 1); diff --git a/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol index 547362c3..cc845d51 100644 --- a/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol +++ b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol @@ -3,34 +3,34 @@ contract C { function gView() public view returns (uint) { return x; } function gNonPayable() public returns (uint) { x = 4; return 0; } - function f1() view public returns (bytes) { + function f1() view public returns (bytes memory) { return abi.encode(gView()); } - function f2() view public returns (bytes) { + function f2() view public returns (bytes memory) { return abi.encodePacked(gView()); } - function f3() view public returns (bytes) { + function f3() view public returns (bytes memory) { return abi.encodeWithSelector(0x12345678, gView()); } - function f4() view public returns (bytes) { + function f4() view public returns (bytes memory) { return abi.encodeWithSignature("f(uint256)", gView()); } - function g1() public returns (bytes) { + function g1() public returns (bytes memory) { return abi.encode(gNonPayable()); } - function g2() public returns (bytes) { + function g2() public returns (bytes memory) { return abi.encodePacked(gNonPayable()); } - function g3() public returns (bytes) { + function g3() public returns (bytes memory) { return abi.encodeWithSelector(0x12345678, gNonPayable()); } - function g4() public returns (bytes) { + function g4() public returns (bytes memory) { return abi.encodeWithSignature("f(uint256)", gNonPayable()); } // This will generate the only warning. - function check() public returns (bytes) { + function check() public returns (bytes memory) { return abi.encode(2); } } // ---- -// Warning: (1044-1121): Function state mutability can be restricted to pure +// Warning: (1100-1184): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/viewPureChecker/assembly.sol b/test/libsolidity/syntaxTests/viewPureChecker/assembly.sol new file mode 100644 index 00000000..0a11dc3a --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/assembly.sol @@ -0,0 +1,23 @@ +contract C { + struct S { uint x; } + S s; + function e() pure public { + assembly { mstore(keccak256(0, 20), mul(s_slot, 2)) } + } + function f() pure public { + uint x; + assembly { x := 7 } + } + function g() view public { + assembly { for {} 1 { pop(sload(0)) } { } pop(gas) } + } + function h() view public { + assembly { function g() { pop(blockhash(20)) } } + } + function j() public { + assembly { pop(call(0, 1, 2, 3, 4, 5, 6)) } + } + function k() public { + assembly { pop(call(gas, 1, 2, 3, 4, 5, 6)) } + } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/assembly_jump_no_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/assembly_jump_no_restrict_warning.sol new file mode 100644 index 00000000..418be561 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/assembly_jump_no_restrict_warning.sol @@ -0,0 +1,7 @@ +contract C { + function k() public { + assembly { jump(2) } + } +} +// ---- +// Warning: (58-65): Jump instructions and labels are low-level EVM features that can lead to incorrect stack access. Because of that they are discouraged. Please consider using "switch", "if" or "for" statements instead. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/assembly_jump_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/assembly_jump_view_fail.sol new file mode 100644 index 00000000..c1729db7 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/assembly_jump_view_fail.sol @@ -0,0 +1,8 @@ +contract C { + function k() public view { + assembly { jump(2) } + } +} +// ---- +// Warning: (63-70): Jump instructions and labels are low-level EVM features that can lead to incorrect stack access. Because of that they are discouraged. Please consider using "switch", "if" or "for" statements instead. +// TypeError: (63-70): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol new file mode 100644 index 00000000..51e36a58 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol @@ -0,0 +1,18 @@ +contract C { + function f() public { + address(this).transfer(1); + require(address(this).send(2)); + selfdestruct(address(this)); + require(address(this).delegatecall("")); + require(address(this).call("")); + } + function g() pure public { + bytes32 x = keccak256("abc"); + bytes32 y = sha256("abc"); + address z = ecrecover(bytes32(1), uint8(2), bytes32(3), bytes32(4)); + require(true); + assert(true); + x; y; z; + } + function() payable external {} +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_restrict_warning.sol new file mode 100644 index 00000000..0b834022 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_restrict_warning.sol @@ -0,0 +1,21 @@ +contract C { + function f() view public { + bytes32 x = keccak256("abc"); + bytes32 y = sha256("abc"); + address z = ecrecover(bytes32(1), uint8(2), bytes32(3), bytes32(4)); + require(true); + assert(true); + x; y; z; + } + function g() public { + bytes32 x = keccak256("abc"); + bytes32 y = sha256("abc"); + address z = ecrecover(bytes32(1), uint8(2), bytes32(3), bytes32(4)); + require(true); + assert(true); + x; y; z; + } +} +// ---- +// Warning: (17-261): Function state mutability can be restricted to pure +// Warning: (266-505): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol new file mode 100644 index 00000000..9b00fd6d --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol @@ -0,0 +1,23 @@ +contract C { + function f() view public { + address(this).transfer(1); + } + function g() view public { + require(address(this).send(2)); + } + function h() view public { + selfdestruct(address(this)); + } + function i() view public { + require(address(this).delegatecall("")); + } + function j() view public { + require(address(this).call("")); + } +} +// ---- +// TypeError: (52-77): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError: (132-153): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError: (201-228): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError: (283-313): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError: (369-391): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol new file mode 100644 index 00000000..e21037bd --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol @@ -0,0 +1,10 @@ +contract C { + uint x; + function f() pure public { g(); } + function g() view public { x; } + function h() view public { i(); } + function i() public { x = 2; } +} +// ---- +// TypeError: (56-59): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". +// TypeError: (130-133): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol new file mode 100644 index 00000000..5aa21ce1 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol @@ -0,0 +1,6 @@ +contract C { + function g() pure public { g(); } + function f() view public returns (uint) { f(); g(); } + function h() public { h(); g(); f(); } + function i() payable public { i(); h(); g(); f(); } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/constant.sol b/test/libsolidity/syntaxTests/viewPureChecker/constant.sol new file mode 100644 index 00000000..36d93497 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/constant.sol @@ -0,0 +1,6 @@ +contract C { + uint constant x = 2; + function k() pure public returns (uint) { + return x; + } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/constant_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/constant_restrict_warning.sol new file mode 100644 index 00000000..a4b4a353 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/constant_restrict_warning.sol @@ -0,0 +1,12 @@ +contract C { + uint constant x = 2; + function f() view public returns (uint) { + return x; + } + function g() public returns (uint) { + return x; + } +} +// ---- +// Warning: (42-107): Function state mutability can be restricted to pure +// Warning: (112-172): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/viewPureChecker/creation_no_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/creation_no_restrict_warning.sol new file mode 100644 index 00000000..d80edd1b --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/creation_no_restrict_warning.sol @@ -0,0 +1,4 @@ +contract D {} +contract C { + function f() public { new D(); } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol new file mode 100644 index 00000000..08e45ea1 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol @@ -0,0 +1,6 @@ +contract D {} +contract C { + function f() public view { new D(); } +} +// ---- +// TypeError: (58-65): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/function_types.sol b/test/libsolidity/syntaxTests/viewPureChecker/function_types.sol new file mode 100644 index 00000000..92943889 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/function_types.sol @@ -0,0 +1,22 @@ +contract C { + function f() pure public { + function () external nonpayFun; + function () external view viewFun; + function () external pure pureFun; + + nonpayFun; + viewFun; + pureFun; + pureFun(); + } + function g() view public { + function () external view viewFun; + + viewFun(); + } + function h() public { + function () external nonpayFun; + + nonpayFun(); + } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol new file mode 100644 index 00000000..d00f65c9 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol @@ -0,0 +1,18 @@ +contract C { + function f() pure public { + function () external nonpayFun; + nonpayFun(); + } + function g() pure public { + function () external view viewFun; + viewFun(); + } + function h() view public { + function () external nonpayFun; + nonpayFun(); + } +} +// ---- +// TypeError: (92-103): Function declared as pure, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError: (193-202): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". +// TypeError: (289-300): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/interface.sol b/test/libsolidity/syntaxTests/viewPureChecker/interface.sol new file mode 100644 index 00000000..0874e78a --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/interface.sol @@ -0,0 +1,6 @@ +interface D { + function f() view external; +} +contract C is D { + function f() view external {} +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables.sol b/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables.sol new file mode 100644 index 00000000..7d01118a --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables.sol @@ -0,0 +1,19 @@ +contract C { + struct S { uint a; } + S s; + function f() view public { + S storage x = s; + x; + } + function g() view public { + S storage x = s; + x = s; + } + function i() public { + s.a = 2; + } + function h() public { + S storage x = s; + x.a = 2; + } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol new file mode 100644 index 00000000..0ff1ac24 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol @@ -0,0 +1,15 @@ +contract C { + struct S { uint a; } + S s; + function f() pure public { + S storage x = s; + x; + } + function g() view public { + S storage x = s; + x.a = 1; + } +} +// ---- +// TypeError: (100-101): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". +// TypeError: (184-187): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/mappings.sol b/test/libsolidity/syntaxTests/viewPureChecker/mappings.sol new file mode 100644 index 00000000..eb0ccbfb --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/mappings.sol @@ -0,0 +1,12 @@ +contract C { + mapping(uint => uint) a; + function f() view public { + a; + } + function g() view public { + a[2]; + } + function h() public { + a[2] = 3; + } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/modifiers.sol b/test/libsolidity/syntaxTests/viewPureChecker/modifiers.sol new file mode 100644 index 00000000..f8f6b2cb --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/modifiers.sol @@ -0,0 +1,17 @@ +contract D { + uint x; + modifier purem(uint) { _; } + modifier viewm(uint) { uint a = x; _; a; } + modifier nonpayablem(uint) { x = 2; _; } +} +contract C is D { + function f() purem(0) pure public {} + function g() viewm(0) view public {} + function h() nonpayablem(0) public {} + function i() purem(x) view public {} + function j() viewm(x) view public {} + function k() nonpayablem(x) public {} + function l() purem(x = 2) public {} + function m() viewm(x = 2) public {} + function n() nonpayablem(x = 2) public {} +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol new file mode 100644 index 00000000..513850f7 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol @@ -0,0 +1,12 @@ +contract D { + uint x; + modifier viewm(uint) { uint a = x; _; a; } + modifier nonpayablem(uint) { x = 2; _; } +} +contract C is D { + function f() viewm(0) pure public {} + function g() nonpayablem(0) view public {} +} +// ---- +// TypeError: (154-162): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". +// TypeError: (195-209): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/overriding_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/overriding_fail.sol new file mode 100644 index 00000000..61702495 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/overriding_fail.sol @@ -0,0 +1,16 @@ +contract D { + uint x; + function f() public view { x; } + function g() public pure {} +} +contract C1 is D { + function f() public {} + function g() public view {} +} +contract C2 is D { + function g() public {} +} +// ---- +// TypeError: (118-140): Overriding function changes state mutability from "view" to "nonpayable". +// TypeError: (145-172): Overriding function changes state mutability from "pure" to "view". +// TypeError: (198-220): Overriding function changes state mutability from "pure" to "nonpayable". diff --git a/test/libsolidity/syntaxTests/viewPureChecker/overriding_no_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/overriding_no_restrict_warning.sol new file mode 100644 index 00000000..c82c7908 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/overriding_no_restrict_warning.sol @@ -0,0 +1,7 @@ +contract D { + uint x; + function f() public { x = 2; } +} +contract C is D { + function f() public {} +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/read_storage_pure_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/read_storage_pure_fail.sol new file mode 100644 index 00000000..785656b9 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/read_storage_pure_fail.sol @@ -0,0 +1,8 @@ +contract C { + uint x; + function f() public pure returns (uint) { + return x; + } +} +// ---- +// TypeError: (86-87): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". diff --git a/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_fail.sol new file mode 100644 index 00000000..e04d0825 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_fail.sol @@ -0,0 +1,13 @@ +contract C { + struct S { uint x; } + S s; + function f() pure internal returns (S storage) { + return s; + } + function g() pure public { + f().x; + } +} +// ---- +// TypeError: (115-116): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". +// TypeError: (163-168): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". diff --git a/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_no_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_no_restrict_warning.sol new file mode 100644 index 00000000..9b4eb466 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_no_restrict_warning.sol @@ -0,0 +1,14 @@ +contract C { + struct S { uint x; } + S s; + function f() view internal returns (S storage) { + return s; + } + function g() public { + f().x = 2; + } + function h() view public { + f(); + f().x; + } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/selector.sol b/test/libsolidity/syntaxTests/viewPureChecker/selector.sol new file mode 100644 index 00000000..c4e30075 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/selector.sol @@ -0,0 +1,12 @@ +contract C { + uint public x; + function f() payable public { + } + function g() pure public returns (bytes4) { + return this.f.selector ^ this.x.selector; + } + function h() view public returns (bytes4) { + x; + return this.f.selector ^ this.x.selector; + } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/selector_complex.sol b/test/libsolidity/syntaxTests/viewPureChecker/selector_complex.sol new file mode 100644 index 00000000..311dec4a --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/selector_complex.sol @@ -0,0 +1,11 @@ +contract C { + function f(C c) pure public returns (C) { + return c; + } + function g() pure public returns (bytes4) { + // By passing `this`, we read from the state, even if f itself is pure. + return f(this).f.selector; + } +} +// ---- +// TypeError: (228-232): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". diff --git a/test/libsolidity/syntaxTests/viewPureChecker/selector_complex2.sol b/test/libsolidity/syntaxTests/viewPureChecker/selector_complex2.sol new file mode 100644 index 00000000..d1543fed --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/selector_complex2.sol @@ -0,0 +1,9 @@ +contract C { + function f() payable public returns (C) { + return this; + } + function g() pure public returns (bytes4) { + C x = C(0x123); + return x.f.selector; + } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/smoke_test.sol b/test/libsolidity/syntaxTests/viewPureChecker/smoke_test.sol new file mode 100644 index 00000000..0e397efc --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/smoke_test.sol @@ -0,0 +1,7 @@ +contract C { + uint x; + function g() pure public {} + function f() view public returns (uint) { return now; } + function h() public { x = 2; } + function i() payable public { x = 2; } +} diff --git a/test/libsolidity/syntaxTests/viewPureChecker/suggest_pure.sol b/test/libsolidity/syntaxTests/viewPureChecker/suggest_pure.sol new file mode 100644 index 00000000..87719eb3 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/suggest_pure.sol @@ -0,0 +1,5 @@ +contract C { + function g() view public { } +} +// ---- +// Warning: (17-45): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/viewPureChecker/suggest_view.sol b/test/libsolidity/syntaxTests/viewPureChecker/suggest_view.sol new file mode 100644 index 00000000..c045dfc4 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/suggest_view.sol @@ -0,0 +1,6 @@ +contract C { + uint x; + function g() public returns (uint) { return x; } +} +// ---- +// Warning: (29-77): Function state mutability can be restricted to view diff --git a/test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol new file mode 100644 index 00000000..3fed4d29 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol @@ -0,0 +1,6 @@ +contract C { + uint x; + function f() view public { x = 2; } +} +// ---- +// TypeError: (56-57): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. diff --git a/test/libsolidity/syntaxTests/visibility/function_no_visibility.sol b/test/libsolidity/syntaxTests/visibility/function_no_visibility.sol new file mode 100644 index 00000000..ecc36f04 --- /dev/null +++ b/test/libsolidity/syntaxTests/visibility/function_no_visibility.sol @@ -0,0 +1,5 @@ +contract C { + function f() pure { } +} +// ---- +// Warning: (17-38): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/visibility/function_no_visibility_050.sol b/test/libsolidity/syntaxTests/visibility/function_no_visibility_050.sol new file mode 100644 index 00000000..ec7c0937 --- /dev/null +++ b/test/libsolidity/syntaxTests/visibility/function_no_visibility_050.sol @@ -0,0 +1,6 @@ +pragma experimental "v0.5.0"; +contract C { + function f() pure { } +} +// ---- +// SyntaxError: (47-68): No visibility specified. diff --git a/test/solcjsTests.sh b/test/solcjsTests.sh index 27797cb4..e0bbc5df 100755 --- a/test/solcjsTests.sh +++ b/test/solcjsTests.sh @@ -53,6 +53,11 @@ DIR=$(mktemp -d) rm -f soljson.js cp "$SOLJSON" soljson.js + # ensure to use always 0.5.0 sources + # FIXME: should be removed once the version bump in this repo is done + rm -rf test/DAO040 + cp -R test/DAO test/DAO040 + # Update version (needed for some tests) echo "Updating package.json to version $VERSION" npm version --no-git-tag-version $VERSION diff --git a/test/tools/CMakeLists.txt b/test/tools/CMakeLists.txt index 11714017..257b4f24 100644 --- a/test/tools/CMakeLists.txt +++ b/test/tools/CMakeLists.txt @@ -1,5 +1,7 @@ add_executable(solfuzzer fuzzer.cpp) target_link_libraries(solfuzzer PRIVATE libsolc evmasm ${Boost_PROGRAM_OPTIONS_LIBRARIES} ${Boost_SYSTEM_LIBRARIES}) -add_executable(isoltest isoltest.cpp ../Options.cpp ../libsolidity/SyntaxTest.cpp ../libsolidity/AnalysisFramework.cpp) +add_executable(isoltest isoltest.cpp ../Options.cpp ../libsolidity/TestCase.cpp ../libsolidity/SyntaxTest.cpp + ../libsolidity/AnalysisFramework.cpp ../libsolidity/SolidityExecutionFramework.cpp ../ExecutionFramework.cpp + ../RPCSession.cpp) target_link_libraries(isoltest PRIVATE libsolc solidity evmasm ${Boost_PROGRAM_OPTIONS_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) diff --git a/test/tools/fuzzer.cpp b/test/tools/fuzzer.cpp index 71f38b67..a5a63854 100644 --- a/test/tools/fuzzer.cpp +++ b/test/tools/fuzzer.cpp @@ -135,6 +135,10 @@ void testCompiler(bool optimize) for (Json::Value const& error: outputJson["errors"]) { string invalid = contains(error.asString(), vector<string>{ + // StandardJSON error types + "Exception", + "InternalCompilerError", + // Old-school error messages "Internal compiler error", "Exception during compilation", "Unknown exception during compilation", diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 100fcbf0..41dff148 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -37,18 +37,22 @@ using namespace std; namespace po = boost::program_options; namespace fs = boost::filesystem; -struct SyntaxTestStats +struct TestStats { int successCount; int runCount; operator bool() const { return successCount == runCount; } }; -class SyntaxTestTool +class TestTool { public: - SyntaxTestTool(string const& _name, fs::path const& _path, bool _formatted): - m_formatted(_formatted), m_name(_name), m_path(_path) + TestTool( + TestCase::TestCaseCreator _testCaseCreator, + string const& _name, + fs::path const& _path, + bool _formatted + ): m_testCaseCreator(_testCaseCreator), m_formatted(_formatted), m_name(_name), m_path(_path) {} enum class Result @@ -60,7 +64,8 @@ public: Result process(); - static SyntaxTestStats processPath( + static TestStats processPath( + TestCase::TestCaseCreator _testCaseCreator, fs::path const& _basepath, fs::path const& _path, bool const _formatted @@ -77,68 +82,16 @@ private: Request handleResponse(bool const _exception); - void printContract() const; - + TestCase::TestCaseCreator m_testCaseCreator; bool const m_formatted; string const m_name; fs::path const m_path; - unique_ptr<SyntaxTest> m_test; + unique_ptr<TestCase> m_test; }; -string SyntaxTestTool::editor; +string TestTool::editor; -void SyntaxTestTool::printContract() const -{ - if (m_formatted) - { - string const& source = m_test->source(); - if (source.empty()) - return; - - std::vector<char const*> sourceFormatting(source.length(), formatting::RESET); - for (auto const& error: m_test->errorList()) - if (error.locationStart >= 0 && error.locationEnd >= 0) - { - assert(static_cast<size_t>(error.locationStart) <= source.length()); - assert(static_cast<size_t>(error.locationEnd) <= source.length()); - bool isWarning = error.type == "Warning"; - for (int i = error.locationStart; i < error.locationEnd; i++) - if (isWarning) - { - if (sourceFormatting[i] == formatting::RESET) - sourceFormatting[i] = formatting::ORANGE_BACKGROUND; - } - else - sourceFormatting[i] = formatting::RED_BACKGROUND; - } - - cout << " " << sourceFormatting.front() << source.front(); - for (size_t i = 1; i < source.length(); i++) - { - if (sourceFormatting[i] != sourceFormatting[i - 1]) - cout << sourceFormatting[i]; - if (source[i] != '\n') - cout << source[i]; - else - { - cout << formatting::RESET << endl; - if (i + 1 < source.length()) - cout << " " << sourceFormatting[i]; - } - } - cout << formatting::RESET << endl; - } - else - { - stringstream stream(m_test->source()); - string line; - while (getline(stream, line)) - cout << " " << line << endl; - cout << endl; - } -} - -SyntaxTestTool::Result SyntaxTestTool::process() +TestTool::Result TestTool::process() { bool success; std::stringstream outputMessages; @@ -147,42 +100,25 @@ SyntaxTestTool::Result SyntaxTestTool::process() try { - m_test = unique_ptr<SyntaxTest>(new SyntaxTest(m_path.string())); + m_test = m_testCaseCreator(m_path.string()); success = m_test->run(outputMessages, " ", m_formatted); } - catch(CompilerError const& _e) - { - FormattedScope(cout, m_formatted, {BOLD, RED}) << - "Exception: " << SyntaxTest::errorMessage(_e) << endl; - return Result::Exception; - } - catch(InternalCompilerError const& _e) - { - FormattedScope(cout, m_formatted, {BOLD, RED}) << - "InternalCompilerError: " << SyntaxTest::errorMessage(_e) << endl; - return Result::Exception; - } - catch(FatalError const& _e) - { - FormattedScope(cout, m_formatted, {BOLD, RED}) << - "FatalError: " << SyntaxTest::errorMessage(_e) << endl; - return Result::Exception; - } - catch(UnimplementedFeatureError const& _e) + catch(boost::exception const& _e) { FormattedScope(cout, m_formatted, {BOLD, RED}) << - "UnimplementedFeatureError: " << SyntaxTest::errorMessage(_e) << endl; + "Exception during syntax test: " << boost::diagnostic_information(_e) << endl; return Result::Exception; } catch (std::exception const& _e) { - FormattedScope(cout, m_formatted, {BOLD, RED}) << "Exception: " << _e.what() << endl; + FormattedScope(cout, m_formatted, {BOLD, RED}) << + "Exception during syntax test: " << _e.what() << endl; return Result::Exception; } catch(...) { FormattedScope(cout, m_formatted, {BOLD, RED}) << - "Unknown Exception" << endl; + "Unknown exception during syntax test." << endl; return Result::Exception; } @@ -196,14 +132,14 @@ SyntaxTestTool::Result SyntaxTestTool::process() FormattedScope(cout, m_formatted, {BOLD, RED}) << "FAIL" << endl; FormattedScope(cout, m_formatted, {BOLD, CYAN}) << " Contract:" << endl; - printContract(); + m_test->printSource(cout, " ", m_formatted); - cout << outputMessages.str() << endl; + cout << endl << outputMessages.str() << endl; return Result::Failure; } } -SyntaxTestTool::Request SyntaxTestTool::handleResponse(bool const _exception) +TestTool::Request TestTool::handleResponse(bool const _exception) { if (_exception) cout << "(e)dit/(s)kip/(q)uit? "; @@ -225,15 +161,14 @@ SyntaxTestTool::Request SyntaxTestTool::handleResponse(bool const _exception) { cout << endl; ofstream file(m_path.string(), ios::trunc); - file << m_test->source(); + m_test->printSource(file); file << "// ----" << endl; - if (!m_test->errorList().empty()) - m_test->printErrorList(file, m_test->errorList(), "// ", false); + m_test->printUpdatedExpectations(file, "// "); return Request::Rerun; } case 'e': cout << endl << endl; - if (system((editor + " \"" + m_path.string() + "\"").c_str())) + if (system((TestTool::editor + " \"" + m_path.string() + "\"").c_str())) cerr << "Error running editor command." << endl << endl; return Request::Rerun; case 'q': @@ -245,8 +180,8 @@ SyntaxTestTool::Request SyntaxTestTool::handleResponse(bool const _exception) } } - -SyntaxTestStats SyntaxTestTool::processPath( +TestStats TestTool::processPath( + TestCase::TestCaseCreator _testCaseCreator, fs::path const& _basepath, fs::path const& _path, bool const _formatted @@ -269,12 +204,12 @@ SyntaxTestStats SyntaxTestTool::processPath( fs::directory_iterator(fullpath), fs::directory_iterator() )) - if (fs::is_directory(entry.path()) || SyntaxTest::isTestFilename(entry.path().filename())) + if (fs::is_directory(entry.path()) || TestCase::isTestFilename(entry.path().filename())) paths.push(currentPath / entry.path().filename()); } else { - SyntaxTestTool testTool(currentPath.string(), fullpath, _formatted); + TestTool testTool(_testCaseCreator, currentPath.string(), fullpath, _formatted); ++runCount; auto result = testTool.process(); @@ -310,9 +245,9 @@ SyntaxTestStats SyntaxTestTool::processPath( int main(int argc, char *argv[]) { if (getenv("EDITOR")) - SyntaxTestTool::editor = getenv("EDITOR"); + TestTool::editor = getenv("EDITOR"); else if (fs::exists("/usr/bin/editor")) - SyntaxTestTool::editor = "/usr/bin/editor"; + TestTool::editor = "/usr/bin/editor"; fs::path testPath; bool formatted = true; @@ -328,7 +263,7 @@ Allowed options)", ("help", "Show this help screen.") ("testpath", po::value<fs::path>(&testPath), "path to test files") ("no-color", "don't use colors") - ("editor", po::value<string>(&SyntaxTestTool::editor), "editor for opening contracts"); + ("editor", po::value<string>(&TestTool::editor), "editor for opening contracts"); po::variables_map arguments; try @@ -348,7 +283,7 @@ Allowed options)", po::notify(arguments); } - catch (po::error const& _exception) + catch (std::exception const& _exception) { cerr << _exception.what() << endl; return 1; @@ -379,7 +314,7 @@ Allowed options)", if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath)) { - auto stats = SyntaxTestTool::processPath(testPath / "libsolidity", "syntaxTests", formatted); + auto stats = TestTool::processPath(SyntaxTest::create, testPath / "libsolidity", "syntaxTests", formatted); cout << endl << "Summary: "; FormattedScope(cout, formatted, {BOLD, stats ? GREEN : RED}) << @@ -390,7 +325,7 @@ Allowed options)", } else { - cerr << "Test path not found. Use the --testpath argument." << endl; + cerr << "Syntax tests not found. Use the --testpath argument." << endl; return 1; } } |