Skip to content

Commit

Permalink
Fix TestWSServer (#14814)
Browse files Browse the repository at this point in the history
* Handle requests once

* check error
  • Loading branch information
DylanTinianov authored Oct 17, 2024
1 parent fa99e39 commit f708ebb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-rats-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Fix testWSServer issue causing panic in testing #internal
34 changes: 3 additions & 31 deletions core/chains/evm/testutils/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,43 +184,15 @@ func (ts *testWSServer) newWSHandler(chainID *big.Int, callback JSONRPCHandler)
ts.mu.Unlock()
if err != nil {
ts.t.Logf("Failed to write message: %v", err)
return
}
} else { // Handle single request
m := req.Get("method")
if m.Type != gjson.String {
ts.t.Logf("Method must be string: %v", m.Type)
return
}

var resp JSONRPCResponse
if chainID != nil && m.String() == "eth_chainId" {
resp.Result = `"0x` + chainID.Text(16) + `"`
} else if m.String() == "eth_syncing" {
resp.Result = "false"
} else {
resp = callback(m.String(), req.Get("params"))
}
id := req.Get("id")
var msg string
if resp.Error.Message != "" {
msg = fmt.Sprintf(`{"jsonrpc":"2.0","id":%s,"error":{"code":%d,"message":"%s"}}`, id, resp.Error.Code, resp.Error.Message)
} else {
msg = fmt.Sprintf(`{"jsonrpc":"2.0","id":%s,"result":%s}`, id, resp.Result)
}
ts.t.Logf("Sending message: %v", msg)
ts.mu.Lock()
err = conn.WriteMessage(websocket.BinaryMessage, []byte(msg))
ts.mu.Unlock()
if err != nil {
ts.t.Logf("Failed to write message: %v", err)
return
}
return
}
// Handle single request
if e := req.Get("error"); e.Exists() {
ts.t.Logf("Received jsonrpc error: %v", e)
continue
}

m := req.Get("method")
if m.Type != gjson.String {
ts.t.Logf("Method must be string: %v", m.Type)
Expand Down

0 comments on commit f708ebb

Please sign in to comment.