From dacf6ae881d69f3ff1af7c49525141366958ab7e Mon Sep 17 00:00:00 2001 From: Haiyi Zhong Date: Tue, 5 Nov 2024 10:44:27 -0500 Subject: [PATCH] address comments --- x/axelarnet/keeper/migrate.go | 15 ++++++++++++--- x/axelarnet/keeper/migrate_test.go | 6 +++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/x/axelarnet/keeper/migrate.go b/x/axelarnet/keeper/migrate.go index 4b04966c6..18f7585e7 100644 --- a/x/axelarnet/keeper/migrate.go +++ b/x/axelarnet/keeper/migrate.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/axelarnetwork/axelar-core/x/axelarnet/types" + nexus "github.com/axelarnetwork/axelar-core/x/nexus/types" ) // Migrate6to7 returns the handler that performs in-place store migrations from version 6 to 7 @@ -14,9 +15,10 @@ func Migrate6to7(k Keeper, bankK types.BankKeeper, accountK types.AccountKeeper, return func(ctx sdk.Context) error { // Failed IBC transfers are held in Axelarnet module account for later retry. // This migration escrows tokens back to escrow accounts so that we can use the same code path for retry. - moduleAccount := accountK.GetModuleAddress(types.ModuleName) + axelarnetModuleAccount := accountK.GetModuleAddress(types.ModuleName) + nexusModuleAccount := accountK.GetModuleAddress(nexus.ModuleName) - balances := bankK.SpendableCoins(ctx, moduleAccount) + balances := bankK.SpendableCoins(ctx, axelarnetModuleAccount) for _, coin := range balances { asset, err := nexusK.NewLockableAsset(ctx, ibcK, bankK, coin) if err != nil { @@ -24,7 +26,14 @@ func Migrate6to7(k Keeper, bankK types.BankKeeper, accountK types.AccountKeeper, continue } - err = asset.LockFrom(ctx, moduleAccount) + // Transfer coins from the Axelarnet module account to the Nexus module account for subsequent locking, + // as the Axelarnet module account is now restricted from sending coins. + err = bankK.SendCoinsFromModuleToModule(ctx, axelarnetModuleAccount.String(), nexusModuleAccount.String(), sdk.NewCoins(asset.GetAsset())) + if err != nil { + return err + } + + err = asset.LockFrom(ctx, nexusModuleAccount) if err != nil { return err } diff --git a/x/axelarnet/keeper/migrate_test.go b/x/axelarnet/keeper/migrate_test.go index 426256295..48c084337 100644 --- a/x/axelarnet/keeper/migrate_test.go +++ b/x/axelarnet/keeper/migrate_test.go @@ -35,7 +35,11 @@ func TestMigrate6to7(t *testing.T) { ctx := sdk.NewContext(fake.NewMultiStore(), tmproto.Header{}, false, log.TestingLogger()) Given("keeper setup before migration", func() { - bank = &mock.BankKeeperMock{} + bank = &mock.BankKeeperMock{ + SendCoinsFromModuleToModuleFunc: func(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error { + return nil + }, + } account = &mock.AccountKeeperMock{ GetModuleAddressFunc: func(_ string) sdk.AccAddress { return rand.AccAddr()