Skip to content

Commit

Permalink
move configs from test folder to .retesteth
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Nov 26, 2019
1 parent a1b142a commit 92f50d6
Show file tree
Hide file tree
Showing 21 changed files with 1,175 additions and 122 deletions.
15 changes: 0 additions & 15 deletions retesteth/ClientConfig.cpp

This file was deleted.

84 changes: 0 additions & 84 deletions retesteth/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,87 +384,3 @@ Options const& Options::get(int argc, const char** argv)
return instance;
}

ClientConfig const& Options::DynamicOptions::getCurrentConfig() const
{
for (auto const& cfg: m_clientConfigs)
{
if (cfg.getId() == m_currentConfigID)
return cfg;
}
ETH_FAIL_MESSAGE("ERROR: current config not found! (DynamicOptions::getCurrentConfig())");
return m_clientConfigs.at(0);
}

void Options::DynamicOptions::setCurrentConfig(ClientConfig const& _config)
{
ETH_FAIL_REQUIRE_MESSAGE(getClientConfigs().size() > 0, "No client configs provided!");
bool found = false;
for (auto const& cfg : getClientConfigs())
if (cfg.getId() == _config.getId() && cfg.getName() == _config.getName())
found = true;
ETH_FAIL_REQUIRE_MESSAGE(found, "_config not found in loaded options! (DynamicOptions::setCurrentConfig)");
m_currentConfigID = _config.getId();

// Verify singleTestNet for the current config
string const& net = Options::get().singleTestNet;
if (!net.empty())
test::checkAllowedNetwork(net, _config.getNetworks());
}

std::vector<ClientConfig> const& Options::DynamicOptions::getClientConfigs()
{
if (m_clientConfigs.size() == 0)
{
// load the configs from options file
std::vector<string> cfgs = Options::get().clients;
if (cfgs.empty())
cfgs.push_back("default");

std::cout << "Active client configurations: '";
for (auto const& clientName : cfgs)
std::cout << clientName << " ";
std::cout << "'" << std::endl;

for (auto const& clientName : cfgs)
{
ETH_FAIL_REQUIRE_MESSAGE(fs::exists(getTestPath()), "Could not locate provided testpath: " + string(getTestPath().c_str()));
fs::path configPath = getTestPath() / fs::path("Retesteth") / clientName;
fs::path configFilePath = configPath / "config";
ETH_FAIL_REQUIRE_MESSAGE(fs::exists(configFilePath),
string("Client config not found: ") + configFilePath.c_str());
string s = dev::contentsString(configFilePath);
ClientConfig cfg(dataobject::ConvertJsoncppStringToData(s), ClientConfigID(),
configPath / string(clientName + ".sh"));

// Load genesis templates
fs::path genesisTemplatePath = configPath / "genesis";
if (!fs::exists(genesisTemplatePath))
{
genesisTemplatePath = configPath.parent_path() / "default" / "genesis";
ETH_FAIL_REQUIRE_MESSAGE(fs::exists(genesisTemplatePath), "default/genesis client config not found!");
}

fs::path correctMiningRewardPath = genesisTemplatePath / "correctMiningReward.json";
ETH_FAIL_REQUIRE_MESSAGE(fs::exists(correctMiningRewardPath), "correctMiningReward.json client config not found!");
s = dev::contentsString(correctMiningRewardPath);
cfg.setMiningRewardInfo(dataobject::ConvertJsoncppStringToData(s));
cfg.setCorrectMiningRewardFilePath(correctMiningRewardPath);

auto registerGenesisTemplate = [&cfg, &genesisTemplatePath, &clientName](string const& _net) {
fs::path configGenesisTemplatePath = genesisTemplatePath / (_net + ".json");
ETH_FAIL_REQUIRE_MESSAGE(fs::exists(configGenesisTemplatePath),
"template .json config for network '" + _net + "' in " + clientName + " not found in tests/Retesteth configs!");
cfg.addGenesisTemplate(_net, configGenesisTemplatePath);
};
for (auto const& net : cfg.getNetworks())
registerGenesisTemplate(net);
for (auto const& net : cfg.getAdditionalNetworks())
registerGenesisTemplate(net);

//*/ Load genesis templates

m_clientConfigs.push_back(cfg);
}
}
return m_clientConfigs;
}
2 changes: 1 addition & 1 deletion retesteth/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma once

