|
|
@ -42,7 +42,7 @@ class ExecutionFramework |
|
|
|
public: |
|
|
|
ExecutionFramework() { g_logVerbosity = 0; } |
|
|
|
|
|
|
|
bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") |
|
|
|
bytes const& execute(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") |
|
|
|
{ |
|
|
|
m_compiler.reset(false, m_addStandardSources); |
|
|
|
m_compiler.addSource("", _sourceCode); |
|
|
@ -50,13 +50,18 @@ public: |
|
|
|
|
|
|
|
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 = "") |
|
|
|
{ |
|
|
|
execute(_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 +79,31 @@ 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 +150,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 |
|
|
|
{ |
|
|
|