Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang authored and tomtau committed Sep 5, 2022
1 parent 030f60c commit 2c9aaa8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
47 changes: 36 additions & 11 deletions store/rootmulti/rollback_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rootmulti_test

import (
"encoding/json"
"fmt"
"testing"

Expand All @@ -12,18 +13,41 @@ import (
dbm "github.com/tendermint/tm-db"
)

func setup(withGenesis bool, invCheckPeriod uint, db dbm.DB) (*simapp.SimApp, simapp.GenesisState) {
encCdc := simapp.MakeTestEncodingConfig()
app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, invCheckPeriod, encCdc, simapp.EmptyAppOptions{})
if withGenesis {
return app, simapp.NewDefaultGenesisState(encCdc.Marshaler)
}
return app, simapp.GenesisState{}
}

// Setup initializes a new SimApp. A Nop logger is set in SimApp.
func SetupWithDB(isCheckTx bool, db dbm.DB) *simapp.SimApp {
app, genesisState := setup(!isCheckTx, 5, db)
if !isCheckTx {
// init chain must be called to stop deliverState from being nil
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
panic(err)
}

// Initialize the chain
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: simapp.DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
}

return app
}

func TestRollback(t *testing.T) {
db := dbm.NewMemDB()
options := simapp.SetupOptions{
Logger: log.NewNopLogger(),
DB: db,
InvCheckPeriod: 0,
EncConfig: simapp.MakeTestEncodingConfig(),
HomePath: simapp.DefaultNodeHome,
SkipUpgradeHeights: map[int64]bool{},
AppOpts: simapp.EmptyAppOptions{},
}
app := simapp.NewSimappWithCustomOptions(t, false, options)
app := SetupWithDB(false, db)
app.Commit()
ver0 := app.LastBlockHeight()
// commit 10 blocks
Expand All @@ -49,7 +73,8 @@ func TestRollback(t *testing.T) {
require.Equal(t, target, app.LastBlockHeight())

// recreate app to have clean check state
app = simapp.NewSimApp(options.Logger, options.DB, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, options.InvCheckPeriod, options.EncConfig, options.AppOpts)
encCdc := simapp.MakeTestEncodingConfig()
app = simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{})
store = app.NewContext(true, tmproto.Header{}).KVStore(app.GetKey("bank"))
require.Equal(t, []byte("value5"), store.Get([]byte("key")))

Expand Down
3 changes: 1 addition & 2 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,6 @@ func (rs *Store) RollbackToVersion(target int64) error {
if target <= 0 {
return fmt.Errorf("invalid rollback height target: %d", target)
}
rs.PruneStores(true, nil)

for key, store := range rs.stores {
if store.GetStoreType() == types.StoreTypeIAVL {
Expand All @@ -989,7 +988,7 @@ func (rs *Store) RollbackToVersion(target int64) error {
}
}

flushMetadata(rs.db, target, rs.lastCommitInfo, rs.pruneHeights)
flushMetadata(rs.db, target, rs.buildCommitInfo(target), []int64{})

return rs.LoadLatestVersion()
}
Expand Down

0 comments on commit 2c9aaa8

Please sign in to comment.