Skip to content

Commit

Permalink
Add failing test reproducing error in #12894
Browse files Browse the repository at this point in the history
ref: #12894
  • Loading branch information
kocubinski committed Aug 18, 2022
1 parent 0ed7360 commit 9b9fc0d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
31 changes: 31 additions & 0 deletions codec/proto_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,37 @@ func (lpm *lyingProtoMarshaler) Size() int {
return lpm.falseSize
}

func TestProtoCodecMarshal(t *testing.T) {
interfaceRegistry := types.NewInterfaceRegistry()
interfaceRegistry.RegisterInterface("testdata.Animal",
(*testdata.Animal)(nil),
&testdata.Cat{})
cdc := codec.NewProtoCodec(interfaceRegistry)

cat := &testdata.Cat{Moniker: "Garfield", Lives: 6}
var (
animalCat testdata.Animal = cat
cartoonCat testdata.Cartoon = cat
)

bz, err := cdc.MarshalInterface(animalCat)
require.NoError(t, err)

err = cdc.UnmarshalInterface(bz, &animalCat)
require.NoError(t, err)

bz, err = cdc.MarshalInterface(cartoonCat)
require.Error(t, err)

err = cdc.UnmarshalInterface(bz, &cartoonCat)
require.Error(t, err)

interfaceRegistry.RegisterInterface("testdata.Cartoon",
(*testdata.Animal)(nil),
&testdata.Cat{})

}

func TestProtoCodecUnmarshalLengthPrefixedChecks(t *testing.T) {
cdc := codec.NewProtoCodec(createTestInterfaceRegistry())

Expand Down
10 changes: 10 additions & 0 deletions testutil/testdata/animal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ type Animal interface {
Greet() string
}

type Cartoon interface {
proto.Message

Identify() string
}

func (c Cat) Greet() string {
return fmt.Sprintf("Meow, my name is %s", c.Moniker)
}

func (c Cat) Identify() string {
return "This is Garfield."
}

func (d Dog) Greet() string {
return fmt.Sprintf("Roof, my name is %s", d.Name)
}
Expand Down

0 comments on commit 9b9fc0d

Please sign in to comment.