Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prepare v1.4.12 #116

Merged
merged 2 commits into from Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,9 +2,13 @@

## Unreleased

## [v1.4.12](https://github.com/cosmos/gogoproto/releases/tag/v1.4.12) - 2024-03-20

### Improvements

- [#115](https://github.com/cosmos/gogoproto/pull/115) Move any type from `cosmos-sdk/codec/types` to `types/any`.

## [v1.4.11](https://github.com/cosmos/gogoproto/releases/tag/v1.4.10) - 2023-05-11
## [v1.4.11](https://github.com/cosmos/gogoproto/releases/tag/v1.4.11) - 2023-08-18

### Improvements

Expand Down
9 changes: 2 additions & 7 deletions go.mod
Expand Up @@ -3,8 +3,8 @@ module github.com/cosmos/gogoproto
go 1.19

require (
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.6.0
github.com/stretchr/testify v1.8.4
github.com/tendermint/go-amino v0.16.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
google.golang.org/grpc v1.61.1
Expand All @@ -13,17 +13,12 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// API changed in an incompatible way
Expand Down
16 changes: 0 additions & 16 deletions go.sum
@@ -1,4 +1,3 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -12,19 +11,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
Expand Down Expand Up @@ -52,8 +40,4 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
5 changes: 3 additions & 2 deletions types/any/any_with_cache.go
Expand Up @@ -5,6 +5,7 @@ import (
fmt "fmt"

"github.com/cosmos/gogoproto/proto"
"github.com/cosmos/gogoproto/types/any/internal"
protov2 "google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -75,7 +76,7 @@ func NewAnyWithCacheWithValue(v proto.Message) (*Any, error) {
}

return &Any{
TypeUrl: MsgTypeURL(v),
TypeUrl: internal.MsgTypeURL(v),
Value: bz,
cachedValue: v,
}, nil
Expand All @@ -100,7 +101,7 @@ func UnsafePackAnyWithCache(x interface{}) *Any {
// the packed value so that it can be retrieved from GetCachedValue without
// unmarshalling
func (any *Any) pack(x proto.Message) error {
any.TypeUrl = MsgTypeURL(x)
any.TypeUrl = internal.MsgTypeURL(x)

var (
bz []byte
Expand Down
2 changes: 1 addition & 1 deletion types/any/util.go → types/any/internal/util.go
@@ -1,4 +1,4 @@
package types
package internal

import (
"github.com/cosmos/gogoproto/proto"
Expand Down
170 changes: 120 additions & 50 deletions types/any/test/compat_test.go
@@ -1,11 +1,11 @@
package test

import (
types "github.com/cosmos/gogoproto/types/any"

"bytes"
"testing"

"github.com/stretchr/testify/suite"
types "github.com/cosmos/gogoproto/types/any"
"github.com/google/go-cmp/cmp"
amino "github.com/tendermint/go-amino"
)

Expand All @@ -14,118 +14,188 @@ type TypeWithInterface struct {
X int64 `json:"x,omitempty"`
}

type Suite struct {
suite.Suite
type testFixture struct {
cdc *amino.Codec
a TypeWithInterface
b HasAnimal
spot *Dog
}

func (s *Suite) SetupTest() {
s.cdc = amino.NewCodec()
s.cdc.RegisterInterface((*Animal)(nil), nil)
s.cdc.RegisterConcrete(&Dog{}, "test/Dog", nil)
func newTestFixture(t *testing.T) *testFixture {
t.Helper()

cdc := amino.NewCodec()
cdc.RegisterInterface((*Animal)(nil), nil)
cdc.RegisterConcrete(&Dog{}, "test/Dog", nil)

s.spot = &Dog{Size_: "small", Name: "Spot"}
s.a = TypeWithInterface{Animal: s.spot}
spot := &Dog{Size_: "small", Name: "Spot"}
a := TypeWithInterface{Animal: spot}

any, err := types.NewAnyWithCacheWithValue(s.spot)
s.Require().NoError(err)
s.b = HasAnimal{Animal: any}
any, err := types.NewAnyWithCacheWithValue(spot)
if err != nil {
t.Fatal(err)
}

b := HasAnimal{Animal: any}

return &testFixture{
cdc: cdc,
a: a,
b: b,
spot: spot,
}
}

func (s *Suite) TestAminoBinary() {
func TestAminoBinary(t *testing.T) {
s := newTestFixture(t)

bz, err := s.cdc.MarshalBinaryBare(s.a)
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}

// expect plain amino marshal to fail
_, err = s.cdc.MarshalBinaryBare(s.b)
s.Require().Error(err)
if err == nil {
t.Fatal("expected error")
}

// expect unpack interfaces before amino marshal to succeed
err = types.UnpackInterfaces(s.b, types.AminoPacker{Cdc: s.cdc})
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}
bz2, err := s.cdc.MarshalBinaryBare(s.b)
s.Require().NoError(err)
s.Require().Equal(bz, bz2)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(bz, bz2) {
t.Fatalf("expected %X, got %X", bz, bz2)
}

var c HasAnimal
err = s.cdc.UnmarshalBinaryBare(bz, &c)
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}
err = types.UnpackInterfaces(c, types.AminoUnpacker{Cdc: s.cdc})
s.Require().NoError(err)
s.Require().Equal(s.spot, c.Animal.GetCachedValue())
if err != nil {
t.Fatal(err)
}

if result := cmp.Diff(s.spot, c.Animal.GetCachedValue()); result != "" {
t.Fatalf("expected %v, got %v: %v", s.spot, c.Animal.GetCachedValue(), result)
}
}

func (s *Suite) TestAminoJSON() {
func TestAminoJSON(t *testing.T) {
s := newTestFixture(t)

bz, err := s.cdc.MarshalJSON(s.a)
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}

// expect plain amino marshal to fail
_, err = s.cdc.MarshalJSON(s.b)
s.Require().Error(err)

if err == nil {
t.Fatal("expected error")
}
// expect unpack interfaces before amino marshal to succeed
err = types.UnpackInterfaces(s.b, types.AminoJSONPacker{Cdc: s.cdc})
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}
bz2, err := s.cdc.MarshalJSON(s.b)
s.Require().NoError(err)
s.Require().Equal(string(bz), string(bz2))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(bz, bz2) {
t.Fatalf("expected %X, got %X", bz, bz2)
}

var c HasAnimal
err = s.cdc.UnmarshalJSON(bz, &c)
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}
err = types.UnpackInterfaces(c, types.AminoJSONUnpacker{Cdc: s.cdc})
s.Require().NoError(err)
s.Require().Equal(s.spot, c.Animal.GetCachedValue())
if err != nil {
t.Fatal(err)
}

if result := cmp.Diff(s.spot, c.Animal.GetCachedValue()); result != "" {
t.Fatalf("expected %v, got %v: %v", s.spot, c.Animal.GetCachedValue(), result)
}
}

func (s *Suite) TestNested() {
func TestNested(t *testing.T) {
s := newTestFixture(t)

s.cdc.RegisterInterface((*HasAnimalI)(nil), nil)
s.cdc.RegisterInterface((*HasHasAnimalI)(nil), nil)
s.cdc.RegisterConcrete(&HasAnimal{}, "test/HasAnimal", nil)
s.cdc.RegisterConcrete(&HasHasAnimal{}, "test/HasHasAnimal", nil)
s.cdc.RegisterConcrete(&HasHasHasAnimal{}, "test/HasHasHasAnimal", nil)

any, err := types.NewAnyWithCacheWithValue(&s.b)
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}
hha := HasHasAnimal{HasAnimal: any}
any2, err := types.NewAnyWithCacheWithValue(&hha)
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}
hhha := HasHasHasAnimal{HasHasAnimal: any2}

// marshal
err = types.UnpackInterfaces(hhha, types.AminoPacker{Cdc: s.cdc})
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}
bz, err := s.cdc.MarshalBinaryBare(hhha)
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}

// unmarshal
var hhha2 HasHasHasAnimal
err = s.cdc.UnmarshalBinaryBare(bz, &hhha2)
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}
err = types.UnpackInterfaces(hhha2, types.AminoUnpacker{Cdc: s.cdc})
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}

