fix: remove setting of finalizeBlockState in FinalizeBlock + fix initialHeight + add ProcessProposal in tests/sims (#16794)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
101992aa7a
commit
0fd6227a06
@ -45,13 +45,15 @@ func (app *BaseApp) InitChain(req *abci.RequestInitChain) (*abci.ResponseInitCha
|
||||
// On a new chain, we consider the init chain block height as 0, even though
|
||||
// req.InitialHeight is 1 by default.
|
||||
initHeader := cmtproto.Header{ChainID: req.ChainId, Time: req.Time}
|
||||
app.initialHeight = req.InitialHeight
|
||||
|
||||
app.logger.Info("InitChain", "initialHeight", req.InitialHeight, "chainID", req.ChainId)
|
||||
|
||||
// Set the initial height, which will be used to determine if we are proposing
|
||||
// or processing the first block or not.
|
||||
app.initialHeight = req.InitialHeight
|
||||
if app.initialHeight == 0 { // If initial height is 0, set it to 1
|
||||
app.initialHeight = 1
|
||||
}
|
||||
|
||||
// if req.InitialHeight is > 1, then we set the initial version on all stores
|
||||
if req.InitialHeight > 1 {
|
||||
@ -675,46 +677,32 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.Respons
|
||||
AppHash: app.LastCommitID().Hash,
|
||||
}
|
||||
|
||||
// Initialize the FinalizeBlock state. If this is the first block, it should
|
||||
// already be initialized in InitChain. Otherwise app.finalizeBlockState will be
|
||||
// nil, since it is reset on Commit.
|
||||
if app.finalizeBlockState == nil {
|
||||
app.setState(execModeFinalize, header)
|
||||
} else {
|
||||
// In the first block, app.finalizeBlockState.ctx will already be initialized
|
||||
// by InitChain. Context is now updated with Header information.
|
||||
app.finalizeBlockState.ctx = app.finalizeBlockState.ctx.
|
||||
WithBlockHeader(header).
|
||||
WithBlockHeight(req.Height).
|
||||
WithHeaderInfo(coreheader.Info{
|
||||
ChainID: app.chainID,
|
||||
Height: req.Height,
|
||||
Time: req.Time,
|
||||
Hash: req.Hash,
|
||||
AppHash: app.LastCommitID().Hash,
|
||||
})
|
||||
}
|
||||
|
||||
gasMeter := app.getBlockGasMeter(app.finalizeBlockState.ctx)
|
||||
|
||||
// app.finalizeBlockState.ctx will already be initialized
|
||||
// by InitChain or by ProcessProposal. Context is now updated with Header information.
|
||||
app.finalizeBlockState.ctx = app.finalizeBlockState.ctx.
|
||||
WithBlockGasMeter(gasMeter).
|
||||
WithBlockHeader(header).
|
||||
WithHeaderHash(req.Hash).
|
||||
WithConsensusParams(app.GetConsensusParams(app.finalizeBlockState.ctx)).
|
||||
WithVoteInfos(req.DecidedLastCommit.Votes).
|
||||
WithExecMode(sdk.ExecModeFinalize).
|
||||
WithHeaderInfo(coreheader.Info{
|
||||
ChainID: app.chainID,
|
||||
Height: req.Height,
|
||||
Time: req.Time,
|
||||
Hash: req.Hash,
|
||||
AppHash: app.LastCommitID().Hash,
|
||||
}).WithCometInfo(cometInfo{
|
||||
Misbehavior: req.Misbehavior,
|
||||
ValidatorsHash: req.NextValidatorsHash,
|
||||
ProposerAddress: req.ProposerAddress,
|
||||
LastCommit: req.DecidedLastCommit,
|
||||
})
|
||||
}).
|
||||
WithConsensusParams(app.GetConsensusParams(app.finalizeBlockState.ctx)).
|
||||
WithVoteInfos(req.DecidedLastCommit.Votes).
|
||||
WithExecMode(sdk.ExecModeFinalize).
|
||||
WithCometInfo(cometInfo{
|
||||
Misbehavior: req.Misbehavior,
|
||||
ValidatorsHash: req.NextValidatorsHash,
|
||||
ProposerAddress: req.ProposerAddress,
|
||||
LastCommit: req.DecidedLastCommit,
|
||||
})
|
||||
|
||||
gasMeter := app.getBlockGasMeter(app.finalizeBlockState.ctx)
|
||||
|
||||
app.finalizeBlockState.ctx = app.finalizeBlockState.ctx.
|
||||
WithBlockGasMeter(gasMeter)
|
||||
|
||||
if app.checkState != nil {
|
||||
app.checkState.ctx = app.checkState.ctx.
|
||||
|
||||
@ -164,6 +164,8 @@ func TestABCI_InitChain(t *testing.T) {
|
||||
require.Equal(t, value, resQ.Value)
|
||||
|
||||
// commit and ensure we can still query
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: app.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.Commit()
|
||||
@ -578,6 +580,12 @@ func TestABCI_FinalizeBlock_DeliverTx(t *testing.T) {
|
||||
txs = append(txs, txBytes)
|
||||
}
|
||||
|
||||
_, err := suite.baseApp.ProcessProposal(&abci.RequestProcessProposal{
|
||||
Height: int64(blockN) + 1,
|
||||
Txs: txs,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
Height: int64(blockN) + 1,
|
||||
Txs: txs,
|
||||
@ -729,6 +737,8 @@ func TestABCI_Query_SimulateTx(t *testing.T) {
|
||||
require.Equal(t, result.Events, simRes.Result.Events)
|
||||
require.True(t, bytes.Equal(result.Data, simRes.Result.Data))
|
||||
|
||||
_, err = suite.baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: count})
|
||||
require.NoError(t, err)
|
||||
_, err = suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: count})
|
||||
require.NoError(t, err)
|
||||
_, err = suite.baseApp.Commit()
|
||||
@ -897,6 +907,10 @@ func TestABCI_TxGasLimits(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = suite.baseApp.ProcessProposal(&abci.RequestProcessProposal{
|
||||
Height: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, err = suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
Height: 1,
|
||||
})
|
||||
@ -934,6 +948,12 @@ func TestABCI_TxGasLimits(t *testing.T) {
|
||||
}
|
||||
|
||||
// Deliver the txs
|
||||
_, err = suite.baseApp.ProcessProposal(&abci.RequestProcessProposal{
|
||||
Height: 2,
|
||||
Txs: txs,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
Height: 2,
|
||||
Txs: txs,
|
||||
@ -1299,7 +1319,9 @@ func TestPrepareCheckStateCalledWithCheckState(t *testing.T) {
|
||||
wasPrepareCheckStateCalled = true
|
||||
})
|
||||
|
||||
_, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
_, err := app.ProcessProposal(&abci.RequestProcessProposal{Height: 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.Commit()
|
||||
require.NoError(t, err)
|
||||
@ -1323,7 +1345,9 @@ func TestPrecommiterCalledWithDeliverState(t *testing.T) {
|
||||
wasPrecommiterCalled = true
|
||||
})
|
||||
|
||||
_, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
_, err := app.ProcessProposal(&abci.RequestProcessProposal{Height: 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.Commit()
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -138,7 +138,13 @@ func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...fun
|
||||
txs = append(txs, txBytes)
|
||||
}
|
||||
|
||||
_, err := suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
_, err := suite.baseApp.ProcessProposal(&abci.RequestProcessProposal{
|
||||
Height: height,
|
||||
Txs: txs,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
Height: height,
|
||||
Txs: txs,
|
||||
})
|
||||
@ -190,6 +196,8 @@ func TestLoadVersion(t *testing.T) {
|
||||
require.Equal(t, emptyCommitID, lastID)
|
||||
|
||||
// execute a block, collect commit ID
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: 1})
|
||||
require.NoError(t, err)
|
||||
res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
require.NoError(t, err)
|
||||
commitID1 := storetypes.CommitID{Version: 1, Hash: res.AppHash}
|
||||
@ -197,6 +205,8 @@ func TestLoadVersion(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// execute a block, collect commit ID
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: 2})
|
||||
require.NoError(t, err)
|
||||
res, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 2})
|
||||
require.NoError(t, err)
|
||||
commitID2 := storetypes.CommitID{Version: 2, Hash: res.AppHash}
|
||||
@ -220,6 +230,8 @@ func TestLoadVersion(t *testing.T) {
|
||||
|
||||
testLoadVersionHelper(t, app, int64(1), commitID1)
|
||||
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: 2})
|
||||
require.NoError(t, err)
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 2})
|
||||
require.NoError(t, err)
|
||||
_, err = app.Commit()
|
||||
@ -308,6 +320,8 @@ func TestSetLoader(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// "execute" one block
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: 2})
|
||||
require.NoError(t, err)
|
||||
res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 2})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, res.AppHash)
|
||||
@ -357,6 +371,8 @@ func TestLoadVersionInvalid(t *testing.T) {
|
||||
err = app.LoadVersion(-1)
|
||||
require.Error(t, err)
|
||||
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: 1})
|
||||
require.NoError(t, err)
|
||||
res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
require.NoError(t, err)
|
||||
commitID1 := storetypes.CommitID{Version: 1, Hash: res.AppHash}
|
||||
@ -576,11 +592,15 @@ func TestABCI_CreateQueryContext(t *testing.T) {
|
||||
name := t.Name()
|
||||
app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil)
|
||||
|
||||
_, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
_, err := app.ProcessProposal(&abci.RequestProcessProposal{Height: 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.Commit()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: 2})
|
||||
require.NoError(t, err)
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 2})
|
||||
require.NoError(t, err)
|
||||
_, err = app.Commit()
|
||||
@ -666,6 +686,8 @@ func TestLoadVersionPruning(t *testing.T) {
|
||||
// Commit seven blocks, of which 7 (latest) is kept in addition to 6, 5
|
||||
// (keep recent) and 3 (keep every).
|
||||
for i := int64(1); i <= 7; i++ {
|
||||
_, err := app.ProcessProposal(&abci.RequestProcessProposal{Height: i})
|
||||
require.NoError(t, err)
|
||||
res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: i})
|
||||
require.NoError(t, err)
|
||||
_, err = app.Commit()
|
||||
|
||||
@ -115,6 +115,8 @@ func TestMsgService(t *testing.T) {
|
||||
app.MsgServiceRouter(),
|
||||
testdata.MsgServerImpl{},
|
||||
)
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ func TestABCI_MultiListener_StateChanges(t *testing.T) {
|
||||
var expectedChangeSet []*storetypes.StoreKVPair
|
||||
|
||||
// create final block context state
|
||||
_, err := suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: int64(blockN) + 1, Txs: txs})
|
||||
_, err := suite.baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: int64(blockN) + 1, Txs: txs})
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := 0; i < txPerHeight; i++ {
|
||||
@ -133,6 +133,7 @@ func Test_Ctx_with_StreamingManager(t *testing.T) {
|
||||
|
||||
for blockN := 0; blockN < nBlocks; blockN++ {
|
||||
|
||||
suite.baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: int64(blockN) + 1})
|
||||
suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: int64(blockN) + 1})
|
||||
|
||||
ctx := getFinalizeBlockStateCtx(suite.baseApp)
|
||||
|
||||
@ -60,7 +60,7 @@ func TestInitApp(t *testing.T) {
|
||||
require.Equal(t, []byte("bar"), qres.Value)
|
||||
}
|
||||
|
||||
func TestDeliverTx(t *testing.T) {
|
||||
func TestFinalizeBlock(t *testing.T) {
|
||||
app := SetupApp(t)
|
||||
|
||||
key := "my-special-key"
|
||||
@ -72,6 +72,13 @@ func TestDeliverTx(t *testing.T) {
|
||||
tx := NewTx(key, value, randomAccounts[0].Address)
|
||||
txBytes := tx.GetSignBytes()
|
||||
|
||||
_, err := app.ProcessProposal(&abci.RequestProcessProposal{
|
||||
Hash: []byte("apphash"),
|
||||
Height: 1,
|
||||
Txs: [][]byte{txBytes},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
Hash: []byte("apphash"),
|
||||
Height: 1,
|
||||
|
||||
@ -70,7 +70,6 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio
|
||||
Address: acc.GetAddress().String(),
|
||||
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))),
|
||||
}
|
||||
|
||||
app := NewSimApp(options.Logger, options.DB, nil, true, options.AppOpts)
|
||||
genesisState := app.DefaultGenesis()
|
||||
genesisState, err = simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)
|
||||
|
||||
@ -95,6 +95,10 @@ func TestExportCmd_Height(t *testing.T) {
|
||||
|
||||
// Fast forward to block `tc.fastForward`.
|
||||
for i := int64(2); i <= tc.fastForward; i++ {
|
||||
app.ProcessProposal(&abci.RequestProcessProposal{
|
||||
Height: i,
|
||||
})
|
||||
|
||||
app.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
Height: i,
|
||||
})
|
||||
|
||||
@ -141,7 +141,7 @@ func checkBalance(t *testing.T, baseApp *baseapp.BaseApp, addr sdk.AccAddress, b
|
||||
t.Helper()
|
||||
ctxCheck := baseApp.NewContext(true)
|
||||
keeperBalances := keeper.GetAllBalances(ctxCheck, addr)
|
||||
require.True(t, balances.Equal(keeperBalances))
|
||||
require.Truef(t, balances.Equal(keeperBalances), "expected %v, got %v", balances, keeperBalances)
|
||||
}
|
||||
|
||||
func TestSendNotEnoughBalance(t *testing.T) {
|
||||
@ -152,10 +152,16 @@ func TestSendNotEnoughBalance(t *testing.T) {
|
||||
genAccs := []authtypes.GenesisAccount{acc}
|
||||
s := createTestSuite(t, genAccs)
|
||||
baseApp := s.App.BaseApp
|
||||
ctx := baseApp.NewContext(false)
|
||||
|
||||
_, err := baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
// context must be taken after InitChain/ProcessProposal, otherwise it's nil
|
||||
ctx := baseApp.NewContext(false)
|
||||
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 67))))
|
||||
_, err := baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
|
||||
|
||||
// FinalizeBlock call is needed because `app.finalizeBlockState.ms.Write()` is called
|
||||
_, err = baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, err = baseApp.Commit()
|
||||
require.NoError(t, err)
|
||||
@ -170,6 +176,9 @@ func TestSendNotEnoughBalance(t *testing.T) {
|
||||
sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)})
|
||||
header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1}
|
||||
txConfig := moduletestutil.MakeTestTxConfig()
|
||||
|
||||
_, err = baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, []sdk.Msg{sendMsg}, "", []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1)
|
||||
require.Error(t, err)
|
||||
|
||||
@ -191,10 +200,13 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {
|
||||
genAccs := []authtypes.GenesisAccount{acc}
|
||||
s := createTestSuite(t, genAccs)
|
||||
baseApp := s.App.BaseApp
|
||||
|
||||
_, err := baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
ctx := baseApp.NewContext(false)
|
||||
|
||||
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 67))))
|
||||
_, err := baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
|
||||
_, err = baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, err = baseApp.Commit()
|
||||
require.NoError(t, err)
|
||||
@ -250,7 +262,11 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {
|
||||
t.Logf("testing %s", tc.desc)
|
||||
header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1}
|
||||
txConfig := moduletestutil.MakeTestTxConfig()
|
||||
_, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
|
||||
_, err := baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: header.Height})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
if tc.expPass {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
@ -274,11 +290,14 @@ func TestMsgMultiSendMultipleOut(t *testing.T) {
|
||||
genAccs := []authtypes.GenesisAccount{acc1, acc2}
|
||||
s := createTestSuite(t, genAccs)
|
||||
baseApp := s.App.BaseApp
|
||||
ctx := baseApp.NewContext(false)
|
||||
|
||||
_, err := baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := baseApp.NewContext(false)
|
||||
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
|
||||
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr2, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
|
||||
_, err := baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
|
||||
_, err = baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, err = baseApp.Commit()
|
||||
require.NoError(t, err)
|
||||
@ -302,7 +321,11 @@ func TestMsgMultiSendMultipleOut(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1}
|
||||
txConfig := moduletestutil.MakeTestTxConfig()
|
||||
_, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
|
||||
_, err := baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, eb := range tc.expectedBalances {
|
||||
@ -320,8 +343,10 @@ func TestMsgMultiSendDependent(t *testing.T) {
|
||||
genAccs := []authtypes.GenesisAccount{acc1, acc2}
|
||||
s := createTestSuite(t, genAccs)
|
||||
baseApp := s.App.BaseApp
|
||||
ctx := baseApp.NewContext(false)
|
||||
|
||||
_, err = baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
ctx := baseApp.NewContext(false)
|
||||
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
|
||||
_, err = baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
@ -357,6 +382,10 @@ func TestMsgMultiSendDependent(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1}
|
||||
txConfig := moduletestutil.MakeTestTxConfig()
|
||||
|
||||
_, err = baseApp.ProcessProposal(&abci.RequestProcessProposal{Height: header.Height})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -372,8 +401,17 @@ func TestMsgSetSendEnabled(t *testing.T) {
|
||||
genAccs := []authtypes.GenesisAccount{acc1}
|
||||
s := createTestSuite(t, genAccs)
|
||||
|
||||
_, err := s.App.ProcessProposal(&abci.RequestProcessProposal{Height: s.App.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := s.App.BaseApp.NewContext(false)
|
||||
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 101))))
|
||||
|
||||
_, err = s.App.FinalizeBlock(&abci.RequestFinalizeBlock{Height: s.App.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, err = s.App.Commit()
|
||||
require.NoError(t, err)
|
||||
|
||||
addr1Str := addr1.String()
|
||||
govAddr := s.BankKeeper.GetAuthority()
|
||||
goodGovProp, err := govv1.NewMsgSubmitProposal(
|
||||
@ -436,6 +474,10 @@ func TestMsgSetSendEnabled(t *testing.T) {
|
||||
t.Run(tc.desc, func(tt *testing.T) {
|
||||
header := cmtproto.Header{Height: s.App.LastBlockHeight() + 1}
|
||||
txGen := moduletestutil.MakeTestTxConfig()
|
||||
|
||||
_, err = s.App.ProcessProposal(&abci.RequestProcessProposal{Height: header.Height})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = simtestutil.SignCheckDeliver(tt, txGen, s.App.BaseApp, header, tc.msgs, "", []uint64{0}, tc.accSeqs, tc.expSimPass, tc.expPass, priv1)
|
||||
if len(tc.expInError) > 0 {
|
||||
require.Error(tt, err)
|
||||
|
||||
@ -285,6 +285,7 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
res, err := f.app.RunMsg(
|
||||
tc.msg,
|
||||
integration.WithAutomaticProcessProposal(),
|
||||
integration.WithAutomaticFinalizeBlock(),
|
||||
integration.WithAutomaticCommit(),
|
||||
)
|
||||
@ -435,7 +436,7 @@ func TestMsgSetWithdrawAddress(t *testing.T) {
|
||||
tc.preRun()
|
||||
res, err := f.app.RunMsg(
|
||||
tc.msg,
|
||||
integration.WithAutomaticFinalizeBlock(),
|
||||
integration.WithAutomaticProcessProposal(),
|
||||
integration.WithAutomaticCommit(),
|
||||
)
|
||||
if tc.expErr {
|
||||
@ -531,7 +532,7 @@ func TestMsgWithdrawValidatorCommission(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
res, err := f.app.RunMsg(
|
||||
tc.msg,
|
||||
integration.WithAutomaticFinalizeBlock(),
|
||||
integration.WithAutomaticProcessProposal(),
|
||||
integration.WithAutomaticCommit(),
|
||||
)
|
||||
if tc.expErr {
|
||||
@ -634,7 +635,7 @@ func TestMsgFundCommunityPool(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
res, err := f.app.RunMsg(
|
||||
tc.msg,
|
||||
integration.WithAutomaticFinalizeBlock(),
|
||||
integration.WithAutomaticProcessProposal(),
|
||||
integration.WithAutomaticCommit(),
|
||||
)
|
||||
if tc.expErr {
|
||||
@ -762,7 +763,7 @@ func TestMsgUpdateParams(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
res, err := f.app.RunMsg(
|
||||
tc.msg,
|
||||
integration.WithAutomaticFinalizeBlock(),
|
||||
integration.WithAutomaticProcessProposal(),
|
||||
integration.WithAutomaticCommit(),
|
||||
)
|
||||
if tc.expErr {
|
||||
@ -841,7 +842,7 @@ func TestMsgCommunityPoolSpend(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
res, err := f.app.RunMsg(
|
||||
tc.msg,
|
||||
integration.WithAutomaticFinalizeBlock(),
|
||||
integration.WithAutomaticProcessProposal(),
|
||||
integration.WithAutomaticCommit(),
|
||||
)
|
||||
if tc.expErr {
|
||||
@ -943,7 +944,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
res, err := f.app.RunMsg(
|
||||
tc.msg,
|
||||
integration.WithAutomaticFinalizeBlock(),
|
||||
integration.WithAutomaticProcessProposal(),
|
||||
integration.WithAutomaticCommit(),
|
||||
)
|
||||
if tc.expErr {
|
||||
|
||||
@ -190,7 +190,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
}
|
||||
_, err = f.app.RunMsg(
|
||||
&msgUnjail,
|
||||
integration.WithAutomaticFinalizeBlock(),
|
||||
integration.WithAutomaticProcessProposal(),
|
||||
integration.WithAutomaticCommit(),
|
||||
)
|
||||
assert.ErrorContains(t, err, "cannot be unjailed")
|
||||
@ -206,7 +206,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
// verify we can immediately unjail
|
||||
_, err = f.app.RunMsg(
|
||||
&msgUnjail,
|
||||
integration.WithAutomaticFinalizeBlock(),
|
||||
integration.WithAutomaticProcessProposal(),
|
||||
integration.WithAutomaticCommit(),
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package rootmulti_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@ -24,16 +25,21 @@ func TestRollback(t *testing.T) {
|
||||
}
|
||||
app := simapp.NewSimappWithCustomOptions(t, false, options)
|
||||
ver0 := app.LastBlockHeight()
|
||||
appStateBz, _ := json.Marshal(app.DefaultGenesis())
|
||||
|
||||
app.InitChain(&abci.RequestInitChain{
|
||||
ConsensusParams: simtestutil.DefaultConsensusParams,
|
||||
AppStateBytes: appStateBz,
|
||||
InitialHeight: 1,
|
||||
})
|
||||
|
||||
// commit 10 blocks
|
||||
for i := int64(1); i <= 10; i++ {
|
||||
header := cmtproto.Header{
|
||||
Height: ver0 + i,
|
||||
AppHash: app.LastCommitID().Hash,
|
||||
}
|
||||
|
||||
app.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
Height: header.Height,
|
||||
})
|
||||
app.ProcessProposal(&abci.RequestProcessProposal{Height: header.Height})
|
||||
ctx := app.NewContextLegacy(false, header)
|
||||
store := ctx.KVStore(app.GetKey("bank"))
|
||||
store.Set([]byte("key"), []byte(fmt.Sprintf("value%d", i)))
|
||||
@ -63,6 +69,7 @@ func TestRollback(t *testing.T) {
|
||||
Height: ver0 + i,
|
||||
AppHash: app.LastCommitID().Hash,
|
||||
}
|
||||
app.ProcessProposal(&abci.RequestProcessProposal{Height: header.Height})
|
||||
app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: header.Height})
|
||||
ctx := app.NewContextLegacy(false, header)
|
||||
store := ctx.KVStore(app.GetKey("bank"))
|
||||
|
||||
@ -167,7 +167,7 @@ func Example_oneModule() {
|
||||
Params: params,
|
||||
},
|
||||
// this allows to the begin and end blocker of the module before and after the message
|
||||
integration.WithAutomaticFinalizeBlock(),
|
||||
integration.WithAutomaticProcessProposal(),
|
||||
// this allows to commit the state after the message
|
||||
integration.WithAutomaticCommit(),
|
||||
)
|
||||
|
||||
@ -2,13 +2,21 @@ package integration
|
||||
|
||||
// Config is the configuration for the integration app.
|
||||
type Config struct {
|
||||
AutomaticFinalizeBlock bool
|
||||
AutomaticCommit bool
|
||||
AutomaticProcessProposal bool
|
||||
AutomaticFinalizeBlock bool
|
||||
AutomaticCommit bool
|
||||
}
|
||||
|
||||
// Option is a function that can be used to configure the integration app.
|
||||
type Option func(*Config)
|
||||
|
||||
// WithAutomaticProcessProposal calls ABCI process proposal.
|
||||
func WithAutomaticProcessProposal() Option {
|
||||
return func(cfg *Config) {
|
||||
cfg.AutomaticProcessProposal = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithAutomaticFinalizeBlock calls ABCI finalize block.
|
||||
func WithAutomaticFinalizeBlock() Option {
|
||||
return func(cfg *Config) {
|
||||
|
||||
@ -132,6 +132,13 @@ func (app *App) RunMsg(msg sdk.Msg, option ...Option) (*codectypes.Any, error) {
|
||||
defer app.Commit()
|
||||
}
|
||||
|
||||
if cfg.AutomaticProcessProposal {
|
||||
height := app.LastBlockHeight() + 1
|
||||
if _, err := app.ProcessProposal(&cmtabcitypes.RequestProcessProposal{Height: height}); err != nil {
|
||||
return nil, fmt.Errorf("failed to run process proposal: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.AutomaticFinalizeBlock {
|
||||
height := app.LastBlockHeight() + 1
|
||||
if _, err := app.FinalizeBlock(&cmtabcitypes.RequestFinalizeBlock{Height: height}); err != nil {
|
||||
|
||||
@ -141,7 +141,8 @@ func SignCheckDeliver(
|
||||
require.False(t, finalizeSuccess)
|
||||
}
|
||||
|
||||
app.Commit()
|
||||
_, err = app.Commit()
|
||||
require.NoError(t, err)
|
||||
|
||||
gInfo := sdk.GasInfo{GasWanted: uint64(txResult.GasWanted), GasUsed: uint64(txResult.GasUsed)}
|
||||
txRes := sdk.Result{Data: txResult.Data, Log: txResult.Log, Events: txResult.Events}
|
||||
|
||||
@ -42,6 +42,7 @@ func initChain(
|
||||
ChainId: chainID,
|
||||
ConsensusParams: consensusParams,
|
||||
Time: genesisTimestamp,
|
||||
InitialHeight: int64(config.InitialBlockHeight),
|
||||
}
|
||||
res, err := app.InitChain(&req)
|
||||
if err != nil {
|
||||
@ -180,6 +181,21 @@ func SimulateFromSeed(
|
||||
// Run the BeginBlock handler
|
||||
logWriter.AddEntry(BeginBlockEntry(blockHeight))
|
||||
|
||||
// Run ProcessProposal to remain compliant with the ABCI spec
|
||||
_, err := app.ProcessProposal(&abci.RequestProcessProposal{
|
||||
Txs: finalizeBlockReq.Txs,
|
||||
ProposedLastCommit: finalizeBlockReq.DecidedLastCommit,
|
||||
Misbehavior: finalizeBlockReq.Misbehavior,
|
||||
Hash: finalizeBlockReq.Hash,
|
||||
Height: finalizeBlockReq.Height,
|
||||
Time: finalizeBlockReq.Time,
|
||||
NextValidatorsHash: finalizeBlockReq.NextValidatorsHash,
|
||||
ProposerAddress: finalizeBlockReq.ProposerAddress,
|
||||
})
|
||||
if err != nil {
|
||||
return true, params, err
|
||||
}
|
||||
|
||||
res, err := app.FinalizeBlock(finalizeBlockReq)
|
||||
if err != nil {
|
||||
return true, params, err
|
||||
|
||||
@ -91,7 +91,10 @@ func TestSlashingMsgs(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1)))
|
||||
|
||||
app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1})
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: app.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctxCheck = baseApp.NewContext(true)
|
||||
validator, err := stakingKeeper.GetValidator(ctxCheck, sdk.ValAddress(addr1))
|
||||
|
||||
@ -79,6 +79,8 @@ func TestStakingMsgs(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1)))
|
||||
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: app.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
ctxCheck = app.BaseApp.NewContext(true)
|
||||
@ -89,6 +91,8 @@ func TestStakingMsgs(t *testing.T) {
|
||||
require.Equal(t, types.Bonded, validator.Status)
|
||||
require.True(math.IntEq(t, bondTokens, validator.BondedTokens()))
|
||||
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: app.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -110,6 +114,8 @@ func TestStakingMsgs(t *testing.T) {
|
||||
delegateMsg := types.NewMsgDelegate(addr2, sdk.ValAddress(addr1), bondCoin)
|
||||
|
||||
header = cmtproto.Header{Height: app.LastBlockHeight() + 1}
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: header.Height})
|
||||
require.NoError(t, err)
|
||||
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{delegateMsg}, "", []uint64{1}, []uint64{0}, true, true, priv2)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -121,6 +127,8 @@ func TestStakingMsgs(t *testing.T) {
|
||||
// begin unbonding
|
||||
beginUnbondingMsg := types.NewMsgUndelegate(addr2, sdk.ValAddress(addr1), bondCoin)
|
||||
header = cmtproto.Header{Height: app.LastBlockHeight() + 1}
|
||||
_, err = app.ProcessProposal(&abci.RequestProcessProposal{Height: header.Height})
|
||||
require.NoError(t, err)
|
||||
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, "", []uint64{1}, []uint64{1}, true, true, priv2)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user