mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 05:38:55 +00:00
139f51efaa
* Add hot state cache * Gaz * Test * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into state-gen-lru-cache * Merge refs/heads/master into state-gen-lru-cache
42 lines
929 B
Go
42 lines
929 B
Go
package cache_test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
|
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
)
|
|
|
|
func TestHotStateCache_RoundTrip(t *testing.T) {
|
|
c := cache.NewHotStateCache()
|
|
root := [32]byte{'A'}
|
|
state := c.Get(root)
|
|
if state != nil {
|
|
t.Errorf("Empty cache returned an object: %v", state)
|
|
}
|
|
if c.Has(root) {
|
|
t.Error("Empty cache has an object")
|
|
}
|
|
|
|
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
|
Slot: 10,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c.Put(root, state)
|
|
|
|
if !c.Has(root) {
|
|
t.Error("Empty cache does not have an object")
|
|
}
|
|
res := c.Get(root)
|
|
if state == nil {
|
|
t.Errorf("Empty cache returned an object: %v", state)
|
|
}
|
|
if !reflect.DeepEqual(state.CloneInnerState(), res.CloneInnerState()) {
|
|
t.Error("Expected equal protos to return from cache")
|
|
}
|
|
}
|