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 (backport #1274) (#1281)

* fix(x/auth): ensure nil .BaseAccounts are reported in ModuleAccount.Validate (#1274)

(cherry picked from commit d9f1133)

# Conflicts:
#	CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Jayden Lee <[email protected]>
Co-authored-by: Youngtaek Yoon <[email protected]>
  • Loading branch information
3 people authored Mar 15, 2024
1 parent cb6669c commit 647075f
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 @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

### Bug Fixes
* (x/auth) [#1281](https://github.com/Finschia/finschia-sdk/pull/1281) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. (backport #1274)

### 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 647075f

Please sign in to comment.