Skip to content

Commit 647075f

Browse files
mergify[bot]tkxkd01590Tech
authored
fix(x/auth): ensure nil .BaseAccounts are reported in ModuleAccount.Validate (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]>
1 parent cb6669c commit 647075f

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4343
### Improvements
4444

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

4748
### Removed
4849

x/auth/types/account.go

+4
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ func (ma ModuleAccount) Validate() error {
225225
return errors.New("module account name cannot be blank")
226226
}
227227

228+
if ma.BaseAccount == nil {
229+
return errors.New("uninitialized ModuleAccount: BaseAccount is nil")
230+
}
231+
228232
if ma.Address != sdk.AccAddress(crypto.AddressHash([]byte(ma.Name))).String() {
229233
return fmt.Errorf("address %s cannot be derived from the module name '%s'", ma.Address, ma.Name)
230234
}

x/auth/types/account_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/require"
10-
yaml "gopkg.in/yaml.v2"
10+
"gopkg.in/yaml.v2"
1111

1212
"github.com/Finschia/finschia-sdk/crypto/keys/secp256k1"
1313
"github.com/Finschia/finschia-sdk/testutil/testdata"
@@ -207,3 +207,8 @@ func TestGenesisAccountsContains(t *testing.T) {
207207
genAccounts = append(genAccounts, acc)
208208
require.True(t, genAccounts.Contains(acc.GetAddress()))
209209
}
210+
211+
func TestModuleAccountValidateNilBaseAccount(t *testing.T) {
212+
ma := &types.ModuleAccount{Name: "foo"}
213+
_ = ma.Validate()
214+
}

0 commit comments

Comments
 (0)