From 67947f6d6b39bddfda8724cbfd7a28e3b526f04e Mon Sep 17 00:00:00 2001
From: Khanh Hoa <hoa@notional.ventures>
Date: Fri, 24 May 2024 16:50:03 +0700
Subject: [PATCH] feat: add v4.1.6 handler

---
 app/app.go                       | 10 +++++++++-
 app/upgrades/v4_1_6/constants.go |  7 +++++++
 app/upgrades/v4_1_6/upgrades.go  | 17 +++++++++++++++++
 scripts/upgrade_test.sh          |  4 ++--
 4 files changed, 35 insertions(+), 3 deletions(-)
 create mode 100644 app/upgrades/v4_1_6/constants.go
 create mode 100644 app/upgrades/v4_1_6/upgrades.go

diff --git a/app/app.go b/app/app.go
index 544b1945..736affc5 100644
--- a/app/app.go
+++ b/app/app.go
@@ -158,6 +158,7 @@ import (
 	v3_0_2 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v3_0_2"
 	v42 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_1_2"
 	v45 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_1_5"
+	v46 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_1_6"
 	"github.com/rakyll/statik/fs"
 
 	// unnamed import of statik for swagger UI support
@@ -1172,6 +1173,13 @@ func (app *MigalooApp) setupUpgradeHandlers() {
 			app.configurator,
 		),
 	)
+	app.UpgradeKeeper.SetUpgradeHandler(
+		v46.UpgradeName,
+		v46.CreateUpgradeHandler(
+			app.mm,
+			app.configurator,
+		),
+	)
 
 	// When a planned update height is reached, the old binary will panic
 	// writing on disk the height and name of the update that triggered it
@@ -1185,7 +1193,7 @@ func (app *MigalooApp) setupUpgradeHandlers() {
 		return
 	}
 
-	if upgradeInfo.Name == v45.UpgradeName {
+	if upgradeInfo.Name == v46.UpgradeName {
 		storeUpgrades := &storetypes.StoreUpgrades{
 			Added:   []string{},
 			Deleted: []string{},
diff --git a/app/upgrades/v4_1_6/constants.go b/app/upgrades/v4_1_6/constants.go
new file mode 100644
index 00000000..53716228
--- /dev/null
+++ b/app/upgrades/v4_1_6/constants.go
@@ -0,0 +1,7 @@
+package v4
+
+// UpgradeName defines the on-chain upgrade name for the Migaloo v4.1.5 upgrade.
+// this upgrade includes the fix for pfm
+const (
+	UpgradeName = "v4.1.6"
+)
diff --git a/app/upgrades/v4_1_6/upgrades.go b/app/upgrades/v4_1_6/upgrades.go
new file mode 100644
index 00000000..efd3c63d
--- /dev/null
+++ b/app/upgrades/v4_1_6/upgrades.go
@@ -0,0 +1,17 @@
+package v4
+
+import (
+	sdk "github.com/cosmos/cosmos-sdk/types"
+	"github.com/cosmos/cosmos-sdk/types/module"
+	upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
+)
+
+// CreateUpgradeHandler that migrates the chain from v4.1.5 to v4.1.6
+func CreateUpgradeHandler(
+	mm *module.Manager,
+	configurator module.Configurator,
+) upgradetypes.UpgradeHandler {
+	return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
+		return mm.RunMigrations(ctx, configurator, fromVM)
+	}
+}
diff --git a/scripts/upgrade_test.sh b/scripts/upgrade_test.sh
index 14f7685c..a32be54e 100755
--- a/scripts/upgrade_test.sh
+++ b/scripts/upgrade_test.sh
@@ -3,13 +3,13 @@
 # the upgrade is a fork, "true" otherwise
 FORK=${FORK:-"false"}
 
-OLD_VERSION=v4.1.4
+OLD_VERSION=v4.1.5
 UPGRADE_WAIT=${UPGRADE_WAIT:-20}
 HOME=mytestnet
 ROOT=$(pwd)
 DENOM=uwhale
 CHAIN_ID=localmigaloo
-SOFTWARE_UPGRADE_NAME="v4.1.5"
+SOFTWARE_UPGRADE_NAME="v4.1.6"
 ADDITIONAL_PRE_SCRIPTS=${ADDITIONAL_PRE_SCRIPTS:-""}
 ADDITIONAL_AFTER_SCRIPTS=${ADDITIONAL_AFTER_SCRIPTS:-""}