chore: fix all linting (#24101)
This commit is contained in:
+13
-10
@@ -716,7 +716,7 @@ func TestABCI_FinalizeBlock_MultiMsg(t *testing.T) {
|
||||
msgs = append(msgs, &baseapptestutil.MsgCounter2{Counter: 0, Signer: addr.String()})
|
||||
msgs = append(msgs, &baseapptestutil.MsgCounter2{Counter: 1, Signer: addr.String()})
|
||||
|
||||
builder.SetMsgs(msgs...)
|
||||
require.NoError(t, builder.SetMsgs(msgs...))
|
||||
builder.SetMemo(tx.GetMemo())
|
||||
setTxSignature(t, builder, 0)
|
||||
|
||||
@@ -888,7 +888,7 @@ func TestABCI_InvalidTransaction(t *testing.T) {
|
||||
{
|
||||
txBuilder := suite.txConfig.NewTxBuilder()
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
txBuilder.SetMsgs(&baseapptestutil.MsgCounter2{Signer: addr.String()})
|
||||
require.NoError(t, txBuilder.SetMsgs(&baseapptestutil.MsgCounter2{Signer: addr.String()}))
|
||||
setTxSignature(t, txBuilder, 0)
|
||||
unknownRouteTx := txBuilder.GetTx()
|
||||
|
||||
@@ -901,10 +901,10 @@ func TestABCI_InvalidTransaction(t *testing.T) {
|
||||
require.EqualValues(t, sdkerrors.ErrUnknownRequest.ABCICode(), code, err)
|
||||
|
||||
txBuilder = suite.txConfig.NewTxBuilder()
|
||||
txBuilder.SetMsgs(
|
||||
require.NoError(t, txBuilder.SetMsgs(
|
||||
&baseapptestutil.MsgCounter{Signer: addr.String()},
|
||||
&baseapptestutil.MsgCounter2{Signer: addr.String()},
|
||||
)
|
||||
))
|
||||
setTxSignature(t, txBuilder, 0)
|
||||
unknownRouteTx = txBuilder.GetTx()
|
||||
|
||||
@@ -920,7 +920,7 @@ func TestABCI_InvalidTransaction(t *testing.T) {
|
||||
// Transaction with an unregistered message
|
||||
{
|
||||
txBuilder := suite.txConfig.NewTxBuilder()
|
||||
txBuilder.SetMsgs(&testdata.MsgCreateDog{})
|
||||
require.NoError(t, txBuilder.SetMsgs(&testdata.MsgCreateDog{}))
|
||||
tx := txBuilder.GetTx()
|
||||
|
||||
_, _, err := suite.baseApp.SimDeliver(suite.txConfig.TxEncoder(), tx)
|
||||
@@ -1543,10 +1543,11 @@ func TestABCI_Proposals_WithVE(t *testing.T) {
|
||||
|
||||
suite := NewBaseAppSuite(t, setInitChainerOpt, prepareOpt)
|
||||
|
||||
suite.baseApp.InitChain(&abci.RequestInitChain{
|
||||
_, err := suite.baseApp.InitChain(&abci.RequestInitChain{
|
||||
InitialHeight: 1,
|
||||
ConsensusParams: &cmtproto.ConsensusParams{},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
reqPrepareProposal := abci.RequestPrepareProposal{
|
||||
MaxTxBytes: 100000,
|
||||
@@ -1683,11 +1684,12 @@ func TestABCI_PrepareProposal_MaxGas(t *testing.T) {
|
||||
baseapptestutil.RegisterCounterServer(suite.baseApp.MsgServiceRouter(), NoopCounterServerImpl{})
|
||||
|
||||
// set max block gas limit to 100
|
||||
suite.baseApp.InitChain(&abci.RequestInitChain{
|
||||
_, err := suite.baseApp.InitChain(&abci.RequestInitChain{
|
||||
ConsensusParams: &cmtproto.ConsensusParams{
|
||||
Block: &cmtproto.BlockParams{MaxGas: 100},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// insert 100 txs, each with a gas limit of 10
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
@@ -1696,7 +1698,7 @@ func TestABCI_PrepareProposal_MaxGas(t *testing.T) {
|
||||
msgs := []sdk.Msg{msg}
|
||||
|
||||
builder := suite.txConfig.NewTxBuilder()
|
||||
builder.SetMsgs(msgs...)
|
||||
require.NoError(t, builder.SetMsgs(msgs...))
|
||||
builder.SetMemo("counter=" + strconv.FormatInt(i, 10) + "&failOnAnte=false")
|
||||
builder.SetGasLimit(10)
|
||||
setTxSignature(t, builder, uint64(i))
|
||||
@@ -2010,13 +2012,14 @@ func TestABCI_HaltChain(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
suite := NewBaseAppSuite(t, baseapp.SetHaltHeight(tc.haltHeight), baseapp.SetHaltTime(tc.haltTime))
|
||||
suite.baseApp.InitChain(&abci.RequestInitChain{
|
||||
_, err := suite.baseApp.InitChain(&abci.RequestInitChain{
|
||||
ConsensusParams: &cmtproto.ConsensusParams{},
|
||||
InitialHeight: tc.blockHeight,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
app := suite.baseApp
|
||||
_, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
Height: tc.blockHeight,
|
||||
Time: time.Unix(tc.blockTime, 0),
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"slices" //nolint: gci // ignore this line for this linter
|
||||
"slices"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmttypes "github.com/cometbft/cometbft/types"
|
||||
protoio "github.com/cosmos/gogoproto/io"
|
||||
"github.com/cosmos/gogoproto/proto" //nolint: gci // ignore this line for this linter
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
|
||||
"cosmossdk.io/core/comet"
|
||||
|
||||
|
||||
+18
-8
@@ -62,6 +62,8 @@ type (
|
||||
)
|
||||
|
||||
func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite {
|
||||
t.Helper()
|
||||
|
||||
cdc := codectestutil.CodecOptions{}.NewCodec()
|
||||
baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry())
|
||||
|
||||
@@ -112,6 +114,8 @@ func getQueryBaseapp(t *testing.T) *baseapp.BaseApp {
|
||||
}
|
||||
|
||||
func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...func(*baseapp.BaseApp)) *BaseAppSuite {
|
||||
t.Helper()
|
||||
|
||||
snapshotTimeout := 1 * time.Minute
|
||||
snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), testutil.GetTempDir(t))
|
||||
require.NoError(t, err)
|
||||
@@ -140,7 +144,7 @@ func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...fun
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
txs := [][]byte{}
|
||||
for txNum := 0; txNum < cfg.blockTxs; txNum++ {
|
||||
msgs := []sdk.Msg{}
|
||||
var msgs []sdk.Msg
|
||||
for msgNum := 0; msgNum < 100; msgNum++ {
|
||||
key := []byte(fmt.Sprintf("%v", keyCounter))
|
||||
value := make([]byte, 10000)
|
||||
@@ -153,7 +157,7 @@ func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...fun
|
||||
}
|
||||
|
||||
builder := suite.txConfig.NewTxBuilder()
|
||||
builder.SetMsgs(msgs...)
|
||||
require.NoError(t, builder.SetMsgs(msgs...))
|
||||
setTxSignature(t, builder, 0)
|
||||
|
||||
txBytes, err := suite.txConfig.TxEncoder()(builder.GetTx())
|
||||
@@ -294,6 +298,8 @@ func TestSetLoader(t *testing.T) {
|
||||
}
|
||||
|
||||
initStore := func(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
|
||||
t.Helper()
|
||||
|
||||
rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
|
||||
rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
|
||||
|
||||
@@ -314,6 +320,8 @@ func TestSetLoader(t *testing.T) {
|
||||
}
|
||||
|
||||
checkStore := func(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) {
|
||||
t.Helper()
|
||||
|
||||
rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
|
||||
rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault))
|
||||
|
||||
@@ -549,7 +557,8 @@ func TestCustomRunTxPanicHandler(t *testing.T) {
|
||||
require.PanicsWithValue(t, customPanicMsg, func() {
|
||||
bz, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1, Txs: [][]byte{bz}})
|
||||
_, err = suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1, Txs: [][]byte{bz}})
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -623,7 +632,8 @@ func TestBaseAppAnteHandler(t *testing.T) {
|
||||
require.Equal(t, int64(2), getIntFromStore(t, store, anteKey))
|
||||
require.Equal(t, int64(1), getIntFromStore(t, store, deliverKey))
|
||||
|
||||
suite.baseApp.Commit()
|
||||
_, err = suite.baseApp.Commit()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestBaseAppPostHandler(t *testing.T) {
|
||||
@@ -869,16 +879,16 @@ func TestGetMaximumBlockGas(t *testing.T) {
|
||||
|
||||
ctx := suite.baseApp.NewContext(true)
|
||||
|
||||
suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 0}})
|
||||
require.NoError(t, suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 0}}))
|
||||
require.Equal(t, uint64(0), suite.baseApp.GetMaximumBlockGas(ctx))
|
||||
|
||||
suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -1}})
|
||||
require.NoError(t, suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -1}}))
|
||||
require.Equal(t, uint64(0), suite.baseApp.GetMaximumBlockGas(ctx))
|
||||
|
||||
suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 5000000}})
|
||||
require.NoError(t, suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 5000000}}))
|
||||
require.Equal(t, uint64(5000000), suite.baseApp.GetMaximumBlockGas(ctx))
|
||||
|
||||
suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -5000000}})
|
||||
require.NoError(t, suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -5000000}}))
|
||||
require.Panics(t, func() { suite.baseApp.GetMaximumBlockGas(ctx) })
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,7 @@ func TestQueryDataRaces_uniqueConnectionsToSameHandler(t *testing.T) {
|
||||
}
|
||||
|
||||
func testQueryDataRacesSameHandler(t *testing.T, makeClientConn func(*baseapp.GRPCQueryRouter) *baseapp.QueryServiceTestHelper) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
qr := baseapp.NewGRPCQueryRouter()
|
||||
|
||||
@@ -245,7 +245,6 @@ func TestABCI_OfferSnapshot_Errors(t *testing.T) {
|
||||
}, abci.ResponseOfferSnapshot_REJECT},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(name, func(t *testing.T) {
|
||||
resp, err := suite.baseApp.OfferSnapshot(&abci.RequestOfferSnapshot{Snapshot: tc.snapshot})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -51,11 +51,12 @@ func TestABCI_MultiListener_StateChanges(t *testing.T) {
|
||||
addListenerOpt := func(bapp *baseapp.BaseApp) { bapp.CommitMultiStore().AddListeners([]storetypes.StoreKey{distKey1}) }
|
||||
suite := NewBaseAppSuite(t, anteOpt, distOpt, streamingManagerOpt, addListenerOpt)
|
||||
|
||||
suite.baseApp.InitChain(
|
||||
_, err := suite.baseApp.InitChain(
|
||||
&abci.RequestInitChain{
|
||||
ConsensusParams: &tmproto.ConsensusParams{},
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
deliverKey := []byte("deliver-key")
|
||||
baseapptestutil.RegisterCounterServer(suite.baseApp.MsgServiceRouter(), CounterServerImpl{t, capKey1, deliverKey})
|
||||
@@ -103,7 +104,8 @@ func TestABCI_MultiListener_StateChanges(t *testing.T) {
|
||||
// require.Equal(t, sdk.MarkEventsToIndex(counterEvent(sdk.EventTypeMessage, counter).ToABCIEvents(), map[string]struct{}{})[0], events[2], "msg handler update counter event")
|
||||
}
|
||||
|
||||
suite.baseApp.Commit()
|
||||
_, err = suite.baseApp.Commit()
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, expectedChangeSet, mockListener1.ChangeSet, "should contain the same changeSet")
|
||||
require.Equal(t, expectedChangeSet, mockListener2.ChangeSet, "should contain the same changeSet")
|
||||
@@ -119,9 +121,10 @@ func Test_Ctx_with_StreamingManager(t *testing.T) {
|
||||
addListenerOpt := func(bapp *baseapp.BaseApp) { bapp.CommitMultiStore().AddListeners([]storetypes.StoreKey{distKey1}) }
|
||||
suite := NewBaseAppSuite(t, streamingManagerOpt, addListenerOpt)
|
||||
|
||||
suite.baseApp.InitChain(&abci.RequestInitChain{
|
||||
_, err := suite.baseApp.InitChain(&abci.RequestInitChain{
|
||||
ConsensusParams: &tmproto.ConsensusParams{},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := getFinalizeBlockStateCtx(suite.baseApp)
|
||||
sm := ctx.StreamingManager()
|
||||
@@ -133,7 +136,8 @@ func Test_Ctx_with_StreamingManager(t *testing.T) {
|
||||
|
||||
for blockN := 0; blockN < nBlocks; blockN++ {
|
||||
|
||||
suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: int64(blockN) + 1})
|
||||
_, err := suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: int64(blockN) + 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := getFinalizeBlockStateCtx(suite.baseApp)
|
||||
sm := ctx.StreamingManager()
|
||||
@@ -141,6 +145,7 @@ func Test_Ctx_with_StreamingManager(t *testing.T) {
|
||||
require.Equal(t, listeners, sm.ABCIListeners, fmt.Sprintf("should contain same listeners: %v", listeners))
|
||||
require.Equal(t, true, sm.StopNodeOnErr, "should contain StopNodeOnErr = true")
|
||||
|
||||
suite.baseApp.Commit()
|
||||
_, err = suite.baseApp.Commit()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
+25
-3
@@ -168,6 +168,8 @@ func incrementCounter(ctx context.Context,
|
||||
deliverKey []byte,
|
||||
msg sdk.Msg,
|
||||
) (*baseapptestutil.MsgCreateCounterResponse, error) {
|
||||
t.Helper()
|
||||
|
||||
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
||||
store := sdkCtx.KVStore(capKey)
|
||||
|
||||
@@ -210,6 +212,8 @@ func counterEvent(evType string, msgCount int64) sdk.Events {
|
||||
}
|
||||
|
||||
func anteHandlerTxTest(t *testing.T, capKey storetypes.StoreKey, storeKey []byte) sdk.AnteHandler {
|
||||
t.Helper()
|
||||
|
||||
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
|
||||
store := ctx.KVStore(capKey)
|
||||
counter, failOnAnte := parseTxMemo(t, tx)
|
||||
@@ -233,6 +237,8 @@ func anteHandlerTxTest(t *testing.T, capKey storetypes.StoreKey, storeKey []byte
|
||||
}
|
||||
|
||||
func incrementingCounter(t *testing.T, store storetypes.KVStore, counterKey []byte, counter int64) (*sdk.Result, error) {
|
||||
t.Helper()
|
||||
|
||||
storedCounter := getIntFromStore(t, store, counterKey)
|
||||
require.Equal(t, storedCounter, counter)
|
||||
setIntOnStore(store, counterKey, counter+1)
|
||||
@@ -283,6 +289,8 @@ func (ps paramStore) Get(_ context.Context) (cmtproto.ConsensusParams, error) {
|
||||
}
|
||||
|
||||
func setTxSignature(t *testing.T, builder client.TxBuilder, nonce uint64) {
|
||||
t.Helper()
|
||||
|
||||
privKey := secp256k1.GenPrivKeyFromSecret([]byte("test"))
|
||||
pubKey := privKey.PubKey()
|
||||
err := builder.SetSignatures(
|
||||
@@ -296,6 +304,8 @@ func setTxSignature(t *testing.T, builder client.TxBuilder, nonce uint64) {
|
||||
}
|
||||
|
||||
func testLoadVersionHelper(t *testing.T, app *baseapp.BaseApp, expectedHeight int64, expectedID storetypes.CommitID) {
|
||||
t.Helper()
|
||||
|
||||
lastHeight := app.LastBlockHeight()
|
||||
lastID := app.LastCommitID()
|
||||
require.Equal(t, expectedHeight, lastHeight)
|
||||
@@ -317,6 +327,8 @@ func getFinalizeBlockStateCtx(app *baseapp.BaseApp) sdk.Context {
|
||||
}
|
||||
|
||||
func parseTxMemo(t *testing.T, tx sdk.Tx) (counter int64, failOnAnte bool) {
|
||||
t.Helper()
|
||||
|
||||
txWithMemo, ok := tx.(sdk.TxWithMemo)
|
||||
require.True(t, ok)
|
||||
|
||||
@@ -332,6 +344,8 @@ func parseTxMemo(t *testing.T, tx sdk.Tx) (counter int64, failOnAnte bool) {
|
||||
}
|
||||
|
||||
func newTxCounter(t *testing.T, cfg client.TxConfig, counter int64, msgCounters ...int64) signing.Tx {
|
||||
t.Helper()
|
||||
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
msgs := make([]sdk.Msg, 0, len(msgCounters))
|
||||
for _, c := range msgCounters {
|
||||
@@ -340,7 +354,7 @@ func newTxCounter(t *testing.T, cfg client.TxConfig, counter int64, msgCounters
|
||||
}
|
||||
|
||||
builder := cfg.NewTxBuilder()
|
||||
builder.SetMsgs(msgs...)
|
||||
require.NoError(t, builder.SetMsgs(msgs...))
|
||||
builder.SetMemo("counter=" + strconv.FormatInt(counter, 10) + "&failOnAnte=false")
|
||||
setTxSignature(t, builder, uint64(counter))
|
||||
|
||||
@@ -348,6 +362,8 @@ func newTxCounter(t *testing.T, cfg client.TxConfig, counter int64, msgCounters
|
||||
}
|
||||
|
||||
func getIntFromStore(t *testing.T, store storetypes.KVStore, key []byte) int64 {
|
||||
t.Helper()
|
||||
|
||||
bz := store.Get(key)
|
||||
if len(bz) == 0 {
|
||||
return 0
|
||||
@@ -360,8 +376,10 @@ func getIntFromStore(t *testing.T, store storetypes.KVStore, key []byte) int64 {
|
||||
}
|
||||
|
||||
func setFailOnAnte(t *testing.T, cfg client.TxConfig, tx signing.Tx, failOnAnte bool) signing.Tx {
|
||||
t.Helper()
|
||||
|
||||
builder := cfg.NewTxBuilder()
|
||||
builder.SetMsgs(tx.GetMsgs()...)
|
||||
require.NoError(t, builder.SetMsgs(tx.GetMsgs()...))
|
||||
|
||||
memo := tx.GetMemo()
|
||||
vals, err := url.ParseQuery(memo)
|
||||
@@ -387,12 +405,16 @@ func setFailOnHandler(cfg client.TxConfig, tx signing.Tx, fail bool) signing.Tx
|
||||
}
|
||||
}
|
||||
|
||||
builder.SetMsgs(msgs...)
|
||||
if err := builder.SetMsgs(msgs...); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return builder.GetTx()
|
||||
}
|
||||
|
||||
// wonkyMsg is to be used to run a MsgCounter2 message when the MsgCounter2 handler is not registered.
|
||||
func wonkyMsg(t *testing.T, cfg client.TxConfig, tx signing.Tx) signing.Tx {
|
||||
t.Helper()
|
||||
|
||||
t.Helper()
|
||||
builder := cfg.NewTxBuilder()
|
||||
builder.SetMemo(tx.GetMemo())
|
||||
|
||||
Reference in New Issue
Block a user