From fea4dec29c7fd20a64c8081e2cfff200f325b86a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 7 Oct 2024 10:53:16 +0800 Subject: [PATCH] Problem: expedited related gov params are not adjusted (#1623) * Problem: expedited related gov params are not adjusted * test * test expedited * lint --- CHANGELOG.md | 1 + app/app.go | 2 +- app/upgrades.go | 62 +++++++++- app/upgrades_test.go | 120 ++++++++++++++++++++ integration_tests/cosmoscli.py | 4 +- integration_tests/gravity_utils.py | 2 +- integration_tests/test_basic.py | 74 ++++++------ integration_tests/test_gov_update_params.py | 61 ++++------ integration_tests/test_gravity_2.py | 6 +- integration_tests/test_min_gas_price.py | 2 +- integration_tests/test_upgrade.py | 86 +++++++------- integration_tests/utils.py | 44 +++++++ 12 files changed, 331 insertions(+), 133 deletions(-) create mode 100644 app/upgrades_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index a000159192..9e805e4fcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ * [#1611](https://github.com/crypto-org-chain/cronos/pull/1611) Fix multisig account failed on threshold encode after send tx. * [#1617](https://github.com/crypto-org-chain/cronos/pull/1617) Fix unsuppored sign mode SIGN_MODE_TEXTUAL for bank transfer. * [#1621](https://github.com/crypto-org-chain/cronos/pull/1621) Update ethermint to the fix of broken opBlockhash and tx validation. +* [#1623](https://github.com/crypto-org-chain/cronos/pull/1623) Ensure expedited related gov params pass the basic validation. *Sep 13, 2024* diff --git a/app/app.go b/app/app.go index b068b08b88..946ea821dd 100644 --- a/app/app.go +++ b/app/app.go @@ -954,7 +954,7 @@ func New( // RegisterUpgradeHandlers is used for registering any on-chain upgrades. // Make sure it's called after `app.mm` and `app.configurator` are set. - app.RegisterUpgradeHandlers(app.appCodec, app.IBCKeeper.ClientKeeper) + app.RegisterUpgradeHandlers(app.appCodec) // add test gRPC service for testing gRPC queries in isolation // testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{}) diff --git a/app/upgrades.go b/app/upgrades.go index 677951d3e4..29f7b9902d 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -3,18 +3,21 @@ package app import ( "context" "fmt" + "time" + sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" upgradetypes "cosmossdk.io/x/upgrade/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" - clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" evmtypes "github.com/evmos/ethermint/x/evm/types" ) -func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clientkeeper.Keeper) { +func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec) { planName := "v1.4" app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { m, err := app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM) @@ -32,6 +35,9 @@ func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clie if err := app.EvmKeeper.SetParams(sdkCtx, evmParams); err != nil { return m, err } + if err := UpdateExpeditedParams(ctx, app.GovKeeper); err != nil { + return m, err + } } return m, nil }) @@ -51,3 +57,55 @@ func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clie } } } + +func UpdateExpeditedParams(ctx context.Context, gov govkeeper.Keeper) error { + govParams, err := gov.Params.Get(ctx) + if err != nil { + return err + } + if len(govParams.MinDeposit) > 0 { + minDeposit := govParams.MinDeposit[0] + expeditedAmount := minDeposit.Amount.MulRaw(govv1.DefaultMinExpeditedDepositTokensRatio) + govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewCoin(minDeposit.Denom, expeditedAmount)) + } + threshold, err := sdkmath.LegacyNewDecFromStr(govParams.Threshold) + if err != nil { + return fmt.Errorf("invalid threshold string: %w", err) + } + expeditedThreshold, err := sdkmath.LegacyNewDecFromStr(govParams.ExpeditedThreshold) + if err != nil { + return fmt.Errorf("invalid expedited threshold string: %w", err) + } + if expeditedThreshold.LTE(threshold) { + expeditedThreshold = threshold.Mul(DefaultThresholdRatio()) + } + if expeditedThreshold.GT(sdkmath.LegacyOneDec()) { + expeditedThreshold = sdkmath.LegacyOneDec() + } + govParams.ExpeditedThreshold = expeditedThreshold.String() + if govParams.ExpeditedVotingPeriod != nil && govParams.VotingPeriod != nil && *govParams.ExpeditedVotingPeriod >= *govParams.VotingPeriod { + votingPeriod := DurationToDec(*govParams.VotingPeriod) + period := DecToDuration(DefaultPeriodRatio().Mul(votingPeriod)) + govParams.ExpeditedVotingPeriod = &period + } + if err := govParams.ValidateBasic(); err != nil { + return err + } + return gov.Params.Set(ctx, govParams) +} + +func DefaultThresholdRatio() sdkmath.LegacyDec { + return govv1.DefaultExpeditedThreshold.Quo(govv1.DefaultThreshold) +} + +func DefaultPeriodRatio() sdkmath.LegacyDec { + return DurationToDec(govv1.DefaultExpeditedPeriod).Quo(DurationToDec(govv1.DefaultPeriod)) +} + +func DurationToDec(d time.Duration) sdkmath.LegacyDec { + return sdkmath.LegacyMustNewDecFromStr(fmt.Sprintf("%f", d.Seconds())) +} + +func DecToDuration(d sdkmath.LegacyDec) time.Duration { + return time.Second * time.Duration(d.RoundInt64()) +} diff --git a/app/upgrades_test.go b/app/upgrades_test.go new file mode 100644 index 0000000000..921ffc99c8 --- /dev/null +++ b/app/upgrades_test.go @@ -0,0 +1,120 @@ +package app_test + +import ( + "testing" + "time" + + "cosmossdk.io/math" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + sdk "github.com/cosmos/cosmos-sdk/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/crypto-org-chain/cronos/v2/app" + "github.com/evmos/ethermint/crypto/ethsecp256k1" + "github.com/stretchr/testify/suite" +) + +type AppTestSuite struct { + suite.Suite + + ctx sdk.Context + app *app.App + govParams govv1.Params +} + +func TestAppTestSuite(t *testing.T) { + suite.Run(t, new(AppTestSuite)) +} + +func (suite *AppTestSuite) SetupTest() { + checkTx := false + privKey, err := ethsecp256k1.GenerateKey() + suite.Require().NoError(err) + suite.app = app.Setup(suite.T(), sdk.AccAddress(privKey.PubKey().Address()).String()) + suite.ctx = suite.app.NewContext(checkTx).WithBlockHeader(tmproto.Header{Height: 1, ChainID: app.TestAppChainID, Time: time.Now().UTC()}) + suite.govParams, err = suite.app.GovKeeper.Params.Get(suite.ctx) + suite.Require().NoError(err) + suite.Require().Equal(govv1.DefaultParams(), suite.govParams) +} + +func (suite *AppTestSuite) TestUpdateExpeditedParams() { + const baseDenom = "basetcro" + + testCases := []struct { + name string + malleate func() + exp func(params govv1.Params) + }{ + { + name: "update ExpeditedMinDeposit with baseDenom", + malleate: func() { + suite.govParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(baseDenom, math.NewInt(2000000000000))) + }, + exp: func(params govv1.Params) { + expected := sdk.NewCoins(sdk.NewCoin(suite.govParams.MinDeposit[0].Denom, suite.govParams.MinDeposit[0].Amount.MulRaw(govv1.DefaultMinExpeditedDepositTokensRatio))) + suite.Require().Equal(expected[0], params.ExpeditedMinDeposit[0]) + }, + }, + { + name: "update ExpeditedThreshold when DefaultExpeditedThreshold >= Threshold", + malleate: func() { + suite.govParams.Threshold = "0.99" + }, + exp: func(params govv1.Params) { + suite.Require().Equal(math.LegacyOneDec().String(), params.ExpeditedThreshold) + }, + }, + { + name: "update ExpeditedThreshold when DefaultExpeditedThreshold >= Threshold", + malleate: func() { + suite.govParams.Threshold = govv1.DefaultExpeditedThreshold.String() + }, + exp: func(params govv1.Params) { + expected := app.DefaultThresholdRatio().Mul(math.LegacyMustNewDecFromStr(suite.govParams.Threshold)) + suite.Require().Equal(expected.String(), params.ExpeditedThreshold) + }, + }, + { + name: "no update ExpeditedThreshold when DefaultExpeditedThreshold < Threshold", + malleate: func() { + suite.govParams.Threshold = govv1.DefaultExpeditedThreshold.Quo(math.LegacyMustNewDecFromStr("1.1")).String() + }, + exp: func(params govv1.Params) { + suite.Require().Equal(suite.govParams.ExpeditedThreshold, params.ExpeditedThreshold) + }, + }, + { + name: "update ExpeditedVotingPeriod when DefaultExpeditedPeriod >= VotingPeriod", + malleate: func() { + period := govv1.DefaultExpeditedPeriod + suite.govParams.VotingPeriod = &period + }, + exp: func(params govv1.Params) { + votingPeriod := app.DurationToDec(*suite.govParams.VotingPeriod) + expected := app.DecToDuration(app.DefaultPeriodRatio().Mul(votingPeriod)) + suite.Require().Equal(expected, *params.ExpeditedVotingPeriod) + }, + }, + { + name: "no update ExpeditedVotingPeriod when DefaultExpeditedPeriod < VotingPeriod", + malleate: func() { + period := govv1.DefaultExpeditedPeriod + 1 + suite.govParams.VotingPeriod = &period + }, + exp: func(params govv1.Params) { + suite.Require().Equal(*suite.govParams.ExpeditedVotingPeriod, *params.ExpeditedVotingPeriod) + }, + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() + tc.malleate() + suite.Require().NoError(suite.app.GovKeeper.Params.Set(suite.ctx, suite.govParams)) + suite.Require().NoError(app.UpdateExpeditedParams(suite.ctx, suite.app.GovKeeper)) + params, err := suite.app.GovKeeper.Params.Get(suite.ctx) + suite.Require().NoError(err) + tc.exp(params) + }) + } +} diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index a2f23fa5ef..2ed8812414 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -1110,7 +1110,7 @@ def query_gravity_params(self): return self.query_params("gravity") def query_params(self, module="cronos", **kwargs): - return json.loads( + res = json.loads( self.raw( "query", module, @@ -1119,6 +1119,8 @@ def query_params(self, module="cronos", **kwargs): **kwargs, ) ) + res = res.get("params") or res + return res def query_signer_set_txs(self): return json.loads( diff --git a/integration_tests/gravity_utils.py b/integration_tests/gravity_utils.py index bd2b289c1d..26c1315bc6 100644 --- a/integration_tests/gravity_utils.py +++ b/integration_tests/gravity_utils.py @@ -116,7 +116,7 @@ def prepare_gravity(custom_cronos, custom_geth): send_transaction(w3, {"to": admin.address, "value": 10**17}, KEYS["validator"]) # deploy gravity contract to geth - gravity_id = cli.query_gravity_params()["params"]["gravity_id"] + gravity_id = cli.query_gravity_params()["gravity_id"] signer_set = cli.query_latest_signer_set_tx()["signer_set"]["signers"] powers = [int(signer["power"]) for signer in signer_set] threshold = int(2**32 * 0.66) # gravity normalize the power to [0, 2**32] diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index 820a2c6635..581b0fe7bd 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -1,4 +1,3 @@ -import hashlib import json import subprocess import time @@ -12,7 +11,7 @@ from hexbytes import HexBytes from pystarport import cluster, ports -from .cosmoscli import CosmosCLI +from .cosmoscli import CosmosCLI, module_address from .network import Geth from .utils import ( ADDRS, @@ -20,13 +19,13 @@ KEYS, Greeter, RevertTestContract, - approve_proposal, + assert_gov_params, build_batch_tx, contract_address, contract_path, deploy_contract, derive_new_account, - eth_to_bech32, + get_expedited_params, get_receipts_by_block, get_sync_info, modify_command_in_supervisor_config, @@ -34,6 +33,7 @@ send_txs, sign_transaction, submit_any_proposal, + submit_gov_proposal, w3_wait_for_block, wait_for_block, wait_for_new_blocks, @@ -43,31 +43,43 @@ def test_ica_enabled(cronos, tmp_path): cli = cronos.cosmos_cli() + param0 = cli.query_params("gov") + param1 = get_expedited_params(param0) + # governance module account as signer + authority = module_address("gov") + submit_gov_proposal( + cronos, + tmp_path, + messages=[ + { + "@type": "/cosmos.gov.v1.MsgUpdateParams", + "authority": authority, + "params": { + **param0, + **param1, + }, + } + ], + ) + assert_gov_params(cli, param0) + p = cli.query_ica_params() assert p["controller_enabled"] p["controller_enabled"] = False - proposal = tmp_path / "proposal.json" - # governance module account as signer - data = hashlib.sha256("gov".encode()).digest()[:20] - signer = eth_to_bech32(data) type = "/ibc.applications.interchain_accounts.controller.v1.MsgUpdateParams" - proposal_src = { - "messages": [ + submit_gov_proposal( + cronos, + tmp_path, + messages=[ { "@type": type, - "signer": signer, + "signer": authority, "params": p, } ], - "deposit": "1basetcro", - "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(cronos, rsp["events"]) - print("check params have been updated now") + deposit="5basetcro", + expedited=True, + ) p = cli.query_ica_params() assert not p["controller_enabled"] @@ -912,30 +924,22 @@ def test_submit_send_enabled(cronos, tmp_path): cli = cronos.cosmos_cli() denoms = ["basetcro", "stake"] assert len(cli.query_bank_send(*denoms)) == 0, "should be empty" - proposal = tmp_path / "proposal.json" - # governance module account as signer - signer = "crc10d07y265gmmuvt4z0w9aw880jnsr700jdufnyd" send_enable = [ {"denom": "basetcro"}, {"denom": "stake", "enabled": True}, ] - proposal_src = { - "messages": [ + authority = module_address("gov") + submit_gov_proposal( + cronos, + tmp_path, + messages=[ { "@type": "/cosmos.bank.v1beta1.MsgSetSendEnabled", - "authority": signer, + "authority": authority, "sendEnabled": send_enable, } ], - "deposit": "1basetcro", - "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(cronos, rsp["events"]) - print("check params have been updated now") + ) assert cli.query_bank_send(*denoms) == send_enable diff --git a/integration_tests/test_gov_update_params.py b/integration_tests/test_gov_update_params.py index c78fc83747..3aee62df7c 100644 --- a/integration_tests/test_gov_update_params.py +++ b/integration_tests/test_gov_update_params.py @@ -1,9 +1,7 @@ -import hashlib -import json - import pytest -from .utils import CONTRACTS, approve_proposal, deploy_contract, eth_to_bech32 +from .cosmoscli import module_address +from .utils import CONTRACTS, deploy_contract, submit_gov_proposal pytestmark = pytest.mark.gov @@ -16,31 +14,22 @@ def test_evm_update_param(cronos, tmp_path): res = contract.caller.randomTokenId() assert res > 0, res cli = cronos.cosmos_cli() - p = cli.query_params("evm")["params"] + p = cli.query_params("evm") del p["chain_config"]["merge_netsplit_block"] del p["chain_config"]["shanghai_time"] - proposal = tmp_path / "proposal.json" - # governance module account as signer - data = hashlib.sha256("gov".encode()).digest()[:20] - signer = eth_to_bech32(data) - proposal_src = { - "messages": [ + authority = module_address("gov") + submit_gov_proposal( + cronos, + tmp_path, + messages=[ { "@type": "/ethermint.evm.v1.MsgUpdateParams", - "authority": signer, + "authority": authority, "params": p, } ], - "deposit": "1basetcro", - "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(cronos, rsp["events"]) - print("check params have been updated now") - p = cli.query_params("evm")["params"] + ) + p = cli.query_params("evm") assert not p["chain_config"]["merge_netsplit_block"] assert not p["chain_config"]["shanghai_time"] invalid_msg = "invalid opcode: PUSH0" @@ -53,11 +42,6 @@ def test_evm_update_param(cronos, tmp_path): def test_gov_update_params(cronos, tmp_path): - cli = cronos.cosmos_cli() - - proposal = tmp_path / "proposal.json" - # governance module account as signer - signer = "crc10d07y265gmmuvt4z0w9aw880jnsr700jdufnyd" params = { "cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp", "enable_auto_deployment": False, @@ -66,23 +50,16 @@ def test_gov_update_params(cronos, tmp_path): "ibc_timeout": "96400000000000", "max_callback_gas": "400000", } - proposal_src = { - "messages": [ + authority = module_address("gov") + submit_gov_proposal( + cronos, + tmp_path, + messages=[ { "@type": "/cronos.MsgUpdateParams", - "authority": signer, + "authority": authority, "params": params, } ], - "deposit": "1basetcro", - "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(cronos, rsp["events"]) - print("check params have been updated now") - rsp = cli.query_params() - print("params", rsp) - assert rsp == params + ) + assert cronos.cosmos_cli().query_params() == params diff --git a/integration_tests/test_gravity_2.py b/integration_tests/test_gravity_2.py index 6389a268be..fa682bb33f 100644 --- a/integration_tests/test_gravity_2.py +++ b/integration_tests/test_gravity_2.py @@ -313,7 +313,7 @@ def test_gravity_detect_malicious_supply(gravity): print(denom) # check that the bridge is activated - activate = cli.query_gravity_params()["params"]["bridge_active"] + activate = cli.query_gravity_params()["bridge_active"] assert activate is True max_int = 2**256 - 1 @@ -332,7 +332,7 @@ def check_gravity_native_tokens(): wait_for_fn("balance", check_gravity_native_tokens) # check that the bridge is still activated - activate = cli.query_gravity_params()["params"]["bridge_active"] + activate = cli.query_gravity_params()["bridge_active"] assert activate is True # need a random transferFrom to increment the counter in the contract @@ -354,7 +354,7 @@ def check_gravity_native_tokens(): wait_for_new_blocks(cli, 30) # check that the bridge has not been deactivated - activate = cli.query_gravity_params()["params"]["bridge_active"] + activate = cli.query_gravity_params()["bridge_active"] assert activate is True # check that balance is still same diff --git a/integration_tests/test_min_gas_price.py b/integration_tests/test_min_gas_price.py index ba6e49809b..2fa727ac5f 100644 --- a/integration_tests/test_min_gas_price.py +++ b/integration_tests/test_min_gas_price.py @@ -60,7 +60,7 @@ def adjust_base_fee(parent_fee, gas_limit, gas_used, params): def get_params(cli): - params = cli.query_params("feemarket")["params"] + params = cli.query_params("feemarket") return {k: int(float(v)) for k, v in params.items()} diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index 2aed548e3d..928748df94 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -16,6 +16,7 @@ ADDRS, CONTRACTS, approve_proposal, + assert_gov_params, deploy_contract, edit_ini_sections, get_consensus_params, @@ -111,6 +112,27 @@ def setup_cronos_test(tmp_path_factory): yield cronos +def assert_evm_params(cli, expected, height): + params = cli.query_params("evm", height=height) + del params["header_hash_num"] + assert expected == params + + +def check_basic_tx(c): + # check basic tx works + wait_for_port(ports.evmrpc_port(c.base_port(0))) + receipt = send_transaction( + c.w3, + { + "to": ADDRS["community"], + "value": 1000, + "maxFeePerGas": 10000000000000, + "maxPriorityFeePerGas": 10000, + }, + ) + assert receipt.status == 1 + + def exec(c, tmp_path_factory): """ - propose an upgrade and pass it @@ -162,6 +184,7 @@ def do_upgrade(plan_name, target, mode=None): # block should pass the target height wait_for_block(c.cosmos_cli(), target + 2, timeout=480) wait_for_port(ports.rpc_port(base_port)) + return c.cosmos_cli() # test migrate keystore cli.migrate_keystore() @@ -169,28 +192,16 @@ def do_upgrade(plan_name, target, mode=None): target_height0 = height + 15 print("upgrade v1.1 height", target_height0) - do_upgrade("v1.1.0", target_height0, "block") - cli = c.cosmos_cli() + cli = do_upgrade("v1.1.0", target_height0, "block") + check_basic_tx(c) - # check basic tx works - wait_for_port(ports.evmrpc_port(base_port)) - receipt = send_transaction( - c.w3, - { - "to": ADDRS["community"], - "value": 1000, - "maxFeePerGas": 10000000000000, - "maxPriorityFeePerGas": 10000, - }, - ) - assert receipt.status == 1 height = cli.block_height() target_height1 = height + 15 print("upgrade v1.2 height", target_height1) w3 = c.w3 random_contract = deploy_contract( - c.w3, + w3, CONTRACTS["Random"], ) with pytest.raises(ValueError) as e_info: @@ -205,21 +216,8 @@ def do_upgrade(plan_name, target, mode=None): ) print("old values", old_height, old_balance, old_base_fee) - do_upgrade("v1.2", target_height1) - cli = c.cosmos_cli() - - # check basic tx works - wait_for_port(ports.evmrpc_port(base_port)) - receipt = send_transaction( - c.w3, - { - "to": ADDRS["community"], - "value": 1000, - "maxFeePerGas": 10000000000000, - "maxPriorityFeePerGas": 10000, - }, - ) - assert receipt.status == 1 + cli = do_upgrade("v1.2", target_height1) + check_basic_tx(c) # deploy contract should still work deploy_contract(w3, CONTRACTS["Greeter"]) @@ -247,14 +245,14 @@ def do_upgrade(plan_name, target, mode=None): assert sorted(p, key=lambda x: x["denom"]) == send_enable rsp = cli.query_params("icaauth") - assert rsp["params"]["min_timeout_duration"] == "3600s", rsp + assert rsp["min_timeout_duration"] == "3600s", rsp max_callback_gas = cli.query_params()["max_callback_gas"] assert max_callback_gas == "50000", max_callback_gas - e0 = cli.query_params("evm", height=target_height0 - 1)["params"] - e1 = cli.query_params("evm", height=target_height1 - 1)["params"] - f0 = cli.query_params("feemarket", height=target_height0 - 1)["params"] - f1 = cli.query_params("feemarket", height=target_height1 - 1)["params"] + e0 = cli.query_params("evm", height=target_height0 - 1) + e1 = cli.query_params("evm", height=target_height1 - 1) + f0 = cli.query_params("feemarket", height=target_height0 - 1) + f1 = cli.query_params("feemarket", height=target_height1 - 1) assert e0["evm_denom"] == e1["evm_denom"] == "basetcro" # update the genesis time = current time + 5 secs @@ -280,24 +278,18 @@ def do_upgrade(plan_name, target, mode=None): height = cli.block_height() target_height3 = height + 15 print("upgrade v1.4 height", target_height2) - do_upgrade("v1.4", target_height3) - - cli = c.cosmos_cli() + gov_param = cli.query_params("gov") - def assert_evm_params(cli, expected, height): - params = cli.query_params("evm", height=height)["params"] - del params["header_hash_num"] - assert expected == params + cli = do_upgrade("v1.4", target_height3) assert_evm_params(cli, e0, target_height0 - 1) assert_evm_params(cli, e1, target_height1 - 1) - - assert f0 == cli.query_params("feemarket", height=target_height0 - 1)["params"] - assert f1 == cli.query_params("feemarket", height=target_height1 - 1)["params"] - assert cli.query_params("evm")["params"]["header_hash_num"] == "10000", p - + assert f0 == cli.query_params("feemarket", height=target_height0 - 1) + assert f1 == cli.query_params("feemarket", height=target_height1 - 1) + assert cli.query_params("evm")["header_hash_num"] == "10000", p with pytest.raises(AssertionError): cli.query_params("icaauth") + assert_gov_params(cli, gov_param) def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory): diff --git a/integration_tests/utils.py b/integration_tests/utils.py index eda86d61d6..adbdaa2bf9 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -10,6 +10,7 @@ import time from collections import defaultdict from concurrent.futures import ThreadPoolExecutor, as_completed +from decimal import Decimal from pathlib import Path import bech32 @@ -163,6 +164,21 @@ def approve_proposal(n, events, event_query_tx=False): assert proposal["status"] == "PROPOSAL_STATUS_PASSED", proposal +def submit_gov_proposal(cronos, tmp_path, **kwargs): + proposal = tmp_path / "proposal.json" + proposal_src = { + "title": "title", + "summary": "summary", + "deposit": "1basetcro", + **kwargs, + } + proposal.write_text(json.dumps(proposal_src)) + rsp = cronos.cosmos_cli().submit_gov_proposal(proposal, from_="community") + assert rsp["code"] == 0, rsp["raw_log"] + approve_proposal(cronos, rsp["events"]) + print("check params have been updated now") + + def wait_for_port(port, host="127.0.0.1", timeout=40.0): start_time = time.perf_counter() while True: @@ -738,3 +754,31 @@ def get_send_enable(port): url = f"http://127.0.0.1:{port}/cosmos/bank/v1beta1/params" raw = requests.get(url).json() return raw["params"]["send_enabled"] + + +def get_expedited_params(param): + min_deposit = param["min_deposit"][0] + voting_period = param["voting_period"] + tokens_ratio = 5 + threshold_ratio = 1.334 + period_ratio = 0.5 + expedited_threshold = float(param["threshold"]) * threshold_ratio + expedited_threshold = Decimal(f"{expedited_threshold}") + expedited_voting_period = int(int(voting_period[:-1]) * period_ratio) + return { + "expedited_min_deposit": [ + { + "denom": min_deposit["denom"], + "amount": str(int(min_deposit["amount"]) * tokens_ratio), + } + ], + "expedited_threshold": f"{expedited_threshold:.18f}", + "expedited_voting_period": f"{expedited_voting_period}s", + } + + +def assert_gov_params(cli, old_param): + param = cli.query_params("gov") + expedited_param = get_expedited_params(old_param) + for key, value in expedited_param.items(): + assert param[key] == value, param