mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
77607c6fdb
* testutils for cache * Merge branch 'master' into cache-test-refactor * removed some empty lines * Merge branch 'origin-master' into cache-test-refactor * Merge remote-tracking branch 'rkapka/cache-test-refactor' into cache-test-refactor * revert package names
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package cache_test
|
|
|
|
import (
|
|
"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"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestHotStateCache_RoundTrip(t *testing.T) {
|
|
c := cache.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")
|
|
}
|