2022-01-24 19:53:05 +00:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_store_PrevJustifiedCheckpt(t *testing.T) {
|
2022-01-25 18:47:39 +00:00
|
|
|
s := &Store{}
|
2022-01-24 19:53:05 +00:00
|
|
|
var cp *ethpb.Checkpoint
|
2022-05-20 18:41:33 +00:00
|
|
|
_, err := s.PrevJustifiedCheckpt()
|
|
|
|
require.ErrorIs(t, ErrNilCheckpoint, err)
|
2022-01-24 19:53:05 +00:00
|
|
|
cp = ðpb.Checkpoint{Epoch: 1, Root: []byte{'a'}}
|
|
|
|
s.SetPrevJustifiedCheckpt(cp)
|
2022-05-20 18:41:33 +00:00
|
|
|
got, err := s.PrevJustifiedCheckpt()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, cp, got)
|
2022-01-24 19:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test_store_BestJustifiedCheckpt(t *testing.T) {
|
2022-01-25 18:47:39 +00:00
|
|
|
s := &Store{}
|
2022-01-24 19:53:05 +00:00
|
|
|
var cp *ethpb.Checkpoint
|
2022-05-20 18:41:33 +00:00
|
|
|
_, err := s.BestJustifiedCheckpt()
|
|
|
|
require.ErrorIs(t, ErrNilCheckpoint, err)
|
2022-01-24 19:53:05 +00:00
|
|
|
cp = ðpb.Checkpoint{Epoch: 1, Root: []byte{'a'}}
|
|
|
|
s.SetBestJustifiedCheckpt(cp)
|
2022-05-20 18:41:33 +00:00
|
|
|
got, err := s.BestJustifiedCheckpt()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, cp, got)
|
2022-01-24 19:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test_store_JustifiedCheckpt(t *testing.T) {
|
2022-01-25 18:47:39 +00:00
|
|
|
s := &Store{}
|
2022-01-24 19:53:05 +00:00
|
|
|
var cp *ethpb.Checkpoint
|
2022-05-20 18:41:33 +00:00
|
|
|
_, err := s.JustifiedCheckpt()
|
|
|
|
require.ErrorIs(t, ErrNilCheckpoint, err)
|
2022-01-24 19:53:05 +00:00
|
|
|
cp = ðpb.Checkpoint{Epoch: 1, Root: []byte{'a'}}
|
2022-05-10 21:20:28 +00:00
|
|
|
h := [32]byte{'b'}
|
|
|
|
s.SetJustifiedCheckptAndPayloadHash(cp, h)
|
2022-05-20 18:41:33 +00:00
|
|
|
got, err := s.JustifiedCheckpt()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, cp, got)
|
2022-05-10 21:20:28 +00:00
|
|
|
require.Equal(t, h, s.JustifiedPayloadBlockHash())
|
2022-01-24 19:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test_store_FinalizedCheckpt(t *testing.T) {
|
2022-01-25 18:47:39 +00:00
|
|
|
s := &Store{}
|
2022-01-24 19:53:05 +00:00
|
|
|
var cp *ethpb.Checkpoint
|
2022-05-20 18:41:33 +00:00
|
|
|
_, err := s.FinalizedCheckpt()
|
|
|
|
require.ErrorIs(t, ErrNilCheckpoint, err)
|
2022-01-24 19:53:05 +00:00
|
|
|
cp = ðpb.Checkpoint{Epoch: 1, Root: []byte{'a'}}
|
2022-05-10 21:20:28 +00:00
|
|
|
h := [32]byte{'b'}
|
|
|
|
s.SetFinalizedCheckptAndPayloadHash(cp, h)
|
2022-05-20 18:41:33 +00:00
|
|
|
got, err := s.FinalizedCheckpt()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, cp, got)
|
2022-05-10 21:20:28 +00:00
|
|
|
require.Equal(t, h, s.FinalizedPayloadBlockHash())
|
2022-01-24 19:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test_store_PrevFinalizedCheckpt(t *testing.T) {
|
2022-01-25 18:47:39 +00:00
|
|
|
s := &Store{}
|
2022-01-24 19:53:05 +00:00
|
|
|
var cp *ethpb.Checkpoint
|
2022-05-20 18:41:33 +00:00
|
|
|
_, err := s.PrevFinalizedCheckpt()
|
|
|
|
require.ErrorIs(t, ErrNilCheckpoint, err)
|
2022-01-24 19:53:05 +00:00
|
|
|
cp = ðpb.Checkpoint{Epoch: 1, Root: []byte{'a'}}
|
|
|
|
s.SetPrevFinalizedCheckpt(cp)
|
2022-05-20 18:41:33 +00:00
|
|
|
got, err := s.PrevFinalizedCheckpt()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, cp, got)
|
2022-01-24 19:53:05 +00:00
|
|
|
}
|