mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
02b6d7706f
* 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
48 lines
1.1 KiB
Go
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] = ðpb.BeaconCommittees_CommitteeItem{ValidatorIndices: []uint64{1, 2, 3}}
|
|
wanted[0] = ðpb.BeaconCommittees_CommitteesList{Committees: committeeItems}
|
|
wantedRes := ðpb.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")
|
|
}
|
|
}
|