Adds support for constructor arguments in isoltest.

This commit is contained in:
Erik Kundt 2019-05-15 12:01:14 +02:00
parent 37375b4271
commit 94597ad9ae
4 changed files with 38 additions and 11 deletions

View File

@ -55,13 +55,28 @@ SemanticTest::SemanticTest(string const& _filename, string const& _ipcPath, lang
TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePrefix, bool _formatted) TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
{ {
soltestAssert(deploy("", 0, bytes()), "Failed to deploy contract.");
bool success = true; bool success = true;
for (auto& test: m_tests) for (auto& test: m_tests)
test.reset(); test.reset();
for (auto& test: m_tests) for (auto& test: m_tests)
{
if (&test == &m_tests.front())
if (test.call().isConstructor)
soltestAssert(deploy("", 0, test.call().arguments.rawBytes()), "Failed to deploy contract with additional constructor arguments.");
else
soltestAssert(deploy("", 0, bytes()), "Failed to deploy contract.");
else
soltestAssert(!test.call().isConstructor, "Constructor has to be the first function call.");
if (test.call().isConstructor)
{
test.setFailure(false);
test.setRawBytes(bytes());
}
else
{ {
bytes output = callContractFunctionWithValueNoEncoding( bytes output = callContractFunctionWithValueNoEncoding(
test.call().signature, test.call().signature,
@ -76,6 +91,7 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
test.setRawBytes(std::move(output)); test.setRawBytes(std::move(output));
test.setContractABI(m_compiler.contractABI(m_compiler.lastContractName())); test.setContractABI(m_compiler.contractABI(m_compiler.lastContractName()));
} }
}
if (!success) if (!success)
{ {

View File

@ -1,4 +1,8 @@
contract C { contract C {
uint public state = 0;
constructor(uint _state) public {
state = _state;
}
function f() payable public returns (uint) { function f() payable public returns (uint) {
return 2; return 2;
} }
@ -31,6 +35,8 @@ contract C {
} }
} }
// ---- // ----
// constructor(): 3 ->
// state() -> 3
// _() -> FAILURE // _() -> FAILURE
// f() -> 2 // f() -> 2
// f(), 1 ether -> 2 // f(), 1 ether -> 2

View File

@ -116,6 +116,9 @@ vector<dev::solidity::test::FunctionCall> TestFileParser::parseFunctionCalls()
accept(Token::Newline, true); accept(Token::Newline, true);
call.expectations.comment = parseComment(); call.expectations.comment = parseComment();
if (call.signature == "constructor()")
call.isConstructor = true;
calls.emplace_back(std::move(call)); calls.emplace_back(std::move(call));
} }
} }

View File

@ -248,6 +248,8 @@ struct FunctionCall
MultiLine MultiLine
}; };
DisplayMode displayMode = DisplayMode::SingleLine; DisplayMode displayMode = DisplayMode::SingleLine;
/// Marks this function call as the constructor.
bool isConstructor = false;
}; };
/** /**