Skip to content

Commit

Permalink
Merge branch 'main' into marko/gomod_change
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Dec 12, 2024
2 parents 8ea3954 + d973191 commit d20e48f
Show file tree
Hide file tree
Showing 9 changed files with 546 additions and 279 deletions.
5 changes: 4 additions & 1 deletion modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ func (k Keeper) sendTransfer(
for _, coin := range coins {
// Using types.UnboundedSpendLimit allows us to send the entire balance of a given denom.
if coin.Amount.Equal(types.UnboundedSpendLimit()) {
coin.Amount = k.bankKeeper.GetBalance(ctx, sender, coin.Denom).Amount
coin.Amount = k.bankKeeper.SpendableCoin(ctx, sender, coin.Denom).Amount
if coin.Amount.IsZero() {
return 0, errorsmod.Wrapf(types.ErrInvalidAmount, "empty spendable balance for %s", coin.Denom)
}
}

token, err := k.tokenFromCoin(ctx, coin)
Expand Down
60 changes: 59 additions & 1 deletion modules/apps/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,64 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
},
nil,
},
// TODO: Migrate vesting account test cases to use x/accounts lockup accounts as mentioned in v0.52 upgrading doc.
// https://github.com/cosmos/ibc-go/issues/7681
// {
// "successful transfer of entire spendable balance with vesting account",
// func() {
// // create vesting account
// vestingAccPrivKey := secp256k1.GenPrivKey()
// vestingAccAddress := sdk.AccAddress(vestingAccPrivKey.PubKey().Address())

// vestingCoins := sdk.NewCoins(sdk.NewCoin(coins[0].Denom, ibctesting.DefaultCoinAmount))
// _, err := suite.chainA.SendMsgs(vestingtypes.NewMsgCreateVestingAccount(
// suite.chainA.SenderAccount.GetAddress(),
// vestingAccAddress,
// vestingCoins,
// suite.chainA.GetContext().BlockTime().Add(time.Hour).Unix(),
// false,
// ))
// suite.Require().NoError(err)
// sender = vestingAccAddress

// // transfer some spendable coins to vesting account
// transferCoins := sdk.NewCoins(sdk.NewCoin(coins[0].Denom, sdkmath.NewInt(42)))
// _, err = suite.chainA.SendMsgs(banktypes.NewMsgSend(suite.chainA.SenderAccount.GetAddress(), vestingAccAddress, transferCoins))
// suite.Require().NoError(err)

// coins = sdk.NewCoins(sdk.NewCoin(coins[0].Denom, types.UnboundedSpendLimit()))
// expEscrowAmounts[0] = transferCoins[0].Amount
// },
// nil,
// },
// {
// "failure: no spendable coins for vesting account",
// func() {
// // create vesting account
// vestingAccPrivKey := secp256k1.GenPrivKey()
// vestingAccAddress := sdk.AccAddress(vestingAccPrivKey.PubKey().Address())

// vestingCoins := sdk.NewCoins(sdk.NewCoin(coins[0].Denom, ibctesting.DefaultCoinAmount))
// _, err := suite.chainA.SendMsgs(vestingtypes.NewMsgCreateVestingAccount(
// suite.chainA.SenderAccount.GetAddress(),
// vestingAccAddress,
// vestingCoins,
// suite.chainA.GetContext().BlockTime().Add(time.Hour).Unix(),
// false,
// ))
// suite.Require().NoError(err)
// sender = vestingAccAddress

// // just to prove that the vesting account has a balance (but not spendable)
// vestingAccBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), vestingAccAddress, coins[0].Denom)
// suite.Require().Equal(vestingCoins[0].Amount.Int64(), vestingAccBalance.Amount.Int64())
// vestinSpendableBalance := suite.chainA.GetSimApp().BankKeeper.SpendableCoins(suite.chainA.GetContext(), vestingAccAddress)
// suite.Require().Zero(vestinSpendableBalance.AmountOf(coins[0].Denom).Int64())

// coins = sdk.NewCoins(sdk.NewCoin(coins[0].Denom, types.UnboundedSpendLimit()))
// },
// types.ErrInvalidAmount,
// },
{
"failure: source channel not found",
func() {
Expand Down Expand Up @@ -223,8 +281,8 @@ func (suite *KeeperTestSuite) TestSendTransfer() {

expPass := tc.expError == nil
if expPass {
suite.Require().NotNil(res)
suite.Require().NoError(err)
suite.Require().NotNil(res)
} else {
suite.Require().Nil(res)
suite.Require().Error(err)
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type BankKeeper interface {
IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error
HasDenomMetaData(ctx context.Context, denom string) bool
SetDenomMetaData(ctx context.Context, denomMetaData banktypes.Metadata)
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
SpendableCoin(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
}

Expand Down
Loading

0 comments on commit d20e48f

Please sign in to comment.