forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
44 lines (33 loc) · 972 Bytes
/
util_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package server
import (
"encoding/json"
"testing"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/stretchr/testify/require"
)
func TestAppendJSON(t *testing.T) {
cdc := wire.NewCodec()
foo := map[string]string{"foo": "foofoo"}
bar := map[string]string{"barInner": "barbar"}
// create raw messages
bz, err := cdc.MarshalJSON(foo)
require.NoError(t, err)
fooRaw := json.RawMessage(bz)
bz, err = cdc.MarshalJSON(bar)
require.NoError(t, err)
barRaw := json.RawMessage(bz)
// make the append
appBz, err := AppendJSON(cdc, fooRaw, "barOuter", barRaw)
require.NoError(t, err)
// test the append
var appended map[string]json.RawMessage
err = cdc.UnmarshalJSON(appBz, &appended)
require.NoError(t, err)
var resBar map[string]string
err = cdc.UnmarshalJSON(appended["barOuter"], &resBar)
require.NoError(t, err)
require.Equal(t, bar, resBar, "appended: %v", appended)
}
func TestSortJSON(t *testing.T) {
// TODO add testcases of several types
}