Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Jul 10, 2023
1 parent d998368 commit 2fcac99
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
37 changes: 19 additions & 18 deletions spec/versionedsubmitblockrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/attestantio/go-builder-client/api/bellatrix"
"github.com/attestantio/go-builder-client/api/capella"
v1 "github.com/attestantio/go-builder-client/api/v1"
consensusspec "github.com/attestantio/go-eth2-client/spec"
consensusbellatrix "github.com/attestantio/go-eth2-client/spec/bellatrix"
consensuscapella "github.com/attestantio/go-eth2-client/spec/capella"
Expand All @@ -46,7 +47,7 @@ func (v *VersionedSubmitBlockRequest) IsEmpty() bool {
}
}

// Slot returns the slot of the request
// Slot returns the slot of the request.
func (v *VersionedSubmitBlockRequest) Slot() (uint64, error) {
if v == nil {
return 0, errors.New("nil struct")
Expand Down Expand Up @@ -235,30 +236,30 @@ func (v *VersionedSubmitBlockRequest) Value() (*uint256.Int, error) {
}
}

// MessageHashTreeRoot returns the hash tree root of the message of the bid.
func (v *VersionedSubmitBlockRequest) MessageHashTreeRoot() (phase0.Root, error) {
// BidTrace returns the bid trace of the request.
func (v *VersionedSubmitBlockRequest) BidTrace() (*v1.BidTrace, error) {
if v == nil {
return phase0.Root{}, errors.New("nil struct")
return nil, errors.New("nil struct")
}
switch v.Version {
case consensusspec.DataVersionBellatrix:
if v.Bellatrix == nil {
return phase0.Root{}, errors.New("no data")
return nil, errors.New("no data")
}
if v.Bellatrix.Message == nil {
return phase0.Root{}, errors.New("no data message")
return nil, errors.New("no data message")
}
return v.Bellatrix.Message.HashTreeRoot()
return v.Bellatrix.Message, nil
case consensusspec.DataVersionCapella:
if v.Capella == nil {
return phase0.Root{}, errors.New("no data")
return nil, errors.New("no data")
}
if v.Capella.Message == nil {
return phase0.Root{}, errors.New("no data message")
return nil, errors.New("no data message")
}
return v.Capella.Message.HashTreeRoot()
return v.Capella.Message, nil
default:
return phase0.Root{}, errors.New("unsupported version")
return nil, errors.New("unsupported version")
}
}

Expand All @@ -283,7 +284,7 @@ func (v *VersionedSubmitBlockRequest) Signature() (phase0.BLSSignature, error) {
}
}

// ExecutionPayloadBlockHash returns the block hash of the payload
// ExecutionPayloadBlockHash returns the block hash of the payload.
func (v *VersionedSubmitBlockRequest) ExecutionPayloadBlockHash() (phase0.Hash32, error) {
if v == nil {
return phase0.Hash32{}, errors.New("nil struct")
Expand All @@ -310,7 +311,7 @@ func (v *VersionedSubmitBlockRequest) ExecutionPayloadBlockHash() (phase0.Hash32
}
}

// ExecutionPayloadParentHash returns the block hash of the payload
// ExecutionPayloadParentHash returns the block hash of the payload.
func (v *VersionedSubmitBlockRequest) ExecutionPayloadParentHash() (phase0.Hash32, error) {
if v == nil {
return phase0.Hash32{}, errors.New("nil struct")
Expand All @@ -337,7 +338,7 @@ func (v *VersionedSubmitBlockRequest) ExecutionPayloadParentHash() (phase0.Hash3
}
}

// PrevRandao returns the prev randao of the payload
// PrevRandao returns the prev randao of the payload.
func (v *VersionedSubmitBlockRequest) PrevRandao() (phase0.Hash32, error) {
if v == nil {
return phase0.Hash32{}, errors.New("nil struct")
Expand All @@ -364,7 +365,7 @@ func (v *VersionedSubmitBlockRequest) PrevRandao() (phase0.Hash32, error) {
}
}

// GasLimit returns the prev randao of the payload
// GasLimit returns the prev randao of the payload.
func (v *VersionedSubmitBlockRequest) GasLimit() (uint64, error) {
if v == nil {
return 0, errors.New("nil struct")
Expand All @@ -391,7 +392,7 @@ func (v *VersionedSubmitBlockRequest) GasLimit() (uint64, error) {
}
}

// GasUsed returns the prev randao of the payload
// GasUsed returns the prev randao of the payload.
func (v *VersionedSubmitBlockRequest) GasUsed() (uint64, error) {
if v == nil {
return 0, errors.New("nil struct")
Expand Down Expand Up @@ -472,7 +473,7 @@ func (v *VersionedSubmitBlockRequest) Timestamp() (uint64, error) {
}
}

// Transactions returns the transactions of the payload
// Transactions returns the transactions of the payload.
func (v *VersionedSubmitBlockRequest) Transactions() ([]consensusbellatrix.Transaction, error) {
if v == nil {
return nil, errors.New("nil struct")
Expand All @@ -499,7 +500,7 @@ func (v *VersionedSubmitBlockRequest) Transactions() ([]consensusbellatrix.Trans
}
}

// Withdrawals returns the withdrawals of the payload
// Withdrawals returns the withdrawals of the payload.
func (v *VersionedSubmitBlockRequest) Withdrawals() ([]*consensuscapella.Withdrawal, error) {
if v == nil {
return nil, errors.New("nil struct")
Expand Down
19 changes: 10 additions & 9 deletions spec/versionedsubmitblockrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/attestantio/go-builder-client/api/bellatrix"
"github.com/attestantio/go-builder-client/api/capella"
apiv1 "github.com/attestantio/go-builder-client/api/v1"
v1 "github.com/attestantio/go-builder-client/api/v1"
"github.com/attestantio/go-builder-client/spec"
consensusspec "github.com/attestantio/go-eth2-client/spec"
consensusbellatrix "github.com/attestantio/go-eth2-client/spec/bellatrix"
Expand Down Expand Up @@ -737,11 +738,11 @@ func TestVersionedSubmitBlockRequestValue(t *testing.T) {
}
}

func TestVersionedSubmitBlockRequestMessageHashTreeRoot(t *testing.T) {
func TestVersionedSubmitBlockRequestBidTrace(t *testing.T) {
tests := []struct {
name string
request *spec.VersionedSubmitBlockRequest
res phase0.Root
res *v1.BidTrace
err string
}{
{
Expand Down Expand Up @@ -780,9 +781,9 @@ func TestVersionedSubmitBlockRequestMessageHashTreeRoot(t *testing.T) {
},
},
},
res: phase0.Root{
0x6e, 0x21, 0x57, 0xbe, 0x11, 0xe5, 0xda, 0xc3, 0x30, 0x6b, 0xd6, 0x41, 0x61, 0x17, 0x93, 0x30,
0x53, 0xe8, 0x7d, 0x66, 0xb2, 0xfc, 0xcd, 0x7b, 0xd1, 0x7f, 0x27, 0xee, 0x90, 0xb4, 0x6c, 0x7c,
res: &v1.BidTrace{
Slot: 123,
Value: uint256.NewInt(12345),
},
},
{
Expand Down Expand Up @@ -810,16 +811,16 @@ func TestVersionedSubmitBlockRequestMessageHashTreeRoot(t *testing.T) {
},
},
},
res: phase0.Root{
0x6e, 0x21, 0x57, 0xbe, 0x11, 0xe5, 0xda, 0xc3, 0x30, 0x6b, 0xd6, 0x41, 0x61, 0x17, 0x93, 0x30,
0x53, 0xe8, 0x7d, 0x66, 0xb2, 0xfc, 0xcd, 0x7b, 0xd1, 0x7f, 0x27, 0xee, 0x90, 0xb4, 0x6c, 0x7c,
res: &v1.BidTrace{
Slot: 123,
Value: uint256.NewInt(12345),
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
res, err := test.request.MessageHashTreeRoot()
res, err := test.request.BidTrace()
if test.err != "" {
require.EqualError(t, err, test.err)
} else {
Expand Down

0 comments on commit 2fcac99

Please sign in to comment.