Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx committed Nov 5, 2024
1 parent e3ac476 commit dacf6ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 12 additions & 3 deletions x/axelarnet/keeper/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,17 +15,25 @@ 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 {
k.Logger(ctx).Info(fmt.Sprintf("coin %s is not a lockable asset", coin), "error", err)
continue

Check warning on line 26 in x/axelarnet/keeper/migrate.go

View check run for this annotation

Codecov / codecov/patch

x/axelarnet/keeper/migrate.go#L25-L26

Added lines #L25 - L26 were not covered by tests
}

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
}

Check warning on line 34 in x/axelarnet/keeper/migrate.go

View check run for this annotation

Codecov / codecov/patch

x/axelarnet/keeper/migrate.go#L33-L34

Added lines #L33 - L34 were not covered by tests

err = asset.LockFrom(ctx, nexusModuleAccount)
if err != nil {
return err
}

Check warning on line 39 in x/axelarnet/keeper/migrate.go

View check run for this annotation

Codecov / codecov/patch

x/axelarnet/keeper/migrate.go#L38-L39

Added lines #L38 - L39 were not covered by tests
Expand Down
6 changes: 5 additions & 1 deletion x/axelarnet/keeper/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit dacf6ae

Please sign in to comment.