Skip to content

Commit

Permalink
Merge pull request #114 from ethereum/develop
Browse files Browse the repository at this point in the history
v 0.1.0  Development
  • Loading branch information
winsvega authored Mar 9, 2021
2 parents ab0e685 + 931a191 commit aa5ff53
Show file tree
Hide file tree
Showing 98 changed files with 1,936 additions and 564 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ HunterGate(
LOCAL
)

project(retesteth VERSION 0.0.9)
set(VERSION_SUFFIX "berlin")
project(retesteth VERSION 0.1.0)
set(VERSION_SUFFIX "accesslist")

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ RUN apt-get install wget && wget https://github.com/ethereum/solidity/releases/d
# Geth
RUN git clone --depth 1 -b master https://github.com/ethereum/go-ethereum.git /geth
RUN cd /geth && apt-get install wget \
&& wget https://dl.google.com/go/go1.13.3.linux-amd64.tar.gz \
&& tar -xvf go1.13.3.linux-amd64.tar.gz \
&& wget https://dl.google.com/go/go1.15.7.linux-amd64.tar.gz \
&& tar -xvf go1.15.7.linux-amd64.tar.gz \
&& mv go /usr/local && ln -s /usr/local/go/bin/go /bin/go \
&& make all && cp /geth/build/bin/evm /bin/evm \
&& cp /geth/build/bin/geth /bin/geth \
Expand Down
2 changes: 1 addition & 1 deletion cmake/EthCompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
add_compile_options(-Wno-unknown-pragmas)

# Configuration-specific compiler settings.
set(CMAKE_CXX_FLAGS_DEBUG "-Og -pg -DETH_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DETH_DEBUG")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
Expand Down
28 changes: 27 additions & 1 deletion retesteth/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <dataObject/ConvertFile.h>
#include <retesteth/Options.h>
#include <retesteth/TestHelper.h>
#include <testStructures/Common.h>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>

Expand Down Expand Up @@ -65,6 +66,7 @@ void printHelp()
cout << setw(40) << "--singletest <TestName>" << setw(0)
<< "Run on a single test. `Testname` is filename without Filler.json\n";
cout << setw(40) << "--singletest <TestName>/<Subtest>" << setw(0) << "`Subtest` is a test name inside the file\n";
cout << setw(40) << "--singlenet <ForkName>" << setw(0) << "Run only specific fork configuration\n";

cout << "\nDebugging\n";
cout << setw(30) << "-d <index>" << setw(25) << "Set the transaction data array index when running GeneralStateTests\n";
Expand Down Expand Up @@ -331,7 +333,22 @@ Options::Options(int argc, const char** argv)
else if (arg == "-d")
{
throwIfNoArgumentFollows();
trDataIndex = atoi(argv[++i]);
string const& argValue = argv[++i];
DigitsType type = stringIntegerType(argValue);
switch (type)
{
case DigitsType::Decimal:
trDataIndex = atoi(argValue.c_str());
break;
case DigitsType::String:
trDataLabel = argValue;
break;
default:
{
ETH_STDERROR_MESSAGE("Wrong argument format: " + argValue);
exit(0);
}
}
}
else if (arg == "-g")
{
Expand Down Expand Up @@ -476,3 +493,12 @@ void displayTestSuites()
cout << "\n";
}

string Options::getGStateTransactionFilter() const
{
string filter;
filter += trDataIndex == -1 ? string() : " dInd: " + to_string(trDataIndex);
filter += trDataLabel.empty() ? string() : " dLbl: " + trDataLabel;
filter += trGasIndex == -1 ? string() : " gInd: " + to_string(trGasIndex);
filter += trValueIndex == -1 ? string() : " vInd: " + to_string(trValueIndex);
return filter;
}
2 changes: 2 additions & 0 deletions retesteth/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Options
std::string singleTestName; // A test name (usually a file.json test)
std::string singleSubTestName; // A test name inside a file.json (for blockchain tests)
std::string singleTestNet;
std::string trDataLabel; ///< GeneralState data
int trDataIndex; ///< GeneralState data
int trGasIndex; ///< GeneralState gas
int trValueIndex; ///< GeneralState value
Expand All @@ -82,6 +83,7 @@ class Options
/// The first time used, options are parsed with argc, argv
static Options const& get(int argc = 0, const char** argv = 0);
static DynamicOptions& getDynamicOptions() { return m_dynamicOptions; }
string getGStateTransactionFilter() const;

