github.com/Finschia/finschia-sdk@v0.48.1/codec/yaml_test.go (about) 1 package codec_test 2 3 import ( 4 "testing" 5 6 "github.com/Finschia/finschia-sdk/codec" 7 8 "github.com/stretchr/testify/require" 9 10 "github.com/Finschia/finschia-sdk/codec/types" 11 "github.com/Finschia/finschia-sdk/testutil/testdata" 12 ) 13 14 func TestMarshalYAML(t *testing.T) { 15 dog := &testdata.Dog{ 16 Size_: "small", 17 Name: "Spot", 18 } 19 any, err := types.NewAnyWithValue(dog) 20 require.NoError(t, err) 21 hasAnimal := &testdata.HasAnimal{ 22 Animal: any, 23 X: 0, 24 } 25 26 // proto 27 protoCdc := codec.NewProtoCodec(NewTestInterfaceRegistry()) 28 bz, err := codec.MarshalYAML(protoCdc, hasAnimal) 29 require.NoError(t, err) 30 require.Equal(t, `animal: 31 '@type': /testdata.Dog 32 name: Spot 33 size: small 34 x: "0" 35 `, string(bz)) 36 37 // amino 38 aminoCdc := codec.NewAminoCodec(&codec.LegacyAmino{testdata.NewTestAmino()}) 39 bz, err = codec.MarshalYAML(aminoCdc, hasAnimal) 40 require.NoError(t, err) 41 require.Equal(t, `type: testdata/HasAnimal 42 value: 43 animal: 44 type: testdata/Dog 45 value: 46 name: Spot 47 size: small 48 `, string(bz)) 49 }