Skip to content

Commit a2cd0b0

Browse files
Aman-Cooladecaro
authored andcommitted
fix(lint): resolve nlreturn and usetesting violations
- Add blank line before return in selector.go for nlreturn compliance - Replace context.Background() with t.Context() in test files - Log unlock errors instead of embedding in error message Signed-off-by: Aman-Cool <aman017102007@gmail.com>
1 parent 7df6376 commit a2cd0b0

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

token/services/interop/htlc/script_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func TestScriptAuthAmIAnAuditor(t *testing.T) {
210210

211211
func TestScriptAuthIssued(t *testing.T) {
212212
sa := htlc.NewScriptAuth(nil)
213-
require.False(t, sa.Issued(context.Background(), nil, &token3.Token{}))
213+
require.False(t, sa.Issued(t.Context(), nil, &token3.Token{}))
214214
}
215215

216216
func TestScriptAuthOwnerType(t *testing.T) {
@@ -287,21 +287,21 @@ func TestScriptAuthIsMine(t *testing.T) {
287287

288288
t.Run("sender owns token", func(t *testing.T) {
289289
sa := htlc.NewScriptAuth(stubWalletService("wallet1", ""))
290-
_, ids, mine := sa.IsMine(context.Background(), tok)
290+
_, ids, mine := sa.IsMine(t.Context(), tok)
291291
require.True(t, mine)
292292
require.Contains(t, ids, "htlc.senderwallet1")
293293
})
294294

295295
t.Run("recipient owns token", func(t *testing.T) {
296296
sa := htlc.NewScriptAuth(stubWalletService("", "wallet2"))
297-
_, ids, mine := sa.IsMine(context.Background(), tok)
297+
_, ids, mine := sa.IsMine(t.Context(), tok)
298298
require.True(t, mine)
299299
require.Contains(t, ids, "htlc.recipientwallet2")
300300
})
301301

302302
t.Run("both own token", func(t *testing.T) {
303303
sa := htlc.NewScriptAuth(stubWalletService("wallet1", "wallet2"))
304-
_, ids, mine := sa.IsMine(context.Background(), tok)
304+
_, ids, mine := sa.IsMine(t.Context(), tok)
305305
require.True(t, mine)
306306
require.Len(t, ids, 2)
307307
require.Contains(t, ids, "htlc.senderwallet1")
@@ -310,7 +310,7 @@ func TestScriptAuthIsMine(t *testing.T) {
310310

311311
t.Run("neither owns token", func(t *testing.T) {
312312
sa := htlc.NewScriptAuth(stubWalletService("", ""))
313-
_, ids, mine := sa.IsMine(context.Background(), tok)
313+
_, ids, mine := sa.IsMine(t.Context(), tok)
314314
require.False(t, mine)
315315
require.Empty(t, ids)
316316
})
@@ -321,7 +321,7 @@ func TestScriptAuthIsMineEdgeCases(t *testing.T) {
321321

322322
t.Run("invalid owner bytes", func(t *testing.T) {
323323
tok := &token3.Token{Owner: []byte("garbage"), Type: "USD", Quantity: "100"}
324-
_, _, mine := sa.IsMine(context.Background(), tok)
324+
_, _, mine := sa.IsMine(t.Context(), tok)
325325
require.False(t, mine)
326326
})
327327

@@ -331,7 +331,7 @@ func TestScriptAuthIsMineEdgeCases(t *testing.T) {
331331
Type: "USD",
332332
Quantity: "100",
333333
}
334-
_, _, mine := sa.IsMine(context.Background(), tok)
334+
_, _, mine := sa.IsMine(t.Context(), tok)
335335
require.False(t, mine)
336336
})
337337

@@ -341,13 +341,13 @@ func TestScriptAuthIsMineEdgeCases(t *testing.T) {
341341
Type: "USD",
342342
Quantity: "100",
343343
}
344-
_, _, mine := sa.IsMine(context.Background(), tok)
344+
_, _, mine := sa.IsMine(t.Context(), tok)
345345
require.False(t, mine)
346346
})
347347

348348
t.Run("nil sender and recipient", func(t *testing.T) {
349349
tok := makeHTLCToken(t, nil, nil)
350-
_, _, mine := sa.IsMine(context.Background(), tok)
350+
_, _, mine := sa.IsMine(t.Context(), tok)
351351
require.False(t, mine)
352352
})
353353
}

token/services/selector/sherdlock/selector.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,16 @@ func (s *selector) selectInternal(ctx context.Context, owner token.OwnerFilter,
162162
return nil, nil, immediateRetries, errors.Wrapf(err, "failed to get tokens for [%s:%s] - unlock: %v", owner.ID(), tokenType, err2)
163163
} else if t == nil {
164164
if !tokensLockedByOthersExist {
165-
err2 := s.locker.UnlockAll(ctx)
165+
if err2 := s.locker.UnlockAll(ctx); err2 != nil {
166+
s.logger.Warnf("failed to unlock tokens on insufficient funds: %v", err2)
167+
}
168+
166169
return nil, nil, immediateRetries, errors.Wrapf(
167170
token.SelectorInsufficientFunds,
168-
"insufficient funds, only [%s] tokens of type [%s] are available, but [%s] were requested and no other process has any tokens locked - unlock: %v",
171+
"insufficient funds, only [%s] tokens of type [%s] are available, but [%s] were requested and no other process has any tokens locked",
169172
sum.Decimal(),
170173
tokenType,
171174
quantity.Decimal(),
172-
err2,
173175
)
174176
}
175177

token/services/selector/sherdlock/selector_shutdown_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestStubbornSelector_ContextCancellation(t *testing.T) {
5656
)
5757

5858
// 50 ms is far shorter than time.Hour backoff — ctx.Done() fires first.
59-
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
59+
ctx, cancel := context.WithTimeout(t.Context(), 50*time.Millisecond)
6060
defer cancel()
6161

6262
_, _, err := sel.Select(ctx, &ownerFilter{id: "wallet1"}, "100", "USD")

0 commit comments

Comments
 (0)