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.

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