Browse Source

VM tests prettier.

cl-refactor
Gav Wood 11 years ago
parent
commit
fecedd1d87
  1. 2
      alethzero/MainWin.cpp
  2. 7
      libethereum/State.cpp
  3. 55
      test/vm.cpp

2
alethzero/MainWin.cpp

@ -1347,7 +1347,7 @@ void Main::updateDebugger()
ui->debugMemory->setHtml(QString::fromStdString(eth::memDump(ws.memory, 16, true))); ui->debugMemory->setHtml(QString::fromStdString(eth::memDump(ws.memory, 16, true)));
ui->debugCode->setCurrentRow(m_pcWarp[(unsigned)ws.curPC]); ui->debugCode->setCurrentRow(m_pcWarp[(unsigned)ws.curPC]);
ostringstream ss; ostringstream ss;
ss << hex << "PC: 0x" << ws.curPC << " | GAS: 0x" << ws.gas; ss << hex << "PC: 0x" << ws.curPC << " | GAS: " << dec << ws.gas << " | (- " << dec << ws.gasUsed << ")";
ui->debugStateInfo->setText(QString::fromStdString(ss.str())); ui->debugStateInfo->setText(QString::fromStdString(ss.str()));
stringstream s; stringstream s;

7
libethereum/State.cpp

@ -760,6 +760,7 @@ MineInfo State::mine(uint _msTimeout)
void State::completeMine() void State::completeMine()
{ {
cdebug << "Completing mine!";
// Got it! // Got it!
// Commit to disk. // Commit to disk.
@ -774,6 +775,12 @@ void State::completeMine()
ret.swapOut(m_currentBytes); ret.swapOut(m_currentBytes);
m_currentBlock.hash = sha3(m_currentBytes); m_currentBlock.hash = sha3(m_currentBytes);
cnote << "Mined " << m_currentBlock.hash << "(parent: " << m_currentBlock.parentHash << ")"; cnote << "Mined " << m_currentBlock.hash << "(parent: " << m_currentBlock.parentHash << ")";
// Quickly reset the transactions.
// TODO: Leave this in a better state than this limbo, or at least record that it's in limbo.
m_transactions.clear();
m_transactionSet.clear();
m_lastTx = m_db;
} }
bool State::addressInUse(Address _id) const bool State::addressInUse(Address _id) const

55
test/vm.cpp

