Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
cross check next fee
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Mar 23, 2023
1 parent 8c5f290 commit fceb6ac
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/integration_tests/test_fee_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit fceb6ac

Please sign in to comment.