From d01183809ba5ebcaedc1d5f423e74e46c676b13e Mon Sep 17 00:00:00 2001 From: Saolyn Date: Wed, 6 Nov 2024 16:39:35 +0100 Subject: [PATCH] fix tests --- beacon-chain/rpc/eth/beacon/handlers_pool.go | 33 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/beacon-chain/rpc/eth/beacon/handlers_pool.go b/beacon-chain/rpc/eth/beacon/handlers_pool.go index 8b5c01642dc..9ea961eb2ac 100644 --- a/beacon-chain/rpc/eth/beacon/handlers_pool.go +++ b/beacon-chain/rpc/eth/beacon/handlers_pool.go @@ -197,7 +197,16 @@ func (s *Server) SubmitAttestations(w http.ResponseWriter, r *http.Request) { var sourceAttestations []*structs.Attestation if err := json.Unmarshal(req.Data, &sourceAttestations); err != nil { - httputil.HandleError(w, fmt.Sprintf("Failed to unmarshal request: %v", err), http.StatusInternalServerError) + var singleAttestation *structs.Attestation + if err := json.Unmarshal(req.Data, &singleAttestation); err != nil { + httputil.HandleError(w, "Could not parse data into attestations: "+err.Error(), http.StatusBadRequest) + return + } + sourceAttestations = append(sourceAttestations, singleAttestation) + } + + if len(sourceAttestations) == 0 { + httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return } @@ -318,7 +327,16 @@ func (s *Server) SubmitAttestationsV2(w http.ResponseWriter, r *http.Request) { if v >= version.Electra { var sourceAttestations []*structs.AttestationElectra if err = json.Unmarshal(req.Data, &sourceAttestations); err != nil { - httputil.HandleError(w, fmt.Sprintf("Failed to unmarshal request: %v", err), http.StatusInternalServerError) + // If that fails, try unmarshaling into a single attestation + var singleAttestation *structs.AttestationElectra + if err := json.Unmarshal(req.Data, &singleAttestation); err != nil { + httputil.HandleError(w, "Could not parse data into attestations: "+err.Error(), http.StatusBadRequest) + return + } + sourceAttestations = append(sourceAttestations, singleAttestation) + } + if len(sourceAttestations) == 0 { + httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return } @@ -379,7 +397,16 @@ func (s *Server) SubmitAttestationsV2(w http.ResponseWriter, r *http.Request) { } else { var sourceAttestations []*structs.Attestation if err = json.Unmarshal(req.Data, &sourceAttestations); err != nil { - httputil.HandleError(w, fmt.Sprintf("Failed to unmarshal request: %v", err), http.StatusInternalServerError) + // If that fails, try unmarshaling into a single attestation + var singleAttestation *structs.Attestation + if err := json.Unmarshal(req.Data, &singleAttestation); err != nil { + httputil.HandleError(w, "Could not parse data into attestations: "+err.Error(), http.StatusBadRequest) + return + } + sourceAttestations = append(sourceAttestations, singleAttestation) + } + if len(sourceAttestations) == 0 { + httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return }