Skip to content

Commit

Permalink
difficulty test run
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Oct 23, 2021
1 parent 3d82e09 commit 28fd847
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 deletions.
40 changes: 33 additions & 7 deletions retesteth/testStructures/types/DifficultyTests/DifficultyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DifficultyTest::DifficultyTest(spDataObject& _data)
TestOutputHelper::get().get().testFile().string() + " A test file must contain at least one test!");
for (auto& el : _data.getContent().getSubObjectsUnsafe())
{
TestOutputHelper::get().setCurrentTestInfo(TestInfo("TransactionTestFiller", el->getKey()));
TestOutputHelper::get().setCurrentTestInfo(TestInfo("DifficultyTestFiller", el->getKey()));
m_tests.push_back(DifficultyTestInFilled(el));
}
}
Expand All @@ -33,17 +33,43 @@ DifficultyTestInFilled::DifficultyTestInFilled(spDataObject& _data)
{
try
{
REQUIRE_JSONFIELDS(_data, "DifficultyTestInFilled " + _data->getKey(),
{{"_info", {{DataType::Object}, jsonField::Required}},
{"result", {{DataType::Object}, jsonField::Required}},
{"txbytes", {{DataType::String}, jsonField::Required}}});

m_name = _data->getKey();
auto const& subObjects = _data->getSubObjects();
if (subObjects.size() < 2)
throw test::UpwardsException("test missing subobjects (_info + tests)!");

if (subObjects.at(0)->getKey() != "_info")
throw test::UpwardsException(_data->getKey() + " missing `_info` section as first subobject!");

m_name = _data->getKey();
for (size_t i = 1; i < subObjects.size(); i++)
m_testVectors.push_back(DifficultyTestVector(subObjects.at(i)));
}
catch (std::exception const& _ex)
{
ETH_ERROR_MESSAGE(string("DifficultyTestFilled convertion error: ") + _ex.what());
}
}

DifficultyTestVector::DifficultyTestVector(spDataObject const& _data)
{
REQUIRE_JSONFIELDS(_data, "DifficultyTestVector " + _data->getKey(),
{
{"currentBlockNumber", {{DataType::String}, jsonField::Required}},
{"currentDifficulty", {{DataType::String}, jsonField::Required}},
{"currentTimestamp", {{DataType::String}, jsonField::Required}},
{"network", {{DataType::String}, jsonField::Required}},
{"parentDifficulty", {{DataType::String}, jsonField::Required}},
{"parentTimestamp", {{DataType::String}, jsonField::Required}},
{"parentUncles", {{DataType::String}, jsonField::Required}},
});

currentBlockNumber = spVALUE(new VALUE(_data->atKey("currentBlockNumber")));
currentDifficulty = spVALUE(new VALUE(_data->atKey("currentDifficulty")));
currentTimestamp = spVALUE(new VALUE(_data->atKey("currentTimestamp")));
network = spFORK(new FORK(_data->atKey("network")));
parentDifficulty = spVALUE(new VALUE(_data->atKey("parentDifficulty")));
parentTimestamp = spVALUE(new VALUE(_data->atKey("parentTimestamp")));
parentUncles = VALUE(_data->atKey("parentUncles")) == 1;

testName = _data->getKey();
}
16 changes: 16 additions & 0 deletions retesteth/testStructures/types/DifficultyTests/DifficultyTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,37 @@
#include "../StateTests/Filler/InfoIncomplete.h"
#include <retesteth/dataObject/DataObject.h>
#include <retesteth/dataObject/SPointer.h>
#include <retesteth/testStructures/basetypes.h>
#include <retesteth/testStructures/configs/FORK.h>
#include <map>

namespace test
{
namespace teststruct
{
struct DifficultyTestVector
{
DifficultyTestVector(spDataObject const&);
spVALUE currentBlockNumber;
spVALUE currentDifficulty;
spVALUE currentTimestamp;
spFORK network;
spVALUE parentDifficulty;
spVALUE parentTimestamp;
bool parentUncles;
string testName;
};

struct DifficultyTestInFilled : GCP_SPointerBase
{
DifficultyTestInFilled(spDataObject&);
string const& testName() const { return m_name; }
std::vector<DifficultyTestVector> const& testVectors() const { return m_testVectors; }

private:
DifficultyTestInFilled() {}
string m_name;
std::vector<DifficultyTestVector> m_testVectors;
};

struct DifficultyTest
Expand Down
13 changes: 9 additions & 4 deletions retesteth/testSuites/DifficultyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ spDataObject FillTest(DifficultyTestInFiller const& _test)
void RunTest(DifficultyTestInFilled const& _test)
{
TestOutputHelper::get().setCurrentTestName(_test.testName());
//SessionInterface& session = RPCSession::instance(TestOutputHelper::getThreadID());
//for (auto const& el : Options::getCurrentConfig().cfgFile().forks())
//{
SessionInterface& session = RPCSession::instance(TestOutputHelper::getThreadID());

//}
for (auto const& v : _test.testVectors())
{
VALUE const res = session.test_calculateDifficulty(
v.network, v.currentBlockNumber, v.parentTimestamp, v.parentDifficulty, v.currentTimestamp, v.parentUncles);
ETH_ERROR_REQUIRE_MESSAGE(res == v.currentDifficulty, _test.testName() + "/" + v.testName +
" difficulty mismatch got: `" + res.asDecString() +
", test want: `" + v.currentDifficulty->asDecString());
}
}

} // namespace
Expand Down

0 comments on commit 28fd847

Please sign in to comment.