Verify interface compliance using typed nil instead of dereferencing and conversion (#7489)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Victor Farazdagi
2020-10-10 03:36:48 +03:00
committed by GitHub
parent 8aaa5b6ad0
commit d98a6dda8f
30 changed files with 37 additions and 37 deletions

View File

@@ -18,9 +18,9 @@ import (
) )
// Ensure Service implements chain info interface. // Ensure Service implements chain info interface.
var _ = ChainInfoFetcher(&Service{}) var _ ChainInfoFetcher = (*Service)(nil)
var _ = TimeFetcher(&Service{}) var _ TimeFetcher = (*Service)(nil)
var _ = ForkFetcher(&Service{}) var _ ForkFetcher = (*Service)(nil)
func TestFinalizedCheckpt_Nil(t *testing.T) { func TestFinalizedCheckpt_Nil(t *testing.T) {
db, sc := testDB.SetupDB(t) db, sc := testDB.SetupDB(t)

View File

@@ -67,7 +67,7 @@ func (mb *mockBroadcaster) BroadcastAttestation(_ context.Context, _ uint64, _ *
return nil return nil
} }
var _ = p2p.Broadcaster(&mockBroadcaster{}) var _ p2p.Broadcaster = (*mockBroadcaster)(nil)
func setupBeaconChain(t *testing.T, beaconDB db.Database, sc *cache.StateSummaryCache) *Service { func setupBeaconChain(t *testing.T, beaconDB db.Database, sc *cache.StateSummaryCache) *Service {
endpoint := "http://127.0.0.1" endpoint := "http://127.0.0.1"

View File

@@ -19,7 +19,7 @@ import (
const nilDepositErr = "Ignoring nil deposit insertion" const nilDepositErr = "Ignoring nil deposit insertion"
var _ = DepositFetcher(&DepositCache{}) var _ DepositFetcher = (*DepositCache)(nil)
func TestInsertDeposit_LogsOnNilDepositInsertion(t *testing.T) { func TestInsertDeposit_LogsOnNilDepositInsertion(t *testing.T) {
hook := logTest.NewGlobal() hook := logTest.NewGlobal()

View File

@@ -13,7 +13,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/assert"
) )
var _ = PendingDepositsFetcher(&DepositCache{}) var _ PendingDepositsFetcher = (*DepositCache)(nil)
func TestInsertPendingDeposit_OK(t *testing.T) { func TestInsertPendingDeposit_OK(t *testing.T) {
dc := DepositCache{} dc := DepositCache{}

View File

@@ -2,4 +2,4 @@ package db
import "github.com/prysmaticlabs/prysm/beacon-chain/db/kv" import "github.com/prysmaticlabs/prysm/beacon-chain/db/kv"
var _ = Database(&kv.Store{}) var _ Database = (*kv.Store)(nil)

View File

@@ -20,7 +20,7 @@ import (
_ "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka/librdkafka" // Required for c++ kafka library. _ "gopkg.in/confluentinc/confluent-kafka-go.v1/kafka/librdkafka" // Required for c++ kafka library.
) )
var _ = iface.Database(&Exporter{}) var _ iface.Database = (*Exporter)(nil)
var log = logrus.WithField("prefix", "exporter") var log = logrus.WithField("prefix", "exporter")
var marshaler = &jsonpb.Marshaler{} var marshaler = &jsonpb.Marshaler{}

View File

@@ -17,7 +17,7 @@ import (
bolt "go.etcd.io/bbolt" bolt "go.etcd.io/bbolt"
) )
var _ = iface.Database(&Store{}) var _ iface.Database = (*Store)(nil)
const ( const (
// VotesCacheSize with 1M validators will be 8MB. // VotesCacheSize with 1M validators will be 8MB.

View File

@@ -17,7 +17,7 @@ import (
"google.golang.org/grpc/connectivity" "google.golang.org/grpc/connectivity"
) )
var _ = shared.Service(&Gateway{}) var _ shared.Service = (*Gateway)(nil)
// Gateway is the gRPC gateway to serve HTTP JSON traffic as a proxy and forward // Gateway is the gRPC gateway to serve HTTP JSON traffic as a proxy and forward
// it to the beacon-chain gRPC server. // it to the beacon-chain gRPC server.

View File

@@ -22,9 +22,9 @@ import (
"github.com/prysmaticlabs/prysm/shared/slotutil" "github.com/prysmaticlabs/prysm/shared/slotutil"
) )
var _ = shared.Service(&Service{}) var _ shared.Service = (*Service)(nil)
var _ = depositcache.DepositFetcher(&Service{}) var _ depositcache.DepositFetcher = (*Service)(nil)
var _ = powchain.ChainStartFetcher(&Service{}) var _ powchain.ChainStartFetcher = (*Service)(nil)
// Service spins up an client interoperability service that handles responsibilities such // Service spins up an client interoperability service that handles responsibilities such
// as kickstarting a genesis state for the beacon node from cli flags or a genesis.ssz file. // as kickstarting a genesis state for the beacon node from cli flags or a genesis.ssz file.

View File

@@ -20,7 +20,7 @@ import (
) )
// Ensure BeaconNode implements interfaces. // Ensure BeaconNode implements interfaces.
var _ = statefeed.Notifier(&BeaconNode{}) var _ statefeed.Notifier = (*BeaconNode)(nil)
// Test that beacon chain node can close. // Test that beacon chain node can close.
func TestNodeClose_OK(t *testing.T) { func TestNodeClose_OK(t *testing.T) {

View File

@@ -4,4 +4,4 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations/kv" "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations/kv"
) )
var _ = Pool(&kv.AttCaches{}) var _ Pool = (*kv.AttCaches)(nil)

View File

@@ -14,7 +14,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/params"
) )
var _ = NetworkEncoding(&SszNetworkEncoder{}) var _ NetworkEncoding = (*SszNetworkEncoder)(nil)
// MaxGossipSize allowed for gossip messages. // MaxGossipSize allowed for gossip messages.
var MaxGossipSize = params.BeaconNetworkConfig().GossipMaxSize // 1 Mib var MaxGossipSize = params.BeaconNetworkConfig().GossipMaxSize // 1 Mib

View File

@@ -37,7 +37,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/slotutil" "github.com/prysmaticlabs/prysm/shared/slotutil"
) )
var _ = shared.Service(&Service{}) var _ shared.Service = (*Service)(nil)
// In the event that we are at our peer limit, we // In the event that we are at our peer limit, we
// stop looking for new peers and instead poll // stop looking for new peers and instead poll

