Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable skipped block list paging unit test #5691

Merged
merged 10 commits into from
May 2, 2020
1 change: 1 addition & 0 deletions beacon-chain/rpc/beacon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ go_test(
srcs = [
"assignments_test.go",
"attestations_test.go",
"beacon_test.go",
"blocks_test.go",
"committees_test.go",
"config_test.go",
Expand Down
3 changes: 2 additions & 1 deletion beacon-chain/rpc/beacon/attestations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,8 @@ func TestServer_StreamIndexedAttestations_ContextCanceled(t *testing.T) {
}

func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
params.UseMainnetConfig()
resetCfg := params.OverrideBeaconConfigWithReset(params.MainnetConfig())
defer resetCfg()
db := dbTest.SetupDB(t)
defer dbTest.TeardownDB(t, db)
exitRoutine := make(chan bool)
Expand Down
20 changes: 20 additions & 0 deletions beacon-chain/rpc/beacon/beacon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package beacon

import (
"os"
"testing"

"github.com/prysmaticlabs/prysm/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/shared/params"
)

func TestMain(m *testing.M) {
// Use minimal config to reduce test setup time.
reset := params.OverrideBeaconConfigWithReset(params.MinimalSpecConfig())
flags.Init(&flags.GlobalFlags{
MaxPageSize: 250,
})
retVal := m.Run()
reset()
os.Exit(retVal)
}
1 change: 0 additions & 1 deletion beacon-chain/rpc/beacon/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
db := dbTest.SetupDB(t)
defer dbTest.TeardownDB(t, db)
ctx := context.Background()
t.Skip("Re-check after PR#5650 is merged")

count := uint64(100)
blks := make([]*ethpb.SignedBeaconBlock, count)
Expand Down
12 changes: 8 additions & 4 deletions beacon-chain/rpc/beacon/validators_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
)

func TestInfostream_EpochToTimestamp(t *testing.T) {
params.UseMainnetConfig()
resetCfg := params.OverrideBeaconConfigWithReset(params.MainnetConfig())
defer resetCfg()
tests := []struct {
name string
epoch uint64
Expand Down Expand Up @@ -48,7 +49,8 @@ func TestInfostream_EpochToTimestamp(t *testing.T) {
}

func TestInfostream_HandleSetValidatorKeys(t *testing.T) {
params.UseMainnetConfig()
resetCfg := params.OverrideBeaconConfigWithReset(params.MainnetConfig())
defer resetCfg()
tests := []struct {
name string
reqPubKeys [][]byte
Expand Down Expand Up @@ -86,7 +88,8 @@ func TestInfostream_HandleSetValidatorKeys(t *testing.T) {
}

func TestInfostream_HandleAddValidatorKeys(t *testing.T) {
params.UseMainnetConfig()
resetCfg := params.OverrideBeaconConfigWithReset(params.MainnetConfig())
defer resetCfg()
tests := []struct {
name string
initialPubKeys [][]byte
Expand Down Expand Up @@ -137,7 +140,8 @@ func TestInfostream_HandleAddValidatorKeys(t *testing.T) {
}

func TestInfostream_HandleRemoveValidatorKeys(t *testing.T) {
params.UseMainnetConfig()
resetCfg := params.OverrideBeaconConfigWithReset(params.MainnetConfig())
defer resetCfg()
tests := []struct {
name string
initialPubKeys [][]byte
Expand Down
8 changes: 0 additions & 8 deletions beacon-chain/rpc/beacon/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ import (
"github.com/prysmaticlabs/prysm/shared/testutil"
)

func init() {
// Use minimal config to reduce test setup time.
params.OverrideBeaconConfig(params.MinimalSpecConfig())
flags.Init(&flags.GlobalFlags{
MaxPageSize: 250,
})
}

func TestServer_GetValidatorActiveSetChanges_CannotRequestFutureEpoch(t *testing.T) {
db := dbTest.SetupDB(t)
defer dbTest.TeardownDB(t, db)
Expand Down
98 changes: 95 additions & 3 deletions shared/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ var defaultBeaconConfig = &BeaconChainConfig{
PruneSlasherStoragePeriod: 10,

// Fork related values.
GenesisForkVersion: []byte{0, 0, 0, 0},
NextForkVersion: []byte{0, 0, 0, 0}, // Set to GenesisForkVersion unless there is a scheduled fork
NextForkEpoch: 1<<64 - 1, // Set to FarFutureEpoch unless there is a scheduled fork.
GenesisForkVersion: []byte{0, 0, 0, 0},
NextForkVersion: []byte{0, 0, 0, 0}, // Set to GenesisForkVersion unless there is a scheduled fork
NextForkEpoch: 1<<64 - 1, // Set to FarFutureEpoch unless there is a scheduled fork.
ForkVersionSchedule: map[uint64][]byte{
// Any further forks must be specified here by their epoch number.
},
Expand Down Expand Up @@ -315,3 +315,95 @@ func UseMainnetConfig() {
func OverrideBeaconConfig(c *BeaconChainConfig) {
beaconConfig = c
}

// OverrideBeaconConfigWithReset replaces config and returns reset function
// that helps returning back to the previous state. Useful in tests.
func OverrideBeaconConfigWithReset(c *BeaconChainConfig) func() {
origConfig := beaconConfig.Copy()
OverrideBeaconConfig(c)
return func() {
OverrideBeaconConfig(origConfig)
}
}

// Copy returns copy of the config object.
func (c *BeaconChainConfig) Copy() *BeaconChainConfig {
return &BeaconChainConfig{
FarFutureEpoch: c.FarFutureEpoch,
BaseRewardsPerEpoch: c.BaseRewardsPerEpoch,
DepositContractTreeDepth: c.DepositContractTreeDepth,
MinGenesisDelay: c.MinGenesisDelay,
TargetCommitteeSize: c.TargetCommitteeSize,
MaxValidatorsPerCommittee: c.MaxValidatorsPerCommittee,
MaxCommitteesPerSlot: c.MaxCommitteesPerSlot,
MinPerEpochChurnLimit: c.MinPerEpochChurnLimit,
ChurnLimitQuotient: c.ChurnLimitQuotient,
ShuffleRoundCount: c.ShuffleRoundCount,
MinGenesisActiveValidatorCount: c.MinGenesisActiveValidatorCount,
MinGenesisTime: c.MinGenesisTime,
TargetAggregatorsPerCommittee: c.TargetAggregatorsPerCommittee,
HysteresisQuotient: c.HysteresisQuotient,
HysteresisDownwardMultiplier: c.HysteresisDownwardMultiplier,
HysteresisUpwardMultiplier: c.HysteresisUpwardMultiplier,
MinDepositAmount: c.MinDepositAmount,
MaxEffectiveBalance: c.MaxEffectiveBalance,
EjectionBalance: c.EjectionBalance,
EffectiveBalanceIncrement: c.EffectiveBalanceIncrement,
BLSWithdrawalPrefixByte: c.BLSWithdrawalPrefixByte,
ZeroHash: c.ZeroHash,
MinAttestationInclusionDelay: c.MinAttestationInclusionDelay,
SecondsPerSlot: c.SecondsPerSlot,
SlotsPerEpoch: c.SlotsPerEpoch,
MinSeedLookahead: c.MinSeedLookahead,
MaxSeedLookahead: c.MaxSeedLookahead,
EpochsPerEth1VotingPeriod: c.EpochsPerEth1VotingPeriod,
SlotsPerHistoricalRoot: c.SlotsPerHistoricalRoot,
MinValidatorWithdrawabilityDelay: c.MinValidatorWithdrawabilityDelay,
PersistentCommitteePeriod: c.PersistentCommitteePeriod,
MinEpochsToInactivityPenalty: c.MinEpochsToInactivityPenalty,
Eth1FollowDistance: c.Eth1FollowDistance,
SafeSlotsToUpdateJustified: c.SafeSlotsToUpdateJustified,
SecondsPerETH1Block: c.SecondsPerETH1Block,
EpochsPerHistoricalVector: c.EpochsPerHistoricalVector,
EpochsPerSlashingsVector: c.EpochsPerSlashingsVector,
HistoricalRootsLimit: c.HistoricalRootsLimit,
ValidatorRegistryLimit: c.ValidatorRegistryLimit,
BaseRewardFactor: c.BaseRewardFactor,
WhistleBlowerRewardQuotient: c.WhistleBlowerRewardQuotient,
ProposerRewardQuotient: c.ProposerRewardQuotient,
InactivityPenaltyQuotient: c.InactivityPenaltyQuotient,
MinSlashingPenaltyQuotient: c.MinSlashingPenaltyQuotient,
MaxProposerSlashings: c.MaxProposerSlashings,
MaxAttesterSlashings: c.MaxAttesterSlashings,
MaxAttestations: c.MaxAttestations,
MaxDeposits: c.MaxDeposits,
MaxVoluntaryExits: c.MaxVoluntaryExits,
DomainBeaconProposer: c.DomainBeaconProposer,
DomainRandao: c.DomainRandao,
DomainBeaconAttester: c.DomainBeaconAttester,
DomainDeposit: c.DomainDeposit,
DomainVoluntaryExit: c.DomainVoluntaryExit,
DomainSelectionProof: c.DomainSelectionProof,
DomainAggregateAndProof: c.DomainAggregateAndProof,
GweiPerEth: c.GweiPerEth,
LogBlockDelay: c.LogBlockDelay,
BLSSecretKeyLength: c.BLSSecretKeyLength,
BLSPubkeyLength: c.BLSPubkeyLength,
BLSSignatureLength: c.BLSSignatureLength,
DefaultBufferSize: c.DefaultBufferSize,
ValidatorPrivkeyFileName: c.ValidatorPrivkeyFileName,
WithdrawalPrivkeyFileName: c.WithdrawalPrivkeyFileName,
RPCSyncCheck: c.RPCSyncCheck,
GoerliBlockTime: c.GoerliBlockTime,
EmptySignature: c.EmptySignature,
DefaultPageSize: c.DefaultPageSize,
MaxPeersToSync: c.MaxPeersToSync,
SlotsPerArchivedPoint: c.SlotsPerArchivedPoint,
WeakSubjectivityPeriod: c.WeakSubjectivityPeriod,
PruneSlasherStoragePeriod: c.PruneSlasherStoragePeriod,
GenesisForkVersion: c.GenesisForkVersion,
NextForkVersion: c.NextForkVersion,
NextForkEpoch: c.NextForkEpoch,
ForkVersionSchedule: c.ForkVersionSchedule,
}
}
17 changes: 17 additions & 0 deletions shared/params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ func TestOverrideBeaconConfig(t *testing.T) {
t.Errorf("Shardcount in BeaconConfig incorrect. Wanted %d, got %d", 5, c.SlotsPerEpoch)
}
}

func TestOverrideBeaconConfigWithReset(t *testing.T) {
cfg := params.BeaconConfig().Copy()
origSlotsPerEpoch := cfg.SlotsPerEpoch
newSlotsPerEpoch := origSlotsPerEpoch + 42

cfg.SlotsPerEpoch = newSlotsPerEpoch
resetFunc := params.OverrideBeaconConfigWithReset(cfg)
if c := params.BeaconConfig(); c.SlotsPerEpoch != newSlotsPerEpoch {
t.Errorf("Config value is incorrect, want: %d, got %d", newSlotsPerEpoch, c.SlotsPerEpoch)
}

resetFunc()
if c := params.BeaconConfig(); c.SlotsPerEpoch != origSlotsPerEpoch {
t.Errorf("Config value is incorrect, want: %d, got %d", origSlotsPerEpoch, c.SlotsPerEpoch)
}
}