2020-12-17 20:40:47 +00:00
|
|
|
package stategen
|
2020-03-04 22:09:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
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-29 21:45:17 +00:00
|
|
|
ethpb "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-03-04 22:09:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHotStateCache_RoundTrip(t *testing.T) {
|
2020-12-17 20:40:47 +00:00
|
|
|
c := newHotStateCache()
|
2020-03-04 22:09:21 +00:00
|
|
|
root := [32]byte{'A'}
|
2021-07-23 16:11:21 +00:00
|
|
|
s := c.get(root)
|
|
|
|
assert.Equal(t, state.BeaconState(nil), s)
|
2020-12-17 20:40:47 +00:00
|
|
|
assert.Equal(t, false, c.has(root), "Empty cache has an object")
|
2020-03-04 22:09:21 +00:00
|
|
|
|
2021-07-29 21:45:17 +00:00
|
|
|
s, err := v1.InitializeFromProto(ðpb.BeaconState{
|
2020-03-04 22:09:21 +00:00
|
|
|
Slot: 10,
|
|
|
|
})
|
2020-07-16 19:34:08 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-23 16:11:21 +00:00
|
|
|
c.put(root, s)
|
2020-12-17 20:40:47 +00:00
|
|
|
assert.Equal(t, true, c.has(root), "Empty cache does not have an object")
|
2020-03-04 22:09:21 +00:00
|
|
|
|
2020-12-17 20:40:47 +00:00
|
|
|
res := c.get(root)
|
2021-07-23 16:11:21 +00:00
|
|
|
assert.NotNil(t, s)
|
|
|
|
assert.DeepEqual(t, res.CloneInnerState(), s.CloneInnerState(), "Expected equal protos to return from cache")
|
2020-05-08 19:02:48 +00:00
|
|
|
|
2020-12-17 20:40:47 +00:00
|
|
|
c.delete(root)
|
|
|
|
assert.Equal(t, false, c.has(root), "Cache not supposed to have the object")
|
2020-03-04 22:09:21 +00:00
|
|
|
}
|