From 7f62ee56e31f84e688c001b4c436130d2b9d8ed6 Mon Sep 17 00:00:00 2001 From: Rootul P Date: Fri, 31 May 2024 09:01:31 -0600 Subject: [PATCH] fix: check if param store is defined (#403) --- baseapp/options.go | 3 +-- baseapp/options_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 baseapp/options_test.go diff --git a/baseapp/options.go b/baseapp/options.go index 0e2b8caf1ce9..614cdc8581e2 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -113,9 +113,8 @@ func (app *BaseApp) SetVersion(v string) { app.version = v } -// SetAppVersion sets the application's protocol version func (app *BaseApp) SetAppVersion(ctx sdk.Context, version uint64) { - if app.paramStore.Has(ctx, ParamStoreKeyVersionParams) { + if app.paramStore != nil && app.paramStore.Has(ctx, ParamStoreKeyVersionParams) { vp := &tmproto.VersionParams{AppVersion: version} app.paramStore.Set(ctx, ParamStoreKeyVersionParams, vp) } diff --git a/baseapp/options_test.go b/baseapp/options_test.go new file mode 100644 index 000000000000..93feabc49dec --- /dev/null +++ b/baseapp/options_test.go @@ -0,0 +1,18 @@ +package baseapp + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" +) + +// TestSetAppVersion verifies that SetAppVersion does not panic if paramStore is nil. +func TestSetAppVersion(t *testing.T) { + baseApp := NewBaseApp("test", nil, nil, nil) + baseApp.paramStore = nil // explicitly set to nil + + require.NotPanics(t, func() { + baseApp.SetAppVersion(types.Context{}, uint64(1)) + }) +}