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(
        providers=[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.generateGasPrice()
    assert int(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(
            providers=[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.generateGasPrice()
    assert str(excinfo.value) == expected_exception_message
Example #3
0
def w3_base():
    return Web3(providers=[BaseProvider()], middlewares=[])
Example #4
0
def w3():
    w3 = Web3(providers=[BaseProvider()], middlewares=[])
    w3.ens = TempENS({NAME: ADDRESS})
    w3.middleware_stack.add(name_to_address_middleware(w3))
    return w3