Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check if param store is defined #403

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
})
}
Comment on lines +10 to +18
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note this test failed before the change in this PR so this test should catch regressions if we attempt to merge in upstream changes from cosmos-sdk and accidentally revert the implementation change in options.go

Loading