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.

53 lines
972 B

  1. package types
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "strings"
  6. "testing"
  7. "github.com/gogo/protobuf/proto"
  8. "github.com/stretchr/testify/assert"
  9. cmn "github.com/tendermint/tmlibs/common"
  10. )
  11. func TestMarshalJSON(t *testing.T) {
  12. b, err := json.Marshal(&ResponseDeliverTx{})
  13. assert.Nil(t, err)
  14. assert.True(t, strings.Contains(string(b), "code"))
  15. r1 := ResponseCheckTx{
  16. Code: 1,
  17. Data: []byte("hello"),
  18. GasWanted: 43,
  19. Fee: cmn.KI64Pair{[]byte("pho"), 12},
  20. }
  21. b, err = json.Marshal(&r1)
  22. assert.Nil(t, err)
  23. var r2 ResponseCheckTx
  24. err = json.Unmarshal(b, &r2)
  25. assert.Nil(t, err)
  26. assert.Equal(t, r1, r2)
  27. }
  28. func TestWriteReadMessage(t *testing.T) {
  29. cases := []proto.Message{
  30. &Header{
  31. NumTxs: 4,
  32. },
  33. // TODO: add the rest
  34. }
  35. for _, c := range cases {
  36. buf := new(bytes.Buffer)
  37. err := WriteMessage(c, buf)
  38. assert.Nil(t, err)
  39. msg := new(Header)
  40. err = ReadMessage(buf, msg)
  41. assert.Nil(t, err)
  42. assert.Equal(t, c, msg)
  43. }
  44. }