Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saolyn committed Nov 6, 2024
1 parent c526fce commit d011838
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions beacon-chain/rpc/eth/beacon/handlers_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit d011838

Please sign in to comment.