Skip to content

Commit

Permalink
fix(axelarnet): SendCoinsFromModuleToModule takes module name instead…
Browse files Browse the repository at this point in the history
… of module account address
  • Loading branch information
fish-sammy committed Nov 19, 2024
1 parent 9514412 commit a14ac45
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion x/axelarnet/keeper/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func escrowFundsFromFailedTransfers(ctx sdk.Context, k Keeper, bankK types.BankK

// 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()))
err = bankK.SendCoinsFromModuleToModule(ctx, types.ModuleName, nexus.ModuleName, sdk.NewCoins(asset.GetAsset()))
if err != nil {
return err
}
Expand Down
38 changes: 30 additions & 8 deletions x/axelarnet/keeper/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ import (

func TestMigrate6to7(t *testing.T) {
var (
bank *mock.BankKeeperMock
account *mock.AccountKeeperMock
nexusK *mock.NexusMock
lockableAsset *nexusmock.LockableAssetMock
transfers []types.IBCTransfer
bank *mock.BankKeeperMock
account *mock.AccountKeeperMock
nexusK *mock.NexusMock
lockableAsset *nexusmock.LockableAssetMock
transfers []types.IBCTransfer
balances sdk.Coins
nexusModuleAccAddr sdk.AccAddress
axelarnetModuleAccAddr sdk.AccAddress
)

encCfg := app.MakeEncodingConfig()
Expand All @@ -44,9 +47,18 @@ func TestMigrate6to7(t *testing.T) {
return nil
},
}
nexusModuleAccAddr = rand.AccAddr()
axelarnetModuleAccAddr = rand.AccAddr()
account = &mock.AccountKeeperMock{
GetModuleAddressFunc: func(_ string) sdk.AccAddress {
return rand.AccAddr()
GetModuleAddressFunc: func(module string) sdk.AccAddress {
switch module {
case types.ModuleName:
return axelarnetModuleAccAddr
case nexustypes.ModuleName:
return nexusModuleAccAddr
default:
panic("unexpected module")
}
},
}
lockableAsset = &nexusmock.LockableAssetMock{
Expand All @@ -64,8 +76,9 @@ func TestMigrate6to7(t *testing.T) {
}
}).
When("there are some failed transfers and Axelarnet module account has balances", func() {
balances = sdk.NewCoins(rand.Coin(), rand.Coin(), rand.Coin())
bank.SpendableCoinsFunc = func(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
return sdk.NewCoins(rand.Coin(), rand.Coin(), rand.Coin())
return balances
}

for i := 0; i < 50; i++ {
Expand All @@ -81,6 +94,15 @@ func TestMigrate6to7(t *testing.T) {
err := keeper.Migrate6to7(k, bank, account, nexusK, ibcK)(ctx)
assert.NoError(t, err)
assert.Len(t, lockableAsset.LockFromCalls(), 3)
for _, call := range lockableAsset.LockFromCalls() {
assert.Equal(t, nexusModuleAccAddr, call.FromAddr)
}

assert.Len(t, bank.SendCoinsFromModuleToModuleCalls(), 3)
for _, call := range bank.SendCoinsFromModuleToModuleCalls() {
assert.Equal(t, types.ModuleName, call.SenderModule)
assert.Equal(t, nexustypes.ModuleName, call.RecipientModule)
}

for _, transfer := range transfers {
actual := funcs.MustOk(k.GetTransfer(ctx, transfer.ID))
Expand Down

0 comments on commit a14ac45

Please sign in to comment.