mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-17 23:38:46 +00:00
c419e4ed8f
* Add database migrations, still need to update the API usage... * gofmt goimports * progress * Merge branch 'master' of github.com:prysmaticlabs/prysm into index-migration * use slot instead of index * rename LastArchivedIndex to LastArchivedSlot * rename LastArchivedIndexRoot to LastArchivedRoot * remove unused HighestSlotStates method * deprecate old key, include in migration * deprecate old key, include in migration * remove blocks index in migration * rename bucket variable * fix code to pass tests * Merge branch 'master' of github.com:prysmaticlabs/prysm into index-migration * gofmt, goimports * fix * Add state slot index * progress * lint * fix build * Merge branch 'master' of github.com:prysmaticlabs/prysm into index-migration * kafka * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * remove SaveArchivedPointRoot, a few other big changes * Merge branch 'index-migration' of github.com:prysmaticlabs/prysm into index-migration * fix tests and lint * lint again * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * block migration, some renaming * gaz, gofmt * add tests * change index to uint bytes * Merge branch 'index-migration' of github.com:prysmaticlabs/prysm into index-migration * rm method notes * stop if the bucket doesn't exist * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * @rauljordan pr feedback * Simplify * Merge refs/heads/master into index-migration * Remove unused method, add roundtrip test * gofmt * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge refs/heads/master into index-migration * Merge branch 'master' of github.com:prysmaticlabs/prysm into index-migration
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package kv
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
"go.etcd.io/bbolt"
|
|
)
|
|
|
|
func Test_migrateBlockSlotIndex(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
setup func(t *testing.T, db *bbolt.DB)
|
|
eval func(t *testing.T, db *bbolt.DB)
|
|
}{
|
|
{
|
|
name: "only runs once",
|
|
setup: func(t *testing.T, db *bbolt.DB) {
|
|
if err := db.Update(func(tx *bbolt.Tx) error {
|
|
if err := tx.Bucket(blockSlotIndicesBucket).Put([]byte("2048"), []byte("foo")); err != nil {
|
|
return err
|
|
}
|
|
return tx.Bucket(migrationsBucket).Put(migrationBlockSlotIndex0Key, migrationCompleted)
|
|
}); err != nil {
|
|
t.Error(err)
|
|
}
|
|
},
|
|
eval: func(t *testing.T, db *bbolt.DB) {
|
|
if err := db.View(func(tx *bbolt.Tx) error {
|
|
v := tx.Bucket(blockSlotIndicesBucket).Get([]byte("2048"))
|
|
if !bytes.Equal(v, []byte("foo")) {
|
|
return fmt.Errorf("did not receive correct data for key 2048, wanted 'foo' got %s", v)
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
t.Error(err)
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: "migrates and deletes entries",
|
|
setup: func(t *testing.T, db *bbolt.DB) {
|
|
if err := db.Update(func(tx *bbolt.Tx) error {
|
|
return tx.Bucket(blockSlotIndicesBucket).Put([]byte("2048"), []byte("foo"))
|
|
}); err != nil {
|
|
t.Error(err)
|
|
}
|
|
},
|
|
eval: func(t *testing.T, db *bbolt.DB) {
|
|
if err := db.View(func(tx *bbolt.Tx) error {
|
|
k := uint64(2048)
|
|
if v := tx.Bucket(blockSlotIndicesBucket).Get(bytesutil.Uint64ToBytesBigEndian(k)); !bytes.Equal(v, []byte("foo")) {
|
|
return fmt.Errorf("did not receive correct data for key %d, wanted 'foo' got %v", k, v)
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
t.Error(err)
|
|
}
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
db := setupDB(t).db
|
|
tt.setup(t, db)
|
|
if err := db.Update(migrateBlockSlotIndex); err != nil {
|
|
t.Errorf("migrateBlockSlotIndex(tx) error = %v", err)
|
|
}
|
|
tt.eval(t, db)
|
|
})
|
|
}
|
|
}
|