diff --git a/app/app.go b/app/app.go index 0d622c856..ad4b7e5e5 100644 --- a/app/app.go +++ b/app/app.go @@ -651,6 +651,7 @@ func NewCanto( app.AccountKeeper, app.Erc20Keeper, govKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) app.CSRKeeper = csrkeeper.NewKeeper( diff --git a/x/csr/keeper/keeper_test.go b/x/csr/keeper/keeper_test.go index 40ec23dd2..c871edbcd 100644 --- a/x/csr/keeper/keeper_test.go +++ b/x/csr/keeper/keeper_test.go @@ -149,10 +149,7 @@ func (suite *KeeperTestSuite) SetupApp() { suite.app.StakingKeeper.Hooks().AfterValidatorCreated(suite.ctx, valbz) err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator) require.NoError(t, err) - - validators, err := s.app.StakingKeeper.GetValidators(s.ctx, 1) - require.NoError(t, err) - suite.validator = validators[0] + suite.validator = validator suite.ethSigner = ethtypes.LatestSignerForChainID(s.app.EvmKeeper.ChainID()) } diff --git a/x/csr/keeper/msg_server_test.go b/x/csr/keeper/msg_server_test.go index 14c855145..a7884d2b9 100644 --- a/x/csr/keeper/msg_server_test.go +++ b/x/csr/keeper/msg_server_test.go @@ -14,7 +14,7 @@ import ( csrtypes "github.com/Canto-Network/Canto/v7/x/csr/types" ) -func (suite *KeeperTestSuite) TestMsgUpdateParamsByProposal() { +func (suite *KeeperTestSuite) TestMsgExecutionByProposal() { suite.SetupTest() // change mindeposit for denom @@ -33,30 +33,52 @@ func (suite *KeeperTestSuite) TestMsgUpdateParamsByProposal() { suite.Require().NoError(err) suite.Require().True(shares.GT(sdkmath.LegacyNewDec(0))) - // submit proposal for change params - changeParams := csrtypes.Params{ - EnableCsr: false, - CsrShares: sdkmath.LegacyNewDecWithPrec(20, 2), - } - msg := &csrtypes.MsgUpdateParams{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Params: changeParams, + testCases := []struct { + name string + msg sdk.Msg + checkFunc func(uint64) + }{ + { + "ok - proposal MsgUpdateParams", + &csrtypes.MsgUpdateParams{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + Params: csrtypes.Params{ + EnableCsr: false, + CsrShares: sdkmath.LegacyNewDecWithPrec(20, 2), + }, + }, + func(proposalId uint64) { + changeParams := csrtypes.Params{ + EnableCsr: false, + CsrShares: sdkmath.LegacyNewDecWithPrec(20, 2), + } + + proposal, err := suite.app.GovKeeper.Proposals.Get(suite.ctx, proposalId) + suite.Require().NoError(err) + suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) + suite.Require().Equal(suite.app.CSRKeeper.GetParams(suite.ctx), changeParams) + }, + }, } - proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, []sdk.Msg{msg}, "", "test", "description", proposer, false) - suite.Require().NoError(err) - suite.Commit() - ok, err := suite.app.GovKeeper.AddDeposit(suite.ctx, proposal.Id, proposer, govParams.MinDeposit) - suite.Require().NoError(err) - suite.Require().True(ok) - suite.Commit() + for _, tc := range testCases { + suite.Run(tc.name, func() { + // submit proposal + proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, []sdk.Msg{tc.msg}, "", "test", "description", proposer, false) + suite.Require().NoError(err) + suite.Commit() - err = suite.app.GovKeeper.AddVote(suite.ctx, proposal.Id, proposer, govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "") - suite.Require().NoError(err) - suite.CommitAfter(*govParams.VotingPeriod) + ok, err := suite.app.GovKeeper.AddDeposit(suite.ctx, proposal.Id, proposer, govParams.MinDeposit) + suite.Require().NoError(err) + suite.Require().True(ok) + suite.Commit() - proposal, err = suite.app.GovKeeper.Proposals.Get(suite.ctx, proposal.Id) - suite.Require().NoError(err) - suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) - suite.Require().Equal(suite.app.CSRKeeper.GetParams(suite.ctx), changeParams) + err = suite.app.GovKeeper.AddVote(suite.ctx, proposal.Id, proposer, govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "") + suite.Require().NoError(err) + suite.CommitAfter(*govParams.VotingPeriod) + + // check proposal result + tc.checkFunc(proposal.Id) + }) + } } diff --git a/x/erc20/client/proposal_handler.go b/x/erc20/client/proposal_handler.go deleted file mode 100644 index 8b4ffe387..000000000 --- a/x/erc20/client/proposal_handler.go +++ /dev/null @@ -1,13 +0,0 @@ -package client - -//import ( -// govclient "github.com/cosmos/cosmos-sdk/x/gov/client" -// -// "github.com/Canto-Network/Canto/v7/x/erc20/client/cli" -//) -// -//var ( -// RegisterCoinProposalHandler = govclient.NewProposalHandler(cli.NewRegisterCoinProposalCmd) -// RegisterERC20ProposalHandler = govclient.NewProposalHandler(cli.NewRegisterERC20ProposalCmd) -// ToggleTokenConversionProposalHandler = govclient.NewProposalHandler(cli.NewToggleTokenConversionProposalCmd) -//) diff --git a/x/erc20/keeper/keeper_test.go b/x/erc20/keeper/keeper_test.go index 2e4cbf93e..0744aa549 100644 --- a/x/erc20/keeper/keeper_test.go +++ b/x/erc20/keeper/keeper_test.go @@ -65,6 +65,7 @@ type KeeperTestSuite struct { ethSigner ethtypes.Signer signer keyring.Signer mintFeeCollector bool + validator stakingtypes.Validator } var s *KeeperTestSuite @@ -90,7 +91,6 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { // consensus key pubKey := ed25519.GenPrivKey().PubKey() - require.NoError(t, err) suite.consAddress = sdk.ConsAddress(pubKey.Address()) // setup feemarketGenesis params @@ -173,12 +173,18 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { suite.app.AccountKeeper.SetAccount(suite.ctx, acc) + // Set Validator valAddr := sdk.ValAddress(suite.address.Bytes()) validator, err := stakingtypes.NewValidator(valAddr.String(), pubKey, stakingtypes.Description{}) require.NoError(t, err) + + valbz, err := s.app.StakingKeeper.ValidatorAddressCodec().StringToBytes(validator.GetOperator()) + s.NoError(err) + suite.app.StakingKeeper.SetValidator(suite.ctx, validator) + suite.app.StakingKeeper.Hooks().AfterValidatorCreated(suite.ctx, valbz) err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator) require.NoError(t, err) - suite.app.StakingKeeper.SetValidator(suite.ctx, validator) + suite.validator = validator encodingConfig := encoding.MakeTestEncodingConfig() suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig) @@ -342,7 +348,12 @@ func (suite *KeeperTestSuite) DeployContractDirectBalanceManipulation(name strin return crypto.CreateAddress(suite.address, nonce) } +// Commit commits and starts a new block with an updated context. func (suite *KeeperTestSuite) Commit() { + suite.CommitAfter(time.Second * 0) +} + +func (suite *KeeperTestSuite) CommitAfter(t time.Duration) { header := suite.ctx.BlockHeader() suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ Height: header.Height, @@ -351,8 +362,11 @@ func (suite *KeeperTestSuite) Commit() { suite.app.Commit() header.Height += 1 + header.Time = header.Time.Add(t) suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: header.Height, + Height: header.Height, + Time: header.Time, + ProposerAddress: suite.consAddress, }) // update ctx diff --git a/x/erc20/keeper/msg_server_test.go b/x/erc20/keeper/msg_server_test.go index 5a33c76b1..98a0ce898 100644 --- a/x/erc20/keeper/msg_server_test.go +++ b/x/erc20/keeper/msg_server_test.go @@ -2,22 +2,28 @@ package keeper_test import ( "fmt" + "math" "math/big" sdkmath "cosmossdk.io/math" - "github.com/Canto-Network/Canto/v7/x/erc20/keeper" - "github.com/Canto-Network/Canto/v7/x/erc20/types" - inflationtypes "github.com/Canto-Network/Canto/v7/x/inflation/types" "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ethereum/go-ethereum/common" + "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/evmos/ethermint/tests" "github.com/evmos/ethermint/x/evm/statedb" evmtypes "github.com/evmos/ethermint/x/evm/types" "github.com/stretchr/testify/mock" + + "github.com/Canto-Network/Canto/v7/testutil" + "github.com/Canto-Network/Canto/v7/x/erc20/keeper" + "github.com/Canto-Network/Canto/v7/x/erc20/types" + inflationtypes "github.com/Canto-Network/Canto/v7/x/inflation/types" ) const ( @@ -1500,3 +1506,161 @@ func (suite *KeeperTestSuite) TestConvertERC20NativeIBCVoucher() { } suite.mintFeeCollector = false } + +func (suite *KeeperTestSuite) TestMsgExecutionByProposal() { + suite.SetupTest() + + // set denom + stakingParams, err := suite.app.StakingKeeper.GetParams(suite.ctx) + suite.Require().NoError(err) + denom := stakingParams.BondDenom + + // change mindeposit for denom + govParams, err := suite.app.GovKeeper.Params.Get(suite.ctx) + suite.Require().NoError(err) + govParams.MinDeposit = []sdk.Coin{sdk.NewCoin(denom, sdkmath.NewInt(1))} + err = suite.app.GovKeeper.Params.Set(suite.ctx, govParams) + suite.Require().NoError(err) + + // create account + privKey, err := ethsecp256k1.GenerateKey() + suite.Require().NoError(err) + proposer := sdk.AccAddress(privKey.PubKey().Address().Bytes()) + + // deligate to validator + initAmount := sdkmath.NewInt(int64(math.Pow10(18)) * 2) + initBalance := sdk.NewCoins(sdk.NewCoin(denom, initAmount)) + testutil.FundAccount(suite.app.BankKeeper, suite.ctx, proposer, initBalance) + shares, err := suite.app.StakingKeeper.Delegate(suite.ctx, proposer, sdk.DefaultPowerReduction, stakingtypes.Unbonded, suite.validator, true) + suite.Require().NoError(err) + suite.Require().True(shares.GT(sdkmath.LegacyNewDec(0))) + + var ( + erc20Address = suite.DeployContractDirectBalanceManipulation(erc20Name, erc20Symbol).String() + ) + + testCases := []struct { + name string + msg sdk.Msg + malleate func() + checkFunc func(uint64) + }{ + { + "ok - proposal MsgRegisterCoin", + &types.MsgRegisterCoin{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + Title: "MsgRegisterCoin", + Description: "MsgRegisterCoin test", + Metadata: banktypes.Metadata{ + Description: "ATOM IBC voucher (channel 14)", + Base: ibcBase, + // NOTE: Denom units MUST be increasing + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: ibcBase, + Exponent: 0, + }, + }, + Name: "ATOM channel-14", + Symbol: "ibcATOM-14", + Display: ibcBase, + }, + }, + func() { + err := suite.app.BankKeeper.MintCoins(suite.ctx, inflationtypes.ModuleName, sdk.Coins{sdk.NewInt64Coin(ibcBase, 1)}) + suite.Require().NoError(err) + }, + func(proposalId uint64) { + proposal, err := suite.app.GovKeeper.Proposals.Get(suite.ctx, proposalId) + suite.Require().NoError(err) + suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) + + id := suite.app.Erc20Keeper.GetTokenPairID(suite.ctx, ibcBase) + pair, ok := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, id) + suite.Require().True(ok) + suite.Require().Equal(suite.app.Erc20Keeper.GetDenomMap(suite.ctx, pair.Denom), id) + suite.Require().Equal(suite.app.Erc20Keeper.GetERC20Map(suite.ctx, common.HexToAddress(pair.Erc20Address)), id) + }, + }, + { + "ok - proposal MsgRegisterERC20", + &types.MsgRegisterERC20{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + Title: "MsgRegisterERC20", + Description: "MsgRegisterERC20 test", + Erc20Address: erc20Address, + }, + func() {}, + func(proposalId uint64) { + proposal, err := suite.app.GovKeeper.Proposals.Get(suite.ctx, proposalId) + suite.Require().NoError(err) + suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) + + id := suite.app.Erc20Keeper.GetTokenPairID(suite.ctx, erc20Address) + pair, ok := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, id) + suite.Require().True(ok) + suite.Require().Equal(suite.app.Erc20Keeper.GetDenomMap(suite.ctx, pair.Denom), id) + suite.Require().Equal(suite.app.Erc20Keeper.GetERC20Map(suite.ctx, common.HexToAddress(pair.Erc20Address)), id) + }, + }, + { + "ok - proposal MsgToggleTokenConversion", + &types.MsgToggleTokenConversion{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + Title: "MsgToggleTokenConversion", + Description: "MsgToggleTokenConversion test", + Token: erc20Address, + }, + func() {}, + func(proposalId uint64) { + proposal, err := suite.app.GovKeeper.Proposals.Get(suite.ctx, proposalId) + suite.Require().NoError(err) + suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) + + id := suite.app.Erc20Keeper.GetTokenPairID(suite.ctx, erc20Address) + pair, ok := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, id) + suite.Require().True(ok) + suite.Require().Equal(pair.Enabled, false) + }, + }, + { + "ok - proposal MsgUpdateParams", + &types.MsgUpdateParams{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + Params: types.NewParams(false, false), + }, + func() {}, + func(proposalId uint64) { + changeParams := types.NewParams(false, false) + + proposal, err := suite.app.GovKeeper.Proposals.Get(suite.ctx, proposalId) + suite.Require().NoError(err) + suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) + suite.Require().Equal(suite.app.Erc20Keeper.GetParams(suite.ctx), changeParams) + }, + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + tc.malleate() + + // submit proposal + proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, []sdk.Msg{tc.msg}, "", "test", "description", proposer, false) + suite.Require().NoError(err) + suite.Commit() + + ok, err := suite.app.GovKeeper.AddDeposit(suite.ctx, proposal.Id, proposer, govParams.MinDeposit) + suite.Require().NoError(err) + suite.Require().True(ok) + suite.Commit() + + err = suite.app.GovKeeper.AddVote(suite.ctx, proposal.Id, proposer, govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "") + suite.Require().NoError(err) + suite.CommitAfter(*govParams.VotingPeriod) + + // check proposal result + tc.checkFunc(proposal.Id) + }) + } +} diff --git a/x/erc20/proposal_handler.go b/x/erc20/proposal_handler.go deleted file mode 100644 index 6d37ea215..000000000 --- a/x/erc20/proposal_handler.go +++ /dev/null @@ -1,79 +0,0 @@ -package erc20 - -// -//import ( -// errorsmod "cosmossdk.io/errors" -// sdk "github.com/cosmos/cosmos-sdk/types" -// sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -// govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -// "github.com/ethereum/go-ethereum/common" -// -// "github.com/Canto-Network/Canto/v7/x/erc20/keeper" -// "github.com/Canto-Network/Canto/v7/x/erc20/types" -//) -// -//// NewErc20ProposalHandler creates a governance handler to manage new proposal types. -//func NewErc20ProposalHandler(k *keeper.Keeper) govtypes.Handler { -// return func(ctx sdk.Context, content govtypes.Content) error { -// switch c := content.(type) { -// case *types.RegisterCoinProposal: -// return handleRegisterCoinProposal(ctx, k, c) -// case *types.RegisterERC20Proposal: -// return handleRegisterERC20Proposal(ctx, k, c) -// case *types.ToggleTokenConversionProposal: -// return handleToggleConversionProposal(ctx, k, c) -// -// default: -// return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s proposal content type: %T", types.ModuleName, c) -// } -// } -//} -// -//func handleRegisterCoinProposal(ctx sdk.Context, k *keeper.Keeper, p *types.RegisterCoinProposal) error { -// pair, err := k.RegisterCoin(ctx, p.Metadata) -// if err != nil { -// return err -// } -// ctx.EventManager().EmitEvent( -// sdk.NewEvent( -// types.EventTypeRegisterCoin, -// sdk.NewAttribute(types.AttributeKeyCosmosCoin, pair.Denom), -// sdk.NewAttribute(types.AttributeKeyERC20Token, pair.Erc20Address), -// ), -// ) -// -// return nil -//} -// -//func handleRegisterERC20Proposal(ctx sdk.Context, k *keeper.Keeper, p *types.RegisterERC20Proposal) error { -// pair, err := k.RegisterERC20(ctx, common.HexToAddress(p.Erc20Address)) -// if err != nil { -// return err -// } -// ctx.EventManager().EmitEvent( -// sdk.NewEvent( -// types.EventTypeRegisterERC20, -// sdk.NewAttribute(types.AttributeKeyCosmosCoin, pair.Denom), -// sdk.NewAttribute(types.AttributeKeyERC20Token, pair.Erc20Address), -// ), -// ) -// -// return nil -//} -// -//func handleToggleConversionProposal(ctx sdk.Context, k *keeper.Keeper, p *types.ToggleTokenConversionProposal) error { -// pair, err := k.ToggleConversion(ctx, p.Token) -// if err != nil { -// return err -// } -// -// ctx.EventManager().EmitEvent( -// sdk.NewEvent( -// types.EventTypeToggleTokenConversion, -// sdk.NewAttribute(types.AttributeKeyCosmosCoin, pair.Denom), -// sdk.NewAttribute(types.AttributeKeyERC20Token, pair.Erc20Address), -// ), -// ) -// -// return nil -//} diff --git a/x/govshuttle/client/proposal_handler.go b/x/govshuttle/client/proposal_handler.go deleted file mode 100644 index ce7435307..000000000 --- a/x/govshuttle/client/proposal_handler.go +++ /dev/null @@ -1,12 +0,0 @@ -package client - -import ( - govclient "github.com/cosmos/cosmos-sdk/x/gov/client" - - "github.com/Canto-Network/Canto/v7/x/govshuttle/client/cli" -) - -var ( - LendingMarketProposalHandler = govclient.NewProposalHandler(cli.NewLendingMarketProposalCmd) - TreasuryProposalHandler = govclient.NewProposalHandler(cli.NewTreasuryProposalCmd) -) diff --git a/x/govshuttle/keeper/keeper.go b/x/govshuttle/keeper/keeper.go index 1db65c8c2..0b888c392 100644 --- a/x/govshuttle/keeper/keeper.go +++ b/x/govshuttle/keeper/keeper.go @@ -33,10 +33,10 @@ func NewKeeper( storeService store.KVStoreService, cdc codec.BinaryCodec, ps paramtypes.Subspace, - ak types.AccountKeeper, ek types.ERC20Keeper, gk *govkeeper.Keeper, + authority string, ) Keeper { // set KeyTable if it has not already been set @@ -45,13 +45,13 @@ func NewKeeper( } return Keeper{ - cdc: cdc, storeService: storeService, paramstore: ps, accKeeper: ak, erc20Keeper: ek, govKeeper: gk, + authority: authority, } } diff --git a/x/govshuttle/keeper/msg_server.go b/x/govshuttle/keeper/msg_server.go index f8e207752..2f9381089 100644 --- a/x/govshuttle/keeper/msg_server.go +++ b/x/govshuttle/keeper/msg_server.go @@ -32,9 +32,6 @@ func (k Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) ctx := sdk.UnwrapSDKContext(goCtx) k.SetParams(ctx, req.Params) - //if err := k.SetParams(ctx, req.Params); err != nil { - // return nil, err - //} return &types.MsgUpdateParamsResponse{}, nil } diff --git a/x/govshuttle/proposal_handler.go b/x/govshuttle/proposal_handler.go deleted file mode 100644 index 42f151818..000000000 --- a/x/govshuttle/proposal_handler.go +++ /dev/null @@ -1,54 +0,0 @@ -package govshuttle - -import ( - errorsmod "cosmossdk.io/errors" - "github.com/Canto-Network/Canto/v7/x/govshuttle/keeper" - "github.com/Canto-Network/Canto/v7/x/govshuttle/types" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -// Return governance handler to process Compound Proposal -func NewgovshuttleProposalHandler(k *keeper.Keeper) govtypes.Handler { - return func(ctx sdk.Context, content govtypes.Content) error { - switch c := content.(type) { - case *types.LendingMarketProposal: - return handleLendingMarketProposal(ctx, k, c) - - case *types.TreasuryProposal: - return handleTreasuryProposal(ctx, k, c) - default: - return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s proposal content type: %T", types.ModuleName, c) - } - } -} - -func handleLendingMarketProposal(ctx sdk.Context, k *keeper.Keeper, p *types.LendingMarketProposal) error { - err := p.ValidateBasic() - if err != nil { - return err - } - _, err = k.AppendLendingMarketProposal(ctx, p) //Defined analogous to (erc20)k.RegisterCoin - if err != nil { - return err - } - - return nil -} - -// governance proposal handler -func handleTreasuryProposal(ctx sdk.Context, k *keeper.Keeper, tp *types.TreasuryProposal) error { - err := tp.ValidateBasic() - if err != nil { - return err - } - lm := tp.FromTreasuryToLendingMarket() - _, err = k.AppendLendingMarketProposal(ctx, lm) - tp.GetMetadata().PropID = lm.GetMetadata().GetPropId() - if err != nil { - return err - } - - return nil -} diff --git a/x/inflation/keeper/keeper_test.go b/x/inflation/keeper/keeper_test.go index 3e26dcbdf..df35b2f44 100644 --- a/x/inflation/keeper/keeper_test.go +++ b/x/inflation/keeper/keeper_test.go @@ -125,10 +125,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { suite.app.StakingKeeper.Hooks().AfterValidatorCreated(suite.ctx, valbz) err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator) require.NoError(t, err) - - validators, err := s.app.StakingKeeper.GetValidators(s.ctx, 1) - require.NoError(t, err) - suite.validator = validators[0] + suite.validator = validator suite.ethSigner = ethtypes.LatestSignerForChainID(s.app.EvmKeeper.ChainID()) diff --git a/x/inflation/keeper/msg_server_test.go b/x/inflation/keeper/msg_server_test.go index cdb126c0e..d3b00d7be 100644 --- a/x/inflation/keeper/msg_server_test.go +++ b/x/inflation/keeper/msg_server_test.go @@ -9,14 +9,13 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/Canto-Network/Canto/v7/testutil" inflationtypes "github.com/Canto-Network/Canto/v7/x/inflation/types" ) -func (suite *KeeperTestSuite) TestMsgUpdateParamsByProposal() { +func (suite *KeeperTestSuite) TestMsgExecutionByProposal() { suite.SetupTest() // set denom @@ -44,41 +43,74 @@ func (suite *KeeperTestSuite) TestMsgUpdateParamsByProposal() { suite.Require().NoError(err) suite.Require().True(shares.GT(sdkmath.LegacyNewDec(0))) - // submit proposal for change params - changeParams := inflationtypes.Params{ - MintDenom: "btc", - ExponentialCalculation: inflationtypes.ExponentialCalculation{ - A: sdkmath.LegacyNewDec(int64(16_304_348)), - R: sdkmath.LegacyNewDecWithPrec(35, 2), - C: sdkmath.LegacyZeroDec(), - BondingTarget: sdkmath.LegacyNewDecWithPrec(66, 2), - MaxVariance: sdkmath.LegacyZeroDec(), - }, - InflationDistribution: inflationtypes.InflationDistribution{ - StakingRewards: sdkmath.LegacyNewDecWithPrec(1000000, 6), - CommunityPool: sdkmath.LegacyZeroDec(), + testCases := []struct { + name string + msg sdk.Msg + checkFunc func(uint64) + }{ + { + "ok - proposal MsgUpdateParams", + &inflationtypes.MsgUpdateParams{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + Params: inflationtypes.Params{ + MintDenom: "btc", + ExponentialCalculation: inflationtypes.ExponentialCalculation{ + A: sdkmath.LegacyNewDec(int64(16_304_348)), + R: sdkmath.LegacyNewDecWithPrec(35, 2), + C: sdkmath.LegacyZeroDec(), + BondingTarget: sdkmath.LegacyNewDecWithPrec(66, 2), + MaxVariance: sdkmath.LegacyZeroDec(), + }, + InflationDistribution: inflationtypes.InflationDistribution{ + StakingRewards: sdkmath.LegacyNewDecWithPrec(1000000, 6), + CommunityPool: sdkmath.LegacyZeroDec(), + }, + EnableInflation: false, + }, + }, + func(proposalId uint64) { + changeParams := inflationtypes.Params{ + MintDenom: "btc", + ExponentialCalculation: inflationtypes.ExponentialCalculation{ + A: sdkmath.LegacyNewDec(int64(16_304_348)), + R: sdkmath.LegacyNewDecWithPrec(35, 2), + C: sdkmath.LegacyZeroDec(), + BondingTarget: sdkmath.LegacyNewDecWithPrec(66, 2), + MaxVariance: sdkmath.LegacyZeroDec(), + }, + InflationDistribution: inflationtypes.InflationDistribution{ + StakingRewards: sdkmath.LegacyNewDecWithPrec(1000000, 6), + CommunityPool: sdkmath.LegacyZeroDec(), + }, + EnableInflation: false, + } + + proposal, err := suite.app.GovKeeper.Proposals.Get(suite.ctx, proposalId) + suite.Require().NoError(err) + suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) + suite.Require().Equal(suite.app.InflationKeeper.GetParams(suite.ctx), changeParams) + }, }, - EnableInflation: false, } - msg := &inflationtypes.MsgUpdateParams{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Params: changeParams, - } - proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, []sdk.Msg{msg}, "", "test", "description", proposer, false) - suite.Require().NoError(err) - suite.Commit() - ok, err := suite.app.GovKeeper.AddDeposit(suite.ctx, proposal.Id, proposer, govParams.MinDeposit) - suite.Require().NoError(err) - suite.Require().True(ok) - suite.Commit() + for _, tc := range testCases { + suite.Run(tc.name, func() { + // submit proposal + proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, []sdk.Msg{tc.msg}, "", "test", "description", proposer, false) + suite.Require().NoError(err) + suite.Commit() - err = suite.app.GovKeeper.AddVote(suite.ctx, proposal.Id, proposer, govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "") - suite.Require().NoError(err) - suite.CommitAfter(*govParams.VotingPeriod) + ok, err := suite.app.GovKeeper.AddDeposit(suite.ctx, proposal.Id, proposer, govParams.MinDeposit) + suite.Require().NoError(err) + suite.Require().True(ok) + suite.Commit() - proposal, err = suite.app.GovKeeper.Proposals.Get(suite.ctx, proposal.Id) - suite.Require().NoError(err) - suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) - suite.Require().Equal(suite.app.InflationKeeper.GetParams(suite.ctx), changeParams) + err = suite.app.GovKeeper.AddVote(suite.ctx, proposal.Id, proposer, govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "") + suite.Require().NoError(err) + suite.CommitAfter(*govParams.VotingPeriod) + + // check proposal result + tc.checkFunc(proposal.Id) + }) + } } diff --git a/x/onboarding/keeper/keeper_test.go b/x/onboarding/keeper/keeper_test.go index eed487238..ad063472e 100644 --- a/x/onboarding/keeper/keeper_test.go +++ b/x/onboarding/keeper/keeper_test.go @@ -82,10 +82,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.app.StakingKeeper.Hooks().AfterValidatorCreated(suite.ctx, valbz) err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator) suite.NoError(err) - - validators, err := suite.app.StakingKeeper.GetValidators(suite.ctx, 1) - suite.NoError(err) - suite.validator = validators[0] + suite.validator = validator stakingParams, err := suite.app.StakingKeeper.GetParams(suite.ctx) suite.NoError(err) diff --git a/x/onboarding/keeper/msg_server_test.go b/x/onboarding/keeper/msg_server_test.go index f6abffc3a..0658e2a57 100644 --- a/x/onboarding/keeper/msg_server_test.go +++ b/x/onboarding/keeper/msg_server_test.go @@ -9,14 +9,13 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/Canto-Network/Canto/v7/testutil" onboardingtypes "github.com/Canto-Network/Canto/v7/x/onboarding/types" ) -func (suite *KeeperTestSuite) TestMsgUpdateParamsByProposal() { +func (suite *KeeperTestSuite) TestMsgExecutionByProposal() { suite.SetupTest() // set denom @@ -44,27 +43,46 @@ func (suite *KeeperTestSuite) TestMsgUpdateParamsByProposal() { suite.Require().NoError(err) suite.Require().True(shares.GT(sdkmath.LegacyNewDec(0))) - // submit proposal for change params - changeParams := onboardingtypes.NewParams(true, sdkmath.NewInt(10000), []string{"channel-0"}) - msg := &onboardingtypes.MsgUpdateParams{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Params: changeParams, + testCases := []struct { + name string + msg sdk.Msg + checkFunc func(uint64) + }{ + { + "ok - proposal MsgUpdateParams", + &onboardingtypes.MsgUpdateParams{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + Params: onboardingtypes.NewParams(true, sdkmath.NewInt(10000), []string{"channel-0"}), + }, + func(proposalId uint64) { + changeParams := onboardingtypes.NewParams(true, sdkmath.NewInt(10000), []string{"channel-0"}) + + proposal, err := suite.app.GovKeeper.Proposals.Get(suite.ctx, proposalId) + suite.Require().NoError(err) + suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) + suite.Require().Equal(suite.app.OnboardingKeeper.GetParams(suite.ctx), changeParams) + }, + }, } - proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, []sdk.Msg{msg}, "", "test", "description", proposer, false) - suite.Require().NoError(err) - suite.Commit() - ok, err := suite.app.GovKeeper.AddDeposit(suite.ctx, proposal.Id, proposer, govParams.MinDeposit) - suite.Require().NoError(err) - suite.Require().True(ok) - suite.Commit() + for _, tc := range testCases { + suite.Run(tc.name, func() { + // submit proposal + proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, []sdk.Msg{tc.msg}, "", "test", "description", proposer, false) + suite.Require().NoError(err) + suite.Commit() - err = suite.app.GovKeeper.AddVote(suite.ctx, proposal.Id, proposer, govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "") - suite.Require().NoError(err) - suite.CommitAfter(*govParams.VotingPeriod) + ok, err := suite.app.GovKeeper.AddDeposit(suite.ctx, proposal.Id, proposer, govParams.MinDeposit) + suite.Require().NoError(err) + suite.Require().True(ok) + suite.Commit() - proposal, err = suite.app.GovKeeper.Proposals.Get(suite.ctx, proposal.Id) - suite.Require().NoError(err) - suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) - suite.Require().Equal(suite.app.OnboardingKeeper.GetParams(suite.ctx), changeParams) + err = suite.app.GovKeeper.AddVote(suite.ctx, proposal.Id, proposer, govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "") + suite.Require().NoError(err) + suite.CommitAfter(*govParams.VotingPeriod) + + // check proposal result + tc.checkFunc(proposal.Id) + }) + } }