You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
988 B

  1. package handler
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "io/ioutil"
  6. "net/http"
  7. "net/http/httptest"
  8. "github.com/tendermint/tendermint/libs/log"
  9. rs "github.com/tendermint/tendermint/rpc/jsonrpc/server"
  10. types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
  11. )
  12. var rpcFuncMap = map[string]*rs.RPCFunc{
  13. "c": rs.NewRPCFunc(func(s string, i int) (string, int) { return "foo", 200 }, "s,i"),
  14. }
  15. var mux *http.ServeMux
  16. func init() {
  17. mux := http.NewServeMux()
  18. buf := new(bytes.Buffer)
  19. lgr := log.NewTMLogger(buf)
  20. rs.RegisterRPCFuncs(mux, rpcFuncMap, lgr)
  21. }
  22. func Fuzz(data []byte) int {
  23. req, _ := http.NewRequest("POST", "http://localhost/", bytes.NewReader(data))
  24. rec := httptest.NewRecorder()
  25. mux.ServeHTTP(rec, req)
  26. res := rec.Result()
  27. blob, err := ioutil.ReadAll(res.Body)
  28. if err != nil {
  29. panic(err)
  30. }
  31. if err := res.Body.Close(); err != nil {
  32. panic(err)
  33. }
  34. recv := new(types.RPCResponse)
  35. if err := json.Unmarshal(blob, recv); err != nil {
  36. panic(err)
  37. }
  38. return 1
  39. }