mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adds support for constructor arguments in isoltest.
This commit is contained in:
parent
37375b4271
commit
94597ad9ae
@ -55,7 +55,7 @@ SemanticTest::SemanticTest(string const& _filename, string const& _ipcPath, lang
|
||||
|
||||
TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||
{
|
||||
soltestAssert(deploy("", 0, bytes()), "Failed to deploy contract.");
|
||||
|
||||
|
||||
bool success = true;
|
||||
for (auto& test: m_tests)
|
||||
@ -63,18 +63,34 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
|
||||
|
||||
for (auto& test: m_tests)
|
||||
{
|
||||
bytes output = callContractFunctionWithValueNoEncoding(
|
||||
test.call().signature,
|
||||
test.call().value,
|
||||
test.call().arguments.rawBytes()
|
||||
);
|
||||
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 ((m_transactionSuccessful == test.call().expectations.failure) || (output != test.call().expectations.rawBytes()))
|
||||
success = false;
|
||||
if (test.call().isConstructor)
|
||||
{
|
||||
test.setFailure(false);
|
||||
test.setRawBytes(bytes());
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes output = callContractFunctionWithValueNoEncoding(
|
||||
test.call().signature,
|
||||
test.call().value,
|
||||
test.call().arguments.rawBytes()
|
||||
);
|
||||
|
||||
test.setFailure(!m_transactionSuccessful);
|
||||
test.setRawBytes(std::move(output));
|
||||
test.setContractABI(m_compiler.contractABI(m_compiler.lastContractName()));
|
||||
if ((m_transactionSuccessful == test.call().expectations.failure) || (output != test.call().expectations.rawBytes()))
|
||||
success = false;
|
||||
|
||||
test.setFailure(!m_transactionSuccessful);
|
||||
test.setRawBytes(std::move(output));
|
||||
test.setContractABI(m_compiler.contractABI(m_compiler.lastContractName()));
|
||||
}
|
||||
}
|
||||
|
||||
if (!success)
|
||||
|
@ -1,4 +1,8 @@
|
||||
contract C {
|
||||
uint public state = 0;
|
||||
constructor(uint _state) public {
|
||||
state = _state;
|
||||
}
|
||||
function f() payable public returns (uint) {
|
||||
return 2;
|
||||
}
|
||||
@ -31,6 +35,8 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// constructor(): 3 ->
|
||||
// state() -> 3
|
||||
// _() -> FAILURE
|
||||
// f() -> 2
|
||||
// f(), 1 ether -> 2
|
||||
|
@ -116,6 +116,9 @@ vector<dev::solidity::test::FunctionCall> TestFileParser::parseFunctionCalls()
|
||||
accept(Token::Newline, true);
|
||||
call.expectations.comment = parseComment();
|
||||
|
||||
if (call.signature == "constructor()")
|
||||
call.isConstructor = true;
|
||||
|
||||
calls.emplace_back(std::move(call));
|
||||
}
|
||||
}
|
||||
|
@ -248,6 +248,8 @@ struct FunctionCall
|
||||
MultiLine
|
||||
};
|
||||
DisplayMode displayMode = DisplayMode::SingleLine;
|
||||
/// Marks this function call as the constructor.
|
||||
bool isConstructor = false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user