Skip to content

Commit

Permalink
more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Dec 22, 2023
1 parent 7eb4226 commit a26e7f9
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
timeout-minutes: 240
strategy:
matrix:
tests: [unmarked, ibc, ibc_rly_evm, ibc_rly_gas, ibc_timeout, ibc_update_client, ica, gov, upgrade, slow]
tests: [unmarked, ibc, ibc_rly_evm, ibc_rly_gas, ibc_timeout, ibc_update_client, ica, gov, upgrade, slow, gas]
env:
TESTS_TO_RUN: ${{ matrix.tests }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/configs/min_gas_price.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ config {
app_state+: {
feemarket+: {
params+: {
base_fee_change_denominator: '300',
base_fee_change_denominator: '3',
elasticity_multiplier: '4',
base_fee: '10000000000000',
min_gas_price: '10000000000000',
Expand Down
13 changes: 13 additions & 0 deletions integration_tests/configs/min_gas_price_eq.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local config = import 'min_gas_price_lte.jsonnet';

config {
'cronos_777-1'+: {
genesis+: {
consensus_params+: {
block+: {
max_gas: '84000000',
},
},
},
},
}
16 changes: 16 additions & 0 deletions integration_tests/configs/min_gas_price_lte.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local config = import 'min_gas_price.jsonnet';

config {
'cronos_777-1'+: {
genesis+: {
app_state+: {
feemarket+: {
params+: {
base_fee_change_denominator: '300',
elasticity_multiplier: '4000',
},
},
},
},
},
}
4 changes: 4 additions & 0 deletions integration_tests/test_eip1559.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import pytest

from .utils import ADDRS, KEYS, send_transaction, w3_wait_for_block

pytestmark = pytest.mark.gas


def adjust_base_fee(parent_fee, gas_limit, gas_used):
"spec: https://eips.ethereum.org/EIPS/eip-1559#specification"
Expand Down
54 changes: 44 additions & 10 deletions integration_tests/test_min_gas_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,67 @@
from .network import setup_custom_cronos
from .utils import ADDRS, KEYS, send_transaction, w3_wait_for_block

pytestmark = pytest.mark.gas


@pytest.fixture(scope="module")
def custom_cronos_eq(tmp_path_factory):
path = tmp_path_factory.mktemp("min-gas-price-eq")
yield from setup_custom_cronos(
path, 26500, Path(__file__).parent / "configs/min_gas_price_eq.jsonnet"
)


@pytest.fixture(scope="module")
def custom_cronos(tmp_path_factory):
path = tmp_path_factory.mktemp("min-gas-price")
yield from setup_custom_cronos(
path, 26500, Path(__file__).parent / "configs/min_gas_price.jsonnet"
path, 26530, Path(__file__).parent / "configs/min_gas_price.jsonnet"
)


@pytest.fixture(scope="module")
def custom_cronos_lte(tmp_path_factory):
path = tmp_path_factory.mktemp("min-gas-price-gt")
yield from setup_custom_cronos(
path, 26560, Path(__file__).parent / "configs/min_gas_price_lte.jsonnet"
)


@pytest.fixture(
scope="module",
params=["custom_cronos_eq", "custom_cronos", "custom_cronos_lte"],
)
def custom_cluster(request, custom_cronos_eq, custom_cronos_lte, custom_cronos):
if request.param == "custom_cronos_eq":
return custom_cronos_eq
elif request.param == "custom_cronos_lte":
return custom_cronos_lte
return custom_cronos


def adjust_base_fee(parent_fee, gas_limit, gas_used, params):
"spec: https://eips.ethereum.org/EIPS/eip-1559#specification"
change_denominator = params["base_fee_change_denominator"]
elasticity_multiplier = params["elasticity_multiplier"]
gas_target = gas_limit // elasticity_multiplier

delta = parent_fee * (gas_target - gas_used) // gas_target // change_denominator
if gas_used == gas_target:
return parent_fee
delta = parent_fee * abs(gas_target - gas_used) // gas_target // change_denominator
# https://github.com/crypto-org-chain/ethermint/blob/develop/x/feemarket/keeper/eip1559.go#L104
return max(parent_fee - delta, params["min_gas_price"])
if gas_target > gas_used:
return max(parent_fee - delta, params["min_gas_price"])
else:
return parent_fee + max(delta, 1)


def get_params(cli):
params = cli.query_params("feemarket")["params"]
return {k: int(float(v)) for k, v in params.items()}


def test_dynamic_fee_tx(custom_cronos):
w3 = custom_cronos.w3
def test_dynamic_fee_tx(custom_cluster):
w3 = custom_cluster.w3
amount = 10000
before = w3.eth.get_balance(ADDRS["community"])
tip_price = 1
Expand All @@ -58,23 +92,23 @@ def test_dynamic_fee_tx(custom_cronos):
# check the next block's base fee is adjusted accordingly
w3_wait_for_block(w3, txreceipt.blockNumber + 1)
fee = w3.eth.get_block(txreceipt.blockNumber + 1).baseFeePerGas
params = get_params(custom_cronos.cosmos_cli())
params = get_params(custom_cluster.cosmos_cli())
assert fee == adjust_base_fee(
blk.baseFeePerGas, blk.gasLimit, blk.gasUsed, params
), fee


def test_base_fee_adjustment(custom_cronos):
def test_base_fee_adjustment(custom_cluster):
"""
verify base fee adjustment of three continuous empty blocks
"""
w3 = custom_cronos.w3
w3 = custom_cluster.w3
begin = w3.eth.block_number
w3_wait_for_block(w3, begin + 3)

blk = w3.eth.get_block(begin)
parent_fee = blk.baseFeePerGas
params = get_params(custom_cronos.cosmos_cli())
params = get_params(custom_cluster.cosmos_cli())

for i in range(3):
fee = w3.eth.get_block(begin + 1 + i).baseFeePerGas
Expand Down

0 comments on commit a26e7f9

Please sign in to comment.