chore: fix all linting (#24101)

This commit is contained in:
Alex | Interchain Labs
2025-03-21 15:04:36 -07:00
committed by GitHub
parent b7fb7f4858
commit 7fd79df4e1
329 changed files with 1282 additions and 1251 deletions
+9 -9
View File
@@ -320,11 +320,11 @@ func (aa AccAddress) String() string {
func (aa AccAddress) Format(s fmt.State, verb rune) {
switch verb {
case 's':
s.Write([]byte(aa.String()))
_, _ = s.Write([]byte(aa.String()))
case 'p':
s.Write([]byte(fmt.Sprintf("%p", aa)))
_, _ = s.Write([]byte(fmt.Sprintf("%p", aa)))
default:
s.Write([]byte(fmt.Sprintf("%X", []byte(aa))))
_, _ = s.Write([]byte(fmt.Sprintf("%X", []byte(aa))))
}
}
@@ -484,11 +484,11 @@ func (va ValAddress) String() string {
func (va ValAddress) Format(s fmt.State, verb rune) {
switch verb {
case 's':
s.Write([]byte(va.String()))
_, _ = s.Write([]byte(va.String()))
case 'p':
s.Write([]byte(fmt.Sprintf("%p", va)))
_, _ = s.Write([]byte(fmt.Sprintf("%p", va)))
default:
s.Write([]byte(fmt.Sprintf("%X", []byte(va))))
_, _ = s.Write([]byte(fmt.Sprintf("%X", []byte(va))))
}
}
@@ -668,11 +668,11 @@ func MustBech32ifyAddressBytes(prefix string, bs []byte) string {
func (ca ConsAddress) Format(s fmt.State, verb rune) {
switch verb {
case 's':
s.Write([]byte(ca.String()))
_, _ = s.Write([]byte(ca.String()))
case 'p':
s.Write([]byte(fmt.Sprintf("%p", ca)))
_, _ = s.Write([]byte(fmt.Sprintf("%p", ca)))
default:
s.Write([]byte(fmt.Sprintf("%X", []byte(ca))))
_, _ = s.Write([]byte(fmt.Sprintf("%X", []byte(ca))))
}
}
+2
View File
@@ -115,6 +115,8 @@ func (a addrMock) Address() []byte {
}
func (a addrMock) AddressWithLen(t *testing.T) []byte {
t.Helper()
addr, err := LengthPrefix(a.Addr)
assert.NoError(t, err)
return addr
-1
View File
@@ -32,7 +32,6 @@ func (suite *StoreKeySuite) TestLengthPrefix() {
}
for _, tt := range tests {
tt := tt
suite.Run(tt.name, func() {
storeKey, err := address.LengthPrefix(tt.addr)
if tt.expErr {
+23 -15
View File
@@ -58,14 +58,17 @@ func (s *addressTestSuite) TestEmptyAddresses() {
s.Require().Equal((types.ConsAddress{}).String(), "")
accAddr, err := types.AccAddressFromBech32("")
s.Require().NotNil(accAddr)
s.Require().True(accAddr.Empty())
s.Require().Error(err)
valAddr, err := types.ValAddressFromBech32("")
s.Require().NotNil(accAddr)
s.Require().True(valAddr.Empty())
s.Require().Error(err)
consAddr, err := types.ConsAddressFromBech32("")
s.Require().NotNil(accAddr)
s.Require().True(consAddr.Empty())
s.Require().Error(err)
}
@@ -92,7 +95,8 @@ func (s *addressTestSuite) TestRandBech32AccAddrConsistency() {
pub := &ed25519.PubKey{Key: pubBz}
for i := 0; i < 1000; i++ {
rand.Read(pub.Key)
_, err := rand.Read(pub.Key)
s.Require().NoError(err)
acc := types.AccAddress(pub.Address())
res := types.AccAddress{}
@@ -101,7 +105,7 @@ func (s *addressTestSuite) TestRandBech32AccAddrConsistency() {
s.testMarshal(&acc, &res, acc.Marshal, (&res).Unmarshal)
str := acc.String()
res, err := types.AccAddressFromBech32(str)
res, err = types.AccAddressFromBech32(str)
s.Require().Nil(err)
s.Require().Equal(acc, res)
@@ -133,7 +137,8 @@ func (s *addressTestSuite) TestAddrCache() {
// Use a random key
pubBz := make([]byte, ed25519.PubKeySize)
pub := &ed25519.PubKey{Key: pubBz}
rand.Read(pub.Key)
_, err := rand.Read(pub.Key)
s.Require().NoError(err)
// Set SDK bech32 prefixes to 'osmo'
prefix := "osmo"
@@ -170,7 +175,8 @@ func (s *addressTestSuite) TestAddrCacheDisabled() {
// Use a random key
pubBz := make([]byte, ed25519.PubKeySize)
pub := &ed25519.PubKey{Key: pubBz}
rand.Read(pub.Key)
_, err := rand.Read(pub.Key)
s.Require().NoError(err)
// Set SDK bech32 prefixes to 'osmo'
prefix := "osmo"
@@ -202,7 +208,8 @@ func (s *addressTestSuite) TestValAddr() {
pub := &ed25519.PubKey{Key: pubBz}
for i := 0; i < 20; i++ {
rand.Read(pub.Key)
_, err := rand.Read(pub.Key)
s.Require().NoError(err)
acc := types.ValAddress(pub.Address())
res := types.ValAddress{}
@@ -211,7 +218,7 @@ func (s *addressTestSuite) TestValAddr() {
s.testMarshal(&acc, &res, acc.Marshal, (&res).Unmarshal)
str := acc.String()
res, err := types.ValAddressFromBech32(str)
res, err = types.ValAddressFromBech32(str)
s.Require().Nil(err)
s.Require().Equal(acc, res)
@@ -243,7 +250,8 @@ func (s *addressTestSuite) TestConsAddress() {
pub := &ed25519.PubKey{Key: pubBz}
for i := 0; i < 20; i++ {
rand.Read(pub.Key[:])
_, err := rand.Read(pub.Key)
s.Require().NoError(err)
acc := types.ConsAddress(pub.Address())
res := types.ConsAddress{}
@@ -252,7 +260,7 @@ func (s *addressTestSuite) TestConsAddress() {
s.testMarshal(&acc, &res, acc.Marshal, (&res).Unmarshal)
str := acc.String()
res, err := types.ConsAddressFromBech32(str)
res, err = types.ConsAddressFromBech32(str)
s.Require().Nil(err)
s.Require().Equal(acc, res)
@@ -293,7 +301,8 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
pub := &ed25519.PubKey{Key: pubBz}
for length := 1; length < 10; length++ {
for times := 1; times < 20; times++ {
rand.Read(pub.Key[:])
_, err := rand.Read(pub.Key[:])
s.Require().NoError(err)
// Test if randomly generated prefix of a given length works
prefix := RandString(length)
@@ -308,7 +317,7 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
acc.String(),
prefix+types.PrefixAccount), acc.String())
bech32Pub := legacybech32.MustMarshalPubKey(legacybech32.AccPK, pub) //nolint:staticcheck // SA1019: legacybech32 is deprecated: use the bech32 package instead.
bech32Pub := legacybech32.MustMarshalPubKey(legacybech32.AccPK, pub)
s.Require().True(strings.HasPrefix(
bech32Pub,
prefix+types.PrefixPublic))
@@ -322,7 +331,7 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
val.String(),
prefix+types.PrefixValidator+types.PrefixAddress))
bech32ValPub := legacybech32.MustMarshalPubKey(legacybech32.ValPK, pub) //nolint:staticcheck // SA1019: legacybech32 is deprecated: use the bech32 package instead.
bech32ValPub := legacybech32.MustMarshalPubKey(legacybech32.ValPK, pub)
s.Require().True(strings.HasPrefix(
bech32ValPub,
prefix+types.PrefixValidator+types.PrefixPublic))
@@ -336,7 +345,7 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
cons.String(),
prefix+types.PrefixConsensus+types.PrefixAddress))
bech32ConsPub := legacybech32.MustMarshalPubKey(legacybech32.ConsPK, pub) //nolint:staticcheck // SA1019: legacybech32 is deprecated: use the bech32 package instead.
bech32ConsPub := legacybech32.MustMarshalPubKey(legacybech32.ConsPK, pub)
s.Require().True(strings.HasPrefix(
bech32ConsPub,
prefix+types.PrefixConsensus+types.PrefixPublic))
@@ -347,7 +356,8 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
func (s *addressTestSuite) TestAddressInterface() {
pubBz := make([]byte, ed25519.PubKeySize)
pub := &ed25519.PubKey{Key: pubBz}
rand.Read(pub.Key)
_, err := rand.Read(pub.Key)
s.Require().NoError(err)
addrs := []types.Address{
types.ConsAddress(pub.Address()),
@@ -453,7 +463,6 @@ func (s *addressTestSuite) TestBech32ifyAddressBytes() {
{"20-byte address", args{"prefixb", addr20byte}, "prefixb1qqqsyqcyq5rqwzqfpg9scrgwpugpzysnrujsuw", false},
}
for _, tt := range tests {
tt := tt
s.T().Run(tt.name, func(t *testing.T) {
got, err := types.Bech32ifyAddressBytes(tt.args.prefix, tt.args.bs)
if (err != nil) != tt.wantErr {
@@ -486,7 +495,6 @@ func (s *addressTestSuite) TestMustBech32ifyAddressBytes() {
{"20-byte address", args{"prefixb", addr20byte}, "prefixb1qqqsyqcyq5rqwzqfpg9scrgwpugpzysnrujsuw", false},
}
for _, tt := range tests {
tt := tt
s.T().Run(tt.name, func(t *testing.T) {
if tt.wantPanic {
require.Panics(t, func() { types.MustBech32ifyAddressBytes(tt.args.prefix, tt.args.bs) })
-2
View File
@@ -420,7 +420,6 @@ func (coins Coins) SafeMulInt(x math.Int) (Coins, bool) {
res := make(Coins, len(coins))
for i, coin := range coins {
coin := coin
res[i] = NewCoin(coin.Denom, coin.Amount.Mul(x))
}
@@ -454,7 +453,6 @@ func (coins Coins) SafeQuoInt(x math.Int) (Coins, bool) {
var res Coins
for _, coin := range coins {
coin := coin
res = append(res, NewCoin(coin.Denom, coin.Amount.Quo(x)))
}
+3
View File
@@ -15,6 +15,7 @@ func BenchmarkCoinsAdditionIntersect(b *testing.B) {
b.ReportAllocs()
benchmarkingFunc := func(numCoinsA, numCoinsB int) func(b *testing.B) {
return func(b *testing.B) {
b.Helper()
b.ReportAllocs()
coinsA := Coins(make([]Coin, numCoinsA))
coinsB := Coins(make([]Coin, numCoinsB))
@@ -46,6 +47,7 @@ func BenchmarkCoinsAdditionNoIntersect(b *testing.B) {
b.ReportAllocs()
benchmarkingFunc := func(numCoinsA, numCoinsB int) func(b *testing.B) {
return func(b *testing.B) {
b.Helper()
b.ReportAllocs()
coinsA := Coins(make([]Coin, numCoinsA))
coinsB := Coins(make([]Coin, numCoinsB))
@@ -80,6 +82,7 @@ func BenchmarkSumOfCoinAdds(b *testing.B) {
// already in the sum, and (coinsPerAdd - numIntersectingCoins) that are new denoms.
benchmarkingFunc := func(numAdds, coinsPerAdd, numIntersectingCoins int, sumFn func([]Coins) Coins) func(b *testing.B) {
return func(b *testing.B) {
b.Helper()
b.ReportAllocs()
addCoins := make([]Coins, numAdds)
nonIntersectingCoins := coinsPerAdd - numIntersectingCoins
+2 -2
View File
@@ -139,7 +139,7 @@ func (s *contextTestSuite) TestContextWithCustom() {
s.Require().Equal(cp, ctx.WithConsensusParams(cp).ConsensusParams())
// test inner context
newContext := context.WithValue(ctx.Context(), struct{}{}, "value")
newContext := context.WithValue(ctx.Context(), struct{}{}, "value") //nolint:staticcheck // this is fine for testing
s.Require().NotEqual(ctx.Context(), ctx.WithContext(newContext).Context())
}
@@ -237,7 +237,7 @@ func (s *contextTestSuite) TestUnwrapSDKContext() {
s.Require().Panics(func() { types.UnwrapSDKContext(ctx) })
// test unwrapping when we've used context.WithValue
ctx = context.WithValue(sdkCtx, struct{}{}, "bar")
ctx = context.WithValue(sdkCtx, struct{}{}, "bar") //nolint:staticcheck // this is fine for testing
sdkCtx2 = types.UnwrapSDKContext(ctx)
s.Require().Equal(sdkCtx, sdkCtx2)
}
+1 -1
View File
@@ -639,7 +639,7 @@ func ParseDecCoin(coinStr string) (coin DecCoin, err error) {
}
if err := ValidateDenom(denomStr); err != nil {
return DecCoin{}, fmt.Errorf("invalid denom cannot contain spaces: %s", err)
return DecCoin{}, fmt.Errorf("invalid denom cannot contain spaces: %w", err)
}
return NewDecCoinFromDec(denomStr, amount), nil
-4
View File
@@ -541,10 +541,8 @@ func (s *MempoolTestSuite) TestRandomTxOrderManyTimes() {
// validateOrder checks that the txs are ordered by priority and nonce
// in O(n^2) time by checking each tx against all the other txs
func validateOrder(mtxs []sdk.Tx) error {
iterations := 0
var itxs []txSpec
for i, mtx := range mtxs {
iterations++
tx := mtx.(testTx)
itxs = append(itxs, txSpec{p: int(tx.priority), n: int(tx.nonce), a: tx.address, i: i})
}
@@ -557,7 +555,6 @@ func validateOrder(mtxs []sdk.Tx) error {
for _, a := range itxs {
for _, b := range itxs {
iterations++
// when b is before a
// when a is before b
@@ -575,7 +572,6 @@ func validateOrder(mtxs []sdk.Tx) error {
// find a tx with same sender as b and lower nonce
found := false
for _, c := range itxs {
iterations++
if c.a.Equals(b.a) && c.n < b.n && c.p <= a.p {
found = true
break
-2
View File
@@ -619,7 +619,6 @@ func (m *Manager) assertNoForgottenModules(setOrderFnName string, moduleNames []
}
var missing []string
for m := range m.Modules {
m := m
if pass != nil && pass(m) {
continue
}
@@ -861,7 +860,6 @@ func (m *Manager) GetVersionMap() VersionMap {
if v, ok := v.(HasConsensusVersion); ok {
version = v.ConsensusVersion()
}
name := name
vermap[name] = version
}
+3 -3
View File
@@ -190,7 +190,7 @@ func TestManager_RegisterQueryServices(t *testing.T) {
mockAppModule1.EXPECT().RegisterServices(cfg).Times(1)
mockAppModule2.EXPECT().RegisterServices(cfg).Times(1)
require.NotPanics(t, func() { mm.RegisterServices(cfg) })
require.NotPanics(t, func() { _ = mm.RegisterServices(cfg) })
}
func TestManager_InitGenesis(t *testing.T) {
@@ -591,7 +591,7 @@ func (MockCoreAppModule) DefaultGenesis(target appmodule.GenesisTarget) error {
if err != nil {
return err
}
someFieldWriter.Write([]byte(`"someKey"`))
_, _ = someFieldWriter.Write([]byte(`"someKey"`))
return someFieldWriter.Close()
}
@@ -618,7 +618,7 @@ func (MockCoreAppModule) ExportGenesis(ctx context.Context, target appmodule.Gen
if err != nil {
return err
}
wrt.Write([]byte(`"someKey"`))
_, _ = wrt.Write([]byte(`"someKey"`))
return wrt.Close()
}
@@ -169,7 +169,6 @@ func TestCollectionPagination(t *testing.T) {
}
for name, tc := range tcs {
tc := tc
t.Run(name, func(t *testing.T) {
gotResults, gotResponse, err := CollectionFilteredPaginate(
ctx,
-3
View File
@@ -24,7 +24,6 @@ func TestRandomAccounts(t *testing.T) {
{"100-accounts", 100, 100},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got := simulation.RandomAccounts(r, tt.n)
require.Equal(t, tt.want, len(got))
@@ -65,8 +64,6 @@ func TestRandomFees(t *testing.T) {
{"0 coins", sdk.NewCoins(sdk.NewInt64Coin("aaa", 10), sdk.NewInt64Coin("bbb", 5)), false, false},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got, err := simulation.RandomFees(r, sdk.Context{}, tt.spendableCoins)
if (err != nil) != tt.wantErr {
-3
View File
@@ -23,7 +23,6 @@ func TestRandSubsetCoins(t *testing.T) {
{"seed=99", rand.New(rand.NewSource(99)), mustParseCoins("100stake,2testtoken")},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got := simulation.RandSubsetCoins(tt.r, tt.coins)
gotStringRep := got.String()
@@ -46,8 +45,6 @@ func TestRandStringOfLength(t *testing.T) {
{"1_000_000-size", 1_000_000, 1_000_000},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got := simulation.RandStringOfLength(r, tt.n)
require.Equal(t, tt.want, len(got))
+1 -1
View File
@@ -5,7 +5,7 @@ import (
)
// TxExtensionOptionI defines the interface for tx extension options
type TxExtensionOptionI interface{} //nolint:revive // to avoid breaking change
type TxExtensionOptionI interface{}
// unpackTxExtensionOptionsI unpacks Any's to TxExtensionOptionI's.
func unpackTxExtensionOptionsI(unpacker types.AnyUnpacker, anys []*types.Any) error {