Esempio n. 1
0
    def gas_price(self):
        """ IncreasingGasPrice """
        GWEI = 1000000000

        return IncreasingGasPrice(initial_price=5*GWEI,
                                  increase_by=10*GWEI,
                                  every_secs=60,
                                  max_price=300*GWEI)
Esempio n. 2
0
    def get_gas_price(self, time_elapsed: int) -> Optional[int]:
        assert(isinstance(time_elapsed, int))

        config = self.reloadable_config.get_config()
        gas_price = config.get('gasPrice', None)
        gas_price_increase = config.get('gasPriceIncrease', None)
        gas_price_increase_every = config.get('gasPriceIncreaseEvery', None)
        gas_price_max = config.get('gasPriceMax', None)

        if gas_price is not None:
            if gas_price_increase and gas_price_increase_every:
                strategy = IncreasingGasPrice(gas_price, gas_price_increase, gas_price_increase_every, gas_price_max)
            else:
                strategy = FixedGasPrice(gas_price)
        else:
            strategy = DefaultGasPrice()

        return strategy.get_gas_price(time_elapsed=time_elapsed)
Esempio n. 3
0
 def get_gas_price(self, time_elapsed: int) -> Optional[int]:
     fast_price = self.gas_station.fast_price()
     if fast_price is not None:
         # start from fast_price + 10 GWei
         # increase by 10 GWei every 60 seconds
         # max is fast_price + 50 GWei
         return min(int(fast_price*1.1) + int(time_elapsed/60)*(10*self.GWEI), int(fast_price*1.1)+(50*self.GWEI))
     else:
         # default gas pricing when EthGasStation feed is down
         return IncreasingGasPrice(initial_price=50*self.GWEI,
                                   increase_by=10*self.GWEI,
                                   every_secs=60,
                                   max_price=100*self.GWEI).get_gas_price(time_elapsed)
Esempio n. 4
0
 def create_gas_price(arguments) -> GasPrice:
     if arguments.smart_gas_price:
         return SmartGasPrice()
     elif arguments.gas_price_file:
         return GasPriceFile(arguments.gas_price_file)
     elif arguments.gas_price:
         if arguments.gas_price_increase is not None:
             return IncreasingGasPrice(initial_price=arguments.gas_price,
                                       increase_by=arguments.gas_price_increase,
                                       every_secs=arguments.gas_price_increase_every,
                                       max_price=arguments.gas_price_max)
         else:
             return FixedGasPrice(arguments.gas_price)
     else:
         return DefaultGasPrice()
Esempio n. 5
0
    def test_gas_price_should_obey_max_value(self):
        # given
        increasing_gas_price = IncreasingGasPrice(1000, 100, 60, 2500)

        # expect
        assert increasing_gas_price.get_gas_price(0) == 1000
        assert increasing_gas_price.get_gas_price(1) == 1000
        assert increasing_gas_price.get_gas_price(59) == 1000
        assert increasing_gas_price.get_gas_price(60) == 1100
        assert increasing_gas_price.get_gas_price(119) == 1100
        assert increasing_gas_price.get_gas_price(120) == 1200
        assert increasing_gas_price.get_gas_price(1200) == 2500
        assert increasing_gas_price.get_gas_price(3000) == 2500
        assert increasing_gas_price.get_gas_price(1000000) == 2500
Esempio n. 6
0
    def test_gas_price_should_increase_with_time(self):
        # given
        increasing_gas_price = IncreasingGasPrice(1000, 100, 60, None)

        # expect
        assert increasing_gas_price.get_gas_price(0) == 1000
        assert increasing_gas_price.get_gas_price(1) == 1000
        assert increasing_gas_price.get_gas_price(59) == 1000
        assert increasing_gas_price.get_gas_price(60) == 1100
        assert increasing_gas_price.get_gas_price(119) == 1100
        assert increasing_gas_price.get_gas_price(120) == 1200
        assert increasing_gas_price.get_gas_price(1200) == 3000
Esempio n. 7
0
    def test_should_require_positive_max_price_if_provided(self):
        with pytest.raises(Exception):
            IncreasingGasPrice(1000, 1000, 60, 0)

        with pytest.raises(Exception):
            IncreasingGasPrice(1000, 1000, 60, -1)
Esempio n. 8
0
    def test_should_require_positive_every_secs_value(self):
        with pytest.raises(Exception):
            IncreasingGasPrice(1000, 100, 0, None)

        with pytest.raises(Exception):
            IncreasingGasPrice(1000, 100, -1, None)
Esempio n. 9
0
    def test_should_require_positive_increase_by_value(self):
        with pytest.raises(Exception):
            IncreasingGasPrice(1000, 0, 60, None)

        with pytest.raises(Exception):
            IncreasingGasPrice(1000, -1, 60, None)
Esempio n. 10
0
    def test_should_require_positive_initial_price(self):
        with pytest.raises(Exception):
            IncreasingGasPrice(0, 1000, 60, None)

        with pytest.raises(Exception):
            IncreasingGasPrice(-1, 1000, 60, None)
Esempio n. 11
0
 def default_gas_pricing(self, time_elapsed: int):
     return IncreasingGasPrice(initial_price=5 * self.GWEI,
                               increase_by=10 * self.GWEI,
                               every_secs=60,
                               max_price=100 *
                               self.GWEI).get_gas_price(time_elapsed)