Skip to content

Commit

Permalink
refactor: add ibctransfermiddleware migration
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed Apr 26, 2024
1 parent 9abde67 commit 2577afd
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/upgrades/v6_6_0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
ibctransfermiddlewaretypes "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"

"github.com/notional-labs/composable/v6/app/keepers"
"github.com/notional-labs/composable/v6/app/upgrades"
bech32authmigration "github.com/notional-labs/composable/v6/bech32-migration/auth"
bech32govmigration "github.com/notional-labs/composable/v6/bech32-migration/gov"
bench32ibctransfermiddleware "github.com/notional-labs/composable/v6/bech32-migration/ibctransfermiddleware"
bech32icamigration "github.com/notional-labs/composable/v6/bech32-migration/ica"
bech32mintmigration "github.com/notional-labs/composable/v6/bech32-migration/mint"
bech32PfmMigration "github.com/notional-labs/composable/v6/bech32-migration/pfmmiddleware"
Expand Down Expand Up @@ -49,6 +51,7 @@ func CreateUpgradeHandler(
bech32transfermiddlewaremigration.MigrateAddressBech32(ctx, keys[transfermiddlewaretypes.StoreKey], codec)
bech32WasmMigration.MigrateAddressBech32(ctx, keys[wasm.StoreKey], codec)
bech32PfmMigration.MigrateAddressBech32(ctx, keys[routertypes.StoreKey], codec, keepers)
bench32ibctransfermiddleware.MigrateAddressBech32(ctx, keys[ibctransfermiddlewaretypes.StoreKey], codec)
return mm.RunMigrations(ctx, configurator, vm)
}
}
43 changes: 43 additions & 0 deletions app/upgrades/v6_6_0/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v6_6_0_test

