forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaml_test.go
49 lines (42 loc) · 1006 Bytes
/
yaml_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
45
46
47
48
49
package codec_test
import (
"testing"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
)
func TestMarshalYAML(t *testing.T) {
dog := &testdata.Dog{
Size_: "small",
Name: "Spot",
}
any, err := types.NewAnyWithValue(dog)
require.NoError(t, err)
hasAnimal := &testdata.HasAnimal{
Animal: any,
X: 0,
}
// proto
protoCdc := codec.NewProtoCodec(NewTestInterfaceRegistry())
bz, err := codec.MarshalYAML(protoCdc, hasAnimal)
require.NoError(t, err)
require.Equal(t, `animal:
'@type': /testdata.Dog
name: Spot
size: small
x: "0"
`, string(bz))
// amino
aminoCdc := codec.NewAminoCodec(&codec.LegacyAmino{testdata.NewTestAmino()})
bz, err = codec.MarshalYAML(aminoCdc, hasAnimal)
require.NoError(t, err)
require.Equal(t, `type: testdata/HasAnimal
value:
animal:
type: testdata/Dog
value:
name: Spot
size: small
`, string(bz))
}