blockchain tests fixes

This commit is contained in:
CJentzsch 2015-03-09 10:28:48 +01:00
parent 2026871882
commit f0a216943f
4 changed files with 37 additions and 44 deletions

View File

@ -181,46 +181,35 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost)
m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries()); m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries());
// export post state // export post state
json_spirit::mObject postState;
for (auto const& a: _statePost.addresses())
{
json_spirit::mObject o;
o["balance"] = toString(_statePost.balance(a.first));
o["nonce"] = toString(_statePost.transactionsFrom(a.first));
{
json_spirit::mObject store;
for (auto const& s: _statePost.storage(a.first))
store["0x"+toHex(toCompactBigEndian(s.first))] = "0x"+toHex(toCompactBigEndian(s.second));
o["storage"] = store;
}
o["code"] = "0x" + toHex(_statePost.code(a.first));
postState[toString(a.first)] = o;
}
m_TestObject["post"] = json_spirit::mValue(postState);
m_TestObject["post"] = fillJsonWithState(_statePost);
m_TestObject["postStateRoot"] = toHex(_statePost.rootHash().asBytes()); m_TestObject["postStateRoot"] = toHex(_statePost.rootHash().asBytes());
// export pre state // export pre state
json_spirit::mObject preState; m_TestObject["pre"] = fillJsonWithState(m_statePre);
}
for (auto const& a: m_statePre.addresses()) json_spirit::mObject fillJsonWithState(State _state)
{
// export pre state
json_spirit::mObject oState;
for (auto const& a: _state.addresses())
{ {
json_spirit::mObject o; json_spirit::mObject o;
o["balance"] = toString(m_statePre.balance(a.first)); o["balance"] = toString(_state.balance(a.first));
o["nonce"] = toString(m_statePre.transactionsFrom(a.first)); o["nonce"] = toString(_state.transactionsFrom(a.first));
{ {
json_spirit::mObject store; json_spirit::mObject store;
for (auto const& s: m_statePre.storage(a.first)) for (auto const& s: _state.storage(a.first))
store["0x"+toHex(toCompactBigEndian(s.first))] = "0x"+toHex(toCompactBigEndian(s.second)); store["0x"+toHex(toCompactBigEndian(s.first))] = "0x"+toHex(toCompactBigEndian(s.second));
o["storage"] = store; o["storage"] = store;
} }
o["code"] = "0x" + toHex(m_statePre.code(a.first)); o["code"] = "0x" + toHex(_state.code(a.first));
preState[toString(a.first)] = o; oState[toString(a.first)] = o;
} }
m_TestObject["pre"] = json_spirit::mValue(preState); return oState;
} }
u256 toInt(json_spirit::mValue const& _v) u256 toInt(json_spirit::mValue const& _v)

View File

@ -117,6 +117,13 @@ private:
json_spirit::mObject& m_TestObject; json_spirit::mObject& m_TestObject;
}; };
class ZeroGasPricer: public eth::GasPricer
{
protected:
u256 ask(eth::State const&) const override { return 0; }
u256 bid(eth::TransactionPriority = eth::TransactionPriority::Medium) const override { return 0; }
};
// helping functions // helping functions
u256 toInt(json_spirit::mValue const& _v); u256 toInt(json_spirit::mValue const& _v);
byte toByte(json_spirit::mValue const& _v); byte toByte(json_spirit::mValue const& _v);
@ -136,6 +143,7 @@ void userDefinedTest(std::string testTypeFlag, std::function<void(json_spirit::m
RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj); RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj);
void processCommandLineOptions(); void processCommandLineOptions();
eth::LastHashes lastHashes(u256 _currentBlockNumber); eth::LastHashes lastHashes(u256 _currentBlockNumber);
json_spirit::mObject fillJsonWithState(eth::State _state);
template<typename mapType> template<typename mapType>
void checkAddresses(mapType& _expectedAddrs, mapType& _resultAddrs) void checkAddresses(mapType& _expectedAddrs, mapType& _resultAddrs)

View File

