mirror of https://github.com/certusone/vouch.git
Fix up tests.
This commit is contained in:
parent
9087add881
commit
ebd1003871
|
@ -286,6 +286,23 @@ func (m *BeaconBlockProposalProvider) BeaconBlockProposal(ctx context.Context, s
|
|||
return block, nil
|
||||
}
|
||||
|
||||
// SignedBeaconBlockProvider is a mock for eth2client.SignedBeaconBlockProvider.
|
||||
type SignedBeaconBlockProvider struct{}
|
||||
|
||||
// NewSignedBeaconBlockProvider returns a mock beacon block proposal provider.
|
||||
func NewSignedBeaconBlockProvider() eth2client.SignedBeaconBlockProvider {
|
||||
return &SignedBeaconBlockProvider{}
|
||||
}
|
||||
|
||||
// SignedBeaconBlock is a mock.
|
||||
func (m *SignedBeaconBlockProvider) SignedBeaconBlock(ctx context.Context, stateID string) (*spec.SignedBeaconBlock, error) {
|
||||
return &spec.SignedBeaconBlock{
|
||||
Message: &spec.BeaconBlock{
|
||||
Slot: 123,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// BeaconProposerDomainProvider is a mock for eth2client.BeaconProposerDomainProvider.
|
||||
type BeaconProposerDomainProvider struct{}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ func TestBeaconBlockProposal(t *testing.T) {
|
|||
"two": mock.NewBeaconBlockProposalProvider(),
|
||||
"three": mock.NewBeaconBlockProposalProvider(),
|
||||
}),
|
||||
best.WithSignedBeaconBlockProvider(mock.NewSignedBeaconBlockProvider()),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -15,23 +15,14 @@ package best
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
spec "github.com/attestantio/go-eth2-client/spec/phase0"
|
||||
"github.com/attestantio/vouch/testutil"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func _bytes(input string) []byte {
|
||||
res, err := hex.DecodeString(strings.TrimPrefix(input, "0x"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func aggregationBits(set uint64, total uint64) bitfield.Bitlist {
|
||||
bits := bitfield.NewBitlist(total)
|
||||
for i := uint64(0); i < set; i++ {
|
||||
|
@ -52,7 +43,7 @@ func TestScore(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
block *spec.BeaconBlock
|
||||
parentSlot uint64
|
||||
parentSlot spec.Slot
|
||||
score float64
|
||||
err string
|
||||
}{
|
||||
|
@ -222,25 +213,25 @@ func TestScore(t *testing.T) {
|
|||
},
|
||||
ProposerSlashings: []*spec.ProposerSlashing{
|
||||
{
|
||||
Header1: &spec.SignedBeaconBlockHeader{
|
||||
SignedHeader1: &spec.SignedBeaconBlockHeader{
|
||||
Message: &spec.BeaconBlockHeader{
|
||||
Slot: 10,
|
||||
ProposerIndex: 1,
|
||||
ParentRoot: _bytes("0x0101010101010101010101010101010101010101010101010101010101010101"),
|
||||
StateRoot: _bytes("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: _bytes("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
ParentRoot: testutil.HexToRoot("0x0101010101010101010101010101010101010101010101010101010101010101"),
|
||||
StateRoot: testutil.HexToRoot("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: testutil.HexToRoot("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
},
|
||||
Signature: _bytes("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
Signature: testutil.HexToSignature("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
},
|
||||
Header2: &spec.SignedBeaconBlockHeader{
|
||||
SignedHeader2: &spec.SignedBeaconBlockHeader{
|
||||
Message: &spec.BeaconBlockHeader{
|
||||
Slot: 10,
|
||||
ProposerIndex: 1,
|
||||
ParentRoot: _bytes("0x0404040404040404040404040404040404040404040404040404040404040404"),
|
||||
StateRoot: _bytes("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: _bytes("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
ParentRoot: testutil.HexToRoot("0x0404040404040404040404040404040404040404040404040404040404040404"),
|
||||
StateRoot: testutil.HexToRoot("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: testutil.HexToRoot("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
},
|
||||
Signature: _bytes("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
Signature: testutil.HexToSignature("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -274,25 +265,25 @@ func TestScore(t *testing.T) {
|
|||
},
|
||||
ProposerSlashings: []*spec.ProposerSlashing{
|
||||
{
|
||||
Header1: &spec.SignedBeaconBlockHeader{
|
||||
SignedHeader1: &spec.SignedBeaconBlockHeader{
|
||||
Message: &spec.BeaconBlockHeader{
|
||||
Slot: 10,
|
||||
ProposerIndex: 1,
|
||||
ParentRoot: _bytes("0x0101010101010101010101010101010101010101010101010101010101010101"),
|
||||
StateRoot: _bytes("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: _bytes("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
ParentRoot: testutil.HexToRoot("0x0101010101010101010101010101010101010101010101010101010101010101"),
|
||||
StateRoot: testutil.HexToRoot("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: testutil.HexToRoot("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
},
|
||||
Signature: _bytes("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
Signature: testutil.HexToSignature("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
},
|
||||
Header2: &spec.SignedBeaconBlockHeader{
|
||||
SignedHeader2: &spec.SignedBeaconBlockHeader{
|
||||
Message: &spec.BeaconBlockHeader{
|
||||
Slot: 10,
|
||||
ProposerIndex: 1,
|
||||
ParentRoot: _bytes("0x0404040404040404040404040404040404040404040404040404040404040404"),
|
||||
StateRoot: _bytes("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: _bytes("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
ParentRoot: testutil.HexToRoot("0x0404040404040404040404040404040404040404040404040404040404040404"),
|
||||
StateRoot: testutil.HexToRoot("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: testutil.HexToRoot("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
},
|
||||
Signature: _bytes("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
Signature: testutil.HexToSignature("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -326,25 +317,25 @@ func TestScore(t *testing.T) {
|
|||
},
|
||||
ProposerSlashings: []*spec.ProposerSlashing{
|
||||
{
|
||||
Header1: &spec.SignedBeaconBlockHeader{
|
||||
SignedHeader1: &spec.SignedBeaconBlockHeader{
|
||||
Message: &spec.BeaconBlockHeader{
|
||||
Slot: 10,
|
||||
ProposerIndex: 1,
|
||||
ParentRoot: _bytes("0x0101010101010101010101010101010101010101010101010101010101010101"),
|
||||
StateRoot: _bytes("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: _bytes("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
ParentRoot: testutil.HexToRoot("0x0101010101010101010101010101010101010101010101010101010101010101"),
|
||||
StateRoot: testutil.HexToRoot("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: testutil.HexToRoot("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
},
|
||||
Signature: _bytes("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
Signature: testutil.HexToSignature("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
},
|
||||
Header2: &spec.SignedBeaconBlockHeader{
|
||||
SignedHeader2: &spec.SignedBeaconBlockHeader{
|
||||
Message: &spec.BeaconBlockHeader{
|
||||
Slot: 10,
|
||||
ProposerIndex: 1,
|
||||
ParentRoot: _bytes("0x0404040404040404040404040404040404040404040404040404040404040404"),
|
||||
StateRoot: _bytes("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: _bytes("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
ParentRoot: testutil.HexToRoot("0x0404040404040404040404040404040404040404040404040404040404040404"),
|
||||
StateRoot: testutil.HexToRoot("0x0202020202020202020202020202020202020202020202020202020202020202"),
|
||||
BodyRoot: testutil.HexToRoot("0x0303030303030303030303030303030303030303030303030303030303030303"),
|
||||
},
|
||||
Signature: _bytes("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
Signature: testutil.HexToSignature("0x040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -42,6 +42,7 @@ func TestService(t *testing.T) {
|
|||
"two": mock.NewBeaconBlockProposalProvider(),
|
||||
"three": mock.NewBeaconBlockProposalProvider(),
|
||||
}),
|
||||
best.WithSignedBeaconBlockProvider(mock.NewSignedBeaconBlockProvider()),
|
||||
},
|
||||
err: "problem with parameters: no client monitor specified",
|
||||
},
|
||||
|
@ -57,6 +58,7 @@ func TestService(t *testing.T) {
|
|||
"two": mock.NewBeaconBlockProposalProvider(),
|
||||
"three": mock.NewBeaconBlockProposalProvider(),
|
||||
}),
|
||||
best.WithSignedBeaconBlockProvider(mock.NewSignedBeaconBlockProvider()),
|
||||
},
|
||||
err: "problem with parameters: no timeout specified",
|
||||
},
|
||||
|
@ -71,28 +73,45 @@ func TestService(t *testing.T) {
|
|||
"two": mock.NewBeaconBlockProposalProvider(),
|
||||
"three": mock.NewBeaconBlockProposalProvider(),
|
||||
}),
|
||||
best.WithSignedBeaconBlockProvider(mock.NewSignedBeaconBlockProvider()),
|
||||
},
|
||||
err: "problem with parameters: no process concurrency specified",
|
||||
},
|
||||
{
|
||||
name: "ProvidersMissing",
|
||||
name: "BeaconBlockProposalProvidersMissing",
|
||||
params: []best.Parameter{
|
||||
best.WithLogLevel(zerolog.Disabled),
|
||||
best.WithClientMonitor(null.New(context.Background())),
|
||||
best.WithProcessConcurrency(1),
|
||||
best.WithSignedBeaconBlockProvider(mock.NewSignedBeaconBlockProvider()),
|
||||
},
|
||||
err: "problem with parameters: no beacon block proposal providers specified",
|
||||
},
|
||||
{
|
||||
name: "ProvidersEmpty",
|
||||
name: "BeaconBlockProposalProvidersEmpty",
|
||||
params: []best.Parameter{
|
||||
best.WithLogLevel(zerolog.Disabled),
|
||||
best.WithClientMonitor(null.New(context.Background())),
|
||||
best.WithProcessConcurrency(1),
|
||||
best.WithBeaconBlockProposalProviders(map[string]eth2client.BeaconBlockProposalProvider{}),
|
||||
best.WithSignedBeaconBlockProvider(mock.NewSignedBeaconBlockProvider()),
|
||||
},
|
||||
err: "problem with parameters: no beacon block proposal providers specified",
|
||||
},
|
||||
{
|
||||
name: "SignedBeaconBlockProviderMissing",
|
||||
params: []best.Parameter{
|
||||
best.WithLogLevel(zerolog.Disabled),
|
||||
best.WithClientMonitor(null.New(context.Background())),
|
||||
best.WithProcessConcurrency(1),
|
||||
best.WithBeaconBlockProposalProviders(map[string]eth2client.BeaconBlockProposalProvider{
|
||||
"one": mock.NewBeaconBlockProposalProvider(),
|
||||
"two": mock.NewBeaconBlockProposalProvider(),
|
||||
"three": mock.NewBeaconBlockProposalProvider(),
|
||||
}),
|
||||
},
|
||||
err: "problem with parameters: no signed beacon block provider specified",
|
||||
},
|
||||
{
|
||||
name: "Good",
|
||||
params: []best.Parameter{
|
||||
|
@ -104,6 +123,7 @@ func TestService(t *testing.T) {
|
|||
"two": mock.NewBeaconBlockProposalProvider(),
|
||||
"three": mock.NewBeaconBlockProposalProvider(),
|
||||
}),
|
||||
best.WithSignedBeaconBlockProvider(mock.NewSignedBeaconBlockProvider()),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue