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.

54 lines
1006 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. // Do not include empty fields.
  15. assert.False(t, strings.Contains(string(b), "code"))
  16. r1 := ResponseCheckTx{
  17. Code: 1,
  18. Data: []byte("hello"),
  19. GasWanted: 43,
  20. Fee: cmn.KI64Pair{[]byte("pho"), 12},
  21. }
  22. b, err = json.Marshal(&r1)
  23. assert.Nil(t, err)
  24. var r2 ResponseCheckTx
  25. err = json.Unmarshal(b, &r2)
  26. assert.Nil(t, err)
  27. assert.Equal(t, r1, r2)
  28. }
  29. func TestWriteReadMessage(t *testing.T) {
  30. cases := []proto.Message{
  31. &Header{
  32. NumTxs: 4,
  33. },
  34. // TODO: add the rest
  35. }
  36. for _, c := range cases {
  37. buf := new(bytes.Buffer)
  38. err := WriteMessage(c, buf)
  39. assert.Nil(t, err)
  40. msg := new(Header)
  41. err = ReadMessage(buf, msg)
  42. assert.Nil(t, err)
  43. assert.Equal(t, c, msg)
  44. }
  45. }