Skip to content

Commit

Permalink
make the linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
facundomedica committed Jan 5, 2023
1 parent 641b0a5 commit fac4b17
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
6 changes: 2 additions & 4 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/jsonpb"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/types"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

Expand Down Expand Up @@ -1382,7 +1381,7 @@ func TestABCI_Proposal_Read_State_PrepareProposal(t *testing.T) {
}

prepareOpt := func(bapp *baseapp.BaseApp) {
bapp.SetPrepareProposal(func(ctx sdk.Context, req types.RequestPrepareProposal) types.ResponsePrepareProposal {
bapp.SetPrepareProposal(func(ctx sdk.Context, req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
value := ctx.KVStore(capKey1).Get(someKey)
// We should be able to access any state written in InitChain
require.Equal(t, "foo", string(value))
Expand All @@ -1405,7 +1404,7 @@ func TestABCI_Proposal_Read_State_PrepareProposal(t *testing.T) {

reqProposalTxBytes := [][]byte{}
reqProcessProposal := abci.RequestProcessProposal{
Txs: reqProposalTxBytes[:],
Txs: reqProposalTxBytes,
}

resProcessProposal := suite.baseApp.ProcessProposal(reqProcessProposal)
Expand All @@ -1414,7 +1413,6 @@ func TestABCI_Proposal_Read_State_PrepareProposal(t *testing.T) {
suite.baseApp.BeginBlock(abci.RequestBeginBlock{
Header: tmproto.Header{Height: suite.baseApp.LastBlockHeight() + 1},
})

}

func TestABCI_PrepareProposal_ReachedMaxBytes(t *testing.T) {
Expand Down
63 changes: 63 additions & 0 deletions simapp/app_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ package simapp

import (
_ "embed"
"errors"
"fmt"
"io"
"os"
"path/filepath"

dbm "github.com/cosmos/cosmos-db"
"github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"

"cosmossdk.io/client/v2/autocli"
Expand All @@ -25,6 +28,8 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
Expand Down Expand Up @@ -245,6 +250,64 @@ func NewSimApp(
panic(err)
}

nonceMempool := mempool.NewSenderNonceMempool()
mempoolOpt := baseapp.SetMempool(nonceMempool)
prepareOpt := func(bapp *baseapp.BaseApp) {
bapp.SetPrepareProposal(func(ctx sdk.Context, req types.RequestPrepareProposal) types.ResponsePrepareProposal {
fmt.Println("prepare proposal!!!! height:", ctx.BlockHeight())
balances := app.BankKeeper.GetAccountsBalances(ctx)
fmt.Println("all balances!!!!!", balances)
err := app.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1000000000000000000))))
fmt.Println("mint coins err:", err)
totalPower := app.StakingKeeper.GetLastTotalPower(ctx)
fmt.Println("total power!!!!!", totalPower)
bankParams := app.StakingKeeper.GetParams(ctx)
fmt.Println("staking params!!!!!", bankParams)
var (
txsBytes [][]byte
byteCount int64
)

iterator := nonceMempool.Select(ctx, req.Txs)
for iterator != nil {
memTx := iterator.Tx()

bz, err := app.txConfig.TxEncoder()(memTx)
if err != nil {
panic(err)
}

txSize := int64(len(bz))

// NOTE: Since runTx was already executed in CheckTx, which calls
// mempool.Insert, ideally everything in the pool should be valid. But
// some mempool implementations may insert invalid txs, so we check again.
res := app.CheckTx(types.RequestCheckTx{
Tx: bz,
Type: types.CheckTxType_Recheck,
})
if res.IsErr() {
err := nonceMempool.Remove(memTx)
if err != nil && !errors.Is(err, mempool.ErrTxNotFound) {
panic(err)
}

iterator = iterator.Next()
continue
} else if byteCount += txSize; byteCount <= req.MaxTxBytes {
txsBytes = append(txsBytes, bz)
} else {
break
}

iterator = iterator.Next()
}

return types.ResponsePrepareProposal{Txs: txsBytes}
})
}
baseAppOptions = append(baseAppOptions, prepareOpt, mempoolOpt)

app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...)

if err := app.App.BaseApp.SetStreamingService(appOpts, app.appCodec, app.kvStoreKeys()); err != nil {
Expand Down

0 comments on commit fac4b17

Please sign in to comment.