2020-12-17 20:40:47 +00:00
|
|
|
package stategen
|
2020-03-04 22:09:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
2022-09-16 22:17:46 +00:00
|
|
|
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
2022-08-16 12:20:13 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/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)
|
|
|
|
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
|
|
|
}
|