Skip to content

Commit

Permalink
[1658]: Set the exchange params to the defaults in the upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpicyLemon committed Oct 17, 2023
1 parent 30e1ceb commit f48c014
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
23 changes: 21 additions & 2 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var upgrades = map[string]appUpgrade{
removeInactiveValidatorDelegations(ctx, app)
setupICQ(ctx, app)
updateMaxSupply(ctx, app)
setExchangeParams(ctx, app)

return vm, nil
},
Expand All @@ -133,6 +134,7 @@ var upgrades = map[string]appUpgrade{
removeInactiveValidatorDelegations(ctx, app)
setupICQ(ctx, app)
updateMaxSupply(ctx, app)
setExchangeParams(ctx, app)

return vm, nil
},
Expand Down Expand Up @@ -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)
Expand All @@ -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.")
}
78 changes: 78 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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")
})
}
}

0 comments on commit f48c014

Please sign in to comment.