diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 4caa0579846..cb481543a23 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -76,6 +76,17 @@ func (k Keeper) GetFeeModuleAddress() sdk.AccAddress { return k.authKeeper.GetModuleAddress(types.ModuleName) } +// EscrowAccountHasBalance verifies if the escrow account has the provided fee. +func (k Keeper) EscrowAccountHasBalance(ctx sdk.Context, coins sdk.Coins) bool { + for _, coin := range coins { + if !k.bankKeeper.HasBalance(ctx, k.GetFeeModuleAddress(), coin) { + return false + } + } + + return true +} + // SetFeeEnabled sets a flag to determine if fee handling logic should run for the given channel // identified by channel and port identifiers. func (k Keeper) SetFeeEnabled(ctx sdk.Context, portID, channelID string) { diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index 92705c9c7cc..1f29a8872d5 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -67,6 +67,27 @@ func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } +func (suite *KeeperTestSuite) TestEscrowAccountHasBalance() { + fee := types.Fee{ + AckFee: defaultAckFee, + RecvFee: defaultReceiveFee, + TimeoutFee: defaultTimeoutFee, + } + + suite.Require().False(suite.chainA.GetSimApp().IBCFeeKeeper.EscrowAccountHasBalance(suite.chainA.GetContext(), fee.Total())) + + // set fee in escrow account + err := suite.chainA.GetSimApp().BankKeeper.SendCoinsFromAccountToModule(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), types.ModuleName, fee.Total()) + suite.Require().Nil(err) + + suite.Require().True(suite.chainA.GetSimApp().IBCFeeKeeper.EscrowAccountHasBalance(suite.chainA.GetContext(), fee.Total())) + + // increase ack fee + fee.AckFee = fee.AckFee.Add(defaultAckFee...) + suite.Require().False(suite.chainA.GetSimApp().IBCFeeKeeper.EscrowAccountHasBalance(suite.chainA.GetContext(), fee.Total())) + +} + func (suite *KeeperTestSuite) TestFeesInEscrow() { suite.coordinator.Setup(suite.path)