Browse Source

fix backward compatibility for WS

pull/456/head
Anton Kaliaev 8 years ago
parent
commit
d6fd0c4ca0
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 29 additions and 1 deletions
  1. +28
    -0
      rpc_test.go
  2. +1
    -1
      server/handlers.go

+ 28
- 0
rpc_test.go View File

@ -261,6 +261,34 @@ func TestWSNewWSRPCFunc(t *testing.T) {
}
}
func TestWSHandlesArrayParams(t *testing.T) {
cl := client.NewWSClient(tcpAddr, websocketEndpoint)
_, err := cl.Start()
require.Nil(t, err)
defer cl.Stop()
val := "acbd"
params := []interface{}{val}
err = cl.WriteJSON(types.RPCRequest{
JSONRPC: "2.0",
ID: "",
Method: "echo_ws",
Params: params,
})
require.Nil(t, err)
select {
case msg := <-cl.ResultsCh:
result := new(Result)
wire.ReadJSONPtr(result, msg, &err)
require.Nil(t, err)
got := (*result).(*ResultEcho).Value
assert.Equal(t, got, val)
case err := <-cl.ErrorsCh:
t.Fatalf("%+v", err)
}
}
func randBytes(t *testing.T) []byte {
n := rand.Intn(10) + 2
buf := make([]byte, n)


+ 1
- 1
server/handlers.go View File

@ -173,7 +173,7 @@ func jsonParamsToArgs(rpcFunc *RPCFunc, paramsI interface{}, argsOffset int) ([]
}
values := make([]reflect.Value, len(params))
for i, p := range params {
ty := rpcFunc.args[i]
ty := rpcFunc.args[i+argsOffset]
v, err := _jsonObjectToArg(ty, p)
if err != nil {
return nil, err


Loading…
Cancel
Save