mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 23:41:22 +00:00
f5cb04012e
* Config * Updated proto * Updated pool * Updated RPC * Updated validator client * run time works * Clean ups * Fix tests * Visibility * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into aggregator * Raul's feedback * Tests for RPC server * Tests for validator client * Span * More tests * Use go routine for SubmitAggregateAndProof * Go routines * Updated comments * Use array of roles * Fixed tests * Build * Update validator/client/runner.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/client/runner.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * If * Merge branch 'refactor-validator-roles' of https://github.com/prysmaticlabs/prysm into refactor-validator-roles * Empty * Feedback * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into aggregator * Removed proto/eth/v1alpha1/shard_chain.pb.go? * Cleaned up * Revert * Comments * Lint * Comment * Merge branch 'master' into aggregator
100 lines
2.8 KiB
Go
100 lines
2.8 KiB
Go
package aggregator
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rand"
|
|
"strings"
|
|
"testing"
|
|
|
|
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
|
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
|
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
func init() {
|
|
// Use minimal config to reduce test setup time.
|
|
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
|
}
|
|
|
|
func TestSubmitAggregateAndProof_Syncing(t *testing.T) {
|
|
db := dbutil.SetupDB(t)
|
|
defer dbutil.TeardownDB(t, db)
|
|
ctx := context.Background()
|
|
|
|
s := &pbp2p.BeaconState{}
|
|
|
|
aggregatorServer := &Server{
|
|
HeadFetcher: &mock.ChainService{State: s},
|
|
SyncChecker: &mockSync.Sync{IsSyncing: true},
|
|
BeaconDB: db,
|
|
}
|
|
|
|
req := &pb.AggregationRequest{CommitteeIndex: 1}
|
|
wanted := "Syncing to latest head, not ready to respond"
|
|
if _, err := aggregatorServer.SubmitAggregateAndProof(ctx, req); !strings.Contains(err.Error(), wanted) {
|
|
t.Error("Did not receive wanted error")
|
|
}
|
|
}
|
|
|
|
func TestSubmitAggregateAndProof_CantFindValidatorIndex(t *testing.T) {
|
|
db := dbutil.SetupDB(t)
|
|
defer dbutil.TeardownDB(t, db)
|
|
ctx := context.Background()
|
|
|
|
s := &pbp2p.BeaconState{
|
|
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
|
}
|
|
|
|
aggregatorServer := &Server{
|
|
HeadFetcher: &mock.ChainService{State: s},
|
|
SyncChecker: &mockSync.Sync{IsSyncing: false},
|
|
BeaconDB: db,
|
|
}
|
|
|
|
priv, err := bls.RandKey(rand.Reader)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sig := priv.Sign([]byte{'A'}, 0)
|
|
req := &pb.AggregationRequest{CommitteeIndex: 1, SlotSignature: sig.Marshal()}
|
|
wanted := "Could not locate validator index in DB"
|
|
if _, err := aggregatorServer.SubmitAggregateAndProof(ctx, req); !strings.Contains(err.Error(), wanted) {
|
|
t.Error("Did not receive wanted error")
|
|
}
|
|
}
|
|
|
|
func TestSubmitAggregateAndProof_IsAggregator(t *testing.T) {
|
|
db := dbutil.SetupDB(t)
|
|
defer dbutil.TeardownDB(t, db)
|
|
ctx := context.Background()
|
|
|
|
s := &pbp2p.BeaconState{
|
|
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
|
}
|
|
|
|
aggregatorServer := &Server{
|
|
HeadFetcher: &mock.ChainService{State: s},
|
|
SyncChecker: &mockSync.Sync{IsSyncing: false},
|
|
BeaconDB: db,
|
|
}
|
|
|
|
priv, err := bls.RandKey(rand.Reader)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sig := priv.Sign([]byte{'A'}, 0)
|
|
pubKey := [48]byte{'A'}
|
|
req := &pb.AggregationRequest{CommitteeIndex: 1, SlotSignature: sig.Marshal(), PublicKey: pubKey[:]}
|
|
if err := aggregatorServer.BeaconDB.SaveValidatorIndex(ctx, pubKey, 100); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if _, err = aggregatorServer.SubmitAggregateAndProof(ctx, req); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|