forked from cerc-io/laconicd-deprecated
* fix(rpc): align fee history (#1611) * update nix * add next fee in fee history * fix test * add change doc * height + 1 for next fee * cross check baseFeePerGas len * Update tests/integration_tests/test_fee_history.py Co-authored-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com> * fix oldestBlock & align earliest input as eth * update doc * update nix * isort test_fee_history.py * fix test * align rpc res as eth * add cross check * add baseFeePerGas len check * add oldestBlock check Co-authored-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> (cherry picked from commit 47fdfd3d8318358c2578b610bc35bc8c1ebb131e) # Conflicts: # CHANGELOG.md * address merge conflicts Co-authored-by: mmsqe <mavis@crypto.com> Co-authored-by: MalteHerrmann <malte@evmos.org> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
co-authored by
mmsqe
MalteHerrmann
Federico Kunze Küllmer
parent
c1c25b1818
commit
949674e511
@@ -0,0 +1,73 @@
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import pytest
|
||||
from web3 import Web3
|
||||
|
||||
from .network import setup_ethermint
|
||||
from .utils import ADDRS, send_transaction
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def custom_ethermint(tmp_path_factory):
|
||||
path = tmp_path_factory.mktemp("fee-history")
|
||||
yield from setup_ethermint(path, 26500, long_timeout_commit=True)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", params=["ethermint", "geth"])
|
||||
def cluster(request, custom_ethermint, geth):
|
||||
"""
|
||||
run on both ethermint and geth
|
||||
"""
|
||||
provider = request.param
|
||||
if provider == "ethermint":
|
||||
yield custom_ethermint
|
||||
elif provider == "geth":
|
||||
yield geth
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def test_basic(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)
|
||||
size = 4
|
||||
# size of base fee + next fee
|
||||
max = size + 1
|
||||
# only 1 base fee + next fee
|
||||
min = 2
|
||||
method = "eth_feeHistory"
|
||||
field = "baseFeePerGas"
|
||||
percentiles = [100]
|
||||
height = w3.eth.block_number
|
||||
latest = dict(
|
||||
blocks=["latest", hex(height)],
|
||||
expect=max,
|
||||
)
|
||||
earliest = dict(
|
||||
blocks=["earliest", "0x0"],
|
||||
expect=min,
|
||||
)
|
||||
for tc in [latest, earliest]:
|
||||
res = []
|
||||
with ThreadPoolExecutor(len(tc["blocks"])) as exec:
|
||||
tasks = [
|
||||
exec.submit(call, method, [size, b, percentiles]) for b in tc["blocks"]
|
||||
]
|
||||
res = [future.result()["result"][field] for future in as_completed(tasks)]
|
||||
assert len(res) == len(tc["blocks"])
|
||||
assert res[0] == res[1]
|
||||
assert len(res[0]) == tc["expect"]
|
||||
|
||||
for x in range(max):
|
||||
i = x + 1
|
||||
fee_history = call(method, [size, hex(i), percentiles])
|
||||
# start to reduce diff on i <= size - min
|
||||
diff = size - min - i
|
||||
reduce = size - diff
|
||||
target = reduce if diff >= 0 else max
|
||||
res = fee_history["result"]
|
||||
assert len(res[field]) == target
|
||||
oldest = i + min - max
|
||||
assert res["oldestBlock"] == hex(oldest if oldest > 0 else 0)
|
||||
@@ -595,8 +595,8 @@ func TestEth_FeeHistory(t *testing.T) {
|
||||
baseFeePerGas := info["baseFeePerGas"].([]interface{})
|
||||
gasUsedRatio := info["gasUsedRatio"].([]interface{})
|
||||
|
||||
require.Equal(t, info["oldestBlock"].(string), "0x6")
|
||||
require.Equal(t, info["oldestBlock"].(string), "0x7")
|
||||
require.Equal(t, 4, len(gasUsedRatio))
|
||||
require.Equal(t, 4, len(baseFeePerGas))
|
||||
require.Equal(t, 5, len(baseFeePerGas))
|
||||
require.Equal(t, 4, len(reward))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user