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.

43 lines
824 B

7 years ago
7 years ago
7 years ago
  1. package rpcclient
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. "github.com/tendermint/go-amino"
  7. )
  8. type Tx []byte
  9. type Foo struct {
  10. Bar int
  11. Baz string
  12. }
  13. func TestArgToJSON(t *testing.T) {
  14. assert := assert.New(t)
  15. require := require.New(t)
  16. cases := []struct {
  17. input interface{}
  18. expected string
  19. }{
  20. {[]byte("1234"), "0x31323334"},
  21. {Tx("654"), "0x363534"},
  22. {Foo{7, "hello"}, `{"Bar":7,"Baz":"hello"}`},
  23. }
  24. cdc := amino.NewCodec()
  25. for i, tc := range cases {
  26. args := map[string]interface{}{"data": tc.input}
  27. err := argsToJSON(cdc, args)
  28. require.Nil(err, "%d: %+v", i, err)
  29. require.Equal(1, len(args), "%d", i)
  30. data, ok := args["data"].(string)
  31. require.True(ok, "%d: %#v", i, args["data"])
  32. assert.Equal(tc.expected, data, "%d", i)
  33. }
  34. }