From de3b8c6e3360d849c82d14522741621c66488f09 Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 12 Mar 2024 14:12:54 +0800 Subject: [PATCH] Problem: no doc for feemarket param gov proposal (#1344) * Problem: no doc for feemarket param gov proposal - add a integration test case for demonstration * fix test --------- Co-authored-by: mmsqe --- integration_tests/cosmoscli.py | 10 ++++++++- integration_tests/test_basic.py | 28 +++++++++++++++++++++++ integration_tests/utils.py | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index b8ab038cd9..f818a88538 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -706,6 +706,7 @@ def gov_propose_v0_7(self, proposer, kind, proposal, **kwargs): def gov_propose_legacy(self, proposer, kind, proposal, **kwargs): kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE) + kwargs.setdefault("gas", 300000) if kind == "software-upgrade": return json.loads( self.raw( @@ -782,7 +783,9 @@ def gov_vote(self, voter, proposal_id, option, **kwargs): ) ) - def gov_deposit(self, depositor, proposal_id, amount): + def gov_deposit(self, depositor, proposal_id, amount, **kwargs): + kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE) + kwargs.setdefault("gas", 300000) return json.loads( self.raw( "tx", @@ -796,6 +799,7 @@ def gov_deposit(self, depositor, proposal_id, amount): node=self.node_rpc, keyring_backend="test", chain_id=self.chain_id, + **kwargs, ) ) @@ -1452,3 +1456,7 @@ def changeset_ingest_versiondb_sst(self, versiondb_dir, sst_dir, **kwargs): "--move-files", **kwargs, ).decode() + + def query_feemarket_params(self, **kwargs): + res = self.raw("q", "feemarket", "params", home=self.data_dir, **kwargs) + return json.loads(res) diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index 5abdfe1496..47632acafd 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -1,6 +1,7 @@ import json import time from concurrent.futures import ThreadPoolExecutor, as_completed +from decimal import Decimal from pathlib import Path import pytest @@ -16,6 +17,7 @@ KEYS, Greeter, RevertTestContract, + approve_proposal, build_batch_tx, contract_address, contract_path, @@ -732,3 +734,29 @@ def test_replay_protection(cronos): match=r"only replay-protected \(EIP-155\) transactions allowed over RPC", ): w3.eth.send_raw_transaction(HexBytes(raw)) + + +def test_gov_min_gas_price(cronos): + cli = cronos.cosmos_cli() + orig = Decimal(cli.query_feemarket_params()["params"]["min_gas_price"]) + + rsp = cli.gov_propose_legacy( + "community", + "param-change", + { + "title": "Update MinGasPrice", + "description": "Update MinGasPrice", + "changes": [ + { + "subspace": "feemarket", + "key": "MinGasPrice", + "value": str(orig + Decimal("0.1")), + }, + ], + }, + ) + + approve_proposal(cronos, rsp) + + new = Decimal(cli.query_feemarket_params()["params"]["min_gas_price"]) + assert new == orig + Decimal("0.1") diff --git a/integration_tests/utils.py b/integration_tests/utils.py index f8ae412b8e..c5b64a6a0f 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -9,6 +9,7 @@ import time from collections import defaultdict from concurrent.futures import ThreadPoolExecutor, as_completed +from datetime import timedelta from pathlib import Path import bech32 @@ -524,3 +525,41 @@ def send_txs(w3, cli, to, keys, params): sended_hash_set = send_raw_transactions(w3, raw_transactions) return block_num_0, sended_hash_set + + +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 get_proposal_id(rsp, msg): + def cb(attrs): + return "proposal_id" in attrs + + ev = find_log_event_attrs(rsp["logs"], "submit_proposal", cb) + assert ev["proposal_messages"] == msg, rsp + return ev["proposal_id"] + + +def approve_proposal(n, rsp): + # get proposal_id + proposal_id = get_proposal_id(rsp, ",/cosmos.gov.v1.MsgExecLegacyContent") + cli = n.cosmos_cli() + proposal = cli.query_proposal(proposal_id) + assert proposal["status"] == "PROPOSAL_STATUS_DEPOSIT_PERIOD", proposal + rsp = cli.gov_deposit("community", proposal_id, "1basetcro") + assert rsp["code"] == 0, rsp["raw_log"] + proposal = cli.query_proposal(proposal_id) + assert proposal["status"] == "PROPOSAL_STATUS_VOTING_PERIOD", proposal + 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_block_time( + cli, isoparse(proposal["voting_end_time"]) + timedelta(seconds=5) + ) + proposal = cli.query_proposal(proposal_id) + assert proposal["status"] == "PROPOSAL_STATUS_PASSED", proposal