Skip to content

Commit

Permalink
style: bank & autocli (#15659)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Ricotta <samanthalricotta@gmail.com>
Co-authored-by: samricotta <37125168+samricotta@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 2, 2023
1 parent 6aaa3cf commit 0c905e8
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 46 deletions.
2 changes: 1 addition & 1 deletion client/v2/autocli/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error {
}
_, err = fmt.Fprintln(cmd.OutOrStdout(), string(out))

return nil
return err
}
22 changes: 11 additions & 11 deletions client/v2/autocli/flag/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,42 @@ import (

type durationType struct{}

func (t durationType) NewValue(context.Context, *Builder) Value {
func (d durationType) NewValue(context.Context, *Builder) Value {
return &durationValue{}
}

func (t durationType) DefaultValue() string {
func (d durationType) DefaultValue() string {
return ""
}

type durationValue struct {
value *durationpb.Duration
}

func (a durationValue) Get(protoreflect.Value) (protoreflect.Value, error) {
if a.value == nil {
func (d durationValue) Get(protoreflect.Value) (protoreflect.Value, error) {
if d.value == nil {
return protoreflect.Value{}, nil
}
return protoreflect.ValueOfMessage(a.value.ProtoReflect()), nil
return protoreflect.ValueOfMessage(d.value.ProtoReflect()), nil
}

func (v durationValue) String() string {
if v.value == nil {
func (d durationValue) String() string {
if d.value == nil {
return ""
}
return v.value.AsDuration().String()
return d.value.AsDuration().String()
}

func (v *durationValue) Set(s string) error {
func (d *durationValue) Set(s string) error {
dur, err := time.ParseDuration(s)
if err != nil {
return err
}

v.value = durationpb.New(dur)
d.value = durationpb.New(dur)
return nil
}

func (v durationValue) Type() string {
func (d durationValue) Type() string {
return "duration"
}
14 changes: 7 additions & 7 deletions client/v2/autocli/flag/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ func (t timestampValue) Get(protoreflect.Value) (protoreflect.Value, error) {
return protoreflect.ValueOfMessage(t.value.ProtoReflect()), nil
}

func (v timestampValue) String() string {
if v.value == nil {
func (t timestampValue) String() string {
if t.value == nil {
return ""
}
return v.value.AsTime().Format(time.RFC3339)
return t.value.AsTime().Format(time.RFC3339)
}

func (v *timestampValue) Set(s string) error {
t, err := time.Parse(time.RFC3339, s)
func (t *timestampValue) Set(s string) error {
time, err := time.Parse(time.RFC3339, s)
if err != nil {
return err
}
v.value = timestamppb.New(t)
t.value = timestamppb.New(time)
return nil
}

func (v timestampValue) Type() string {
func (t timestampValue) Type() string {
return "timestamp (RFC 3339)"
}
4 changes: 0 additions & 4 deletions client/v2/autocli/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,3 @@ func TestEnhanceMessageCommand(t *testing.T) {
err = b.enhanceCommandCommon(cmd, options, customCommands, enhanceMsg)
assert.NilError(t, err)
}

type testMessageServer struct {
testpb.UnimplementedMsgServer
}
4 changes: 2 additions & 2 deletions log/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func BenchmarkLoggers_StructuredVsFields(b *testing.B) {

b.Run("logger structured", func(b *testing.B) {
zl := zerolog.New(io.Discard)
var logger = log.NewCustomLogger(zl)
logger := log.NewCustomLogger(zl)
zerolog := logger.Impl().(*zerolog.Logger)
for i := 0; i < b.N; i++ {
zerolog.Info().Int64("foo", 100000).Msg(message)
Expand All @@ -150,7 +150,7 @@ func BenchmarkLoggers_StructuredVsFields(b *testing.B) {

b.Run("logger", func(b *testing.B) {
zl := zerolog.New(io.Discard)
var logger = log.NewCustomLogger(zl)
logger := log.NewCustomLogger(zl)
for i := 0; i < b.N; i++ {
logger.Info(message, "foo", 100000)
logger.Info(message, "foo", "foo")
Expand Down
18 changes: 9 additions & 9 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ func (suite *KeeperTestSuite) TestSupply_SendCoins() {

authKeeper.EXPECT().GetModuleAddress("").Return(nil)
require.Panics(func() {
_ = keeper.SendCoinsFromModuleToModule(ctx, "", holderAcc.GetName(), initCoins) //nolint:errcheck
_ = keeper.SendCoinsFromModuleToModule(ctx, "", holderAcc.GetName(), initCoins) //nolint:errcheck // we're testing for a panic, not an error
})

authKeeper.EXPECT().GetModuleAddress(burnerAcc.Name).Return(burnerAcc.GetAddress())
authKeeper.EXPECT().GetModuleAccount(ctx, "").Return(nil)
require.Panics(func() {
_ = keeper.SendCoinsFromModuleToModule(ctx, authtypes.Burner, "", initCoins) //nolint:errcheck
_ = keeper.SendCoinsFromModuleToModule(ctx, authtypes.Burner, "", initCoins) //nolint:errcheck // we're testing for a panic, not an error
})

authKeeper.EXPECT().GetModuleAddress("").Return(nil)
require.Panics(func() {
_ = keeper.SendCoinsFromModuleToAccount(ctx, "", baseAcc.GetAddress(), initCoins) //nolint:errcheck
_ = keeper.SendCoinsFromModuleToAccount(ctx, "", baseAcc.GetAddress(), initCoins) //nolint:errcheck // we're testing for a panic, not an error
})

authKeeper.EXPECT().GetModuleAddress(holderAcc.Name).Return(holderAcc.GetAddress())
Expand Down Expand Up @@ -371,16 +371,16 @@ func (suite *KeeperTestSuite) TestSupply_MintCoins() {
require.NoError(err)

authKeeper.EXPECT().GetModuleAccount(ctx, "").Return(nil)
require.Panics(func() { _ = keeper.MintCoins(ctx, "", initCoins) }, "no module account") //nolint:errcheck
require.Panics(func() { _ = keeper.MintCoins(ctx, "", initCoins) }, "no module account") //nolint:errcheck // we're testing for a panic, not an error

suite.mockMintCoins(burnerAcc)
require.Panics(func() { _ = keeper.MintCoins(ctx, authtypes.Burner, initCoins) }, "invalid permission") //nolint:errcheck
require.Panics(func() { _ = keeper.MintCoins(ctx, authtypes.Burner, initCoins) }, "invalid permission") //nolint:errcheck // we're testing for a panic, not an error

suite.mockMintCoins(minterAcc)
require.Error(keeper.MintCoins(ctx, authtypes.Minter, sdk.Coins{sdk.Coin{Denom: "denom", Amount: sdk.NewInt(-10)}}), "insufficient coins")

authKeeper.EXPECT().GetModuleAccount(ctx, randomPerm).Return(nil)
require.Panics(func() { _ = keeper.MintCoins(ctx, randomPerm, initCoins) }) //nolint:errcheck
require.Panics(func() { _ = keeper.MintCoins(ctx, randomPerm, initCoins) }) //nolint:errcheck // we're testing for a panic, not an error

suite.mockMintCoins(minterAcc)
require.NoError(keeper.MintCoins(ctx, authtypes.Minter, initCoins))
Expand Down Expand Up @@ -424,13 +424,13 @@ func (suite *KeeperTestSuite) TestSupply_BurnCoins() {
require.NoError(err)

authKeeper.EXPECT().GetModuleAccount(ctx, "").Return(nil)
require.Panics(func() { _ = keeper.BurnCoins(ctx, "", initCoins) }, "no module account") //nolint:errcheck
require.Panics(func() { _ = keeper.BurnCoins(ctx, "", initCoins) }, "no module account") //nolint:errcheck // we're testing for a panic, not an error

authKeeper.EXPECT().GetModuleAccount(ctx, minterAcc.Name).Return(nil)
require.Panics(func() { _ = keeper.BurnCoins(ctx, authtypes.Minter, initCoins) }, "invalid permission") //nolint:errcheck
require.Panics(func() { _ = keeper.BurnCoins(ctx, authtypes.Minter, initCoins) }, "invalid permission") //nolint:errcheck // we're testing for a panic, not an error

authKeeper.EXPECT().GetModuleAccount(ctx, randomPerm).Return(nil)
require.Panics(func() { _ = keeper.BurnCoins(ctx, randomPerm, supplyAfterInflation) }, "random permission") //nolint:errcheck
require.Panics(func() { _ = keeper.BurnCoins(ctx, randomPerm, supplyAfterInflation) }, "random permission") //nolint:errcheck // we're testing for a panic, not an error

suite.mockBurnCoins(burnerAcc)
require.Error(keeper.BurnCoins(ctx, authtypes.Burner, supplyAfterInflation), "insufficient coins")
Expand Down
10 changes: 4 additions & 6 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ func init() {
)
}

//nolint:revive
type BankInputs struct {
type ModuleInputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -220,15 +219,14 @@ type BankInputs struct {
LegacySubspace exported.Subspace `optional:"true"`
}

//nolint:revive
type BankOutputs struct {
type ModuleOutputs struct {
depinject.Out

BankKeeper keeper.BaseKeeper
Module appmodule.AppModule
}

func ProvideModule(in BankInputs) BankOutputs {
func ProvideModule(in ModuleInputs) ModuleOutputs {
// Configure blocked module accounts.
//
// Default behavior for blockedAddresses is to regard any module mentioned in
Expand Down Expand Up @@ -259,5 +257,5 @@ func ProvideModule(in BankInputs) BankOutputs {
)
m := NewAppModule(in.Cdc, bankKeeper, in.AccountKeeper, in.LegacySubspace)

return BankOutputs{BankKeeper: bankKeeper, Module: m}
return ModuleOutputs{BankKeeper: bankKeeper, Module: m}
}
2 changes: 1 addition & 1 deletion x/bank/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRandomizedGenState(t *testing.T) {
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &bankGenesis)

assert.Equal(t, true, bankGenesis.Params.GetDefaultSendEnabled(), "Params.GetDefaultSendEnabled")
assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck
assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck // we're testing deprecated code here
if assert.Len(t, bankGenesis.Balances, 3) {
assert.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", bankGenesis.Balances[2].GetAddress().String(), "Balances[2] address")
assert.Equal(t, "1000stake", bankGenesis.Balances[2].GetCoins().String(), "Balances[2] coins")
Expand Down
2 changes: 1 addition & 1 deletion x/bank/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ func TestProposalMsgs(t *testing.T) {

fmt.Println(msgUpdateParams)
assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority)
assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) //nolint:staticcheck
assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) //nolint:staticcheck // we're testing deprecated code here
assert.Equal(t, true, msgUpdateParams.Params.DefaultSendEnabled)
}
2 changes: 1 addition & 1 deletion x/bank/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {

var (
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
ModuleCdc = codec.NewAminoCodec(amino) //nolint:staticcheck // TODO: remove once amino is removed
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion x/gov/client/testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil"
Expand Down
2 changes: 1 addition & 1 deletion x/nft/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (s *CLITestSuite) TestCLITxSend() {
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
args := append(tc.args, extraArgs...) //nolint:gocritic // false positive
args := append(tc.args, extraArgs...)
cmd := cli.NewCmdSend()
cmd.SetContext(s.ctx)
cmd.SetArgs(args)
Expand Down
2 changes: 1 addition & 1 deletion x/nft/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

const (
// OpWeightMsgSend Simulation operation weights constants
OpWeightMsgSend = "op_weight_msg_send" //nolint:gosec
OpWeightMsgSend = "op_weight_msg_send"

// WeightSend nft operations weights
WeightSend = 100
Expand Down

0 comments on commit 0c905e8

Please sign in to comment.