Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions simulators/ethereum/rpc-compat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down