import (
"encoding/json"
ibctransfermiddlewaretypes "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"
"strings"
"testing"
"time"
Expand All @@ -19,6 +20,8 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
ibctransfemiddlewaretypes "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"

apptesting "github.com/notional-labs/composable/v6/app"
"github.com/notional-labs/composable/v6/bech32-migration/utils"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -60,6 +63,7 @@ func (s *UpgradeTestSuite) TestForMigratingNewPrefix() {
prepareForTestingMintModule(s)
prepareForTestingTransferMiddlewareModule(s)
prepareForTestingPfmMiddlewareModule(s)
prepareForTestingIbcTransferMiddlewareModule(s)

/* == UPGRADE == */
upgradeHeight := int64(5)
Expand All @@ -75,6 +79,7 @@ func (s *UpgradeTestSuite) TestForMigratingNewPrefix() {
checkUpgradeMintModule(s)
checkUpgradeTransferMiddlewareModule(s)
checkUpgradePfmMiddlewareModule(s)
checkUpgradeIbcTransferMiddlewareModule(s)
}

func prepareForTestingGovModule(s *UpgradeTestSuite) (sdk.AccAddress, govtypes.Proposal) {
Expand Down Expand Up @@ -248,6 +253,33 @@ func prepareForTestingPfmMiddlewareModule(s *UpgradeTestSuite) {
store.Set(key, bz)
}

func prepareForTestingIbcTransferMiddlewareModule(s *UpgradeTestSuite) {
store := s.Ctx.KVStore(s.App.GetKey(ibctransfermiddlewaretypes.StoreKey))
var fees []*ibctransfemiddlewaretypes.ChannelFee
fees = append(fees, &ibctransfemiddlewaretypes.ChannelFee{
Channel: "channel-7",
AllowedTokens: []*ibctransfemiddlewaretypes.CoinItem{{
MinFee: sdk.Coin{},
Percentage: 20,
}},
FeeAddress: "centauri1hj5fveer5cjtn4wd6wstzugjfdxzl0xpzxlwgs",
MinTimeoutTimestamp: 0,
})
fees = append(fees, &ibctransfemiddlewaretypes.ChannelFee{
Channel: "channel-9",
AllowedTokens: []*ibctransfemiddlewaretypes.CoinItem{{
MinFee: sdk.Coin{},
Percentage: 10,
}},
FeeAddress: "centauri1hj5fveer5cjtn4wd6wstzugjfdxzl0xpzxlwgs",
MinTimeoutTimestamp: 0,
})
params := ibctransfemiddlewaretypes.Params{ChannelFees: fees}
encCdc := apptesting.MakeEncodingConfig()
bz := encCdc.Amino.MustMarshal(&params)
store.Set(ibctransfemiddlewaretypes.ParamsKey, bz)
}

func checkUpgradeGovModule(s *UpgradeTestSuite, acc1 sdk.AccAddress, proposal govtypes.Proposal) {
// CONVERT ACC TO NEW PREFIX
_, bz, _ := bech32.DecodeAndConvert(acc1.String())
Expand Down Expand Up @@ -451,6 +483,17 @@ func checkUpgradePfmMiddlewareModule(s *UpgradeTestSuite) {
s.Suite.Equal("pica1hj5fveer5cjtn4wd6wstzugjfdxzl0xpas3hgy", data.OriginalSenderAddress)
}

func checkUpgradeIbcTransferMiddlewareModule(s *UpgradeTestSuite) {
data := s.App.IbcTransferMiddlewareKeeper.GetChannelFeeAddress(s.Ctx, "channel-9")
s.Suite.Equal("pica1hj5fveer5cjtn4wd6wstzugjfdxzl0xpas3hgy", data)

data = s.App.IbcTransferMiddlewareKeeper.GetChannelFeeAddress(s.Ctx, "channel-7")
s.Suite.Equal("pica1hj5fveer5cjtn4wd6wstzugjfdxzl0xpas3hgy", data)
data = s.App.IbcTransferMiddlewareKeeper.GetChannelFeeAddress(s.Ctx, "channel-1")
s.Suite.Equal("", data)

}

func CreateVestingAccount(s *UpgradeTestSuite,
) vestingtypes.ContinuousVestingAccount {
str := `{"@type":"/cosmos.vesting.v1beta1.ContinuousVestingAccount","base_vesting_account":{"base_account":{"address":"centauri1alga5e8vr6ccr9yrg0kgxevpt5xgmgrvfkc5p8","pub_key":{"@type":"/cosmos.crypto.multisig.LegacyAminoPubKey","threshold":4,"public_keys":[{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AlnzK22KrkylnvTCvZZc8eZnydtQuzCWLjJJSMFUvVHf"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Aiw2Ftg+fnoHDU7M3b0VMRsI0qurXlerW0ahtfzSDZA4"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AvEHv+MVYRVau8FbBcJyG0ql85Tbbn7yhSA0VGmAY4ku"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Az5VHWqi3zMJu1rLGcu2EgNXLLN+al4Dy/lj6UZTzTCl"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Ai4GlSH3uG+joMnAFbQC3jQeHl9FPvVTlRmwIFt7d7TI"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A2kAzH2bZr530jmFq/bRFrT2q8SRqdnfIebba+YIBqI1"}]},"account_number":46,"sequence":27},"original_vesting":[{"denom":"stake","amount":"22165200000000"}],"delegated_free":[{"denom":"stake","amount":"443382497453"}],"delegated_vesting":[{"denom":"stake","amount":"22129422502547"}],"end_time":1770994800},"start_time":1676300400}`
Expand Down
32 changes: 32 additions & 0 deletions bech32-migration/ibctransfermiddleware/ibctransfermiddleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ibctransfermiddleware

import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/notional-labs/composable/v6/bech32-migration/utils"
"github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"
)

func MigrateAddressBech32(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) {
ctx.Logger().Info("Migration of address bech32 for ibctransfermiddleware module begin")
totalAddr := uint64(0)
store := ctx.KVStore(storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return
}
var params types.Params
cdc.MustUnmarshal(bz, &params)
for i := range params.ChannelFees {
totalAddr++
params.ChannelFees[i].FeeAddress = utils.SafeConvertAddress(params.ChannelFees[i].FeeAddress)
}
bz = cdc.MustMarshal(&params)
store.Set(types.ParamsKey, bz)

ctx.Logger().Info(
"Migration of address bech32 for ibctransfermiddleware module done",
"totalAddr", totalAddr,
)
}
2 changes: 1 addition & 1 deletion bech32-migration/ica/ica.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package slashing
package ica

import (
"strings"
Expand Down

0 comments on commit 2577afd

Please sign in to comment.