/// <summary> /// Initializes a new instance of the <see cref="PoolConfig"/> class. /// </summary> /// <param name="config">The configuration.</param> /// <param name="coinConfig"></param> public PoolConfig(dynamic config, ICoinConfig coinConfig) { try { Enabled = config.enabled ? config.enabled : false; if (Enabled == false) // if the configuration is not enabled return; // just skip reading rest of the parameters. Coin = coinConfig; Daemon = new DaemonConfig(config.daemon); Wallet = new WalletConfig(config.wallet); Rewards = new RewardsConfig(config.rewards); Payments = new PaymentConfig(config.payments); Miner = new MinerConfig(config.miner); Job = new JobConfig(config.job); Stratum = new StratumServerConfig(config.stratum); Banning = new BanConfig(config.banning); Storage = new RedisConfig(config.storage.redis); Vanilla = new VanillaServerConfig(config.vanilla); Valid = true; } catch (Exception e) { Valid = false; Log.Logger.ForContext<PoolConfig>().Error(e, "Error loading pool configuration"); } }
public void InvalidConfig_ShouldReturnDefaults() { // read a valid json config sample. var data = _jsonConfigReader.Read("invalid-config.json"); var config = new BanConfig(data); // as we have just supplied an invalid config, we should get a valid config object with default values config.Enabled.Should().Equal(false); config.Duration.Should().Equal(600); config.InvalidPercent.Should().Equal(50); config.CheckThreshold.Should().Equal(100); config.PurgeInterval.Should().Equal(300); config.Valid.Should().Equal(true); }
/// <summary> /// Initializes a new instance of the <see cref="PoolConfig"/> class. /// </summary> /// <param name="config">The configuration.</param> /// <param name="coinConfig"></param> public PoolConfig(dynamic config, ICoinConfig coinConfig) { try { _logger = Log.ForContext<PoolConfig>().ForContext("Component", coinConfig.Name); Enabled = config.enabled ? config.enabled : false; if (Enabled == false) // if the configuration is not enabled return; // just skip reading rest of the parameters. // load the sections. Coin = coinConfig; // assign the coin config. Daemon = new DaemonConfig(config.daemon); Meta = new MetaConfig(config.meta); Wallet = new WalletConfig(config.wallet); Rewards = new RewardsConfig(config.rewards); Payments = new PaymentConfig(config.payments); Miner = new MinerConfig(config.miner); Job = new JobConfig(config.job); Stratum = new StratumServerConfig(config.stratum); Banning = new BanConfig(config.banning); Storage = new StorageConfig(config.storage); Getwork = new GetworkServerConfig(config.getwork); // process extra checks if (Storage.Layer is MposStorageConfig) { if (Payments.Enabled) { Payments.Disable(); _logger.Information("Disabled payment processor as it can not be enabled when MPOS mode is on"); } } Valid = true; } catch (Exception e) { Valid = false; _logger.Error(e, "Error loading pool configuration"); } }
public void ValidConfig_ShouldSuccess() { // read a valid json config sample. var data = _jsonConfigReader.Read("Banning/valid-config.json"); var config = new BanConfig(data); // make sure our expected values are set. config.Enabled.Should().Equal(true); config.Duration.Should().Equal(1); config.InvalidPercent.Should().Equal(2); config.CheckThreshold.Should().Equal(3); config.PurgeInterval.Should().Equal(4); config.Valid.Should().Equal(true); }
public void InvalidJson_ShouldBeInvalid() { // read a valid json config sample. var data = _jsonConfigReader.Read("invalid-json.json"); var config = new BanConfig(data); // as we have just supplied an invalid json, config should be just marked as invalid. config.Valid.Should().Equal(false); }