forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: rollback command don't actually delete multistore versions (back…
…port cosmos#11361) (cosmos#13089) * fix: rollback command don't actually delete multistore versions (cosmos#11361) * rollback command don't actually delete multistore versions Closes: cosmos#11333 - add unit tests - use LoadVersionForOverwriting - update tendermint dependency to 0.35.x release branch Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> flushMetadata after rollback Update server/rollback.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> fix build gofumpt * fix unit test (cherry picked from commit 51d2de5) * fix unit test * changelog * api breaking changelog Co-authored-by: yihuang <huang@crypto.com>
- Loading branch information
1 parent
78c24eb
commit a95c626
Showing
11 changed files
with
123 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package rootmulti_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/simapp" | ||
"github.com/stretchr/testify/require" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
dbm "github.com/tendermint/tm-db" | ||
) | ||
|
||
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.Commit() | ||
ver0 := app.LastBlockHeight() | ||
// commit 10 blocks | ||
for i := int64(1); i <= 10; i++ { | ||
header := tmproto.Header{ | ||
Height: ver0 + i, | ||
AppHash: app.LastCommitID().Hash, | ||
} | ||
app.BeginBlock(abci.RequestBeginBlock{Header: header}) | ||
ctx := app.NewContext(false, header) | ||
store := ctx.KVStore(app.GetKey("bank")) | ||
store.Set([]byte("key"), []byte(fmt.Sprintf("value%d", i))) | ||
app.Commit() | ||
} | ||
|
||
require.Equal(t, ver0+10, app.LastBlockHeight()) | ||
store := app.NewContext(true, tmproto.Header{}).KVStore(app.GetKey("bank")) | ||
require.Equal(t, []byte("value10"), store.Get([]byte("key"))) | ||
|
||
// rollback 5 blocks | ||
target := ver0 + 5 | ||
require.NoError(t, app.CommitMultiStore().RollbackToVersion(target)) | ||
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) | ||
store = app.NewContext(true, tmproto.Header{}).KVStore(app.GetKey("bank")) | ||
require.Equal(t, []byte("value5"), store.Get([]byte("key"))) | ||
|
||
// commit another 5 blocks with different values | ||
for i := int64(6); i <= 10; i++ { | ||
header := tmproto.Header{ | ||
Height: ver0 + i, | ||
AppHash: app.LastCommitID().Hash, | ||
} | ||
app.BeginBlock(abci.RequestBeginBlock{Header: header}) | ||
ctx := app.NewContext(false, header) | ||
store := ctx.KVStore(app.GetKey("bank")) | ||
store.Set([]byte("key"), []byte(fmt.Sprintf("VALUE%d", i))) | ||
app.Commit() | ||
} | ||
|
||
require.Equal(t, ver0+10, app.LastBlockHeight()) | ||
store = app.NewContext(true, tmproto.Header{}).KVStore(app.GetKey("bank")) | ||
require.Equal(t, []byte("VALUE10"), store.Get([]byte("key"))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters