示例#1
0
        public async Task update_async_should_set_types_if_client_returns_result()
        {
            var result = new GasPriceService.Result
            {
                SafeLow     = 1,
                SafeLowWait = 1000,
                Average     = 10,
                AvgWait     = 100,
                Fast        = 100,
                FastWait    = 10,
                Fastest     = 1000,
                FastestWait = 1
            };

            _client.GetAsync <GasPriceService.Result>(Arg.Any <string>()).Returns(result);
            await _gasPriceService.UpdateAsync();

            _gasPriceService.Types.SafeLow.Should()
            .Be(new GasPriceDetails(((int)result.SafeLow).GWei(), result.SafeLowWait));
            _gasPriceService.Types.Average.Should()
            .Be(new GasPriceDetails(((int)result.Average).GWei(), result.AvgWait));
            _gasPriceService.Types.Fast.Should()
            .Be(new GasPriceDetails(((int)result.Fast).GWei(), result.FastWait));
            _gasPriceService.Types.Fastest.Should()
            .Be(new GasPriceDetails(((int)result.Fastest).GWei(), result.FastestWait));
            _gasPriceService.Types.Custom.Should()
            .Be(new GasPriceDetails(_config.GasPrice, 0));
            _gasPriceService.Types.Type.Should().Be(_config.GasPriceType);
            _gasPriceService.Types.UpdatedAt.Should().Be(_timestamper.EpochSeconds);
            await _configManager.Received().GetAsync(ConfigId);

            await _client.Received().GetAsync <GasPriceService.Result>(Arg.Any <string>());
        }
示例#2
0
        public async Task update_async_should_set_types_if_client_returns_result()
        {
            var result = new GasPriceService.Result
            {
                SafeLow     = 10,
                SafeLowWait = 1000,
                Average     = 100,
                AvgWait     = 100,
                Fast        = 1000,
                FastWait    = 10,
                Fastest     = 10000,
                FastestWait = 1
            };

            _client.GetAsync <GasPriceService.Result>(Arg.Any <string>()).Returns(result);
            await _gasPriceService.UpdateGasPriceAsync();

            _gasPriceService.Types.SafeLow.Should()
            .Be(new GasPriceDetails(GetGasPriceGwei(result.SafeLow), result.SafeLowWait));
            _gasPriceService.Types.Average.Should()
            .Be(new GasPriceDetails(GetGasPriceGwei(result.Average), result.AvgWait));
            _gasPriceService.Types.Fast.Should()
            .Be(new GasPriceDetails(GetGasPriceGwei(result.Fast), result.FastWait));
            _gasPriceService.Types.Fastest.Should()
            .Be(new GasPriceDetails(GetGasPriceGwei(result.Fastest), result.FastestWait));
            _gasPriceService.Types.Custom.Should()
            .Be(new GasPriceDetails(_config.GasPrice, 0));
            _gasPriceService.Types.Type.Should().Be(_config.GasPriceType);
            _gasPriceService.Types.UpdatedAt.Should().Be(_timestamper.UnixTime.Seconds);
            await _configManager.Received().GetAsync(ConfigId);

            await _client.Received().GetAsync <GasPriceService.Result>(Arg.Any <string>());

            UInt256 GetGasPriceGwei(decimal gasPrice) => ((int)Math.Ceiling(gasPrice / 10)).GWei();
        }
示例#3
0
        public async Task set_should_parse_gas_price_type_and_update_config(string type)
        {
            var result = new GasPriceService.Result
            {
                SafeLow     = 1,
                SafeLowWait = 1000,
                Average     = 10,
                AvgWait     = 100,
                Fast        = 100,
                FastWait    = 10,
                Fastest     = 1000,
                FastestWait = 1
            };

            _client.GetAsync <GasPriceService.Result>(Arg.Any <string>()).Returns(result);
            await _gasPriceService.UpdateAsync();

            await _gasPriceService.SetAsync(type);

            _config.GasPriceType = type;
            switch (type)
            {
            case "safelow":
                _config.GasPrice = _gasPriceService.Types.SafeLow.Price;
                break;

            case "average":
                _config.GasPrice = _gasPriceService.Types.Average.Price;
                break;

            case "fast":
                _config.GasPrice = _gasPriceService.Types.Fast.Price;
                break;

            case "fastest":
                _config.GasPrice = _gasPriceService.Types.Fastest.Price;
                break;
            }

            await _configManager.Received().GetAsync(ConfigId);

            await _configManager.Received().UpdateAsync(_config);
        }