aboutsummaryrefslogtreecommitdiffstats
path: root/solidityExecutionFramework.h
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2015-01-09 00:18:31 +0800
committerLefteris Karapetsas <lefteris@refu.co>2015-01-09 00:18:31 +0800
commitefdef7f526d7cdf0dead9036a27794126bc4dceb (patch)
treea1feef6ad82705386eb22d96043eecf5dac726c3 /solidityExecutionFramework.h
parent9f7e9d9cdd148892876c223de785ce70c2b50b36 (diff)
downloaddexon-solidity-efdef7f526d7cdf0dead9036a27794126bc4dceb.tar.gz
dexon-solidity-efdef7f526d7cdf0dead9036a27794126bc4dceb.tar.zst
dexon-solidity-efdef7f526d7cdf0dead9036a27794126bc4dceb.zip
Compiler EVM generation now takes into account for the new function hash
identifier - Changed tests to comply with the new function hash identifier - Changed the function index offset to 4, and made it a constant for easy adjustment in the future
Diffstat (limited to 'solidityExecutionFramework.h')
-rw-r--r--solidityExecutionFramework.h41
1 files changed, 12 insertions, 29 deletions
diff --git a/solidityExecutionFramework.h b/solidityExecutionFramework.h
index 9beabdc5..07c804cf 100644
--- a/solidityExecutionFramework.h
+++ b/solidityExecutionFramework.h
@@ -29,7 +29,6 @@
#include <libethereum/State.h>
#include <libethereum/Executive.h>
#include <libsolidity/CompilerStack.h>
-#include <libsolidity/AST.h>
namespace dev
{
@@ -49,57 +48,44 @@ public:
bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "")
{
- /* dev::solidity::CompilerStack compiler; */
- m_compiler.compile(_sourceCode, m_optimize);
- bytes code = m_compiler.getBytecode(_contractName);
- /* m_contractDefinition = compiler.getContractDefinition(_contractName); */
+ dev::solidity::CompilerStack compiler;
+ compiler.compile(_sourceCode, m_optimize);
+ bytes code = compiler.getBytecode(_contractName);
sendMessage(code, true, _value);
BOOST_REQUIRE(!m_output.empty());
return m_output;
}
- bytes const& callContractFunction(byte _index, bytes const& _data = bytes(),
+ bytes const& callContractFunction(std::string _sig, bytes const& _data = bytes(),
u256 const& _value = 0)
{
- /* if (!_contractDef) */
- /* _contractDef = m_contractDefinition; */
-
- unsigned index = 0;
- auto interfaceFunctions = m_compiler.getContractDefinition("").getInterfaceFunctions();
- for (auto it = interfaceFunctions.cbegin(); it != interfaceFunctions.cend(); ++it, ++index)
- if (index == _index)
- {
- sendMessage(it->first.asBytes() + _data, false, _value);
- /* sendMessage(bytes(1, _index) + _data, false, _value); */
- return m_output;
- }
-
- BOOST_FAIL("Function with index " << _index << "not found");
+ FixedHash<4> hash(dev::sha3(_sig));
+ sendMessage(hash.asBytes() + _data, false, _value);
return m_output;
}
template <class... Args>
- bytes const& callContractFunction(byte _index, Args const&... _arguments)
+ bytes const& callContractFunction(std::string _sig, Args const&... _arguments)
{
- return callContractFunction(_index, argsToBigEndian(_arguments...));
+ return callContractFunction(_sig, argsToBigEndian(_arguments...));
}
template <class CppFunction, class... Args>
- void testSolidityAgainstCpp(byte _index, CppFunction const& _cppFunction, Args const&... _arguments)
+ void testSolidityAgainstCpp(std::string _sig, CppFunction const& _cppFunction, Args const&... _arguments)
{
- bytes solidityResult = callContractFunction(_index, _arguments...);
+ 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));
}
template <class CppFunction, class... Args>
- void testSolidityAgainstCppOnRange(byte _index, CppFunction const& _cppFunction,
+ void testSolidityAgainstCppOnRange(std::string _sig, CppFunction const& _cppFunction,
u256 const& _rangeStart, u256 const& _rangeEnd)
{
for (u256 argument = _rangeStart; argument < _rangeEnd; ++argument)
{
- bytes solidityResult = callContractFunction(_index, 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) +
@@ -165,9 +151,6 @@ protected:
bool m_optimize = false;
Address m_sender;
Address m_contractAddress;
- /* ContractDefinition m_contractDefinition; */
- dev::solidity::CompilerStack m_compiler;
-
eth::State m_state;
u256 const m_gasPrice = 100 * eth::szabo;
u256 const m_gas = 1000000;