From f708ebb094ecd6f4f77e9c480ceacd250fc1fadc Mon Sep 17 00:00:00 2001 From: Dylan Tinianov Date: Thu, 17 Oct 2024 08:53:55 -0400 Subject: [PATCH] Fix TestWSServer (#14814) * Handle requests once * check error --- .changeset/ten-rats-tie.md | 5 +++++ core/chains/evm/testutils/client.go | 34 +++-------------------------- 2 files changed, 8 insertions(+), 31 deletions(-) create mode 100644 .changeset/ten-rats-tie.md diff --git a/.changeset/ten-rats-tie.md b/.changeset/ten-rats-tie.md new file mode 100644 index 00000000000..f97594914cd --- /dev/null +++ b/.changeset/ten-rats-tie.md @@ -0,0 +1,5 @@ +--- +"chainlink": patch +--- + +Fix testWSServer issue causing panic in testing #internal diff --git a/core/chains/evm/testutils/client.go b/core/chains/evm/testutils/client.go index dfa4653de1c..325e24300be 100644 --- a/core/chains/evm/testutils/client.go +++ b/core/chains/evm/testutils/client.go @@ -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)