Skip to content

Commit

Permalink
comply with golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Apr 29, 2023
1 parent 8ee0735 commit 6fa6429
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 70 deletions.
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/spf13/cast"

errorsmod "cosmossdk.io/errors"
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -122,16 +123,16 @@ func SetAddressPrefixes() {
// source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141
config.SetAddressVerifier(func(bytes []byte) error {
if len(bytes) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
return errorsmod.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
}

if len(bytes) > address.MaxAddrLen {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
}

// TODO: Do we want to allow addresses of lengths other than 20 and 32 bytes?
if len(bytes) != 20 && len(bytes) != 32 {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
}

return nil
Expand Down Expand Up @@ -251,7 +252,6 @@ func New(
bApp,
legacyAmino,
keepers.GetMaccPerms(),
app.ModuleAccountAddrs(),
enabledProposals,
appOpts,
wasmOpts,
Expand Down
7 changes: 4 additions & 3 deletions app/decorators/min_commission.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package decorators

import (
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -35,7 +36,7 @@ func (min MinCommissionDecorator) AnteHandle(
// commission set below 5%
c := msg.Commission
if c.Rate.LT(minCommissionRate) {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%")
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%")
}
case *stakingtypes.MsgEditValidator:
// if commission rate is nil, it means only
Expand All @@ -44,7 +45,7 @@ func (min MinCommissionDecorator) AnteHandle(
break
}
if msg.CommissionRate.LT(minCommissionRate) {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%")
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%")
}
}

Expand All @@ -56,7 +57,7 @@ func (min MinCommissionDecorator) AnteHandle(
var innerMsg sdk.Msg
err := min.cdc.UnpackAny(v, &innerMsg)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "cannot unmarshal authz exec msgs")
return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "cannot unmarshal authz exec msgs")
}

err = validMsg(innerMsg)
Expand Down
15 changes: 11 additions & 4 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,21 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.AppKeepers.DistrKeeper.SetFeePool(ctx, feePool)

app.AppKeepers.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
return false
err := app.AppKeepers.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())

return err != nil
})

// reinitialize all delegations
for _, del := range dels {
app.AppKeepers.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
app.AppKeepers.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
err := app.AppKeepers.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
if err != nil {
panic(err)
}
err = app.AppKeepers.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
if err != nil {
panic(err)
}
}

