style: bank & autocli (#15659)

Co-authored-by: Sam Ricotta <samanthalricotta@gmail.com>
Co-authored-by: samricotta <37125168+samricotta@users.noreply.github.com>
This commit is contained in:
Jacob Gadikian 2023-04-02 07:20:59 +07:00 committed by GitHub
parent 6aaa3cf2ed
commit 0c905e8707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 40 additions and 46 deletions

View File

@ -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
}

View File

@ -10,11 +10,11 @@ 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 ""
}
@ -22,30 +22,30 @@ 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"
}

View File

@ -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)"
}

View File

@ -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
}

View File

@ -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)
@ -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")

View File

@ -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())
@ -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))
@ -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")

View File

@ -206,8 +206,7 @@ func init() {
)
}
//nolint:revive
type BankInputs struct {
type ModuleInputs struct {
depinject.In
Config *modulev1.Module
@ -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
@ -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}
}

View File

@ -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")

View File

@ -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)
}

View File

@ -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() {

View File

@ -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"

View File

@ -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)

View File

@ -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