@ -231,21 +231,16 @@ public:
store[curKey] = curVal; store[curKey] = curVal;
o["storage"] = store; o["storage"] = store;
} }
{ o["code"] = "0x" + toHex(get<3>(a.second));
mArray d;
for (auto const& i: get<3>(a.second))
push(d, i);
o["code"] = d;
}
ret[toString(a.first)] = o; ret[toString(a.first)] = o;
} }
return ret; return ret;
} }
void importState(mObject& _o) void importState(mObject& _object)
{ {
for (auto const& i: _o) for (auto const& i: _object)
{ {
mObject o = i.second.get_obj(); mObject o = i.second.get_obj();
BOOST_REQUIRE(o.count("balance") > 0); BOOST_REQUIRE(o.count("balance") > 0);
@ -262,8 +257,12 @@ public:
for (auto const& k: j.second.get_array()) for (auto const& k: j.second.get_array())
get<2>(a)[adr++] = toInt(k); get<2>(a)[adr++] = toInt(k);
} }
if (o["code"].type() == str_type) if (o["code"].type() == str_type)
get<3>(a) = compileLLL(o["code"].get_str()); if (o["code"].get_str().find_first_of("0x") != 0)
get<3>(a) = compileLLL(o["code"].get_str(), false);
else
get<3>(a) = fromHex(o["code"].get_str().substr(2));
else else
{ {
get<3>(a).clear(); get<3>(a).clear();
@ -282,14 +281,8 @@ public:
push(ret, "value", value); push(ret, "value", value);
push(ret, "gasPrice", gasPrice); push(ret, "gasPrice", gasPrice);
push(ret, "gas", gas); push(ret, "gas", gas);
mArray d; ret["data"] = "0x" + toHex(data);
for (auto const& i: data) ret["code"] = "0x" + toHex(code);
push(d, i);
ret["data"] = d;
mArray c;
for (auto const& i: code)
push(c, i);
ret["code"] = c;
return ret; return ret;
} }
@ -313,7 +306,10 @@ public:
thisTxCode.clear(); thisTxCode.clear();
code = &thisTxCode; code = &thisTxCode;
if (_o["code"].type() == str_type) if (_o["code"].type() == str_type)
thisTxCode = compileLLL(_o["code"].get_str()); if (_o["code"].get_str().find_first_of("0x") == 0)
thisTxCode = compileLLL(_o["code"].get_str());
else
thisTxCode = fromHex(_o["code"].get_str().substr(2));
else if (_o["code"].type() == array_type) else if (_o["code"].type() == array_type)
for (auto const& j: _o["code"].get_array()) for (auto const& j: _o["code"].get_array())
thisTxCode.push_back(toByte(j)); thisTxCode.push_back(toByte(j));
@ -322,7 +318,10 @@ public:
thisTxData.clear(); thisTxData.clear();
if (_o["data"].type() == str_type) if (_o["data"].type() == str_type)
thisTxData = fromHex(_o["data"].get_str()); if (_o["data"].get_str().find_first_of("0x") == 0)
thisTxData = fromHex(_o["data"].get_str().substr(2));
else
thisTxData = fromHex(_o["data"].get_str());
else else
for (auto const& j: _o["data"].get_array()) for (auto const& j: _o["data"].get_array())
thisTxData.push_back(toByte(j)); thisTxData.push_back(toByte(j));
@ -338,10 +337,7 @@ public:
o["destination"] = toString(tx.receiveAddress); o["destination"] = toString(tx.receiveAddress);
push(o, "gasLimit", tx.gas); push(o, "gasLimit", tx.gas);
push(o, "value", tx.value); push(o, "value", tx.value);
mArray d; o["data"] = "0x" + toHex(tx.data);
for (auto const& i: tx.data)
push(d, i);
o["data"] = d;
ret.push_back(o); ret.push_back(o);
} }
return ret; return ret;
@ -361,7 +357,10 @@ public:
t.value = toInt(tx["value"]); t.value = toInt(tx["value"]);
t.gas = toInt(tx["gasLimit"]); t.gas = toInt(tx["gasLimit"]);
if (tx["data"].type() == str_type) if (tx["data"].type() == str_type)
t.data = fromHex(tx["data"].get_str()); if (tx["data"].get_str().find_first_of("0x") == 0)
t.data = fromHex(tx["data"].get_str().substr(2));
else
t.data = fromHex(tx["data"].get_str());
else else
for (auto const& j: tx["data"].get_array()) for (auto const& j: tx["data"].get_array())
t.data.push_back(toByte(j)); t.data.push_back(toByte(j));
@ -468,7 +467,7 @@ void doTests(json_spirit::mValue& v, bool _fillin)
BOOST_AUTO_TEST_CASE(vm_tests) BOOST_AUTO_TEST_CASE(vm_tests)
{ {
// Populate tests first: // Populate tests first:
/* try // try
{ {
cnote << "Populating VM tests..."; cnote << "Populating VM tests...";
json_spirit::mValue v; json_spirit::mValue v;
@ -478,11 +477,11 @@ BOOST_AUTO_TEST_CASE(vm_tests)
eth::test::doTests(v, true); eth::test::doTests(v, true);
writeFile("../../../tests/vmtests.json", asBytes(json_spirit::write_string(v, true))); writeFile("../../../tests/vmtests.json", asBytes(json_spirit::write_string(v, true)));
} }
catch (std::exception const& e) /* catch (std::exception const& e)
{ {
BOOST_ERROR("Failed VM Test with Exception: " << e.what()); BOOST_ERROR("Failed VM Test with Exception: " << e.what());
} }*/
*/
try try
{ {
cnote << "Testing VM..."; cnote << "Testing VM...";

Loading…
Cancel
Save