diff --git a/CHANGELOG.md b/CHANGELOG.md index 8090d058e60f..abde89f98759 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (deps) [#16565](https://github.com/cosmos/cosmos-sdk/pull/16565) Bump CometBFT to [v0.37.2](https://github.com/cometbft/cometbft/blob/v0.37.2/CHANGELOG.md). +### Bug Fixes + +* (x/auth) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. + ## [v0.47.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.3) - 2023-06-08 ### Features diff --git a/x/auth/types/account.go b/x/auth/types/account.go index 313b563b98ac..fbdef4e89257 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -236,6 +236,10 @@ func (ma ModuleAccount) Validate() error { return errors.New("module account name cannot be blank") } + if ma.BaseAccount == nil { + return errors.New("uninitialized ModuleAccount: BaseAccount is nil") + } + if ma.Address != sdk.AccAddress(crypto.AddressHash([]byte(ma.Name))).String() { return fmt.Errorf("address %s cannot be derived from the module name '%s'", ma.Address, ma.Name) } diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index d465ed852568..74ab5784b199 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -228,3 +228,8 @@ func TestNewModuleAddressOrBech32Address(t *testing.T) { require.Equal(t, input, types.NewModuleAddressOrBech32Address(input).String()) require.Equal(t, "cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl", types.NewModuleAddressOrBech32Address("distribution").String()) } + +func TestModuleAccountValidateNilBaseAccount(t *testing.T) { + ma := &types.ModuleAccount{Name: "foo"} + _ = ma.Validate() +}