forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
40 lines (30 loc) · 901 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
package server
import (
"encoding/json"
"testing"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/stretchr/testify/require"
)
func TestInsertKeyJSON(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 := InsertKeyJSON(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)
}