paymentsdb: refactor test helpers

This commit is contained in:
ziggie committed 2026-02-25 08:02:26 +01:00
1 parent 995ad7e1b5
commit a861ac8d46
2 files changed
+61 -107

No files matched your search

+9 -21
View File
@@ -35,16 +35,14 @@ func TestKVStoreDeleteDuplicatePayments(t *testing.T) {
paymentDB := NewKVTestDB(t) paymentDB := NewKVTestDB(t)
// Create a successful payment. // Create a successful payment.
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimg[:]) rhash := sha256.Sum256(preimg[:])
info := genPaymentCreationInfo(t, rhash) info := genPaymentCreationInfo(t, rhash)
attempt, err := genAttemptWithHash(t, 0, genSessionKey(t), rhash) attempt := genAttemptWithHash(t, 0, genSessionKey(t), rhash)
require.NoError(t, err)
// Init and settle the payment. // Init and settle the payment.
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info) err := paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to init payment") require.NoError(t, err, "unable to init payment")
_, err = paymentDB.RegisterAttempt( _, err = paymentDB.RegisterAttempt(
@@ -279,11 +277,10 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
ctx := t.Context() ctx := t.Context()
// Generate a test payment which does not have duplicates. // Generate a test payment which does not have duplicates.
noDuplicates, _, err := genInfo(t) noDuplicates, _ := genInfo(t)
require.NoError(t, err)
// Create a new payment entry in the database. // Create a new payment entry in the database.
err = paymentDB.InitPayment( err := paymentDB.InitPayment(
ctx, noDuplicates.PaymentIdentifier, noDuplicates, ctx, noDuplicates.PaymentIdentifier, noDuplicates,
) )
require.NoError(t, err) require.NoError(t, err)
@@ -295,8 +292,7 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Generate a test payment which we will add duplicates to. // Generate a test payment which we will add duplicates to.
hasDuplicates, preimg, err := genInfo(t) hasDuplicates, preimg := genInfo(t)
require.NoError(t, err)
// Create a new payment entry in the database. // Create a new payment entry in the database.
err = paymentDB.InitPayment( err = paymentDB.InitPayment(
@@ -453,8 +449,7 @@ func putDuplicatePayment(t *testing.T, duplicateBucket kvdb.RwBucket,
require.NoError(t, err) require.NoError(t, err)
// Generate fake information for the duplicate payment. // Generate fake information for the duplicate payment.
info, _, err := genInfo(t) info, _ := genInfo(t)
require.NoError(t, err)
// Write the payment info to disk under the creation info key. This code // Write the payment info to disk under the creation info key. This code
// is copied rather than using serializePaymentCreationInfo to ensure // is copied rather than using serializePaymentCreationInfo to ensure
@@ -579,10 +574,6 @@ func TestKVStoreQueryPaymentsDuplicates(t *testing.T) {
paymentDB := NewKVTestDB(t) paymentDB := NewKVTestDB(t)
// Initialize the payment database.
paymentDB, err := NewKVStore(paymentDB.db)
require.NoError(t, err)
// Make a preliminary query to make sure it's ok to // Make a preliminary query to make sure it's ok to
// query when we have no payments. // query when we have no payments.
resp, err := paymentDB.QueryPayments(ctx, tt.query) resp, err := paymentDB.QueryPayments(ctx, tt.query)
@@ -600,11 +591,8 @@ func TestKVStoreQueryPaymentsDuplicates(t *testing.T) {
for i := 0; i < nonDuplicatePayments; i++ { for i := 0; i < nonDuplicatePayments; i++ {
// Generate a test payment. // Generate a test payment.
info, preimg, err := genInfo(t) info, preimg := genInfo(t)
if err != nil {
t.Fatalf("unable to create test "+
"payment: %v", err)
}
// Override creation time to allow for testing // Override creation time to allow for testing
// of CreationDateStart and CreationDateEnd. // of CreationDateStart and CreationDateEnd.
info.CreationTime = time.Unix(int64(i+1), 0) info.CreationTime = time.Unix(int64(i+1), 0)
+52 -86
View File
@@ -130,8 +130,7 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
attemptID := uint64(0) attemptID := uint64(0)
for i := 0; i < len(payments); i++ { for i := 0; i < len(payments); i++ {
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimg[:]) rhash := sha256.Sum256(preimg[:])
info := genPaymentCreationInfo(t, rhash) info := genPaymentCreationInfo(t, rhash)
@@ -139,15 +138,14 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
// Set the payment id accordingly in the payments slice. // Set the payment id accordingly in the payments slice.
payments[i].id = info.PaymentIdentifier payments[i].id = info.PaymentIdentifier
attempt, err := genAttemptWithHash( attempt := genAttemptWithHash(
t, attemptID, genSessionKey(t), rhash, t, attemptID, genSessionKey(t), rhash,
) )
require.NoError(t, err)
attemptID++ attemptID++
// Init the payment. // Init the payment.
err = p.InitPayment(ctx, info.PaymentIdentifier, info) err := p.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message") require.NoError(t, err, "unable to send htlc message")
// Register and fail the first attempt for all payments. // Register and fail the first attempt for all payments.
@@ -169,10 +167,9 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
// Depending on the test case, fail or succeed the next // Depending on the test case, fail or succeed the next
// attempt. // attempt.
attempt, err = genAttemptWithHash( attempt = genAttemptWithHash(
t, attemptID, genSessionKey(t), rhash, t, attemptID, genSessionKey(t), rhash,
) )
require.NoError(t, err)
attemptID++ attemptID++
_, err = p.RegisterAttempt(ctx, info.PaymentIdentifier, attempt) _, err = p.RegisterAttempt(ctx, info.PaymentIdentifier, attempt)
@@ -182,7 +179,7 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
// Fail the attempt and the payment overall. // Fail the attempt and the payment overall.
case StatusFailed: case StatusFailed:
htlcFailure := HTLCFailUnreadable htlcFailure := HTLCFailUnreadable
_, err = p.FailAttempt( _, err := p.FailAttempt(
ctx, info.PaymentIdentifier, attempt.AttemptID, ctx, info.PaymentIdentifier, attempt.AttemptID,
&HTLCFailInfo{ &HTLCFailInfo{
Reason: htlcFailure, Reason: htlcFailure,
@@ -363,15 +360,14 @@ func assertDBPayments(t *testing.T, paymentDB DB, payments []*payment) {
} }
// genPreimage generates a random preimage. // genPreimage generates a random preimage.
func genPreimage(t *testing.T) (lntypes.Preimage, error) { func genPreimage(t *testing.T) lntypes.Preimage {
t.Helper() t.Helper()
var preimage [32]byte var preimage [32]byte
if _, err := io.ReadFull(rand.Reader, preimage[:]); err != nil { _, err := io.ReadFull(rand.Reader, preimage[:])
return preimage, err require.NoError(t, err, "unable to generate preimage")
}
return preimage, nil return preimage
} }
// genSessionKey generates a new random private key for use as a session key. // genSessionKey generates a new random private key for use as a session key.
@@ -410,24 +406,22 @@ func genPaymentCreationInfo(t *testing.T,
} }
// genPreimageAndHash generates a random preimage and its corresponding hash. // genPreimageAndHash generates a random preimage and its corresponding hash.
func genPreimageAndHash(t *testing.T) (lntypes.Preimage, lntypes.Hash, error) { func genPreimageAndHash(t *testing.T) (lntypes.Preimage, lntypes.Hash) {
t.Helper() t.Helper()
preimage, err := genPreimage(t) preimage := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimage[:]) rhash := sha256.Sum256(preimage[:])
var hash lntypes.Hash var hash lntypes.Hash
copy(hash[:], rhash[:]) copy(hash[:], rhash[:])
return preimage, hash, nil return preimage, hash
} }
// genAttemptWithPreimage generates an HTLC attempt and returns both the // genAttemptWithPreimage generates an HTLC attempt and returns both the
// attempt and preimage. // attempt and preimage.
func genAttemptWithHash(t *testing.T, attemptID uint64, func genAttemptWithHash(t *testing.T, attemptID uint64,
sessionKey *btcec.PrivateKey, hash lntypes.Hash) (*HTLCAttemptInfo, sessionKey *btcec.PrivateKey, hash lntypes.Hash) *HTLCAttemptInfo {
error) {
t.Helper() t.Helper()
@@ -435,24 +429,21 @@ func genAttemptWithHash(t *testing.T, attemptID uint64,
attemptID, sessionKey, *testRoute.Copy(), time.Time{}, attemptID, sessionKey, *testRoute.Copy(), time.Time{},
&hash, &hash,
) )
if err != nil { require.NoError(t, err, "unable to generate htlc attempt")
return nil, err
}
return &attempt.HTLCAttemptInfo, nil return &attempt.HTLCAttemptInfo
} }
// genInfo generates a payment creation info and the corresponding preimage. // genInfo generates a payment creation info and the corresponding preimage.
func genInfo(t *testing.T) (*PaymentCreationInfo, lntypes.Preimage, error) { func genInfo(t *testing.T) (*PaymentCreationInfo, lntypes.Preimage) {
preimage, _, err := genPreimageAndHash(t) t.Helper()
if err != nil {
return nil, preimage, err preimage, _ := genPreimageAndHash(t)
}
rhash := sha256.Sum256(preimage[:]) rhash := sha256.Sum256(preimage[:])
creationInfo := genPaymentCreationInfo(t, rhash) creationInfo := genPaymentCreationInfo(t, rhash)
return creationInfo, preimage, nil return creationInfo, preimage
} }
// TestDeleteFailedAttempts checks that DeleteFailedAttempts properly removes // TestDeleteFailedAttempts checks that DeleteFailedAttempts properly removes
@@ -534,21 +525,19 @@ func TestMPPRecordValidation(t *testing.T) {
paymentDB, _ := NewTestDB(t) paymentDB, _ := NewTestDB(t)
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimg[:]) rhash := sha256.Sum256(preimg[:])
info := genPaymentCreationInfo(t, rhash) info := genPaymentCreationInfo(t, rhash)
attemptID := uint64(0) attemptID := uint64(0)
attempt, err := genAttemptWithHash( attempt := genAttemptWithHash(
t, attemptID, genSessionKey(t), rhash, t, attemptID, genSessionKey(t), rhash,
) )
require.NoError(t, err, "unable to generate htlc message")
// Init the payment. // Init the payment.
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info) err := paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message") require.NoError(t, err, "unable to send htlc message")
// Create three unique attempts we'll use for the test, and // Create three unique attempts we'll use for the test, and
@@ -566,10 +555,9 @@ func TestMPPRecordValidation(t *testing.T) {
// Now try to register a non-MPP attempt, which should fail. // Now try to register a non-MPP attempt, which should fail.
attemptID++ attemptID++
attempt2, err := genAttemptWithHash( attempt2 := genAttemptWithHash(
t, attemptID, genSessionKey(t), rhash, t, attemptID, genSessionKey(t), rhash,
) )
require.NoError(t, err)
attempt2.Route.FinalHop().MPP = nil attempt2.Route.FinalHop().MPP = nil
@@ -598,19 +586,15 @@ func TestMPPRecordValidation(t *testing.T) {
// Create and init a new payment. This time we'll check that we cannot // Create and init a new payment. This time we'll check that we cannot
// register an MPP attempt if we already registered a non-MPP one. // register an MPP attempt if we already registered a non-MPP one.
preimg, err = genPreimage(t) preimg = genPreimage(t)
require.NoError(t, err)
rhash = sha256.Sum256(preimg[:]) rhash = sha256.Sum256(preimg[:])
info = genPaymentCreationInfo(t, rhash) info = genPaymentCreationInfo(t, rhash)
attemptID++ attemptID++
attempt, err = genAttemptWithHash( attempt = genAttemptWithHash(
t, attemptID, genSessionKey(t), rhash, t, attemptID, genSessionKey(t), rhash,
) )
require.NoError(t, err)
require.NoError(t, err, "unable to generate htlc message")
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info) err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message") require.NoError(t, err, "unable to send htlc message")
@@ -623,10 +607,9 @@ func TestMPPRecordValidation(t *testing.T) {
// Attempt to register an MPP attempt, which should fail. // Attempt to register an MPP attempt, which should fail.
attemptID++ attemptID++
attempt2, err = genAttemptWithHash( attempt2 = genAttemptWithHash(
t, attemptID, genSessionKey(t), rhash, t, attemptID, genSessionKey(t), rhash,
) )
require.NoError(t, err)
attempt2.Route.FinalHop().MPP = record.NewMPP( attempt2.Route.FinalHop().MPP = record.NewMPP(
info.Value, [32]byte{1}, info.Value, [32]byte{1},
@@ -1604,14 +1587,13 @@ func TestSuccessesWithoutInFlight(t *testing.T) {
paymentDB, _ := NewTestDB(t) paymentDB, _ := NewTestDB(t)
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimg[:]) rhash := sha256.Sum256(preimg[:])
info := genPaymentCreationInfo(t, rhash) info := genPaymentCreationInfo(t, rhash)
// Attempt to complete the payment should fail. // Attempt to complete the payment should fail.
_, err = paymentDB.SettleAttempt( _, err := paymentDB.SettleAttempt(
t.Context(), t.Context(),
info.PaymentIdentifier, 0, info.PaymentIdentifier, 0,
&HTLCSettleInfo{ &HTLCSettleInfo{
@@ -1628,14 +1610,13 @@ func TestFailsWithoutInFlight(t *testing.T) {
paymentDB, _ := NewTestDB(t) paymentDB, _ := NewTestDB(t)
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimg[:]) rhash := sha256.Sum256(preimg[:])
info := genPaymentCreationInfo(t, rhash) info := genPaymentCreationInfo(t, rhash)
// Calling Fail should return an error. // Calling Fail should return an error.
_, err = paymentDB.Fail( _, err := paymentDB.Fail(
t.Context(), info.PaymentIdentifier, FailureReasonNoRoute, t.Context(), info.PaymentIdentifier, FailureReasonNoRoute,
) )
require.ErrorIs(t, err, ErrPaymentNotInitiated) require.ErrorIs(t, err, ErrPaymentNotInitiated)
@@ -1732,15 +1713,13 @@ func TestDeleteNonInFlight(t *testing.T) {
} }
for _, p := range payments { for _, p := range payments {
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimg[:]) rhash := sha256.Sum256(preimg[:])
info := genPaymentCreationInfo(t, rhash) info := genPaymentCreationInfo(t, rhash)
attempt, err := genAttemptWithHash( attempt := genAttemptWithHash(
t, attemptID, genSessionKey(t), rhash, t, attemptID, genSessionKey(t), rhash,
) )
require.NoError(t, err)
// After generating the attempt, increment the attempt ID to // After generating the attempt, increment the attempt ID to
// have unique attempt IDs for each attempt otherwise the unique // have unique attempt IDs for each attempt otherwise the unique
@@ -1748,7 +1727,7 @@ func TestDeleteNonInFlight(t *testing.T) {
attemptID++ attemptID++
// Init payment which initiates StatusInFlight. // Init payment which initiates StatusInFlight.
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info) err := paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to init payment") require.NoError(t, err, "unable to init payment")
_, err = paymentDB.RegisterAttempt( _, err = paymentDB.RegisterAttempt(
@@ -1872,17 +1851,15 @@ func TestSwitchDoubleSend(t *testing.T) {
paymentDB, harness := NewTestDB(t) paymentDB, harness := NewTestDB(t)
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimg[:]) rhash := sha256.Sum256(preimg[:])
info := genPaymentCreationInfo(t, rhash) info := genPaymentCreationInfo(t, rhash)
attempt, err := genAttemptWithHash(t, 0, genSessionKey(t), rhash) attempt := genAttemptWithHash(t, 0, genSessionKey(t), rhash)
require.NoError(t, err)
// Sends base htlc message which initiate base status and move it to // Sends base htlc message which initiate base status and move it to
// StatusInFlight and verifies that it was changed. // StatusInFlight and verifies that it was changed.
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info) err := paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message") require.NoError(t, err, "unable to send htlc message")
harness.AssertPaymentIndex(t, info.PaymentIdentifier) harness.AssertPaymentIndex(t, info.PaymentIdentifier)
@@ -1952,16 +1929,14 @@ func TestSwitchFail(t *testing.T) {
paymentDB, harness := NewTestDB(t) paymentDB, harness := NewTestDB(t)
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimg[:]) rhash := sha256.Sum256(preimg[:])
info := genPaymentCreationInfo(t, rhash) info := genPaymentCreationInfo(t, rhash)
attempt, err := genAttemptWithHash(t, 0, genSessionKey(t), rhash) attempt := genAttemptWithHash(t, 0, genSessionKey(t), rhash)
require.NoError(t, err)
// Sends base htlc message which initiate StatusInFlight. // Sends base htlc message which initiate StatusInFlight.
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info) err := paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message") require.NoError(t, err, "unable to send htlc message")
harness.AssertPaymentIndex(t, info.PaymentIdentifier) harness.AssertPaymentIndex(t, info.PaymentIdentifier)
@@ -2036,7 +2011,7 @@ func TestSwitchFail(t *testing.T) {
assertPaymentInfo(t, paymentDB, info.PaymentIdentifier, info, nil, htlc) assertPaymentInfo(t, paymentDB, info.PaymentIdentifier, info, nil, htlc)
// Record another attempt. // Record another attempt.
attempt, err = genAttemptWithHash( attempt = genAttemptWithHash(
t, 1, genSessionKey(t), rhash, t, 1, genSessionKey(t), rhash,
) )
require.NoError(t, err) require.NoError(t, err)
@@ -2120,14 +2095,13 @@ func TestMultiShard(t *testing.T) {
runSubTest := func(t *testing.T, test testCase) { runSubTest := func(t *testing.T, test testCase) {
paymentDB, harness := NewTestDB(t) paymentDB, harness := NewTestDB(t)
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimg[:]) rhash := sha256.Sum256(preimg[:])
info := genPaymentCreationInfo(t, rhash) info := genPaymentCreationInfo(t, rhash)
// Init the payment, moving it to the StatusInFlight state. // Init the payment, moving it to the StatusInFlight state.
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info) err := paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err) require.NoError(t, err)
harness.AssertPaymentIndex(t, info.PaymentIdentifier) harness.AssertPaymentIndex(t, info.PaymentIdentifier)
@@ -2146,10 +2120,9 @@ func TestMultiShard(t *testing.T) {
var attempts []*HTLCAttemptInfo var attempts []*HTLCAttemptInfo
for i := uint64(0); i < 3; i++ { for i := uint64(0); i < 3; i++ {
a, err := genAttemptWithHash( a := genAttemptWithHash(
t, i, genSessionKey(t), rhash, t, i, genSessionKey(t), rhash,
) )
require.NoError(t, err)
a.Route.FinalHop().AmtToForward = shardAmt a.Route.FinalHop().AmtToForward = shardAmt
a.Route.FinalHop().MPP = record.NewMPP( a.Route.FinalHop().MPP = record.NewMPP(
@@ -2181,10 +2154,9 @@ func TestMultiShard(t *testing.T) {
// For a fourth attempt, check that attempting to // For a fourth attempt, check that attempting to
// register it will fail since the total sent amount // register it will fail since the total sent amount
// will be too large. // will be too large.
b, err := genAttemptWithHash( b := genAttemptWithHash(
t, 3, genSessionKey(t), rhash, t, 3, genSessionKey(t), rhash,
) )
require.NoError(t, err)
b.Route.FinalHop().AmtToForward = shardAmt b.Route.FinalHop().AmtToForward = shardAmt
b.Route.FinalHop().MPP = record.NewMPP( b.Route.FinalHop().MPP = record.NewMPP(
@@ -2290,10 +2262,9 @@ func TestMultiShard(t *testing.T) {
// Try to register yet another attempt. This should fail now // Try to register yet another attempt. This should fail now
// that the payment has reached a terminal condition. // that the payment has reached a terminal condition.
b, err = genAttemptWithHash( b = genAttemptWithHash(
t, 3, genSessionKey(t), rhash, t, 3, genSessionKey(t), rhash,
) )
require.NoError(t, err)
b.Route.FinalHop().AmtToForward = shardAmt b.Route.FinalHop().AmtToForward = shardAmt
b.Route.FinalHop().MPP = record.NewMPP( b.Route.FinalHop().MPP = record.NewMPP(
@@ -2752,8 +2723,7 @@ func TestQueryPayments(t *testing.T) {
// First, create all payments. // First, create all payments.
for i := range numberOfPayments { for i := range numberOfPayments {
// Generate a test payment. // Generate a test payment.
info, _, err := genInfo(t) info, _ := genInfo(t)
require.NoError(t, err)
// Override creation time to allow for testing // Override creation time to allow for testing
// of CreationDateStart and CreationDateEnd. // of CreationDateStart and CreationDateEnd.
@@ -2941,8 +2911,7 @@ func TestFetchInFlightPayments(t *testing.T) {
require.Contains(t, inFlightHashes, payments[3].id) require.Contains(t, inFlightHashes, payments[3].id)
// Now settle one of the in-flight payments. // Now settle one of the in-flight payments.
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
_, err = paymentDB.SettleAttempt( _, err = paymentDB.SettleAttempt(
ctx, payments[2].id, 5, ctx, payments[2].id, 5,
@@ -2974,28 +2943,25 @@ func TestFetchInFlightPaymentsMultipleAttempts(t *testing.T) {
paymentDB, _ := NewTestDB(t) paymentDB, _ := NewTestDB(t)
preimg, err := genPreimage(t) preimg := genPreimage(t)
require.NoError(t, err)
rhash := sha256.Sum256(preimg[:]) rhash := sha256.Sum256(preimg[:])
info := genPaymentCreationInfo(t, rhash) info := genPaymentCreationInfo(t, rhash)
// Init payment with double the amount to allow two attempts. // Init payment with double the amount to allow two attempts.
info.Value *= 2 info.Value *= 2
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info) err := paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err) require.NoError(t, err)
// Register two attempts for the same payment. // Register two attempts for the same payment.
attempt1, err := genAttemptWithHash(t, 0, genSessionKey(t), rhash) attempt1 := genAttemptWithHash(t, 0, genSessionKey(t), rhash)
require.NoError(t, err)
_, err = paymentDB.RegisterAttempt( _, err = paymentDB.RegisterAttempt(
ctx, info.PaymentIdentifier, attempt1, ctx, info.PaymentIdentifier, attempt1,
) )
require.NoError(t, err) require.NoError(t, err)
attempt2, err := genAttemptWithHash(t, 1, genSessionKey(t), rhash) attempt2 := genAttemptWithHash(t, 1, genSessionKey(t), rhash)
require.NoError(t, err)
_, err = paymentDB.RegisterAttempt( _, err = paymentDB.RegisterAttempt(
ctx, info.PaymentIdentifier, attempt2, ctx, info.PaymentIdentifier, attempt2,