Skip to content

Commit

Permalink
chore: prepare v1.4.12 (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Mar 20, 2024
1 parent 07294c8 commit 0e44463
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 77 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 0e44463

Please sign in to comment.