MCPcopy Create free account
hub / github.com/tendermint/tendermint / TestWriteRPCResponseHTTP

Function TestWriteRPCResponseHTTP

rpc/jsonrpc/server/http_server_test.go:109–161  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

107}
108
109func TestWriteRPCResponseHTTP(t *testing.T) {
110 id := rpctypes.JSONRPCIntID(-1)
111
112 // one argument
113 w := httptest.NewRecorder()
114 err := WriteRPCResponseHTTP(w, true, rpctypes.NewRPCSuccessResponse(id, &sampleResult{"hello"}))
115 require.NoError(t, err)
116 resp := w.Result()
117 body, err := ioutil.ReadAll(resp.Body)
118 _ = resp.Body.Close()
119 require.NoError(t, err)
120 assert.Equal(t, 200, resp.StatusCode)
121 assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
122 assert.Equal(t, "max-age=31536000", resp.Header.Get("Cache-control"))
123 assert.Equal(t, `{
124 "jsonrpc": "2.0",
125 "id": -1,
126 "result": {
127 "value": "hello"
128 }
129}`, string(body))
130
131 // multiple arguments
132 w = httptest.NewRecorder()
133 err = WriteRPCResponseHTTP(w,
134 false,
135 rpctypes.NewRPCSuccessResponse(id, &sampleResult{"hello"}),
136 rpctypes.NewRPCSuccessResponse(id, &sampleResult{"world"}))
137 require.NoError(t, err)
138 resp = w.Result()
139 body, err = ioutil.ReadAll(resp.Body)
140 _ = resp.Body.Close()
141 require.NoError(t, err)
142
143 assert.Equal(t, 200, resp.StatusCode)
144 assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
145 assert.Equal(t, `[
146 {
147 "jsonrpc": "2.0",
148 "id": -1,
149 "result": {
150 "value": "hello"
151 }
152 },
153 {
154 "jsonrpc": "2.0",
155 "id": -1,
156 "result": {
157 "value": "world"
158 }
159 }
160]`, string(body))
161}
162
163func TestWriteRPCResponseHTTPError(t *testing.T) {
164 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 4

WriteRPCResponseHTTPFunction · 0.85
CloseMethod · 0.65
EqualMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…