prysm-pulse/beacon-chain/sync/service_test.go
frederickalcantara a170c69653 upgrading linter from gometalinter to golangci-lint (#2100)
* upgrading linter from gometalinter to golangci-lint

* fixed golangci-lint linting

* removed linting before_script command

* removed disable-all command

* Fixed golang config file

* fixed golang config file v2

* removed gosec issue rule

* formatting

* fixed travis build to run golangci-lint

* Add install golangci-lint command

* fixing golangci-lint script

* removed https://

* Added golangci-lint cmd script

* added go get for local lint install

* created a before_script

* add install before script

* Added get script

* added go mod download

* removed go mod downloads

* changed

* removed before script

* Added before script go get lint

* added exit zero to see what went wrong

* removed golang run script

* removed before script

* change lint command

* verbose output

* removed verbose

* change linter enable and disable configuration

* Update .golangci.yml

Removed gotype as a linter

* Update .golangci.yml

Added typecheck linter

* Update .golangci.yml

Added fixed lint version

* Update .golangci.yml

Added gotype

* Update .golangci.yml

Added typecheck

* removed env:lint

* Added env lint

* fixing lint upgrade

* Changing travis configuration

* FIxed spelling errors

* disabled typecheck

* Enabled typecheck

* remove binary

* Deleting lib binary

* adding more linters

* fixed constants

* fix spelling

* fixed all lint issues

* Revert "Changing travis configuration"

This reverts commit 334afe9d05e96261b01f275aa3ada20e7f36aac4.

* Merge branch 'master' of https://github.com/prysmaticlabs/prysm into update-linter

* Changed from Infof to Info

* Fixing commits

* fixing commits with linter config

* added install

* Fixing

* fix log statement
2019-04-26 14:24:01 +08:00

101 lines
2.5 KiB
Go

package sync
import (
"context"
"crypto/rand"
"testing"
"time"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
)
func NotSyncQuerierConfig() *QuerierConfig {
return &QuerierConfig{
ResponseBufferSize: 100,
CurrentHeadSlot: 10,
}
}
func init() {
featureconfig.InitFeatureConfig(&featureconfig.FeatureFlagConfig{})
}
func initializeTestSyncService(ctx context.Context, cfg *Config, synced bool) *Service {
var sqCfg *QuerierConfig
if synced {
sqCfg = DefaultQuerierConfig()
} else {
sqCfg = NotSyncQuerierConfig()
}
services := NewSyncService(ctx, cfg)
sqCfg.BeaconDB = cfg.BeaconDB
sqCfg.P2P = cfg.P2P
sq := NewQuerierService(ctx, sqCfg)
services.Querier = sq
return services
}
func setupInitialDeposits(t *testing.T) ([]*pb.Deposit, []*bls.SecretKey) {
numOfDeposits := 10
privKeys := make([]*bls.SecretKey, numOfDeposits)
deposits := make([]*pb.Deposit, numOfDeposits)
for i := 0; i < len(deposits); i++ {
priv, err := bls.RandKey(rand.Reader)
if err != nil {
t.Fatal(err)
}
depositInput := &pb.DepositInput{
Pubkey: priv.PublicKey().Marshal(),
}
balance := params.BeaconConfig().MaxDepositAmount
depositData, err := helpers.EncodeDepositData(depositInput, balance, time.Now().Unix())
if err != nil {
t.Fatalf("Cannot encode data: %v", err)
}
deposits[i] = &pb.Deposit{DepositData: depositData}
privKeys[i] = priv
}
return deposits, privKeys
}
func setupTestSyncService(t *testing.T, synced bool) (*Service, *db.BeaconDB) {
db := internal.SetupDB(t)
unixTime := uint64(time.Now().Unix())
deposits, _ := setupInitialDeposits(t)
if err := db.InitializeState(context.Background(), unixTime, deposits, &pb.Eth1Data{}); err != nil {
t.Fatalf("Failed to initialize state: %v", err)
}
cfg := &Config{
ChainService: &mockChainService{
db: db,
},
P2P: &mockP2P{},
BeaconDB: db,
OperationService: &mockOperationService{},
}
service := initializeTestSyncService(context.Background(), cfg, synced)
return service, db
}
func TestStatus_NotSynced(t *testing.T) {
serviceNotSynced, db := setupTestSyncService(t, false)
defer internal.TeardownDB(t, db)
synced, _ := serviceNotSynced.InitialSync.NodeIsSynced()
if synced {
t.Error("Wanted false, but got true")
}
}