From 67ef7008857369086556db0cb18035e0f03d5aa6 Mon Sep 17 00:00:00 2001 From: nulnut <151493716+nulnut@users.noreply.github.com> Date: Mon, 4 Nov 2024 11:44:56 +0800 Subject: [PATCH] fix: migration of pundix bank code --- app/upgrade_test.go | 5 ++++- app/upgrades/v8/pundix.go | 10 +++++++--- app/upgrades/v8/upgrade.go | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/upgrade_test.go b/app/upgrade_test.go index 26eba549..59b54728 100644 --- a/app/upgrade_test.go +++ b/app/upgrade_test.go @@ -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) { diff --git a/app/upgrades/v8/pundix.go b/app/upgrades/v8/pundix.go index f3a6ac77..c3e0bb88 100644 --- a/app/upgrades/v8/pundix.go +++ b/app/upgrades/v8/pundix.go @@ -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" @@ -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 { @@ -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 } diff --git a/app/upgrades/v8/upgrade.go b/app/upgrades/v8/upgrade.go index 543e6586..5e582b7c 100644 --- a/app/upgrades/v8/upgrade.go +++ b/app/upgrades/v8/upgrade.go @@ -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 {