aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/solidityExecutionFramework.h
diff options
context:
space:
mode:
authorsubtly <subtly@users.noreply.github.com>2015-06-04 22:55:59 +0800
committersubtly <subtly@users.noreply.github.com>2015-06-04 22:55:59 +0800
commit2afad75469658a45da547e3b78a652cc8c8ad728 (patch)
treef555ba9e1463cddf1d0750f8250968b946a51895 /libsolidity/solidityExecutionFramework.h
parentf9955c8ba10332f9c2a674ffdfc447895c15b01a (diff)
parent2f88fd6f5874a1f15135d443b5f05699ae971f18 (diff)
downloaddexon-solidity-2afad75469658a45da547e3b78a652cc8c8ad728.tar
dexon-solidity-2afad75469658a45da547e3b78a652cc8c8ad728.tar.gz
dexon-solidity-2afad75469658a45da547e3b78a652cc8c8ad728.tar.bz2
dexon-solidity-2afad75469658a45da547e3b78a652cc8c8ad728.tar.lz
dexon-solidity-2afad75469658a45da547e3b78a652cc8c8ad728.tar.xz
dexon-solidity-2afad75469658a45da547e3b78a652cc8c8ad728.tar.zst
dexon-solidity-2afad75469658a45da547e3b78a652cc8c8ad728.zip
Merge branch 'develop' into whisper
Diffstat (limited to 'libsolidity/solidityExecutionFramework.h')
-rw-r--r--libsolidity/solidityExecutionFramework.h54
1 files changed, 36 insertions, 18 deletions
diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h
index f76465f2..1e11ae90 100644
--- a/libsolidity/solidityExecutionFramework.h
+++ b/libsolidity/solidityExecutionFramework.h
@@ -42,21 +42,25 @@ class ExecutionFramework
public:
ExecutionFramework() { g_logVerbosity = 0; }
- bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "")
+ bytes const& compileAndRunWthoutCheck(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "")
{
- dev::solidity::CompilerStack compiler(m_addStandardSources);
- compiler.addSource("", _sourceCode);
- ETH_TEST_REQUIRE_NO_THROW(compiler.compile(m_optimize), "Compiling contract failed");
-
- bytes code = compiler.getBytecode(_contractName);
+ m_compiler.reset(false, m_addStandardSources);
+ m_compiler.addSource("", _sourceCode);
+ ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize), "Compiling contract failed");
+ bytes code = m_compiler.getBytecode(_contractName);
sendMessage(code, true, _value);
+ return m_output;
+ }
+
+ bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "")
+ {
+ compileAndRunWthoutCheck(_sourceCode, _value, _contractName);
BOOST_REQUIRE(!m_output.empty());
return m_output;
}
template <class... Args>
- bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value,
- Args const&... _arguments)
+ bytes const& callContractFunctionWithValue(std::string _sig, u256 const& _value, Args const&... _arguments)
{
FixedHash<4> hash(dev::sha3(_sig));
sendMessage(hash.asBytes() + encodeArgs(_arguments...), false, _value);
@@ -74,21 +78,30 @@ public:
{
bytes solidityResult = callContractFunction(_sig, _arguments...);
bytes cppResult = callCppAndEncodeResult(_cppFunction, _arguments...);
- BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match."
- "\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult));
+ BOOST_CHECK_MESSAGE(
+ solidityResult == cppResult,
+ "Computed values do not match.\nSolidity: " +
+ toHex(solidityResult) +
+ "\nC++: " +
+ toHex(cppResult));
}
template <class CppFunction, class... Args>
- void testSolidityAgainstCppOnRange(std::string _sig, CppFunction const& _cppFunction,
- u256 const& _rangeStart, u256 const& _rangeEnd)
+ void testSolidityAgainstCppOnRange(std::string _sig, CppFunction const& _cppFunction, u256 const& _rangeStart, u256 const& _rangeEnd)
{
for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument)
{
bytes solidityResult = callContractFunction(_sig, argument);
bytes cppResult = callCppAndEncodeResult(_cppFunction, argument);
- BOOST_CHECK_MESSAGE(solidityResult == cppResult, "Computed values do not match."
- "\nSolidity: " + toHex(solidityResult) + "\nC++: " + toHex(cppResult) +
- "\nArgument: " + toHex(encode(argument)));
+ BOOST_CHECK_MESSAGE(
+ solidityResult == cppResult,
+ "Computed values do not match.\nSolidity: " +
+ toHex(solidityResult) +
+ "\nC++: " +
+ toHex(cppResult) +
+ "\nArgument: " +
+ toHex(encode(argument))
+ );
}
}
@@ -135,8 +148,10 @@ protected:
{
m_state.addBalance(m_sender, _value); // just in case
eth::Executive executive(m_state, eth::LastHashes(), 0);
- eth::Transaction t = _isCreation ? eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec())
- : eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec());
+ eth::Transaction t =
+ _isCreation ?
+ eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec()) :
+ eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec());
bytes transactionRLP = t.rlp();
try
{
@@ -155,17 +170,19 @@ protected:
else
{
BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress));
- BOOST_REQUIRE(!executive.call(m_contractAddress, m_contractAddress, m_sender, _value, m_gasPrice, &_data, m_gas, m_sender));
+ BOOST_REQUIRE(!executive.call(m_contractAddress, m_sender, _value, m_gasPrice, &_data, m_gas));
}
BOOST_REQUIRE(executive.go());
m_state.noteSending(m_sender);
executive.finalize();
+ m_gasUsed = executive.gasUsed();
m_output = executive.out().toVector();
m_logs = executive.logs();
}
bool m_optimize = false;
bool m_addStandardSources = false;
+ dev::solidity::CompilerStack m_compiler;
Address m_sender;
Address m_contractAddress;
eth::State m_state;
@@ -173,6 +190,7 @@ protected:
u256 const m_gas = 100000000;
bytes m_output;
eth::LogEntries m_logs;
+ u256 m_gasUsed;
};
}