Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a lot of linting issues. #1982

Merged
merged 7 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ linters-settings:

- github.com/armon/go-metrics

- cosmossdk.io/client/v2/autocli
- cosmossdk.io/core
- cosmossdk.io/errors
- cosmossdk.io/log
Expand Down Expand Up @@ -119,6 +120,8 @@ linters-settings:

- github.com/cosmos/gogoproto

- github.com/golang/protobuf/proto

- github.com/google/uuid

- github.com/gorilla/mux
Expand Down Expand Up @@ -155,6 +158,8 @@ linters-settings:
- github.com/cometbft/cometbft-db

- github.com/rs/zerolog

- sigs.k8s.io/yaml
test:
files:
- "$test"
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ install: go.sum
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install $(BUILD_FLAGS) ./cmd/provenanced

build: validate-go-version go.sum
# TODO[1760]: Remove this delay once we're stable again.
@if [ -z "${ACK_50}" ]; then printf '\033[93mWARNING:\033[0m This branch is currently unstable and should not be built for use.\n To bypass this 10 second delay: ACK_50=1 make build\n'; sleep 10; fi
mkdir -p $(BUILDDIR)
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -o $(BUILDDIR)/ $(BUILD_FLAGS) ./cmd/provenanced

Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ func New(
sanction.ModuleName,
hold.ModuleName,
exchange.ModuleName,
consensusparamtypes.ModuleName, // TODO[1760]: Is this the correct placement?
consensusparamtypes.ModuleName,

ibcratelimit.ModuleName,
ibchookstypes.ModuleName,
Expand Down
1 change: 1 addition & 0 deletions cmd/provenanced/cmd/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/provenance-io/provenance/x/exchange"
exchangecli "github.com/provenance-io/provenance/x/exchange/client/cli"
markercli "github.com/provenance-io/provenance/x/marker/client/cli"
Expand Down Expand Up @@ -609,7 +610,7 @@
return err
}

_, ok := msg.(sdk.Msg)

