From 9cfb7fd813b370208bdad8775b43673987f5a03d Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 30 Mar 2023 22:32:26 -0400 Subject: [PATCH 1/2] feat: ignore error difference when comparing rpc output --- simulators/ethereum/rpc-compat/main.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/simulators/ethereum/rpc-compat/main.go b/simulators/ethereum/rpc-compat/main.go index 2b62f41eee..477671f7b3 100644 --- a/simulators/ethereum/rpc-compat/main.go +++ b/simulators/ethereum/rpc-compat/main.go @@ -126,11 +126,28 @@ 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 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 { + respMap["error"] = wantMap["error"] + } + + // Now compare. + d := diff.New().CompareObjects(respMap, wantMap) + // If there is a discrepancy, return error. if d.Modified() { var got map[string]interface{} From 1c0c304ebca9277826ae6f9733898784b7d128c6 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 30 Mar 2023 23:01:02 -0400 Subject: [PATCH 2/2] only ignore rpc error message --- simulators/ethereum/rpc-compat/main.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/simulators/ethereum/rpc-compat/main.go b/simulators/ethereum/rpc-compat/main.go index 477671f7b3..91bdea7e84 100644 --- a/simulators/ethereum/rpc-compat/main.go +++ b/simulators/ethereum/rpc-compat/main.go @@ -138,11 +138,17 @@ func runTest(t *hivesim.T, c *hivesim.Client, data []byte) error { return fmt.Errorf("failed to unmarshal value: %s\n", err) } - // 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 { - respMap["error"] = wantMap["error"] + 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.