diff --git a/p2p/conn/secret_connection.go b/p2p/conn/secret_connection.go index 0cde9d825..43f84f0bf 100644 --- a/p2p/conn/secret_connection.go +++ b/p2p/conn/secret_connection.go @@ -268,6 +268,7 @@ func genChallenge(loPubKey, hiPubKey *[32]byte) (challenge *[32]byte) { func signChallenge(challenge *[32]byte, locPrivKey crypto.PrivKey) (signature crypto.Signature) { signature, err := locPrivKey.Sign(challenge[:]) + // TODO(ismail): let signChallenge return an error instead if err != nil { panic(err) } diff --git a/rpc/lib/server/handlers_test.go b/rpc/lib/server/handlers_test.go index d1b41ecda..5ad8c3e82 100644 --- a/rpc/lib/server/handlers_test.go +++ b/rpc/lib/server/handlers_test.go @@ -16,8 +16,16 @@ import ( rs "github.com/tendermint/tendermint/rpc/lib/server" types "github.com/tendermint/tendermint/rpc/lib/types" "github.com/tendermint/tmlibs/log" + "github.com/gorilla/websocket" ) +////////////////////////////////////////////////////////////////////////////// +// HTTP REST API +// TODO + +////////////////////////////////////////////////////////////////////////////// +// JSON-RPC over HTTP + func testMux() *http.ServeMux { funcMap := map[string]*rs.RPCFunc{ "c": rs.NewRPCFunc(func(s string, i int) (string, error) { return "foo", nil }, "s,i"), @@ -108,3 +116,44 @@ func TestUnknownRPCPath(t *testing.T) { // Always expecting back a 404 error require.Equal(t, http.StatusNotFound, res.StatusCode, "should always return 404") } + +////////////////////////////////////////////////////////////////////////////// +// JSON-RPC over WEBSOCKETS + +func TestWebsocketManagerHandler(t *testing.T) { + s := newWSServer() + defer s.Close() + + // check upgrader works + d := websocket.Dialer{} + c, dialResp, err := d.Dial("ws://"+s.Listener.Addr().String()+"/websocket", nil) + require.NoError(t, err) + + if got, want := dialResp.StatusCode, http.StatusSwitchingProtocols; got != want { + t.Errorf("dialResp.StatusCode = %q, want %q", got, want) + } + + // check basic functionality works + req, err := types.MapToRequest(amino.NewCodec(), "TestWebsocketManager", "c", map[string]interface{}{"s": "a", "i": 10}) + require.NoError(t, err) + err = c.WriteJSON(req) + require.NoError(t, err) + + var resp types.RPCResponse + err = c.ReadJSON(&resp) + require.NoError(t, err) + require.Nil(t, resp.Error) +} + +func newWSServer() *httptest.Server { + funcMap := map[string]*rs.RPCFunc{ + "c": rs.NewWSRPCFunc(func(wsCtx types.WSRPCContext, s string, i int) (string, error) { return "foo", nil }, "s,i"), + } + wm := rs.NewWebsocketManager(funcMap, amino.NewCodec()) + wm.SetLogger(log.TestingLogger()) + + mux := http.NewServeMux() + mux.HandleFunc("/websocket", wm.WebsocketHandler) + + return httptest.NewServer(mux) +} diff --git a/types/priv_validator.go b/types/priv_validator.go index f51abcc0e..85db65a41 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -76,7 +76,7 @@ func (pv *MockPV) SignProposal(chainID string, proposal *Proposal) error { signBytes := proposal.SignBytes(chainID) sig, err := pv.privKey.Sign(signBytes) if err != nil { - panic(err) + return err } proposal.Signature = sig return nil @@ -86,7 +86,7 @@ func (pv *MockPV) SignProposal(chainID string, proposal *Proposal) error { func (pv *MockPV) SignHeartbeat(chainID string, heartbeat *Heartbeat) error { sig, err := pv.privKey.Sign(heartbeat.SignBytes(chainID)) if err != nil { - panic(err) + return err } heartbeat.Signature = sig return nil