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] 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() +}