Browse Source

Merge pull request #2777 from CJentzsch/fixStateTestsFilling

compile code in accounts when importing state
cl-refactor
Gav Wood 10 years ago
parent
commit
d1465ea13f
  1. 11
      libethereum/Account.cpp
  2. 13
      test/TestHelper.cpp
  3. 8
      test/libethereum/blockchain.cpp
  4. 13
      test/libethereum/state.cpp

11
libethereum/Account.cpp

@ -20,6 +20,7 @@
*/ */
#include "Account.h" #include "Account.h"
#include <liblll/Compiler.h>
#include <test/JsonSpiritHeaders.h> #include <test/JsonSpiritHeaders.h>
#include <libethcore/Common.h> #include <libethcore/Common.h>
using namespace std; using namespace std;
@ -63,7 +64,15 @@ AccountMap dev::eth::jsonToAccountMap(std::string const& _json, AccountMaskMap*
if (haveCode) if (haveCode)
{ {
ret[a] = Account(balance, Account::ContractConception); ret[a] = Account(balance, Account::ContractConception);
ret[a].setCode(fromHex(o["code"].get_str())); if (o["code"].type() == json_spirit::str_type)
{
if (o["code"].get_str().find("0x") != 0)
ret[a].setCode(compileLLL(o["code"].get_str(), false));
else
ret[a].setCode(fromHex(o["code"].get_str().substr(2)));
}
else
cerr << "Error importing code of account " << a << "! Code field needs to be a string";
} }
else else
ret[a] = Account(balance, Account::NormalCreation); ret[a] = Account(balance, Account::NormalCreation);

13
test/TestHelper.cpp

@ -121,10 +121,21 @@ bytes ImportTest::executeTest()
{ {
ExecutionResult res; ExecutionResult res;
eth::State tmpState = m_statePre; eth::State tmpState = m_statePre;
try
{
std::pair<ExecutionResult, TransactionReceipt> execOut = m_statePre.execute(m_envInfo, m_transaction); std::pair<ExecutionResult, TransactionReceipt> execOut = m_statePre.execute(m_envInfo, m_transaction);
res = execOut.first; res = execOut.first;
m_logs = execOut.second.log(); m_logs = execOut.second.log();
}
catch (Exception const& _e)
{
cnote << "Exception: " << diagnostic_information(_e);
}
catch (std::exception const& _e)
{
cnote << "state execution exception: " << _e.what();
}
m_statePre.commit(); m_statePre.commit();
m_statePost = m_statePre; m_statePost = m_statePre;
m_statePre = tmpState; m_statePre = tmpState;

8
test/libethereum/blockchain.cpp

@ -51,14 +51,6 @@ void overwriteBlockHeader(BlockHeader& _current_BlockHeader, mObject& _blObj, co
void updatePoW(BlockHeader& _bi); void updatePoW(BlockHeader& _bi);
mArray importUncles(mObject const& _blObj, vector<BlockHeader>& _vBiUncles, vector<BlockHeader> const& _vBiBlocks, std::vector<blockSet> _blockSet); mArray importUncles(mObject const& _blObj, vector<BlockHeader>& _vBiUncles, vector<BlockHeader> const& _vBiBlocks, std::vector<blockSet> _blockSet);
//void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
//{
// if (_fillin == false)
// _v.get_bool();
// cerr << "BlockChainTests not implemented!" << endl;
//}
void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
{ {
for (auto& i: _v.get_obj()) for (auto& i: _v.get_obj())

13
test/libethereum/state.cpp

@ -59,20 +59,9 @@ void doStateTests(json_spirit::mValue& v, bool _fillin)
const State importedStatePost = importer.m_statePost; const State importedStatePost = importer.m_statePost;
bytes output; bytes output;
try // execute transaction
{
Listener::ExecTimeGuard guard{i.first}; Listener::ExecTimeGuard guard{i.first};
output = importer.executeTest(); output = importer.executeTest();
}
catch (Exception const& _e)
{
cnote << "Exception: " << diagnostic_information(_e);
//theState.commit();
}
catch (std::exception const& _e)
{
cnote << "state execution exception: " << _e.what();
}
if (_fillin) if (_fillin)
{ {

Loading…
Cancel
Save