aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt29
-rwxr-xr-xtest/externalTests.sh49
-rw-r--r--test/libsolidity/SolidityABIJSON.cpp58
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp41
-rw-r--r--test/libsolidity/SolidityParser.cpp5
5 files changed, 155 insertions, 27 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 8e7b8916..6a8a4399 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,26 +1,9 @@
-cmake_policy(SET CMP0015 NEW)
+file(GLOB_RECURSE sources "*.cpp")
+list(REMOVE_ITEM sources "${CMAKE_CURRENT_SOURCE_DIR}/fuzzer.cpp")
+file(GLOB_RECURSE headers "*.h")
-aux_source_directory(. SRC_LIST)
-aux_source_directory(libdevcore SRC_LIST)
-aux_source_directory(libevmasm SRC_LIST)
-aux_source_directory(libsolidity SRC_LIST)
-aux_source_directory(libjulia SRC_LIST)
-aux_source_directory(contracts SRC_LIST)
-aux_source_directory(liblll SRC_LIST)
-aux_source_directory(libjulia SRC_LIST)
-
-list(REMOVE_ITEM SRC_LIST "./fuzzer.cpp")
-
-get_filename_component(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
-
-file(GLOB HEADERS "*.h" "*/*.h")
-set(EXECUTABLE soltest)
-eth_simple_add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS})
-
-eth_use(${EXECUTABLE} REQUIRED Solidity::solidity Solidity::lll)
-
-include_directories(BEFORE ..)
-target_link_libraries(${EXECUTABLE} soljson ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
+add_executable(soltest ${sources} ${headers})
+target_link_libraries(soltest PRIVATE soljson solidity lll evmasm devcore ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
add_executable(solfuzzer fuzzer.cpp)
-target_link_libraries(solfuzzer soljson ${Boost_PROGRAM_OPTIONS_LIBRARIES})
+target_link_libraries(solfuzzer soljson evmasm ${Boost_PROGRAM_OPTIONS_LIBRARIES})
diff --git a/test/externalTests.sh b/test/externalTests.sh
new file mode 100755
index 00000000..1b74561b
--- /dev/null
+++ b/test/externalTests.sh
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+#------------------------------------------------------------------------------
+# Bash script to run external Solidity tests.
+#
+# Argument: Path to soljson.js to test.
+#
+# Requires npm, networking access and git to download the tests.
+#
+# ------------------------------------------------------------------------------
+# 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/>
+#
+# (c) 2016 solidity contributors.
+#------------------------------------------------------------------------------
+
+set -e
+
+if [ ! -f "$1" ]
+then
+ echo "Usage: $0 <path to soljson.js>"
+ exit 1
+fi
+
+SOLJSON="$1"
+
+DIR=$(mktemp -d)
+(
+ cd "$DIR"
+ echo "Running Zeppelin tests..."
+ git clone https://github.com/OpenZeppelin/zeppelin-solidity.git
+ cd zeppelin-solidity
+ npm install
+ cp "$SOLJSON" ./node_modules/solc/soljson.js
+ npm run test
+)
+rm -rf "$DIR"
diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp
index 80b4b6ad..12fb1f9c 100644
--- a/test/libsolidity/SolidityABIJSON.cpp
+++ b/test/libsolidity/SolidityABIJSON.cpp
@@ -250,7 +250,63 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
checkInterface(sourceCode, interface);
}
-BOOST_AUTO_TEST_CASE(const_function)
+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 boo(uint32 a) view 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);
+}
+
+// constant is an alias to view above
+BOOST_AUTO_TEST_CASE(constant_function)
{
char const* sourceCode = R"(
contract test {
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index e349bf83..380978e8 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -1172,7 +1172,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors)
BOOST_REQUIRE(function && function->hasDeclaration());
auto returnParams = function->returnParameterTypes();
BOOST_CHECK_EQUAL(returnParams.at(0)->canonicalName(false), "uint256");
- BOOST_CHECK(function->isConstant());
+ BOOST_CHECK(function->stateMutability() == StateMutability::View);
function = retrieveFunctionBySignature(*contract, "map(uint256)");
BOOST_REQUIRE(function && function->hasDeclaration());
@@ -1180,7 +1180,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors)
BOOST_CHECK_EQUAL(params.at(0)->canonicalName(false), "uint256");
returnParams = function->returnParameterTypes();
BOOST_CHECK_EQUAL(returnParams.at(0)->canonicalName(false), "bytes4");
- BOOST_CHECK(function->isConstant());
+ BOOST_CHECK(function->stateMutability() == StateMutability::View);
function = retrieveFunctionBySignature(*contract, "multiple_map(uint256,uint256)");
BOOST_REQUIRE(function && function->hasDeclaration());
@@ -1189,7 +1189,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors)
BOOST_CHECK_EQUAL(params.at(1)->canonicalName(false), "uint256");
returnParams = function->returnParameterTypes();
BOOST_CHECK_EQUAL(returnParams.at(0)->canonicalName(false), "bytes4");
- BOOST_CHECK(function->isConstant());
+ BOOST_CHECK(function->stateMutability() == StateMutability::View);
}
BOOST_AUTO_TEST_CASE(function_clash_with_state_variable_accessor)
@@ -6709,6 +6709,41 @@ BOOST_AUTO_TEST_CASE(experimental_pragma)
// CHECK_ERROR_ALLOW_MULTI(text, SyntaxError, "Duplicate experimental feature name.");
}
+BOOST_AUTO_TEST_CASE(reject_interface_creation)
+{
+ char const* text = R"(
+ interface I {}
+ contract C {
+ function f() {
+ 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() {
+ 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_SUITE_END()
}
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index 30dc80d9..8e84ead1 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -920,6 +920,11 @@ BOOST_AUTO_TEST_CASE(multiple_statemutability_specifiers)
CHECK_PARSE_ERROR(text, "State mutability already specified as \"view\".");
text = R"(
contract c {
+ function f() constant view {}
+ })";
+ CHECK_PARSE_ERROR(text, "State mutability already specified as \"view\".");
+ text = R"(
+ contract c {
function f() payable constant {}
})";
CHECK_PARSE_ERROR(text, "State mutability already specified as \"payable\".");