Beispiel #1
0
        protected override (CommandLineApplication, Func <IConfigProvider>, Func <string>) BuildCommandLineApp()
        {
            var app = new CommandLineApplication {
                Name = "Nethermind.Runner"
            };

            app.HelpOption("-?|-h|--help");
            var configFile = app.Option("-c|--config <configFile>", "config file path", CommandOptionType.SingleValue);
            var dbBasePath = app.Option("-d|--baseDbPath <baseDbPath>", "base db path", CommandOptionType.SingleValue);

            IConfigProvider BuildConfigProvider()
            {
                // ReSharper disable once NotAccessedVariable
                var config = typeof(KeystoreConfig).Assembly;

                config = typeof(NetworkConfig).Assembly;
                config = typeof(JsonRpcConfig).Assembly;
                config = typeof(InitConfig).Assembly;
                config = typeof(DbConfig).Assembly;
                config = typeof(StatsConfig).Assembly;
                config = typeof(BlockchainConfig).Assembly;

                var configProvider = new JsonConfigProvider();

                string configFilePath     = configFile.HasValue() ? configFile.Value() : _defaultConfigFile;
                var    configPathVariable = Environment.GetEnvironmentVariable("NETHERMIND_CONFIG");

                if (!string.IsNullOrWhiteSpace(configPathVariable))
                {
                    configFilePath = configPathVariable;
                }

                if (!Path.HasExtension(configFilePath) && !configFilePath.Contains(Path.DirectorySeparatorChar))
                {
                    string redirectedConfigPath = Path.Combine("configs", string.Concat(configFilePath, ".cfg"));
                    Console.WriteLine($"Redirecting config {configFilePath} to {redirectedConfigPath}");
                    configFilePath = redirectedConfigPath;
                }

                Console.WriteLine($"Reading config file from {configFilePath}");
                configProvider.LoadJsonConfig(configFilePath);
                return(configProvider);
            }

            string GetBaseDbPath()
            {
                return(dbBasePath.HasValue() ? dbBasePath.Value() : null);
            }

            return(app, BuildConfigProvider, GetBaseDbPath);
        }
        public void TestLoadJsonConfig()
        {
            _configProvider.LoadJsonConfig("SampleJsonConfig.json");

            var keystoreConfig = _configProvider.GetConfig <IKeystoreConfig>();
            var networkConfig  = _configProvider.GetConfig <INetworkConfig>();
            var jsonRpcConfig  = _configProvider.GetConfig <IJsonRpcConfig>();
            var statsConfig    = _configProvider.GetConfig <IStatsConfig>();

            Assert.AreEqual(100, keystoreConfig.KdfparamsDklen);
            Assert.AreEqual("test", keystoreConfig.Cipher);

            Assert.AreEqual("test", jsonRpcConfig.JsonRpcVersion);
            Assert.AreEqual("UTF7", jsonRpcConfig.MessageEncoding);
            Assert.AreEqual(2, jsonRpcConfig.EnabledModules.Count());
            new[] { ModuleType.Eth, ModuleType.Shh }.ToList().ForEach(x =>
            {
                Assert.IsTrue(jsonRpcConfig.EnabledModules.Contains(x));
            });

            Assert.AreEqual(4, networkConfig.Concurrency);
            Assert.AreEqual(3, statsConfig.PenalizedReputationLocalDisconnectReasons.Length);
            new[] { DisconnectReason.UnexpectedIdentity, DisconnectReason.IncompatibleP2PVersion, DisconnectReason.BreachOfProtocol }
            .ToList().ForEach(x =>
            {
                Assert.IsTrue(statsConfig.PenalizedReputationLocalDisconnectReasons.Contains(x));
            });
            Assert.AreEqual(2, networkConfig.BootNodes.Length);

            var node1 = networkConfig.BootNodes.FirstOrDefault(x => x.NodeId == "testNodeId");

            Assert.IsNotNull(node1);
            Assert.AreEqual("testHist", node1.Host);
            Assert.AreEqual(43, node1.Port);

            var node2 = networkConfig.BootNodes.FirstOrDefault(x => x.NodeId == "testNodeId2");

            Assert.IsNotNull(node2);
            Assert.AreEqual("testHist2", node2.Host);
            Assert.AreEqual(44, node2.Port);
        }
Beispiel #3
0
        protected override (CommandLineApplication, Func <IConfigProvider>, Func <string>) BuildCommandLineApp()
        {
            var app = new CommandLineApplication {
                Name = "Nethermind.Runner"
            };

            app.HelpOption("-?|-h|--help");
            var configFile = app.Option("-c|--config <configFile>", "config file path", CommandOptionType.SingleValue);
            var dbBasePath = app.Option("-d|--baseDbPath <baseDbPath>", "base db path", CommandOptionType.SingleValue);

            IConfigProvider BuildConfigProvider()
            {
                //TODO find better way to enforce assemblies with config impl are loaded
                // ReSharper disable once NotAccessedVariable
                var config = typeof(KeystoreConfig).Assembly;

                config = typeof(NetworkConfig).Assembly;
                config = typeof(JsonRpcConfig).Assembly;
                config = typeof(InitConfig).Assembly;
                config = typeof(DbConfig).Assembly;
                config = typeof(StatsConfig).Assembly;
                config = typeof(BlockchainConfig).Assembly;

                var configProvider = new JsonConfigProvider();

                configProvider.LoadJsonConfig(configFile.HasValue() ? configFile.Value() : DefaultConfigFile);
                return(configProvider);
            };

            string GetBaseDbPath()
            {
                return(dbBasePath.HasValue() ? dbBasePath.Value() : null);
            }

            return(app, BuildConfigProvider, GetBaseDbPath);
        }