Skip to content

Commit

Permalink
fix: check if param store is defined (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp authored May 31, 2024
1 parent 46df629 commit 7f62ee5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
18 changes: 18 additions & 0 deletions baseapp/options_test.go
Original file line number Diff line number Diff line change
@@ -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))
})
}

0 comments on commit 7f62ee5

Please sign in to comment.