View File

@@ -27,10 +27,10 @@ import (
logTest "github.com/sirupsen/logrus/hooks/test" logTest "github.com/sirupsen/logrus/hooks/test"
) )
var _ = ChainStartFetcher(&Service{}) var _ ChainStartFetcher = (*Service)(nil)
var _ = ChainInfoFetcher(&Service{}) var _ ChainInfoFetcher = (*Service)(nil)
var _ = POWBlockFetcher(&Service{}) var _ POWBlockFetcher = (*Service)(nil)
var _ = Chain(&Service{}) var _ Chain = (*Service)(nil)
type goodLogger struct { type goodLogger struct {
backend *backends.SimulatedBackend backend *backends.SimulatedBackend

View File

@@ -2,4 +2,4 @@ package beaconv1
import ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1" import ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1"
var _ = ethpb.BeaconChainServer(&Server{}) var _ ethpb.BeaconChainServer = (*Server)(nil)

View File

@@ -23,7 +23,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var _ = shared.Service(&Service{}) var _ shared.Service = (*Service)(nil)
// blockchainService defines the interface for interaction with block chain service. // blockchainService defines the interface for interaction with block chain service.
type blockchainService interface { type blockchainService interface {

View File

@@ -32,7 +32,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/timeutils"
) )
var _ = shared.Service(&Service{}) var _ shared.Service = (*Service)(nil)
const rangeLimit = 1024 const rangeLimit = 1024
const seenBlockSize = 1000 const seenBlockSize = 1000

View File

@@ -37,7 +37,7 @@ import (
type source struct{} type source struct{}
var _ = mrand.Source64(&source{}) var _ mrand.Source64 = (*source)(nil)
// Seed does nothing when crypto/rand is used as source. // Seed does nothing when crypto/rand is used as source.
func (s *source) Seed(seed int64) {} func (s *source) Seed(seed int64) {}

View File

@@ -5,7 +5,7 @@ import (
"time" "time"
) )
var _ = Ticker(&SlotTicker{}) var _ Ticker = (*SlotTicker)(nil)
func TestSlotTicker(t *testing.T) { func TestSlotTicker(t *testing.T) {
ticker := &SlotTicker{ ticker := &SlotTicker{

View File

@@ -2,4 +2,4 @@ package testing
import "github.com/prysmaticlabs/prysm/shared/slotutil" import "github.com/prysmaticlabs/prysm/shared/slotutil"
var _ = slotutil.Ticker(&MockTicker{}) var _ slotutil.Ticker = (*MockTicker)(nil)

View File

@@ -2,4 +2,4 @@ package db
import "github.com/prysmaticlabs/prysm/slasher/db/kv" import "github.com/prysmaticlabs/prysm/slasher/db/kv"
var _ = Database(&kv.Store{}) var _ Database = (*kv.Store)(nil)

View File

@@ -8,7 +8,7 @@ import (
"github.com/prysmaticlabs/prysm/slasher/detection/attestations/types" "github.com/prysmaticlabs/prysm/slasher/detection/attestations/types"
) )
var _ = iface.SpanDetector(&MockSpanDetector{}) var _ iface.SpanDetector = (*MockSpanDetector)(nil)
// MockSpanDetector defines a struct which can detect slashable // MockSpanDetector defines a struct which can detect slashable
// attestation offenses by tracking validator min-max // attestation offenses by tracking validator min-max

View File

@@ -35,7 +35,7 @@ var (
// TODO(#5040): Remove lookback and handle min spans properly. // TODO(#5040): Remove lookback and handle min spans properly.
const epochLookback = 128 const epochLookback = 128
var _ = iface.SpanDetector(&SpanDetector{}) var _ iface.SpanDetector = (*SpanDetector)(nil)
// SpanDetector defines a struct which can detect slashable // SpanDetector defines a struct which can detect slashable
// attestation offenses by tracking validator min-max // attestation offenses by tracking validator min-max

View File

@@ -13,7 +13,7 @@ import (
testDetect "github.com/prysmaticlabs/prysm/slasher/detection/testing" testDetect "github.com/prysmaticlabs/prysm/slasher/detection/testing"
) )
var _ = iface.ProposalsDetector(&ProposeDetector{}) var _ iface.ProposalsDetector = (*ProposeDetector)(nil)
func TestProposalsDetector_DetectSlashingsForBlockHeaders(t *testing.T) { func TestProposalsDetector_DetectSlashingsForBlockHeaders(t *testing.T) {
type testStruct struct { type testStruct struct {

View File

@@ -4,4 +4,4 @@ import (
pb "github.com/prysmaticlabs/prysm/proto/cluster" pb "github.com/prysmaticlabs/prysm/proto/cluster"
) )
var _ = pb.PrivateKeyServiceServer(&server{}) var _ pb.PrivateKeyServiceServer = (*server)(nil)

View File

@@ -8,7 +8,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/timeutils"
) )
var _ = Validator(&FakeValidator{}) var _ Validator = (*FakeValidator)(nil)
// FakeValidator for mocking. // FakeValidator for mocking.
type FakeValidator struct { type FakeValidator struct {

View File

@@ -17,7 +17,7 @@ import (
logTest "github.com/sirupsen/logrus/hooks/test" logTest "github.com/sirupsen/logrus/hooks/test"
) )
var _ = shared.Service(&ValidatorService{}) var _ shared.Service = (*ValidatorService)(nil)
var validatorKey *keystore.Key var validatorKey *keystore.Key
var validatorPubKey [48]byte var validatorPubKey [48]byte
var keyMap map[[48]byte]*keystore.Key var keyMap map[[48]byte]*keystore.Key

View File

@@ -28,7 +28,7 @@ func init() {
logrus.SetOutput(ioutil.Discard) logrus.SetOutput(ioutil.Discard)
} }
var _ = Validator(&validator{}) var _ Validator = (*validator)(nil)
const cancelledCtx = "context has been canceled" const cancelledCtx = "context has been canceled"

View File

@@ -21,7 +21,7 @@ import (
"github.com/prysmaticlabs/prysm/validator/keymanager/v2/derived" "github.com/prysmaticlabs/prysm/validator/keymanager/v2/derived"
) )
var _ = accountCreator(&mockAccountCreator{}) var _ accountCreator = (*mockAccountCreator)(nil)
type mockAccountCreator struct { type mockAccountCreator struct {
data *ethpb.Deposit_Data data *ethpb.Deposit_Data

View File

@@ -4,4 +4,4 @@ import (
pb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2" pb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
) )
var _ = pb.AuthServer(&Server{}) var _ pb.AuthServer = (*Server)(nil)