prysm-pulse/slasher/cache/committees_cache_test.go
shayzluf 02b6d7706f
Slasher committees cache (#4812)
* add committees cache
* committees cache usage
* fix test
* fix log
* goimports
* Merge branch 'master' of github.com:prysmaticlabs/prysm into slasher_committees_cache

# Conflicts:
#	slasher/service/data_update.go
* fix imports
* fix comment
* fix comment
* Merge refs/heads/master into slasher_committees_cache
* Merge refs/heads/master into slasher_committees_cache
* Update slasher/cache/BUILD.bazel

Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com>
* Merge refs/heads/master into slasher_committees_cache
* Merge refs/heads/master into slasher_committees_cache
* Merge refs/heads/master into slasher_committees_cache
* added in the service context
* baz
* Merge refs/heads/master into slasher_committees_cache
* Merge refs/heads/master into slasher_committees_cache
2020-02-10 20:09:14 +00:00

48 lines
1.1 KiB
Go

package cache_test
import (
"context"
"reflect"
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/slasher/cache"
)
func TestCommitteesCache_RoundTrip(t *testing.T) {
ctx := context.Background()
c := cache.NewCommitteesCache()
numValidators := 64
wanted := make(map[uint64]*ethpb.BeaconCommittees_CommitteesList)
committeeItems := make([]*ethpb.BeaconCommittees_CommitteeItem, 1)
committeeItems[0] = &ethpb.BeaconCommittees_CommitteeItem{ValidatorIndices: []uint64{1, 2, 3}}
wanted[0] = &ethpb.BeaconCommittees_CommitteesList{Committees: committeeItems}
wantedRes := &ethpb.BeaconCommittees{
Epoch: 5,
Committees: wanted,
ActiveValidatorCount: uint64(numValidators),
}
committees, err := c.Get(ctx, 5)
if err != nil {
t.Error(err)
}
if committees != nil {
t.Errorf("Empty cache returned an object: %v", committees)
}
if err = c.Put(ctx, 5, wantedRes); err != nil {
t.Error(err)
}
res, err := c.Get(ctx, 5)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(wantedRes, res) {
t.Error("Expected equal protos to return from cache")
}
}