2024-01-11 01:06:35 +00:00
|
|
|
//go:build integration
|
|
|
|
|
2023-12-25 01:34:13 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon/cl/clparams"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetSpec(t *testing.T) {
|
|
|
|
|
|
|
|
// setupTestingHandler(t, clparams.Phase0Version)
|
|
|
|
_, _, _, _, _, handler, _, _, _ := setupTestingHandler(t, clparams.Phase0Version)
|
|
|
|
|
|
|
|
server := httptest.NewServer(handler.mux)
|
|
|
|
defer server.Close()
|
|
|
|
|
|
|
|
resp, err := http.Get(server.URL + "/eth/v1/config/spec")
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
out := make(map[string]interface{})
|
|
|
|
err = json.NewDecoder(resp.Body).Decode(&out)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
data := out["data"].(map[string]interface{})
|
|
|
|
require.Equal(t, data["SlotsPerEpoch"], float64(32))
|
|
|
|
require.Equal(t, data["SlotsPerHistoricalRoot"], float64(8192))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetForkSchedule(t *testing.T) {
|
|
|
|
|
|
|
|
// setupTestingHandler(t, clparams.Phase0Version)
|
|
|
|
_, _, _, _, _, handler, _, _, _ := setupTestingHandler(t, clparams.Phase0Version)
|
|
|
|
|
|
|
|
server := httptest.NewServer(handler.mux)
|
|
|
|
defer server.Close()
|
|
|
|
|
|
|
|
resp, err := http.Get(server.URL + "/eth/v1/config/fork_schedule")
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
out := make(map[string]interface{})
|
|
|
|
err = json.NewDecoder(resp.Body).Decode(&out)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Greater(t, len(out["data"].([]interface{})), 2)
|
|
|
|
for _, v := range out["data"].([]interface{}) {
|
|
|
|
data := v.(map[string]interface{})
|
|
|
|
require.NotNil(t, data["current_version"])
|
|
|
|
require.NotNil(t, data["epoch"])
|
|
|
|
require.NotNil(t, data["previous_version"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetDepositContract(t *testing.T) {
|
|
|
|
|
|
|
|
// setupTestingHandler(t, clparams.Phase0Version)
|
|
|
|
_, _, _, _, _, handler, _, _, _ := setupTestingHandler(t, clparams.Phase0Version)
|
|
|
|
|
|
|
|
server := httptest.NewServer(handler.mux)
|
|
|
|
defer server.Close()
|
|
|
|
|
|
|
|
resp, err := http.Get(server.URL + "/eth/v1/config/deposit_contract")
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
out := make(map[string]interface{})
|
|
|
|
err = json.NewDecoder(resp.Body).Decode(&out)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
data := out["data"].(map[string]interface{})
|
|
|
|
require.Equal(t, data["address"], "0x00000000219ab540356cBB839Cbe05303d7705Fa")
|
2023-12-25 23:34:38 +00:00
|
|
|
require.Equal(t, data["chain_id"], "1")
|
2023-12-25 01:34:13 +00:00
|
|
|
}
|