#include <libdevcore/Exceptions.h>
#include <retesteth/ClientConfig.h>
#include <retesteth/configs/ClientConfig.h>
#include <boost/filesystem.hpp>
#include <boost/optional.hpp>
#include <boost/program_options.hpp>
Expand Down
165 changes: 165 additions & 0 deletions retesteth/configs/ClientConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#include <retesteth/configs/ClientConfig.h>
#include <mutex>
std::mutex g_staticDeclaration_clientConfigID;
namespace test
{
ClientConfigID::ClientConfigID()
{
std::lock_guard<std::mutex> lock(g_staticDeclaration_clientConfigID);
static unsigned uniqueID = 0;
uniqueID++;
m_id = uniqueID;
}

} // namespace test

using namespace std;
string default_config = R"({
"name" : "Ethereum GO on TCP",
"socketType" : "tcp",
"socketAddress" : [
"127.0.0.1:8545",
"127.0.0.1:8546",
"127.0.0.1:8547",
"127.0.0.1:8548",
"127.0.0.1:8549",
"127.0.0.1:8550",
"127.0.0.1:8551",
"127.0.0.1:8552"
],
"forks" : [
"Frontier",
"Homestead",
"EIP150",
"EIP158",
"Byzantium",
"Constantinople",
"ConstantinopleFix",
"Istanbul"
],
"additionalForks" : [
"FrontierToHomesteadAt5",
"HomesteadToEIP150At5",
"EIP158ToByzantiumAt5",
"HomesteadToDaoAt5",
"ByzantiumToConstantinopleFixAt5"
]
})";

string besu_config = R"({
"name" : "Hyperledger Besu on TCP",
"socketType" : "tcp",
"socketAddress" : [
"127.0.0.1:47710"
],
"forks" : [
"Frontier",
"Homestead",
"EIP150",
"EIP158",
"Byzantium",
"Constantinople",
"ConstantinopleFix",
"Istanbul"
],
"additionalForks" : [
"FrontierToHomesteadAt5",
"HomesteadToEIP150At5",
"EIP158ToByzantiumAt5",
"HomesteadToDaoAt5",
"ByzantiumToConstantinopleFixAt5"
]
})";

string alethTCP_config = R"({
"name" : "Ethereum aleth on TCP",
"socketType" : "tcp",
"socketAddress" : [
"127.0.0.1:8545",
"127.0.0.1:8546"
],
"forks" : [
"Frontier",
"Homestead",
"EIP150",
"EIP158",
"Byzantium",
"Constantinople",
"ConstantinopleFix",
"Istanbul"
],
"additionalForks" : [
"FrontierToHomesteadAt5",
"HomesteadToEIP150At5",
"EIP158ToByzantiumAt5",
"HomesteadToDaoAt5",
"ByzantiumToConstantinopleFixAt5"
]
})";

string alethIPCDebug_config = R"({
"name" : "Ethereum aleth on IPC Debug",
"socketType" : "ipc-debug",
"socketAddress" : "/home/username/.ethereum/geth.ipc",
"forks" : [
"Frontier",
"Homestead",
"EIP150",
"EIP158",
"Byzantium",
"Constantinople",
"ConstantinopleFix",
"Istanbul"
],
"additionalForks" : [
"FrontierToHomesteadAt5",
"HomesteadToEIP150At5",
"EIP158ToByzantiumAt5",
"HomesteadToDaoAt5",
"ByzantiumToConstantinopleFixAt5"
]
})";


string aleth_config = R"({
"name" : "Ethereum cpp-client",
"socketType" : "ipc",
"socketAddress" : "local",
"forks" : [
"Frontier",
"Homestead",
"EIP150",
"EIP158",
"Byzantium",
"Constantinople",
"ConstantinopleFix",
"Istanbul"
],
"additionalForks" : [
"FrontierToHomesteadAt5",
"HomesteadToEIP150At5",
"EIP158ToByzantiumAt5",
"HomesteadToDaoAt5",
"ByzantiumToConstantinopleFixAt5"
]
})";

string aleth_config_sh = R"({
#!/bin/bash
onexit()
{
kill $child
}
trap onexit SIGTERM
trap onexit SIGABRT
##ARGUMENTS PASSED BY RETESTETH
##
## $1 <db-path> A path to database directory that a client should use
## $2 <ipcpath> A path to the ipc socket file (has /geth.ipc at the end)
#####
aleth --test --db-path $1 --ipcpath $2 --log-verbosity 5 &
child=$!
wait "$child"
)";
53 changes: 31 additions & 22 deletions retesteth/ClientConfig.h → retesteth/configs/ClientConfig.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <retesteth/Socket.h>
#include <retesteth/ethObjects/object.h>
#include <retesteth/dataObject/ConvertFile.h>
#include <retesteth/ethObjects/object.h>
#include <boost/asio.hpp>
#include <mutex>
#include <string>
Expand All @@ -20,19 +20,19 @@ bool validateIP(std::string const& _ip)
return false;
return true;
}
}
} // namespace