// reset context height
Expand Down
1 change: 0 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ func NewAppKeepers(
bApp *baseapp.BaseApp,
cdc *codec.LegacyAmino,
maccPerms map[string][]string,
blockedAddress map[string]bool,
enabledProposals []wasm.ProposalType,
appOpts servertypes.AppOptions,
wasmOpts []wasm.Option,
Expand Down
4 changes: 2 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func Setup(t *testing.T) *App {
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *App {
t.Helper()

junoApp, genesisState := setup(true, 5)
junoApp, genesisState := setup(true)
genesisState = genesisStateWithValSet(t, junoApp, genesisState, valSet, genAccs, balances...)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand All @@ -119,7 +119,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
return junoApp
}

func setup(withGenesis bool, invCheckPeriod uint) (*App, GenesisState) {
func setup(withGenesis bool) (*App, GenesisState) {
db := dbm.NewMemDB()
encCdc := MakeEncodingConfig()
var emptyWasmOpts []wasm.Option
Expand Down
4 changes: 2 additions & 2 deletions x/feeshare/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func CreateTestApp(isCheckTx bool) (*junoapp.App, sdk.Context) {
}

func Setup(isCheckTx bool) *junoapp.App {
app, genesisState := GenApp(!isCheckTx, 5)
app, genesisState := GenApp(!isCheckTx)
if !isCheckTx {
// init chain must be called to stop deliverState from being nil
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand All @@ -49,7 +49,7 @@ func Setup(isCheckTx bool) *junoapp.App {
return app
}

func GenApp(withGenesis bool, invCheckPeriod uint) (*junoapp.App, junoapp.GenesisState) {
func GenApp(withGenesis bool) (*junoapp.App, junoapp.GenesisState) {
db := dbm.NewMemDB()
encCdc := junoapp.MakeEncodingConfig()

Expand Down
14 changes: 7 additions & 7 deletions x/feeshare/types/errors.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package types

import (
sdkerrrors "github.com/cosmos/cosmos-sdk/types/errors"
errorsmod "cosmossdk.io/errors"
)

// errors
var (
ErrFeeShareDisabled = sdkerrrors.Register(ModuleName, 1, "feeshare module is disabled by governance")
ErrFeeShareAlreadyRegistered = sdkerrrors.Register(ModuleName, 2, "feeshare already exists for given contract")
ErrFeeShareNoContractDeployed = sdkerrrors.Register(ModuleName, 3, "no contract deployed")
ErrFeeShareContractNotRegistered = sdkerrrors.Register(ModuleName, 4, "no feeshare registered for contract")
ErrFeeSharePayment = sdkerrrors.Register(ModuleName, 5, "feeshare payment error")
ErrFeeShareInvalidWithdrawer = sdkerrrors.Register(ModuleName, 6, "invalid withdrawer address")
ErrFeeShareDisabled = errorsmod.Register(ModuleName, 1, "feeshare module is disabled by governance")
ErrFeeShareAlreadyRegistered = errorsmod.Register(ModuleName, 2, "feeshare already exists for given contract")
ErrFeeShareNoContractDeployed = errorsmod.Register(ModuleName, 3, "no contract deployed")
ErrFeeShareContractNotRegistered = errorsmod.Register(ModuleName, 4, "no feeshare registered for contract")
ErrFeeSharePayment = errorsmod.Register(ModuleName, 5, "feeshare payment error")
ErrFeeShareInvalidWithdrawer = errorsmod.Register(ModuleName, 6, "invalid withdrawer address")
)
3 changes: 2 additions & 1 deletion x/feeshare/types/feeshare.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerror "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -53,7 +54,7 @@ func (fs FeeShare) Validate() error {
}

if fs.WithdrawerAddress == "" {
return sdkerror.Wrap(sdkerror.ErrInvalidAddress, "withdrawer address cannot be empty")
return errorsmod.Wrap(sdkerror.ErrInvalidAddress, "withdrawer address cannot be empty")
}

if _, err := sdk.AccAddressFromBech32(fs.WithdrawerAddress); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions x/feeshare/types/msg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -134,15 +135,15 @@ func (msg MsgUpdateFeeShare) Type() string { return TypeMsgUpdateFeeShare }
// ValidateBasic runs stateless checks on the message
func (msg MsgUpdateFeeShare) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.DeployerAddress); err != nil {
return sdkerrors.Wrapf(err, "invalid deployer address %s", msg.DeployerAddress)
return errorsmod.Wrapf(err, "invalid deployer address %s", msg.DeployerAddress)
}

if _, err := sdk.AccAddressFromBech32(msg.ContractAddress); err != nil {
return sdkerrors.Wrapf(err, "invalid contract address %s", msg.ContractAddress)
return errorsmod.Wrapf(err, "invalid contract address %s", msg.ContractAddress)
}

if _, err := sdk.AccAddressFromBech32(msg.WithdrawerAddress); err != nil {
return sdkerrors.Wrapf(err, "invalid withdraw address %s", msg.WithdrawerAddress)
return errorsmod.Wrapf(err, "invalid withdraw address %s", msg.WithdrawerAddress)
}

return nil
Expand Down
3 changes: 1 addition & 2 deletions x/globalfee/ante/antetest/fee_test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/CosmosContracts/juno/v15/app"
gaiafeeante "github.com/CosmosContracts/juno/v15/x/globalfee/ante"

junoapp "github.com/CosmosContracts/juno/v15/app"
appparams "github.com/CosmosContracts/juno/v15/app/params"
"github.com/CosmosContracts/juno/v15/x/globalfee"
globfeetypes "github.com/CosmosContracts/juno/v15/x/globalfee/types"
Expand All @@ -29,7 +28,7 @@ import (
type IntegrationTestSuite struct {
suite.Suite

app *junoapp.App
app *app.App
ctx sdk.Context
clientCtx client.Context
txBuilder client.TxBuilder
Expand Down
2 changes: 1 addition & 1 deletion x/ibc-hooks/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/CosmosContracts/juno/v15/x/ibc-hooks/types"
)

func indexRunCmd(cmd *cobra.Command, args []string) error {
func indexRunCmd(cmd *cobra.Command, _ []string) error {
usageTemplate := `Usage:{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}
Expand Down
18 changes: 9 additions & 9 deletions x/ibc-hooks/sdkmodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ func (AppModuleBasic) Name() string {
}

// RegisterLegacyAminoCodec registers the ibc-hooks module's types on the given LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {}

// RegisterInterfaces registers the module's interface types.
func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {}

// DefaultGenesis returns default genesis state as raw bytes for the
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
func (AppModuleBasic) DefaultGenesis(_ codec.JSONCodec) json.RawMessage {
emptyString := "{}"
return []byte(emptyString)
}

// ValidateGenesis performs genesis state validation for the ibc-hooks module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig, _ json.RawMessage) error {
return nil
}

// RegisterRESTRoutes registers the REST routes for the ibc-hooks module.
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {}
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc-hooks module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {}
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {}

// GetTxCmd returns no root tx command for the ibc-hooks module.
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }
Expand Down Expand Up @@ -100,21 +100,21 @@ func (AppModule) QuerierRoute() string {

// RegisterServices registers a gRPC query service to respond to the
// module-specific gRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
func (am AppModule) RegisterServices(_ module.Configurator) {
}

// InitGenesis performs genesis initialization for the ibc-hooks module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}

func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONCodec) json.RawMessage {
return json.RawMessage([]byte("{}"))
}

// BeginBlock returns the begin blocker for the ibc-hooks module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {
}

// EndBlock returns the end blocker for the ibc-hooks module. It returns no validator
Expand Down
4 changes: 2 additions & 2 deletions x/ibc-hooks/wasm_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,15 @@ func (h WasmHooks) OnAcknowledgementPacketOverride(im IBCMiddleware, ctx sdk.Con
}

// Notify the sender that the ack has been received
ackAsJson, err := json.Marshal(acknowledgement)
ackAsJSON, err := json.Marshal(acknowledgement)
if err != nil {
// If the ack is not a json object, error
return err
}

sudoMsg := []byte(fmt.Sprintf(
`{"ibc_lifecycle_complete": {"ibc_ack": {"channel": "%s", "sequence": %d, "ack": %s, "success": %s}}}`,
packet.SourceChannel, packet.Sequence, ackAsJson, success))
packet.SourceChannel, packet.Sequence, ackAsJSON, success))
_, err = h.ContractKeeper.Sudo(ctx, contractAddr, sudoMsg)
if err != nil {
// error processing the callback
Expand Down
19 changes: 2 additions & 17 deletions x/mint/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,13 @@ import (
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"

junoapp "github.com/CosmosContracts/juno/v15/app"

"github.com/CosmosContracts/juno/v15/x/mint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// returns context and an app with updated mint keeper
func createTestApp(isCheckTx bool) (*junoapp.App, sdk.Context) { //nolint:unparam
app := setup(isCheckTx)

ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{})
app.AppKeepers.MintKeeper.SetParams(ctx, types.DefaultParams())
app.AppKeepers.MintKeeper.SetMinter(ctx, types.DefaultInitialMinter())

return app, ctx
}

func setup(isCheckTx bool) *junoapp.App {
app, genesisState := genApp(!isCheckTx, 5)
app, genesisState := genApp(!isCheckTx)
if !isCheckTx {
// init chain must be called to stop deliverState from being nil
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand All @@ -49,7 +34,7 @@ func setup(isCheckTx bool) *junoapp.App {
return app
}

func genApp(withGenesis bool, invCheckPeriod uint) (*junoapp.App, junoapp.GenesisState) {
func genApp(withGenesis bool) (*junoapp.App, junoapp.GenesisState) {
db := dbm.NewMemDB()
encCdc := junoapp.MakeEncodingConfig()

Expand Down
2 changes: 1 addition & 1 deletion x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
}

// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { //nolint:staticcheck // we need this to satisfy the upstream interface
return nil
}

Expand Down
Loading

0 comments on commit 6fa6429

Please sign in to comment.