mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
|
)
|
|
|
|
func TestArchivedPointIndexRoot_CanSaveRetrieve(t *testing.T) {
|
|
db := setupDB(t)
|
|
ctx := context.Background()
|
|
i1 := types.Slot(100)
|
|
r1 := [32]byte{'A'}
|
|
|
|
received := db.ArchivedPointRoot(ctx, i1)
|
|
require.NotEqual(t, r1, received, "Should not have been saved")
|
|
st, err := util.NewBeaconState()
|
|
require.NoError(t, err)
|
|
require.NoError(t, st.SetSlot(i1))
|
|
require.NoError(t, db.SaveState(ctx, st, r1))
|
|
received = db.ArchivedPointRoot(ctx, i1)
|
|
assert.Equal(t, r1, received, "Should have been saved")
|
|
}
|
|
|
|
func TestLastArchivedPoint_CanRetrieve(t *testing.T) {
|
|
db := setupDB(t)
|
|
ctx := context.Background()
|
|
i, err := db.LastArchivedSlot(ctx)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, types.Slot(0), i, "Did not get correct index")
|
|
|
|
st, err := util.NewBeaconState()
|
|
require.NoError(t, err)
|
|
assert.NoError(t, db.SaveState(ctx, st, [32]byte{'A'}))
|
|
assert.Equal(t, [32]byte{'A'}, db.LastArchivedRoot(ctx), "Did not get wanted root")
|
|
|
|
assert.NoError(t, st.SetSlot(2))
|
|
assert.NoError(t, db.SaveState(ctx, st, [32]byte{'B'}))
|
|
assert.Equal(t, [32]byte{'B'}, db.LastArchivedRoot(ctx))
|
|
|
|
assert.NoError(t, st.SetSlot(3))
|
|
assert.NoError(t, db.SaveState(ctx, st, [32]byte{'C'}))
|
|
|
|
i, err = db.LastArchivedSlot(ctx)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, types.Slot(3), i, "Did not get correct index")
|
|
}
|