private:
Options(int argc = 0, const char** argv = 0);
Expand Down
78 changes: 76 additions & 2 deletions retesteth/TestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,47 @@ vector<string> levenshteinDistance(std::string const& _needle, std::vector<std::
return ret;
}

std::mutex g_strFindMutex;
DigitsType stringIntegerType(std::string const& _string, bool _wasPrefix)
{
if (_string[0] == '0' && _string[1] == 'x' && !_wasPrefix)
{
DigitsType substringType = stringIntegerType(_string, true);
if (substringType == DigitsType::Hex)
return DigitsType::HexPrefixed;

if (substringType == DigitsType::Decimal)
{
if (_string.size() % 2 == 0)
return DigitsType::HexPrefixed;
else
return DigitsType::UnEvenHexPrefixed;
}

if (substringType == DigitsType::UnEvenHex)
return DigitsType::UnEvenHexPrefixed;
}

bool isDecimalOnly = true;
std::lock_guard<std::mutex> lock(g_strFindMutex); // string.find is not thread safe + static
for (size_t i = _wasPrefix ? 2 : 0; i < _string.length(); i++)
{
if (!isxdigit(_string[i]))
return DigitsType::String;

if (isDecimalOnly && !isdigit(_string[i]))
isDecimalOnly = false;
}

if (isDecimalOnly)
return DigitsType::Decimal;

if (_string.size() % 2 == 0)
return DigitsType::Hex;

return DigitsType::UnEvenHex;
}

