From d00ef95a72c06c1972be9234a8a96ecabd504271 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 28 Oct 2020 19:04:24 +0100 Subject: [PATCH] Refactor isoltest function call kind. --- test/libsolidity/SemanticTest.cpp | 29 +++++++++++-------- test/libsolidity/util/SoltestTypes.h | 19 +++++++----- test/libsolidity/util/TestFileParser.cpp | 11 ++++--- test/libsolidity/util/TestFileParserTests.cpp | 4 +-- test/libsolidity/util/TestFunctionCall.cpp | 2 +- 5 files changed, 39 insertions(+), 26 deletions(-) diff --git a/test/libsolidity/SemanticTest.cpp b/test/libsolidity/SemanticTest.cpp index c46f59939..9c784c32e 100644 --- a/test/libsolidity/SemanticTest.cpp +++ b/test/libsolidity/SemanticTest.cpp @@ -154,12 +154,12 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line { if (constructed) { - soltestAssert(!test.call().isLibrary, "Libraries have to be deployed before any other call."); + soltestAssert(test.call().kind != FunctionCall::Kind::Library, "Libraries have to be deployed before any other call."); soltestAssert( - !test.call().isConstructor, + test.call().kind != FunctionCall::Kind::Constructor, "Constructor has to be the first function call expect for library deployments."); } - else if (test.call().isLibrary) + else if (test.call().kind == FunctionCall::Kind::Library) { soltestAssert( deploy(test.call().signature, 0, {}, libraries) && m_transactionSuccessful, @@ -169,14 +169,14 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line } else { - if (test.call().isConstructor) + if (test.call().kind == FunctionCall::Kind::Constructor) deploy("", test.call().value.value, test.call().arguments.rawBytes(), libraries); else soltestAssert(deploy("", 0, bytes(), libraries), "Failed to deploy contract."); constructed = true; } - if (test.call().isConstructor) + if (test.call().kind == FunctionCall::Kind::Constructor) { if (m_transactionSuccessful == test.call().expectations.failure) success = false; @@ -187,22 +187,27 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line else { bytes output; - if (test.call().useCallWithoutSignature) + if (test.call().kind == FunctionCall::Kind::LowLevel) output = callLowLevel(test.call().arguments.rawBytes(), test.call().value.value); else { soltestAssert( - m_allowNonExistingFunctions || m_compiler.methodIdentifiers(m_compiler.lastContractName()) - .isMember(test.call().signature), - "The function " + test.call().signature + " is not known to the compiler"); + m_allowNonExistingFunctions || + m_compiler.methodIdentifiers(m_compiler.lastContractName()).isMember(test.call().signature), + "The function " + test.call().signature + " is not known to the compiler" + ); output = callContractFunctionWithValueNoEncoding( - test.call().signature, test.call().value.value, test.call().arguments.rawBytes() + test.call().signature, + test.call().value.value, + test.call().arguments.rawBytes() ); } - if ((m_transactionSuccessful == test.call().expectations.failure) - || (output != test.call().expectations.rawBytes())) + if ( + m_transactionSuccessful == test.call().expectations.failure || + output != test.call().expectations.rawBytes() + ) success = false; test.setFailure(!m_transactionSuccessful); diff --git a/test/libsolidity/util/SoltestTypes.h b/test/libsolidity/util/SoltestTypes.h index 26b92d535..de901dc95 100644 --- a/test/libsolidity/util/SoltestTypes.h +++ b/test/libsolidity/util/SoltestTypes.h @@ -275,16 +275,21 @@ struct FunctionCall MultiLine }; DisplayMode displayMode = DisplayMode::SingleLine; - /// Marks this function call as the constructor. - bool isConstructor = false; - /// If this function call's signature has no name and no arguments, - /// a low-level call with unstructured calldata will be issued. - bool useCallWithoutSignature = false; + + enum class Kind { + Regular, + /// Marks this function call as the constructor. + Constructor, + /// If this function call's signature has no name and no arguments, + /// a low-level call with unstructured calldata will be issued. + LowLevel, + /// Marks a library deployment call. + Library + }; + Kind kind = Kind::Regular; /// Marks this function call as "short-handed", meaning /// no `->` declared. bool omitsArrow = true; - /// Marks a library deployment call. - bool isLibrary = false; }; } diff --git a/test/libsolidity/util/TestFileParser.cpp b/test/libsolidity/util/TestFileParser.cpp index 046193d39..2ea6cd994 100644 --- a/test/libsolidity/util/TestFileParser.cpp +++ b/test/libsolidity/util/TestFileParser.cpp @@ -82,12 +82,16 @@ vector TestFileParser::parseFunctionCall expect(Token::Colon); call.signature = m_scanner.currentLiteral(); expect(Token::Identifier); - call.isLibrary = true; + call.kind = FunctionCall::Kind::Library; call.expectations.failure = false; } else { - tie(call.signature, call.useCallWithoutSignature) = parseFunctionSignature(); + bool lowLevelCall = false; + tie(call.signature, lowLevelCall) = parseFunctionSignature(); + if (lowLevelCall) + call.kind = FunctionCall::Kind::LowLevel; + if (accept(Token::Comma, true)) call.value = parseFunctionCallValue(); @@ -124,8 +128,7 @@ vector TestFileParser::parseFunctionCall call.expectations.comment = parseComment(); if (call.signature == "constructor()") - call.isConstructor = true; - + call.kind = FunctionCall::Kind::Constructor; } calls.emplace_back(std::move(call)); diff --git a/test/libsolidity/util/TestFileParserTests.cpp b/test/libsolidity/util/TestFileParserTests.cpp index 6b3ba2d7a..35c542ea6 100644 --- a/test/libsolidity/util/TestFileParserTests.cpp +++ b/test/libsolidity/util/TestFileParserTests.cpp @@ -82,8 +82,8 @@ void testFunctionCall( } } - BOOST_REQUIRE_EQUAL(_call.isConstructor, _isConstructor); - BOOST_REQUIRE_EQUAL(_call.isLibrary, _isLibrary); + BOOST_REQUIRE_EQUAL(_call.kind == FunctionCall::Kind::Constructor, _isConstructor); + BOOST_REQUIRE_EQUAL(_call.kind == FunctionCall::Kind::Library, _isLibrary); } BOOST_AUTO_TEST_SUITE(TestFileParserTest) diff --git a/test/libsolidity/util/TestFunctionCall.cpp b/test/libsolidity/util/TestFunctionCall.cpp index e258a4976..b7bd460b6 100644 --- a/test/libsolidity/util/TestFunctionCall.cpp +++ b/test/libsolidity/util/TestFunctionCall.cpp @@ -56,7 +56,7 @@ string TestFunctionCall::format( string newline = formatToken(Token::Newline); string failure = formatToken(Token::Failure); - if (m_call.isLibrary) + if (m_call.kind == FunctionCall::Kind::Library) { stream << _linePrefix << newline << ws << "library:" << ws << m_call.signature; return;