namespace test
{

struct ClientConfigID
{
/// ClientConfigID handles the unique id logic so not to store it inside int and accedentially change
/// or mistake with some other value. ???possibly a class for unique object ids???
/// ClientConfigID handles the unique id logic so not to store it inside int and accedentially
/// change or mistake with some other value. ???possibly a class for unique object ids???
ClientConfigID();
bool operator == (ClientConfigID const& _right) const { return m_id == _right.id(); }
bool operator != (ClientConfigID const& _right) const { return m_id != _right.id(); }
bool operator==(ClientConfigID const& _right) const { return m_id == _right.id(); }
bool operator!=(ClientConfigID const& _right) const { return m_id != _right.id(); }
unsigned id() const { return m_id; }

private:
unsigned m_id;
};
Expand All @@ -44,15 +44,18 @@ class ClientConfig : public object
: object(_obj), m_shellPath(_shell), m_id(_id)
{
requireJsonFields(_obj, "ClientConfig ",
{{"name", {DataType::String}}, {"socketType", {DataType::String}},
{
{"name", {DataType::String}},
{"socketType", {DataType::String}},
{"socketAddress", {DataType::String, DataType::Array}},
{"forks", {DataType::Array}},
{"additonalForks", {DataType::Array}},
}, true);
{"additionalForks", {DataType::Array}},
},
true);

for (auto const& name : m_data.atKey("forks").getSubObjects())
m_networks.push_back(name.asString());
for (auto const& name : m_data.atKey("additonalForks").getSubObjects())
for (auto const& name : m_data.atKey("additionalForks").getSubObjects())
m_additional_networks.push_back(name.asString());

std::string const& socketTypeStr = _obj.atKey("socketType").asString();
Expand Down Expand Up @@ -106,26 +109,32 @@ class ClientConfig : public object
ClientConfigID const& getId() const { return m_id; }
std::vector<string> const& getNetworks() const { return m_networks; }
std::vector<string> const& getAdditionalNetworks() const { return m_additional_networks; }
void addGenesisTemplate(string const& _network, fs::path const& _pathToJson) {
void addGenesisTemplate(string const& _network, fs::path const& _pathToJson)
{
string s = dev::contentsString(_pathToJson);
m_genesisTemplate[_network] = dataobject::ConvertJsoncppStringToData(s);
}
DataObject const& getGenesisTemplate(string const& _network) const {
ETH_FAIL_REQUIRE_MESSAGE(m_genesisTemplate.count(_network), "Genesis template for network '" + _network + "' not found!");
DataObject const& getGenesisTemplate(string const& _network) const
{
ETH_FAIL_REQUIRE_MESSAGE(m_genesisTemplate.count(_network),
"Genesis template for network '" + _network + "' not found!");
return m_genesisTemplate.at(_network);
}
void setMiningRewardInfo(DataObject const& _info) { m_correctReward = _info; }
void setCorrectMiningRewardFilePath(fs::path const& _path) { m_configCorrectMiningRewardFilePath = _path; }
void setCorrectMiningRewardFilePath(fs::path const& _path)
{
m_configCorrectMiningRewardFilePath = _path;
}
DataObject const& getMiningRewardInfo() const { return m_correctReward; }

private:
Socket::SocketType m_socketType; ///< Connection type
fs::path m_shellPath; ///< Script to start new instance of a client (for ipc)
fs::path m_configCorrectMiningRewardFilePath; ///< Config correctMiningReward file path
ClientConfigID m_id; ///< Internal id
std::vector<string> m_networks; ///< Allowed forks as network name
std::vector<string> m_additional_networks; ///< Allowed forks as network name
std::map<string, DataObject> m_genesisTemplate; ///< Template For test_setChainParams
DataObject m_correctReward; ///< Correct mining reward info for StateTests->BlockchainTests
fs::path m_configCorrectMiningRewardFilePath; ///< Config correctMiningReward file path
ClientConfigID m_id; ///< Internal id
std::vector<string> m_networks; ///< Allowed forks as network name
std::vector<string> m_additional_networks; ///< Allowed forks as network name
std::map<string, DataObject> m_genesisTemplate; ///< Template For test_setChainParams
DataObject m_correctReward; ///< Correct mining reward info for StateTests->BlockchainTests
};
}
} // namespace test
Loading

0 comments on commit 92f50d6

Please sign in to comment.