Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
vladjdk committed Feb 26, 2025
1 parent c3c1968 commit 2001db3
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 79 deletions.
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@ linters-settings:
custom-order: true
dogsled:
max-blank-identifiers: 3
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
revive:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,6 @@ func TestPacketForwardMiddleware(t *testing.T) {
require.NoError(t, err)

transferTx, err := chainA.SendIBCTransfer(ctx, abChan.ChannelID, userA.KeyName(), transfer, ibc.TransferOptions{
//Timeout: &ibc.IBCTimeout{
// NanoSeconds: uint64(time.Now().Add(1 * time.Minute).Unix()),
// Height: 0,
//},
Memo: string(memo),
})
require.NoError(t, err)
Expand All @@ -430,10 +426,6 @@ func TestPacketForwardMiddleware(t *testing.T) {
_, err = testutil.PollForAck(ctx, chainA, chainAHeight, chainAHeight+25, transferTx.Packet)
require.NoError(t, err)

// Wait for the packet to relayed back to A
//err = testutil.WaitForCondition(time.Minute*5, time.Second*5, func() (bool, error) {
// return PacketAcknowledged(ctx, chainA, abChan.PortID, abChan.ChannelID, transferTx.Packet.Sequence), nil
//
//})
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, waitBlocks, chainA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ func (im IBCMiddleware) OnAcknowledgementPacket(

// OnTimeoutPacket implements the IBCModule interface.
func (im IBCMiddleware) OnTimeoutPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) error {

var data transfertypes.FungibleTokenPacketData
if err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
im.keeper.Logger(ctx).Error("packetForwardMiddleware error parsing packet data from timeout packet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
key := key
value := value
bz := k.cdc.MustMarshal(&value)
store.Set([]byte(key), bz)
err := store.Set([]byte(key), bz)
if err != nil {
return
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (k *Keeper) ForwardTransferPacket(
k.Logger(ctx).Error("packetForwardMiddleware error marshaling next as JSON",
"error", err,
)
return errorsmod.Wrapf(sdkerrors.ErrJSONMarshal, err.Error())
return errorsmod.Wrapf(sdkerrors.ErrJSONMarshal, "%s", err.Error())
}
memo = string(memoBz)
}
Expand Down Expand Up @@ -355,7 +355,7 @@ func (k *Keeper) ForwardTransferPacket(
"amount", token.Amount.String(), "denom", token.Denom,
"error", err,
)
return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, "%s", err.Error())
}

// Store the following information in keeper:
Expand Down Expand Up @@ -385,7 +385,10 @@ func (k *Keeper) ForwardTransferPacket(
key := types.RefundPacketKey(metadata.Channel, metadata.Port, res.Sequence)
store := k.storeService.OpenKVStore(ctx)
bz := k.cdc.MustMarshal(inFlightPacket)
store.Set(key, bz)
err = store.Set(key, bz)
if err != nil {
return err
}

defer func() {
if token.Amount.IsInt64() {
Expand Down Expand Up @@ -537,7 +540,10 @@ func (k *Keeper) GetAndClearInFlightPacket(
}

// done with packet key now, delete.
store.Delete(key)
err = store.Delete(key)
if err != nil {
return nil
}

var inFlightPacket types.InFlightPacket
k.cdc.MustUnmarshal(bz, &inFlightPacket)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
v3 "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/migrations/v3"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// Migrator is a struct for handling in-place state migrations.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package v3

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types"

sdk "github.com/cosmos/cosmos-sdk/types"

transfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ package v3_test
import (
"testing"

"cosmossdk.io/log"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
dbm "github.com/cosmos/cosmos-db"
v3 "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/migrations/v3"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/test/mock"
transfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"cosmossdk.io/log"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"

sdk "github.com/cosmos/cosmos-sdk/types"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

transfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types"
)

func TestMigrate(t *testing.T) {
Expand Down Expand Up @@ -45,9 +48,9 @@ func TestMigrate(t *testing.T) {
// the values are used to correct the escrow state in the migration and also
// to verify the correctness of the new escrow state afterwards.
tests := []struct {
giveTransferEscrowState map[string]sdk.Coin
bankBalances map[string]sdk.Coins
name string
giveTransferEscrowState map[string]sdk.Coin // denom -> escrow amount
bankBalances map[string]sdk.Coins // escrow address -> bank balance
}{
{
name: "empty channels",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package types
import (
"context"

cmtbytes "github.com/cometbft/cometbft/libs/bytes"

sdk "github.com/cosmos/cosmos-sdk/types"

cmtbytes "github.com/cometbft/cometbft/libs/bytes"

transfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ type PacketMetadata struct {
}

type ForwardMetadata struct {
Receiver string `json:"receiver,omitempty"`
Port string `json:"port,omitempty"`
Channel string `json:"channel,omitempty"`
Timeout Duration `json:"timeout,omitempty"`
Retries *uint8 `json:"retries,omitempty"`

// Using JSONObject so that objects for next property will not be mutated by golang's lexicographic key sort on map keys during Marshal.
// Supports primitives for Unmarshal/Marshal so that an escaped JSON-marshaled string is also valid.
Next *JSONObject `json:"next,omitempty"`
Retries *uint8 `json:"retries,omitempty"`
Next *JSONObject `json:"next,omitempty"`
Receiver string `json:"receiver,omitempty"`
Port string `json:"port,omitempty"`
Channel string `json:"channel,omitempty"`
Timeout Duration `json:"timeout,omitempty"`
}

type Duration time.Duration
Expand All @@ -47,9 +44,9 @@ func (m *ForwardMetadata) Validate() error {
// In the case the value is a JSON object, OrderedMap type is used so that key order
// is retained across Unmarshal/Marshal.
type JSONObject struct {
obj bool
primitive []byte
orderedMap orderedmap.OrderedMap
primitive []byte
obj bool
}

// NewJSONObject is a constructor used for tests.
Expand Down
4 changes: 2 additions & 2 deletions middleware/packet-forward-middleware/test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ type testMocks struct {
}

type initializer struct {
DB *dbm.MemDB
StateStore store.CommitMultiStore
Ctx sdk.Context
Marshaler codec.Codec
DB *dbm.MemDB
Amino *codec.LegacyAmino
Ctx sdk.Context
}

// Create an initializer with in memory database and default codecs
Expand Down
55 changes: 22 additions & 33 deletions middleware/packet-forward-middleware/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,48 +182,37 @@ var (
// SimApp extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions
type SimApp struct {
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino
AccountKeeper authkeeper.AccountKeeper
GroupKeeper groupkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
ParamsKeeper paramskeeper.Keeper
BankKeeper bankkeeper.Keeper
configurator module.Configurator
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry types.InterfaceRegistry

invCheckPeriod uint

// keys to access the substores
keys map[string]*storetypes.KVStoreKey
tkeys map[string]*storetypes.TransientStoreKey
memKeys map[string]*storetypes.MemoryStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
GroupKeeper groupkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino
sm *module.SimulationManager
BasicModuleManager module.BasicManager
mm *module.Manager
memKeys map[string]*storetypes.MemoryStoreKey
CrisisKeeper *crisiskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
AuthzKeeper authzkeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
tkeys map[string]*storetypes.TransientStoreKey
keys map[string]*storetypes.KVStoreKey
StakingKeeper *stakingkeeper.Keeper
PacketForwardKeeper *packetforwardkeeper.Keeper
GovKeeper govkeeper.Keeper
DistrKeeper distrkeeper.Keeper
MintKeeper mintkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper

// the module manager
mm *module.Manager
BasicModuleManager module.BasicManager

// simulation manager
sm *module.SimulationManager

// the configurator
configurator module.Configurator
SlashingKeeper slashingkeeper.Keeper
invCheckPeriod uint
}

func init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ func initAppConfig() (string, interface{}) {
}

type CustomAppConfig struct {
Custom CustomConfig `mapstructure:"custom"`
serverconfig.Config `mapstructure:",squash"`

Custom CustomConfig `mapstructure:"custom"`
}

// Optionally allow the chain developer to overwrite the SDK's default
Expand Down

0 comments on commit 2001db3

Please sign in to comment.