예제 #1
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
예제 #2
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
예제 #3
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)