diff --git a/app/modules.go b/app/modules.go index 4f947226..3b4ed8dc 100644 --- a/app/modules.go +++ b/app/modules.go @@ -12,7 +12,7 @@ import ( customdistr "github.com/classic-terra/core/v3/custom/distribution" customevidence "github.com/classic-terra/core/v3/custom/evidence" customfeegrant "github.com/classic-terra/core/v3/custom/feegrant" - "github.com/classic-terra/core/v3/custom/gov" + // "github.com/classic-terra/core/v3/custom/gov" customgov "github.com/classic-terra/core/v3/custom/gov" custommint "github.com/classic-terra/core/v3/custom/mint" customparams "github.com/classic-terra/core/v3/custom/params" @@ -167,7 +167,7 @@ func appModules( bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), - gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper, app.GetSubspace(govtypes.ModuleName)), + customgov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper, app.GetSubspace(govtypes.ModuleName)), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), @@ -202,7 +202,7 @@ func simulationModules( custombank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), - gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper, app.GetSubspace(govtypes.ModuleName)), + customgov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper, app.GetSubspace(govtypes.ModuleName)), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), diff --git a/custom/gov/client/cli/init_test.go b/custom/gov/client/cli/init_test.go index a2a906b2..817e3bed 100644 --- a/custom/gov/client/cli/init_test.go +++ b/custom/gov/client/cli/init_test.go @@ -1,42 +1,42 @@ -package cli_test +package cli_test import ( - - "io" - "testing" - "github.com/stretchr/testify/suite" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/gov" - // "github.com/cosmos/cosmos-sdk/x/gov/client/cli" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" + "io" + "testing" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/stretchr/testify/suite" + // "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" ) type CLITestSuite struct { - suite.Suite + suite.Suite - kr keyring.Keyring - encCfg testutilmod.TestEncodingConfig //This holds the encoding configuration, which is crucial for marshaling and unmarshaling data for transactions and messages. - baseCtx client.Context //This is a base context used for all operations in the test suite. + kr keyring.Keyring + encCfg testutilmod.TestEncodingConfig // This holds the encoding configuration, which is crucial for marshaling and unmarshaling data for transactions and messages. + baseCtx client.Context // This is a base context used for all operations in the test suite. } func TestCLITestSuite(t *testing.T) { - suite.Run(t, new(CLITestSuite)) + suite.Run(t, new(CLITestSuite)) } -//run once before any tests in the suite + +// run once before any tests in the suite func (s *CLITestSuite) SetupSuite() { - //It initializes the necessary components, such as the codec, which is used for marshaling and unmarshaling data. - s.encCfg = testutilmod.MakeTestEncodingConfig(gov.AppModuleBasic{}) - s.kr = keyring.NewInMemory(s.encCfg.Codec) - s.baseCtx = client.Context{}. - WithKeyring(s.kr). - WithTxConfig(s.encCfg.TxConfig). - WithCodec(s.encCfg.Codec). - WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). - WithAccountRetriever(client.MockAccountRetriever{}). - WithOutput(io.Discard). - WithChainID("test-chain") + s.encCfg = testutilmod.MakeTestEncodingConfig(gov.AppModuleBasic{}) + s.kr = keyring.NewInMemory(s.encCfg.Codec) + s.baseCtx = client.Context{}. + WithKeyring(s.kr). + WithTxConfig(s.encCfg.TxConfig). + WithCodec(s.encCfg.Codec). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). + WithAccountRetriever(client.MockAccountRetriever{}). + WithOutput(io.Discard). + WithChainID("test-chain") +} -} \ No newline at end of file diff --git a/custom/gov/client/cli/query.go b/custom/gov/client/cli/query.go index ccc22b53..0b4c1ea5 100644 --- a/custom/gov/client/cli/query.go +++ b/custom/gov/client/cli/query.go @@ -97,7 +97,7 @@ func GetCmdQueryCustomParams() *cobra.Command { Use: "custom-params", Args: cobra.NoArgs, Short: "Query custom params of module", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err diff --git a/custom/gov/client/cli/query_test.go b/custom/gov/client/cli/query_test.go index 91dd66e0..fefe9155 100644 --- a/custom/gov/client/cli/query_test.go +++ b/custom/gov/client/cli/query_test.go @@ -1,40 +1,41 @@ -package cli_test +package cli_test import ( - "fmt" - "strings" - v2lunc1cli "github.com/classic-terra/core/v3/custom/gov/client/cli" + "fmt" + "strings" + + v2lunc1cli "github.com/classic-terra/core/v3/custom/gov/client/cli" ) func (s *CLITestSuite) TestGetCmdQueryMinimalDeposit() { - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "proposal with id", - []string{ - "1", - }, - "1", - }, - { - "proposal with no id", - []string{ - "", - }, - "", - }, - } + testCases := []struct { + name string + args []string + expCmdOutput string + }{ + { + "proposal with id", + []string{ + "1", + }, + "1", + }, + { + "proposal with no id", + []string{ + "", + }, + "", + }, + } - for _, tc := range testCases { - tc := tc + for _, tc := range testCases { + tc := tc - s.Run(tc.name, func() { - cmd := v2lunc1cli.GetCmdQueryMinimalDeposit() - cmd.SetArgs(tc.args) - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - }) - } -} \ No newline at end of file + s.Run(tc.name, func() { + cmd := v2lunc1cli.GetCmdQueryMinimalDeposit() + cmd.SetArgs(tc.args) + s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) + }) + } +} diff --git a/custom/gov/client/cli/util.go b/custom/gov/client/cli/util.go index 736569c7..85076bcd 100644 --- a/custom/gov/client/cli/util.go +++ b/custom/gov/client/cli/util.go @@ -1,52 +1,52 @@ package cli -import ( - "encoding/json" - "os" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// proposal defines the new Msg-based proposal. -type proposal struct { - // Msgs defines an array of sdk.Msgs proto-JSON-encoded as Anys. - Messages []json.RawMessage `json:"messages,omitempty"` - Metadata string `json:"metadata"` - Deposit string `json:"deposit"` - Title string `json:"title"` - Summary string `json:"summary"` -} - -// parseSubmitProposal reads and parses the proposal. -func parseSubmitProposal(cdc codec.Codec, path string) ([]sdk.Msg, string, string, string, sdk.Coins, error) { - var proposal proposal - - contents, err := os.ReadFile(path) - if err != nil { - return nil, "", "", "", nil, err - } - - err = json.Unmarshal(contents, &proposal) - if err != nil { - return nil, "", "", "", nil, err - } - - msgs := make([]sdk.Msg, len(proposal.Messages)) - for i, anyJSON := range proposal.Messages { - var msg sdk.Msg - err := cdc.UnmarshalInterfaceJSON(anyJSON, &msg) - if err != nil { - return nil, "", "", "", nil, err - } - - msgs[i] = msg - } - - deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit) - if err != nil { - return nil, "", "", "", nil, err - } - - return msgs, proposal.Metadata, proposal.Title, proposal.Summary, deposit, nil -} +// import ( +// "encoding/json" +// "os" + +// "github.com/cosmos/cosmos-sdk/codec" +// sdk "github.com/cosmos/cosmos-sdk/types" +// ) + +// // proposal defines the new Msg-based proposal. +// type proposal struct { +// // Msgs defines an array of sdk.Msgs proto-JSON-encoded as Anys. +// Messages []json.RawMessage `json:"messages,omitempty"` +// Metadata string `json:"metadata"` +// Deposit string `json:"deposit"` +// Title string `json:"title"` +// Summary string `json:"summary"` +// } + +// // parseSubmitProposal reads and parses the proposal. +// func parseSubmitProposal(cdc codec.Codec, path string) ([]sdk.Msg, string, string, string, sdk.Coins, error) { +// var proposal proposal + +// contents, err := os.ReadFile(path) +// if err != nil { +// return nil, "", "", "", nil, err +// } + +// err = json.Unmarshal(contents, &proposal) +// if err != nil { +// return nil, "", "", "", nil, err +// } + +// msgs := make([]sdk.Msg, len(proposal.Messages)) +// for i, anyJSON := range proposal.Messages { +// var msg sdk.Msg +// err := cdc.UnmarshalInterfaceJSON(anyJSON, &msg) +// if err != nil { +// return nil, "", "", "", nil, err +// } + +// msgs[i] = msg +// } + +// deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit) +// if err != nil { +// return nil, "", "", "", nil, err +// } + +// return msgs, proposal.Metadata, proposal.Title, proposal.Summary, deposit, nil +// } diff --git a/custom/gov/keeper/deposit_test.go b/custom/gov/keeper/deposit_test.go index 794e9f4f..4455dcdc 100644 --- a/custom/gov/keeper/deposit_test.go +++ b/custom/gov/keeper/deposit_test.go @@ -64,7 +64,7 @@ func TestAddDeposits(t *testing.T) { require.True(t, sdk.NewCoins(proposal.TotalDeposit...).IsEqual(sdk.NewCoins())) // Check no deposits at beginning - deposit, found := govKeeper.GetDeposit(ctx, proposalID, addr1) + _, found := govKeeper.GetDeposit(ctx, proposalID, addr1) require.False(t, found) proposal, ok := govKeeper.GetProposal(ctx, proposalID) require.True(t, ok) @@ -74,7 +74,7 @@ func TestAddDeposits(t *testing.T) { votingStarted, err := govKeeper.AddDeposit(ctx, proposalID, addr1, amountDeposit1) require.NoError(t, err) require.False(t, votingStarted) - deposit, found = govKeeper.GetDeposit(ctx, proposalID, addr1) + deposit, found := govKeeper.GetDeposit(ctx, proposalID, addr1) require.True(t, found) require.Equal(t, amountDeposit1, sdk.NewCoins(deposit.Amount...)) require.Equal(t, addr1.String(), deposit.Depositor) @@ -233,7 +233,6 @@ func TestValidateInitialDeposit(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - params := v2lunc1.DefaultParams() params.MinDeposit = tc.minDeposit params.MinInitialDepositRatio = sdk.NewDec(tc.minInitialDepositPercent).Quo(sdk.NewDec(100)).String() diff --git a/custom/gov/keeper/grpc_query.go b/custom/gov/keeper/grpc_query.go index 1b8003eb..2a80bad4 100644 --- a/custom/gov/keeper/grpc_query.go +++ b/custom/gov/keeper/grpc_query.go @@ -15,7 +15,8 @@ var _ v2lunc1.QueryServer = queryServer{} func NewQueryServerImpl(k Keeper) v2lunc1.QueryServer { return queryServer{ k: k, - govQueryServer: govkeeper.NewLegacyQueryServer(k.Keeper)} + govQueryServer: govkeeper.NewLegacyQueryServer(k.Keeper), + } } type queryServer struct { diff --git a/custom/gov/keeper/grpc_query_test.go b/custom/gov/keeper/grpc_query_test.go index 54a3f1da..af1c14a4 100644 --- a/custom/gov/keeper/grpc_query_test.go +++ b/custom/gov/keeper/grpc_query_test.go @@ -1,55 +1,55 @@ package keeper_test - - import ( - "context" - "testing" - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/classic-terra/core/v3/custom/gov/types/v2lunc1" // Adjust the import path as necessary - "github.com/stretchr/testify/require" + "context" + "fmt" + "testing" + + "github.com/classic-terra/core/v3/custom/gov/types/v2lunc1" // Adjust the import path as necessary + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" ) // MockQueryServer is a mock implementation of the v2lunc1.QueryServer interface type MockQueryServer struct { - // You can store any state needed for the mock here - ProposalResponse *v2lunc1.QueryMinimalDepositProposalResponse - Err error + // You can store any state needed for the mock here + ProposalResponse *v2lunc1.QueryMinimalDepositProposalResponse + Err error } // ProposalMinimalLUNCByUusd implements the v2lunc1.QueryServer interface -func (m *MockQueryServer) ProposalMinimalLUNCByUusd(ctx context.Context, req *v2lunc1.QueryProposalRequest) (*v2lunc1.QueryMinimalDepositProposalResponse, error) { - if m.Err != nil { - return nil, m.Err - } - return m.ProposalResponse, nil +func (m *MockQueryServer) ProposalMinimalLUNCByUusd(_ context.Context, _ *v2lunc1.QueryProposalRequest) (*v2lunc1.QueryMinimalDepositProposalResponse, error) { + if m.Err != nil { + return nil, m.Err + } + return m.ProposalResponse, nil } // Test your keeper logic with the mock func TestKeeperWithMockQueryServer(t *testing.T) { -mockQueryServer := &MockQueryServer{ - ProposalResponse: &v2lunc1.QueryMinimalDepositProposalResponse{ - //MinimalDeposit: sdk.Coin{sdk.NewCoin("uusd", sdk.NewInt(1000))}, - MinimalDeposit: sdk.NewCoin("uusd", sdk.NewInt(1000)), - }, + mockQueryServer := &MockQueryServer{ + ProposalResponse: &v2lunc1.QueryMinimalDepositProposalResponse{ + // MinimalDeposit: sdk.Coin{sdk.NewCoin("uusd", sdk.NewInt(1000))}, + MinimalDeposit: sdk.NewCoin("uusd", sdk.NewInt(1000)), + }, + } + + // Create your context and other setup logic as needed + + t.Run("successful query", func(t *testing.T) { + req := &v2lunc1.QueryProposalRequest{ProposalId: 1} + res, err := mockQueryServer.ProposalMinimalLUNCByUusd(context.Background(), req) + require.NoError(t, err) + require.NotNil(t, res) + require.Equal(t, sdk.NewInt(1000), res.MinimalDeposit.Amount) + }) + + t.Run("error when querying proposal", func(t *testing.T) { + mockQueryServer.Err = fmt.Errorf("proposal not found") + req := &v2lunc1.QueryProposalRequest{ProposalId: 1} + _, err := mockQueryServer.ProposalMinimalLUNCByUusd(context.Background(), req) + require.Error(t, err) + require.Equal(t, "proposal not found", err.Error()) + }) } - // Create your context and other setup logic as needed - - t.Run("successful query", func(t *testing.T) { - req := &v2lunc1.QueryProposalRequest{ProposalId: 1} - res, err := mockQueryServer.ProposalMinimalLUNCByUusd(context.Background(), req) - require.NoError(t, err) - require.NotNil(t, res) - require.Equal(t, sdk.NewInt(1000), res.MinimalDeposit.Amount) - }) - - t.Run("error when querying proposal", func(t *testing.T) { - mockQueryServer.Err = fmt.Errorf("proposal not found") - req := &v2lunc1.QueryProposalRequest{ProposalId: 1} - _, err := mockQueryServer.ProposalMinimalLUNCByUusd(context.Background(), req) - require.Error(t, err) - require.Equal(t, "proposal not found", err.Error()) - }) -} diff --git a/custom/gov/keeper/migrator.go b/custom/gov/keeper/migrator.go index 78921c53..e0e00a6c 100644 --- a/custom/gov/keeper/migrator.go +++ b/custom/gov/keeper/migrator.go @@ -1,12 +1,12 @@ package keeper import ( + v5 "github.com/classic-terra/core/v3/custom/gov/migrations/v5" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/exported" v2 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v2" v3 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v3" v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4" - v5 "github.com/classic-terra/core/v3/custom/gov/migrations/v5" ) // Migrator is a struct for handling in-place store migrations. @@ -41,4 +41,4 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error { // Migrate4to5 migrates from version 4 to 5. func (m Migrator) Migrate4to5(ctx sdk.Context) error { return v5.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc) -} \ No newline at end of file +} diff --git a/custom/gov/keeper/migrator_test.go b/custom/gov/keeper/migrator_test.go index a3cfda3b..e6f046b0 100644 --- a/custom/gov/keeper/migrator_test.go +++ b/custom/gov/keeper/migrator_test.go @@ -3,38 +3,32 @@ package keeper_test import ( "testing" - //"github.com/cosmos/cosmos-sdk/x/gov/exported" + // "github.com/cosmos/cosmos-sdk/x/gov/exported" sdk "github.com/cosmos/cosmos-sdk/types" - //"github.com/cosmos/cosmos-sdk/x/gov/keeper" - "github.com/classic-terra/core/v3/custom/gov/keeper" + // "github.com/cosmos/cosmos-sdk/x/gov/keeper" + "github.com/classic-terra/core/v3/custom/gov/keeper" "github.com/stretchr/testify/require" - ) // MockParamSubspace is a mock implementation of ParamSubspace for testing. type MockParamSubspace struct{} - // Satisfy the ParamSubspace interface by adding dummy methods. -func (m MockParamSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) {} - +func (m MockParamSubspace) Get(_ sdk.Context, _ []byte, _ interface{}) {} // TestNewMigrator tests the NewMigrator constructor func TestNewMigrator(t *testing.T) { - - - // Create a keeper - mockKeeper := &keeper.Keeper{} - // mockKeeper := &keeper.Keeper{} - t.Logf("mockKeeper: %v", mockKeeper) - - // Use the mock ParamSubspace - mockSubspace := MockParamSubspace{} - t.Logf("mockSubspace: %v", mockSubspace) - - migrator := keeper.NewMigrator(mockKeeper, mockSubspace) - require.NotNil(t, migrator) - } - + // Create a keeper + mockKeeper := &keeper.Keeper{} + // mockKeeper := &keeper.Keeper{} + t.Logf("mockKeeper: %v", mockKeeper) + + // Use the mock ParamSubspace + mockSubspace := MockParamSubspace{} + t.Logf("mockSubspace: %v", mockSubspace) + + migrator := keeper.NewMigrator(mockKeeper, mockSubspace) + require.NotNil(t, migrator) +} diff --git a/custom/gov/keeper/msg_server_test.go b/custom/gov/keeper/msg_server_test.go index 82e64dbf..66588ac7 100644 --- a/custom/gov/keeper/msg_server_test.go +++ b/custom/gov/keeper/msg_server_test.go @@ -1,14 +1,13 @@ package keeper import ( + "strings" + "testing" "time" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/stretchr/testify/require" - "strings" - "testing" - sdk "github.com/cosmos/cosmos-sdk/types" v2lunc1types "github.com/classic-terra/core/v3/custom/gov/types/v2lunc1" @@ -21,11 +20,11 @@ import ( ) const ( - baseDepositTestAmount = 100 + // baseDepositTestAmount = 100 + testQuorumABC = "abc" + testQuorumNeg01 = "-0.1" ) -var () - func TestSubmitProposalReq(t *testing.T) { // Set up the necessary dependencies and context input := CreateTestInput(t) @@ -193,8 +192,8 @@ func TestVoteReq(t *testing.T) { res, err := govMsgSvr.SubmitProposal(ctx, msg) require.NoError(t, err) require.NotNil(t, res.ProposalId) - proposalId := res.ProposalId - requiredAmount := govKeeper.GetDepositLimitBaseUusd(ctx, proposalId) + proposalID := res.ProposalId + requiredAmount := govKeeper.GetDepositLimitBaseUusd(ctx, proposalID) cases := map[string]struct { preRun func() uint64 @@ -230,11 +229,11 @@ func TestVoteReq(t *testing.T) { "metadata too long": { preRun: func() uint64 { // set proposal to status activedVoting - proposal, ok := govKeeper.GetProposal(ctx, proposalId) + proposal, ok := govKeeper.GetProposal(ctx, proposalID) require.True(t, ok) proposal.Status = v1.StatusVotingPeriod govKeeper.SetProposal(ctx, proposal) - return proposalId + return proposalID }, option: v1.VoteOption_VOTE_OPTION_YES, voter: proposer, @@ -244,7 +243,7 @@ func TestVoteReq(t *testing.T) { }, "voter error": { preRun: func() uint64 { - return proposalId + return proposalID }, option: v1.VoteOption_VOTE_OPTION_YES, voter: sdk.AccAddress(strings.Repeat("a", 300)), @@ -284,10 +283,9 @@ func TestVoteReq(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { - - pId := tc.preRun() + pID := tc.preRun() FundAccount(input, addr, coins) - voteReq := v1.NewMsgVote(tc.voter, pId, tc.option, tc.metadata) + voteReq := v1.NewMsgVote(tc.voter, pID, tc.option, tc.metadata) _, err := govMsgSvr.Vote(ctx, voteReq) if tc.expErr { if err == nil { @@ -338,7 +336,7 @@ func TestVoteWeightedReq(t *testing.T) { res, err := govMsgSvr.SubmitProposal(ctx, msg) require.NoError(t, err) require.NotNil(t, res.ProposalId) - proposalId := res.ProposalId + proposalID := res.ProposalId // requiredAmount := suite.govKeeper.GetDepositLimitBaseUusd(suite.ctx, proposalId).TruncateInt() cases := map[string]struct { @@ -376,11 +374,11 @@ func TestVoteWeightedReq(t *testing.T) { "metadata too long": { preRun: func() uint64 { // set proposal to status activedVoting - proposal, ok := govKeeper.GetProposal(ctx, proposalId) + proposal, ok := govKeeper.GetProposal(ctx, proposalID) require.True(t, ok) proposal.Status = v1.StatusVotingPeriod govKeeper.SetProposal(ctx, proposal) - return proposalId + return proposalID }, option: v1.VoteOption_VOTE_OPTION_YES, voter: proposer, @@ -390,7 +388,7 @@ func TestVoteWeightedReq(t *testing.T) { }, "voter error": { preRun: func() uint64 { - return proposalId + return proposalID }, option: v1.VoteOption_VOTE_OPTION_YES, voter: sdk.AccAddress(strings.Repeat("a", 300)), @@ -429,9 +427,8 @@ func TestVoteWeightedReq(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { - - pId := tc.preRun() - voteReq := v1.NewMsgVoteWeighted(tc.voter, pId, v1.NewNonSplitVoteOption(tc.option), tc.metadata) + pID := tc.preRun() + voteReq := v1.NewMsgVoteWeighted(tc.voter, pID, v1.NewNonSplitVoteOption(tc.option), tc.metadata) _, err := govMsgSvr.VoteWeighted(ctx, voteReq) if tc.expErr { if err == nil { @@ -482,12 +479,12 @@ func TestDepositReq(t *testing.T) { res, err := govMsgSvr.SubmitProposal(ctx, msg) require.NoError(t, err) require.NotNil(t, res.ProposalId) - pId := res.ProposalId + pID := res.ProposalId cases := map[string]struct { preRun func() uint64 expErr bool - proposalId uint64 + proposalID uint64 depositor sdk.AccAddress deposit sdk.Coins options v1.WeightedVoteOptions @@ -503,7 +500,7 @@ func TestDepositReq(t *testing.T) { }, "all good": { preRun: func() uint64 { - return pId + return pID }, depositor: proposer, deposit: coins, @@ -514,9 +511,9 @@ func TestDepositReq(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { - proposalId := tc.preRun() + proposalID := tc.preRun() FundAccount(input, addr, coins) - depositReq := v1.NewMsgDeposit(tc.depositor, proposalId, tc.deposit) + depositReq := v1.NewMsgDeposit(tc.depositor, proposalID, tc.deposit) _, err := govMsgSvr.Deposit(ctx, depositReq) if tc.expErr { if err == nil { @@ -632,7 +629,7 @@ func TestMsgUpdateParams(t *testing.T) { name: "invalid quorum", input: func() *v2lunc1types.MsgUpdateParams { params1 := params - params1.Quorum = "abc" + params1.Quorum = testQuorumABC return &v2lunc1types.MsgUpdateParams{ Authority: authority, @@ -646,7 +643,7 @@ func TestMsgUpdateParams(t *testing.T) { name: "negative quorum", input: func() *v2lunc1types.MsgUpdateParams { params1 := params - params1.Quorum = "-0.1" + params1.Quorum = testQuorumNeg01 return &v2lunc1types.MsgUpdateParams{ Authority: authority, @@ -674,7 +671,7 @@ func TestMsgUpdateParams(t *testing.T) { name: "invalid threshold", input: func() *v2lunc1types.MsgUpdateParams { params1 := params - params1.Threshold = "abc" + params1.Threshold = testQuorumABC return &v2lunc1types.MsgUpdateParams{ Authority: authority, @@ -688,7 +685,7 @@ func TestMsgUpdateParams(t *testing.T) { name: "negative threshold", input: func() *v2lunc1types.MsgUpdateParams { params1 := params - params1.Threshold = "-0.1" + params1.Threshold = testQuorumNeg01 return &v2lunc1types.MsgUpdateParams{ Authority: authority, @@ -716,7 +713,7 @@ func TestMsgUpdateParams(t *testing.T) { name: "invalid veto threshold", input: func() *v2lunc1types.MsgUpdateParams { params1 := params - params1.VetoThreshold = "abc" + params1.VetoThreshold = testQuorumABC return &v2lunc1types.MsgUpdateParams{ Authority: authority, @@ -730,7 +727,7 @@ func TestMsgUpdateParams(t *testing.T) { name: "negative veto threshold", input: func() *v2lunc1types.MsgUpdateParams { params1 := params - params1.VetoThreshold = "-0.1" + params1.VetoThreshold = testQuorumNeg01 return &v2lunc1types.MsgUpdateParams{ Authority: authority, @@ -947,10 +944,8 @@ func TestLegacyMsgSubmitProposal(t *testing.T) { legacyMsgSrvr := NewLegacyMsgServerImpl(govAcct.String(), NewMsgServerImpl(input.GovKeeper)) for name, c := range cases { - t.Run(name, func(t *testing.T) { msg, err := c.preRun() - if err != nil { t.Fatalf("preRun error: %v", err) } @@ -1081,8 +1076,8 @@ func TestLegacyMsgVote(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { - pId := tc.preRun() - voteReq := v1beta1.NewMsgVote(tc.voter, pId, tc.option) + pID := tc.preRun() + voteReq := v1beta1.NewMsgVote(tc.voter, pID, tc.option) _, err := legacyMsgSrvr.Vote(ctx, voteReq) proposal.Status = v1.StatusVotingPeriod input.GovKeeper.SetProposal(ctx, proposal) @@ -1111,7 +1106,6 @@ func TestLegacyVoteWeighted(t *testing.T) { FundAccount(input, addr, coins) proposal, err := input.GovKeeper.SubmitProposal(ctx, []sdk.Msg{}, "", "Test Proposal", "This is a test proposal", proposer) - if err != nil { t.Fatalf("preRun error: %v", err) } @@ -1203,9 +1197,9 @@ func TestLegacyVoteWeighted(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { - pId := tc.preRun() + pID := tc.preRun() - voteReq := v1beta1.NewMsgVoteWeighted(tc.voter, pId, v1beta1.NewNonSplitVoteOption(v1beta1.VoteOption(tc.option))) + voteReq := v1beta1.NewMsgVoteWeighted(tc.voter, pID, v1beta1.NewNonSplitVoteOption(tc.option)) proposal.Status = v1.StatusVotingPeriod input.GovKeeper.SetProposal(ctx, proposal) _, err := legacyMsgSrvr.VoteWeighted(ctx, voteReq) @@ -1240,7 +1234,7 @@ func TestLegacyMsgDeposit(t *testing.T) { cases := map[string]struct { preRun func() uint64 expErr bool - proposalId uint64 + proposalID uint64 depositor sdk.AccAddress deposit sdk.Coins options v1beta1.WeightedVoteOptions @@ -1269,8 +1263,8 @@ func TestLegacyMsgDeposit(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { - proposalId := tc.preRun() - depositReq := v1beta1.NewMsgDeposit(tc.depositor, proposalId, tc.deposit) + proposalID := tc.preRun() + depositReq := v1beta1.NewMsgDeposit(tc.depositor, proposalID, tc.deposit) _, err := legacyMsgSrvr.Deposit(ctx, depositReq) if tc.expErr { require.Error(t, err) diff --git a/custom/gov/keeper/proposal.go b/custom/gov/keeper/proposal.go index 47da3fc8..5de652ed 100644 --- a/custom/gov/keeper/proposal.go +++ b/custom/gov/keeper/proposal.go @@ -15,7 +15,6 @@ import ( // SubmitProposal creates a new proposal given an array of messages func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadata, title, summary string, proposer sdk.AccAddress) (v1.Proposal, error) { err := keeper.assertMetadataLength(metadata) - if err != nil { return v1.Proposal{}, err } @@ -69,7 +68,7 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadat if msg, ok := msg.(*v1.MsgExecLegacyContent); ok { cacheCtx, _ := ctx.CacheContext() if _, err := handler(cacheCtx, msg); err != nil { - if errors.Is(types.ErrNoProposalHandlerExists, err) { + if errors.Is(err, types.ErrNoProposalHandlerExists) { return v1.Proposal{}, err } return v1.Proposal{}, sdkerrors.Wrap(types.ErrInvalidProposalContent, err.Error()) diff --git a/custom/gov/keeper/proposal_test.go b/custom/gov/keeper/proposal_test.go index 8c03609f..29f7b37b 100644 --- a/custom/gov/keeper/proposal_test.go +++ b/custom/gov/keeper/proposal_test.go @@ -56,7 +56,6 @@ func TestGetSetProposal(t *testing.T) { minLunaAmount := govKeeper.GetDepositLimitBaseUusd(ctx, proposalID) fmt.Printf("minLunaAmount %s\n", minLunaAmount) require.Equal(t, totalLuncMinDeposit, minLunaAmount) - } func TestDeleteProposal(t *testing.T) { diff --git a/custom/gov/migrations/v5/store_test.go b/custom/gov/migrations/v5/store_test.go index 5c0381a8..e322811d 100644 --- a/custom/gov/migrations/v5/store_test.go +++ b/custom/gov/migrations/v5/store_test.go @@ -33,8 +33,8 @@ func TestMigrateStore(t *testing.T) { storeService := storetypes.StoreKey(govKey) - maxDepositPeriod := time.Duration(time.Hour * 24 * 2) - votingPeriod := time.Duration(time.Hour * 24 * 3) + maxDepositPeriod := (time.Hour * 24 * 2) + votingPeriod := (time.Hour * 24 * 3) // Setup initial governance params in the store (old params before migration) oldParams := v1.Params{ @@ -88,5 +88,4 @@ func TestMigrateStore(t *testing.T) { // Check any new fields from the `v2lunc1.Params` require.Equal(t, v2lunc1.DefaultParams().MinUusdDeposit, newParams.MinUusdDeposit) - } diff --git a/custom/gov/module.go b/custom/gov/module.go index a0960124..b9810d38 100644 --- a/custom/gov/module.go +++ b/custom/gov/module.go @@ -89,7 +89,7 @@ func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) // DefaultGenesis returns default genesis state as raw bytes for the gov // module. -func (am AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { +func (a AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { // customize to set default genesis state deposit denom to uluna defaultGenesisState := v2lunc1.DefaultGenesisState() defaultGenesisState.Params.MinDeposit[0].Denom = core.MicroLunaDenom @@ -98,7 +98,7 @@ func (am AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { } // ValidateGenesis performs genesis state validation for the gov module. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { var data v2lunc1.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", govtypes.ModuleName, err) @@ -216,12 +216,12 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { // ProposalContents returns all the gov content functions used to // simulate governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { //nolint:staticcheck +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { return simulation.ProposalContents() } // ProposalMsgs returns all the gov msgs used to simulate governance proposals. -func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { +func (AppModule) ProposalMsgs(_ module.SimulationState) []simtypes.WeightedProposalMsg { return simulation.ProposalMsgs() } diff --git a/custom/gov/types/v2lunc1/genesis.go b/custom/gov/types/v2lunc1/genesis.go index 006ae2fb..d11f7d80 100644 --- a/custom/gov/types/v2lunc1/genesis.go +++ b/custom/gov/types/v2lunc1/genesis.go @@ -43,33 +43,33 @@ func ValidateGenesis(data *GenesisState) error { var errGroup errgroup.Group // weed out duplicate proposals - proposalIds := make(map[uint64]struct{}) + proposalIDs := make(map[uint64]struct{}) for _, p := range data.Proposals { - if _, ok := proposalIds[p.Id]; ok { + if _, ok := proposalIDs[p.Id]; ok { return fmt.Errorf("duplicate proposal id: %d", p.Id) } - proposalIds[p.Id] = struct{}{} + proposalIDs[p.Id] = struct{}{} } // weed out duplicate deposits errGroup.Go(func() error { type depositKey struct { - ProposalId uint64 + ProposalID uint64 Depositor string } - depositIds := make(map[depositKey]struct{}) + depositIDs := make(map[depositKey]struct{}) for _, d := range data.Deposits { - if _, ok := proposalIds[d.ProposalId]; !ok { + if _, ok := proposalIDs[d.ProposalId]; !ok { return fmt.Errorf("deposit %v has non-existent proposal id: %d", d, d.ProposalId) } dk := depositKey{d.ProposalId, d.Depositor} - if _, ok := depositIds[dk]; ok { + if _, ok := depositIDs[dk]; ok { return fmt.Errorf("duplicate deposit: %v", d) } - depositIds[dk] = struct{}{} + depositIDs[dk] = struct{}{} } return nil @@ -78,21 +78,21 @@ func ValidateGenesis(data *GenesisState) error { // weed out duplicate votes errGroup.Go(func() error { type voteKey struct { - ProposalId uint64 + ProposalID uint64 Voter string } - voteIds := make(map[voteKey]struct{}) + voteIDs := make(map[voteKey]struct{}) for _, v := range data.Votes { - if _, ok := proposalIds[v.ProposalId]; !ok { + if _, ok := proposalIDs[v.ProposalId]; !ok { return fmt.Errorf("vote %v has non-existent proposal id: %d", v, v.ProposalId) } vk := voteKey{v.ProposalId, v.Voter} - if _, ok := voteIds[vk]; ok { + if _, ok := voteIDs[vk]; ok { return fmt.Errorf("duplicate vote: %v", v) } - voteIds[vk] = struct{}{} + voteIDs[vk] = struct{}{} } return nil