Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-cosmos into branch-v6.6.1
  • Loading branch information
hoank101 committed Apr 26, 2024
2 parents fd90e43 + 7e1d398 commit 41dc537
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ import (
)

const (
Name = "picasso"
Name = "pica"
dirName = "banksy"
ForkHeight = 244008
)
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/v6_6_1/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ 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"
ibchookstypes "github.com/notional-labs/composable/v6/x/ibc-hooks/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"
bech32IbcHooksMigration "github.com/notional-labs/composable/v6/bech32-migration/ibchooks"
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 +53,8 @@ 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)
bech32IbcHooksMigration.MigrateAddressBech32(ctx, keys[ibchookstypes.StoreKey], codec)
return mm.RunMigrations(ctx, configurator, vm)
}
}
63 changes: 63 additions & 0 deletions app/upgrades/v6_6_1/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package v6_6_1_test

import (
"encoding/json"
ibchookskeeper "github.com/notional-labs/composable/v6/x/ibc-hooks/keeper"

Check failure on line 5 in app/upgrades/v6_6_1/upgrades_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
ibctransfermiddlewaretypes "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"

Check failure on line 6 in app/upgrades/v6_6_1/upgrades_test.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types" is being imported more than once (stylecheck)
"strings"
"testing"
"time"

Check failure on line 9 in app/upgrades/v6_6_1/upgrades_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
Expand All @@ -19,6 +21,9 @@ 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"
ibchookstypes "github.com/notional-labs/composable/v6/x/ibc-hooks/types"
ibctransfemiddlewaretypes "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"

Check failure on line 25 in app/upgrades/v6_6_1/upgrades_test.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types" (stylecheck)

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 +65,8 @@ func (s *UpgradeTestSuite) TestForMigratingNewPrefix() {
prepareForTestingMintModule(s)
prepareForTestingTransferMiddlewareModule(s)
prepareForTestingPfmMiddlewareModule(s)
prepareForTestingIbcTransferMiddlewareModule(s)
prepareForTestingIbcHooksModule(s)

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

func prepareForTestingGovModule(s *UpgradeTestSuite) (sdk.AccAddress, govtypes.Proposal) {
Expand Down Expand Up @@ -248,6 +257,39 @@ 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 prepareForTestingIbcHooksModule(s *UpgradeTestSuite) {
store := s.Ctx.KVStore(s.App.GetKey(ibchookstypes.StoreKey))
store.Set(ibchookskeeper.GetPacketKey("channel-2", 2), []byte("centauri1hj5fveer5cjtn4wd6wstzugjfdxzl0xpzxlwgs"))
store.Set(ibchookskeeper.GetPacketKey("channel-4", 2), []byte("centauri1wkjvpgkuchq0r8425g4z4sf6n85zj5wtmqzjv9"))
}

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 +493,27 @@ 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 checkUpgradeIbcHooksMiddlewareModule(s *UpgradeTestSuite) {
data := s.App.IBCHooksKeeper.GetPacketCallback(s.Ctx, "channel-2", 2)
s.Suite.Equal("pica1hj5fveer5cjtn4wd6wstzugjfdxzl0xpas3hgy", data)

data = s.App.IBCHooksKeeper.GetPacketCallback(s.Ctx, "channel-4", 2)
s.Suite.Equal("pica1wkjvpgkuchq0r8425g4z4sf6n85zj5wtykvtv3", data)

data = s.App.IBCHooksKeeper.GetPacketCallback(s.Ctx, "channel-2", 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
29 changes: 29 additions & 0 deletions bech32-migration/ibchooks/ibchooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ibchooks

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"
)

func MigrateAddressBech32(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) {
ctx.Logger().Info("Migration of address bech32 for ibchooks module begin")
totalAddr := uint64(0)
store := ctx.KVStore(storeKey)
channelKey := []byte("channel")
iterator := sdk.KVStorePrefixIterator(store, channelKey)
for ; iterator.Valid(); iterator.Next() {
totalAddr++
fullKey := iterator.Key()
contract := string(store.Get(fullKey))
contract = utils.SafeConvertAddress(contract)
totalAddr++
store.Set(fullKey, []byte(contract))
}

ctx.Logger().Info(
"Migration of address bech32 for ibchooks module done",
"totalAddr", totalAddr,
)
}
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
4 changes: 2 additions & 2 deletions cmd/picad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) {
WithViper("ICA")

rootCmd := &cobra.Command{
Use: app.Name + "d",
Short: "Composable App",
Use: "picad",
Short: "Picasso",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
// set the default command outputs
cmd.SetOut(cmd.OutOrStdout())
Expand Down

0 comments on commit 41dc537

Please sign in to comment.