prysm-pulse/beacon-chain/state/stategen/hot_state_cache_test.go
Raul Jordan a9a4bb9163
Move Shared/Testutil into Testing (#9659)
* move testutil

* util pkg

* build

* gaz

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-09-23 18:53:46 +00:00

35 lines
977 B
Go

package stategen
import (
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/assert"
"github.com/prysmaticlabs/prysm/testing/require"
)
func TestHotStateCache_RoundTrip(t *testing.T) {
c := newHotStateCache()
root := [32]byte{'A'}
s := c.get(root)
assert.Equal(t, state.BeaconState(nil), s)
assert.Equal(t, false, c.has(root), "Empty cache has an object")
s, err := v1.InitializeFromProto(&ethpb.BeaconState{
Slot: 10,
})
require.NoError(t, err)
c.put(root, s)
assert.Equal(t, true, c.has(root), "Empty cache does not have an object")
res := c.get(root)
assert.NotNil(t, s)
assert.DeepEqual(t, res.CloneInnerState(), s.CloneInnerState(), "Expected equal protos to return from cache")
c.delete(root)
assert.Equal(t, false, c.has(root), "Cache not supposed to have the object")
}