s.Require().Equal(s.spot, hhha2.TheHasHasAnimal().TheHasAnimal().TheAnimal())
if result := cmp.Diff(hhha2.TheHasHasAnimal().TheHasAnimal().TheAnimal(), s.spot); result != "" {
t.Fatalf("expected %v, got %v: %v", s.spot, hhha2.TheHasHasAnimal().TheHasAnimal().TheAnimal(), result)
}

// json marshal
err = types.UnpackInterfaces(hhha, types.AminoJSONPacker{Cdc: s.cdc})
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}
jsonBz, err := s.cdc.MarshalJSON(hhha)
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}

// json unmarshal
var hhha3 HasHasHasAnimal
err = s.cdc.UnmarshalJSON(jsonBz, &hhha3)
s.Require().NoError(err)
if err != nil {
t.Fatal(err)
}
err = types.UnpackInterfaces(hhha3, types.AminoJSONUnpacker{Cdc: s.cdc})
s.Require().NoError(err)

s.Require().Equal(s.spot, hhha3.TheHasHasAnimal().TheHasAnimal().TheAnimal())
}
if err != nil {
t.Fatal(err)
}

func TestSuite(t *testing.T) {
suite.Run(t, &Suite{})
if result := cmp.Diff(hhha3.TheHasHasAnimal().TheHasAnimal().TheAnimal(), s.spot); result != "" {
t.Fatalf("expected %v, got %v: %v", s.spot, hhha3.TheHasHasAnimal().TheHasAnimal().TheAnimal(), result)
}
}