aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-03-31 01:33:30 +0800
committerchriseth <c@ethdev.com>2015-03-31 01:33:30 +0800
commitea98b3b07e30efdb8b146a1ad82006d2f1d949e2 (patch)
treed2eab70f25c17e23bdd48fdf4ddfc2df777828c6
parent735c02c468de32b4f91c59794039b67ab29a8170 (diff)
parentde09be29ba80486b7fddafef4b740d5093d0c726 (diff)
downloaddexon-solidity-ea98b3b07e30efdb8b146a1ad82006d2f1d949e2.tar.gz
dexon-solidity-ea98b3b07e30efdb8b146a1ad82006d2f1d949e2.tar.zst
dexon-solidity-ea98b3b07e30efdb8b146a1ad82006d2f1d949e2.zip
Merge pull request #1414 from LefterisJP/sol_notImplementedFuncs
Interface contracts
-rw-r--r--SolidityNameAndTypeResolution.cpp57
-rw-r--r--SolidityParser.cpp8
2 files changed, 65 insertions, 0 deletions
diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp
index 3bec70a2..ddcf3614 100644
--- a/SolidityNameAndTypeResolution.cpp
+++ b/SolidityNameAndTypeResolution.cpp
@@ -359,6 +359,63 @@ BOOST_AUTO_TEST_CASE(comparison_bitop_precedence)
ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed");
}
+BOOST_AUTO_TEST_CASE(function_no_implementation)
+{
+ ASTPointer<SourceUnit> sourceUnit;
+ char const* text = "contract test {\n"
+ " function functionName(bytes32 input) returns (bytes32 out);\n"
+ "}\n";
+ ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed");
+ std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->getNodes();
+ ContractDefinition* contract = dynamic_cast<ContractDefinition*>(nodes[0].get());
+ BOOST_CHECK(contract);
+ BOOST_CHECK(!contract->isFullyImplemented());
+ BOOST_CHECK(!contract->getDefinedFunctions()[0]->isFullyImplemented());
+}
+
+BOOST_AUTO_TEST_CASE(abstract_contract)
+{
+ ASTPointer<SourceUnit> sourceUnit;
+ char const* text = R"(
+ contract base { function foo(); }
+ contract derived is base { function foo() {} }
+ )";
+ ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed");
+ std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->getNodes();
+ ContractDefinition* base = dynamic_cast<ContractDefinition*>(nodes[0].get());
+ ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[1].get());
+ BOOST_CHECK(base);
+ BOOST_CHECK(!base->isFullyImplemented());
+ BOOST_CHECK(!base->getDefinedFunctions()[0]->isFullyImplemented());
+ BOOST_CHECK(derived);
+ BOOST_CHECK(derived->isFullyImplemented());
+ BOOST_CHECK(derived->getDefinedFunctions()[0]->isFullyImplemented());
+}
+
+BOOST_AUTO_TEST_CASE(create_abstract_contract)
+{
+ ASTPointer<SourceUnit> sourceUnit;
+ char const* text = R"(
+ contract base { function foo(); }
+ contract derived {
+ base b;
+ function foo() { b = new base();}
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(redeclare_implemented_abstract_function_as_abstract)
+{
+ ASTPointer<SourceUnit> sourceUnit;
+ char const* text = R"(
+ contract base { function foo(); }
+ contract derived is base { function foo() {} }
+ contract wrong is derived { function foo(); }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
BOOST_AUTO_TEST_CASE(function_canonical_signature)
{
ASTPointer<SourceUnit> sourceUnit;
diff --git a/SolidityParser.cpp b/SolidityParser.cpp
index 392d9ac4..7640f91a 100644
--- a/SolidityParser.cpp
+++ b/SolidityParser.cpp
@@ -108,6 +108,14 @@ BOOST_AUTO_TEST_CASE(single_function_param)
ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed.");
}
+BOOST_AUTO_TEST_CASE(function_no_body)
+{
+ char const* text = "contract test {\n"
+ " function functionName(bytes32 input) returns (bytes32 out);\n"
+ "}\n";
+ ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed.");
+}
+
BOOST_AUTO_TEST_CASE(missing_parameter_name_in_named_args)
{
char const* text = "contract test {\n"