mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10140 from ethereum/isoltestfunctioncallkind
Refactor isoltest function call kind.
This commit is contained in:
commit
f42280f5c9
@ -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);
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -82,12 +82,16 @@ vector<solidity::frontend::test::FunctionCall> 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<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
|
||||
call.expectations.comment = parseComment();
|
||||
|
||||
if (call.signature == "constructor()")
|
||||
call.isConstructor = true;
|
||||
|
||||
call.kind = FunctionCall::Kind::Constructor;
|
||||
}
|
||||
|
||||
calls.emplace_back(std::move(call));
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user