-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for max_priority_fee when eth_maxPriorityFeePerGas is not a…
…vailable
- Loading branch information
Showing
5 changed files
with
157 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import pytest | ||
|
||
from eth_utils import ( | ||
is_integer, | ||
) | ||
|
||
from web3.middleware import ( | ||
construct_error_generator_middleware, | ||
construct_result_generator_middleware, | ||
) | ||
from web3.types import ( | ||
RPCEndpoint, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'fee_history_result,expected_max_prio_calc', | ||
( | ||
( | ||
{ | ||
'reward': [[10 ** 20], [10 ** 20], [10 ** 20], [10 ** 20]], | ||
}, | ||
15 * (10 ** 8), | ||
), | ||
( | ||
{ | ||
'reward': [[10 ** 2], [10 ** 2], [10 ** 2], [10 ** 2], [10 ** 2]], | ||
}, | ||
10 ** 9, | ||
), | ||
( | ||
{ | ||
'reward': [[0], [0], [0], [0], [0]], | ||
}, | ||
10 ** 9, | ||
), | ||
( | ||
{ | ||
'reward': [[1223344455], [1111111111], [1222777777], [0], [1000222111], [0], [0]], | ||
}, | ||
round(sum([1223344455, 1111111111, 1222777777, 1000222111]) / 4), | ||
), | ||
), | ||
ids=[ | ||
'test-max', 'test-min', 'test-min-all-zero-fees', 'test-non-zero-average' | ||
] | ||
) | ||
# Test fee_utils indirectly by mocking eth_feeHistory results and checking against expected output | ||
def test_fee_utils_indirectly( | ||
web3, fee_history_result, expected_max_prio_calc | ||
) -> None: | ||
fail_max_prio_middleware = construct_error_generator_middleware( | ||
{RPCEndpoint("eth_maxPriorityFeePerGas"): lambda *_: ''} | ||
) | ||
fee_history_result_middleware = construct_result_generator_middleware( | ||
{RPCEndpoint('eth_feeHistory'): lambda *_: fee_history_result} | ||
) | ||
|
||
web3.middleware_onion.add(fail_max_prio_middleware, 'fail_max_prio') | ||
web3.middleware_onion.inject(fee_history_result_middleware, 'fee_history_result', layer=0) | ||
|
||
with pytest.warns( | ||
UserWarning, | ||
match="There was an issue with the method eth_maxPriorityFeePerGas. Calculating using " | ||
"eth_feeHistory." | ||
): | ||
max_priority_fee = web3.eth.max_priority_fee | ||
assert is_integer(max_priority_fee) | ||
assert max_priority_fee == expected_max_prio_calc | ||
|
||
# clean up | ||
web3.middleware_onion.remove('fail_max_prio') | ||
web3.middleware_onion.remove('fee_history_result') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters