Skip to content

Commit

Permalink
reproduce with param change
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 19, 2023
1 parent 0b3f557 commit c0312a4
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 15 deletions.
1 change: 1 addition & 0 deletions cmd/ethermintd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func queryCommand() *cobra.Command {
rpc.BlockCommand(),
authcmd.QueryTxsByEventsCmd(),
authcmd.QueryTxCmd(),
rpc.QueryEventForTxCmd(),
)

app.ModuleBasics.AddQueryCommands(cmd)
Expand Down
14 changes: 14 additions & 0 deletions tests/integration_tests/configs/cosmovisor.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ config {
base_fee:: super.base_fee,
},
},
gov: {
voting_params: {
voting_period: '10s',
},
deposit_params: {
max_deposit_period: '10s',
min_deposit: [
{
denom: 'aphoton',
amount: '1',
},
],
},
},
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions tests/integration_tests/configs/default.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@
},
},
gov: {
voting_params: {
params: {
voting_period: '10s',
},
deposit_params: {
max_deposit_period: '10s',
min_deposit: [
{
Expand Down
41 changes: 39 additions & 2 deletions tests/integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import subprocess
import tempfile

import requests
Expand All @@ -13,10 +14,10 @@ class ChainCommand:
def __init__(self, cmd):
self.cmd = cmd

def __call__(self, cmd, *args, stdin=None, **kwargs):
def __call__(self, cmd, *args, stdin=None, stderr=subprocess.STDOUT, **kwargs):
"execute chain-maind"
args = " ".join(build_cli_args_safe(cmd, *args, **kwargs))
return interact(f"{self.cmd} {args}", input=stdin)
return interact(f"{self.cmd} {args}", input=stdin, stderr=stderr)


class CosmosCLI:
Expand Down Expand Up @@ -700,6 +701,7 @@ def gov_propose(self, proposer, kind, proposal, **kwargs):

def gov_vote(self, voter, proposal_id, option, **kwargs):
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
kwargs.setdefault("broadcast_mode", "sync")
return json.loads(
self.raw(
"tx",
Expand Down Expand Up @@ -839,3 +841,38 @@ def rollback(self):

def migrate_keystore(self):
return self.raw("keys", "migrate", home=self.data_dir)

def get_default_kwargs(self):
return {
"gas_prices": DEFAULT_GAS_PRICE,
"gas": "auto",
"gas_adjustment": "1.5",
}

def event_query_tx_for(self, hash):
return json.loads(
self.raw(
"query",
"event-query-tx-for",
hash,
"-y",
home=self.data_dir,
stderr=subprocess.DEVNULL,
)
)

def submit_gov_proposal(self, proposal, **kwargs):
default_kwargs = self.get_default_kwargs()
kwargs.setdefault("broadcast_mode", "sync")
return json.loads(
self.raw(
"tx",
"gov",
"submit-proposal",
proposal,
"-y",
home=self.data_dir,
stderr=subprocess.DEVNULL,
**(default_kwargs | kwargs),
)
)
70 changes: 60 additions & 10 deletions tests/integration_tests/test_fee_history.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import hashlib
import json
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path

import pytest
from web3 import Web3

from .network import setup_custom_ethermint
from .utils import ADDRS, send_transaction, w3_wait_for_new_blocks
from .utils import (
ADDRS,
approve_proposal,
eth_to_bech32,
send_transaction,
w3_wait_for_new_blocks,
)


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -162,17 +170,59 @@ def test_percentiles(cluster):
assert all(msg in res["error"]["message"] for res in result)


def test_concurrent(custom_ethermint):
def test_concurrent(custom_ethermint, tmp_path):
w3: Web3 = custom_ethermint.w3
call = w3.provider.make_request
b = w3.eth.block_number
field = "baseFeePerGas"
base = call("eth_getBlockByNumber", [b, False])["result"][field]
tx = {"to": ADDRS["community"], "value": 10, "gasPrice": w3.eth.gas_price}
# send multi txs, overlap happens with query with 2nd tx's block number
send_transaction(w3, tx)
receipt1 = send_transaction(w3, tx)
b1 = receipt1.blockNumber
send_transaction(w3, tx)

call = w3.provider.make_request
field = "baseFeePerGas"

cli = custom_ethermint.cosmos_cli()
p = cli.get_params("feemarket")["params"]
new_multiplier = 2
new_denominator = 200000000
p["elasticity_multiplier"] = new_multiplier
p["base_fee_change_denominator"] = new_denominator

proposal = tmp_path / "proposal.json"
# governance module account as signer
data = hashlib.sha256("gov".encode()).digest()[:20]
signer = eth_to_bech32(data)
print("mm-signer", signer)
proposal_src = {
"messages": [
{
"@type": "/ethermint.feemarket.v1.MsgUpdateParams",
"authority": signer,
"params": p,
}
],
"deposit": "2aphoton",
"title": "title",
"summary": "summary",
}
proposal.write_text(json.dumps(proposal_src))
rsp = cli.submit_gov_proposal(proposal, from_="community")
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(custom_ethermint, rsp)
print("check params have been updated now")
p = cli.get_params("feemarket")["params"]
assert p["elasticity_multiplier"] == new_multiplier
assert p["base_fee_change_denominator"] == new_denominator

percentiles = []
method = "eth_feeHistory"

for i in range(3):
history = call(method, [i + 1, hex(b), percentiles])["result"][field]
assert history[i] == base
# big enough concurrent requests to trigger overwrite bug
total = 10
size = 2
params = [size, hex(b1), percentiles]
res = []
with ThreadPoolExecutor(total) as exec:
t = [exec.submit(call, method, params) for i in range(total)]
res = [future.result()["result"][field] for future in as_completed(t)]
assert all(sublist == res[0] for sublist in res), res
34 changes: 34 additions & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,37 @@ def build_batch_tx(w3, cli, txs, key=KEYS["validator"]):
},
"signatures": [],
}, tx_hashes


def find_log_event_attrs(logs, ev_type, cond=None):
for ev in logs[0]["events"]:
if ev["type"] == ev_type:
attrs = {attr["key"]: attr["value"] for attr in ev["attributes"]}
if cond is None or cond(attrs):
return attrs
return None


def approve_proposal(n, rsp, event_query_tx=True):
cli = n.cosmos_cli()
if event_query_tx:
rsp = cli.event_query_tx_for(rsp["txhash"])
# get proposal_id

def cb(attrs):
return "proposal_id" in attrs

ev = find_log_event_attrs(rsp["logs"], "submit_proposal", cb)
proposal_id = ev["proposal_id"]
for i in range(len(n.config["validators"])):
rsp = n.cosmos_cli(i).gov_vote("validator", proposal_id, "yes")
assert rsp["code"] == 0, rsp["raw_log"]
wait_for_new_blocks(cli, 1)
assert (
int(cli.query_tally(proposal_id)["yes_count"]) == cli.staking_pool()
), "all validators should have voted yes"
print("wait for proposal to be activated")
proposal = cli.query_proposal(proposal_id)
wait_for_block_time(cli, isoparse(proposal["voting_end_time"]))
proposal = cli.query_proposal(proposal_id)
assert proposal["status"] == "PROPOSAL_STATUS_PASSED", proposal

0 comments on commit c0312a4

Please sign in to comment.