Skip to content

Commit d543390

Browse files
committed
paymentsdb: refactor test helpers
1 parent 2ad5a2e commit d543390

File tree

2 files changed

+61
-107
lines changed

2 files changed

+61
-107
lines changed

payments/db/kv_store_test.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,14 @@ func TestKVStoreDeleteDuplicatePayments(t *testing.T) {
3535
paymentDB := NewKVTestDB(t)
3636

3737
// Create a successful payment.
38-
preimg, err := genPreimage(t)
39-
require.NoError(t, err)
38+
preimg := genPreimage(t)
4039

4140
rhash := sha256.Sum256(preimg[:])
4241
info := genPaymentCreationInfo(t, rhash)
43-
attempt, err := genAttemptWithHash(t, 0, genSessionKey(t), rhash)
44-
require.NoError(t, err)
42+
attempt := genAttemptWithHash(t, 0, genSessionKey(t), rhash)
4543

4644
// Init and settle the payment.
47-
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
45+
err := paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
4846
require.NoError(t, err, "unable to init payment")
4947

5048
_, err = paymentDB.RegisterAttempt(
@@ -279,11 +277,10 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
279277
ctx := t.Context()
280278

281279
// Generate a test payment which does not have duplicates.
282-
noDuplicates, _, err := genInfo(t)
283-
require.NoError(t, err)
280+
noDuplicates, _ := genInfo(t)
284281

285282
// Create a new payment entry in the database.
286-
err = paymentDB.InitPayment(
283+
err := paymentDB.InitPayment(
287284
ctx, noDuplicates.PaymentIdentifier, noDuplicates,
288285
)
289286
require.NoError(t, err)
@@ -295,8 +292,7 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
295292
require.NoError(t, err)
296293

297294
// Generate a test payment which we will add duplicates to.
298-
hasDuplicates, preimg, err := genInfo(t)
299-
require.NoError(t, err)
295+
hasDuplicates, preimg := genInfo(t)
300296

301297
// Create a new payment entry in the database.
302298
err = paymentDB.InitPayment(
@@ -453,8 +449,7 @@ func putDuplicatePayment(t *testing.T, duplicateBucket kvdb.RwBucket,
453449
require.NoError(t, err)
454450

455451
// Generate fake information for the duplicate payment.
456-
info, _, err := genInfo(t)
457-
require.NoError(t, err)
452+
info, _ := genInfo(t)
458453

459454
// Write the payment info to disk under the creation info key. This code
460455
// is copied rather than using serializePaymentCreationInfo to ensure
@@ -579,10 +574,6 @@ func TestKVStoreQueryPaymentsDuplicates(t *testing.T) {
579574

580575
paymentDB := NewKVTestDB(t)
581576

582-
// Initialize the payment database.
583-
paymentDB, err := NewKVStore(paymentDB.db)
584-
require.NoError(t, err)
585-
586577
// Make a preliminary query to make sure it's ok to
587578
// query when we have no payments.
588579
resp, err := paymentDB.QueryPayments(ctx, tt.query)
@@ -600,11 +591,8 @@ func TestKVStoreQueryPaymentsDuplicates(t *testing.T) {
600591

601592
for i := 0; i < nonDuplicatePayments; i++ {
602593
// Generate a test payment.
603-
info, preimg, err := genInfo(t)
604-
if err != nil {
605-
t.Fatalf("unable to create test "+
606-
"payment: %v", err)
607-
}
594+
info, preimg := genInfo(t)
595+
608596
// Override creation time to allow for testing
609597
// of CreationDateStart and CreationDateEnd.
610598
info.CreationTime = time.Unix(int64(i+1), 0)

0 commit comments

Comments
 (0)