Skip to content

Commit

Permalink
[1703]: Create the tourmaline-rc3 upgrade to set the new exchange par…
Browse files Browse the repository at this point in the history
…ams relating to payments.
  • Loading branch information
SpicyLemon committed Mar 7, 2024
1 parent ee015e3 commit 565de24
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
26 changes: 26 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
},
},
Expand Down Expand Up @@ -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) {
Expand All @@ -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))
Expand All @@ -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.")
}
68 changes: 68 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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")
})
}
}
1 change: 0 additions & 1 deletion x/exchange/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 565de24

Please sign in to comment.