Refactor mock test helpers (#10133)

* Delete deploy contract tool. Move mock to its own package as testonly with some helper functions

* gofmt contracts/deposit/mock/mock.go

* move stategen mock.go to its on testonly pkg

* move password_reader_mock.go to mock testonly package

* move mock keymanager to its own testonly package

* move attestations mock

* move voluntaryexits mock

* Move slashings mock to mock pkg

* move the slasher mock

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Preston Van Loon
2022-01-26 08:48:20 -06:00
committed by GitHub
parent d9799e6b6c
commit 943dec525c
64 changed files with 281 additions and 367 deletions

View File

@@ -10,7 +10,6 @@ go_library(
"helpers.go",
"log.go",
"metrics.go",
"mock_slashing_checker.go",
"params.go",
"process_slashings.go",
"queue.go",
@@ -75,7 +74,8 @@ go_test(
"//beacon-chain/core/feed/state:go_default_library",
"//beacon-chain/core/signing:go_default_library",
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/operations/slashings:go_default_library",
"//beacon-chain/operations/slashings/mock:go_default_library",
"//beacon-chain/slasher/mock:go_default_library",
"//beacon-chain/slasher/types:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/sync/initial-sync/testing:go_default_library",

View File

@@ -10,7 +10,7 @@ import (
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings"
slashingsmock "github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings/mock"
slashertypes "github.com/prysmaticlabs/prysm/beacon-chain/slasher/types"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/crypto/bls"
@@ -238,7 +238,7 @@ func Test_processQueuedAttestations(t *testing.T) {
StateNotifier: &mock.MockStateNotifier{},
HeadStateFetcher: mockChain,
AttestationStateFetcher: mockChain,
SlashingPoolInserter: &slashings.PoolMock{},
SlashingPoolInserter: &slashingsmock.PoolMock{},
},
params: DefaultParams(),
attsQueue: newAttestationsQueue(),
@@ -297,7 +297,7 @@ func Test_processQueuedAttestations_MultipleChunkIndices(t *testing.T) {
StateNotifier: &mock.MockStateNotifier{},
HeadStateFetcher: mockChain,
AttestationStateFetcher: mockChain,
SlashingPoolInserter: &slashings.PoolMock{},
SlashingPoolInserter: &slashingsmock.PoolMock{},
},
params: slasherParams,
attsQueue: newAttestationsQueue(),
@@ -364,7 +364,7 @@ func Test_processQueuedAttestations_OverlappingChunkIndices(t *testing.T) {
StateNotifier: &mock.MockStateNotifier{},
HeadStateFetcher: mockChain,
AttestationStateFetcher: mockChain,
SlashingPoolInserter: &slashings.PoolMock{},
SlashingPoolInserter: &slashingsmock.PoolMock{},
},
params: slasherParams,
attsQueue: newAttestationsQueue(),

View File

@@ -8,7 +8,7 @@ import (
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings"
slashingsmock "github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings/mock"
slashertypes "github.com/prysmaticlabs/prysm/beacon-chain/slasher/types"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/config/params"
@@ -61,7 +61,7 @@ func Test_processQueuedBlocks_DetectsDoubleProposals(t *testing.T) {
StateNotifier: &mock.MockStateNotifier{},
HeadStateFetcher: mockChain,
StateGen: stategen.New(beaconDB),
SlashingPoolInserter: &slashings.PoolMock{},
SlashingPoolInserter: &slashingsmock.PoolMock{},
},
params: DefaultParams(),
blksQueue: newBlocksQueue(),

View File

@@ -0,0 +1,13 @@
load("@prysm//tools/go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["mock_slashing_checker.go"],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/slasher/mock",
visibility = ["//visibility:public"],
deps = [
"//config/params:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
],
)

View File

@@ -1,4 +1,4 @@
package slasher
package mock
import (
"context"

View File

@@ -7,7 +7,7 @@ import (
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings"
slashingsmock "github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings/mock"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/crypto/bls"
@@ -45,7 +45,7 @@ func TestService_processAttesterSlashings(t *testing.T) {
Database: slasherDB,
AttestationStateFetcher: mockChain,
StateGen: stategen.New(beaconDB),
SlashingPoolInserter: &slashings.PoolMock{},
SlashingPoolInserter: &slashingsmock.PoolMock{},
HeadStateFetcher: mockChain,
},
}
@@ -152,7 +152,7 @@ func TestService_processProposerSlashings(t *testing.T) {
Database: slasherDB,
AttestationStateFetcher: mockChain,
StateGen: stategen.New(beaconDB),
SlashingPoolInserter: &slashings.PoolMock{},
SlashingPoolInserter: &slashingsmock.PoolMock{},
HeadStateFetcher: mockChain,
},
}

View File

@@ -12,6 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
mockslasher "github.com/prysmaticlabs/prysm/beacon-chain/slasher/mock"
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/util"
@@ -21,7 +22,7 @@ import (
)
var _ = SlashingChecker(&Service{})
var _ = SlashingChecker(&MockSlashingChecker{})
var _ = SlashingChecker(&mockslasher.MockSlashingChecker{})
func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)