mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
b7175b3482
* Revert "Revert "Update fastssz" (#7100)"
This reverts commit b954db9704
.
* Preston's patch
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Update fssz, add regression test case
* more HTR with fssz
* fix some tests
* only one test left
* Make it so that HTR will work
* gofmt, imports
* gofmt, imports
* fix
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* fix
* Merge branch 'master' into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* gaz
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* fix test
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
108 lines
3.4 KiB
Go
108 lines
3.4 KiB
Go
package kv
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"go.etcd.io/bbolt"
|
|
)
|
|
|
|
func Test_migrateArchivedIndex(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) {
|
|
err := db.Update(func(tx *bbolt.Tx) error {
|
|
_, err := tx.CreateBucketIfNotExists(archivedRootBucket)
|
|
assert.NoError(t, err)
|
|
if err := tx.Bucket(archivedRootBucket).Put(bytesutil.Uint64ToBytesLittleEndian(2048), []byte("foo")); err != nil {
|
|
return err
|
|
}
|
|
return tx.Bucket(migrationsBucket).Put(migrationArchivedIndex0Key, migrationCompleted)
|
|
})
|
|
assert.NoError(t, err)
|
|
},
|
|
eval: func(t *testing.T, db *bbolt.DB) {
|
|
err := db.View(func(tx *bbolt.Tx) error {
|
|
v := tx.Bucket(archivedRootBucket).Get(bytesutil.Uint64ToBytesLittleEndian(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
|
|
})
|
|
assert.NoError(t, err)
|
|
},
|
|
},
|
|
{
|
|
name: "migrates and deletes entries",
|
|
setup: func(t *testing.T, db *bbolt.DB) {
|
|
err := db.Update(func(tx *bbolt.Tx) error {
|
|
_, err := tx.CreateBucketIfNotExists(archivedRootBucket)
|
|
assert.NoError(t, err)
|
|
_, err = tx.CreateBucketIfNotExists(slotsHasObjectBucket)
|
|
assert.NoError(t, err)
|
|
if err := tx.Bucket(archivedRootBucket).Put(bytesutil.Uint64ToBytesLittleEndian(2048), []byte("foo")); err != nil {
|
|
return err
|
|
}
|
|
sb := testutil.NewBeaconBlock()
|
|
sb.Block.Slot = 2048
|
|
b, err := encode(context.Background(), sb)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return tx.Bucket(blocksBucket).Put([]byte("foo"), b)
|
|
})
|
|
assert.NoError(t, err)
|
|
},
|
|
eval: func(t *testing.T, db *bbolt.DB) {
|
|
err := db.View(func(tx *bbolt.Tx) error {
|
|
k := uint64(2048)
|
|
if v := tx.Bucket(stateSlotIndicesBucket).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
|
|
})
|
|
assert.NoError(t, err)
|
|
},
|
|
},
|
|
{
|
|
name: "deletes old buckets",
|
|
setup: func(t *testing.T, db *bbolt.DB) {
|
|
err := db.Update(func(tx *bbolt.Tx) error {
|
|
_, err := tx.CreateBucketIfNotExists(archivedRootBucket)
|
|
assert.NoError(t, err)
|
|
_, err = tx.CreateBucketIfNotExists(slotsHasObjectBucket)
|
|
assert.NoError(t, err)
|
|
return tx.Bucket(slotsHasObjectBucket).Put(savedStateSlotsKey, []byte("foo"))
|
|
})
|
|
assert.NoError(t, err)
|
|
},
|
|
eval: func(t *testing.T, db *bbolt.DB) {
|
|
err := db.View(func(tx *bbolt.Tx) error {
|
|
assert.Equal(t, (*bbolt.Bucket)(nil), tx.Bucket(slotsHasObjectBucket), "Expected %v to be deleted", savedStateSlotsKey)
|
|
assert.Equal(t, (*bbolt.Bucket)(nil), tx.Bucket(archivedRootBucket), "Expected %v to be deleted", savedStateSlotsKey)
|
|
return nil
|
|
})
|
|
assert.NoError(t, err)
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
db := setupDB(t).db
|
|
tt.setup(t, db)
|
|
assert.NoError(t, db.Update(migrateArchivedIndex), "migrateArchivedIndex(tx) error")
|
|
tt.eval(t, db)
|
|
})
|
|
}
|
|
}
|