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 8f7fed9 commit ed6f4f1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 27 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
6 changes: 3 additions & 3 deletions integration_tests/configs/min_gas_price.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ local config = import 'default.jsonnet';
config {
'cronos_777-1'+: {
validators: [validator {
gas_prices: '20000000000000basetcro',
gas_prices: '10000000000000basetcro',
} for validator in super.validators],
genesis+: {
app_state+: {
feemarket+: {
params+: {
base_fee_change_denominator: '300',
base_fee_change_denominator: '3',
elasticity_multiplier: '4',
base_fee: '10000000000000',
min_gas_price: '10000000000001',
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
65 changes: 42 additions & 23 deletions integration_tests/test_min_gas_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,71 @@
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"
parent_base_fee = params["base_fee"]
print("mm-parent_base_fee", parent_base_fee)
change_denominator = params["base_fee_change_denominator"]
elasticity_multiplier = params["elasticity_multiplier"]
gas_target = gas_limit // elasticity_multiplier
print("mm-gas_used", gas_used)
print("mm-gas_target", gas_target)
if gas_used == gas_target:
return parent_base_fee

delta = parent_fee * (gas_target - gas_used) // gas_target // change_denominator
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
if gas_target > gas_used:
res1 = max(parent_fee - delta, params["min_gas_price"])
print("mm-res1", res1)
return res1
return max(parent_fee - delta, params["min_gas_price"])
else:
res2 = parent_fee - min(delta, -1)
print("mm-res2", res2)
return res2
return parent_fee + max(delta, 1)


def get_params(cli):
params = cli.query_params("feemarket")["params"]
print("mm-params", 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
min_gas_price = 10000000000001
max_price = min_gas_price + tip_price
max_price = 10000000000000 + tip_price
tx = {
"to": "0x0000000000000000000000000000000000000000",
"value": amount,
Expand All @@ -73,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 ed6f4f1

Please sign in to comment.