Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 78355a2

Browse files
author
winsvega
authored
Merge pull request #5712 from ethereum/noreward2
fix testeth stateTests transaction execution on expectSections
2 parents 782a728 + fc3e25d commit 78355a2

File tree

2 files changed

+87
-32
lines changed

2 files changed

+87
-32
lines changed

test/tools/libtesteth/ImportTest.cpp

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ vector<h256> lastHashes(u256 _currentBlockNumber)
4444
ret.push_back(sha3(toString(_currentBlockNumber - i)));
4545
return ret;
4646
}
47+
48+
vector<int> parseJsonIntValueIntoVector(json_spirit::mValue const& _json)
49+
{
50+
vector<int> out;
51+
if (_json.type() == json_spirit::array_type)
52+
{
53+
for (auto const& val : _json.get_array())
54+
out.push_back(val.get_int());
55+
}
56+
else
57+
out.push_back(_json.get_int());
58+
return out;
59+
}
4760
}
4861

4962
ImportTest::ImportTest(json_spirit::mObject const& _input, json_spirit::mObject& _output):
@@ -205,6 +218,52 @@ set<eth::Network> ImportTest::getAllNetworksFromExpectSections(
205218
return networkSet;
206219
}
207220

221+
void ImportTest::parseJsonStrValueIntoSet(json_spirit::mValue const& _json, set<string>& _out)
222+
{
223+
if (_json.type() == json_spirit::array_type)
224+
{
225+
for (auto const& val : _json.get_array())
226+
_out.emplace(val.get_str());
227+
}
228+
else
229+
_out.emplace(_json.get_str());
230+
}
231+
232+
bool ImportTest::findExpectSectionForTransaction(
233+
transactionToExecute const& _tr, eth::Network const& _net, bool _isFilling) const
234+
{
235+
json_spirit::mArray const& expects =
236+
_isFilling ? m_testInputObject.at("expect").get_array() :
237+
m_testInputObject.at("post").get_obj().at(netIdToString(_net)).get_array();
238+
for (auto const& exp : expects)
239+
{
240+
json_spirit::mObject const& expSection = exp.get_obj();
241+
242+
if (_isFilling)
243+
{
244+
set<string> networkSet;
245+
parseJsonStrValueIntoSet(expSection.at("network"), networkSet);
246+
networkSet = test::translateNetworks(networkSet);
247+
if (!networkSet.count(netIdToString(_net)))
248+
continue;
249+
}
250+
251+
BOOST_REQUIRE_MESSAGE(expSection.at("indexes").type() == jsonVType::obj_type,
252+
"indexes field expected to be json Object!");
253+
json_spirit::mObject const& indexes = expSection.at("indexes").get_obj();
254+
vector<int> d = parseJsonIntValueIntoVector(indexes.at("data"));
255+
vector<int> g = parseJsonIntValueIntoVector(indexes.at("gas"));
256+
vector<int> v = parseJsonIntValueIntoVector(indexes.at("value"));
257+
BOOST_CHECK_MESSAGE(d.size() > 0 && g.size() > 0 && v.size() > 0,
258+
TestOutputHelper::get().testName() + " Indexes arrays not set!");
259+
if ((inArray(d, _tr.dataInd) || inArray(d, -1)) &&
260+
(inArray(g, _tr.gasInd) || inArray(g, -1)) &&
261+
(inArray(v, _tr.valInd) || inArray(v, -1)))
262+
return true;
263+
}
264+
return false;
265+
}
266+
208267
bytes ImportTest::executeTest(bool _isFilling)
209268
{
210269
assert(m_envInfo);
@@ -231,7 +290,7 @@ bytes ImportTest::executeTest(bool _isFilling)
231290
if (isDisabledNetwork(net))
232291
continue;
233292

234-
for (auto& tr : m_transactions)
293+
for (auto const& tr : m_transactions)
235294
{
236295
Options const& opt = Options::get();
237296
if(opt.trDataIndex != -1 && opt.trDataIndex != tr.dataInd)
@@ -241,10 +300,25 @@ bytes ImportTest::executeTest(bool _isFilling)
241300
if(opt.trValueIndex != -1 && opt.trValueIndex != tr.valInd)
242301
continue;
243302

244-
std::tie(tr.postState, tr.output, tr.changeLog) =
245-
executeTransaction(net, *m_envInfo, m_statePre, tr.transaction);
246-
tr.netId = net;
247-
transactionResults.push_back(tr);
303+
// Skip transaction if there is no expect section for this transaction
304+
// (noindex data, gas, val, network)
305+
if (!findExpectSectionForTransaction(tr, net, _isFilling))
306+
continue;
307+
308+
transactionToExecute transactionResult = tr;
309+
std::tie(transactionResult.postState, transactionResult.output,
310+
transactionResult.changeLog) =
311+
executeTransaction(net, *m_envInfo, m_statePre, tr.transaction);
312+
transactionResult.netId = net;
313+
if (Options::get().verbosity > 2)
314+
{
315+
std::cout << "Executed transaction: \n";
316+
std::cerr << "Network: " << netIdToString(transactionResult.netId) << "\n";
317+
std::cerr << "Indexes: d: " << transactionResult.dataInd
318+
<< " g: " << transactionResult.gasInd
319+
<< " v: " << transactionResult.valInd << "\n\n";
320+
}
321+
transactionResults.push_back(transactionResult);
248322
}
249323
}
250324

