Skip to content

Commit

Permalink
chore: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed May 22, 2024
1 parent a2062c9 commit a28396d
Show file tree
Hide file tree
Showing 54 changed files with 88 additions and 824 deletions.
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ issues:
- text: "ST1016:"
linters:
- stylecheck
- path: "migrations"
text: "SA1019:"
- text: "SA1019:"
linters:
- staticcheck
- text: "leading space"
Expand Down
15 changes: 7 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package app

import (
"fmt"
"io"
"os"
"path/filepath"

"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"fmt"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
"io"
"os"
"path/filepath"

"cosmossdk.io/x/circuit"
circuittypes "cosmossdk.io/x/circuit/types"
Expand Down Expand Up @@ -268,7 +270,6 @@ func NewComposableApp(
homePath string,
invCheckPeriod uint,
appOpts servertypes.AppOptions,
wasmOpts []wasm.Option,
devnetGov *string,
baseAppOptions ...func(*baseapp.BaseApp),
) *ComposableApp {
Expand All @@ -283,7 +284,6 @@ func NewComposableApp(
},
},
})

if err != nil {
panic(err)
}
Expand Down Expand Up @@ -595,7 +595,7 @@ func NewComposableApp(
tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err))
}

//if err := wasm08keeper.InitializePinnedCodes(ctx); err != nil {
// if err := wasm08keeper.InitializePinnedCodes(ctx); err != nil {
// tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err))
//}
}
Expand Down Expand Up @@ -749,7 +749,6 @@ func (app *ComposableApp) customPreUpgradeHandler(_ upgradetypes.Plan) {

func (app *ComposableApp) setupUpgradeHandlers() {
for _, upgrade := range Upgrades {

app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
Expand Down
1 change: 0 additions & 1 deletion app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func MakeEncodingConfig() EncodingConfig {
},
},
})

if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (app *ComposableApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedA
panic(err)
}

accumCommission, err := app.DistrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr)
accumCommission, _ := app.DistrKeeper.GetValidatorAccumulatedCommission(ctx, valAddr)
if accumCommission.Commission.IsZero() {
return false
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func (app *ComposableApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedA
panic(err)
}

scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valAddr)
scraps, _ := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valAddr)

feePool, err := app.DistrKeeper.FeePool.Get(ctx)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"cosmossdk.io/log"
"cosmossdk.io/math"
"github.com/CosmWasm/wasmd/x/wasm"
abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
Expand Down Expand Up @@ -60,7 +59,7 @@ func NewContextForApp(app composable.ComposableApp) sdk.Context {
return ctx
}

