public NdmFaucet( INdmBlockchainBridge?blockchainBridge, IEthRequestRepository?requestRepository, Address?faucetAddress, UInt256 maxValue, UInt256 dailyRequestsTotalValueEth, bool enabled, ITimestamper?timestamper, IWallet?wallet, ILogManager?logManager) { _blockchainBridge = blockchainBridge ?? throw new ArgumentNullException(nameof(blockchainBridge)); _requestRepository = requestRepository ?? throw new ArgumentNullException(nameof(requestRepository)); _faucetAddress = faucetAddress; _maxValue = maxValue; _dailyRequestsTotalValueWei = dailyRequestsTotalValueEth * 1_000_000_000_000_000_000; _enabled = enabled; _timestamper = timestamper ?? throw new ArgumentNullException(nameof(timestamper)); _wallet = wallet ?? throw new ArgumentNullException(nameof(wallet)); _today = _timestamper.UtcNow; _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); if (!_enabled || _faucetAddress is null) { return; } if (_logger.IsInfo) { _logger.Info($"NDM Faucet was enabled for this host, account: {faucetAddress}, request max value: {maxValue} wei"); } _requestRepository.SumDailyRequestsTotalValueAsync(_today).ContinueWith(t => { if (t.IsFaulted && _logger.IsError) { _logger.Error($"Error during NDM faucet today's ({_today.Date:d}) total value initialization.", t.Exception); return; } _todayRequestsTotalValueWei = t.Result; _initialized = true; if (_logger.IsInfo) { _logger.Info($"Initialized NDM faucet today's ({_today.Date:d}) total value: {_todayRequestsTotalValueWei} wei"); } }); }
public void Setup() { _blockchainBridge = Substitute.For <IBlockchainBridge>(); _repository = Substitute.For <IEthRequestRepository>(); _repository.SumDailyRequestsTotalValueAsync(Arg.Any <DateTime>()).ReturnsForAnyArgs(UInt256.Zero); _faucetAddress = Address.FromNumber(1); _maxValue = 1.Ether(); _dailyRequestsTotalValueEth = 500; _enabled = true; _timestamper = new Timestamper(); _logManager = LimboLogs.Instance; _host = "127.0.0.1"; _address = Address.FromNumber(2); _value = 1.Ether(); _faucetAccount = Account.TotallyEmpty; _transactionHash = Keccak.Zero; _blockchainBridge.GetAccount(_faucetAddress).Returns(_faucetAccount); _blockchainBridge.SendTransaction(Arg.Any <Transaction>(), true).Returns(_transactionHash); }