Skip to content

Commit

Permalink
chore: fumpt sdk v45 series #12442
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Jul 5, 2022
1 parent 10961d0 commit 0e166fa
Show file tree
Hide file tree
Showing 337 changed files with 915 additions and 785 deletions.
4 changes: 1 addition & 3 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ const (
runTxModeDeliver // Deliver a transaction
)

var (
_ abci.Application = (*BaseApp)(nil)
)
var _ abci.Application = (*BaseApp)(nil)

type (
// Enum mode for app.runTx
Expand Down
1 change: 0 additions & 1 deletion baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,6 @@ func TestTxGasLimits(t *testing.T) {

return newCtx, nil
})

}

routerOpt := func(bapp *BaseApp) {
Expand Down
1 change: 0 additions & 1 deletion client/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,4 @@ func TestBroadcastError(t *testing.T) {
require.Equal(t, txHash, resp.TxHash)
}
}

}
2 changes: 1 addition & 1 deletion client/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func writeConfigToFile(configFilePath string, config *ClientConfig) error {
return err
}

return ioutil.WriteFile(configFilePath, buffer.Bytes(), 0600)
return ioutil.WriteFile(configFilePath, buffer.Bytes(), 0o600)
}

// ensureConfigPath creates a directory configPath if it does not exist
Expand Down
2 changes: 0 additions & 2 deletions client/debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ $ %s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
`, version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

addrString := args[0]
var addr []byte

Expand All @@ -86,7 +85,6 @@ $ %s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg

if err3 != nil {
return fmt.Errorf("expected hex or bech32. Got errors: hex: %v, bech32 acc: %v, bech32 val: %v", err, err2, err3)

}
}
}
Expand Down
6 changes: 2 additions & 4 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions client/grpc/tmservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ type queryServer struct {
interfaceRegistry codectypes.InterfaceRegistry
}

var _ ServiceServer = queryServer{}
var _ codectypes.UnpackInterfacesMessage = &GetLatestValidatorSetResponse{}
var (
_ ServiceServer = queryServer{}
_ codectypes.UnpackInterfacesMessage = &GetLatestValidatorSetResponse{}
)

// NewQueryServer creates a new tendermint query server.
func NewQueryServer(clientCtx client.Context, interfaceRegistry codectypes.InterfaceRegistry) ServiceServer {
Expand Down
2 changes: 1 addition & 1 deletion client/grpc/tmservice/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (s IntegrationTestSuite) TestQueryLatestValidatorSet() {
s.Require().Equal(true, ok)
s.Require().Equal(content, val.PubKey)

//with pagination
// with pagination
_, err = s.queryClient.GetLatestValidatorSet(context.Background(), &tmservice.GetLatestValidatorSetRequest{Pagination: &qtypes.PageRequest{
Offset: 0,
Limit: 10,
Expand Down
1 change: 1 addition & 0 deletions client/grpc_query_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build norace
// +build norace

package client_test
Expand Down
1 change: 0 additions & 1 deletion client/input/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ func TestReadLineFromBuf(t *testing.T) {
_, err := readLineFromBuf(buf)
require.ErrorIs(t, err, expectedErr)
})

}
3 changes: 2 additions & 1 deletion client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build ledger test_ledger_mock
//go:build ledger || test_ledger_mock
// +build ledger test_ledger_mock

package keys

Expand Down
2 changes: 1 addition & 1 deletion client/keys/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ HbP+c6JmeJy9JXe2rbbF1QtCX1gLqGcDQPBXiCtFvP7/8wTZtVOPj8vREzhZ9ElO

keyfile := filepath.Join(kbHome, "key.asc")

require.NoError(t, ioutil.WriteFile(keyfile, []byte(armoredKey), 0644))
require.NoError(t, ioutil.WriteFile(keyfile, []byte(armoredKey), 0o644))

defer func() {
_ = os.RemoveAll(kbHome)
Expand Down
2 changes: 1 addition & 1 deletion client/keys/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Test_runListCmd(t *testing.T) {
clientCtx := client.Context{}.WithKeyring(kb)
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)

path := "" //sdk.GetConfig().GetFullBIP44Path()
path := "" // sdk.GetConfig().GetFullBIP44Path()
_, err = kb.NewAccount("something", testdata.TestMnemonic, "", path, hd.Secp256k1)
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions client/keys/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func Test_runMigrateCmd(t *testing.T) {

cmd := MigrateCommand()
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
//mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
// mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
mockIn, mockOut := testutil.ApplyMockIO(cmd)

cmd.SetArgs([]string{
kbHome,
//fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
// fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
fmt.Sprintf("--%s=true", flags.FlagDryRun),
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
})
Expand Down
2 changes: 1 addition & 1 deletion client/query_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build norace
// +build norace

package client_test
Expand All @@ -11,7 +12,6 @@ import (
)

func (s *IntegrationTestSuite) TestQueryABCIHeight() {

testCases := []struct {
name string
reqHeight int64
Expand Down
1 change: 0 additions & 1 deletion client/tx/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func ConvertTxToStdTx(codec *codec.LegacyAmino, tx signing.Tx) (legacytx.StdTx,

err := CopyTx(tx, builder, true)
if err != nil {

return legacytx.StdTx{}, err
}

Expand Down
2 changes: 1 addition & 1 deletion codec/amino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestAminoCodecUnpackAnyFails(t *testing.T) {
func TestAminoCodecFullDecodeAndEncode(t *testing.T) {
// This tx comes from https://github.com/cosmos/cosmos-sdk/issues/8117.
txSigned := `{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgCreateValidator","value":{"description":{"moniker":"fulltest","identity":"satoshi","website":"example.com","details":"example inc"},"commission":{"rate":"0.500000000000000000","max_rate":"1.000000000000000000","max_change_rate":"0.200000000000000000"},"min_self_delegation":"1000000","delegator_address":"cosmos14pt0q5cwf38zt08uu0n6yrstf3rndzr5057jys","validator_address":"cosmosvaloper14pt0q5cwf38zt08uu0n6yrstf3rndzr52q28gr","pubkey":{"type":"tendermint/PubKeyEd25519","value":"CYrOiM3HtS7uv1B1OAkknZnFYSRpQYSYII8AtMMtev0="},"value":{"denom":"umuon","amount":"700000000"}}}],"fee":{"amount":[{"denom":"umuon","amount":"6000"}],"gas":"160000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AwAOXeWgNf1FjMaayrSnrOOKz+Fivr6DiI/i0x0sZCHw"},"signature":"RcnfS/u2yl7uIShTrSUlDWvsXo2p2dYu6WJC8VDVHMBLEQZWc8bsINSCjOnlsIVkUNNe1q/WCA9n3Gy1+0zhYA=="}],"memo":"","timeout_height":"0"}}`
var legacyCdc = simapp.MakeTestEncodingConfig().Amino
legacyCdc := simapp.MakeTestEncodingConfig().Amino
var tx legacytx.StdTx
err := legacyCdc.UnmarshalJSON([]byte(txSigned), &tx)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions codec/any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestMarshalProtoPubKey(t *testing.T) {
var pkI cryptotypes.PubKey
err = ccfg.InterfaceRegistry.UnpackAny(&pkAny2, &pkI)
require.NoError(err)
var pk2 = pkAny2.GetCachedValue().(cryptotypes.PubKey)
pk2 := pkAny2.GetCachedValue().(cryptotypes.PubKey)
require.True(pk2.Equals(pk))

// **** test binary serialization ****
Expand All @@ -92,7 +92,7 @@ func TestMarshalProtoPubKey(t *testing.T) {
require.NoError(err)
err = ccfg.InterfaceRegistry.UnpackAny(&pkAny3, &pkI)
require.NoError(err)
var pk3 = pkAny3.GetCachedValue().(cryptotypes.PubKey)
pk3 := pkAny3.GetCachedValue().(cryptotypes.PubKey)
require.True(pk3.Equals(pk))
}

Expand Down
6 changes: 4 additions & 2 deletions codec/codec_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func testMarshaling(t *testing.T, cdc codec.Codec) {
&testdata.Cat{},
false,
true,
}}
},
}
if _, ok := cdc.(*codec.AminoCodec); ok {
testCases = append(testCases, testCase{
"any marshaling",
Expand All @@ -123,7 +124,8 @@ func testMarshaling(t *testing.T, cdc codec.Codec) {
func(i codec.ProtoMarshaler) ([]byte, error) { return cdc.MarshalJSON(i) },
func(i codec.ProtoMarshaler) []byte { return cdc.MustMarshalJSON(i) },
func(bz []byte, ptr codec.ProtoMarshaler) error { return cdc.UnmarshalJSON(bz, ptr) },
func(bz []byte, ptr codec.ProtoMarshaler) { cdc.MustUnmarshalJSON(bz, ptr) }}
func(bz []byte, ptr codec.ProtoMarshaler) { cdc.MustUnmarshalJSON(bz, ptr) },
}

t.Run(tc.name+"_BinaryBare",
func(t *testing.T) { testMarshalingTestCase(require.New(t), tc, m1) })
Expand Down
6 changes: 4 additions & 2 deletions codec/proto_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ type ProtoCodec struct {
interfaceRegistry types.InterfaceRegistry
}

var _ Codec = &ProtoCodec{}
var _ ProtoCodecMarshaler = &ProtoCodec{}
var (
_ Codec = &ProtoCodec{}
_ ProtoCodecMarshaler = &ProtoCodec{}
)

// NewProtoCodec returns a reference to a new ProtoCodec
func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec {
Expand Down
4 changes: 2 additions & 2 deletions codec/proto_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func mustAny(msg proto.Message) *types.Any {
}

func BenchmarkProtoCodecMarshalLengthPrefixed(b *testing.B) {
var pCdc = codec.NewProtoCodec(types.NewInterfaceRegistry())
var msg = &testdata.HasAnimal{
pCdc := codec.NewProtoCodec(types.NewInterfaceRegistry())
msg := &testdata.HasAnimal{
X: 1000,
Animal: mustAny(&testdata.HasAnimal{
X: 2000,
Expand Down
6 changes: 4 additions & 2 deletions codec/types/any_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ type Animal interface {
Greet() string
}

var _ Animal = (*Dog)(nil)
var _ proto.Message = (*Dog)(nil)
var (
_ Animal = (*Dog)(nil)
_ proto.Message = (*Dog)(nil)
)

func TestAnyPackUnpack(t *testing.T) {
registry := NewInterfaceRegistry()
Expand Down
3 changes: 3 additions & 0 deletions codec/unknownproto/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func init() {
func BenchmarkRejectUnknownFields_serial(b *testing.B) {
benchmarkRejectUnknownFields(b, false)
}

func BenchmarkRejectUnknownFields_parallel(b *testing.B) {
benchmarkRejectUnknownFields(b, true)
}
Expand Down Expand Up @@ -82,9 +83,11 @@ func benchmarkRejectUnknownFields(b *testing.B, parallel bool) {
func BenchmarkProtoUnmarshal_serial(b *testing.B) {
benchmarkProtoUnmarshal(b, false)
}

func BenchmarkProtoUnmarshal_parallel(b *testing.B) {
benchmarkProtoUnmarshal(b, true)
}

func benchmarkProtoUnmarshal(b *testing.B, parallel bool) {
b.ReportAllocs()

Expand Down
12 changes: 8 additions & 4 deletions codec/unknownproto/unknown_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ func RejectUnknownFields(bz []byte, msg proto.Message, allowUnknownNonCriticals
return hasUnknownNonCriticals, nil
}

var protoMessageForTypeNameMu sync.RWMutex
var protoMessageForTypeNameCache = make(map[string]proto.Message)
var (
protoMessageForTypeNameMu sync.RWMutex
protoMessageForTypeNameCache = make(map[string]proto.Message)
)

// protoMessageForTypeName takes in a fully qualified name e.g. testdata.TestVersionFD1
// and returns a corresponding empty protobuf message that serves the prototype for typechecking.
Expand Down Expand Up @@ -382,8 +384,10 @@ type descriptorMatch struct {
desc *descriptor.DescriptorProto
}

var descprotoCacheMu sync.RWMutex
var descprotoCache = make(map[reflect.Type]*descriptorMatch)
var (
descprotoCacheMu sync.RWMutex
descprotoCache = make(map[reflect.Type]*descriptorMatch)
)

// getDescriptorInfo retrieves the mapping of field numbers to their respective field descriptors.
func getDescriptorInfo(desc descriptorIface, msg proto.Message) (map[int32]*descriptor.FieldDescriptorProto, *descriptor.DescriptorProto, error) {
Expand Down
6 changes: 3 additions & 3 deletions cosmovisor/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ func (cfg *Config) CurrentBin() (string, error) {
// if nothing here, fallback to genesis
info, err := os.Lstat(cur)
if err != nil {
//Create symlink to the genesis
// Create symlink to the genesis
return cfg.SymLinkToGenesis()
}
// if it is there, ensure it is a symlink
if info.Mode()&os.ModeSymlink == 0 {
//Create symlink to the genesis
// Create symlink to the genesis
return cfg.SymLinkToGenesis()
}

// resolve it
dest, err := os.Readlink(cur)
if err != nil {
//Create symlink to the genesis
// Create symlink to the genesis
return cfg.SymLinkToGenesis()
}

Expand Down
1 change: 1 addition & 0 deletions cosmovisor/process_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package cosmovisor_test
Expand Down
6 changes: 3 additions & 3 deletions cosmovisor/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func MarkExecutable(path string) error {
return fmt.Errorf("stating binary: %w", err)
}
// end early if world exec already set
if info.Mode()&0001 == 1 {
if info.Mode()&0o001 == 1 {
return nil
}
// now try to set all exec bits
newMode := info.Mode().Perm() | 0111
newMode := info.Mode().Perm() | 0o111
return os.Chmod(path, newMode)
}

Expand Down Expand Up @@ -186,7 +186,7 @@ func EnsureBinary(path string) error {
}

// this checks if the world-executable bit is set (we cannot check owner easily)
exec := info.Mode().Perm() & 0001
exec := info.Mode().Perm() & 0o001
if exec == 0 {
return fmt.Errorf("%s is not world executable", info.Name())
}
Expand Down
1 change: 1 addition & 0 deletions cosmovisor/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package cosmovisor_test
Expand Down
1 change: 0 additions & 1 deletion crypto/armor.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ func EncryptArmorPrivKey(privKey cryptotypes.PrivKey, passphrase string, algo st
func encryptPrivKey(privKey cryptotypes.PrivKey, passphrase string) (saltBytes []byte, encBytes []byte) {
saltBytes = crypto.CRandBytes(16)
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), BcryptSecurityParameter)

if err != nil {
panic(sdkerrors.Wrap(err, "error generating bcrypt key from passphrase"))
}
Expand Down
17 changes: 8 additions & 9 deletions crypto/hd/algo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ const (
Sr25519Type = PubKeyType("sr25519")
)

var (
// Secp256k1 uses the Bitcoin secp256k1 ECDSA parameters.
Secp256k1 = secp256k1Algo{}
)
// Secp256k1 uses the Bitcoin secp256k1 ECDSA parameters.
var Secp256k1 = secp256k1Algo{}

type DeriveFn func(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error)
type GenerateFn func(bz []byte) types.PrivKey
type (
DeriveFn func(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error)
GenerateFn func(bz []byte) types.PrivKey
)

type WalletGenerator interface {
Derive(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error)
Generate(bz []byte) types.PrivKey
}

type secp256k1Algo struct {
}
type secp256k1Algo struct{}

func (s secp256k1Algo) Name() PubKeyType {
return Secp256k1Type
Expand All @@ -63,7 +62,7 @@ func (s secp256k1Algo) Derive() DeriveFn {
// Generate generates a secp256k1 private key from the given bytes.
func (s secp256k1Algo) Generate() GenerateFn {
return func(bz []byte) types.PrivKey {
var bzArr = make([]byte, secp256k1.PrivKeySize)
bzArr := make([]byte, secp256k1.PrivKeySize)
copy(bzArr, bz)

return &secp256k1.PrivKey{Key: bzArr}
Expand Down
1 change: 0 additions & 1 deletion crypto/hd/hdpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func TestParamsFromPath(t *testing.T) {
require.Nil(t, params, errStr)
require.Error(t, err, errStr)
}

}

func TestCreateHDPath(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func newRealPrompt(dir string, buf io.Reader) func(string) (string, error) {
continue
}

if err := ioutil.WriteFile(dir+"/keyhash", passwordHash, 0555); err != nil {
if err := ioutil.WriteFile(dir+"/keyhash", passwordHash, 0o555); err != nil {
return "", err
}

Expand Down
Loading

0 comments on commit 0e166fa

Please sign in to comment.