Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simulators/rpc-compat: allow for any message in error checks #975

Closed
Closed
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
32 changes: 28 additions & 4 deletions simulators/ethereum/rpc-compat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,35 @@ 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 {
return fmt.Errorf("failed to unmarshal value: %s\n", err)

// 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", err)
}

var respMap map[string]interface{}
if err := json.Unmarshal(resp, &respMap); err != nil {
return fmt.Errorf("failed to unmarshal value: %s", 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"]
respError["data"] = wantError["data"]
// 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