From fceb6ac0a576bab047f5ee8b20a9a9d45f5cba89 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 23 Mar 2023 18:32:10 +0800 Subject: [PATCH] cross check next fee --- tests/integration_tests/test_fee_history.py | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/integration_tests/test_fee_history.py b/tests/integration_tests/test_fee_history.py index fede5ccacc..afdd049061 100644 --- a/tests/integration_tests/test_fee_history.py +++ b/tests/integration_tests/test_fee_history.py @@ -90,3 +90,36 @@ def test_change(cluster): assert history1 != history0 else: assert history1 == history0 + + +def adjust_base_fee(parent_fee, gas_limit, gas_used): + "spec: https://eips.ethereum.org/EIPS/eip-1559#specification" + change_denominator = 8 + elasticity_multiplier = 2 + gas_target = gas_limit // elasticity_multiplier + delta = parent_fee * (gas_target - gas_used) // gas_target // change_denominator + return parent_fee - delta + + +def test_next(cluster): + w3: Web3 = cluster.w3 + call = w3.provider.make_request + tx = {"to": ADDRS["community"], "value": 10, "gasPrice": w3.eth.gas_price} + send_transaction(w3, tx) + method = "eth_feeHistory" + field = "baseFeePerGas" + percentiles = [100] + blocks = [] + for _ in range(3): + b = w3.eth.block_number + blocks.append(b) + history = call(method, [1, hex(b), percentiles])["result"][field] + print(b, history) + w3_wait_for_new_blocks(w3, 1, 0.1) + blocks.append(w3.eth.block_number) + for b in blocks: + next_base_price = w3.eth.get_block(b).baseFeePerGas + blk = w3.eth.get_block(b - 1) + assert next_base_price == adjust_base_fee( + blk.baseFeePerGas, blk.gasLimit, blk.gasUsed + )