rpc manager: do not transform input JSON
This commit is contained in:
parent
6b3f7aabdf
commit
823b5364b8
|
@ -199,15 +199,6 @@ func (s *BackendTestSuite) TestCallRPC() {
|
|||
progress <- struct{}{}
|
||||
},
|
||||
},
|
||||
{
|
||||
`{"jsonrpc":"2.0","method":"net_version","params":[]}`, // w/o id
|
||||
func(resultJSON string) {
|
||||
expected := `{"jsonrpc":"2.0","id":1,"result":"4"}` + "\n"
|
||||
s.Equal(expected, resultJSON)
|
||||
s.T().Log("net_version: ", resultJSON)
|
||||
progress <- struct{}{}
|
||||
},
|
||||
},
|
||||
{
|
||||
`{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}`,
|
||||
func(resultJSON string) {
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
|
||||
const (
|
||||
jsonrpcVersion = "2.0"
|
||||
serviceMethodSeparator = "_"
|
||||
)
|
||||
|
||||
type jsonRequest struct {
|
||||
|
@ -69,12 +68,6 @@ func (c *RPCManager) Call(inputJSON string) string {
|
|||
// allow HTTP requests to block w/o
|
||||
outputJSON := make(chan string, 1)
|
||||
go func() {
|
||||
inputJSON, err = c.prepare(inputJSON)
|
||||
if err != nil {
|
||||
outputJSON <- c.makeJSONErrorResponse(err)
|
||||
return
|
||||
}
|
||||
|
||||
httpReq := httptest.NewRequest("POST", "/", strings.NewReader(inputJSON))
|
||||
rr := httptest.NewRecorder()
|
||||
server.ServeHTTP(rr, httpReq)
|
||||
|
@ -101,34 +94,6 @@ func (c *RPCManager) Call(inputJSON string) string {
|
|||
return c.makeJSONErrorResponse(ErrRPCServerTimeout)
|
||||
}
|
||||
|
||||
// prepare applies necessary transformations to incoming JSON
|
||||
func (c *RPCManager) prepare(inputJSON string) (string, error) {
|
||||
var in jsonRequest
|
||||
if err := json.Unmarshal(json.RawMessage(inputJSON), &in); err != nil {
|
||||
return inputJSON, err
|
||||
}
|
||||
|
||||
elems := strings.Split(in.Method, serviceMethodSeparator)
|
||||
if len(elems) != 2 {
|
||||
return inputJSON, ErrInvalidMethod
|
||||
}
|
||||
|
||||
// inject next ID
|
||||
if in.ID == 0 {
|
||||
c.Lock()
|
||||
c.requestID++
|
||||
c.Unlock()
|
||||
in.ID = c.requestID
|
||||
}
|
||||
|
||||
outputJSON, err := json.Marshal(&in)
|
||||
if err != nil {
|
||||
return inputJSON, err
|
||||
}
|
||||
|
||||
return string(outputJSON), nil
|
||||
}
|
||||
|
||||
// makeJSONErrorResponse returns error as JSON response
|
||||
func (c *RPCManager) makeJSONErrorResponse(err error) string {
|
||||
response := jsonErrResponse{
|
||||
|
|
|
@ -82,15 +82,6 @@ func (s *RPCTestSuite) TestCallRPC() {
|
|||
progress <- struct{}{}
|
||||
},
|
||||
},
|
||||
{
|
||||
`{"jsonrpc":"2.0","method":"net_version","params":[]}`, // w/o id
|
||||
func(resultJSON string) {
|
||||
expected := `{"jsonrpc":"2.0","id":1,"result":"4"}` + "\n"
|
||||
s.Equal(expected, resultJSON)
|
||||
s.T().Log("net_version: ", resultJSON)
|
||||
progress <- struct{}{}
|
||||
},
|
||||
},
|
||||
{
|
||||
`{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}`,
|
||||
func(resultJSON string) {
|
||||
|
|
Loading…
Reference in New Issue