Refactor isoltest function call kind.

This commit is contained in:
chriseth 2020-10-28 19:04:24 +01:00
parent d190c4f1d4
commit d00ef95a72
5 changed files with 39 additions and 26 deletions

View File

@ -154,12 +154,12 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
{ {
if (constructed) 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( soltestAssert(
!test.call().isConstructor, test.call().kind != FunctionCall::Kind::Constructor,
"Constructor has to be the first function call expect for library deployments."); "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( soltestAssert(
deploy(test.call().signature, 0, {}, libraries) && m_transactionSuccessful, deploy(test.call().signature, 0, {}, libraries) && m_transactionSuccessful,
@ -169,14 +169,14 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
} }
else else
{ {
if (test.call().isConstructor) if (test.call().kind == FunctionCall::Kind::Constructor)
deploy("", test.call().value.value, test.call().arguments.rawBytes(), libraries); deploy("", test.call().value.value, test.call().arguments.rawBytes(), libraries);
else else
soltestAssert(deploy("", 0, bytes(), libraries), "Failed to deploy contract."); soltestAssert(deploy("", 0, bytes(), libraries), "Failed to deploy contract.");
constructed = true; constructed = true;
} }
if (test.call().isConstructor) if (test.call().kind == FunctionCall::Kind::Constructor)
{ {
if (m_transactionSuccessful == test.call().expectations.failure) if (m_transactionSuccessful == test.call().expectations.failure)
success = false; success = false;
@ -187,22 +187,27 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
else else
{ {
bytes output; bytes output;
if (test.call().useCallWithoutSignature) if (test.call().kind == FunctionCall::Kind::LowLevel)
output = callLowLevel(test.call().arguments.rawBytes(), test.call().value.value); output = callLowLevel(test.call().arguments.rawBytes(), test.call().value.value);
else else
{ {
soltestAssert( soltestAssert(
m_allowNonExistingFunctions || m_compiler.methodIdentifiers(m_compiler.lastContractName()) m_allowNonExistingFunctions ||
.isMember(test.call().signature), m_compiler.methodIdentifiers(m_compiler.lastContractName()).isMember(test.call().signature),
"The function " + test.call().signature + " is not known to the compiler"); "The function " + test.call().signature + " is not known to the compiler"
);
output = callContractFunctionWithValueNoEncoding( 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) if (
|| (output != test.call().expectations.rawBytes())) m_transactionSuccessful == test.call().expectations.failure ||
output != test.call().expectations.rawBytes()
)
success = false; success = false;
test.setFailure(!m_transactionSuccessful); test.setFailure(!m_transactionSuccessful);

View File

@ -275,16 +275,21 @@ struct FunctionCall
MultiLine MultiLine
}; };
DisplayMode displayMode = DisplayMode::SingleLine; DisplayMode displayMode = DisplayMode::SingleLine;
/// Marks this function call as the constructor.
bool isConstructor = false; enum class Kind {
/// If this function call's signature has no name and no arguments, Regular,
/// a low-level call with unstructured calldata will be issued. /// Marks this function call as the constructor.
bool useCallWithoutSignature = false; 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 /// Marks this function call as "short-handed", meaning
/// no `->` declared. /// no `->` declared.
bool omitsArrow = true; bool omitsArrow = true;
/// Marks a library deployment call.
bool isLibrary = false;
}; };
} }

View File

@ -82,12 +82,16 @@ vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
expect(Token::Colon); expect(Token::Colon);
call.signature = m_scanner.currentLiteral(); call.signature = m_scanner.currentLiteral();
expect(Token::Identifier); expect(Token::Identifier);
call.isLibrary = true; call.kind = FunctionCall::Kind::Library;
call.expectations.failure = false; call.expectations.failure = false;
} }
else 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)) if (accept(Token::Comma, true))
call.value = parseFunctionCallValue(); call.value = parseFunctionCallValue();
@ -124,8 +128,7 @@ vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
call.expectations.comment = parseComment(); call.expectations.comment = parseComment();
if (call.signature == "constructor()") if (call.signature == "constructor()")
call.isConstructor = true; call.kind = FunctionCall::Kind::Constructor;
} }
calls.emplace_back(std::move(call)); calls.emplace_back(std::move(call));

View File

@ -82,8 +82,8 @@ void testFunctionCall(
} }
} }
BOOST_REQUIRE_EQUAL(_call.isConstructor, _isConstructor); BOOST_REQUIRE_EQUAL(_call.kind == FunctionCall::Kind::Constructor, _isConstructor);
BOOST_REQUIRE_EQUAL(_call.isLibrary, _isLibrary); BOOST_REQUIRE_EQUAL(_call.kind == FunctionCall::Kind::Library, _isLibrary);
} }
BOOST_AUTO_TEST_SUITE(TestFileParserTest) BOOST_AUTO_TEST_SUITE(TestFileParserTest)

View File

@ -56,7 +56,7 @@ string TestFunctionCall::format(
string newline = formatToken(Token::Newline); string newline = formatToken(Token::Newline);
string failure = formatToken(Token::Failure); 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; stream << _linePrefix << newline << ws << "library:" << ws << m_call.signature;
return; return;