Skip to content

Commit

Permalink
upgrade handler
Browse files Browse the repository at this point in the history
  • Loading branch information
affanv14 committed Sep 24, 2024
1 parent c34d56d commit ac61de2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions protocol/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (app *App) setupUpgradeHandlers() {
app.configurator,
app.PricesKeeper,
app.VaultKeeper,
app.AffiliatesKeeper,
),
)
}
Expand Down
10 changes: 10 additions & 0 deletions protocol/app/upgrades/v7.0.0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/dydxprotocol/v4-chain/protocol/lib"
"github.com/dydxprotocol/v4-chain/protocol/lib/slinky"
affiliateskeeper "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/keeper"
affiliatetypes "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types"
pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types"
vaultkeeper "github.com/dydxprotocol/v4-chain/protocol/x/vault/keeper"
vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types"
Expand Down Expand Up @@ -55,11 +57,16 @@ func migrateVaultQuotingParamsToVaultParams(ctx sdk.Context, k vaultkeeper.Keepe
}
}

func setDefaultTiersForAffiliates(ctx sdk.Context, k affiliateskeeper.Keeper) {
k.UpdateAffiliateTiers(ctx, affiliatetypes.DefaultAffiliateTiers)
}

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
pricesKeeper pricestypes.PricesKeeper,
vaultKeeper vaultkeeper.Keeper,
affiliatesKeeper affiliateskeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
sdkCtx := lib.UnwrapSDKContext(ctx, "app/upgrades")
Expand All @@ -71,6 +78,9 @@ func CreateUpgradeHandler(
// Migrate vault quoting params to vault params.
migrateVaultQuotingParamsToVaultParams(sdkCtx, vaultKeeper)

// Set default tiers for affiliates.
setDefaultTiersForAffiliates(sdkCtx, affiliatesKeeper)

return mm.RunMigrations(ctx, configurator, vm)
}
}
21 changes: 21 additions & 0 deletions protocol/app/upgrades/v7.0.0/upgrade_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/dydxprotocol/v4-chain/protocol/dtypes"
"github.com/dydxprotocol/v4-chain/protocol/testing/containertest"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
affiliatestypes "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types"
vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -48,6 +49,9 @@ func preUpgradeChecks(node *containertest.Node, t *testing.T) {
func postUpgradeChecks(node *containertest.Node, t *testing.T) {
// Add test for your upgrade handler logic below
postUpgradeVaultParamsCheck(node, t)

// Check that the affiliates module has been initialized with the default tiers.
postUpgradeAffiliatesModuleTiersCheck(node, t)
}

func postUpgradeVaultParamsCheck(node *containertest.Node, t *testing.T) {
Expand Down Expand Up @@ -96,3 +100,20 @@ func checkVaultParams(
require.Equal(t, expectedStatus, vaultParamsResp.VaultParams.Status)
require.Equal(t, expectedQuotingParams, vaultParamsResp.VaultParams.QuotingParams)
}

func postUpgradeAffiliatesModuleTiersCheck(node *containertest.Node, t *testing.T) {

resp, err := containertest.Query(
node,
affiliatestypes.NewQueryClient,
affiliatestypes.QueryClient.AllAffiliateTiers,
&affiliatestypes.AllAffiliateTiersRequest{},
)
require.NoError(t, err)
require.NotNil(t, resp)

affiliateTiersResp := affiliatestypes.AllAffiliateTiersResponse{}
err = proto.UnmarshalText(resp.String(), &affiliateTiersResp)
require.NoError(t, err)
require.Equal(t, affiliatestypes.DefaultAffiliateTiers, affiliateTiersResp.Tiers)
}

0 comments on commit ac61de2

Please sign in to comment.