void parseJsonStrValueIntoSet(DataObject const& _json, set<string>& _out)
{
if (_json.type() == DataType::Array)
Expand All @@ -194,19 +235,52 @@ void parseJsonStrValueIntoSet(DataObject const& _json, set<string>& _out)

void parseJsonIntValueIntoSet(DataObject const& _json, set<int>& _out)
{
auto parseRange = [&_out](DataObject const& a) {
string const& s = a.asString();
size_t delimeter = s.find('-');
if (delimeter != string::npos)
{
string const firstPartString = s.substr(0, delimeter);
if (stringIntegerType(firstPartString) != DigitsType::Decimal)
ETH_ERROR_MESSAGE("parseJsonIntValueIntoSet require x to be decimal in `x-y` range! `" + firstPartString);

string const secondPartString = s.substr(delimeter + 1);
if (stringIntegerType(secondPartString) != DigitsType::Decimal)
ETH_ERROR_MESSAGE("parseJsonIntValueIntoSet require y to be decimal in `x-y` range! `" + secondPartString);

size_t const indexStart = atoi(firstPartString.c_str());
size_t const indexEnd = atoi(secondPartString.c_str());
for (size_t i = indexStart; i <= indexEnd; i++)
_out.emplace(i);
}
else
ETH_ERROR_MESSAGE("parseJsonIntValueIntoSet: Error parsing integer range string! format: \"x-y\", got: `" + s);
};

if (_json.type() == DataType::Array)
{
for (auto const& val: _json.getSubObjects())
{
ETH_ERROR_REQUIRE_MESSAGE(val.type() == DataType::Integer, "parseJsonIntValueIntoSet expected value type = int!");
_out.emplace(val.asInt());
if (val.type() == DataType::Integer)
_out.emplace(val.asInt());
else
{
ETH_ERROR_REQUIRE_MESSAGE(
val.type() == DataType::String, "parseJsonIntValueIntoSet expected value type = int, \"int-int\" range!");
parseRange(val);
}
}
}
else if (_json.type() == DataType::Integer)
{
ETH_ERROR_REQUIRE_MESSAGE(_json.type() == DataType::Integer, "parseJsonIntValueIntoSet expected json type = int!");
_out.emplace(_json.asInt());
}
else if (_json.type() == DataType::String)
{
// Try to parse range into values "x-y"
parseRange(_json);
}
}

string prepareVersionString()
Expand Down
14 changes: 13 additions & 1 deletion retesteth/TestHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <dataObject/DataObject.h>
#include <retesteth/EthChecks.h>
#include <retesteth/compiler/Compiler.h>
#include <retesteth/testStructures/basetypes/BYTES.h>

using namespace dataobject;
namespace fs = boost::filesystem;
Expand Down Expand Up @@ -94,6 +95,18 @@ bool inArray(std::list<T> const& _array, const T& _val)
/// Explode string into array of strings by `delim`
std::vector<std::string> explode(std::string const& s, char delim);

/// See what kind of a string is str
enum class DigitsType
{
Decimal,
Hex,
UnEvenHex,
HexPrefixed,
UnEvenHexPrefixed,
String
};
DigitsType stringIntegerType(std::string const& _string, bool _wasPrefix = false);

/// popen with pid at return
enum popenOutput
{
Expand All @@ -114,5 +127,4 @@ string fto_string(t _val)
{
return std::to_string(_val);
}

} // namespace test
6 changes: 5 additions & 1 deletion retesteth/TestOutputHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,5 +399,9 @@ std::string TestInfo::errorDebug() const
message += ", block: " + to_string(m_blockNumber);
else if (m_isStateTransactionInfo)
message += ", TrInfo: d: " + to_string(m_trD) + ", g: " + to_string(m_trG) + ", v: " + to_string(m_trV);
return message + ")" + cRed;

if (!m_sTransactionData.empty())
message += ", TrData: `" + m_sTransactionData + "`";

return message + ")" + cDefault;
}
9 changes: 5 additions & 4 deletions retesteth/TestOutputHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ struct TestInfo

TestInfo(): m_isStateTransactionInfo(false), m_isBlockchainTestInfo(false) {}
std::string errorDebug() const;
static std::string caseName()
{
return boost::unit_test::framework::current_test_case().p_name;
}
static std::string caseName() { return boost::unit_test::framework::current_test_case().p_name; }

void setTrDataDebug(std::string const& _data) { m_sTransactionData = _data; }

private:
std::string m_sFork, m_sChainName;
std::string m_currentTestCaseName;
std::string m_sTransactionData;

