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)
|
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)
|
||||||
@ -63,18 +63,34 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
|
|||||||
|
|
||||||
for (auto& test: m_tests)
|
for (auto& test: m_tests)
|
||||||
{
|
{
|
||||||
bytes output = callContractFunctionWithValueNoEncoding(
|
if (&test == &m_tests.front())
|
||||||
test.call().signature,
|
if (test.call().isConstructor)
|
||||||
test.call().value,
|
soltestAssert(deploy("", 0, test.call().arguments.rawBytes()), "Failed to deploy contract with additional constructor arguments.");
|
||||||
test.call().arguments.rawBytes()
|
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()))
|
if (test.call().isConstructor)
|
||||||
success = false;
|
{
|
||||||
|
test.setFailure(false);
|
||||||
|
test.setRawBytes(bytes());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bytes output = callContractFunctionWithValueNoEncoding(
|
||||||
|
test.call().signature,
|
||||||
|
test.call().value,
|
||||||
|
test.call().arguments.rawBytes()
|
||||||
|
);
|
||||||
|
|
||||||
test.setFailure(!m_transactionSuccessful);
|
if ((m_transactionSuccessful == test.call().expectations.failure) || (output != test.call().expectations.rawBytes()))
|
||||||
test.setRawBytes(std::move(output));
|
success = false;
|
||||||
test.setContractABI(m_compiler.contractABI(m_compiler.lastContractName()));
|
|
||||||
|
test.setFailure(!m_transactionSuccessful);
|
||||||
|
test.setRawBytes(std::move(output));
|
||||||
|
test.setContractABI(m_compiler.contractABI(m_compiler.lastContractName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
|
@ -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
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user