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:
Facundo Medica
2023-07-06 13:33:10 +00:00
committed by GitHub
co-authored by Aleksandr Bezobchuk
parent 101992aa7a
commit 0fd6227a06
19 changed files with 206 additions and 66 deletions
+4
View File
@@ -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,
})
+51 -9
View File
@@ -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"))