Skip to content

Commit 392ab8d

Browse files
authored
gzip testdata (#459)
1 parent 3e00a29 commit 392ab8d

13 files changed

+40
-593
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ go run . website --network sepolia --db postgres://postgres:postgres@localhost:5
107107
curl localhost:9062/eth/v1/builder/status
108108

109109
# Send test validator registrations
110-
curl -X POST localhost:9062/eth/v1/builder/validators -d @testdata/valreg2.json
110+
curl -X POST -H'Content-Encoding: gzip' localhost:9062/eth/v1/builder/validators --data-binary @testdata/valreg2.json.gz
111111

112112
# Delete previous registrations
113113
redis-cli DEL boost-relay/sepolia:validators-registration boost-relay/sepolia:validators-registration-timestamp

common/ssz_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ import (
1212
)
1313

1414
func TestSSZBuilderSubmission(t *testing.T) {
15-
depositData := new(capella.SubmitBlockRequest)
16-
17-
byteValue, err := os.ReadFile("../testdata/submitBlockPayloadCapella_Goerli.json")
18-
require.NoError(t, err)
15+
byteValue := LoadGzippedBytes(t, "../testdata/submitBlockPayloadCapella_Goerli.json.gz")
1916

20-
err = json.Unmarshal(byteValue, &depositData)
17+
depositData := new(capella.SubmitBlockRequest)
18+
err := json.Unmarshal(byteValue, &depositData)
2119
require.NoError(t, err)
2220

2321
ssz, err := depositData.MarshalSSZ()
2422
require.NoError(t, err)
2523

26-
sszExpectedBytes, err := os.ReadFile("../testdata/submitBlockPayloadCapella_Goerli.ssz")
27-
require.NoError(t, err)
24+
sszExpectedBytes := LoadGzippedBytes(t, "../testdata/submitBlockPayloadCapella_Goerli.ssz.gz")
2825
require.Equal(t, sszExpectedBytes, ssz)
2926

3027
htr, err := depositData.HashTreeRoot()

common/test_utils.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package common
22

33
import (
4+
"compress/gzip"
5+
"encoding/json"
6+
"io"
7+
"os"
8+
"testing"
9+
410
"github.com/attestantio/go-builder-client/api/capella"
511
"github.com/attestantio/go-eth2-client/spec/bellatrix"
612
consensuscapella "github.com/attestantio/go-eth2-client/spec/capella"
713
"github.com/flashbots/go-boost-utils/bls"
814
boostTypes "github.com/flashbots/go-boost-utils/types"
915
"github.com/sirupsen/logrus"
16+
"github.com/stretchr/testify/require"
1017
)
1118

1219
// TestLog is used to log information in the test methods
@@ -71,3 +78,23 @@ func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2) BuilderSu
7178
},
7279
}
7380
}
81+
82+
func LoadGzippedBytes(t *testing.T, filename string) []byte {
83+
t.Helper()
84+
fi, err := os.Open(filename)
85+
require.NoError(t, err)
86+
defer fi.Close()
87+
fz, err := gzip.NewReader(fi)
88+
require.NoError(t, err)
89+
defer fz.Close()
90+
val, err := io.ReadAll(fz)
91+
require.NoError(t, err)
92+
return val
93+
}
94+
95+
func LoadGzippedJSON(t *testing.T, filename string, dst any) {
96+
t.Helper()
97+
b := LoadGzippedBytes(t, filename)
98+
err := json.Unmarshal(b, dst)
99+
require.NoError(t, err)
100+
}

database/typesconv_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
package database
22

33
import (
4-
"os"
54
"testing"
65
"time"
76

8-
"github.com/attestantio/go-eth2-client/spec/capella"
97
"github.com/flashbots/mev-boost-relay/common"
108
"github.com/stretchr/testify/require"
119
)
1210

