diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-19 22:34:15 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-19 22:34:15 +0800 |
commit | 933d65e9863e4f1d57500ccba85e6cde116d962a (patch) | |
tree | e524c296e8bf0a6464045908ac90210afaff4a2c /solidityExecutionFramework.h | |
parent | ae9ec885d7fa3f10fcfae51bab2db17f4770e4b3 (diff) | |
download | dexon-solidity-933d65e9863e4f1d57500ccba85e6cde116d962a.tar dexon-solidity-933d65e9863e4f1d57500ccba85e6cde116d962a.tar.gz dexon-solidity-933d65e9863e4f1d57500ccba85e6cde116d962a.tar.bz2 dexon-solidity-933d65e9863e4f1d57500ccba85e6cde116d962a.tar.lz dexon-solidity-933d65e9863e4f1d57500ccba85e6cde116d962a.tar.xz dexon-solidity-933d65e9863e4f1d57500ccba85e6cde116d962a.tar.zst dexon-solidity-933d65e9863e4f1d57500ccba85e6cde116d962a.zip |
Some addition to Solidity Execution Framework
Diffstat (limited to 'solidityExecutionFramework.h')
-rw-r--r-- | solidityExecutionFramework.h | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/solidityExecutionFramework.h b/solidityExecutionFramework.h index 8d3c7e77..1160d046 100644 --- a/solidityExecutionFramework.h +++ b/solidityExecutionFramework.h @@ -29,6 +29,7 @@ #include <libethereum/State.h> #include <libethereum/Executive.h> #include <libsolidity/CompilerStack.h> +#include "TestHelper.h" namespace dev { @@ -46,7 +47,20 @@ 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); + try + { + compiler.compile(_sourceCode, m_optimize); + } + catch (const std::exception& e) + { + std::string const* extra = boost::get_error_info<errinfo_comment>(e); + std::string msg = std::string("Parsing contract failed with: ") + + e.what() + std::string("\n"); + if (extra) + msg += *extra; + BOOST_FAIL(msg); + } + bytes code = compiler.getBytecode(_contractName); sendMessage(code, true, _value); BOOST_REQUIRE(!m_output.empty()); @@ -97,6 +111,7 @@ public: static bytes encode(char const* _value) { return encode(std::string(_value)); } static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; } static bytes encode(u256 const& _value) { return toBigEndian(_value); } + static bytes encode(h256 const& _value) { return _value.asBytes(); } static bytes encode(bytes const& _value, bool _padLeft = true) { bytes padding = bytes((32 - _value.size() % 32) % 32, 0); @@ -114,6 +129,12 @@ public: return bytes(); } + eth::LastHashes setCurrentBlockNumber(u256 _currentBlockNumber) + { + m_lastHashes = dev::test::lastHashes(_currentBlockNumber); + return m_lastHashes; + } + private: template <class CppFunction, class... Args> auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments) @@ -132,7 +153,7 @@ private: void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0) { m_state.addBalance(m_sender, _value); // just in case - eth::Executive executive(m_state, eth::LastHashes(), 0); + eth::Executive executive(m_state, m_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()); bytes transactionRLP = t.rlp(); @@ -170,6 +191,7 @@ protected: u256 const m_gas = 1000000; bytes m_output; eth::LogEntries m_logs; + eth::LastHashes m_lastHashes; }; } |