From 849ccb41596ac77b429e8e33a98335cf59dfbbfa Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 5 Nov 2014 17:50:59 +0100 Subject: [PATCH] Fix test framework after change to Transaction. --- solidityEndToEndTest.cpp | 47 +++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp index 7bb01fa12..5aeaf3e61 100644 --- a/solidityEndToEndTest.cpp +++ b/solidityEndToEndTest.cpp @@ -39,39 +39,56 @@ namespace test class ExecutionFramework { public: - ExecutionFramework() { g_logVerbosity = 0; } + ExecutionFramework(): m_executive(m_state) { g_logVerbosity = 0; } bytes compileAndRun(std::string const& _sourceCode) { bytes code = dev::solidity::CompilerStack::compile(_sourceCode); - eth::Executive ex(m_state); - BOOST_REQUIRE(!ex.create(Address(), 0, m_gasPrice, m_gas, &code, Address())); - BOOST_REQUIRE(ex.go()); - ex.finalize(); - m_contractAddress = ex.newAddress(); - return ex.out().toBytes(); + sendMessage(code, true); + m_contractAddress = m_executive.newAddress(); + BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); + return m_output; } bytes callFunction(byte _index, bytes const& _data) { - bytes data = bytes(1, _index) + _data; - eth::Executive ex(m_state); - BOOST_REQUIRE(!ex.call(m_contractAddress, Address(), 0, m_gasPrice, &data, m_gas, Address())); - BOOST_REQUIRE(ex.go()); - ex.finalize(); - return ex.out().toBytes(); + sendMessage(bytes(1, _index) + _data, false); + return m_output; } - bytes callFunction(byte _index, u256 const& _argument) + bytes callFunction(byte _index, u256 const& _argument1) { - return callFunction(_index, toBigEndian(_argument)); + callFunction(_index, toBigEndian(_argument1)); + return m_output; } private: + void sendMessage(bytes const& _data, bool _isCreation) + { + eth::Transaction t = _isCreation ? eth::Transaction(0, m_gasPrice, m_gas, _data) + : eth::Transaction(0, m_gasPrice, m_gas, m_contractAddress, _data); + bytes transactionRLP = t.rlp(); + try + { + // this will throw since the transaction is invalid, but it should nevertheless store the transaction + m_executive.setup(&transactionRLP); + } + catch (...) {} + if (_isCreation) + BOOST_REQUIRE(!m_executive.create(Address(), 0, m_gasPrice, m_gas, &_data, Address())); + else + BOOST_REQUIRE(!m_executive.call(m_contractAddress, Address(), 0, m_gasPrice, &_data, m_gas, Address())); + BOOST_REQUIRE(m_executive.go()); + m_executive.finalize(); + m_output = m_executive.out().toBytes(); + } + Address m_contractAddress; eth::State m_state; + eth::Executive m_executive; u256 const m_gasPrice = 100 * eth::szabo; u256 const m_gas = 1000000; + bytes m_output; }; BOOST_AUTO_TEST_SUITE(SolidityCompilerEndToEndTest)