From 69a0dcfa15fe4789dc4bfb02eda3427f24780caa Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 8 Jan 2015 00:19:19 +0100 Subject: [PATCH] work in progress in testing the new function selector in the end to end tests --- libsolidity/Compiler.cpp | 6 +++--- test/solidityExecutionFramework.h | 29 ++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/libsolidity/Compiler.cpp b/libsolidity/Compiler.cpp index 83fd69f52..514e1a27c 100644 --- a/libsolidity/Compiler.cpp +++ b/libsolidity/Compiler.cpp @@ -124,12 +124,12 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract) if (interfaceFunctions.size() > 4294967295) // 2 ** 32 BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("More than 4294967295 public functions for contract.")); - // retrieve the first function signature hash from the calldata - m_context << u256(1) << u256(0) << u256(2.6959947e+67) // some constants + // retrieve the function signature hash from the calldata + m_context << u256(1) << u256(0) << u256(4294967296) * u256(4294967296) * u256(4294967296) * u256(4294967296) * u256(4294967296) * u256(4294967296) * u256(4294967296)// some constants << eth::dupInstruction(2) << eth::Instruction::CALLDATALOAD << eth::Instruction::DIV; - // stack now is: 1 0 2.6959947e+67 + // stack now is: 1 0 for (auto it = interfaceFunctions.begin(); it != interfaceFunctions.end(); ++it) { callDataUnpackerEntryPoints.push_back(m_context.newTag()); diff --git a/test/solidityExecutionFramework.h b/test/solidityExecutionFramework.h index 9f25b3725..9beabdc54 100644 --- a/test/solidityExecutionFramework.h +++ b/test/solidityExecutionFramework.h @@ -29,6 +29,7 @@ #include #include #include +#include namespace dev { @@ -48,17 +49,32 @@ public: bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") { - dev::solidity::CompilerStack compiler; - compiler.compile(_sourceCode, m_optimize); - bytes code = compiler.getBytecode(_contractName); + /* dev::solidity::CompilerStack compiler; */ + m_compiler.compile(_sourceCode, m_optimize); + bytes code = m_compiler.getBytecode(_contractName); + /* m_contractDefinition = compiler.getContractDefinition(_contractName); */ sendMessage(code, true, _value); BOOST_REQUIRE(!m_output.empty()); return m_output; } - bytes const& callContractFunction(byte _index, bytes const& _data = bytes(), u256 const& _value = 0) + bytes const& callContractFunction(byte _index, bytes const& _data = bytes(), + u256 const& _value = 0) { - sendMessage(bytes(1, _index) + _data, false, _value); + /* 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"); return m_output; } @@ -149,6 +165,9 @@ 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;