1311
func TestExecutionPayloadEntryToExecutionPayload(t *testing.T) {
14-
capellaPayload := new(capella.ExecutionPayload)
15-
val, err := os.ReadFile("../testdata/executionPayloadCapella_Goerli.json")
16-
require.NoError(t, err)
17-
err = capellaPayload.UnmarshalJSON(val)
18-
require.NoError(t, err)
19-
12+
filename := "../testdata/executionPayloadCapella_Goerli.json.gz"
13+
payloadBytes := common.LoadGzippedBytes(t, filename)
2014
entry := &ExecutionPayloadEntry{
2115
ID: 123,
2216
Slot: 5552306,
@@ -25,10 +19,10 @@ func TestExecutionPayloadEntryToExecutionPayload(t *testing.T) {
2519
ProposerPubkey: "0x8559727ee65c295279332198029c939557f4d2aba0751fc55f71d0733b8aa17cd0301232a7f21a895f81eacf55c97ec4",
2620
BlockHash: "0x1bafdc454116b605005364976b134d761dd736cb4788d25c835783b46daeb121",
2721
Version: common.ForkVersionStringCapella,
28-
Payload: string(val),
22+
Payload: string(payloadBytes),
2923
}
3024

3125
payload, err := ExecutionPayloadEntryToExecutionPayload(entry)
3226
require.NoError(t, err)
33-
require.Equal(t, capellaPayload.BlockHash.String(), payload.Capella.Capella.BlockHash.String())
27+
require.Equal(t, "0x1bafdc454116b605005364976b134d761dd736cb4788d25c835783b46daeb121", payload.Capella.Capella.BlockHash.String())
3428
}

services/api/service_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"math/big"
1010
"net/http"
1111
"net/http/httptest"
12-
"os"
1312
"testing"
1413
"time"
1514

@@ -372,11 +371,10 @@ func TestDataApiGetDataProposerPayloadDelivered(t *testing.T) {
372371
}
373372

374373
func TestBuilderSubmitBlockSSZ(t *testing.T) {
375-
requestPayloadJSONBytes, err := os.ReadFile("../../testdata/submitBlockPayloadCapella_Goerli.json")
376-
require.NoError(t, err)
374+
requestPayloadJSONBytes := common.LoadGzippedBytes(t, "../../testdata/submitBlockPayloadCapella_Goerli.json.gz")
377375

378376
req := new(common.BuilderSubmitBlockRequest)
379-
err = json.Unmarshal(requestPayloadJSONBytes, &req)
377+
err := json.Unmarshal(requestPayloadJSONBytes, &req)
380378
require.NoError(t, err)
381379

382380
reqSSZ, err := req.Capella.MarshalSSZ()
@@ -397,7 +395,7 @@ func TestBuilderSubmitBlock(t *testing.T) {
397395
submissionTimestamp := 1606824419
398396

399397
// Payload attributes
400-
payloadJSONFilename := "../../testdata/submitBlockPayloadCapella_Goerli.json"
398+
payloadJSONFilename := "../../testdata/submitBlockPayloadCapella_Goerli.json.gz"
401399
parentHash := "0xbd3291854dc822b7ec585925cda0e18f06af28fa2886e15f52d52dd4b6f94ed6"
402400
feeRec, err := types.HexToAddress("0x5cc0dde14e7256340cc820415a6022a7d1c93a35")
403401
require.NoError(t, err)
@@ -429,7 +427,7 @@ func TestBuilderSubmitBlock(t *testing.T) {
429427

430428
// Prepare the request payload
431429
req := new(common.BuilderSubmitBlockRequest)
432-
requestPayloadJSONBytes, err := os.ReadFile(payloadJSONFilename)
430+
requestPayloadJSONBytes := common.LoadGzippedBytes(t, payloadJSONFilename)
433431
require.NoError(t, err)
434432
err = json.Unmarshal(requestPayloadJSONBytes, &req)
435433
require.NoError(t, err)

0 commit comments

Comments
 (0)