@@ -599,28 +673,6 @@ int ImportTest::compareStates(State const& _stateExpect, State const& _statePost
599673
return wasError;
600674
}
601675

602-
void ImportTest::parseJsonStrValueIntoSet(json_spirit::mValue const& _json, set<string>& _out)
603-
{
604-
if (_json.type() == json_spirit::array_type)
605-
{
606-
for (auto const& val: _json.get_array())
607-
_out.emplace(val.get_str());
608-
}
609-
else
610-
_out.emplace(_json.get_str());
611-
}
612-
613-
void parseJsonIntValueIntoVector(json_spirit::mValue const& _json, vector<int>& _out)
614-
{
615-
if (_json.type() == json_spirit::array_type)
616-
{
617-
for (auto const& val: _json.get_array())
618-
_out.push_back(val.get_int());
619-
}
620-
else
621-
_out.push_back(_json.get_int());
622-
}
623-
624676
set<string> const& getAllowedNetworks()
625677
{
626678
static set<string> allowedNetowks;
@@ -698,9 +750,9 @@ bool ImportTest::checkGeneralTestSectionSearch(json_spirit::mObject const& _expe
698750
BOOST_REQUIRE_MESSAGE(_expects.at("indexes").type() == jsonVType::obj_type,
699751
"indexes field expected to be json Object!");
700752
json_spirit::mObject const& indexes = _expects.at("indexes").get_obj();
701-
parseJsonIntValueIntoVector(indexes.at("data"), d);
702-
parseJsonIntValueIntoVector(indexes.at("gas"), g);
703-
parseJsonIntValueIntoVector(indexes.at("value"), v);
753+
d = parseJsonIntValueIntoVector(indexes.at("data"));
754+
g = parseJsonIntValueIntoVector(indexes.at("gas"));
755+
v = parseJsonIntValueIntoVector(indexes.at("value"));
704756
BOOST_CHECK_MESSAGE(d.size() > 0 && g.size() > 0 && v.size() > 0, TestOutputHelper::get().testName() + " Indexes arrays not set!");
705757

706758
//Skip this check if does not fit to options request

test/tools/libtesteth/ImportTest.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ class ImportTest
6969
eth::State m_statePost;
7070

7171
private:
72-
using ExecOutput = std::pair<eth::ExecutionResult, eth::TransactionReceipt>;
72+
struct transactionToExecute;
73+
using ExecOutput = std::pair<eth::ExecutionResult, eth::TransactionReceipt>;
7374
std::tuple<eth::State, ExecOutput, eth::ChangeLog> executeTransaction(eth::Network const _sealEngineNetwork, eth::EnvInfo const& _env, eth::State const& _preState, eth::Transaction const& _tr);
75+
bool findExpectSectionForTransaction(
76+
transactionToExecute const& _tr, eth::Network const& _net, bool _isFilling) const;
7477

75-
std::unique_ptr<eth::LastBlockHashesFace const> m_lastBlockHashes;
78+
std::unique_ptr<eth::LastBlockHashesFace const> m_lastBlockHashes;
7679
std::unique_ptr<eth::EnvInfo> m_envInfo;
7780
eth::Transaction m_transaction;
7881

0 commit comments

Comments
 (0)