@@ -37,17 +37,38 @@ func (suite *TransferTestSuite) SetupTest() {
37
37
// 2 - from chainB to chainC
38
38
// 3 - from chainC to chainB
39
39
func (suite * TransferTestSuite ) TestHandleMsgTransfer () {
40
- testCases := []struct {
41
- name string
40
+ var (
42
41
sourceDenomsToTransfer []string
42
+ msgAmount sdkmath.Int
43
+ )
44
+
45
+ testCases := []struct {
46
+ name string
47
+ malleate func ()
43
48
}{
44
49
{
45
50
"transfer single denom" ,
46
- []string {sdk .DefaultBondDenom },
51
+ func () {},
52
+ },
53
+ {
54
+ "transfer amount larger than int64" ,
55
+ func () {
56
+ var ok bool
57
+ msgAmount , ok = sdkmath .NewIntFromString ("9223372036854775808" ) // 2^63 (one above int64)
58
+ suite .Require ().True (ok )
59
+ },
47
60
},
48
61
{
49
62
"transfer multiple denoms" ,
50
- []string {sdk .DefaultBondDenom , ibctesting .SecondaryDenom },
63
+ func () {
64
+ sourceDenomsToTransfer = []string {sdk .DefaultBondDenom , ibctesting .SecondaryDenom }
65
+ },
66
+ },
67
+ {
68
+ "transfer entire balance" ,
69
+ func () {
70
+ msgAmount = types .UnboundedSpendLimit ()
71
+ },
51
72
},
52
73
}
53
74
@@ -63,19 +84,22 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() {
63
84
pathAToB .Setup ()
64
85
traceAToB := types .NewHop (pathAToB .EndpointB .ChannelConfig .PortID , pathAToB .EndpointB .ChannelID )
65
86
87
+ sourceDenomsToTransfer = []string {sdk .DefaultBondDenom }
88
+ msgAmount = ibctesting .DefaultCoinAmount
89
+
90
+ tc .malleate ()
91
+
66
92
originalBalances := sdk .NewCoins ()
67
- for _ , denom := range tc . sourceDenomsToTransfer {
93
+ for _ , denom := range sourceDenomsToTransfer {
68
94
originalBalance := suite .chainA .GetSimApp ().BankKeeper .GetBalance (suite .chainA .GetContext (), suite .chainA .SenderAccount .GetAddress (), denom )
69
95
originalBalances = originalBalances .Add (originalBalance )
70
96
}
71
97
72
98
timeoutHeight := clienttypes .NewHeight (1 , 110 )
73
99
74
- amount , ok := sdkmath .NewIntFromString ("9223372036854775808" ) // 2^63 (one above int64)
75
- suite .Require ().True (ok )
76
100
originalCoins := sdk .NewCoins ()
77
- for _ , denom := range tc . sourceDenomsToTransfer {
78
- coinToSendToB := sdk .NewCoin (denom , amount )
101
+ for _ , denom := range sourceDenomsToTransfer {
102
+ coinToSendToB := sdk .NewCoin (denom , msgAmount )
79
103
originalCoins = originalCoins .Add (coinToSendToB )
80
104
}
81
105
@@ -87,6 +111,12 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() {
87
111
packet , err := ibctesting .ParsePacketFromEvents (res .Events )
88
112
suite .Require ().NoError (err )
89
113
114
+ // Get the packet data to determine the amount of tokens being transferred (needed for sending entire balance)
115
+ packetData , err := types .UnmarshalPacketData (packet .GetData (), pathAToB .EndpointA .GetChannel ().Version , "" )
116
+ suite .Require ().NoError (err )
117
+ transferAmount , ok := sdkmath .NewIntFromString (packetData .Tokens [0 ].Amount )
118
+ suite .Require ().True (ok )
119
+
90
120
// relay send
91
121
err = pathAToB .RelayPacket (packet )
92
122
suite .Require ().NoError (err ) // relay committed
@@ -96,16 +126,16 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() {
96
126
for _ , coin := range originalCoins {
97
127
// check that the balance for chainA is updated
98
128
chainABalance := suite .chainA .GetSimApp ().BankKeeper .GetBalance (suite .chainA .GetContext (), suite .chainA .SenderAccount .GetAddress (), coin .Denom )
99
- suite .Require ().Equal (originalBalances .AmountOf (coin .Denom ).Sub (amount ). Int64 (), chainABalance .Amount . Int64 ( ))
129
+ suite .Require ().True (originalBalances .AmountOf (coin .Denom ).Sub (transferAmount ). Equal ( chainABalance .Amount ))
100
130
101
131
// check that module account escrow address has locked the tokens
102
132
chainAEscrowBalance := suite .chainA .GetSimApp ().BankKeeper .GetBalance (suite .chainA .GetContext (), escrowAddress , coin .Denom )
103
- suite .Require ().Equal (coin , chainAEscrowBalance )
133
+ suite .Require ().True ( transferAmount . Equal (chainAEscrowBalance . Amount ) )
104
134
105
135
// check that voucher exists on chain B
106
136
chainBDenom := types .NewDenom (coin .Denom , traceAToB )
107
137
chainBBalance := suite .chainB .GetSimApp ().BankKeeper .GetBalance (suite .chainB .GetContext (), suite .chainB .SenderAccount .GetAddress (), chainBDenom .IBCDenom ())
108
- coinSentFromAToB := sdk .NewCoin (chainBDenom .IBCDenom (), amount )
138
+ coinSentFromAToB := sdk .NewCoin (chainBDenom .IBCDenom (), transferAmount )
109
139
suite .Require ().Equal (coinSentFromAToB , chainBBalance )
110
140
111
141
coinsSentFromAToB = coinsSentFromAToB .Add (coinSentFromAToB )
@@ -137,7 +167,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() {
137
167
chainCDenom := types .NewDenom (coin .Denom , traceBToC , traceAToB )
138
168
139
169
// check that the balance is updated on chainC
140
- coinSentFromBToC := sdk .NewCoin (chainCDenom .IBCDenom (), amount )
170
+ coinSentFromBToC := sdk .NewCoin (chainCDenom .IBCDenom (), transferAmount )
141
171
chainCBalance := suite .chainC .GetSimApp ().BankKeeper .GetBalance (suite .chainC .GetContext (), suite .chainC .SenderAccount .GetAddress (), coinSentFromBToC .Denom )
142
172
suite .Require ().Equal (coinSentFromBToC , chainCBalance )
143
173
@@ -182,12 +212,12 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() {
182
212
for _ , coin := range originalCoins {
183
213
// check that the balance is unchanged
184
214
chainABalance := suite .chainA .GetSimApp ().BankKeeper .GetBalance (suite .chainA .GetContext (), suite .chainA .SenderAccount .GetAddress (), coin .Denom )
185
- suite .Require ().Equal (originalBalances .AmountOf (coin .Denom ).Sub (amount ). Int64 (), chainABalance .Amount . Int64 ( ))
215
+ suite .Require ().True (originalBalances .AmountOf (coin .Denom ).Sub (transferAmount ). Equal ( chainABalance .Amount ))
186
216
187
217
// check that module account escrow address is unchanged
188
218
escrowAddress = types .GetEscrowAddress (pathAToB .EndpointA .ChannelConfig .PortID , pathAToB .EndpointA .ChannelID )
189
219
chainAEscrowBalance := suite .chainA .GetSimApp ().BankKeeper .GetBalance (suite .chainA .GetContext (), escrowAddress , coin .Denom )
190
- suite .Require ().Equal (coin , chainAEscrowBalance )
220
+ suite .Require ().True ( transferAmount . Equal (chainAEscrowBalance . Amount ) )
191
221
}
192
222
})
193
223
}
0 commit comments