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

fix: .String() panics when pubkey is set on a BaseAccount #13838

Merged
merged 8 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (x/auth) [#13838](https://github.com/cosmos/cosmos-sdk/pull/13838) Fix calling `String()` and `MarshalYAML` panics when pubkey is set on a `BaseAccount`.
* (rosetta) [#13583](https://github.com/cosmos/cosmos-sdk/pull/13583) Misc fixes for cosmos-rosetta.
* (x/evidence) [#13740](https://github.com/cosmos/cosmos-sdk/pull/13740) Fix evidence query API to decode the hash properly.
* (bank) [#13691](https://github.com/cosmos/cosmos-sdk/issues/13691) Fix unhandled error for vesting account transfers, when total vesting amount exceeds total balance.
Expand Down
105 changes: 52 additions & 53 deletions api/cosmos/auth/v1beta1/auth.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,6 @@ replace (
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1
)

replace github.com/cosmos/gogoproto => ../gogoproto
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

retract v0.43.0
7 changes: 3 additions & 4 deletions proto/cosmos/auth/v1beta1/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types";
// for basic account functionality. Any custom account type should extend this
// type for additional functionality (e.g. vesting).
message BaseAccount {
option (amino.name) = "cosmos-sdk/BaseAccount";
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.equal) = false;
option (amino.name) = "cosmos-sdk/BaseAccount";
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = false;

option (cosmos_proto.implements_interface) = "AccountI";

Expand Down
17 changes: 10 additions & 7 deletions x/auth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -137,14 +138,12 @@ func (acc BaseAccount) Validate() error {
return nil
}

func (acc BaseAccount) String() string {
out, _ := acc.MarshalYAML()
return out.(string)
}

// MarshalYAML returns the YAML representation of an account.
func (acc BaseAccount) MarshalYAML() (interface{}, error) {
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also remove this method?

Copy link
Member Author

@julienrbrt julienrbrt Nov 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is sort of what #13850 is aimed to do.

bz, err := codec.MarshalYAML(codec.NewProtoCodec(codectypes.NewInterfaceRegistry()), &acc)
registry := codectypes.NewInterfaceRegistry()
cryptocodec.RegisterInterfaces(registry)

bz, err := codec.MarshalYAML(codec.NewProtoCodec(registry), &acc)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -253,7 +252,11 @@ type moduleAccountPretty struct {
}

func (ma ModuleAccount) String() string {
out, _ := ma.MarshalYAML()
out, err := ma.MarshalYAML()
if err != nil {
panic(err)
}

return out.(string)
}

Expand Down
7 changes: 7 additions & 0 deletions x/auth/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func TestBaseAddressPubKey(t *testing.T) {
err = acc2.SetAddress(addr2)
require.Nil(t, err)
require.EqualValues(t, addr2, acc2.GetAddress())

// no error when calling MarshalYAML with an account with pubkey
_, err = acc.MarshalYAML()
require.Nil(t, err)

// no panic on calling string with an account with pubkey
require.NotPanics(t, func() { _ = acc.String() })
}

func TestBaseSequence(t *testing.T) {
Expand Down
Loading