Skip to content

Commit

Permalink
fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xenowits committed Oct 19, 2023
1 parent 9965481 commit 77fc3df
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
11 changes: 4 additions & 7 deletions app/eth2wrap/synthproposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package eth2wrap_test

import (
"context"
"math/rand"
"testing"

eth2api "github.com/attestantio/go-eth2-client/api"
Expand Down Expand Up @@ -59,10 +58,6 @@ func TestSynthProposer(t *testing.T) {
}
signedBeaconBlock := bmock.SignedBeaconBlock
bmock.SignedBeaconBlockFunc = func(ctx context.Context, blockID string) (*spec.VersionedSignedBeaconBlock, error) {
if rand.Float32() < 0.3 { // Fail to find 2/3 of blocks.
return nil, nil //nolint:nilnil // go-eth2-client returns nilnil if block not found.
}

opts := &eth2api.SignedBeaconBlockOpts{Block: blockID}
resp, err := signedBeaconBlock(ctx, opts)
if err != nil {
Expand Down Expand Up @@ -105,14 +100,16 @@ func TestSynthProposer(t *testing.T) {
for _, duty := range duties {
var graff [32]byte
copy(graff[:], "test")
opts := &eth2api.BeaconBlockProposalOpts{
opts1 := &eth2api.BeaconBlockProposalOpts{
Slot: duty.Slot,
RandaoReveal: testutil.RandomEth2Signature(),
Graffiti: graff,
}
resp, err := eth2Cl.BeaconBlockProposal(ctx, opts)

resp, err := eth2Cl.BeaconBlockProposal(ctx, opts1)
require.NoError(t, err)
block := resp.Data

if duty.Slot == realBlockSlot {
require.NotContains(t, string(block.Capella.Body.Graffiti[:]), "DO NOT SUBMIT")
require.NotEqual(t, feeRecipient, block.Capella.Body.ExecutionPayload.FeeRecipient)
Expand Down
7 changes: 4 additions & 3 deletions app/eth2wrap/valcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/rand"
"testing"

eth2api "github.com/attestantio/go-eth2-client/api"
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -42,10 +43,10 @@ func TestValidatorCache(t *testing.T) {

// Configure it to return the set of validators if queried.
var queried int
eth2Cl.ValidatorsByPubKeyFunc = func(ctx context.Context, stateID string, keys []eth2p0.BLSPubKey) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) {
eth2Cl.ValidatorsFunc = func(ctx context.Context, opts *eth2api.ValidatorsOpts) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) {
queried++
require.Equal(t, "head", stateID)
require.Equal(t, pubkeys, keys)
require.Equal(t, "head", opts.State)
require.Equal(t, pubkeys, opts.PubKeys)

return set, nil
}
Expand Down
4 changes: 2 additions & 2 deletions testutil/beaconmock/beaconmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type Mock struct {
SubmitBlindedBeaconBlockFunc func(context.Context, *eth2api.VersionedSignedBlindedBeaconBlock) error
SubmitVoluntaryExitFunc func(context.Context, *eth2p0.SignedVoluntaryExit) error
ValidatorsByPubKeyFunc func(context.Context, string, []eth2p0.BLSPubKey) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)
ValidatorsFunc func(context.Context, string, []eth2p0.ValidatorIndex) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)
ValidatorsFunc func(context.Context, *eth2api.ValidatorsOpts) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)
GenesisTimeFunc func(context.Context) (time.Time, error)
NodeSyncingFunc func(context.Context) (*eth2v1.SyncState, error)
SubmitValidatorRegistrationsFunc func(context.Context, []*eth2api.VersionedSignedValidatorRegistration) error
Expand Down Expand Up @@ -255,7 +255,7 @@ func (m Mock) SyncCommitteeDuties(ctx context.Context, opts *eth2api.SyncCommitt
}

func (m Mock) Validators(ctx context.Context, opts *eth2api.ValidatorsOpts) (*eth2api.Response[map[eth2p0.ValidatorIndex]*eth2v1.Validator], error) {
vals, err := m.ValidatorsFunc(ctx, opts.State, opts.Indices)
vals, err := m.ValidatorsFunc(ctx, opts)
if err != nil {
return nil, err
}

Check warning on line 261 in testutil/beaconmock/beaconmock.go

View check run for this annotation

Codecov / codecov/patch

testutil/beaconmock/beaconmock.go#L260-L261

Added lines #L260 - L261 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion testutil/beaconmock/beaconmock_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func WithBeaconMockFuzzer() Option {
return att, nil
}

mock.ValidatorsFunc = func(context.Context, string, []eth2p0.ValidatorIndex) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) {
mock.ValidatorsFunc = func(context.Context, *eth2api.ValidatorsOpts) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) {

Check warning on line 126 in testutil/beaconmock/beaconmock_fuzz.go

View check run for this annotation

Codecov / codecov/patch

testutil/beaconmock/beaconmock_fuzz.go#L126

Added line #L126 was not covered by tests
var vals map[eth2p0.ValidatorIndex]*eth2v1.Validator
fuzz.New().Fuzz(&vals)

Expand Down
8 changes: 4 additions & 4 deletions testutil/beaconmock/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ func WithValidatorSet(set ValidatorSet) Option {
return resp, nil
}

mock.ValidatorsFunc = func(ctx context.Context, stateID string, indexes []eth2p0.ValidatorIndex) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) {
mock.ValidatorsFunc = func(ctx context.Context, opts *eth2api.ValidatorsOpts) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) {
resp := make(map[eth2p0.ValidatorIndex]*eth2v1.Validator)
if len(indexes) == 0 {
if len(opts.Indices) == 0 {
for idx, val := range set {
resp[idx] = cloneValidator(val)
}

return resp, nil
}

for _, index := range indexes {
for _, index := range opts.Indices {
val, ok := set[index]
if ok {
resp[index] = cloneValidator(val)
Expand Down Expand Up @@ -529,7 +529,7 @@ func defaultMock(httpMock HTTPMock, httpServer *http.Server, clock clockwork.Clo
ActiveValidatorsFunc: func(ctx context.Context) (eth2wrap.ActiveValidators, error) {
return nil, nil
},
ValidatorsFunc: func(context.Context, string, []eth2p0.ValidatorIndex) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) {
ValidatorsFunc: func(context.Context, *eth2api.ValidatorsOpts) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) {

Check warning on line 532 in testutil/beaconmock/options.go

View check run for this annotation

Codecov / codecov/patch

testutil/beaconmock/options.go#L532

Added line #L532 was not covered by tests
return nil, nil
},
ValidatorsByPubKeyFunc: func(context.Context, string, []eth2p0.BLSPubKey) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) {
Expand Down

0 comments on commit 77fc3df

Please sign in to comment.