Skip to content

Commit

Permalink
ci changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TymKh committed Nov 6, 2024
1 parent 22862dc commit 13f561d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 46 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Set up Go
uses: actions/setup-go@v3
Expand All @@ -20,6 +35,9 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Run migrations
run: for file in schema/*.sql; do psql "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" -f $file; done

- name: Run unit tests and generate the coverage report
run: make test-race

Expand All @@ -40,7 +58,7 @@ jobs:
run: go install mvdan.cc/[email protected]

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@v0.4.2
run: go install honnef.co/go/tools/cmd/staticcheck@2024.1.1

- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/[email protected]
Expand Down
21 changes: 11 additions & 10 deletions adapters/database/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package database

import (
"context"
"fmt"
"net"
"testing"

"github.com/stretchr/testify/require"
)

func TestGetBuilder(t *testing.T) {
Expand All @@ -14,25 +15,25 @@ func TestGetBuilder(t *testing.T) {
}
t.Run("GetBuilder2", func(t *testing.T) {
t.Run("should return a builder", func(t *testing.T) {
_, err := serv.DB.Exec("INSERT INTO public.builders (name, ip_address, is_active, created_at, updated_at) VALUES ('flashbots-builder', '192.168.1.1', true, '2024-10-11 13:05:56.845615 +00:00', '2024-10-11 13:05:56.845615 +00:00');")
require.NoError(t, err)
whitelist, err := serv.GetBuilderByIP(net.ParseIP("192.168.1.1"))
if err != nil {
t.Errorf("GetIPWhitelistByIP() = %v; want nil", err)
}
fmt.Println(whitelist)
require.NoError(t, err)
require.Equal(t, whitelist.Name, "flashbots-builder")
})
t.Run("get all active builders", func(t *testing.T) {
whitelist, err := serv.GetActiveBuildersWithServiceCredentials(context.Background())
if err != nil {
t.Errorf("GetIPWhitelistByIP() = %v; want nil", err)
}
fmt.Println(whitelist)
require.Nil(t, err)
require.Lenf(t, whitelist, 1, "expected 1 builder, got %d", len(whitelist))
require.Equal(t, whitelist[0].Builder.Name, "flashbots-builder")
})
t.Run("get all active measurements", func(t *testing.T) {
whitelist, err := serv.GetActiveMeasurements(context.Background())
if err != nil {
t.Errorf("GetIPWhitelistByIP() = %v; want nil", err)
}
fmt.Println(whitelist)
require.Len(t, whitelist, 0)
// fmt.Println(whitelist)
})
})
}
4 changes: 0 additions & 4 deletions httpserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,3 @@ func (srv *Server) handleTestPanic(w http.ResponseWriter, r *http.Request) {
panic("foo")
// w.WriteHeader(http.StatusOK)
}

//
// BuilderConfigHub API: https://www.notion.so/flashbots/BuilderConfigHub-1076b4a0d8768074bcdcd1c06c26ec87?pvs=4#10a6b4a0d87680fd81e0cad9bac3b8c5
//
32 changes: 1 addition & 31 deletions httpserver/handler_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package httpserver

import (
"bytes"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -17,6 +16,7 @@ import (
var testServerConfig = &HTTPServerConfig{
Log: getTestLogger(),
}
var _ = testServerConfig

func getTestLogger() *httplog.Logger {
return common.SetupLogger(&common.LoggingOpts{
Expand Down Expand Up @@ -99,33 +99,3 @@ func Test_Handlers_Healthcheck_Drain_Undrain(t *testing.T) {
require.Equal(t, http.StatusOK, resp.StatusCode, "Healthcheck must return `Ok` after undraining")
}
}

func Test_Handlers_BuilderConfigHub(t *testing.T) {
routes := []struct {
method string
path string
payload []byte
}{
// BuilderConfigHub API: https://www.notion.so/flashbots/BuilderConfigHub-1076b4a0d8768074bcdcd1c06c26ec87?pvs=4#10a6b4a0d87680fd81e0cad9bac3b8c5
{http.MethodGet, "/api/l1-builder/v1/measurements", nil},
{http.MethodGet, "/api/l1-builder/v1/configuration", nil},
{http.MethodGet, "/api/l1-builder/v1/builders", nil},
{http.MethodPost, "/api/l1-builder/v1/register_credentials/rbuilder", []byte(`{"var1":"foo"}`)},
}

srv, err := NewHTTPServer(testServerConfig, ports.NewBuilderHubHandler(nil, getTestLogger()))
require.NoError(t, err)

for _, r := range routes {
var payload io.Reader
if r.payload != nil {
payload = bytes.NewReader(r.payload)
}
req, err := http.NewRequest(r.method, r.path, payload)
require.NoError(t, err)

rr := httptest.NewRecorder()
srv.getRouter().ServeHTTP(rr, req)
require.Equal(t, http.StatusOK, rr.Code)
}
}

0 comments on commit 13f561d

Please sign in to comment.