@@ -3,6 +3,7 @@ package keeper_test
33import (
44 "bytes"
55 "context"
6+ "encoding/hex"
67 "fmt"
78 "testing"
89 "time"
@@ -21,6 +22,7 @@ import (
2122 clienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
2223 channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types"
2324 ibctesting "github.com/cosmos/ibc-go/v10/testing"
25+ ibcmock "github.com/cosmos/ibc-go/v10/testing/mock"
2426)
2527
2628type KeeperTestSuite struct {
@@ -161,70 +163,100 @@ func (s *KeeperTestSuite) TestWriteAcknowledgementForForwardedPacket() {
161163}
162164
163165func (s * KeeperTestSuite ) TestForwardTransferPacket () {
164- s .SetupTest ()
165- path := ibctesting .NewTransferPath (s .chainA , s .chainB )
166- path .Setup ()
167-
168- pfmKeeper := keeper .NewKeeper (s .chainA .GetSimApp ().AppCodec (), runtime .NewKVStoreService (s .chainA .GetSimApp ().GetKey (pfmtypes .StoreKey )), & transferMock {}, s .chainA .GetSimApp ().IBCKeeper .ChannelKeeper , s .chainA .GetSimApp ().BankKeeper , "authority" )
166+ var (
167+ pfmKeeper * keeper.Keeper
168+ initialSender string
169+ finalReceiver string
170+ )
171+ tests := []struct {
172+ name string
173+ malleate func ()
174+ }{
175+ {
176+ name : "success: standard cosmos address" ,
177+ malleate : func () {},
178+ },
179+ {
180+ name : "success: with hex address codec" ,
181+ malleate : func () {
182+ pfmKeeper = keeper .NewKeeper (s .chainA .GetSimApp ().AppCodec (), ibcmock.TestAddressCodec {}, runtime .NewKVStoreService (s .chainA .GetSimApp ().GetKey (pfmtypes .StoreKey )), & transferMock {}, s .chainA .GetSimApp ().IBCKeeper .ChannelKeeper , s .chainA .GetSimApp ().BankKeeper , "authority" )
169183
170- ctx := s .chainA .GetContext ()
171- srcPacket := channeltypes.Packet {
172- Data : []byte {1 },
173- Sequence : 1 ,
174- SourcePort : path .EndpointA .ChannelConfig .PortID ,
175- SourceChannel : path .EndpointA .ChannelID ,
176- DestinationPort : path .EndpointB .ChannelConfig .PortID ,
177- DestinationChannel : path .EndpointB .ChannelID ,
178- TimeoutHeight : clienttypes.Height {
179- RevisionNumber : 10 ,
180- RevisionHeight : 100 ,
184+ initialSender = hex .EncodeToString (s .chainA .SenderAccount .GetAddress ().Bytes ())
185+ finalReceiver = hex .EncodeToString (s .chainB .SenderAccount .GetAddress ().Bytes ())
186+ },
181187 },
182- TimeoutTimestamp : 10101001 ,
183188 }
184189
185- retries := uint8 (2 )
186- timeout := time .Duration (1010101010 )
187- nonRefundable := false
190+ for _ , tc := range tests {
191+ s .Run (tc .name , func () {
192+ s .SetupTest ()
193+ path := ibctesting .NewTransferPath (s .chainA , s .chainB )
194+ path .Setup ()
188195
189- metadata := pfmtypes.ForwardMetadata {
190- Receiver : "first-receiver" ,
191- Port : path .EndpointA .ChannelConfig .PortID ,
192- Channel : path .EndpointA .ChannelID ,
193- Timeout : timeout ,
194- Retries : & retries ,
195- Next : nil ,
196- }
196+ pfmKeeper = keeper .NewKeeper (s .chainA .GetSimApp ().AppCodec (), s .chainA .GetSimApp ().AccountKeeper .AddressCodec (), runtime .NewKVStoreService (s .chainA .GetSimApp ().GetKey (pfmtypes .StoreKey )), & transferMock {}, s .chainA .GetSimApp ().IBCKeeper .ChannelKeeper , s .chainA .GetSimApp ().BankKeeper , "authority" )
197197
198- initialSender := s .chainA .SenderAccount .GetAddress ()
199- finalReceiver := s .chainB .SenderAccount .GetAddress ()
198+ ctx := s .chainA .GetContext ()
199+ srcPacket := channeltypes.Packet {
200+ Data : []byte {1 },
201+ Sequence : 1 ,
202+ SourcePort : path .EndpointA .ChannelConfig .PortID ,
203+ SourceChannel : path .EndpointA .ChannelID ,
204+ DestinationPort : path .EndpointB .ChannelConfig .PortID ,
205+ DestinationChannel : path .EndpointB .ChannelID ,
206+ TimeoutHeight : clienttypes.Height {
207+ RevisionNumber : 10 ,
208+ RevisionHeight : 100 ,
209+ },
210+ TimeoutTimestamp : 10101001 ,
211+ }
200212
201- err := pfmKeeper .ForwardTransferPacket (ctx , nil , srcPacket , initialSender .String (), finalReceiver .String (), metadata , sdk .NewInt64Coin ("denom" , 1000 ), 2 , timeout , nil , nonRefundable )
202- s .Require ().NoError (err )
213+ retries := uint8 (2 )
214+ timeout := time .Duration (1010101010 )
215+ nonRefundable := false
203216
204- // Get the inflight packer
205- inflightPacket , err := pfmKeeper .GetInflightPacket (ctx , srcPacket )
206- s .Require ().NoError (err )
217+ metadata := pfmtypes.ForwardMetadata {
218+ Receiver : "first-receiver" ,
219+ Port : path .EndpointA .ChannelConfig .PortID ,
220+ Channel : path .EndpointA .ChannelID ,
221+ Timeout : timeout ,
222+ Retries : & retries ,
223+ Next : nil ,
224+ }
207225
208- s .Require ().Equal (inflightPacket .RetriesRemaining , int32 (retries ))
226+ initialSender = s .chainA .SenderAccount .GetAddress ().String ()
227+ finalReceiver = s .chainB .SenderAccount .GetAddress ().String ()
209228
210- // Call the same function again with inflight packet. Num retries should decrease.
211- err = pfmKeeper .ForwardTransferPacket (ctx , inflightPacket , srcPacket , initialSender .String (), finalReceiver .String (), metadata , sdk .NewInt64Coin ("denom" , 1000 ), 2 , timeout , nil , nonRefundable )
212- s .Require ().NoError (err )
229+ tc .malleate ()
213230
214- // Get the inflight packer
215- inflightPacket2 , err := pfmKeeper .GetInflightPacket (ctx , srcPacket )
216- s .Require ().NoError (err )
231+ err := pfmKeeper .ForwardTransferPacket (ctx , nil , srcPacket , initialSender , finalReceiver , metadata , sdk .NewInt64Coin ("denom" , 1000 ), 2 , timeout , nil , nonRefundable )
232+ s .Require ().NoError (err )
217233
218- s .Require ().Equal (inflightPacket .RetriesRemaining , inflightPacket2 .RetriesRemaining )
219- s .Require ().Equal (int32 (retries - 1 ), inflightPacket .RetriesRemaining )
234+ // Get the inflight packer
235+ inflightPacket , err := pfmKeeper .GetInflightPacket (ctx , srcPacket )
236+ s .Require ().NoError (err )
237+
238+ s .Require ().Equal (inflightPacket .RetriesRemaining , int32 (retries ))
239+
240+ // Call the same function again with inflight packet. Num retries should decrease.
241+ err = pfmKeeper .ForwardTransferPacket (ctx , inflightPacket , srcPacket , initialSender , finalReceiver , metadata , sdk .NewInt64Coin ("denom" , 1000 ), 2 , timeout , nil , nonRefundable )
242+ s .Require ().NoError (err )
243+
244+ // Get the inflight packer
245+ inflightPacket2 , err := pfmKeeper .GetInflightPacket (ctx , srcPacket )
246+ s .Require ().NoError (err )
247+
248+ s .Require ().Equal (inflightPacket .RetriesRemaining , inflightPacket2 .RetriesRemaining )
249+ s .Require ().Equal (int32 (retries - 1 ), inflightPacket .RetriesRemaining )
250+ })
251+ }
220252}
221253
222254func (s * KeeperTestSuite ) TestForwardTransferPacketWithNext () {
223255 s .SetupTest ()
224256 path := ibctesting .NewTransferPath (s .chainA , s .chainB )
225257 path .Setup ()
226258
227- pfmKeeper := keeper .NewKeeper (s .chainA .GetSimApp ().AppCodec (), runtime .NewKVStoreService (s .chainA .GetSimApp ().GetKey (pfmtypes .StoreKey )), & transferMock {}, s .chainA .GetSimApp ().IBCKeeper .ChannelKeeper , s .chainA .GetSimApp ().BankKeeper , "authority" )
259+ pfmKeeper := keeper .NewKeeper (s .chainA .GetSimApp ().AppCodec (), s . chainA . GetSimApp (). AccountKeeper . AddressCodec (), runtime .NewKVStoreService (s .chainA .GetSimApp ().GetKey (pfmtypes .StoreKey )), & transferMock {}, s .chainA .GetSimApp ().IBCKeeper .ChannelKeeper , s .chainA .GetSimApp ().BankKeeper , "authority" )
228260 ctx := s .chainA .GetContext ()
229261 srcPacket := channeltypes.Packet {
230262 Data : []byte {1 },
@@ -283,7 +315,7 @@ func (s *KeeperTestSuite) TestRetryTimeoutErrorGettingNext() {
283315 path := ibctesting .NewTransferPath (s .chainA , s .chainB )
284316 path .Setup ()
285317
286- pfmKeeper := keeper .NewKeeper (s .chainA .GetSimApp ().AppCodec (), runtime .NewKVStoreService (s .chainA .GetSimApp ().GetKey (pfmtypes .StoreKey )), & transferMock {}, s .chainA .GetSimApp ().IBCKeeper .ChannelKeeper , s .chainA .GetSimApp ().BankKeeper , "authority" )
318+ pfmKeeper := keeper .NewKeeper (s .chainA .GetSimApp ().AppCodec (), s . chainA . GetSimApp (). AccountKeeper . AddressCodec (), runtime .NewKVStoreService (s .chainA .GetSimApp ().GetKey (pfmtypes .StoreKey )), & transferMock {}, s .chainA .GetSimApp ().IBCKeeper .ChannelKeeper , s .chainA .GetSimApp ().BankKeeper , "authority" )
287319 ctx := s .chainA .GetContext ()
288320
289321 // Create a transfer detail with invalid memo that will cause GetPacketMetadataFromPacketdata to fail
0 commit comments