Skip to content

Commit

Permalink
Tidy up tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jan 5, 2023
1 parent 3f64e90 commit 9b8226c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
7 changes: 5 additions & 2 deletions services/blockrelay/standard/proposerconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/attestantio/vouch/services/beaconblockproposer"
"github.com/pkg/errors"
e2wtypes "github.com/wealdtech/go-eth2-wallet-types/v2"
)

Expand All @@ -33,7 +32,11 @@ func (s *Service) ProposerConfig(ctx context.Context,
s.executionConfigMu.RLock()
defer s.executionConfigMu.RUnlock()
if s.executionConfig == nil {
return nil, errors.New("no execution config at current")
log.Warn().Msg("No execution configuration available; using fallback information")
return &beaconblockproposer.ProposerConfig{
FeeRecipient: s.fallbackFeeRecipient,
Relays: make([]*beaconblockproposer.RelayConfig, 0),
}, nil
}
return s.executionConfig.ProposerConfig(ctx, account, pubkey, s.fallbackFeeRecipient, s.fallbackGasLimit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/attestantio/vouch/mock"
mockaccountmanager "github.com/attestantio/vouch/services/accountmanager/mock"
"github.com/attestantio/vouch/services/blockrelay/standard"
Expand All @@ -46,7 +47,7 @@ import (
standardmajordomo "github.com/wealdtech/go-majordomo/standard"
)

func TestExecConfig(t *testing.T) {
func TestProposerConfig(t *testing.T) {
ctx := context.Background()

genesisTime := time.Now()
Expand All @@ -59,6 +60,7 @@ func TestExecConfig(t *testing.T) {
domainProvider := mock.NewDomainProvider()

mockValidatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider()
mockAccountsProvider := mockaccountmanager.NewAccountsProvider()
require.NoError(t, e2types.InitBLS())
store := scratch.New()
require.NoError(t, e2wallet.UseStore(store))
Expand Down Expand Up @@ -105,11 +107,11 @@ func TestExecConfig(t *testing.T) {
require.NoError(t, os.WriteFile(badConfigFile, []byte(`bad`), 0600))

tests := []struct {
name string
params []standard.Parameter
execConfig string
err string
logEntries []map[string]interface{}
name string
params []standard.Parameter
proposerConfig string
err string
logEntries []map[string]interface{}
}{
{
name: "Fallback",
Expand All @@ -124,11 +126,12 @@ func TestExecConfig(t *testing.T) {
standard.WithFallbackFeeRecipient(bellatrix.ExecutionAddress{0x01}),
standard.WithFallbackGasLimit(10000000),
standard.WithValidatingAccountsProvider(mockValidatingAccountsProvider),
standard.WithAccountsProvider(mockAccountsProvider),
standard.WithValidatorRegistrationSigner(mockSigner),
standard.WithSpecProvider(specProvider),
standard.WithDomainProvider(domainProvider),
},
execConfig: `{"default_config":{"fee_recipient":"0x0100000000000000000000000000000000000000","gas_limit":"10000000","builder":{"enabled":false}}}`,
proposerConfig: `{"fee_recipient":"0x0100000000000000000000000000000000000000","relays":[]}`,
},
{
name: "File",
Expand All @@ -143,11 +146,12 @@ func TestExecConfig(t *testing.T) {
standard.WithFallbackFeeRecipient(bellatrix.ExecutionAddress{0x01}),
standard.WithFallbackGasLimit(10000000),
standard.WithValidatingAccountsProvider(mockValidatingAccountsProvider),
standard.WithAccountsProvider(mockAccountsProvider),
standard.WithValidatorRegistrationSigner(mockSigner),
standard.WithSpecProvider(specProvider),
standard.WithDomainProvider(domainProvider),
},
execConfig: `{"default_config":{"fee_recipient":"0x0200000000000000000000000000000000000000","gas_limit":"20000000","builder":{"enabled":false}}}`,
proposerConfig: `{"fee_recipient":"0x0200000000000000000000000000000000000000","relays":[]}`,
logEntries: []map[string]interface{}{
{
"message": "Obtained configuration",
Expand All @@ -167,14 +171,15 @@ func TestExecConfig(t *testing.T) {
standard.WithFallbackFeeRecipient(bellatrix.ExecutionAddress{0x01}),
standard.WithFallbackGasLimit(10000000),
standard.WithValidatingAccountsProvider(mockValidatingAccountsProvider),
standard.WithAccountsProvider(mockAccountsProvider),
standard.WithValidatorRegistrationSigner(mockSigner),
standard.WithSpecProvider(specProvider),
standard.WithDomainProvider(domainProvider),
},
execConfig: `{"default_config":{"fee_recipient":"0x0100000000000000000000000000000000000000","gas_limit":"10000000","builder":{"enabled":false}}}`,
proposerConfig: `{"fee_recipient":"0x0100000000000000000000000000000000000000","relays":[]}`,
logEntries: []map[string]interface{}{
{
"message": "Failed to obtain execution configuration; setting default configuration with fallback values from configuration",
"message": "No execution configuration available; using fallback information",
},
},
},
Expand All @@ -185,14 +190,14 @@ func TestExecConfig(t *testing.T) {
capture := logger.NewLogCapture()
s, err := standard.New(ctx, test.params...)
require.NoError(t, err)
execConfig, err := s.ExecutionConfig(ctx)
proposerConfig, err := s.ProposerConfig(ctx, testAccount, phase0.BLSPubKey{})
if test.err != "" {
require.EqualError(t, err, test.err)
} else {
require.NoError(t, err)
data, err := json.Marshal(execConfig)
data, err := json.Marshal(proposerConfig)
require.NoError(t, err)
require.Equal(t, test.execConfig, string(data))
require.Equal(t, test.proposerConfig, string(data))
}
for _, logEntry := range test.logEntries {
if !capture.HasLog(logEntry) {
Expand Down

0 comments on commit 9b8226c

Please sign in to comment.