Skip to content

Commit 26976a7

Browse files
authored
[CI] Added API spec tests (#61)
## 📝 Summary Adding CI API spec tests to prevent future regressions. Basic plumbing in this PR, more tests coming in follow-up PR(s). Tests using Hurl: - https://github.com/Orange-OpenSource/hurl - https://hurl.dev/
1 parent 14ba0d8 commit 26976a7

File tree

6 files changed

+152
-3
lines changed

6 files changed

+152
-3
lines changed

.github/workflows/checks.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
id: go
3434

3535
- name: Check out code into the Go module directory
36-
uses: actions/checkout@v2
36+
uses: actions/checkout@v4
3737

3838
- name: Run migrations
3939
run: for file in schema/*.sql; do psql "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" -f $file; done
@@ -52,7 +52,7 @@ jobs:
5252
id: go
5353

5454
- name: Check out code into the Go module directory
55-
uses: actions/checkout@v2
55+
uses: actions/checkout@v4
5656

5757
- name: Install gofumpt
5858
run: go install mvdan.cc/gofumpt@v0.4.0
@@ -74,3 +74,25 @@ jobs:
7474
go mod tidy
7575
git update-index -q --really-refresh
7676
git diff-index HEAD
77+
78+
integration-test:
79+
name: Integration Test
80+
runs-on: ubuntu-latest
81+
steps:
82+
- name: Set up Go
83+
uses: actions/setup-go@v3
84+
with:
85+
go-version: ^1.24
86+
id: go
87+
88+
- name: Check out code into the Go module directory
89+
uses: actions/checkout@v4
90+
91+
- name: Set up Docker Compose
92+
uses: docker/setup-compose-action@v1
93+
94+
- name: Integration test
95+
run: |
96+
curl --location --remote-name https://github.com/Orange-OpenSource/hurl/releases/download/6.1.1/hurl_6.1.1_amd64.deb
97+
sudo dpkg -i hurl_6.1.1_amd64.deb
98+
./scripts/ci/integration-test.sh

docker/docker-compose.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
services:
22
db:
33
image: flashbots/builder-hub-db
4+
build:
5+
context: ../.
6+
dockerfile: docker/database/Dockerfile
47
ports:
58
- 127.0.0.1:5432:5432
69
environment:
@@ -17,6 +20,9 @@ services:
1720

1821
web:
1922
image: flashbots/builder-hub
23+
build:
24+
context: ../.
25+
dockerfile: docker/httpserver/Dockerfile
2026
depends_on:
2127
db:
2228
condition: service_healthy

docs/devenv-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ curl -v \
6767
--data '{
6868
"name": "test_builder",
6969
"ip_address": "1.2.3.4",
70+
"dns_name": "foobar-v1.a.b.c",
7071
"network": "production"
7172
}'
7273

7374
# 3. Create (and enable) a new builder configuration
7475
curl -v \
7576
--url http://localhost:8081/api/admin/v1/builders/configuration/test_builder \
7677
--data '{
77-
"dns_name": "foobar-v1.a.b.c",
7878
"rbuilder": {
7979
"extra_data": "FooBar"
8080
}

scripts/ci/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API tests using https://hurl.dev

scripts/ci/integration-test.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
SCRIPT_DIR=$(dirname "$0")
5+
cd "$SCRIPT_DIR/../.."
6+
7+
# Build the Docker images
8+
docker compose -f docker/docker-compose.yaml build
9+
10+
# Start the Docker containers
11+
docker compose -f docker/docker-compose.yaml up -d
12+
13+
# Waiting for the service to be ready
14+
echo "Waiting for containers to be ready..."
15+
printf 'GET http://localhost:8888/\nHTTP 404' | hurl --retry 60 > /dev/null;
16+
17+
# Run the tests
18+
echo "Running integration tests..."
19+
hurl --test scripts/ci/setup.hurl
20+
echo "Integration tests completed successfully."
21+
22+
# Stop and remove the Docker containers
23+
docker compose -f docker/docker-compose.yaml down -v

scripts/ci/setup.hurl

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#
2+
# MEASUREMENTS SETUP
3+
#
4+
# [Admin API] Create a new measurement
5+
POST http://localhost:8081/api/admin/v1/measurements
6+
{
7+
"measurement_id": "test1",
8+
"attestation_type": "test",
9+
"measurements": {}
10+
}
11+
HTTP 200
12+
13+
# [Admin API] Enable the measurement
14+
POST http://localhost:8081/api/admin/v1/measurements/activation/test1
15+
{
16+
"enabled": true
17+
}
18+
HTTP 200
19+
20+
# [Internal API] Verify that the measurement is now available
21+
GET http://localhost:8082/api/l1-builder/v1/measurements
22+
HTTP 200
23+
[Asserts]
24+
jsonpath "$.[0].measurement_id" == "test1"
25+
jsonpath "$.[0].attestation_type" == "test"
26+
27+
#
28+
# BUILDER SETUP
29+
#
30+
# [Admin API] Create a new builder instance (with IP address 1.2.3.4, which is fixed in the mock-proxy)
31+
POST http://localhost:8081/api/admin/v1/builders
32+
{
33+
"name": "test_builder",
34+
"ip_address": "1.2.3.4",
35+
"dns_name": "foobar-v1.a.b.c",
36+
"network": "production"
37+
}
38+
HTTP 200
39+
40+
# [Admin API] Create (and enable) a new builder configuration
41+
POST http://localhost:8081/api/admin/v1/builders/configuration/test_builder
42+
{
43+
"rbuilder": {
44+
"extra_data": "FooBar"
45+
}
46+
}
47+
HTTP 200
48+
49+
# [Admin API] Enable the new builder instance
50+
POST http://localhost:8081/api/admin/v1/builders/activation/test_builder
51+
{
52+
"enabled": true
53+
}
54+
HTTP 200
55+
56+
# [Internal API] Get the list of peers
57+
GET http://localhost:8080/api/internal/l1-builder/v1/builders
58+
HTTP 200
59+
[Asserts]
60+
jsonpath "$.[0].ip" == "1.2.3.4"
61+
jsonpath "$.[0].name" == "test_builder"
62+
63+
# [Internal API] Get the list of peers (v2)
64+
GET http://localhost:8080/api/internal/l1-builder/v2/network/production/builders
65+
HTTP 200
66+
[Asserts]
67+
jsonpath "$.[0].ip" == "1.2.3.4"
68+
jsonpath "$.[0].name" == "test_builder"
69+
70+
# [Builder API] Verify that the builder can get it's configuration (NOT WORKING, TODO)
71+
#GET http://localhost:8888/api/l1-builder/v1/configuration
72+
#HTTP 200
73+
#[Asserts]
74+
#jsonpath "$.[0].dns_name" == "foobar-v1.a.b.c"
75+
#jsonpath "$.[0].rbuilder.extra_data" == "FooBar"
76+
77+
#
78+
# BUILDER APIs (via proxy)
79+
#
80+
# [Builder API] Get the list of peers
81+
GET http://localhost:8888/api/l1-builder/v1/builders
82+
HTTP 200
83+
[Asserts]
84+
jsonpath "$.[0].ip" == "1.2.3.4"
85+
jsonpath "$.[0].name" == "test_builder"
86+
87+
# [Builder API] Register credentials for 'rbuilder' service
88+
#POST http://localhost:8888/api/l1-builder/v1/register_credentials/rbuilder
89+
#{
90+
# "ecdsa_pubkey_address": "0x321f3426eEc20DE1910af1CD595c4DD83BEA0BA5"
91+
#}
92+
93+
## [Builder API] List of peers now includes the added credentials
94+
#GET http://localhost:8888/api/l1-builder/v1/builders
95+
#HTTP 200
96+
#[Asserts]
97+
#jsonpath "$.[0].rbuilder.ecdsa_pubkey_address" == "0x321f3426eec20de1910af1cd595c4dd83bea0ba5"

0 commit comments

Comments
 (0)