MCPcopy Create free account
hub / github.com/erpc/erpc / TestHttp_EvmGetLogs_SplitOnError_MergedResponse

Function TestHttp_EvmGetLogs_SplitOnError_MergedResponse

erpc/http_server_logs_test.go:25–164  ·  view source on GitHub ↗

This test validates that split-on-error happens end-to-end at project-level (post-forward) and returns a merged response when the upstream responds with a 413-like large-range error.

(t *testing.T)

Source from the content-addressed store, hash-verified

23// This test validates that split-on-error happens end-to-end at project-level (post-forward)
24// and returns a merged response when the upstream responds with a 413-like large-range error.
25func TestHttp_EvmGetLogs_SplitOnError_MergedResponse(t *testing.T) {
26 util.ResetGock()
27 defer util.ResetGock()
28 gock.EnableNetworking()
29 gock.NetworkingFilter(func(req *http.Request) bool {
30 // Allow localhost connections for the test HTTP server; mock only upstream
31 return strings.Split(req.URL.Host, ":")[0] == "localhost"
32 })
33 util.SetupMocksForEvmStatePoller()
34 defer util.AssertNoPendingMocks(t, 0)
35
36 // 1) Initial upstream call returns request-too-large (range) error
37 gock.New("http://rpc1.localhost").
38 Post("/").
39 Filter(func(r *http.Request) bool { return strings.Contains(util.SafeReadBody(r), "eth_getLogs") }).
40 Times(1).
41 Reply(200).
42 JSON(map[string]interface{}{
43 "jsonrpc": "2.0",
44 "id": 1,
45 "error": map[string]interface{}{
46 "code": int(common.JsonRpcErrorCallException),
47 "message": "Request exceeds the range",
48 },
49 })
50
51 // 2) After split-on-error, sub-requests should be issued; respond to two ranges
52 gock.New("http://rpc1.localhost").
53 Post("/").
54 Filter(func(r *http.Request) bool {
55 b := util.SafeReadBody(r)
56 return strings.Contains(b, "eth_getLogs") && strings.Contains(b, "\"fromBlock\":\"0x18100\"") && strings.Contains(b, "\"toBlock\":\"0x181ff\"")
57 }).
58 Times(1).
59 Reply(200).
60 JSON(map[string]interface{}{
61 "jsonrpc": "2.0",
62 "id": 2,
63 "result": []map[string]interface{}{
64 {"blockNumber": "0x18101", "logIndex": "0x2"},
65 },
66 })
67 gock.New("http://rpc1.localhost").
68 Post("/").
69 Filter(func(r *http.Request) bool {
70 b := util.SafeReadBody(r)
71 return strings.Contains(b, "eth_getLogs") && strings.Contains(b, "\"fromBlock\":\"0x18200\"") && strings.Contains(b, "\"toBlock\":\"0x182ff\"")
72 }).
73 Times(1).
74 Reply(200).
75 JSON(map[string]interface{}{
76 "jsonrpc": "2.0",
77 "id": 3,
78 "result": []map[string]interface{}{
79 {"blockNumber": "0x18202", "logIndex": "0x3"},
80 },
81 })
82

Callers

nothing calls this directly

Calls 15

BootstrapMethod · 0.95
ResetGockFunction · 0.92
AssertNoPendingMocksFunction · 0.92
SafeReadBodyFunction · 0.92
BoolPtrFunction · 0.92
NewSharedStateRegistryFunction · 0.92
NewERPCFunction · 0.85
NewHttpServerFunction · 0.85
sendFunction · 0.85
AddrMethod · 0.80
ServeMethod · 0.80

Tested by

no test coverage detected