diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/contracts/AuctionRegistrar.cpp | 2 | ||||
-rw-r--r-- | test/contracts/FixedFeeRegistrar.cpp | 2 | ||||
-rw-r--r-- | test/contracts/Wallet.cpp | 3 | ||||
-rw-r--r-- | test/libsolidity/GasMeter.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/Imports.cpp | 74 | ||||
-rw-r--r-- | test/libsolidity/SemVerMatcher.cpp | 223 | ||||
-rw-r--r-- | test/libsolidity/SolidityABIJSON.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityExecutionFramework.h | 4 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 51 | ||||
-rw-r--r-- | test/libsolidity/SolidityNatspecJSON.cpp | 2 |
10 files changed, 307 insertions, 58 deletions
diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp index 6eba2706..1c47e70e 100644 --- a/test/contracts/AuctionRegistrar.cpp +++ b/test/contracts/AuctionRegistrar.cpp @@ -39,7 +39,7 @@ namespace { static char const* registrarCode = R"DELIMITER( -//sol +pragma solidity ^0.3.6; contract NameRegister { function addr(string _name) constant returns (address o_owner); diff --git a/test/contracts/FixedFeeRegistrar.cpp b/test/contracts/FixedFeeRegistrar.cpp index 3acfba62..0df26ee4 100644 --- a/test/contracts/FixedFeeRegistrar.cpp +++ b/test/contracts/FixedFeeRegistrar.cpp @@ -52,6 +52,8 @@ static char const* registrarCode = R"DELIMITER( // @authors: // Gav Wood <g@ethdev.com> +pragma solidity ^0.3.6; + contract Registrar { event Changed(string indexed name); diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp index 9e797af4..70c35cc1 100644 --- a/test/contracts/Wallet.cpp +++ b/test/contracts/Wallet.cpp @@ -54,6 +54,9 @@ static char const* walletCode = R"DELIMITER( // use modifiers onlyowner (just own owned) or onlymanyowners(hash), whereby the same hash must be provided by // some number (specified in constructor) of the set of owners (specified in the constructor, modifiable) before the // interior is executed. + +pragma solidity ^0.3.6; + contract multiowned { // TYPES diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp index 41204a0a..603ad683 100644 --- a/test/libsolidity/GasMeter.cpp +++ b/test/libsolidity/GasMeter.cpp @@ -46,7 +46,7 @@ public: GasMeterTestFramework() { } void compile(string const& _sourceCode) { - m_compiler.setSource(_sourceCode); + m_compiler.setSource("pragma solidity >= 0;" + _sourceCode); ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(), "Compiling contract failed"); AssemblyItems const* items = m_compiler.runtimeAssemblyItems(""); diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp index 0736a853..b88ab189 100644 --- a/test/libsolidity/Imports.cpp +++ b/test/libsolidity/Imports.cpp @@ -39,106 +39,106 @@ BOOST_AUTO_TEST_SUITE(SolidityImports) BOOST_AUTO_TEST_CASE(smoke_test) { CompilerStack c; - c.addSource("a", "contract C {}"); + c.addSource("a", "contract C {} pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } BOOST_AUTO_TEST_CASE(regular_import) { CompilerStack c; - c.addSource("a", "contract C {}"); - c.addSource("b", "import \"a\"; contract D is C {}"); + c.addSource("a", "contract C {} pragma solidity >= 0;"); + c.addSource("b", "import \"a\"; contract D is C {} pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } BOOST_AUTO_TEST_CASE(import_does_not_clutter_importee) { CompilerStack c; - c.addSource("a", "contract C { D d; }"); - c.addSource("b", "import \"a\"; contract D is C {}"); + c.addSource("a", "contract C { D d; } pragma solidity >= 0;"); + c.addSource("b", "import \"a\"; contract D is C {} pragma solidity >= 0;"); BOOST_CHECK(!c.compile()); } BOOST_AUTO_TEST_CASE(import_is_transitive) { CompilerStack c; - c.addSource("a", "contract C { }"); - c.addSource("b", "import \"a\";"); - c.addSource("c", "import \"b\"; contract D is C {}"); + c.addSource("a", "contract C { } pragma solidity >= 0;"); + c.addSource("b", "import \"a\"; pragma solidity >= 0;"); + c.addSource("c", "import \"b\"; contract D is C {} pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } BOOST_AUTO_TEST_CASE(circular_import) { CompilerStack c; - c.addSource("a", "import \"b\"; contract C { D d; }"); - c.addSource("b", "import \"a\"; contract D { C c; }"); + c.addSource("a", "import \"b\"; contract C { D d; } pragma solidity >= 0;"); + c.addSource("b", "import \"a\"; contract D { C c; } pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } BOOST_AUTO_TEST_CASE(relative_import) { CompilerStack c; - c.addSource("a", "import \"./dir/b\"; contract A is B {}"); - c.addSource("dir/b", "contract B {}"); - c.addSource("dir/c", "import \"../a\"; contract C is A {}"); + c.addSource("a", "import \"./dir/b\"; contract A is B {} pragma solidity >= 0;"); + c.addSource("dir/b", "contract B {} pragma solidity >= 0;"); + c.addSource("dir/c", "import \"../a\"; contract C is A {} pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } BOOST_AUTO_TEST_CASE(relative_import_multiplex) { CompilerStack c; - c.addSource("a", "contract A {}"); - c.addSource("dir/a/b/c", "import \"../../.././a\"; contract B is A {}"); + c.addSource("a", "contract A {} pragma solidity >= 0;"); + c.addSource("dir/a/b/c", "import \"../../.././a\"; contract B is A {} pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } BOOST_AUTO_TEST_CASE(simple_alias) { CompilerStack c; - c.addSource("a", "contract A {}"); - c.addSource("dir/a/b/c", "import \"../../.././a\" as x; contract B is x.A { function() { x.A r = x.A(20); } }"); + c.addSource("a", "contract A {} pragma solidity >= 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;"); BOOST_CHECK(c.compile()); } BOOST_AUTO_TEST_CASE(library_name_clash) { CompilerStack c; - c.addSource("a", "library A {}"); - c.addSource("b", "library A {}"); + c.addSource("a", "library A {} pragma solidity >= 0;"); + c.addSource("b", "library A {} pragma solidity >= 0;"); BOOST_CHECK(!c.compile()); } BOOST_AUTO_TEST_CASE(library_name_clash_with_contract) { CompilerStack c; - c.addSource("a", "contract A {}"); - c.addSource("b", "library A {}"); + c.addSource("a", "contract A {} pragma solidity >= 0;"); + c.addSource("b", "library A {} pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } BOOST_AUTO_TEST_CASE(complex_import) { CompilerStack c; - c.addSource("a", "contract A {} contract B {} contract C { struct S { uint a; } }"); + c.addSource("a", "contract A {} contract B {} contract C { struct S { uint a; } } pragma solidity >= 0;"); c.addSource("b", "import \"a\" as x; import {B as b, C as c, C} from \"a\"; " - "contract D is b { function f(c.S var1, x.C.S var2, C.S var3) internal {} }"); + "contract D is b { function f(c.S var1, x.C.S var2, C.S var3) internal {} } pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } BOOST_AUTO_TEST_CASE(name_clash_in_import) { CompilerStack c; - c.addSource("a", "contract A {}"); - c.addSource("b", "import \"a\"; contract A {} "); + c.addSource("a", "contract A {} pragma solidity >= 0;"); + c.addSource("b", "import \"a\"; contract A {} pragma solidity >= 0;"); BOOST_CHECK(!c.compile()); - c.addSource("b", "import \"a\" as A; contract A {} "); + c.addSource("b", "import \"a\" as A; contract A {} pragma solidity >= 0;"); BOOST_CHECK(!c.compile()); - c.addSource("b", "import {A as b} from \"a\"; contract b {} "); + c.addSource("b", "import {A as b} from \"a\"; contract b {} pragma solidity >= 0;"); BOOST_CHECK(!c.compile()); - c.addSource("b", "import {A} from \"a\"; contract A {} "); + c.addSource("b", "import {A} from \"a\"; contract A {} pragma solidity >= 0;"); BOOST_CHECK(!c.compile()); - c.addSource("b", "import {A} from \"a\"; contract B {} "); + c.addSource("b", "import {A} from \"a\"; contract B {} pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } @@ -146,10 +146,10 @@ BOOST_AUTO_TEST_CASE(remappings) { CompilerStack c; c.setRemappings(vector<string>{"s=s_1.4.6", "t=Tee"}); - c.addSource("a", "import \"s/s.sol\"; contract A is S {}"); - c.addSource("b", "import \"t/tee.sol\"; contract A is Tee {} "); - c.addSource("s_1.4.6/s.sol", "contract S {}"); - c.addSource("Tee/tee.sol", "contract Tee {}"); + c.addSource("a", "import \"s/s.sol\"; contract A is S {} pragma solidity >= 0;"); + c.addSource("b", "import \"t/tee.sol\"; contract A is Tee {} pragma solidity >= 0;"); + c.addSource("s_1.4.6/s.sol", "contract S {} pragma solidity >= 0;"); + c.addSource("Tee/tee.sol", "contract Tee {} pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } @@ -157,10 +157,10 @@ BOOST_AUTO_TEST_CASE(context_dependent_remappings) { CompilerStack c; c.setRemappings(vector<string>{"a:s=s_1.4.6", "b:s=s_1.4.7"}); - c.addSource("a/a.sol", "import \"s/s.sol\"; contract A is SSix {}"); - c.addSource("b/b.sol", "import \"s/s.sol\"; contract B is SSeven {}"); - c.addSource("s_1.4.6/s.sol", "contract SSix {} "); - c.addSource("s_1.4.7/s.sol", "contract SSeven {} "); + c.addSource("a/a.sol", "import \"s/s.sol\"; contract A is SSix {} pragma solidity >= 0;"); + c.addSource("b/b.sol", "import \"s/s.sol\"; contract B is SSeven {} pragma solidity >= 0;"); + c.addSource("s_1.4.6/s.sol", "contract SSix {} pragma solidity >= 0;"); + c.addSource("s_1.4.7/s.sol", "contract SSeven {} pragma solidity >= 0;"); BOOST_CHECK(c.compile()); } diff --git a/test/libsolidity/SemVerMatcher.cpp b/test/libsolidity/SemVerMatcher.cpp new file mode 100644 index 00000000..80bdf16f --- /dev/null +++ b/test/libsolidity/SemVerMatcher.cpp @@ -0,0 +1,223 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum 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. + + cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. +*/ +/** + * @author Christian <chris@ethereum.org> + * @date 2016 + * Unit tests for the semantic versioning matcher. + */ + +#include <string> +#include <vector> +#include <tuple> +#include <libsolidity/parsing/Scanner.h> +#include <libsolidity/analysis/SemVerHandler.h> +#include "../TestHelper.h" + +using namespace std; + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +BOOST_AUTO_TEST_SUITE(SemVerMatcher) + +SemVerMatchExpression parseExpression(string const& _input) +{ + Scanner scanner{CharStream(_input)}; + vector<string> literals; + vector<Token::Value> tokens; + while (scanner.currentToken() != Token::EOS) + { + auto token = scanner.currentToken(); + string literal = scanner.currentLiteral(); + if (literal.empty() && Token::toString(token)) + literal = Token::toString(token); + literals.push_back(literal); + tokens.push_back(token); + scanner.next(); + } + + auto expression = SemVerMatchExpressionParser(tokens, literals).parse(); + BOOST_CHECK_MESSAGE( + expression.isValid(), + "Expression \"" + _input + "\" did not parse properly." + ); + return expression; +} + +BOOST_AUTO_TEST_CASE(positive_range) +{ + // Positive range tests + vector<pair<string, string>> tests = { + {"*", "1.2.3-foo"}, + {"1.0.0 - 2.0.0", "1.2.3"}, + {"1.0.0", "1.0.0"}, + {">=*", "0.2.4"}, + {"*", "1.2.3"}, + {">=1.0.0", "1.0.0"}, + {">=1.0.0", "1.0.1"}, + {">=1.0.0", "1.1.0"}, + {">1.0.0", "1.0.1"}, + {">1.0.0", "1.1.0"}, + {"<=2.0.0", "2.0.0"}, + {"<=2.0.0", "1.9999.9999"}, + {"<=2.0.0", "0.2.9"}, + {"<2.0.0", "1.9999.9999"}, + {"<2.0.0", "0.2.9"}, + {">= 1.0.0", "1.0.0"}, + {">= 1.0.0", "1.0.1"}, + {">= 1.0.0", "1.1.0"}, + {"> 1.0.0", "1.0.1"}, + {"> 1.0.0", "1.1.0"}, + {"<= 2.0.0", "2.0.0"}, + {"<= 2.0.0", "1.9999.9999"}, + {"<= 2.0.0", "0.2.9"}, + {"< 2.0.0", "1.9999.9999"}, + {"<\t2.0.0", "0.2.9"}, + {">=0.1.97", "0.1.97"}, + {"0.1.20 || 1.2.4", "1.2.4"}, + {">=0.2.3 || <0.0.1", "0.0.0"}, + {">=0.2.3 || <0.0.1", "0.2.3"}, + {">=0.2.3 || <0.0.1", "0.2.4"}, + {"\"2.x.x\"", "2.1.3"}, + {"1.2.x", "1.2.3"}, + {"\"1.2.x\" || \"2.x\"", "2.1.3"}, + {"\"1.2.x\" || \"2.x\"", "1.2.3"}, + {"x", "1.2.3"}, + {"2.*.*", "2.1.3"}, + {"1.2.*", "1.2.3"}, + {"1.2.* || 2.*", "2.1.3"}, + {"1.2.* || 2.*", "1.2.3"}, + {"*", "1.2.3"}, + {"2", "2.1.2"}, + {"2.3", "2.3.1"}, + {"~2.4", "2.4.0"}, // >=2.4.0 <2.5.0 + {"~2.4", "2.4.5"}, + {"~1", "1.2.3"}, // >=1.0.0 <2.0.0 + {"~1.0", "1.0.2"}, // >=1.0.0 <1.1.0, + {"~ 1.0", "1.0.2"}, + {"~ 1.0.3", "1.0.12"}, + {">=1", "1.0.0"}, + {">= 1", "1.0.0"}, + {"<1.2", "1.1.1"}, + {"< 1.2", "1.1.1"}, + {"=0.7.x", "0.7.2"}, + {"<=0.7.x", "0.7.2"}, + {">=0.7.x", "0.7.2"}, + {"<=0.7.x", "0.6.2"}, + {"~1.2.1 >=1.2.3", "1.2.3"}, + {"~1.2.1 =1.2.3", "1.2.3"}, + {"~1.2.1 1.2.3", "1.2.3"}, + {"~1.2.1 >=1.2.3 1.2.3", "1.2.3"}, + {"~1.2.1 1.2.3 >=1.2.3", "1.2.3"}, + {">=\"1.2.1\" 1.2.3", "1.2.3"}, + {"1.2.3 >=1.2.1", "1.2.3"}, + {">=1.2.3 >=1.2.1", "1.2.3"}, + {">=1.2.1 >=1.2.3", "1.2.3"}, + {">=1.2", "1.2.8"}, + {"^1.2.3", "1.8.1"}, + {"^0.1.2", "0.1.2"}, + {"^0.1", "0.1.2"}, + {"^1.2", "1.4.2"}, + {"<=1.2.3", "1.2.3-beta"}, + {">1.2", "1.3.0-beta"}, + {"<1.2.3", "1.2.3-beta"}, + {"^1.2 ^1", "1.4.2"} + }; + for (auto const& t: tests) + { + SemVerVersion version(t.second); + SemVerMatchExpression expression = parseExpression(t.first); + BOOST_CHECK_MESSAGE( + expression.matches(version), + "Version \"" + t.second + "\" did not satisfy expression \"" + t.first + "\"" + ); + } +} + +BOOST_AUTO_TEST_CASE(negative_range) +{ + // Positive range tests + vector<pair<string, string>> tests = { + {"1.0.0 - 2.0.0", "2.2.3"}, + {"^1.2.3", "1.2.3-pre"}, + {"^1.2", "1.2.0-pre"}, + {"^1.2.3", "1.2.3-beta"}, + {"=0.7.x", "0.7.0-asdf"}, + {">=0.7.x", "0.7.0-asdf"}, + {"1.0.0", "1.0.1"}, + {">=1.0.0", "0.0.0"}, + {">=1.0.0", "0.0.1"}, + {">=1.0.0", "0.1.0"}, + {">1.0.0", "0.0.1"}, + {">1.0.0", "0.1.0"}, + {"<=2.0.0", "3.0.0"}, + {"<=2.0.0", "2.9999.9999"}, + {"<=2.0.0", "2.2.9"}, + {"<2.0.0", "2.9999.9999"}, + {"<2.0.0", "2.2.9"}, + {">=0.1.97", "0.1.93"}, + {"0.1.20 || 1.2.4", "1.2.3"}, + {">=0.2.3 || <0.0.1", "0.0.3"}, + {">=0.2.3 || <0.0.1", "0.2.2"}, + {"\"2.x.x\"", "1.1.3"}, + {"\"2.x.x\"", "3.1.3"}, + {"1.2.x", "1.3.3"}, + {"\"1.2.x\" || \"2.x\"", "3.1.3"}, + {"\"1.2.x\" || \"2.x\"", "1.1.3"}, + {"2.*.*", "1.1.3"}, + {"2.*.*", "3.1.3"}, + {"1.2.*", "1.3.3"}, + {"1.2.* || 2.*", "3.1.3"}, + {"1.2.* || 2.*", "1.1.3"}, + {"2", "1.1.2"}, + {"2.3", "2.4.1"}, + {"~2.4", "2.5.0"}, // >=2.4.0 <2.5.0 + {"~2.4", "2.3.9"}, + {"~1", "0.2.3"}, // >=1.0.0 <2.0.0 + {"~1.0", "1.1.0"}, // >=1.0.0 <1.1.0 + {"<1", "1.0.0"}, + {">=1.2", "1.1.1"}, + {"=0.7.x", "0.8.2"}, + {">=0.7.x", "0.6.2"}, + {"<0.7.x", "0.7.2"}, + {"=1.2.3", "1.2.3-beta"}, + {">1.2", "1.2.8"}, + {"^1.2.3", "2.0.0-alpha"}, + {"^1.2.3", "1.2.2"}, + {"^1.2", "1.1.9"} + }; + for (auto const& t: tests) + { + SemVerVersion version(t.second); + SemVerMatchExpression expression = parseExpression(t.first); + BOOST_CHECK_MESSAGE( + !expression.matches(version), + "Version \"" + t.second + "\" did satisfy expression \"" + t.first + "\" " + + "(although it should not)" + ); + } +} + +BOOST_AUTO_TEST_SUITE_END() + +} +} +} // end namespaces diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index cfc7b9bd..6bcc7b3c 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -39,7 +39,7 @@ public: void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString) { - ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parse(_code), "Parsing contract failed"); + ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parse("pragma solidity >=0;\n" + _code), "Parsing contract failed"); std::string generatedInterfaceString = m_compilerStack.metadata("", DocumentationType::ABIInterface); Json::Value generatedInterface; m_reader.parse(generatedInterfaceString, generatedInterface); diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index f4bdc657..33347600 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -67,8 +67,10 @@ public: std::map<std::string, Address> const& _libraryAddresses = std::map<std::string, Address>() ) { + // Silence compiler version warning + std::string sourceCode = "pragma solidity >=0;\n" + _sourceCode; m_compiler.reset(false); - m_compiler.addSource("", _sourceCode); + m_compiler.addSource("", sourceCode); if (!m_compiler.compile(m_optimize, m_optimizeRuns)) { for (auto const& error: m_compiler.errors()) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index fdd8d7f4..5f29bf89 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -45,15 +45,17 @@ namespace { pair<ASTPointer<SourceUnit>, std::shared_ptr<Error::Type const>> -parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false) +parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false, bool _insertVersionPragma = true) { + // Silence compiler version warning + string source = _insertVersionPragma ? "pragma solidity >=0;\n" + _source : _source; ErrorList errors; Parser parser(errors); ASTPointer<SourceUnit> sourceUnit; // catch exceptions for a transition period try { - sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(_source))); + sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(source))); if(!sourceUnit) return make_pair(sourceUnit, nullptr); @@ -445,8 +447,8 @@ BOOST_AUTO_TEST_CASE(function_no_implementation) "}\n"; ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseAndAnalyse(text), "Parsing and name Resolving failed"); std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->nodes(); - ContractDefinition* contract = dynamic_cast<ContractDefinition*>(nodes[0].get()); - BOOST_CHECK(contract); + ContractDefinition* contract = dynamic_cast<ContractDefinition*>(nodes[1].get()); + BOOST_REQUIRE(contract); BOOST_CHECK(!contract->annotation().isFullyImplemented); BOOST_CHECK(!contract->definedFunctions()[0]->isImplemented()); } @@ -460,12 +462,12 @@ BOOST_AUTO_TEST_CASE(abstract_contract) )"; ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseAndAnalyse(text), "Parsing and name Resolving failed"); std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->nodes(); - ContractDefinition* base = dynamic_cast<ContractDefinition*>(nodes[0].get()); - ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[1].get()); - BOOST_CHECK(base); + ContractDefinition* base = dynamic_cast<ContractDefinition*>(nodes[1].get()); + ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[2].get()); + BOOST_REQUIRE(base); BOOST_CHECK(!base->annotation().isFullyImplemented); BOOST_CHECK(!base->definedFunctions()[0]->isImplemented()); - BOOST_CHECK(derived); + BOOST_REQUIRE(derived); BOOST_CHECK(derived->annotation().isFullyImplemented); BOOST_CHECK(derived->definedFunctions()[0]->isImplemented()); } @@ -479,8 +481,8 @@ BOOST_AUTO_TEST_CASE(abstract_contract_with_overload) )"; ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseAndAnalyse(text), "Parsing and name Resolving failed"); std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->nodes(); - ContractDefinition* base = dynamic_cast<ContractDefinition*>(nodes[0].get()); - ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[1].get()); + ContractDefinition* base = dynamic_cast<ContractDefinition*>(nodes[1].get()); + ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[2].get()); BOOST_REQUIRE(base); BOOST_CHECK(!base->annotation().isFullyImplemented); BOOST_REQUIRE(derived); @@ -527,9 +529,9 @@ BOOST_AUTO_TEST_CASE(abstract_contract_constructor_args_not_provided) )"; ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseAndAnalyse(text), "Parsing and name resolving failed"); std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->nodes(); - BOOST_CHECK_EQUAL(nodes.size(), 3); - ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[2].get()); - BOOST_CHECK(derived); + BOOST_CHECK_EQUAL(nodes.size(), 4); + ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[3].get()); + BOOST_REQUIRE(derived); BOOST_CHECK(!derived->annotation().isFullyImplemented); } @@ -553,9 +555,9 @@ BOOST_AUTO_TEST_CASE(implement_abstract_via_constructor) )"; ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseAndAnalyse(text), "Parsing and name resolving failed"); std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->nodes(); - BOOST_CHECK_EQUAL(nodes.size(), 2); - ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[1].get()); - BOOST_CHECK(derived); + BOOST_CHECK_EQUAL(nodes.size(), 3); + ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[2].get()); + BOOST_REQUIRE(derived); BOOST_CHECK(!derived->annotation().isFullyImplemented); } @@ -3853,6 +3855,23 @@ BOOST_AUTO_TEST_CASE(modifier_without_underscore) BOOST_CHECK(expectError(text, true) == Error::Type::SyntaxError); } +BOOST_AUTO_TEST_CASE(warn_nonpresent_pragma) +{ + char const* text = "contract C {}"; + auto sourceAndError = parseAnalyseAndReturnError(text, true, false); + BOOST_REQUIRE(!!sourceAndError.second); + BOOST_REQUIRE(!!sourceAndError.first); + BOOST_CHECK(*sourceAndError.second == Error::Type::Warning); +} + +BOOST_AUTO_TEST_CASE(unsatisfied_version) +{ + char const* text = R"( + pragma solidity ^99.99.0; + )"; + BOOST_CHECK(expectError(text, true) == Error::Type::SyntaxError); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNatspecJSON.cpp b/test/libsolidity/SolidityNatspecJSON.cpp index 56572b43..4071e973 100644 --- a/test/libsolidity/SolidityNatspecJSON.cpp +++ b/test/libsolidity/SolidityNatspecJSON.cpp @@ -46,7 +46,7 @@ public: ) { std::string generatedDocumentationString; - ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parse(_code), "Parsing failed"); + ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parse("pragma solidity >=0;\n" + _code), "Parsing failed"); if (_userDocumentation) generatedDocumentationString = m_compilerStack.metadata("", DocumentationType::NatspecUser); |