scmigrate: ensure target key is correctly renamed (#8276)

Prior to v0.35, the keys for seen-commit records included the applicable
height.  In v0.35 and beyond, we only keep the record for the latest height,
and its key does not include the height.

Update the seen-commit migration to ensure that the record we retain after
migration is correctly renamed to omit the height from its key.

Update the test cases to check for this condition after migrating.
This commit is contained in:
M. J. Fromberger
2022-04-07 15:09:09 -07:00
committed by GitHub
parent 9d20e06900
commit f3858e52de
7 changed files with 81 additions and 99 deletions
+3 -14
View File
@@ -117,7 +117,7 @@ func TestMigration(t *testing.T) {
})
t.Run("Conversion", func(t *testing.T) {
for kind, le := range legacyPrefixes {
nk, err := migarateKey(le)
nk, err := migrateKey(le)
require.NoError(t, err, kind)
require.False(t, keyIsLegacy(nk), kind)
}
@@ -159,7 +159,7 @@ func TestMigration(t *testing.T) {
"UserKey3": []byte("foo/bar/baz/1.2/4"),
}
for kind, key := range table {
out, err := migarateKey(key)
out, err := migrateKey(key)
require.Error(t, err, kind)
require.Nil(t, out, kind)
}
@@ -177,7 +177,7 @@ func TestMigration(t *testing.T) {
return nil, errors.New("hi")
}))
})
t.Run("KeyDisapears", func(t *testing.T) {
t.Run("KeyDisappears", func(t *testing.T) {
db := dbm.NewMemDB()
key := keyID("hi")
require.NoError(t, db.Set(key, []byte("world")))
@@ -215,17 +215,6 @@ func TestMigration(t *testing.T) {
require.False(t, keyIsLegacy(key))
}
})
t.Run("ChannelConversion", func(t *testing.T) {
ch := makeKeyChan([]keyID{
makeKey(t, "abc", int64(2), int64(42)),
makeKey(t, int64(42)),
})
count := 0
for range ch {
count++
}
require.Equal(t, 2, count)
})
t.Run("Migrate", func(t *testing.T) {
_, db := getLegacyDatabase(t)