2020-12-17 20:40:47 +00:00
|
|
|
package stategen
|
2020-03-04 22:09:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-03-08 22:37:33 +00:00
|
|
|
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
2021-06-30 15:06:19 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
2020-03-04 22:09:21 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
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'}
|
2020-12-17 20:40:47 +00:00
|
|
|
state := c.get(root)
|
2021-03-10 20:38:16 +00:00
|
|
|
assert.Equal(t, iface.BeaconState(nil), state)
|
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-06-30 15:06:19 +00:00
|
|
|
state, 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)
|
|
|
|
|
2020-12-17 20:40:47 +00:00
|
|
|
c.put(root, state)
|
|
|
|
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)
|
2020-07-16 19:34:08 +00:00
|
|
|
assert.NotNil(t, state)
|
|
|
|
assert.DeepEqual(t, res.CloneInnerState(), state.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
|
|
|
}
|