@@ -4,11 +4,9 @@ package pfm
44
55import (
66 "context"
7- "encoding/json"
87 "testing"
98
109 "github.com/cosmos/interchaintest/v10/ibc"
11- "github.com/iancoleman/orderedmap"
1210 testifysuite "github.com/stretchr/testify/suite"
1311
1412 "github.com/cosmos/ibc-go/e2e/testsuite"
@@ -77,30 +75,27 @@ func (s *PFMTestSuite) TestForwardPacket() {
7775 // From A -> B will be handled by transfer msg.
7876 // From B -> C will be handled by firstHopMetadata.
7977 // From C -> D will be handled by secondHopMetadata.
80- secondHopMetadata := & pfmtypes.PacketMetadata {
81- Forward : & pfmtypes.ForwardMetadata {
78+ secondHopMetadata := pfmtypes.PacketMetadata {
79+ Forward : pfmtypes.ForwardMetadata {
8280 Receiver : userD .FormattedAddress (),
8381 Channel : chanCD .ChannelID ,
8482 Port : chanCD .PortID ,
8583 },
8684 }
87- nextBz , err := json .Marshal (secondHopMetadata )
88- s .Require ().NoError (err )
89- next := pfmtypes .NewJSONObject (false , nextBz , * orderedmap .New ())
9085
91- firstHopMetadata := & pfmtypes.PacketMetadata {
92- Forward : & pfmtypes.ForwardMetadata {
86+ firstHopMetadata := pfmtypes.PacketMetadata {
87+ Forward : pfmtypes.ForwardMetadata {
9388 Receiver : userC .FormattedAddress (),
9489 Channel : chanBC .ChannelID ,
9590 Port : chanBC .PortID ,
96- Next : next ,
91+ Next : & secondHopMetadata ,
9792 },
9893 }
9994
100- memo , err := json . Marshal ( firstHopMetadata )
95+ memo , err := firstHopMetadata . ToMemo ( )
10196 s .Require ().NoError (err )
10297
103- txResp := s .Transfer (ctx , chainA , userA , chanAB .PortID , chanAB .ChannelID , testvalues .DefaultTransferAmount (denomA ), userA .FormattedAddress (), userB .FormattedAddress (), s .GetTimeoutHeight (ctx , chainA ), 0 , string ( memo ) )
98+ txResp := s .Transfer (ctx , chainA , userA , chanAB .PortID , chanAB .ChannelID , testvalues .DefaultTransferAmount (denomA ), userA .FormattedAddress (), userB .FormattedAddress (), s .GetTimeoutHeight (ctx , chainA ), 0 , memo )
10499 s .AssertTxSuccess (txResp )
105100
106101 s .FlushPackets (ctx , relayer , []ibc.Chain {chainA , chainB , chainC , chainD })
@@ -133,30 +128,27 @@ func (s *PFMTestSuite) TestForwardPacket() {
133128 })
134129
135130 t .Run ("Packet forwarded [D -> C -> B -> A]" , func (_ * testing.T ) {
136- secondHopMetadata := & pfmtypes.PacketMetadata {
137- Forward : & pfmtypes.ForwardMetadata {
131+ secondHopMetadata := pfmtypes.PacketMetadata {
132+ Forward : pfmtypes.ForwardMetadata {
138133 Receiver : userA .FormattedAddress (),
139134 Channel : chanAB .Counterparty .ChannelID ,
140135 Port : chanAB .Counterparty .PortID ,
141136 },
142137 }
143- nextBz , err := json .Marshal (secondHopMetadata )
144- s .Require ().NoError (err )
145- next := pfmtypes .NewJSONObject (false , nextBz , * orderedmap .New ())
146138
147- firstHopMetadata := & pfmtypes.PacketMetadata {
148- Forward : & pfmtypes.ForwardMetadata {
139+ firstHopMetadata := pfmtypes.PacketMetadata {
140+ Forward : pfmtypes.ForwardMetadata {
149141 Receiver : userB .FormattedAddress (),
150142 Channel : chanBC .Counterparty .ChannelID ,
151143 Port : chanBC .Counterparty .PortID ,
152- Next : next ,
144+ Next : & secondHopMetadata ,
153145 },
154146 }
155147
156- memo , err := json . Marshal ( firstHopMetadata )
148+ memo , err := firstHopMetadata . ToMemo ( )
157149 s .Require ().NoError (err )
158150
159- txResp := s .Transfer (ctx , chainD , userD , chanCD .Counterparty .PortID , chanCD .Counterparty .ChannelID , testvalues .DefaultTransferAmount (ibcTokenD .IBCDenom ()), userD .FormattedAddress (), userC .FormattedAddress (), s .GetTimeoutHeight (ctx , chainD ), 0 , string ( memo ) )
151+ txResp := s .Transfer (ctx , chainD , userD , chanCD .Counterparty .PortID , chanCD .Counterparty .ChannelID , testvalues .DefaultTransferAmount (ibcTokenD .IBCDenom ()), userD .FormattedAddress (), userC .FormattedAddress (), s .GetTimeoutHeight (ctx , chainD ), 0 , memo )
160152 s .AssertTxSuccess (txResp )
161153
162154 // Flush the packet all the way back to Chain A and then the acknowledgement back to Chain D
@@ -186,31 +178,27 @@ func (s *PFMTestSuite) TestForwardPacket() {
186178 })
187179
188180 t .Run ("Error while forwarding: Refund ok [A -> B -> C ->X D]" , func (_ * testing.T ) {
189- secondHopMetadata := & pfmtypes.PacketMetadata {
190- Forward : & pfmtypes.ForwardMetadata {
181+ secondHopMetadata := pfmtypes.PacketMetadata {
182+ Forward : pfmtypes.ForwardMetadata {
191183 Receiver : "GurbageAddress" ,
192184 Channel : chanCD .ChannelID ,
193185 Port : chanCD .PortID ,
194186 },
195187 }
196- nextBz , err := json .Marshal (secondHopMetadata )
197- s .Require ().NoError (err )
198-
199- next := pfmtypes .NewJSONObject (false , nextBz , * orderedmap .New ())
200188
201- firstHopMetadata := & pfmtypes.PacketMetadata {
202- Forward : & pfmtypes.ForwardMetadata {
189+ firstHopMetadata := pfmtypes.PacketMetadata {
190+ Forward : pfmtypes.ForwardMetadata {
203191 Receiver : userC .FormattedAddress (),
204192 Channel : chanBC .ChannelID ,
205193 Port : chanBC .PortID ,
206- Next : next ,
194+ Next : & secondHopMetadata ,
207195 },
208196 }
209197
210- memo , err := json . Marshal ( firstHopMetadata )
198+ memo , err := firstHopMetadata . ToMemo ( )
211199 s .Require ().NoError (err )
212200
213- txResp := s .Transfer (ctx , chainA , userA , chanAB .PortID , chanAB .ChannelID , testvalues .DefaultTransferAmount (ibcTokenD .IBCDenom ()), userA .FormattedAddress (), userB .FormattedAddress (), s .GetTimeoutHeight (ctx , chainA ), 0 , string ( memo ) )
201+ txResp := s .Transfer (ctx , chainA , userA , chanAB .PortID , chanAB .ChannelID , testvalues .DefaultTransferAmount (ibcTokenD .IBCDenom ()), userA .FormattedAddress (), userB .FormattedAddress (), s .GetTimeoutHeight (ctx , chainA ), 0 , memo )
214202 s .AssertTxFailure (txResp , transfertypes .ErrDenomNotFound )
215203
216204 // Flush the packet all the way back to Chain D and then the acknowledgement back to Chain A
@@ -283,18 +271,18 @@ func (s *PFMTestSuite) TestForwardPacket() {
283271 balanceBInt , err := s .GetChainBNativeBalance (ctx , userB )
284272 s .Require ().NoError (err )
285273
286- firstHopMetadata := & pfmtypes.PacketMetadata {
287- Forward : & pfmtypes.ForwardMetadata {
274+ firstHopMetadata := pfmtypes.PacketMetadata {
275+ Forward : pfmtypes.ForwardMetadata {
288276 Receiver : userA .FormattedAddress (),
289277 Channel : chanAB .Counterparty .ChannelID ,
290278 Port : chanAB .Counterparty .PortID ,
291279 },
292280 }
293281
294- memo , err := json . Marshal ( firstHopMetadata )
282+ memo , err := firstHopMetadata . ToMemo ( )
295283 s .Require ().NoError (err )
296284
297- txResp := s .Transfer (ctx , chainA , userA , chanAB .PortID , chanAB .ChannelID , testvalues .DefaultTransferAmount (denomA ), userA .FormattedAddress (), userB .FormattedAddress (), s .GetTimeoutHeight (ctx , chainA ), 0 , string ( memo ) )
285+ txResp := s .Transfer (ctx , chainA , userA , chanAB .PortID , chanAB .ChannelID , testvalues .DefaultTransferAmount (denomA ), userA .FormattedAddress (), userB .FormattedAddress (), s .GetTimeoutHeight (ctx , chainA ), 0 , memo )
298286 s .AssertTxSuccess (txResp )
299287
300288 s .FlushPackets (ctx , relayer , []ibc.Chain {chainA , chainB })
0 commit comments