Skip to content

Commit

Permalink
fixed golangci-lint-Related Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ntluongdev95 committed Oct 30, 2024
1 parent 6e3a28c commit 30c7ccc
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 249 deletions.
6 changes: 3 additions & 3 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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)),
Expand Down
60 changes: 30 additions & 30 deletions custom/gov/client/cli/init_test.go
Original file line number Diff line number Diff line change
@@ -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")
}

}
2 changes: 1 addition & 1 deletion custom/gov/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 34 additions & 33 deletions custom/gov/client/cli/query_test.go
Original file line number Diff line number Diff line change
@@ -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))
})
}
}
s.Run(tc.name, func() {
cmd := v2lunc1cli.GetCmdQueryMinimalDeposit()
cmd.SetArgs(tc.args)
s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput))
})
}
}
100 changes: 50 additions & 50 deletions custom/gov/client/cli/util.go
Original file line number Diff line number Diff line change
@@ -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
// }
5 changes: 2 additions & 3 deletions custom/gov/keeper/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion custom/gov/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 30c7ccc

Please sign in to comment.