@@ -44,24 +44,34 @@ var (
4444 flashbotsSigner * signature.Signer
4545)
4646
47- func testAddBuilderhubPeer (proxyIndex int ) {
47+ func testAddBuilderhubPeer (t * testing.T , proxyIndex int ) {
48+ t .Helper ()
4849 proxy := proxies [proxyIndex ]
4950
51+ // first we ask proxy to register its own credentials on the builderhub (its will register signign key address)
52+ err := proxy .proxy .RegisterSecrets (context .Background ())
53+ if err != nil {
54+ t .Fatal ("Failed to register secret" , err )
55+ }
56+
57+ // next we add instance data for a valid TLS certificate
5058 ip := proxy .ip
5159 name := proxy .proxy .Name
5260
53- req := ConfighubOrderflowProxyCredentials {
54- EcdsaPubkeyAddress : proxy .proxy .OrderflowSigner .Address (),
61+ index := - 1
62+ for i , peer := range builderHubPeers {
63+ if peer .Name == name && peer .IP == ip {
64+ index = i
65+ break
66+ }
67+ }
68+ if index == - 1 {
69+ t .Fatal ("Peer is not properly registered on the builerhub" )
5570 }
5671
57- builderHubPeers = append (builderHubPeers , ConfighubBuilder {
58- Name : name ,
59- DNSName : ip ,
60- OrderflowProxy : req ,
61- Instance : ConfighubInstanceData {
62- TLSCert : string (proxy .PublicCertPEM ),
63- },
64- })
72+ builderHubPeers [index ].Instance = ConfighubInstanceData {
73+ TLSCert : string (proxy .PublicCertPEM ),
74+ }
6575}
6676
6777func ServeHTTPRequestToChan (channel chan * RequestData ) * httptest.Server {
@@ -168,7 +178,32 @@ func TestMain(m *testing.M) {
168178
169179 archiveServerRequests = make (chan * RequestData )
170180 builderHub = httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
171- if r .URL .Path == "/api/l1-builder/v1/builders" {
181+ body , _ := io .ReadAll (r .Body )
182+
183+ if r .URL .Path == "/api/l1-builder/v1/register_credentials/orderflow_proxy" {
184+ var req ConfighubOrderflowProxyCredentials
185+ err := json .Unmarshal (body , & req )
186+ if err != nil {
187+ w .WriteHeader (http .StatusBadRequest )
188+ _ , _ = w .Write ([]byte (err .Error ()))
189+ }
190+ var (
191+ ip string
192+ name string
193+ )
194+ for _ , proxy := range proxies {
195+ if proxy .proxy .OrderflowSigner .Address () == req .EcdsaPubkeyAddress {
196+ ip = proxy .ip
197+ name = proxy .proxy .Name
198+ break
199+ }
200+ }
201+ builderHubPeers = append (builderHubPeers , ConfighubBuilder {
202+ Name : name ,
203+ IP : ip ,
204+ OrderflowProxy : req ,
205+ })
206+ } else if r .URL .Path == "/api/l1-builder/v1/builders" {
172207 res , err := json .Marshal (builderHubPeers )
173208 if err != nil {
174209 panic (err )
@@ -294,7 +329,7 @@ func TestProxyBundleRequestWithPeerUpdate(t *testing.T) {
294329
295330 // we start with no peers
296331 builderHubPeers = nil
297- testAddBuilderhubPeer (0 )
332+ testAddBuilderhubPeer (t , 0 )
298333 proxiesUpdatePeers (t )
299334
300335 blockNumber := hexutil .Uint64 (1000 )
@@ -312,7 +347,7 @@ func TestProxyBundleRequestWithPeerUpdate(t *testing.T) {
312347 slog .Info ("Adding first peer" )
313348
314349 // add one more peer
315- testAddBuilderhubPeer (1 )
350+ testAddBuilderhubPeer (t , 1 )
316351 proxiesUpdatePeers (t )
317352
318353 blockNumber = hexutil .Uint64 (1001 )
@@ -331,7 +366,7 @@ func TestProxyBundleRequestWithPeerUpdate(t *testing.T) {
331366 // add another peer
332367 slog .Info ("Adding second peer" )
333368
334- testAddBuilderhubPeer (2 )
369+ testAddBuilderhubPeer (t , 2 )
335370 proxiesUpdatePeers (t )
336371
337372 blockNumber = hexutil .Uint64 (1002 )
@@ -375,7 +410,7 @@ func TestProxySendToArchive(t *testing.T) {
375410
376411 // we start with no peers
377412 builderHubPeers = nil
378- testAddBuilderhubPeer (0 )
413+ testAddBuilderhubPeer (t , 0 )
379414 proxiesUpdatePeers (t )
380415
381416 apiNow = func () time.Time {
@@ -458,7 +493,7 @@ func TestProxyShareBundleReplacementUUIDAndCancellation(t *testing.T) {
458493
459494 // we start with no peers
460495 builderHubPeers = nil
461- testAddBuilderhubPeer (0 )
496+ testAddBuilderhubPeer (t , 0 )
462497 proxiesUpdatePeers (t )
463498
464499 // first call
@@ -538,7 +573,7 @@ func TestProxyBidSubsidiseBlockCall(t *testing.T) {
538573 // we add all proxies to the list of peers
539574 builderHubPeers = nil
540575 for i := range proxies {
541- testAddBuilderhubPeer (i )
576+ testAddBuilderhubPeer (t , i )
542577 }
543578 proxiesUpdatePeers (t )
544579
@@ -564,7 +599,7 @@ func TestValidateLocalBundles(t *testing.T) {
564599
565600 // we start with no peers
566601 builderHubPeers = nil
567- testAddBuilderhubPeer (0 )
602+ testAddBuilderhubPeer (t , 0 )
568603 proxiesUpdatePeers (t )
569604
570605 apiNow = func () time.Time {
0 commit comments