func setup(withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*composable.ComposableApp, composable.GenesisState) {
func setup(withGenesis bool, invCheckPeriod uint) (*composable.ComposableApp, composable.GenesisState) {
db := dbm.NewMemDB()
app := composable.NewComposableApp(
log.NewNopLogger(),
Expand All @@ -71,7 +70,6 @@ func setup(withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*composa
composable.DefaultNodeHome,
invCheckPeriod,
EmptyAppOptions{},
opts,
nil,
)
if withGenesis {
Expand Down Expand Up @@ -170,6 +168,7 @@ func SetupComposableAppWithValSetWithGenAccout(t *testing.T) (*composable.Compos

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
for _, val := range valSet.Validators {
//lint:ignore SA1019
pk, _ := cryptocodec.FromTmPubKeyInterface(val.PubKey)
pkAny, _ := codectypes.NewAnyWithValue(pk)

Expand Down
86 changes: 20 additions & 66 deletions app/ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ package ibctesting

import (
"context"
"fmt"
"testing"
"time"

"cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
"fmt"

servertypes "github.com/cosmos/cosmos-sdk/server/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/testutil"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
customibctransferkeeper "github.com/notional-labs/composable/v6/custom/ibc-transfer/keeper"
transfermiddlewarekeeper "github.com/notional-labs/composable/v6/x/transfermiddleware/keeper"
"testing"
"time"

ratelimitmodulekeeper "github.com/notional-labs/composable/v6/x/ratelimit/keeper"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
Expand All @@ -30,14 +33,10 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
Expand All @@ -53,7 +52,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtprotoversion "github.com/cometbft/cometbft/proto/tendermint/version"
"github.com/notional-labs/composable/v6/app"
)
Expand All @@ -70,8 +68,8 @@ type ChainApp interface {
servertypes.ABCI
AppCodec() codec.Codec
GetContextForFinalizeBlock(txBytes []byte) sdk.Context
NewContextLegacy(isCheckTx bool, header cmtproto.Header) sdk.Context
NewUncachedContext(isCheckTx bool, header cmtproto.Header) sdk.Context
NewContextLegacy(isCheckTx bool, header tmproto.Header) sdk.Context
NewUncachedContext(isCheckTx bool, header tmproto.Header) sdk.Context
LastBlockHeight() int64
LastCommitID() storetypes.CommitID
GetBaseApp() *baseapp.BaseApp
Expand Down Expand Up @@ -130,7 +128,7 @@ type PacketAck struct {
}

// ChainAppFactory abstract factory method that usually implemented by app.SetupWithGenesisValSet
type ChainAppFactory func(t *testing.T, valSet *cmttypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, opts []wasmkeeper.Option, balances ...banktypes.Balance) ChainApp
type ChainAppFactory func(t *testing.T, valSet *cmttypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, balances ...banktypes.Balance) ChainApp

// NewTestChain initializes a new TestChain instance with a single validator set using a
// generated private key. It also creates a sender account to be used for delivering transactions.
Expand Down Expand Up @@ -190,7 +188,7 @@ func NewTestChain(t *testing.T, coord *Coordinator, appFactory ChainAppFactory,
senderAccs = append(senderAccs, senderAcc)
}

app := appFactory(t, valSet, genAccs, chainID, nil, genBals...)
app := appFactory(t, valSet, genAccs, chainID, genBals...)

// app := NewTestingAppDecorator(t, app.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, "", nil, balance))

Expand Down Expand Up @@ -340,7 +338,7 @@ func (chain *TestChain) commitBlock(res *abci.ResponseFinalizeBlock) {
chain.NextVals = ibctesting.ApplyValSetChanges(chain.t, chain.Vals, res.ValidatorUpdates)

// increment the current header
chain.CurrentHeader = cmtproto.Header{
chain.CurrentHeader = tmproto.Header{
ChainID: chain.ChainID,
Height: chain.App.LastBlockHeight() + 1,
AppHash: chain.App.LastCommitID().Hash,
Expand Down Expand Up @@ -372,8 +370,8 @@ func (chain *TestChain) CurrentCmtClientHeader() *ibctmtypes.Header {
// caller flexibility to use params that differ from the chain.
func (chain *TestChain) CreateCmtClientHeader(chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, cmtValSet, nextVals, cmtTrustedVals *cmttypes.ValidatorSet, signers map[string]cmttypes.PrivValidator) *ibctmtypes.Header {
var (
valSet *cmtproto.ValidatorSet
trustedVals *cmtproto.ValidatorSet
valSet *tmproto.ValidatorSet
trustedVals *tmproto.ValidatorSet
)
require.NotNil(chain.t, cmtValSet)

Expand All @@ -399,7 +397,7 @@ func (chain *TestChain) CreateCmtClientHeader(chainID string, blockHeight int64,

hhash := cmtHeader.Hash()
blockID := MakeBlockID(hhash, 3, tmhash.Sum([]byte("part_set")))
voteSet := cmttypes.NewExtendedVoteSet(chainID, blockHeight, 1, cmtproto.PrecommitType, cmtValSet)
voteSet := cmttypes.NewExtendedVoteSet(chainID, blockHeight, 1, tmproto.PrecommitType, cmtValSet)
// MakeCommit expects a signer array in the same order as the validator array.
// Thus we iterate over the ordered validator set and construct a signer array
// from the signer map in the same order.
Expand All @@ -410,7 +408,7 @@ func (chain *TestChain) CreateCmtClientHeader(chainID string, blockHeight int64,
extCommit, err := cmttypes.MakeExtCommit(blockID, blockHeight, 1, voteSet, signerArr, timestamp, true)
require.NoError(chain.t, err)

signedHeader := &cmtproto.SignedHeader{
signedHeader := &tmproto.SignedHeader{
Header: cmtHeader.ToProto(),
Commit: extCommit.ToCommit().ToProto(),
}
Expand Down Expand Up @@ -457,7 +455,7 @@ func (chain *TestChain) sendMsgs(msgs ...sdk.Msg) error {
// occurred.
func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*abci.ExecTxResult, error) {
rsp, gotErr := chain.sendWithSigner(chain.SenderPrivKey, chain.SenderAccount, msgs...)
//require.NoError(chain.t, chain.SenderAccount.SetSequence(chain.SenderAccount.GetSequence()+1))

return rsp, gotErr
}

Expand Down Expand Up @@ -522,18 +520,7 @@ func (chain *TestChain) SendMsgsWithExpPass(expPass bool, msgs ...sdk.Msg) (*abc
// ensure the chain has the latest time
chain.Coordinator.UpdateTimeForChain(chain)

blockResp, err := app.SignAndDeliverWithoutCommit(
chain.t,
chain.TxConfig,
chain.App.GetBaseApp(),
msgs,
chain.DefaultMsgFees,
chain.ChainID,
[]uint64{chain.SenderAccount.GetAccountNumber()},
[]uint64{chain.SenderAccount.GetSequence()},
chain.CurrentHeader.GetTime(),
chain.SenderPrivKey,
)
blockResp, err := app.SignAndDeliverWithoutCommit(chain.t, chain.TxConfig, chain.App.GetBaseApp(), msgs, chain.ChainID, []uint64{chain.SenderAccount.GetAccountNumber()}, []uint64{chain.SenderAccount.GetSequence()}, chain.CurrentHeader.GetTime(), chain.SenderPrivKey)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -769,7 +756,7 @@ func (chain *TestChain) QueryContract(suite *suite.Suite, contract sdk.AccAddres
}

//
//func (chain *TestChain) StoreContractCode(suite *suite.Suite, path string) {
// func (chain *TestChain) StoreContractCode(suite *suite.Suite, path string) {
// govModuleAddress := chain.App.GetAccountKeeper().GetModuleAddress(govtypes.ModuleName)
// wasmCode, err := os.ReadFile(path)
// suite.Require().NoError(err)
Expand All @@ -796,36 +783,3 @@ func (chain *TestChain) InstantiateContract(suite *suite.Suite, msg string, code
suite.Require().NoError(err)
return addr
}

func mustSubmitAndExecuteLegacyProposal(t *testing.T, ctx sdk.Context, content v1beta1.Content, myActorAddress string, govKeeper *govkeeper.Keeper, authority string) {
t.Helper()
msgServer := govkeeper.NewMsgServerImpl(govKeeper)
// ignore all submit events
contentMsg, err := submitLegacyProposal(t, ctx.WithEventManager(sdk.NewEventManager()), content, myActorAddress, authority, msgServer)
require.NoError(t, err)

_, err = msgServer.ExecLegacyContent(sdk.WrapSDKContext(ctx), v1.NewMsgExecLegacyContent(contentMsg.Content, authority))
require.NoError(t, err)
}

// does not fail on submit proposal
func submitLegacyProposal(t *testing.T, ctx sdk.Context, content v1beta1.Content, myActorAddress, govAuthority string, msgServer v1.MsgServer) (*v1.MsgExecLegacyContent, error) {
t.Helper()
contentMsg, err := v1.NewLegacyContent(content, govAuthority)
require.NoError(t, err)

proposal, err := v1.NewMsgSubmitProposal(
[]sdk.Msg{contentMsg},
sdk.Coins{},
myActorAddress,
"",
"my title",
"my description",
false,
)
require.NoError(t, err)

// when stored
_, err = msgServer.SubmitProposal(sdk.WrapSDKContext(ctx), proposal)
return contentMsg, err
}
3 changes: 2 additions & 1 deletion app/ibctesting/chain_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package ibctesting_test

import (
"testing"

transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
"github.com/notional-labs/composable/v6/app/ibctesting"
"testing"

"github.com/stretchr/testify/require"

Expand Down
2 changes: 1 addition & 1 deletion app/ibctesting/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

abci "github.com/cometbft/cometbft/abci/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
Expand Down
16 changes: 3 additions & 13 deletions app/ibctesting/event_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@ package ibctesting
import (
"encoding/hex"
"fmt"
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
"strconv"
"strings"

connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"

abci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
)

func getSendPackets(evts []abci.Event) []channeltypes.Packet {
var res []channeltypes.Packet
for _, evt := range evts {
if evt.Type == "send_packet" {
packet := parsePacketFromEvent(evt)
res = append(res, packet)
}
}
return res
}

func getAckPackets(evts []abci.Event) []PacketAck {
var res []PacketAck
for _, evt := range evts {
Expand Down Expand Up @@ -68,7 +58,7 @@ func ParsePacketFromEvents(events sdk.Events) (channeltypes.Packet, error) {
packet := channeltypes.Packet{}
for _, attr := range ev.Attributes {
switch attr.Key {
case channeltypes.AttributeKeyData: //nolint: staticcheck
case channeltypes.AttributeKeyData:
packet.Data = []byte(attr.Value)

case channeltypes.AttributeKeySequence:
Expand Down
Loading

0 comments on commit a28396d

Please sign in to comment.