prysm-pulse/beacon-chain/state/stategen/hot_state_cache_test.go
terence tsao df93affb4e
Move hot state cache to stategen (#8153)
* Move hot state cache to stategen

* Fix build.bazel

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2020-12-17 20:40:47 +00:00

34 lines
975 B
Go

package stategen
import (
"testing"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestHotStateCache_RoundTrip(t *testing.T) {
c := newHotStateCache()
root := [32]byte{'A'}
state := c.get(root)
assert.Equal(t, (*stateTrie.BeaconState)(nil), state)
assert.Equal(t, false, c.has(root), "Empty cache has an object")
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
Slot: 10,
})
require.NoError(t, err)
c.put(root, state)
assert.Equal(t, true, c.has(root), "Empty cache does not have an object")
res := c.get(root)
assert.NotNil(t, state)
assert.DeepEqual(t, res.CloneInnerState(), state.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")
}