2020-01-21 02:19:42 +00:00
|
|
|
package cache_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
2021-07-23 16:11:21 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
2021-07-22 17:13:18 +00:00
|
|
|
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
2021-07-28 21:23:44 +00:00
|
|
|
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2020-07-16 19:34:08 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-01-21 02:19:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSkipSlotCache_RoundTrip(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := cache.NewSkipSlotCache()
|
|
|
|
|
2020-10-28 03:09:05 +00:00
|
|
|
r := [32]byte{'a'}
|
2021-07-23 16:11:21 +00:00
|
|
|
s, err := c.Get(ctx, r)
|
2020-07-16 19:34:08 +00:00
|
|
|
require.NoError(t, err)
|
2021-07-23 16:11:21 +00:00
|
|
|
assert.Equal(t, state.BeaconState(nil), s, "Empty cache returned an object")
|
2020-01-21 02:19:42 +00:00
|
|
|
|
2020-10-28 03:09:05 +00:00
|
|
|
require.NoError(t, c.MarkInProgress(r))
|
2020-01-21 02:19:42 +00:00
|
|
|
|
2021-07-23 16:11:21 +00:00
|
|
|
s, err = v1.InitializeFromProto(&statepb.BeaconState{
|
2020-01-31 20:57:01 +00:00
|
|
|
Slot: 10,
|
|
|
|
})
|
2020-07-16 19:34:08 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-21 02:19:42 +00:00
|
|
|
|
2021-07-23 16:11:21 +00:00
|
|
|
require.NoError(t, c.Put(ctx, r, s))
|
2020-10-28 03:09:05 +00:00
|
|
|
require.NoError(t, c.MarkNotInProgress(r))
|
2020-01-21 02:19:42 +00:00
|
|
|
|
2020-10-28 03:09:05 +00:00
|
|
|
res, err := c.Get(ctx, r)
|
2020-07-16 19:34:08 +00:00
|
|
|
require.NoError(t, err)
|
2021-07-23 16:11:21 +00:00
|
|
|
assert.DeepEqual(t, res.CloneInnerState(), s.CloneInnerState(), "Expected equal protos to return from cache")
|
2020-01-21 02:19:42 +00:00
|
|
|
}
|