Skip to content

Commit

Permalink
fix: migration of pundix bank code (#802)
Browse files Browse the repository at this point in the history
Co-authored-by: nulnut <151493716+nulnut@users.noreply.github.com>
  • Loading branch information
zakir-code and nulnut authored Nov 4, 2024
1 parent 921baff commit 7684c50
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ func checkPundixChainMigrate(t *testing.T, ctx sdk.Context, myApp *app.App) {
appState, err := nextversion.ReadGenesisState(pundixGenesisPath)
require.NoError(t, err)

checkPundixBank(t, ctx, myApp, appState[banktypes.ModuleName])
bankGenesis, ok := appState[banktypes.ModuleName]
require.True(t, ok)
require.NotEmpty(t, bankGenesis)
checkPundixBank(t, ctx, myApp, bankGenesis)
}

func checkPundixBank(t *testing.T, ctx sdk.Context, myApp *app.App, raw json.RawMessage) {
Expand Down
10 changes: 7 additions & 3 deletions app/upgrades/v8/pundix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
"github.com/ethereum/go-ethereum/common"
evmtypes "github.com/evmos/ethermint/x/evm/types"

"github.com/functionx/fx-core/v8/app/keepers"
"github.com/functionx/fx-core/v8/contract"
Expand Down Expand Up @@ -62,7 +62,11 @@ func (m *Pundix) Migrate(ctx sdk.Context) error {
return err
}
// todo migrate other data
return m.migrateBank(ctx, appState[banktypes.ModuleName])
bankGenesis, ok := appState[banktypes.ModuleName]
if !ok || len(bankGenesis) == 0 {
return sdkerrors.ErrNotFound.Wrap("bank genesis")
}
return m.migrateBank(ctx, bankGenesis)
}

func (m *Pundix) migrateBank(ctx sdk.Context, bankRaw json.RawMessage) error {
Expand Down Expand Up @@ -287,7 +291,7 @@ func (m *Pundix) migratePundixPurse(

func (m *Pundix) updatePurseErc20Owner(ctx sdk.Context, erc20Token erc20types.ERC20Token) error {
erc20ModuleHexAddress := common.BytesToAddress(types.NewModuleAddress(erc20types.ModuleName).Bytes())
newOwner := common.BytesToAddress(types.NewModuleAddress(govtypes.ModuleName))
newOwner := common.BytesToAddress(types.NewModuleAddress(evmtypes.ModuleName))
if _, err := m.erc20TokenKeeper.TransferOwnership(ctx, erc20Token.GetERC20Contract(), erc20ModuleHexAddress, newOwner); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v8/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator,
}

if err = NewPundix(app).Migrate(cacheCtx); err != nil {
return nil, err
return fromVM, err
}

if err = migrateBridgeBalance(cacheCtx, app.BankKeeper, app.AccountKeeper); err != nil {
Expand Down

0 comments on commit 7684c50

Please sign in to comment.