5
5
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
6
6
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
7
7
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
8
+ "github.com/cosmos/ibc-go/v3/testing/mock"
8
9
"github.com/tendermint/tendermint/crypto/secp256k1"
9
10
)
10
11
@@ -18,6 +19,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
18
19
refundAccBal sdk.Coin
19
20
packetFee types.PacketFee
20
21
packetFees []types.PacketFee
22
+ fee types.Fee
21
23
)
22
24
23
25
testCases := []struct {
@@ -27,7 +29,10 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
27
29
}{
28
30
{
29
31
"success" ,
30
- func () {},
32
+ func () {
33
+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
34
+ packetFees = []types.PacketFee {packetFee , packetFee }
35
+ },
31
36
func () {
32
37
// check if fees has been deleted
33
38
packetID := channeltypes .NewPacketId (suite .path .EndpointA .ChannelConfig .PortID , suite .path .EndpointA .ChannelID , 1 )
@@ -56,8 +61,30 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
56
61
suite .Require ().Equal (sdk .NewCoin (sdk .DefaultBondDenom , sdk .NewInt (0 )), balance )
57
62
},
58
63
},
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
+ },
59
83
{
60
84
"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
+
61
88
// pass in an extra packet fee
62
89
packetFees = append (packetFees , packetFee )
63
90
},
@@ -76,6 +103,9 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
76
103
{
77
104
"invalid forward address" ,
78
105
func () {
106
+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
107
+ packetFees = []types.PacketFee {packetFee , packetFee }
108
+
79
109
forwardRelayer = "invalid address"
80
110
},
81
111
func () {
@@ -88,6 +118,9 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
88
118
{
89
119
"invalid forward address: blocked address" ,
90
120
func () {
121
+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
122
+ packetFees = []types.PacketFee {packetFee , packetFee }
123
+
91
124
forwardRelayer = suite .chainA .GetSimApp ().AccountKeeper .GetModuleAccount (suite .chainA .GetContext (), transfertypes .ModuleName ).GetAddress ().String ()
92
125
},
93
126
func () {
@@ -100,6 +133,9 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
100
133
{
101
134
"invalid receiver address: ack fee returned to sender" ,
102
135
func () {
136
+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
137
+ packetFees = []types.PacketFee {packetFee , packetFee }
138
+
103
139
reverseRelayer = suite .chainA .GetSimApp ().AccountKeeper .GetModuleAccount (suite .chainA .GetContext (), transfertypes .ModuleName ).GetAddress ()
104
140
},
105
141
func () {
@@ -112,6 +148,9 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
112
148
{
113
149
"invalid refund address: no-op, timeout fee remains in escrow" ,
114
150
func () {
151
+ packetFee = types .NewPacketFee (fee , refundAcc .String (), []string {})
152
+ packetFees = []types.PacketFee {packetFee , packetFee }
153
+
115
154
packetFees [0 ].RefundAddress = suite .chainA .GetSimApp ().AccountKeeper .GetModuleAccount (suite .chainA .GetContext (), transfertypes .ModuleName ).GetAddress ().String ()
116
155
packetFees [1 ].RefundAddress = suite .chainA .GetSimApp ().AccountKeeper .GetModuleAccount (suite .chainA .GetContext (), transfertypes .ModuleName ).GetAddress ().String ()
117
156
},
@@ -137,18 +176,15 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
137
176
refundAcc = suite .chainA .SenderAccount .GetAddress ()
138
177
139
178
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 )
141
180
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 ()
145
182
183
+ // escrow the packet fees & store the fees in state
146
184
suite .chainA .GetSimApp ().IBCFeeKeeper .SetFeesInEscrow (suite .chainA .GetContext (), packetID , types .NewPacketFees (packetFees ))
147
185
err := suite .chainA .GetSimApp ().BankKeeper .SendCoinsFromAccountToModule (suite .chainA .GetContext (), refundAcc , types .ModuleName , packetFee .Fee .Total ().Add (packetFee .Fee .Total ()... ))
148
186
suite .Require ().NoError (err )
149
187
150
- tc .malleate ()
151
-
152
188
// fetch the account balances before fee distribution (forward, reverse, refund)
153
189
forwardAccAddress , _ := sdk .AccAddressFromBech32 (forwardRelayer )
154
190
forwardRelayerBal = suite .chainA .GetSimApp ().BankKeeper .GetBalance (suite .chainA .GetContext (), forwardAccAddress , sdk .DefaultBondDenom )
0 commit comments