From f6b4919099a32a781b5134b3c48f3a4690ec3b6c Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:41:15 +0900 Subject: [PATCH 1/2] add nil checking --- x/auth/types/account.go | 4 ++++ x/auth/types/account_test.go | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/x/auth/types/account.go b/x/auth/types/account.go index 52813e9999..d770f0dfaa 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -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) } diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 0aed16c51c..a90a633051 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -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" @@ -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() +} From 0ff2753de248eef90b0f5738fd9935fa31723d4e Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:43:32 +0900 Subject: [PATCH 2/2] add CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c5c5569f4..5ac04e13c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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