From d66ebbd90407d22b52a74711d21073409a91c571 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Fri, 10 Mar 2017 12:03:16 +0400 Subject: [PATCH 1/6] use testify package --- Makefile | 3 ++ rpc_test.go | 82 ++++++++++++++--------------------------------------- 2 files changed, 25 insertions(+), 60 deletions(-) diff --git a/Makefile b/Makefile index a2e3bea7f..0937558a8 100644 --- a/Makefile +++ b/Makefile @@ -11,5 +11,8 @@ test: get_deps: @echo "--> Running go get" @go get -v -d $(PACKAGES) + @go list -f '{{join .TestImports "\n"}}' ./... | \ + grep -v /vendor/ | sort | uniq | \ + xargs go get -v -d .PHONY: all test get_deps diff --git a/rpc_test.go b/rpc_test.go index b1ae2566d..b52794ada 100644 --- a/rpc_test.go +++ b/rpc_test.go @@ -9,6 +9,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" client "github.com/tendermint/go-rpc/client" server "github.com/tendermint/go-rpc/server" types "github.com/tendermint/go-rpc/types" @@ -105,13 +107,9 @@ func testURI(t *testing.T, cl *client.URIClient) { } var result Result _, err := cl.Call("status", params, &result) - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) got := result.(*ResultStatus).Value - if got != val { - t.Fatalf("Got: %v .... Expected: %v \n", got, val) - } + assert.Equal(t, got, val) } func testJSONRPC(t *testing.T, cl *client.JSONRPCClient) { @@ -121,13 +119,9 @@ func testJSONRPC(t *testing.T, cl *client.JSONRPCClient) { } var result Result _, err := cl.Call("status", params, &result) - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) got := result.(*ResultStatus).Value - if got != val { - t.Fatalf("Got: %v .... Expected: %v \n", got, val) - } + assert.Equal(t, got, val) } func testWS(t *testing.T, cl *client.WSClient) { @@ -141,21 +135,15 @@ func testWS(t *testing.T, cl *client.WSClient) { Method: "status", Params: params, }) - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) select { case msg := <-cl.ResultsCh: result := new(Result) wire.ReadJSONPtr(result, msg, &err) - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) got := (*result).(*ResultStatus).Value - if got != val { - t.Fatalf("Got: %v .... Expected: %v \n", got, val) - } + assert.Equal(t, got, val) case err := <-cl.ErrorsCh: t.Fatal(err) } @@ -186,18 +174,14 @@ func TestJSONRPC_UNIX(t *testing.T) { func TestWS_TCP(t *testing.T) { cl := client.NewWSClient(tcpAddr, websocketEndpoint) _, err := cl.Start() - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) testWS(t, cl) } func TestWS_UNIX(t *testing.T) { cl := client.NewWSClient(unixAddr, websocketEndpoint) _, err := cl.Start() - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) testWS(t, cl) } @@ -210,13 +194,9 @@ func TestHexStringArg(t *testing.T) { } var result Result _, err := cl.Call("status", params, &result) - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) got := result.(*ResultStatus).Value - if got != val { - t.Fatalf("Got: %v .... Expected: %v \n", got, val) - } + assert.Equal(t, got, val) } func TestQuotedStringArg(t *testing.T) { @@ -228,22 +208,16 @@ func TestQuotedStringArg(t *testing.T) { } var result Result _, err := cl.Call("status", params, &result) - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) got := result.(*ResultStatus).Value - if got != val { - t.Fatalf("Got: %v .... Expected: %v \n", got, val) - } + assert.Equal(t, got, val) } func randBytes(t *testing.T) []byte { n := rand.Intn(10) + 2 buf := make([]byte, n) _, err := crand.Read(buf) - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) return bytes.Replace(buf, []byte("="), []byte{100}, -1) } @@ -256,21 +230,15 @@ func TestByteSliceViaJSONRPC(t *testing.T) { } var result Result _, err := cl.Call("bytes", params, &result) - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) got := result.(*ResultBytes).Value - if bytes.Compare(got, val) != 0 { - t.Fatalf("Got: %v .... Expected: %v \n", got, val) - } + assert.Equal(t, got, val) } func TestWSNewWSRPCFunc(t *testing.T) { cl := client.NewWSClient(unixAddr, websocketEndpoint) _, err := cl.Start() - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) defer cl.Stop() val := "acbd" @@ -283,21 +251,15 @@ func TestWSNewWSRPCFunc(t *testing.T) { Method: "status_ws", Params: params, }) - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) select { case msg := <-cl.ResultsCh: result := new(Result) wire.ReadJSONPtr(result, msg, &err) - if err != nil { - t.Fatal(err) - } + require.Nil(t, err) got := (*result).(*ResultStatus).Value - if got != val { - t.Fatalf("Got: %v .... Expected: %v \n", got, val) - } + assert.Equal(t, got, val) case err := <-cl.ErrorsCh: t.Fatal(err) } From 0874c72819f0b78ded043e05a4cdce3b973230e0 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Fri, 10 Mar 2017 12:52:40 +0400 Subject: [PATCH 2/6] refactor tests --- rpc_test.go | 83 +++++++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 56 deletions(-) diff --git a/rpc_test.go b/rpc_test.go index b52794ada..acbf440d0 100644 --- a/rpc_test.go +++ b/rpc_test.go @@ -3,6 +3,7 @@ package rpc import ( "bytes" crand "crypto/rand" + "fmt" "math/rand" "net/http" "os/exec" @@ -100,31 +101,25 @@ func init() { } -func testURI(t *testing.T, cl *client.URIClient) { - val := "acbd" +func status(cl client.HTTPClient, val string) (string, error) { params := map[string]interface{}{ "arg": val, } var result Result - _, err := cl.Call("status", params, &result) - require.Nil(t, err) - got := result.(*ResultStatus).Value - assert.Equal(t, got, val) + if _, err := cl.Call("status", params, &result); err != nil { + return "", err + } + return result.(*ResultStatus).Value, nil } -func testJSONRPC(t *testing.T, cl *client.JSONRPCClient) { +func testWithHTTPClient(t *testing.T, cl client.HTTPClient) { val := "acbd" - params := map[string]interface{}{ - "arg": val, - } - var result Result - _, err := cl.Call("status", params, &result) + got, err := status(cl, val) require.Nil(t, err) - got := result.(*ResultStatus).Value assert.Equal(t, got, val) } -func testWS(t *testing.T, cl *client.WSClient) { +func testWithWSClient(t *testing.T, cl *client.WSClient) { val := "acbd" params := map[string]interface{}{ "arg": val, @@ -151,51 +146,32 @@ func testWS(t *testing.T, cl *client.WSClient) { //------------- -func TestURI_TCP(t *testing.T) { - cl := client.NewURIClient(tcpAddr) - testURI(t, cl) -} - -func TestURI_UNIX(t *testing.T) { - cl := client.NewURIClient(unixAddr) - testURI(t, cl) -} - -func TestJSONRPC_TCP(t *testing.T) { - cl := client.NewJSONRPCClient(tcpAddr) - testJSONRPC(t, cl) -} +func TestServersAndClientsBasic(t *testing.T) { + serverAddrs := [...]string{tcpAddr, unixAddr} + for _, addr := range serverAddrs { + cl1 := client.NewURIClient(addr) + fmt.Printf("=== testing server on %s using %v client", addr, cl1) + testWithHTTPClient(t, cl1) -func TestJSONRPC_UNIX(t *testing.T) { - cl := client.NewJSONRPCClient(unixAddr) - testJSONRPC(t, cl) -} + cl2 := client.NewJSONRPCClient(tcpAddr) + fmt.Printf("=== testing server on %s using %v client", addr, cl2) + testWithHTTPClient(t, cl2) -func TestWS_TCP(t *testing.T) { - cl := client.NewWSClient(tcpAddr, websocketEndpoint) - _, err := cl.Start() - require.Nil(t, err) - testWS(t, cl) -} - -func TestWS_UNIX(t *testing.T) { - cl := client.NewWSClient(unixAddr, websocketEndpoint) - _, err := cl.Start() - require.Nil(t, err) - testWS(t, cl) + cl3 := client.NewWSClient(tcpAddr, websocketEndpoint) + _, err := cl3.Start() + require.Nil(t, err) + fmt.Printf("=== testing server on %s using %v client", addr, cl3) + testWithWSClient(t, cl3) + cl3.Stop() + } } func TestHexStringArg(t *testing.T) { cl := client.NewURIClient(tcpAddr) // should NOT be handled as hex val := "0xabc" - params := map[string]interface{}{ - "arg": val, - } - var result Result - _, err := cl.Call("status", params, &result) + got, err := status(cl, val) require.Nil(t, err) - got := result.(*ResultStatus).Value assert.Equal(t, got, val) } @@ -203,13 +179,8 @@ func TestQuotedStringArg(t *testing.T) { cl := client.NewURIClient(tcpAddr) // should NOT be unquoted val := "\"abc\"" - params := map[string]interface{}{ - "arg": val, - } - var result Result - _, err := cl.Call("status", params, &result) + got, err := status(cl, val) require.Nil(t, err) - got := result.(*ResultStatus).Value assert.Equal(t, got, val) } From c88257b0384f6ceeb1219c527cb0ce06402acb1d Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Fri, 10 Mar 2017 12:57:14 +0400 Subject: [PATCH 3/6] rename rpc function status to echo echo means we're returning the input, which is exactly what this function does. --- rpc_test.go | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/rpc_test.go b/rpc_test.go index acbf440d0..7b043953c 100644 --- a/rpc_test.go +++ b/rpc_test.go @@ -31,38 +31,37 @@ const ( // Define a type for results and register concrete versions type Result interface{} -type ResultStatus struct { +type ResultEcho struct { Value string } -type ResultBytes struct { +type ResultEchoBytes struct { Value []byte } var _ = wire.RegisterInterface( struct{ Result }{}, - wire.ConcreteType{&ResultStatus{}, 0x1}, - wire.ConcreteType{&ResultBytes{}, 0x2}, + wire.ConcreteType{&ResultEcho{}, 0x1}, + wire.ConcreteType{&ResultEchoBytes{}, 0x2}, ) // Define some routes var Routes = map[string]*server.RPCFunc{ - "status": server.NewRPCFunc(StatusResult, "arg"), - "status_ws": server.NewWSRPCFunc(StatusWSResult, "arg"), - "bytes": server.NewRPCFunc(BytesResult, "arg"), + "echo": server.NewRPCFunc(EchoResult, "arg"), + "echo_ws": server.NewWSRPCFunc(EchoWSResult, "arg"), + "echo_bytes": server.NewRPCFunc(EchoBytesResult, "arg"), } -// an rpc function -func StatusResult(v string) (Result, error) { - return &ResultStatus{v}, nil +func EchoResult(v string) (Result, error) { + return &ResultEcho{v}, nil } -func StatusWSResult(wsCtx types.WSRPCContext, v string) (Result, error) { - return &ResultStatus{v}, nil +func EchoWSResult(wsCtx types.WSRPCContext, v string) (Result, error) { + return &ResultEcho{v}, nil } -func BytesResult(v []byte) (Result, error) { - return &ResultBytes{v}, nil +func EchoBytesResult(v []byte) (Result, error) { + return &ResultEchoBytes{v}, nil } // launch unix and tcp servers @@ -101,20 +100,20 @@ func init() { } -func status(cl client.HTTPClient, val string) (string, error) { +func echo(cl client.HTTPClient, val string) (string, error) { params := map[string]interface{}{ "arg": val, } var result Result - if _, err := cl.Call("status", params, &result); err != nil { + if _, err := cl.Call("echo", params, &result); err != nil { return "", err } - return result.(*ResultStatus).Value, nil + return result.(*ResultEcho).Value, nil } func testWithHTTPClient(t *testing.T, cl client.HTTPClient) { val := "acbd" - got, err := status(cl, val) + got, err := echo(cl, val) require.Nil(t, err) assert.Equal(t, got, val) } @@ -127,7 +126,7 @@ func testWithWSClient(t *testing.T, cl *client.WSClient) { err := cl.WriteJSON(types.RPCRequest{ JSONRPC: "2.0", ID: "", - Method: "status", + Method: "echo", Params: params, }) require.Nil(t, err) @@ -137,7 +136,7 @@ func testWithWSClient(t *testing.T, cl *client.WSClient) { result := new(Result) wire.ReadJSONPtr(result, msg, &err) require.Nil(t, err) - got := (*result).(*ResultStatus).Value + got := (*result).(*ResultEcho).Value assert.Equal(t, got, val) case err := <-cl.ErrorsCh: t.Fatal(err) @@ -170,7 +169,7 @@ func TestHexStringArg(t *testing.T) { cl := client.NewURIClient(tcpAddr) // should NOT be handled as hex val := "0xabc" - got, err := status(cl, val) + got, err := echo(cl, val) require.Nil(t, err) assert.Equal(t, got, val) } @@ -179,7 +178,7 @@ func TestQuotedStringArg(t *testing.T) { cl := client.NewURIClient(tcpAddr) // should NOT be unquoted val := "\"abc\"" - got, err := status(cl, val) + got, err := echo(cl, val) require.Nil(t, err) assert.Equal(t, got, val) } @@ -200,9 +199,9 @@ func TestByteSliceViaJSONRPC(t *testing.T) { "arg": val, } var result Result - _, err := cl.Call("bytes", params, &result) + _, err := cl.Call("echo_bytes", params, &result) require.Nil(t, err) - got := result.(*ResultBytes).Value + got := result.(*ResultEchoBytes).Value assert.Equal(t, got, val) } @@ -219,7 +218,7 @@ func TestWSNewWSRPCFunc(t *testing.T) { err = cl.WriteJSON(types.RPCRequest{ JSONRPC: "2.0", ID: "", - Method: "status_ws", + Method: "echo_ws", Params: params, }) require.Nil(t, err) @@ -229,7 +228,7 @@ func TestWSNewWSRPCFunc(t *testing.T) { result := new(Result) wire.ReadJSONPtr(result, msg, &err) require.Nil(t, err) - got := (*result).(*ResultStatus).Value + got := (*result).(*ResultEcho).Value assert.Equal(t, got, val) case err := <-cl.ErrorsCh: t.Fatal(err) From 3233c9c003b8ed81ce2e9d18d39fdb5164d2d62a Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Fri, 10 Mar 2017 14:56:04 +0400 Subject: [PATCH 4/6] WSClient failed to "echo_bytes" Error: ``` Expected nil, but got: encoding/hex: invalid byte: U+0078 'x' ``` --- rpc_test.go | 112 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 35 deletions(-) diff --git a/rpc_test.go b/rpc_test.go index 7b043953c..41952fca4 100644 --- a/rpc_test.go +++ b/rpc_test.go @@ -97,10 +97,9 @@ func init() { // wait for servers to start time.Sleep(time.Second * 2) - } -func echo(cl client.HTTPClient, val string) (string, error) { +func echoViaHTTP(cl client.HTTPClient, val string) (string, error) { params := map[string]interface{}{ "arg": val, } @@ -111,15 +110,30 @@ func echo(cl client.HTTPClient, val string) (string, error) { return result.(*ResultEcho).Value, nil } +func echoBytesViaHTTP(cl client.HTTPClient, bytes []byte) ([]byte, error) { + params := map[string]interface{}{ + "arg": bytes, + } + var result Result + if _, err := cl.Call("echo_bytes", params, &result); err != nil { + return []byte{}, err + } + return result.(*ResultEchoBytes).Value, nil +} + func testWithHTTPClient(t *testing.T, cl client.HTTPClient) { val := "acbd" - got, err := echo(cl, val) + got, err := echoViaHTTP(cl, val) require.Nil(t, err) assert.Equal(t, got, val) + + val2 := randBytes(t) + got2, err := echoBytesViaHTTP(cl, val2) + require.Nil(t, err) + assert.Equal(t, got2, val2) } -func testWithWSClient(t *testing.T, cl *client.WSClient) { - val := "acbd" +func echoViaWS(cl *client.WSClient, val string) (string, error) { params := map[string]interface{}{ "arg": val, } @@ -129,20 +143,62 @@ func testWithWSClient(t *testing.T, cl *client.WSClient) { Method: "echo", Params: params, }) - require.Nil(t, err) + if err != nil { + return "", 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) + if err != nil { + return "", nil + } + return (*result).(*ResultEcho).Value, nil case err := <-cl.ErrorsCh: - t.Fatal(err) + return "", err } } +func echoBytesViaWS(cl *client.WSClient, bytes []byte) ([]byte, error) { + params := map[string]interface{}{ + "arg": bytes, + } + err := cl.WriteJSON(types.RPCRequest{ + JSONRPC: "2.0", + ID: "", + Method: "echo_bytes", + Params: params, + }) + if err != nil { + return []byte{}, err + } + + select { + case msg := <-cl.ResultsCh: + result := new(Result) + wire.ReadJSONPtr(result, msg, &err) + if err != nil { + return []byte{}, nil + } + return (*result).(*ResultEchoBytes).Value, nil + case err := <-cl.ErrorsCh: + return []byte{}, err + } +} + +func testWithWSClient(t *testing.T, cl *client.WSClient) { + val := "acbd" + got, err := echoViaWS(cl, val) + require.Nil(t, err) + assert.Equal(t, got, val) + + val2 := randBytes(t) + got2, err := echoBytesViaWS(cl, val2) + require.Nil(t, err) + assert.Equal(t, got2, val2) +} + //------------- func TestServersAndClientsBasic(t *testing.T) { @@ -169,7 +225,7 @@ func TestHexStringArg(t *testing.T) { cl := client.NewURIClient(tcpAddr) // should NOT be handled as hex val := "0xabc" - got, err := echo(cl, val) + got, err := echoViaHTTP(cl, val) require.Nil(t, err) assert.Equal(t, got, val) } @@ -178,35 +234,13 @@ func TestQuotedStringArg(t *testing.T) { cl := client.NewURIClient(tcpAddr) // should NOT be unquoted val := "\"abc\"" - got, err := echo(cl, val) + got, err := echoViaHTTP(cl, val) require.Nil(t, err) assert.Equal(t, got, val) } -func randBytes(t *testing.T) []byte { - n := rand.Intn(10) + 2 - buf := make([]byte, n) - _, err := crand.Read(buf) - require.Nil(t, err) - return bytes.Replace(buf, []byte("="), []byte{100}, -1) -} - -func TestByteSliceViaJSONRPC(t *testing.T) { - cl := client.NewJSONRPCClient(unixAddr) - - val := randBytes(t) - params := map[string]interface{}{ - "arg": val, - } - var result Result - _, err := cl.Call("echo_bytes", params, &result) - require.Nil(t, err) - got := result.(*ResultEchoBytes).Value - assert.Equal(t, got, val) -} - func TestWSNewWSRPCFunc(t *testing.T) { - cl := client.NewWSClient(unixAddr, websocketEndpoint) + cl := client.NewWSClient(tcpAddr, websocketEndpoint) _, err := cl.Start() require.Nil(t, err) defer cl.Stop() @@ -234,3 +268,11 @@ func TestWSNewWSRPCFunc(t *testing.T) { t.Fatal(err) } } + +func randBytes(t *testing.T) []byte { + n := rand.Intn(10) + 2 + buf := make([]byte, n) + _, err := crand.Read(buf) + require.Nil(t, err) + return bytes.Replace(buf, []byte("="), []byte{100}, -1) +} From 5d19a008ce4ea633b2002404df1e6b6be298f886 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Fri, 10 Mar 2017 15:23:43 +0400 Subject: [PATCH 5/6] add Call method to WSClient, which does proper encoding of params --- README.md | 1 + client/http_client.go | 1 - client/ws_client.go | 26 ++++++++++++++++++++++++-- rpc_test.go | 14 ++------------ 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 06a679032..5928e6fe0 100644 --- a/README.md +++ b/README.md @@ -125,3 +125,4 @@ IMPROVEMENTS: - added `HTTPClient` interface, which can be used for both `ClientURI` and `ClientJSONRPC` - all params are now optional (Golang's default will be used if some param is missing) +- added `Call` method to `WSClient` (see method's doc for details) diff --git a/client/http_client.go b/client/http_client.go index 96bae9d9b..f4a2a6d7e 100644 --- a/client/http_client.go +++ b/client/http_client.go @@ -72,7 +72,6 @@ func (c *JSONRPCClient) Call(method string, params map[string]interface{}, resul // (handlers.go:176) on the server side encodedParams := make(map[string]interface{}) for k, v := range params { - // log.Printf("%s: %v (%s)\n", k, v, string(wire.JSONBytes(v))) bytes := json.RawMessage(wire.JSONBytes(v)) encodedParams[k] = &bytes } diff --git a/client/ws_client.go b/client/ws_client.go index b56547dd6..ecf641221 100644 --- a/client/ws_client.go +++ b/client/ws_client.go @@ -10,6 +10,7 @@ import ( "github.com/pkg/errors" cmn "github.com/tendermint/go-common" types "github.com/tendermint/go-rpc/types" + wire "github.com/tendermint/go-wire" ) const ( @@ -116,7 +117,8 @@ func (wsc *WSClient) receiveEventsRoutine() { close(wsc.ErrorsCh) } -// subscribe to an event +// Subscribe to an event. Note the server must have a "subscribe" route +// defined. func (wsc *WSClient) Subscribe(eventid string) error { err := wsc.WriteJSON(types.RPCRequest{ JSONRPC: "2.0", @@ -127,7 +129,8 @@ func (wsc *WSClient) Subscribe(eventid string) error { return err } -// unsubscribe from an event +// Unsubscribe from an event. Note the server must have a "unsubscribe" route +// defined. func (wsc *WSClient) Unsubscribe(eventid string) error { err := wsc.WriteJSON(types.RPCRequest{ JSONRPC: "2.0", @@ -137,3 +140,22 @@ func (wsc *WSClient) Unsubscribe(eventid string) error { }) return err } + +// Call asynchronously calls a given method by sending an RPCRequest to the +// server. Results will be available on ResultsCh, errors, if any, on ErrorsCh. +func (wsc *WSClient) Call(method string, params map[string]interface{}) error { + // we need this step because we attempt to decode values using `go-wire` + // (handlers.go:470) on the server side + encodedParams := make(map[string]interface{}) + for k, v := range params { + bytes := json.RawMessage(wire.JSONBytes(v)) + encodedParams[k] = &bytes + } + err := wsc.WriteJSON(types.RPCRequest{ + JSONRPC: "2.0", + Method: method, + Params: encodedParams, + ID: "", + }) + return err +} diff --git a/rpc_test.go b/rpc_test.go index 41952fca4..8a05d7295 100644 --- a/rpc_test.go +++ b/rpc_test.go @@ -137,12 +137,7 @@ func echoViaWS(cl *client.WSClient, val string) (string, error) { params := map[string]interface{}{ "arg": val, } - err := cl.WriteJSON(types.RPCRequest{ - JSONRPC: "2.0", - ID: "", - Method: "echo", - Params: params, - }) + err := cl.Call("echo", params) if err != nil { return "", err } @@ -164,12 +159,7 @@ func echoBytesViaWS(cl *client.WSClient, bytes []byte) ([]byte, error) { params := map[string]interface{}{ "arg": bytes, } - err := cl.WriteJSON(types.RPCRequest{ - JSONRPC: "2.0", - ID: "", - Method: "echo_bytes", - Params: params, - }) + err := cl.Call("echo_bytes", params) if err != nil { return []byte{}, err } From 4b30cb3083f8275a8d9c94527c290996a42c3707 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 12 Apr 2017 19:30:05 -0400 Subject: [PATCH 6/6] test: check err on cmd.Wait --- rpc_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rpc_test.go b/rpc_test.go index 8a05d7295..56b8ade32 100644 --- a/rpc_test.go +++ b/rpc_test.go @@ -71,7 +71,9 @@ func init() { if err != nil { panic(err) } - err = cmd.Wait() + if err = cmd.Wait(); err != nil { + panic(err) + } mux := http.NewServeMux() server.RegisterRPCFuncs(mux, Routes)