github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/state/stategen/hot_state_cache_test.go (about) 1 package stategen 2 3 import ( 4 "testing" 5 6 iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface" 7 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" 8 pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" 9 "github.com/prysmaticlabs/prysm/shared/testutil/assert" 10 "github.com/prysmaticlabs/prysm/shared/testutil/require" 11 ) 12 13 func TestHotStateCache_RoundTrip(t *testing.T) { 14 c := newHotStateCache() 15 root := [32]byte{'A'} 16 state := c.get(root) 17 assert.Equal(t, iface.BeaconState(nil), state) 18 assert.Equal(t, false, c.has(root), "Empty cache has an object") 19 20 state, err := v1.InitializeFromProto(&pb.BeaconState{ 21 Slot: 10, 22 }) 23 require.NoError(t, err) 24 25 c.put(root, state) 26 assert.Equal(t, true, c.has(root), "Empty cache does not have an object") 27 28 res := c.get(root) 29 assert.NotNil(t, state) 30 assert.DeepEqual(t, res.CloneInnerState(), state.CloneInnerState(), "Expected equal protos to return from cache") 31 32 c.delete(root) 33 assert.Equal(t, false, c.has(root), "Cache not supposed to have the object") 34 }