Skip to content

Commit

Permalink
fix LegacyTests run on old sorted hash calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Aug 22, 2021
1 parent 225b07b commit b96307e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions retesteth/TestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ spDataObject readJsonData(fs::path const& _file, string const& _stopper, bool _a
}

/// Safely read the yaml file into DataObject
spDataObject readYamlData(fs::path const& _file)
spDataObject readYamlData(fs::path const& _file, bool _sort)
{
try
{
string s = dev::contentsString(_file);
ETH_ERROR_REQUIRE_MESSAGE(
s.length() > 0, "Contents of " + _file.string() + " is empty. Trying to parse empty file. (forgot --filltests?)");
return dataobject::ConvertYamlToData(YAML::Load(s));
return dataobject::ConvertYamlToData(YAML::Load(s), _sort);
}
catch (std::exception const& _ex)
{
Expand Down
2 changes: 1 addition & 1 deletion retesteth/TestHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Json::Value readJson(fs::path const& _path);
/// Safely read the json file into DataObject
spDataObject readJsonData(
fs::path const& _file, string const& _stopper = string(), bool _autosort = false);
spDataObject readYamlData(fs::path const& _file);
spDataObject readYamlData(fs::path const& _file, bool _sort = false);

/// Get files from directory
std::vector<boost::filesystem::path> getFiles(boost::filesystem::path const& _dirPath, std::set<std::string> _extentionMask, std::string const& _particularFile = {});
Expand Down
14 changes: 10 additions & 4 deletions retesteth/TestSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ struct TestFileData

TestFileData readTestFile(fs::path const& _testFileName)
{
// Binary file hash calculation is impossible as git messes up with the files
// So we read json structure and print it here to calculate the hash from string
// Adds around 1% to execution time
static bool isLegacy = (Options::get().rCurrentTestSuite.find("LegacyTests") != string::npos);
ETH_LOG("Read json structure " + string(_testFileName.filename().c_str()), 5);
TestFileData testData;
if (_testFileName.extension() == ".json")
testData.data = test::readJsonData(_testFileName, string(), false);
testData.data = test::readJsonData(_testFileName, string(), isLegacy);
else if (_testFileName.extension() == ".yml")
testData.data = test::readYamlData(_testFileName);
testData.data = test::readYamlData(_testFileName, isLegacy);
else
ETH_ERROR_MESSAGE(
"Unknown test format!" + test::TestOutputHelper::get().testFile().string());
Expand Down Expand Up @@ -704,8 +708,8 @@ void TestSuite::executeTest(string const& _testFolder, fs::path const& _testFile
void TestSuite::executeFile(boost::filesystem::path const& _file) const
{
TestSuiteOptions opt;
opt.isLegacyTests = Options::get().rCurrentTestSuite.find("LegacyTests") != string::npos;
opt.isLegacyTests = opt.isLegacyTests || legacyTestSuiteFlag();
static bool isLegacy = Options::get().rCurrentTestSuite.find("LegacyTests") != string::npos;
opt.isLegacyTests = isLegacy || legacyTestSuiteFlag();

if (_file.extension() != ".json")
ETH_ERROR_MESSAGE("The generated test must have `.json` format!");
Expand All @@ -715,4 +719,6 @@ void TestSuite::executeFile(boost::filesystem::path const& _file) const
ETH_LOG("Read json finish", 5);
doTests(res, opt);
}


}
2 changes: 1 addition & 1 deletion retesteth/configs/clientconfigs/t8ntool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ string const t8ntool_config = R"({
"TooMuchGasUsed2" : "Error importing raw rlp block: t8ntool didn't return a transaction with hash",
"InvalidNumber" : "BlockHeader number != parent.number + 1",
"InvalidTimestampEqualParent" : "timestamp equals parent's",
"InvalidTimestampOlderParent" : "BlockHeader timestamp is less then it's parent block!",
"InvalidTimestampOlderParent" : "BlockHeader timestamp is less or equal then it's parent block!",
"InvalidLogBloom" : "Error in field: bloom",
"InvalidStateRoot" : "Error in field: stateRoot",
"InvalidGasUsed" : "Error in field: gasUsed",
Expand Down
12 changes: 7 additions & 5 deletions retesteth/dataObject/ConvertYaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std::string yamlTypeAsString(YAML::NodeType::value _type)
return "";
}

spDataObject ConvertYamlToData(YAML::Node const& _node)
spDataObject ConvertYamlToData(YAML::Node const& _node, bool _sort)
{
if (_node.IsNull())
return spDataObject(new DataObject(DataType::Null));
Expand All @@ -41,18 +41,20 @@ spDataObject ConvertYamlToData(YAML::Node const& _node)
if (_node.IsMap())
{
spDataObject jObject(new DataObject(DataType::Object));
//(*jObject).setAutosort(true);
if (_sort)
(*jObject).setAutosort(true);
for (auto const& i : _node)
(*jObject).addSubObject(i.first.as<string>(), ConvertYamlToData(i.second));
(*jObject).addSubObject(i.first.as<string>(), ConvertYamlToData(i.second, _sort));
return jObject;
}

if (_node.IsSequence())
{
spDataObject jArray(new DataObject(DataType::Array));
//(*jArray).setAutosort(true);
if (_sort)
(*jArray).setAutosort(true);
for (size_t i = 0; i < _node.size(); i++)
(*jArray).addArrayObject(ConvertYamlToData(_node[i]));
(*jArray).addArrayObject(ConvertYamlToData(_node[i], _sort));
return jArray;
}

Expand Down
2 changes: 1 addition & 1 deletion retesteth/dataObject/ConvertYaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ namespace dataobject
std::string yamlTypeAsString(YAML::NodeType::value _type);

/// Convert Yaml object to DataObject
spDataObject ConvertYamlToData(YAML::Node const& _input);
spDataObject ConvertYamlToData(YAML::Node const& _input, bool _sort = false);
}

0 comments on commit b96307e

Please sign in to comment.