-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Tests for builder service #11214
Merged
Merged
Tests for builder service #11214
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bc62a14
Tests for builder service
rkapka 5f1fd8e
fix glob
rkapka 0bd6701
minor changes to mock
rkapka 320c3c4
add comments to mock
rkapka c596006
Merge branch 'develop' into builder-service-tests
terencechain 89a85b5
Revert "Auxiliary commit to revert individual files from bc62a140347e…
rkapka b1dcac4
correct comment
rkapka 5ac79e6
Merge branch 'develop' into builder-service-tests
rauljordan 62e0101
Do not init builder for empty endpoint
rkapka ecff211
Merge branch '__develop' into builder-service-tests
rkapka 85d6d81
revert merging issues
rkapka ce39989
Merge branch '__develop' into builder-service-tests
rkapka 57832e9
better nil checks
rkapka 813280d
Merge branch '__develop' into builder-service-tests
rkapka e02a337
test fix
rkapka 4b0ca9e
Merge branch 'develop' into builder-service-tests
rkapka e7053ac
Merge refs/heads/develop into builder-service-tests
prylabs-bulldozer[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
load("@prysm//tools/go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["mock.go"], | ||
importpath = "github.com/prysmaticlabs/prysm/v3/api/client/builder/testing", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//consensus-types/primitives:go_default_library", | ||
"//encoding/bytesutil:go_default_library", | ||
"//proto/engine/v1:go_default_library", | ||
"//proto/prysm/v1alpha1:go_default_library", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package testing | ||
|
||
import ( | ||
"context" | ||
|
||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" | ||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" | ||
v1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" | ||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" | ||
) | ||
|
||
// MockClient is a mock implementation of BuilderClient. | ||
type MockClient struct { | ||
RegisteredVals map[[48]byte]bool | ||
} | ||
|
||
// NewClient creates a new, correctly initialized mock. | ||
func NewClient() MockClient { | ||
return MockClient{RegisteredVals: map[[48]byte]bool{}} | ||
} | ||
|
||
// NodeURL -- | ||
func (MockClient) NodeURL() string { | ||
return "" | ||
} | ||
|
||
// GetHeader -- | ||
func (MockClient) GetHeader(_ context.Context, _ types.Slot, _ [32]byte, _ [48]byte) (*ethpb.SignedBuilderBid, error) { | ||
return nil, nil | ||
} | ||
|
||
// RegisterValidator -- | ||
func (m MockClient) RegisterValidator(_ context.Context, svr []*ethpb.SignedValidatorRegistrationV1) error { | ||
for _, r := range svr { | ||
b := bytesutil.ToBytes48(r.Message.Pubkey) | ||
m.RegisteredVals[b] = true | ||
} | ||
return nil | ||
} | ||
|
||
// SubmitBlindedBlock -- | ||
func (MockClient) SubmitBlindedBlock(_ context.Context, _ *ethpb.SignedBlindedBeaconBlockBellatrix) (*v1.ExecutionPayload, error) { | ||
return nil, nil | ||
} | ||
|
||
// Status -- | ||
func (MockClient) Status(_ context.Context) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package builder | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
buildertesting "github.com/prysmaticlabs/prysm/v3/api/client/builder/testing" | ||
blockchainTesting "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing" | ||
dbtesting "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing" | ||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" | ||
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/v3/testing/assert" | ||
"github.com/prysmaticlabs/prysm/v3/testing/require" | ||
) | ||
|
||
func Test_NewServiceWithBuilder(t *testing.T) { | ||
s, err := NewService(context.Background(), WithBuilderClient(&buildertesting.MockClient{})) | ||
require.NoError(t, err) | ||
assert.Equal(t, true, s.Configured()) | ||
} | ||
|
||
func Test_NewServiceWithoutBuilder(t *testing.T) { | ||
s, err := NewService(context.Background()) | ||
require.NoError(t, err) | ||
assert.Equal(t, false, s.Configured()) | ||
} | ||
|
||
func Test_RegisterValidator(t *testing.T) { | ||
ctx := context.Background() | ||
db := dbtesting.SetupDB(t) | ||
headFetcher := &blockchainTesting.ChainService{} | ||
builder := buildertesting.NewClient() | ||
s, err := NewService(ctx, WithDatabase(db), WithHeadFetcher(headFetcher), WithBuilderClient(&builder)) | ||
require.NoError(t, err) | ||
pubkey := bytesutil.ToBytes48([]byte("pubkey")) | ||
var feeRecipient [20]byte | ||
require.NoError(t, s.RegisterValidator(ctx, []*eth.SignedValidatorRegistrationV1{{Message: ð.ValidatorRegistrationV1{Pubkey: pubkey[:], FeeRecipient: feeRecipient[:]}}})) | ||
assert.Equal(t, true, builder.RegisteredVals[pubkey]) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be useful as a general helper in a common location, we do something like this in execution service as well. Another PR will be great for this