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