55 "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
66 transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
77 channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
8+ "github.com/cosmos/ibc-go/v3/testing/mock"
89 "github.com/tendermint/tendermint/crypto/secp256k1"
910)
1011
@@ -18,6 +19,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
1819 refundAccBal sdk.Coin
1920 packetFee types.PacketFee
2021 packetFees []types.PacketFee
22+ fee types.Fee
2123 )
2224
2325 testCases := []struct {
@@ -27,7 +29,10 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
2729 }{
2830 {
2931 "success" ,
30- func () {},
32+ func () {
33+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
34+ packetFees = []types.PacketFee {packetFee , packetFee }
35+ },
3136 func () {
3237 // check if fees has been deleted
3338 packetID := channeltypes .NewPacketId (suite .path .EndpointA .ChannelConfig .PortID , suite .path .EndpointA .ChannelID , 1 )
@@ -56,8 +61,30 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
5661 suite .Require ().Equal (sdk .NewCoin (sdk .DefaultBondDenom , sdk .NewInt (0 )), balance )
5762 },
5863 },
64+ {
65+ "success: refund account is module account" ,
66+ func () {
67+ refundAcc = suite .chainA .GetSimApp ().AccountKeeper .GetModuleAddress (mock .ModuleName )
68+
69+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
70+ packetFees = []types.PacketFee {packetFee , packetFee }
71+
72+ // fund mock account
73+ err := suite .chainA .GetSimApp ().BankKeeper .SendCoinsFromAccountToModule (suite .chainA .GetContext (), suite .chainA .SenderAccount .GetAddress (), mock .ModuleName , packetFee .Fee .Total ().Add (packetFee .Fee .Total ()... ))
74+ suite .Require ().NoError (err )
75+ },
76+ func () {
77+ // check if the refund acc has been refunded the timeoutFee
78+ expectedRefundAccBal := defaultTimeoutFee [0 ].Add (defaultTimeoutFee [0 ])
79+ balance := suite .chainA .GetSimApp ().BankKeeper .GetBalance (suite .chainA .GetContext (), refundAcc , sdk .DefaultBondDenom )
80+ suite .Require ().Equal (expectedRefundAccBal , balance )
81+ },
82+ },
5983 {
6084 "escrow account out of balance, fee module becomes locked - no distribution" , func () {
85+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
86+ packetFees = []types.PacketFee {packetFee , packetFee }
87+
6188 // pass in an extra packet fee
6289 packetFees = append (packetFees , packetFee )
6390 },
@@ -76,6 +103,9 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
76103 {
77104 "invalid forward address" ,
78105 func () {
106+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
107+ packetFees = []types.PacketFee {packetFee , packetFee }
108+
79109 forwardRelayer = "invalid address"
80110 },
81111 func () {
@@ -88,6 +118,9 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
88118 {
89119 "invalid forward address: blocked address" ,
90120 func () {
121+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
122+ packetFees = []types.PacketFee {packetFee , packetFee }
123+
91124 forwardRelayer = suite .chainA .GetSimApp ().AccountKeeper .GetModuleAccount (suite .chainA .GetContext (), transfertypes .ModuleName ).GetAddress ().String ()
92125 },
93126 func () {
@@ -100,6 +133,9 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
100133 {
101134 "invalid receiver address: ack fee returned to sender" ,
102135 func () {
136+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
137+ packetFees = []types.PacketFee {packetFee , packetFee }
138+
103139 reverseRelayer = suite .chainA .GetSimApp ().AccountKeeper .GetModuleAccount (suite .chainA .GetContext (), transfertypes .ModuleName ).GetAddress ()
104140 },
105141 func () {
@@ -112,6 +148,9 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
112148 {
113149 "invalid refund address: no-op, timeout fee remains in escrow" ,
114150 func () {
151+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
152+ packetFees = []types.PacketFee {packetFee , packetFee }
153+
115154 packetFees [0 ].RefundAddress = suite .chainA .GetSimApp ().AccountKeeper .GetModuleAccount (suite .chainA .GetContext (), transfertypes .ModuleName ).GetAddress ().String ()
116155 packetFees [1 ].RefundAddress = suite .chainA .GetSimApp ().AccountKeeper .GetModuleAccount (suite .chainA .GetContext (), transfertypes .ModuleName ).GetAddress ().String ()
117156 },
@@ -137,18 +176,15 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
137176 refundAcc = suite .chainA .SenderAccount .GetAddress ()
138177
139178 packetID := channeltypes .NewPacketId (suite .path .EndpointA .ChannelConfig .PortID , suite .path .EndpointA .ChannelID , 1 )
140- fee : = types .NewFee (defaultRecvFee , defaultAckFee , defaultTimeoutFee )
179+ fee = types .NewFee (defaultRecvFee , defaultAckFee , defaultTimeoutFee )
141180
142- // escrow the packet fees & store the fees in state
143- packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
144- packetFees = []types.PacketFee {packetFee , packetFee }
181+ tc .malleate ()
145182
183+ // escrow the packet fees & store the fees in state
146184 suite .chainA .GetSimApp ().IBCFeeKeeper .SetFeesInEscrow (suite .chainA .GetContext (), packetID , types .NewPacketFees (packetFees ))
147185 err := suite .chainA .GetSimApp ().BankKeeper .SendCoinsFromAccountToModule (suite .chainA .GetContext (), refundAcc , types .ModuleName , packetFee .Fee .Total ().Add (packetFee .Fee .Total ()... ))
148186 suite .Require ().NoError (err )
149187
150- tc .malleate ()
151-
152188 // fetch the account balances before fee distribution (forward, reverse, refund)
153189 forwardAccAddress , _ := sdk .AccAddressFromBech32 (forwardRelayer )
154190 forwardRelayerBal = suite .chainA .GetSimApp ().BankKeeper .GetBalance (suite .chainA .GetContext (), forwardAccAddress , sdk .DefaultBondDenom )
0 commit comments