Skip to content
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

Test for PublicNode Sepolia Beaon APIs #2113

Merged
merged 11 commits into from
Nov 6, 2024
51 changes: 51 additions & 0 deletions go/host/l1/blobresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package l1
import (
"context"
"net/http"
"net/url"
"testing"

gethcommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -30,3 +31,53 @@ func TestBlobResolver(t *testing.T) {
require.NoError(t, err)
require.Len(t, blobs, 2)
}

// TestSepoliaBlobResolver checks the public node sepolia beacon APIs work as expected
func TestSepoliaBlobResolver(t *testing.T) {
httpClient := ethadapter.NewBaseHTTPClient(new(http.Client), "https://ethereum-sepolia-beacon-api.publicnode.com/")

// get the latest slot from the beacon headers
var beaconHeaderResponse BeaconHeaderResponse
err := httpClient.Request(
context.Background(),
&beaconHeaderResponse,
"/eth/v1/beacon/headers/",
url.Values{}, // empty query params

)

require.NoError(t, err, "Expected no error when calling /eth/v1/beacon/headers")
require.NotEmpty(t, beaconHeaderResponse.Data)
require.NotEmpty(t, beaconHeaderResponse.Data[0].Header.Message.Slot)

slot := beaconHeaderResponse.Data[0].Header.Message.Slot

// get the sidecars for the latest slot from the beacon blob sidecars
// manually calling the endpoint instead of using the blob resolver since we dont want to convert the slot back to
// a block timestamp and convert back to the slot in FetchBlobs
var sidecarResponse ethadapter.APIGetBlobSidecarsResponse
err = httpClient.Request(
context.Background(),
&sidecarResponse,
"eth/v1/beacon/blob_sidecars/"+slot,
url.Values{}, // empty query params
)

require.NoError(t, err)
require.True(t, len(sidecarResponse.Data) > 1)
}

// Response struct for /eth/v1/beacon/headers/
type BeaconHeaderResponse struct {
ExecutionOptimistic bool `json:"execution_optimistic"`
Finalized bool `json:"finalized"`
Data []struct {
Root string `json:"root"`
Canonical bool `json:"canonical"`
Header struct {
Message struct {
Slot string `json:"slot"`
} `json:"message"`
} `json:"header"`
} `json:"data"`
}
Loading