2020-12-17 20:40:47 +00:00
|
|
|
package stategen
|
2020-03-04 22:09:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
|
|
|
|
state_native "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/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
|
|
|
|
2022-09-16 22:17:46 +00:00
|
|
|
s, err := state_native.InitializeFromProtoPhase0(ð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)
|
2022-10-19 14:37:45 +00:00
|
|
|
assert.DeepEqual(t, res.ToProto(), s.ToProto(), "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
|
|
|
}
|