From 565de2468a2d58409a57ffbd0e5060c981c6c9c8 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 7 Mar 2024 10:07:56 -0700 Subject: [PATCH] [1703]: Create the tourmaline-rc3 upgrade to set the new exchange params relating to payments. --- app/upgrades.go | 26 ++++++++++++++ app/upgrades_test.go | 68 +++++++++++++++++++++++++++++++++++++ x/exchange/keeper/params.go | 1 - 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index b051996740..98978932ce 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -133,6 +133,12 @@ var upgrades = map[string]appUpgrade{ }, }, "tourmaline-rc2": {}, // upgrade for v1.18.0-rc2 + "tourmaline-rc3": { // upgrade for v1.18.0-rc3 + Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) { + updateExchangePaymentParams(ctx, app) + return vm, nil + }, + }, "tourmaline": { // upgrade for v1.18.0 Added: []string{ibcratelimit.ModuleName}, Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) { @@ -148,6 +154,8 @@ var upgrades = map[string]appUpgrade{ // This isn't in an rc because it was handled via gov prop for testnet. updateMsgFeesNhashPerMil(ctx, app) + updateExchangePaymentParams(ctx, app) + return vm, nil }, }, @@ -357,6 +365,7 @@ func updateIbcMarkerDenomMetadata(ctx sdk.Context, app *App) { } // convertNavUnits iterates all the net asset values and updates their units if they are using usd. +// TODO: Remove with the tourmaline handlers. func convertNavUnits(ctx sdk.Context, app *App) { ctx.Logger().Info("Converting NAV units.") err := app.MarkerKeeper.IterateAllNetAssetValues(ctx, func(markerAddr sdk.AccAddress, nav markertypes.NetAssetValue) (stop bool) { @@ -382,6 +391,7 @@ func convertNavUnits(ctx sdk.Context, app *App) { } // updateMsgFeesNhashPerMil updates the MsgFees Params to set the NhashPerUsdMil to 40,000,000. +// TODO: Remove with the tourmaline handlers. func updateMsgFeesNhashPerMil(ctx sdk.Context, app *App) { var newVal uint64 = 40_000_000 ctx.Logger().Info(fmt.Sprintf("Setting MsgFees Params NhashPerUsdMil to %d.", newVal)) @@ -390,3 +400,19 @@ func updateMsgFeesNhashPerMil(ctx sdk.Context, app *App) { app.MsgFeesKeeper.SetParams(ctx, params) ctx.Logger().Info("Done setting MsgFees Params NhashPerUsdMil.") } + +// updateExchangePaymentParams updates the exchange module params to have the default create payment and accept payment values. +// TODO: Remove with the tourmaline handlers. +func updateExchangePaymentParams(ctx sdk.Context, app *App) { + ctx.Logger().Info("Setting default exchange module payment params.") + defaultParams := exchange.DefaultParams() + curParams := app.ExchangeKeeper.GetParams(ctx) + if curParams == nil { + curParams = defaultParams + } else { + curParams.FeeCreatePaymentFlat = defaultParams.FeeCreatePaymentFlat + curParams.FeeAcceptPaymentFlat = defaultParams.FeeAcceptPaymentFlat + } + app.ExchangeKeeper.SetParams(ctx, curParams) + ctx.Logger().Info("Done setting default exchange module payment params.") +} diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 70a5ae71ee..cc4ac57fb6 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -442,6 +442,15 @@ func (s *UpgradeTestSuite) TestTourmalineRC2() { s.Require().Empty(upgrades[key], "upgrades[%q]", key) } +func (s *UpgradeTestSuite) TestTourmalineRC3() { + expInLog := []string{ + "INF Setting default exchange module payment params.", + "INF Done setting default exchange module payment params.", + } + + s.AssertUpgradeHandlerLogs("tourmaline-rc3", expInLog, nil) +} + func (s *UpgradeTestSuite) TestTourmaline() { expInLog := []string{ "INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.", @@ -974,3 +983,62 @@ func (s *UpgradeTestSuite) TestUpdateMsgFeesNhashPerMil() { }) } } + +func (s *UpgradeTestSuite) TestUpdateExchangePaymentParams() { + origParams := s.app.ExchangeKeeper.GetParams(s.ctx) + defer s.app.ExchangeKeeper.SetParams(s.ctx, origParams) + + defaultParams := exchange.DefaultParams() + + tests := []struct { + name string + existingParams *exchange.Params + expectedParams *exchange.Params + }{ + { + name: "no params set yet", + existingParams: nil, + expectedParams: defaultParams, + }, + { + name: "params set previously", + existingParams: &exchange.Params{ + DefaultSplit: 333, + DenomSplits: []exchange.DenomSplit{{Denom: "date", Split: 99}}, + FeeCreatePaymentFlat: nil, + FeeAcceptPaymentFlat: nil, + }, + expectedParams: &exchange.Params{ + DefaultSplit: 333, + DenomSplits: []exchange.DenomSplit{{Denom: "date", Split: 99}}, + FeeCreatePaymentFlat: defaultParams.FeeCreatePaymentFlat, + FeeAcceptPaymentFlat: defaultParams.FeeAcceptPaymentFlat, + }, + }, + } + + for _, tc := range tests { + s.Run(tc.name, func() { + s.app.ExchangeKeeper.SetParams(s.ctx, tc.existingParams) + expInLog := []string{ + "INF Setting default exchange module payment params.", + "INF Done setting default exchange module payment params.", + } + + // Reset the log buffer and call the func. Relog the output if it panics. + s.logBuffer.Reset() + testFunc := func() { + updateExchangePaymentParams(s.ctx, s.app) + } + didNotPanic := s.Assert().NotPanics(testFunc, "updateExchangePaymentParams") + logOutput := s.GetLogOutput("updateExchangePaymentParams") + if !didNotPanic { + return + } + s.AssertLogContents(logOutput, expInLog, nil, true, "updateExchangePaymentParams") + + actParams := s.app.ExchangeKeeper.GetParams(s.ctx) + s.Assert().Equal(tc.expectedParams, actParams, "Exchange Params after updateExchangePaymentParams") + }) + } +} diff --git a/x/exchange/keeper/params.go b/x/exchange/keeper/params.go index b6906aa57b..4dfe030d7a 100644 --- a/x/exchange/keeper/params.go +++ b/x/exchange/keeper/params.go @@ -126,7 +126,6 @@ func (k Keeper) SetParams(ctx sdk.Context, params *exchange.Params) { feeAccept = params.FeeAcceptPaymentFlat } - // TODO[1703]: In an upgrade handler, update the exchange params to include the new fields. setParamsFeeCreatePaymentFlat(store, feeCreate) setParamsFeeAcceptPaymentFlat(store, feeAccept) }