MCPcopy Create free account
hub / github.com/tendermint/tendermint / TestParseJSONArray

Function TestParseJSONArray

rpc/jsonrpc/server/parse_test.go:103–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

101}
102
103func TestParseJSONArray(t *testing.T) {
104 input := []byte(`["1234",22]`)
105
106 // naive is float,string
107 var p1 []interface{}
108 err := json.Unmarshal(input, &p1)
109 if assert.Nil(t, err) {
110 v, ok := p1[0].(string)
111 if assert.True(t, ok, "%#v", p1[0]) {
112 assert.EqualValues(t, "1234", v)
113 }
114 h, ok := p1[1].(float64)
115 if assert.True(t, ok, "%#v", p1[1]) {
116 assert.EqualValues(t, 22, h)
117 }
118 }
119
120 // preloading map with values helps here (unlike map - p2 above)
121 tmp := 0
122 p2 := []interface{}{&bytes.HexBytes{}, &tmp}
123 err = json.Unmarshal(input, &p2)
124 if assert.Nil(t, err) {
125 v, ok := p2[0].(*bytes.HexBytes)
126 if assert.True(t, ok, "%#v", p2[0]) {
127 assert.EqualValues(t, []byte{0x12, 0x34}, *v)
128 }
129 h, ok := p2[1].(*int)
130 if assert.True(t, ok, "%#v", p2[1]) {
131 assert.EqualValues(t, 22, *h)
132 }
133 }
134}
135
136func TestParseJSONRPC(t *testing.T) {
137 demo := func(ctx *rpctypes.Context, height int, name string) {}

Callers

nothing calls this directly

Calls 1

UnmarshalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…