fix(x/auth): ensure nil .BaseAccounts are reported in ModuleAccount.Validate (backport #16554) (#16568)
Co-authored-by: Emmanuel T Odeke <emmanuel@orijtech.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
e0dd83ffed
commit
ae3e30a715
@ -42,6 +42,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
* (all) [#16497](https://github.com/cosmos/cosmos-sdk/pull/16497) Removed all exported vestiges of `sdk.MustSortJSON` and `sdk.SortJSON`.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* (x/auth) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking.
|
||||
|
||||
## [v0.50.0-alpha.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-alpha.0) - 2023-06-07
|
||||
|
||||
### Features
|
||||
|
||||
@ -218,6 +218,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)
|
||||
}
|
||||
|
||||
@ -193,3 +193,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()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user