Skip to content

Commit

Permalink
WWIP
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Aug 20, 2021
1 parent c73fa86 commit a18af89
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 48 deletions.
2 changes: 1 addition & 1 deletion retesteth/dataObject/SPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GCP_SPointer
}
}
else
throw SPointerException("SPointer delete more times than counter increased!");
throwException("GCP_SPointer::release() SPointer delete more times than counter increased!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ using namespace test::teststruct;
spDataObject StateTestTransactionBase::asDataObject() const
{
// Serialize data back to JSON

return m_rawData;
/*
spDataObject _out(new DataObject());
DataObject& out = _out.getContent();
size_t index = 0;
Expand All @@ -29,6 +32,7 @@ spDataObject StateTestTransactionBase::asDataObject() const
if (atLeastOneNonNullAccessList)
out.atKeyPointer("accessLists") = txAccessListData;
// MOVE THIS CHECKS TO CONSTRUCTOR!!!
if (!m_maxFeePerGas.isEmpty() || !m_maxPriorityFeePerGas.isEmpty())
{
if (m_maxFeePerGas.isEmpty() || m_maxPriorityFeePerGas.isEmpty())
Expand Down Expand Up @@ -61,7 +65,7 @@ spDataObject StateTestTransactionBase::asDataObject() const
out["value"].addArrayObject(els);
}
return _out;
return _out;*/
}

/// Construct individual transactions from gstate test transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct StateTestTransactionBase : GCP_SPointerBase

protected:
StateTestTransactionBase(){};
spDataObject m_rawData;
std::vector<Databox> m_databox;
std::vector<VALUE> m_gasLimit;
std::vector<VALUE> m_value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct InfoIncomplete : GCP_SPointerBase
{
InfoIncomplete(spDataObjectMove);
string const& comment() const { return m_comment; }
spDataObject const& rawData() const { return m_rawData; }

private:
string m_comment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,62 @@ namespace test
{
namespace teststruct
{
StateTestFillerTransaction::StateTestFillerTransaction(DataObject const& _data)
StateTestFillerTransaction::StateTestFillerTransaction(spDataObjectMove _data)
{
try
{
spDataObject tmpD(new DataObject());
(*tmpD).copyFrom(_data);
(*tmpD).removeKey("data");
(*tmpD).performModifier(mod_valueToCompactEvenHexPrefixed);
m_rawData = _data.getPointer();

// Read data from JSON in test filler
// The VALUE fields can be decimal -> convert it to hex
// The data field can be LLL or other code -> compile it to BYTES
if (_data.atKey("to").asString().empty())
(*m_rawData).atKeyUnsafe("gasLimit").performModifier(mod_valueToCompactEvenHexPrefixed);
(*m_rawData).atKeyUnsafe("nonce").performModifier(mod_valueToCompactEvenHexPrefixed);
(*m_rawData).atKeyUnsafe("value").performModifier(mod_valueToCompactEvenHexPrefixed);
if (m_rawData->count("gasPrice"))
{
(*m_rawData).atKeyUnsafe("gasPrice").performModifier(mod_valueToCompactEvenHexPrefixed);
}
else if (m_rawData->count("maxFeePerGas"))
{
(*m_rawData).atKeyUnsafe("maxFeePerGas").performModifier(mod_valueToCompactEvenHexPrefixed);
(*m_rawData).atKeyUnsafe("maxPriorityFeePerGas").performModifier(mod_valueToCompactEvenHexPrefixed);
}
if (m_rawData->count("secretKey"))
(*m_rawData).atKeyUnsafe("secretKey").performModifier(mod_valueInsertZeroXPrefix);
(*m_rawData).performModifier(mod_valueToLowerCase);

if (m_rawData->atKey("to").asString().empty())
m_creation = true;
else
{
m_creation = false;
spDataObject dTo(new DataObject());
(*dTo).copyFrom(_data.atKey("to"));
string const& to = _data.atKey("to").asString();
if (to.size() > 1 && to[1] != 'x')
(*dTo) = "0x" + _data.atKey("to").asString();
m_to = spFH20(new FH20(dTo));
(*m_rawData).atKeyUnsafe("to").performModifier(mod_valueInsertZeroXPrefix);
m_to = spFH20(new FH20(m_rawData->atKey("to")));
}
m_secretKey = spFH32(new FH32(tmpD->atKey("secretKey")));
m_nonce = spVALUE(new VALUE(tmpD->atKey("nonce")));

for (auto const& el2 : _data.atKey("data").getSubObjects())
m_secretKey = spFH32(new FH32(m_rawData->atKey("secretKey")));
m_nonce = spVALUE(new VALUE(m_rawData->atKey("nonce")));

for (auto& el : (*m_rawData).atKeyUnsafe("data").getSubObjectsUnsafe())
{
DataObject const& el = el2.getCContent();
spDataObject dataInKey(new DataObject());
spDataObject dataInKey;
spAccessList accessList;
if (el.type() == DataType::Object)
if (el->type() == DataType::Object)
{
(*dataInKey).copyFrom(el.atKey("data"));
accessList = spAccessList(new AccessList(el.atKey("accessList")));
requireJsonFields(el, "StateTestFillerTransaction::dataWithList " + _data.getKey(),
requireJsonFields(el, "StateTestFillerTransaction::dataWithList " + m_rawData->getKey(),
{{"data", {{DataType::String}, jsonField::Required}},
{"accessList", {{DataType::Array}, jsonField::Required}}});

dataInKey = (*el).atKeyPointerUnsafe("data");
accessList = spAccessList(new AccessList(el->atKey("accessList")));
}
else
(*dataInKey).copyFrom(el);
dataInKey = el;

// -- Compile LLL in transaction data into byte code if not already
(*dataInKey).setKey("`data` array element in General Transaction Section"); // Hint
// (*dataInKey).setKey("`data` array element in General Transaction Section"); // Hint
// Detect :label prefix over code compilation

string label;
string rawData = dataInKey->asString();
Expand All @@ -75,17 +86,17 @@ StateTestFillerTransaction::StateTestFillerTransaction(DataObject const& _data)
// ---
m_databox.push_back(Databox(dataInKey.getContent(), label, rawData.substr(0, 20), accessList));
}
for (auto const& el : tmpD->atKey("gasLimit").getSubObjects())
for (auto const& el : m_rawData->atKey("gasLimit").getSubObjects())
m_gasLimit.push_back(el.getCContent());
for (auto const& el : tmpD->atKey("value").getSubObjects())
for (auto const& el : m_rawData->atKey("value").getSubObjects())
m_value.push_back(el.getCContent());

if (tmpD->count("maxFeePerGas") || tmpD->count("maxPriorityFeePerGas"))
if (m_rawData->count("maxFeePerGas") || m_rawData->count("maxPriorityFeePerGas"))
{
// EIP 1559 TRANSACTION TEMPLATE (gtest FILLER)
m_maxFeePerGas = spVALUE(new VALUE(tmpD->atKey("maxFeePerGas")));
m_maxPriorityFeePerGas = spVALUE(new VALUE(tmpD->atKey("maxPriorityFeePerGas")));
requireJsonFields(_data, "StateTestFillerTransaction " + _data.getKey(),
m_maxFeePerGas = spVALUE(new VALUE(m_rawData->atKey("maxFeePerGas")));
m_maxPriorityFeePerGas = spVALUE(new VALUE(m_rawData->atKey("maxPriorityFeePerGas")));
requireJsonFields(m_rawData, "StateTestFillerTransaction " + m_rawData->getKey(),
{{"data", {{DataType::Array}, jsonField::Required}},
{"gasLimit", {{DataType::Array}, jsonField::Required}},
{"nonce", {{DataType::String}, jsonField::Required}},
Expand All @@ -98,8 +109,8 @@ StateTestFillerTransaction::StateTestFillerTransaction(DataObject const& _data)
else
{
// LEGACY TRANSACTION TEMPLATE (gtest FILLER)
m_gasPrice = spVALUE(new VALUE(tmpD->atKey("gasPrice")));
requireJsonFields(_data, "StateTestFillerTransaction " + _data.getKey(),
m_gasPrice = spVALUE(new VALUE(m_rawData->atKey("gasPrice")));
requireJsonFields(m_rawData, "StateTestFillerTransaction " + m_rawData->getKey(),
{{"data", {{DataType::Array}, jsonField::Required}},
{"gasLimit", {{DataType::Array}, jsonField::Required}},
{"gasPrice", {{DataType::String}, jsonField::Required}},
Expand All @@ -108,10 +119,45 @@ StateTestFillerTransaction::StateTestFillerTransaction(DataObject const& _data)
{"to", {{DataType::String}, jsonField::Required}},
{"secretKey", {{DataType::String}, jsonField::Required}}});
}


// Prepare data for export (export format is different to import format in this case
size_t index = 0;
bool atLeastOneNonNullAccessList = false;
spDataObject exportDatas(new DataObject());
spDataObject txAccessListData(new DataObject(DataType::Array));
for (Databox const& el : m_databox)
{
spDataObject elb(new DataObject(el.m_data.asString()));
(*exportDatas).addArrayObject(elb);
if (el.m_accessList.isEmpty())
(*txAccessListData).addArrayObject(spDataObject(new DataObject(DataType::Null)));
else
{
(*txAccessListData).addArrayObject(el.m_accessList->asDataObject());
atLeastOneNonNullAccessList = true;
}
index++;
}

(*exportDatas).setKey("data");
(*m_rawData).atKeyPointer("data") = exportDatas;
if (atLeastOneNonNullAccessList)
(*m_rawData).atKeyPointer("accessLists") = txAccessListData;

if (!m_maxFeePerGas.isEmpty() || !m_maxPriorityFeePerGas.isEmpty())
{
if (m_maxFeePerGas.isEmpty() || m_maxPriorityFeePerGas.isEmpty())
ETH_FAIL_MESSAGE("Must be defined both m_maxFeePerGas and m_maxPriorityFeePerGas!");
if (!atLeastOneNonNullAccessList)
ETH_FAIL_MESSAGE("Basefee transaction must have accesslist!");
}


}
catch (std::exception const& _ex)
{
throw UpwardsException(string("StateTestFillerTransaction parse error: ") + _ex.what() + "\n" + _data.asJson());
throw UpwardsException(string("StateTestFillerTransaction parse error: ") + _ex.what() + "\n" + m_rawData->asJson());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace teststruct
// Constructor conver all fields to hex and compile src data code into bytes
struct StateTestFillerTransaction : StateTestTransactionBase
{
StateTestFillerTransaction(DataObject const&);
StateTestFillerTransaction(spDataObjectMove);
};

typedef GCP_SPointer<StateTestFillerTransaction> spStateTestFillerTransaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ StateTestInFiller::StateTestInFiller(spDataObject& _data)
if (_data->count("solidity"))
solidityCode = test::compiler::compileSolidity(_data->atKey("solidity").asString());

// "Pre" section
convertDecStateToHex((*_data).atKeyPointerUnsafe("pre"), solidityCode);
convertDecStateToHex((*_data).atKeyPointerUnsafe("pre"), solidityCode); // "Pre" section
m_pre = spState(new State(MOVE(_data, "pre")));
m_transaction = spStateTestFillerTransaction(new StateTestFillerTransaction(_data->atKey("transaction")));
m_transaction = spStateTestFillerTransaction(new StateTestFillerTransaction(MOVE(_data, "transaction")));

for (auto& el : (*_data).atKeyUnsafe("expect").getSubObjectsUnsafe())
m_expectSections.push_back(StateTestFillerExpectSection(dataobject::move(el), m_transaction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ struct StateTestInFiller : GCP_SPointerBase

string const& testName() const { return m_name; }
bool hasInfo() const { return !m_info.isEmpty(); }
InfoIncomplete const& Info() const
{
assert(hasInfo());
return m_info;
}
InfoIncomplete const& Info() const { return m_info; }
StateTestFillerEnv const& Env() const { return m_env; }
State const& Pre() const { return m_pre; }
StateTestFillerTransaction const& GeneralTr() const { return m_transaction; }
Expand Down
3 changes: 2 additions & 1 deletion retesteth/testStructures/types/VMTests/VMTestFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ VMTestInFiller::VMTestInFiller(spDataObject& _data)
m_pre = spState(new State(MOVE(_data, "pre")));
m_name = _data->getKey();

StateTestFillerTransaction stateTx(translateExecToTransaction(_data->atKey("exec")));
auto t = translateExecToTransaction(_data->atKey("exec"));
StateTestFillerTransaction stateTx(dataobject::move(t));
m_transaction = spTransaction(new TransactionLegacy(stateTx.buildTransactions().at(0).transaction()->asDataObject()));
if (_data->count("expect"))
{
Expand Down
3 changes: 1 addition & 2 deletions retesteth/testSuites/StateTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ spDataObject FillTest(StateTestInFiller const& _test)
SessionInterface& session = RPCSession::instance(TestOutputHelper::getThreadID());

if (_test.hasInfo())
(*filledTest)["_info"]["comment"] = _test.Info().comment();

(*filledTest).atKeyPointer("_info") = _test.Info().rawData();
(*filledTest).atKeyPointer("env") = _test.Env().asDataObject();

// Explicitly print default basefee for filled state tests
Expand Down
2 changes: 1 addition & 1 deletion retesteth/unitTests/expectSectionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ StateTestFillerExpectSection makeExpectSection(string const& _tr, string const&
{
spDataObject res = ConvertJsoncppStringToData(_tr);
spStateTestFillerTransaction spTransaction =
spStateTestFillerTransaction(new StateTestFillerTransaction(res));
spStateTestFillerTransaction(new StateTestFillerTransaction(dataobject::move(res)));
spDataObject res2 = ConvertJsoncppStringToData(_exp);
return StateTestFillerExpectSection(dataobject::move(res2), spTransaction);
}
Expand Down
3 changes: 2 additions & 1 deletion retesteth/unitTests/trDataCompileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ StateTestFillerTransaction makeTransaction(std::vector<string> const& _data)
str += ", ";
}
str += "]," + transactionCommon + "}";
return StateTestFillerTransaction(ConvertJsoncppStringToData(str));
auto p = ConvertJsoncppStringToData(str);
return StateTestFillerTransaction(dataobject::move(p));
}

BOOST_FIXTURE_TEST_SUITE(trDataCompileSuite, TestOutputHelperFixture)
Expand Down

0 comments on commit a18af89

Please sign in to comment.