Skip to content

Commit

Permalink
merge balance of collided accounts in pre state of a test with config…
Browse files Browse the repository at this point in the history
… pre
  • Loading branch information
winsvega committed Nov 11, 2019
1 parent d45d50b commit 85d45a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions retesteth/dataObject/DataObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ DataObject const& DataObject::atKey(std::string const& _key) const
return m_subObjects.at(0);
}

DataObject& DataObject::atKeyUnsafe(std::string const& _key)
{
_assert(count(_key), "count(_key) _key=" + _key + " (DataObject::at)");
for (auto& i : m_subObjects)
if (i.getKey() == _key)
return i;
_assert(false, "item not found! (DataObject::at)");
return m_subObjects.at(0);
}

DataObject const& DataObject::at(size_t _pos) const
{
_assert((size_t)_pos < m_subObjects.size(), "DataObject::at(int) out of range!");
Expand Down
1 change: 1 addition & 0 deletions retesteth/dataObject/DataObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class DataObject
void replace(DataObject const& _value);

DataObject const& atKey(std::string const& _key) const;
DataObject& atKeyUnsafe(std::string const& _key);
DataObject const& at(size_t _pos) const;

void addArrayObject(DataObject const& _obj);
Expand Down
11 changes: 10 additions & 1 deletion retesteth/ethObjects/stateTest/scheme_stateTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ DataObject scheme_stateTestBase::getGenesisForRPC(
DataObject genesis = prepareGenesisParams(_network, _sealEngine);
genesis["genesis"] = getEnv().getDataForRPC();
for (auto const& acc : getPre().getData().getSubObjects())
genesis["accounts"].addSubObject(acc);
{
if (genesis["accounts"].count(acc.getKey()))
{
ETH_LOG("Test `pre` section interfere with genesis config pre state!", 2);
// Replace the balance field
genesis["accounts"].atKeyUnsafe(acc.getKey())["balance"] = acc.atKey("balance").asString();
}
else
genesis["accounts"].addSubObject(acc);
}
return genesis;
}

Expand Down

0 comments on commit 85d45a9

Please sign in to comment.