2020-03-02 04:27:56 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
2020-08-08 18:39:01 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-03-02 04:27:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStateSummary_CanSaveRretrieve(t *testing.T) {
|
|
|
|
db := setupDB(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
r1 := bytesutil.ToBytes32([]byte{'A'})
|
|
|
|
r2 := bytesutil.ToBytes32([]byte{'B'})
|
2020-03-27 20:28:38 +00:00
|
|
|
s1 := &pb.StateSummary{Slot: 1, Root: r1[:]}
|
2020-03-02 04:27:56 +00:00
|
|
|
|
|
|
|
// State summary should not exist yet.
|
2020-08-08 18:39:01 +00:00
|
|
|
require.Equal(t, false, db.HasStateSummary(ctx, r1), "State summary should not be saved")
|
|
|
|
require.NoError(t, db.SaveStateSummary(ctx, s1))
|
|
|
|
require.Equal(t, true, db.HasStateSummary(ctx, r1), "State summary should be saved")
|
2020-03-02 04:27:56 +00:00
|
|
|
|
|
|
|
saved, err := db.StateSummary(ctx, r1)
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.DeepEqual(t, s1, saved, "State summary does not equal")
|
2020-03-02 04:27:56 +00:00
|
|
|
|
|
|
|
// Save a new state summary.
|
2020-03-27 20:28:38 +00:00
|
|
|
s2 := &pb.StateSummary{Slot: 2, Root: r2[:]}
|
2020-03-02 04:27:56 +00:00
|
|
|
|
|
|
|
// State summary should not exist yet.
|
2020-08-08 18:39:01 +00:00
|
|
|
require.Equal(t, false, db.HasStateSummary(ctx, r2), "State summary should not be saved")
|
|
|
|
require.NoError(t, db.SaveStateSummary(ctx, s2))
|
|
|
|
require.Equal(t, true, db.HasStateSummary(ctx, r2), "State summary should be saved")
|
2020-03-02 04:27:56 +00:00
|
|
|
|
|
|
|
saved, err = db.StateSummary(ctx, r2)
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.DeepEqual(t, s2, saved, "State summary does not equal")
|
2020-03-02 04:27:56 +00:00
|
|
|
}
|