Skip to content

Commit

Permalink
fix(x/auth): ensure nil .BaseAccounts are reported in ModuleAccount.V…
Browse files Browse the repository at this point in the history
…alidate (#1274)
  • Loading branch information
tkxkd0159 authored Mar 15, 2024
1 parent dc1d49e commit d9f1133
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes
* chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue
* (x/auth, x/slashing) [\#1179](https://github.com/Finschia/finschia-sdk/pull/1179) modify missing changes of converting to tendermint
* (x/auth) [#1274](https://github.com/Finschia/finschia-sdk/pull/1274) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking.

### Removed

Expand Down
4 changes: 4 additions & 0 deletions x/auth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,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)
}
Expand Down
7 changes: 6 additions & 1 deletion x/auth/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"

"github.com/Finschia/finschia-sdk/crypto/keys/secp256k1"
"github.com/Finschia/finschia-sdk/testutil/testdata"
Expand Down Expand Up @@ -207,3 +207,8 @@ func TestGenesisAccountsContains(t *testing.T) {
genAccounts = append(genAccounts, acc)
require.True(t, genAccounts.Contains(acc.GetAddress()))
}

func TestModuleAccountValidateNilBaseAccount(t *testing.T) {
ma := &types.ModuleAccount{Name: "foo"}
_ = ma.Validate()
}

0 comments on commit d9f1133

Please sign in to comment.