Check failure on line 613 in cmd/provenanced/cmd/genesis.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1040: type assertion to the same type: msg already has type sdk.Msg (gosimple)
if !ok {
return fmt.Errorf("message type is not a sdk message: %v", msgTypeURL)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/provenanced/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"

"github.com/provenance-io/provenance/app"
"github.com/provenance-io/provenance/app/params"
"github.com/provenance-io/provenance/cmd/provenanced/config"
Expand Down
1 change: 1 addition & 0 deletions cmd/provenanced/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func WriteConfigToFile(configFilePath string, config *ClientConfig) {
panic(err)
}

//nolint:gosec // The config file should be readable by anyone.
if err := os.WriteFile(configFilePath, buffer.Bytes(), 0o644); err != nil {
panic(err)
}
Expand Down
10 changes: 3 additions & 7 deletions internal/handlers/msg_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (msr *PioMsgServiceRouter) registerHybridHandler(sd *grpc.ServiceDesc, meth
return nil
}

func (msr *PioMsgServiceRouter) registerMsgServiceHandler(sd *grpc.ServiceDesc, method grpc.MethodDesc, handler interface{}) error {
func (msr *PioMsgServiceRouter) registerMsgServiceHandler(sd *grpc.ServiceDesc, method grpc.MethodDesc, handler interface{}) {
fqMethod := fmt.Sprintf("/%s/%s", sd.ServiceName, method.MethodName)
methodHandler := method.Handler

Expand Down Expand Up @@ -201,7 +201,6 @@ func (msr *PioMsgServiceRouter) registerMsgServiceHandler(sd *grpc.ServiceDesc,

return sdk.WrapServiceResult(ctx, resMsg, err)
}
return nil
}

// RegisterService implements the gRPC Server.RegisterService method. sd is a gRPC
Expand All @@ -214,11 +213,8 @@ func (msr *PioMsgServiceRouter) registerMsgServiceHandler(sd *grpc.ServiceDesc,
func (msr *PioMsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler interface{}) {
// Adds a top-level query handler based on the gRPC service name.
for _, method := range sd.Methods {
err := msr.registerMsgServiceHandler(sd, method, handler)
if err != nil {
panic(err)
}
err = msr.registerHybridHandler(sd, method, handler)
msr.registerMsgServiceHandler(sd, method, handler)
err := msr.registerHybridHandler(sd, method, handler)
if err != nil {
panic(err)
}
Expand Down
55 changes: 28 additions & 27 deletions testutil/cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
sdkcli "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"

Taztingo marked this conversation as resolved.
Show resolved Hide resolved
"github.com/provenance-io/provenance/testutil/assertions"
"github.com/provenance-io/provenance/testutil/queries"
)

// CLITxExecutor helps facilitate the execution and testing of a CLI command.
// TxExecutor helps facilitate the execution and testing of a CLI command.
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
//
// The command will be executed when either .Execute() or .AssertExecute() are called.
// The former will halt the test upon failure, the latter will allow test execution to continue.
Expand All @@ -26,9 +27,9 @@ import (
//
// The result code and raw log are only checked if a Tx result is available.
// It's considered a failure if the command did not return an error, but the Tx result is not available.
type CLITxExecutor struct {
type TxExecutor struct {
// Name is the name of the test. It's not actually used in here, but included
// in case you want to use []CLITxExecutor to define your test cases.
// in case you want to use []TxExecutor to define your test cases.
Name string
// Cmd is the cobra.Command to execute.
Cmd *cobra.Command
Expand Down Expand Up @@ -56,64 +57,64 @@ type CLITxExecutor struct {
ExpInRawLog []string
}

// NewCLITxExecutor creates a new CLITxExecutor with the provided command and args.
func NewCLITxExecutor(cmd *cobra.Command, args []string) CLITxExecutor {
return CLITxExecutor{
// NewTxExecutor creates a new TxExecutor with the provided command and args.
func NewTxExecutor(cmd *cobra.Command, args []string) TxExecutor {
return TxExecutor{
Cmd: cmd,
Args: args,
}
}

// WithName returns a copy of this CLITxExecutor that has the provided Name.
func (c CLITxExecutor) WithName(name string) CLITxExecutor {
// WithName returns a copy of this TxExecutor that has the provided Name.
func (c TxExecutor) WithName(name string) TxExecutor {
c.Name = name
return c
}

// WithCmd returns a copy of this CLITxExecutor that has the provided Cmd.
func (c CLITxExecutor) WithCmd(cmd *cobra.Command) CLITxExecutor {
// WithCmd returns a copy of this TxExecutor that has the provided Cmd.
func (c TxExecutor) WithCmd(cmd *cobra.Command) TxExecutor {
c.Cmd = cmd
return c
}

// WithArgs returns a copy of this CLITxExecutor that has the provided Args.
func (c CLITxExecutor) WithArgs(args []string) CLITxExecutor {
// WithArgs returns a copy of this TxExecutor that has the provided Args.
func (c TxExecutor) WithArgs(args []string) TxExecutor {
c.Args = args
return c
}

// WithExpErr returns a copy of this CLITxExecutor that has the provided ExpErr.
func (c CLITxExecutor) WithExpErr(expErr bool) CLITxExecutor {
// WithExpErr returns a copy of this TxExecutor that has the provided ExpErr.
func (c TxExecutor) WithExpErr(expErr bool) TxExecutor {
c.ExpErr = expErr
return c
}

// WithExpErrMsg returns a copy of this CLITxExecutor that has the provided ExpErrMsg.
func (c CLITxExecutor) WithExpErrMsg(expErrMsg string) CLITxExecutor {
// WithExpErrMsg returns a copy of this TxExecutor that has the provided ExpErrMsg.
func (c TxExecutor) WithExpErrMsg(expErrMsg string) TxExecutor {
c.ExpErrMsg = expErrMsg
return c
}

// WithExpInErrMsg returns a copy of this CLITxExecutor that has the provided ExpInErrMsg.
func (c CLITxExecutor) WithExpInErrMsg(expInErrMsg []string) CLITxExecutor {
// WithExpInErrMsg returns a copy of this TxExecutor that has the provided ExpInErrMsg.
func (c TxExecutor) WithExpInErrMsg(expInErrMsg []string) TxExecutor {
c.ExpInErrMsg = expInErrMsg
return c
}

// WithExpCode returns a copy of this CLITxExecutor that has the provided ExpCode.
func (c CLITxExecutor) WithExpCode(expCode uint32) CLITxExecutor {
// WithExpCode returns a copy of this TxExecutor that has the provided ExpCode.
func (c TxExecutor) WithExpCode(expCode uint32) TxExecutor {
c.ExpCode = expCode
return c
}

// WithExpRawLog returns a copy of this CLITxExecutor that has the provided ExpRawLog.
func (c CLITxExecutor) WithExpRawLog(expRawLog string) CLITxExecutor {
// WithExpRawLog returns a copy of this TxExecutor that has the provided ExpRawLog.
func (c TxExecutor) WithExpRawLog(expRawLog string) TxExecutor {
c.ExpRawLog = expRawLog
return c
}

// WithExpInRawLog returns a copy of this CLITxExecutor that has the provided ExpInRawLog.
func (c CLITxExecutor) WithExpInRawLog(expInRawLog []string) CLITxExecutor {
// WithExpInRawLog returns a copy of this TxExecutor that has the provided ExpInRawLog.
func (c TxExecutor) WithExpInRawLog(expInRawLog []string) TxExecutor {
c.ExpInRawLog = expInRawLog
return c
}
Expand All @@ -123,7 +124,7 @@ func (c CLITxExecutor) WithExpInRawLog(expInRawLog []string) CLITxExecutor {
// It is possible for everything to be as expected, and still get a nil TxResponse from this.
//
// To allow test execution to continue on a failure, use AssertExecute.
func (c CLITxExecutor) Execute(t *testing.T, n *network.Network) *sdk.TxResponse {
func (c TxExecutor) Execute(t *testing.T, n *network.Network) *sdk.TxResponse {
t.Helper()
rv, ok := c.AssertExecute(t, n)
if !ok {
Expand All @@ -138,9 +139,9 @@ func (c CLITxExecutor) Execute(t *testing.T, n *network.Network) *sdk.TxResponse
// The returned bool is true if everything is as expected, false otherwise.
//
// To halt test execution on failure, use Execute.
func (c CLITxExecutor) AssertExecute(t *testing.T, n *network.Network) (*sdk.TxResponse, bool) {
func (c TxExecutor) AssertExecute(t *testing.T, n *network.Network) (*sdk.TxResponse, bool) {
t.Helper()
if !assert.NotNil(t, c.Cmd, "CLITxExecutor.Cmd cannot be nil") {
if !assert.NotNil(t, c.Cmd, "TxExecutor.Cmd cannot be nil") {
return nil, false
}
if !assert.NotEmpty(t, n.Validators, "Network.Validators") {
Expand Down
2 changes: 1 addition & 1 deletion testutil/ibc/testchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (chain *TestChain) commitBlock(suite *suite.Suite, res *abci.ResponseFinali
// from ibctesting
func SignAndDeliver(
txCfg client.TxConfig, app *baseapp.BaseApp, msgs []sdk.Msg,
chainID string, accNums, accSeqs []uint64, expPass bool, blockTime time.Time, nextValHash []byte, priv ...cryptotypes.PrivKey,
chainID string, accNums, accSeqs []uint64, _ bool, blockTime time.Time, nextValHash []byte, priv ...cryptotypes.PrivKey,
) (*abci.ResponseFinalizeBlock, error) {
// tb.Helper()
tx, err := simtestutil.GenSignedMockTx(
Expand Down
2 changes: 1 addition & 1 deletion testutil/queries/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func createQueryCmd[T proto.Message](n *network.Network, cmdName, url string, em
Use: "generic-" + cmdName,
Args: cobra.NoArgs,
SilenceUsage: true,
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
10 changes: 5 additions & 5 deletions x/attribute/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ func (s *IntegrationTestSuite) TestAttributeTxCommands() {

for _, tc := range testCases {
s.Run(tc.name, func() {
testcli.NewCLITxExecutor(tc.cmd, tc.args).
testcli.NewTxExecutor(tc.cmd, tc.args).
WithExpErr(tc.expectErr).
WithExpCode(tc.expectedCode).
Execute(s.T(), s.testnet)
Expand Down Expand Up @@ -1017,7 +1017,7 @@ func (s *IntegrationTestSuite) TestUpdateAccountAttributeTxCommands() {

for _, tc := range testCases {
s.Run(tc.name, func() {
testcli.NewCLITxExecutor(tc.cmd, tc.args).
testcli.NewTxExecutor(tc.cmd, tc.args).
WithExpErr(tc.expectErr).
WithExpCode(tc.expectedCode).
Execute(s.T(), s.testnet)
Expand Down Expand Up @@ -1122,7 +1122,7 @@ func (s *IntegrationTestSuite) TestDeleteDistinctAccountAttributeTxCommands() {

for _, tc := range testCases {
s.Run(tc.name, func() {
testcli.NewCLITxExecutor(tc.cmd, tc.args).
testcli.NewTxExecutor(tc.cmd, tc.args).
WithExpErr(tc.expectErr).
WithExpCode(tc.expectedCode).
Execute(s.T(), s.testnet)
Expand Down Expand Up @@ -1206,7 +1206,7 @@ func (s *IntegrationTestSuite) TestDeleteAccountAttributeTxCommands() {

for _, tc := range testCases {
s.Run(tc.name, func() {
testcli.NewCLITxExecutor(tc.cmd, tc.args).
testcli.NewTxExecutor(tc.cmd, tc.args).
WithExpErr(tc.expectErr).
WithExpCode(tc.expectedCode).
Execute(s.T(), s.testnet)
Expand Down Expand Up @@ -1519,7 +1519,7 @@ func (s *IntegrationTestSuite) TestUpdateAccountAttributeExpirationCmd() {

for _, tc := range testCases {
s.Run(tc.name, func() {
testcli.NewCLITxExecutor(tc.cmd, tc.args).
testcli.NewTxExecutor(tc.cmd, tc.args).
WithExpErrMsg(tc.expectErr).
WithExpCode(tc.expectedCode).
Execute(s.T(), s.testnet)
Expand Down
10 changes: 2 additions & 8 deletions x/attribute/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,8 @@ func (k Keeper) IterateRecords(ctx sdk.Context, prefix []byte, handle Handler) e
for ; iterator.Valid(); iterator.Next() {
record := types.Attribute{}
// get proto objects for legacy prefix with legacy amino codec.
if bytes.Equal(types.AttributeKeyPrefixAmino, prefix) {
if err := k.cdc.Unmarshal(iterator.Value(), &record); err != nil {
return err
}
} else {
if err := k.cdc.Unmarshal(iterator.Value(), &record); err != nil {
return err
}
if err := k.cdc.Unmarshal(iterator.Value(), &record); err != nil {
return err
}
if err := handle(record); err != nil {
return err
Expand Down
6 changes: 0 additions & 6 deletions x/attribute/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}

// ProposalContents returns all the attribute content functions used to
// simulate attribute governance proposals.
func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return simulation.ProposalContents(am.keeper)
}

// RandomizedParams creates randomized attribute param changes for the simulator.
func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.LegacyParamChange {
return simulation.ParamChanges(r)
Expand Down
12 changes: 0 additions & 12 deletions x/attribute/simulation/proposals.go

This file was deleted.

10 changes: 5 additions & 5 deletions x/exchange/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func (s *CmdTestSuite) runTxCmdTestCase(tc txCmdTestCase) {
}

var cmdOk bool
txResponse, cmdOk = testcli.NewCLITxExecutor(cmd, args).
txResponse, cmdOk = testcli.NewTxExecutor(cmd, args).
WithExpInErrMsg(tc.expInErr).
WithExpCode(tc.expectedCode).
WithExpInRawLog(tc.expInRawLog).
Expand Down Expand Up @@ -1028,7 +1028,7 @@ func (s *CmdTestSuite) createOrder(order *exchange.Order, creationFee *sdk.Coin)
"--"+flags.FlagSkipConfirmation,
)

resp := testcli.NewCLITxExecutor(cmd, args).Execute(s.T(), s.testnet)
resp := testcli.NewTxExecutor(cmd, args).Execute(s.T(), s.testnet)
s.Require().NotNil(resp, "TxResponse from creating order")
orderIDStr, err := s.findNewOrderID(resp)
s.Require().NoError(err, "findNewOrderID")
Expand All @@ -1055,7 +1055,7 @@ func (s *CmdTestSuite) commitFunds(addr sdk.AccAddress, marketID uint32, amount
"--"+flags.FlagSkipConfirmation,
)

testcli.NewCLITxExecutor(cmd, args).Execute(s.T(), s.testnet)
testcli.NewTxExecutor(cmd, args).Execute(s.T(), s.testnet)
}

// createPayment issues a command to create a payment.
Expand Down Expand Up @@ -1084,7 +1084,7 @@ func (s *CmdTestSuite) createPayment(payment *exchange.Payment) {
"--"+flags.FlagSkipConfirmation,
)

testcli.NewCLITxExecutor(cmd, args).Execute(s.T(), s.testnet)
testcli.NewTxExecutor(cmd, args).Execute(s.T(), s.testnet)
}

// queryBankBalances executes a bank query to get an account's balances.
Expand All @@ -1107,7 +1107,7 @@ func (s *CmdTestSuite) execBankSend(fromAddr, toAddr, amount string) {
"--" + flags.FlagBroadcastMode, flags.BroadcastSync,
"--" + flags.FlagSkipConfirmation,
}
testcli.NewCLITxExecutor(cmd, args).Execute(s.T(), s.testnet)
testcli.NewTxExecutor(cmd, args).Execute(s.T(), s.testnet)
}

// untypeEvent calls untypeEvent and requires it to not return an error.
Expand Down
6 changes: 0 additions & 6 deletions x/exchange/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ func (am AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}

// ProposalContents returns all the exchange content functions used to
// simulate governance proposals, of which there are none for the exchange module.
func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}

// RandomizedParams returns randomized exchange param changes for the simulator,
// of which there are none since this module doesn't use the params module.
func (AppModule) RandomizedParams(_ *rand.Rand) []simtypes.LegacyParamChange { return nil }
Expand Down
Loading
Loading