@@ -4,11 +4,9 @@ package pfm
4
4
5
5
import (
6
6
"context"
7
- "encoding/json"
8
7
"testing"
9
8
10
9
"github.com/cosmos/interchaintest/v10/ibc"
11
- "github.com/iancoleman/orderedmap"
12
10
testifysuite "github.com/stretchr/testify/suite"
13
11
14
12
"github.com/cosmos/ibc-go/e2e/testsuite"
@@ -77,30 +75,27 @@ func (s *PFMTestSuite) TestForwardPacket() {
77
75
// From A -> B will be handled by transfer msg.
78
76
// From B -> C will be handled by firstHopMetadata.
79
77
// From C -> D will be handled by secondHopMetadata.
80
- secondHopMetadata := & pfmtypes.PacketMetadata {
81
- Forward : & pfmtypes.ForwardMetadata {
78
+ secondHopMetadata := pfmtypes.PacketMetadata {
79
+ Forward : pfmtypes.ForwardMetadata {
82
80
Receiver : userD .FormattedAddress (),
83
81
Channel : chanCD .ChannelID ,
84
82
Port : chanCD .PortID ,
85
83
},
86
84
}
87
- nextBz , err := json .Marshal (secondHopMetadata )
88
- s .Require ().NoError (err )
89
- next := pfmtypes .NewJSONObject (false , nextBz , * orderedmap .New ())
90
85
91
- firstHopMetadata := & pfmtypes.PacketMetadata {
92
- Forward : & pfmtypes.ForwardMetadata {
86
+ firstHopMetadata := pfmtypes.PacketMetadata {
87
+ Forward : pfmtypes.ForwardMetadata {
93
88
Receiver : userC .FormattedAddress (),
94
89
Channel : chanBC .ChannelID ,
95
90
Port : chanBC .PortID ,
96
- Next : next ,
91
+ Next : & secondHopMetadata ,
97
92
},
98
93
}
99
94
100
- memo , err := json . Marshal ( firstHopMetadata )
95
+ memo , err := firstHopMetadata . ToMemo ( )
101
96
s .Require ().NoError (err )
102
97
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 )
104
99
s .AssertTxSuccess (txResp )
105
100
106
101
s .FlushPackets (ctx , relayer , []ibc.Chain {chainA , chainB , chainC , chainD })
@@ -133,30 +128,27 @@ func (s *PFMTestSuite) TestForwardPacket() {
133
128
})
134
129
135
130
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 {
138
133
Receiver : userA .FormattedAddress (),
139
134
Channel : chanAB .Counterparty .ChannelID ,
140
135
Port : chanAB .Counterparty .PortID ,
141
136
},
142
137
}
143
- nextBz , err := json .Marshal (secondHopMetadata )
144
- s .Require ().NoError (err )
145
- next := pfmtypes .NewJSONObject (false , nextBz , * orderedmap .New ())
146
138
147
- firstHopMetadata := & pfmtypes.PacketMetadata {
148
- Forward : & pfmtypes.ForwardMetadata {
139
+ firstHopMetadata := pfmtypes.PacketMetadata {
140
+ Forward : pfmtypes.ForwardMetadata {
149
141
Receiver : userB .FormattedAddress (),
150
142
Channel : chanBC .Counterparty .ChannelID ,
151
143
Port : chanBC .Counterparty .PortID ,
152
- Next : next ,
144
+ Next : & secondHopMetadata ,
153
145
},
154
146
}
155
147
156
- memo , err := json . Marshal ( firstHopMetadata )
148
+ memo , err := firstHopMetadata . ToMemo ( )
157
149
s .Require ().NoError (err )
158
150
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 )
160
152
s .AssertTxSuccess (txResp )
161
153
162
154
// 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() {
186
178
})
187
179
188
180
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 {
191
183
Receiver : "GurbageAddress" ,
192
184
Channel : chanCD .ChannelID ,
193
185
Port : chanCD .PortID ,
194
186
},
195
187
}
196
- nextBz , err := json .Marshal (secondHopMetadata )
197
- s .Require ().NoError (err )
198
-
199
- next := pfmtypes .NewJSONObject (false , nextBz , * orderedmap .New ())
200
188
201
- firstHopMetadata := & pfmtypes.PacketMetadata {
202
- Forward : & pfmtypes.ForwardMetadata {
189
+ firstHopMetadata := pfmtypes.PacketMetadata {
190
+ Forward : pfmtypes.ForwardMetadata {
203
191
Receiver : userC .FormattedAddress (),
204
192
Channel : chanBC .ChannelID ,
205
193
Port : chanBC .PortID ,
206
- Next : next ,
194
+ Next : & secondHopMetadata ,
207
195
},
208
196
}
209
197
210
- memo , err := json . Marshal ( firstHopMetadata )
198
+ memo , err := firstHopMetadata . ToMemo ( )
211
199
s .Require ().NoError (err )
212
200
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 )
214
202
s .AssertTxFailure (txResp , transfertypes .ErrDenomNotFound )
215
203
216
204
// 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() {
283
271
balanceBInt , err := s .GetChainBNativeBalance (ctx , userB )
284
272
s .Require ().NoError (err )
285
273
286
- firstHopMetadata := & pfmtypes.PacketMetadata {
287
- Forward : & pfmtypes.ForwardMetadata {
274
+ firstHopMetadata := pfmtypes.PacketMetadata {
275
+ Forward : pfmtypes.ForwardMetadata {
288
276
Receiver : userA .FormattedAddress (),
289
277
Channel : chanAB .Counterparty .ChannelID ,
290
278
Port : chanAB .Counterparty .PortID ,
291
279
},
292
280
}
293
281
294
- memo , err := json . Marshal ( firstHopMetadata )
282
+ memo , err := firstHopMetadata . ToMemo ( )
295
283
s .Require ().NoError (err )
296
284
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 )
298
286
s .AssertTxSuccess (txResp )
299
287
300
288
s .FlushPackets (ctx , relayer , []ibc.Chain {chainA , chainB })
0 commit comments