int m_trD, m_trG, m_trV;
size_t m_blockNumber;
bool m_isStateTransactionInfo = false;
Expand Down
49 changes: 45 additions & 4 deletions retesteth/TestSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,24 @@ void addClientInfo(DataObject& _v, fs::path const& _testSource, h256 const& _tes
{
string comment;
DataObject clientinfo;
clientinfo.setKey("_info");
if (o.count("_info"))
{
DataObject const& existingInfo = o.atKey("_info");
if (existingInfo.count("comment"))
comment = existingInfo.atKey("comment").asString();
if (existingInfo.count("labels"))
clientinfo["labels"] = existingInfo.atKey("labels");
}

clientinfo.setKey("_info");
clientinfo["comment"] = comment;
clientinfo["filling-rpc-server"] = session.web3_clientVersion();
clientinfo["filling-tool-version"] = test::prepareVersionString();
clientinfo["lllcversion"] = test::prepareLLLCVersionString();
clientinfo["source"] = _testSource.string();
clientinfo["sourceHash"] = toString(_testSourceHash);
if (clientinfo.count("labels"))
clientinfo.setKeyPos("labels", clientinfo.getSubObjects().size() - 1);

o["_info"].replace(clientinfo);
o.setKeyPos("_info", 0);
Expand Down Expand Up @@ -224,6 +228,8 @@ void TestSuite::runTestWithoutFiller(boost::filesystem::path const& _file) const
if (Options::get().filltests)
{
TestFileData testData = readTestFile(_file);
removeComments(testData.data);

string fileName = _file.stem().c_str();
if (fileName.find("Filler") == string::npos)
ETH_ERROR_MESSAGE("Trying to fill `" + string(_file.c_str()) + "`, but file does not have Filler suffix!");
Expand Down Expand Up @@ -261,9 +267,7 @@ string TestSuite::checkFillerExistance(string const& _testFolder) const
string const testNameFilter = opt.singleTestName.empty() ? string() : opt.singleTestName;
string filter = testNameFilter;
filter += opt.singleTestNet.empty() ? string() : " " + opt.singleTestNet;
filter += opt.trDataIndex == -1 ? string() : " dInd: " + to_string(opt.trDataIndex);
filter += opt.trGasIndex == -1 ? string() : " gInd: " + to_string(opt.trGasIndex);
filter += opt.trValueIndex == -1 ? string() : " vInd: " + to_string(opt.trValueIndex);
filter += opt.getGStateTransactionFilter();
ETH_LOG("Checking test filler hashes for " + boost::unit_test::framework::current_test_case().full_name(), 4);
if (!filter.empty())
ETH_LOG("Filter: '" + filter + "'", 0);
Expand All @@ -276,6 +280,32 @@ string TestSuite::checkFillerExistance(string const& _testFolder) const
vector<fs::path> compiledFiles = test::getFiles(testsPath.path(), {".json", ".yml"}, testNameFilter);
AbsoluteFillerPath fullPathToFillers = getFullPathFiller(_testFolder);

// Check unfilled tests
if (Options::get().checkhash)
{
vector<fs::path> fillerFiles = test::getFiles(fullPathToFillers.path(), {".json", ".yml"}, testNameFilter);
if (fillerFiles.size() > compiledFiles.size())
{
string message = "Tests are not generated: ";
for (auto const& filler : fillerFiles)
{
bool found = false;
for (auto const& filled : compiledFiles)
{
string const fillerName = filler.stem().string();
if (fillerName.substr(0, fillerName.size() - 6) == filled.stem().string())
{
found = true;
break;
}
}
if (!found)
message += "\n " + string(filler.c_str());
}
ETH_ERROR_MESSAGE(message + "\n");
}
}

bool checkFillerWhenFilterIsSetButNoTestsFilled = false;
if (compiledFiles.size() == 0)
{
Expand Down Expand Up @@ -370,6 +400,7 @@ void TestSuite::runAllTestsInFolder(string const& _testFolder) const
string filter;
try
{
TestOutputHelper::get().setCurrentTestInfo(TestInfo("checkFillerExistance", _testFolder));
filter = checkFillerExistance(_testFolder);
}
catch (std::exception const&)
Expand Down Expand Up @@ -544,6 +575,12 @@ void TestSuite::executeTest(string const& _testFolder, fs::path const& _testFile
// Add client info for all of the tests in output
addClientInfo(output, boostRelativeTestPath, testData.hash);
writeFile(boostTestPath.path(), asBytes(output.asJson()));

if (!Options::get().getGStateTransactionFilter().empty())
{
ETH_WARNING("GState transaction filter is set. Disabling generated test run!");
opt.disableSecondRun = true;
}
}
catch (test::EthError const& _ex)
{
Expand Down Expand Up @@ -606,6 +643,10 @@ 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();

if (_file.extension() != ".json")
ETH_ERROR_MESSAGE("The generated test must have `.json` format!");

doTests(test::readJsonData(_file), opt);
}
}
Loading

0 comments on commit aa5ff53

Please sign in to comment.