assertJSONRPC20Error checks that a response is an error JSON-RPC 2.0 response
(t *testing.T, response map[string]interface{}, expectedID interface{}, expectedCode float64)
| 425 | |
| 426 | // assertJSONRPC20Error checks that a response is an error JSON-RPC 2.0 response |
| 427 | func assertJSONRPC20Error(t *testing.T, response map[string]interface{}, expectedID interface{}, expectedCode float64) map[string]interface{} { |
| 428 | t.Helper() |
| 429 | expected := map[string]interface{}{ |
| 430 | "jsonrpc": "2.0", |
| 431 | "id": expectedID, |
| 432 | } |
| 433 | if diff := compareJSON(expected, response); diff != "" { |
| 434 | t.Errorf("Response structure mismatch:\n%s", diff) |
| 435 | } |
| 436 | if response["result"] != nil { |
| 437 | t.Fatalf("Expected no result on error, got: %v", response["result"]) |
| 438 | } |
| 439 | if response["error"] == nil { |
| 440 | t.Fatalf("Expected error field, got nil") |
| 441 | } |
| 442 | errorObj := response["error"].(map[string]interface{}) |
| 443 | if errorObj["code"].(float64) != expectedCode { |
| 444 | t.Errorf("Expected error code %v, got: %v", expectedCode, errorObj["code"]) |
| 445 | } |
| 446 | return errorObj |
| 447 | } |
| 448 | |
| 449 | // compareJSON compares two JSON objects and returns a human-readable diff |
| 450 | func compareJSON(expected, actual map[string]interface{}) string { |
nothing calls this directly
no test coverage detected