@ -265,23 +265,7 @@
"uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
}, },
{ {
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "theSameAsBefore" : "1"
"coinbase" : "0000000000000000000000000000000000000000",
"difficulty" : "131072",
"extraData" : "0x",
"gasLimit" : "99902343",
"gasUsed" : "0",
"hash" : "9de9879b6a81d1b6c4993c63c90a3c9d1e775f14572694778e828bc64972ae04",
"mixHash" : "b557f905d29ed0fca99d65d0adcce698dee97cf72a13c7cd8d7a7826b8eee770",
"nonce" : "18a524c1790fa83b",
"number" : "2",
"parentHash" : "6134fc6b5d99ee03c4aab1592640f6f9dcbc850668d75d631aee34989b938fae",
"receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"seedHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"stateRoot" : "ff640b30d613c35dad43e3693329e1b1ee6350f989cf46a288025a1cbfdab9cd",
"timestamp" : "0x54c98c82",
"transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
} }
] ]
} }

View File

@ -52,6 +52,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
ImportTest importer(o["pre"].get_obj()); ImportTest importer(o["pre"].get_obj());
State state(Address(), OverlayDB(), BaseState::Empty); State state(Address(), OverlayDB(), BaseState::Empty);
importer.importState(o["pre"].get_obj(), state); importer.importState(o["pre"].get_obj(), state);
o["pre"] = fillJsonWithState(state);
state.commit(); state.commit();
if (_fillin) if (_fillin)
@ -87,7 +88,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
// get txs // get txs
TransactionQueue txs; TransactionQueue txs;
TrivialGasPricer gp; ZeroGasPricer gp;
BOOST_REQUIRE(blObj.count("transactions")); BOOST_REQUIRE(blObj.count("transactions"));
for (auto const& txObj: blObj["transactions"].get_array()) for (auto const& txObj: blObj["transactions"].get_array())
{ {
@ -101,10 +102,18 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
BlockQueue uncleBlockQueue; BlockQueue uncleBlockQueue;
mArray aUncleList; mArray aUncleList;
vector<BlockInfo> vBiUncles; vector<BlockInfo> vBiUncles;
mObject uncleHeaderObj_pre;
for (auto const& uHObj: blObj["uncleHeaders"].get_array()) for (auto const& uHObj: blObj["uncleHeaders"].get_array())
{ {
mObject uncleHeaderObj = uHObj.get_obj(); mObject uncleHeaderObj = uHObj.get_obj();
if ( uncleHeaderObj.count("theSameAsBefore") )
{
writeBlockHeaderToJson(uncleHeaderObj_pre, vBiUncles[vBiUncles.size()-1]);
aUncleList.push_back(uncleHeaderObj_pre);
vBiUncles.push_back(vBiUncles[vBiUncles.size()-1]);
continue;
}
BlockInfo uncleBlockFromFields = constructBlock(uncleHeaderObj); BlockInfo uncleBlockFromFields = constructBlock(uncleHeaderObj);
// make uncle header valid // make uncle header valid
@ -123,6 +132,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
cnote << "import uncle in blockQueue"; cnote << "import uncle in blockQueue";
RLPStream uncle = createFullBlockFromHeader(uncleBlockFromFields); RLPStream uncle = createFullBlockFromHeader(uncleBlockFromFields);
uncleBlockQueue.import(&uncle.out(), bc); uncleBlockQueue.import(&uncle.out(), bc);
uncleHeaderObj_pre = uncleHeaderObj;
} }
blObj["uncleHeaders"] = aUncleList; blObj["uncleHeaders"] = aUncleList;
@ -579,6 +590,7 @@ void updatePoW(BlockInfo& _bi)
ret = pow.mine(_bi, 10000, true, true); // tie(ret, blockFromFields.nonce) ret = pow.mine(_bi, 10000, true, true); // tie(ret, blockFromFields.nonce)
Ethash::assignResult(ret.second, _bi); Ethash::assignResult(ret.second, _bi);
} }
_bi.hash = _bi.headerHash(WithNonce);
} }
void writeBlockHeaderToJson(mObject& _o, const BlockInfo& _bi) void writeBlockHeaderToJson(mObject& _o, const BlockInfo& _bi)