def test_time_based_gas_price_strategy(strategy_params, expected): fixture_middleware = construct_result_generator_middleware({ 'eth_getBlockByHash': _get_block_by_something, 'eth_getBlockByNumber': _get_block_by_something, }) w3 = Web3( provider=BaseProvider(), middlewares=[fixture_middleware], ) time_based_gas_price_strategy = construct_time_based_gas_price_strategy( **strategy_params, ) w3.eth.setGasPriceStrategy(time_based_gas_price_strategy) actual = w3.eth.generate_gas_price() assert actual == expected
def test_time_based_gas_price_strategy_zero_sample(strategy_params_zero, expected_exception_message): with pytest.raises(ValidationError) as excinfo: fixture_middleware = construct_result_generator_middleware({ 'eth_getBlockByHash': _get_block_by_something, 'eth_getBlockByNumber': _get_block_by_something, }) w3 = Web3( provider=BaseProvider(), middlewares=[fixture_middleware], ) time_based_gas_price_strategy_zero = construct_time_based_gas_price_strategy( **strategy_params_zero, ) w3.eth.setGasPriceStrategy(time_based_gas_price_strategy_zero) w3.eth.generate_gas_price() assert str(excinfo.value) == expected_exception_message
def w3_base(): return Web3(providers=[BaseProvider()], middlewares=[])
def w3(): w3 = Web3(provider=BaseProvider(), middlewares=[]) w3.ens = TempENS({NAME: ADDRESS}) w3.middleware_onion.add(name_to_address_middleware(w3)) return w3