diff --git a/simulators/ethereum/rpc-compat/main.go b/simulators/ethereum/rpc-compat/main.go index 2b62f41eee..91bdea7e84 100644 --- a/simulators/ethereum/rpc-compat/main.go +++ b/simulators/ethereum/rpc-compat/main.go @@ -126,11 +126,34 @@ func runTest(t *hivesim.T, c *hivesim.Client, data []byte) error { return fmt.Errorf("invalid test, response before request") } want := []byte(strings.TrimSpace(line)[3:]) // trim leading "<< " - // Now compare. - d, err := diff.New().Compare(resp, want) - if err != nil { + + // Unmarshal to map[string]interface{} to compare. + var wantMap map[string]interface{} + if err := json.Unmarshal(want, &wantMap); err != nil { + return fmt.Errorf("failed to unmarshal value: %s\n", err) + } + + var respMap map[string]interface{} + if err := json.Unmarshal(resp, &respMap); err != nil { return fmt.Errorf("failed to unmarshal value: %s\n", err) } + + if c.Type == "reth" { + // If errors exist in both, make them equal. + // While error comparison might be desirable, error text across + // clients is not standardized, so we should not compare them. + if wantMap["error"] != nil && respMap["error"] != nil { + respError := respMap["error"].(map[string]interface{}) + wantError := wantMap["error"].(map[string]interface{}) + respError["message"] = wantError["message"] + // cast back into the any type + respMap["error"] = respError + } + } + + // Now compare. + d := diff.New().CompareObjects(respMap, wantMap) + // If there is a discrepancy, return error. if d.Modified() { var got map[string]interface{}