Skip to content

Commit

Permalink
Add ForkchoiceResponse store test (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain authored Mar 18, 2022
1 parent fc34b90 commit 9912f48
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
8 changes: 4 additions & 4 deletions lib/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestStrToBytes(t *testing.T) {
require.Equal(t, a, b)
}

func TestMevService_ForckChoiceUpdated(t *testing.T) {
func TestMevService_ForkChoiceUpdated(t *testing.T) {
tests := []httpTest{
{
"basic success",
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestRelayService_ProposeBlindedBlockV1(t *testing.T) {
}
}

func TestRelayervice_GetPayloadHeaderV1(t *testing.T) {
func TestRelayService_GetPayloadHeaderV1(t *testing.T) {
tests := []httpTest{
{
"basic success",
Expand All @@ -274,7 +274,7 @@ func TestRelayervice_GetPayloadHeaderV1(t *testing.T) {
}
}

func TestRelayervice_GetPayloadAndPropose(t *testing.T) {
func TestRelayService_GetPayloadAndPropose(t *testing.T) {
store := NewStore()

payload := ExecutionPayloadWithTxRootV1{
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestRelayervice_GetPayloadAndPropose(t *testing.T) {
}
}

func TestRelayervice_GetPayloadAndProposeCamelCase(t *testing.T) {
func TestRelayService_GetPayloadAndProposeCamelCase(t *testing.T) {
store := NewStore()

payload := ExecutionPayloadWithTxRootV1{
Expand Down
10 changes: 6 additions & 4 deletions lib/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ type rpcResponseContainer struct {
}

// ForkchoiceUpdatedV1 TODO
func (m *RelayService) ForkchoiceUpdatedV1(r *http.Request, args *[]interface{}, result *ForkChoiceResponse) error {
func (m *RelayService) ForkchoiceUpdatedV1(_ *http.Request, args *[]interface{}, result *ForkChoiceResponse) error {
method := "engine_forkchoiceUpdatedV1"
logMethod := m.log.WithField("method", method)

boostPayloadID := make(hexutil.Bytes, 8)
rand.Read(boostPayloadID)
if _, err := rand.Read(boostPayloadID); err != nil {
return err
}

var wg sync.WaitGroup
hasValidResponse := false
Expand Down Expand Up @@ -142,7 +144,7 @@ func (m *RelayService) ForkchoiceUpdatedV1(r *http.Request, args *[]interface{},
}

// ProposeBlindedBlockV1 TODO
func (m *RelayService) ProposeBlindedBlockV1(r *http.Request, args *SignedBlindedBeaconBlock, result *ExecutionPayloadWithTxRootV1) error {
func (m *RelayService) ProposeBlindedBlockV1(_ *http.Request, args *SignedBlindedBeaconBlock, result *ExecutionPayloadWithTxRootV1) error {
method := "builder_proposeBlindedBlockV1"
logMethod := m.log.WithField("method", method)

Expand Down Expand Up @@ -232,7 +234,7 @@ func (m *RelayService) ProposeBlindedBlockV1(r *http.Request, args *SignedBlinde
}

// GetPayloadHeaderV1 TODO
func (m *RelayService) GetPayloadHeaderV1(r *http.Request, args *string, result *ExecutionPayloadWithTxRootV1) error {
func (m *RelayService) GetPayloadHeaderV1(_ *http.Request, args *string, result *ExecutionPayloadWithTxRootV1) error {
method := "engine_getPayloadV1"
logMethod := m.log.WithField("method", method)

Expand Down
28 changes: 27 additions & 1 deletion lib/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)

func Test_store_Get(t *testing.T) {
func Test_store_SetGetExecutionPayload(t *testing.T) {
s := NewStore()
h := common.HexToHash("0x1")
payload := s.GetExecutionPayload(h)
Expand All @@ -27,3 +28,28 @@ func Test_store_Get(t *testing.T) {
t.Errorf("Expected %v, got %v", payload, s.GetExecutionPayload(h))
}
}

func Test_store_SetGetGetForkchoiceResponse(t *testing.T) {
s := NewStore()
id := "0x1"
_, ok := s.GetForkchoiceResponse(id)
require.Equal(t, false, ok)

relayURL := "abc"
relayPayloadID := "0x2"
s.SetForkchoiceResponse(id, relayURL, relayPayloadID)

res, ok := s.GetForkchoiceResponse(id)
require.Equal(t, true, ok)
require.Equal(t, res[relayURL], relayPayloadID)

relayURL = "def"
_, ok = res[relayURL]
require.Equal(t, false, ok)
relayPayloadID = "0x3"
s.SetForkchoiceResponse(id, relayURL, relayPayloadID)

res, ok = s.GetForkchoiceResponse(id)
require.Equal(t, true, ok)
require.Equal(t, res[relayURL], relayPayloadID)
}

0 comments on commit 9912f48

Please sign in to comment.