diff --git a/app/upgrades.go b/app/upgrades.go index 32606cba94..38d4e0abae 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -114,6 +114,7 @@ var upgrades = map[string]appUpgrade{ removeInactiveValidatorDelegations(ctx, app) setupICQ(ctx, app) updateMaxSupply(ctx, app) + setExchangeParams(ctx, app) return vm, nil }, @@ -133,6 +134,7 @@ var upgrades = map[string]appUpgrade{ removeInactiveValidatorDelegations(ctx, app) setupICQ(ctx, app) updateMaxSupply(ctx, app) + setExchangeParams(ctx, app) return vm, nil }, @@ -325,14 +327,16 @@ func setAccountDataNameRecord(ctx sdk.Context, accountK attributetypes.AccountKe return attributekeeper.EnsureModuleAccountAndAccountDataNameRecord(ctx, accountK, nameK) } -// setupICQ sets the correct default values for ICQKeeper +// setupICQ sets the correct default values for ICQKeeper. +// TODO: Remove with the saffron handlers. func setupICQ(ctx sdk.Context, app *App) { ctx.Logger().Info("Updating ICQ params") app.ICQKeeper.SetParams(ctx, icqtypes.NewParams(true, []string{"/provenance.oracle.v1.Query/Oracle"})) ctx.Logger().Info("Done updating ICQ params") } -// updateMaxSupply sets the value of max supply to the current value of MaxTotalSupply +// updateMaxSupply sets the value of max supply to the current value of MaxTotalSupply. +// TODO: Remove with the saffron handlers. func updateMaxSupply(ctx sdk.Context, app *App) { ctx.Logger().Info("Updating MaxSupply marker param") params := app.MarkerKeeper.GetParams(ctx) @@ -341,3 +345,18 @@ func updateMaxSupply(ctx sdk.Context, app *App) { app.MarkerKeeper.SetParams(ctx, params) ctx.Logger().Info("Done updating MaxSupply marker param") } + +// setExchangeParams sets exchange module's params to the defaults. +// TODO: Remove with the saffron handlers. +func setExchangeParams(ctx sdk.Context, app *App) { + ctx.Logger().Info("Ensuring exchange module params are set.") + params := app.ExchangeKeeper.GetParams(ctx) + if params != nil { + ctx.Logger().Info("Exchange module params are already defined.") + } else { + params = exchange.DefaultParams() + ctx.Logger().Info("Setting exchange module params to defaults.") + app.ExchangeKeeper.SetParams(ctx, params) + } + ctx.Logger().Info("Done ensuring exchange module params are set.") +} diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 769330a3b9..f264b24dee 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -24,6 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/provenance-io/provenance/x/exchange" msgfeetypes "github.com/provenance-io/provenance/x/msgfees/types" ) @@ -426,6 +427,7 @@ func (s *UpgradeTestSuite) TestSaffronRC1() { "INF Done updating ICQ params", "INF Updating MaxSupply marker param", "INF Done updating MaxSupply marker param", + "INF Ensuring exchange module params are set.", } s.AssertUpgradeHandlerLogs("saffron-rc1", expInLog, nil) @@ -442,6 +444,7 @@ func (s *UpgradeTestSuite) TestSaffron() { "INF Done updating ICQ params", "INF Updating MaxSupply marker param", "INF Done updating MaxSupply marker param", + "INF Ensuring exchange module params are set.", } s.AssertUpgradeHandlerLogs("saffron", expInLog, nil) @@ -841,3 +844,78 @@ func (s *UpgradeTestSuite) TestSetAccountDataNameRecord() { s.Require().NoError(err, "setAccountDataNameRecord") s.AssertLogContents(logOutput, expInLog, nil, true, "setAccountDataNameRecord") } + +func (s *UpgradeTestSuite) TestSetExchangeParams() { + startMsg := "INF Ensuring exchange module params are set." + noopMsg := "INF Exchange module params are already defined." + updateMsg := "INF Setting exchange module params to defaults." + doneMsg := "INF Done ensuring exchange module params are set." + + tests := []struct { + name string + existingParams *exchange.Params + expectedParams *exchange.Params + expInLog []string + }{ + { + name: "no params set yet", + existingParams: nil, + expectedParams: exchange.DefaultParams(), + expInLog: []string{startMsg, updateMsg, doneMsg}, + }, + { + name: "params set with no splits and default zero", + existingParams: &exchange.Params{DefaultSplit: 0}, + expectedParams: &exchange.Params{DefaultSplit: 0}, + expInLog: []string{startMsg, noopMsg, doneMsg}, + }, + { + name: "params set with no splits and different default", + existingParams: &exchange.Params{DefaultSplit: exchange.DefaultDefaultSplit + 100}, + expectedParams: &exchange.Params{DefaultSplit: exchange.DefaultDefaultSplit + 100}, + expInLog: []string{startMsg, noopMsg, doneMsg}, + }, + { + name: "params set with some splits", + existingParams: &exchange.Params{ + DefaultSplit: exchange.DefaultDefaultSplit + 100, + DenomSplits: []exchange.DenomSplit{ + {Denom: "peach", Split: 3000}, + {Denom: "plum", Split: 100}, + }, + }, + expectedParams: &exchange.Params{ + DefaultSplit: exchange.DefaultDefaultSplit + 100, + DenomSplits: []exchange.DenomSplit{ + {Denom: "peach", Split: 3000}, + {Denom: "plum", Split: 100}, + }, + }, + expInLog: []string{startMsg, noopMsg, doneMsg}, + }, + } + + for _, tc := range tests { + s.Run(tc.name, func() { + s.app.ExchangeKeeper.SetParams(s.ctx, tc.existingParams) + + // Reset the log buffer and call the fun. Relog the output if it panics. + s.logBuffer.Reset() + testFunc := func() { + setExchangeParams(s.ctx, s.app) + } + didNotPanic := s.Assert().NotPanics(testFunc, "setExchangeParams") + logOutput := s.GetLogOutput("setExchangeParams") + if !didNotPanic { + return + } + + // Make sure the log has the expected lines. + s.AssertLogContents(logOutput, tc.expInLog, nil, true, "setExchangeParams") + + // Make sure the params are as expected now. + params := s.app.ExchangeKeeper.GetParams(s.ctx) + s.Assert().Equal(tc.expectedParams, params, "params after setExchangeParams") + }) + } +}