@@ -63,6 +63,23 @@ func TestValidateOptions(t *testing.T) {
63
63
})
64
64
}
65
65
66
+ func TestBuildPayments (t * testing.T ) {
67
+ dest := "ABCD"
68
+ operations := []txnbuild.Operation {
69
+ & txnbuild.Payment {
70
+ Destination : dest ,
71
+ Amount : "1.0" ,
72
+ Asset : txnbuild.NativeAsset {},
73
+ },
74
+ }
75
+ src := "EFGH"
76
+ payments , error := buildPayments (src , operations )
77
+ assert .Empty (t , error )
78
+ assert .Equal (t , src , payments [0 ].(* txnbuild.Payment ).SourceAccount )
79
+ assert .Equal (t , dest , payments [0 ].(* txnbuild.Payment ).Destination )
80
+ assert .Equal (t , txnbuild.NativeAsset {}, payments [0 ].(* txnbuild.Payment ).Asset )
81
+ }
82
+
66
83
func TestSignAndBuildNewFeeBumpTransaction (t * testing.T ) {
67
84
distributionAccountSignatureClient := signing.SignatureClientMock {}
68
85
defer distributionAccountSignatureClient .AssertExpectations (t )
@@ -115,7 +132,31 @@ func TestSignAndBuildNewFeeBumpTransaction(t *testing.T) {
115
132
assert .Equal (t , "getting channel account details from horizon: horizon down" , err .Error ())
116
133
})
117
134
118
- t .Run ("horizon_client_sign_stellar_transaction_w_channel_account_err" , func (t * testing.T ) {
135
+ t .Run ("distribution_account_signature_client_get_account_public_key_err" , func (t * testing.T ) {
136
+ channelAccount := keypair .MustRandom ()
137
+ channelAccountSignatureClient .
138
+ On ("GetAccountPublicKey" , context .Background ()).
139
+ Return (channelAccount .Address (), nil ).
140
+ Once ()
141
+
142
+ distributionAccountSignatureClient .
143
+ On ("GetAccountPublicKey" , context .Background ()).
144
+ Return ("" , errors .New ("client down" )).
145
+ Once ()
146
+
147
+ horizonClient .
148
+ On ("AccountDetail" , horizonclient.AccountRequest {
149
+ AccountID : channelAccount .Address (),
150
+ }).
151
+ Return (horizon.Account {AccountID : channelAccount .Address (), Sequence : 1 }, nil ).
152
+ Once ()
153
+
154
+ feeBumpTx , err := txService .SignAndBuildNewFeeBumpTransaction (context .Background (), txStr )
155
+ assert .Empty (t , feeBumpTx )
156
+ assert .Equal (t , "getting distribution account public key: client down" , err .Error ())
157
+ })
158
+
159
+ t .Run ("sign_stellar_transaction_w_channel_account_err" , func (t * testing.T ) {
119
160
channelAccount := keypair .MustRandom ()
120
161
channelAccountSignatureClient .
121
162
On ("GetAccountPublicKey" , context .Background ()).
@@ -124,6 +165,11 @@ func TestSignAndBuildNewFeeBumpTransaction(t *testing.T) {
124
165
On ("SignStellarTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.Transaction" ), []string {channelAccount .Address ()}).
125
166
Return (nil , errors .New ("unable to sign" )).
126
167
Once ()
168
+ distributionAccount := keypair .MustRandom ()
169
+ distributionAccountSignatureClient .
170
+ On ("GetAccountPublicKey" , context .Background ()).
171
+ Return (distributionAccount .Address (), nil ).
172
+ Once ()
127
173
128
174
horizonClient .
129
175
On ("AccountDetail" , horizonclient.AccountRequest {
@@ -137,20 +183,24 @@ func TestSignAndBuildNewFeeBumpTransaction(t *testing.T) {
137
183
assert .Equal (t , "signing transaction with channel account: unable to sign" , err .Error ())
138
184
})
139
185
140
- t .Run ("distribution_account_signature_client_get_account_public_key_err " , func (t * testing.T ) {
186
+ t .Run ("sign_stellar_transaction_w_distribition_account_err " , func (t * testing.T ) {
141
187
channelAccount := keypair .MustRandom ()
142
- signedTx := txnbuild. Transaction {}
188
+ signedTx := utils . BuildTestTransaction ()
143
189
channelAccountSignatureClient .
144
190
On ("GetAccountPublicKey" , context .Background ()).
145
191
Return (channelAccount .Address (), nil ).
146
192
Once ().
147
193
On ("SignStellarTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.Transaction" ), []string {channelAccount .Address ()}).
148
- Return (& signedTx , nil ).
194
+ Return (signedTx , nil ).
149
195
Once ()
150
196
197
+ distributionAccount := keypair .MustRandom ()
151
198
distributionAccountSignatureClient .
152
199
On ("GetAccountPublicKey" , context .Background ()).
153
- Return ("" , errors .New ("client down" )).
200
+ Return (distributionAccount .Address (), nil ).
201
+ Once ().
202
+ On ("SignStellarTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.Transaction" ), []string {distributionAccount .Address ()}).
203
+ Return (nil , errors .New ("unable to sign" )).
154
204
Once ()
155
205
156
206
horizonClient .
@@ -162,33 +212,36 @@ func TestSignAndBuildNewFeeBumpTransaction(t *testing.T) {
162
212
163
213
feeBumpTx , err := txService .SignAndBuildNewFeeBumpTransaction (context .Background (), txStr )
164
214
assert .Empty (t , feeBumpTx )
165
- assert .Equal (t , "getting distribution account public key: client down " , err .Error ())
215
+ assert .Equal (t , "signing transaction with distribution account: unable to sign " , err .Error ())
166
216
})
167
217
168
- t .Run ("horizon_client_sign_stellar_transaction_w_distribition_account_err " , func (t * testing.T ) {
169
- account := keypair .MustRandom ()
218
+ t .Run ("sign_feebump_transaction_w_distribition_account_err " , func (t * testing.T ) {
219
+ channelAccount := keypair .MustRandom ()
170
220
signedTx := utils .BuildTestTransaction ()
171
221
channelAccountSignatureClient .
172
222
On ("GetAccountPublicKey" , context .Background ()).
173
- Return (account .Address (), nil ).
223
+ Return (channelAccount .Address (), nil ).
174
224
Once ().
175
- On ("SignStellarTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.Transaction" ), []string {account .Address ()}).
225
+ On ("SignStellarTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.Transaction" ), []string {channelAccount .Address ()}).
176
226
Return (signedTx , nil ).
177
227
Once ()
178
228
229
+ distributionAccount := keypair .MustRandom ()
179
230
distributionAccountSignatureClient .
180
231
On ("GetAccountPublicKey" , context .Background ()).
181
- Return (account .Address (), nil ).
232
+ Return (distributionAccount .Address (), nil ).
182
233
Once ().
234
+ On ("SignStellarTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.Transaction" ), []string {distributionAccount .Address ()}).
235
+ Return (signedTx , nil ).
183
236
On ("SignStellarFeeBumpTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.FeeBumpTransaction" )).
184
237
Return (nil , errors .New ("unable to sign" )).
185
238
Once ()
186
239
187
240
horizonClient .
188
241
On ("AccountDetail" , horizonclient.AccountRequest {
189
- AccountID : account .Address (),
242
+ AccountID : channelAccount .Address (),
190
243
}).
191
- Return (horizon.Account {AccountID : account .Address (), Sequence : 1 }, nil ).
244
+ Return (horizon.Account {AccountID : channelAccount .Address (), Sequence : 1 }, nil ).
192
245
Once ()
193
246
194
247
feeBumpTx , err := txService .SignAndBuildNewFeeBumpTransaction (context .Background (), txStr )
@@ -197,36 +250,39 @@ func TestSignAndBuildNewFeeBumpTransaction(t *testing.T) {
197
250
})
198
251
199
252
t .Run ("returns_signed_tx" , func (t * testing.T ) {
200
- account := keypair .MustRandom ()
253
+ channelAccount := keypair .MustRandom ()
201
254
signedTx := utils .BuildTestTransaction ()
202
255
testFeeBumpTx , _ := txnbuild .NewFeeBumpTransaction (
203
256
txnbuild.FeeBumpTransactionParams {
204
257
Inner : signedTx ,
205
- FeeAccount : account .Address (),
258
+ FeeAccount : channelAccount .Address (),
206
259
BaseFee : int64 (100 ),
207
260
},
208
261
)
209
262
channelAccountSignatureClient .
210
263
On ("GetAccountPublicKey" , context .Background ()).
211
- Return (account .Address (), nil ).
264
+ Return (channelAccount .Address (), nil ).
212
265
Once ().
213
- On ("SignStellarTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.Transaction" ), []string {account .Address ()}).
266
+ On ("SignStellarTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.Transaction" ), []string {channelAccount .Address ()}).
214
267
Return (signedTx , nil ).
215
268
Once ()
216
269
270
+ distributionAccount := keypair .MustRandom ()
217
271
distributionAccountSignatureClient .
218
272
On ("GetAccountPublicKey" , context .Background ()).
219
- Return (account .Address (), nil ).
273
+ Return (distributionAccount .Address (), nil ).
220
274
Once ().
275
+ On ("SignStellarTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.Transaction" ), []string {distributionAccount .Address ()}).
276
+ Return (signedTx , nil ).
221
277
On ("SignStellarFeeBumpTransaction" , context .Background (), mock .AnythingOfType ("*txnbuild.FeeBumpTransaction" )).
222
278
Return (testFeeBumpTx , nil ).
223
279
Once ()
224
280
225
281
horizonClient .
226
282
On ("AccountDetail" , horizonclient.AccountRequest {
227
- AccountID : account .Address (),
283
+ AccountID : channelAccount .Address (),
228
284
}).
229
- Return (horizon.Account {AccountID : account .Address (), Sequence : 1 }, nil ).
285
+ Return (horizon.Account {AccountID : channelAccount .Address (), Sequence : 1 }, nil ).
230
286
Once ()
231
287
232
288
feeBumpTx , err := txService .SignAndBuildNewFeeBumpTransaction (context .Background (), txStr )
0 commit comments