@@ -34,6 +34,24 @@ class PaymentsDbTestsCommon : EclairTestSuite() {
3434 assertEquals(pending.copy(received = IncomingPayment .Received (200_000 .msat, IncomingPayment .ReceivedWith .LightningPayment , 110 )), received)
3535 }
3636
37+ @Test
38+ fun `add and receive incoming payments` () = runSuspendTest {
39+ val db = InMemoryPaymentsDb ()
40+ val preimage = randomBytes32()
41+ val channelId = randomBytes32()
42+ val amount = MilliSatoshi (50_000_000 )
43+ val origin = IncomingPayment .Origin .SwapIn (" 1PwLgmRdDjy5GAKWyp8eyAC4SFzWuboLLb" )
44+ val receivedWith = IncomingPayment .ReceivedWith .NewChannel (fees = MilliSatoshi (1234 ), channelId = channelId)
45+ assertNull(db.getIncomingPayment(randomBytes32()))
46+
47+ db.addAndReceivePayment(preimage = preimage, origin = origin, amount = amount, receivedWith = receivedWith)
48+ val payment = db.getIncomingPayment(Crypto .sha256(preimage).toByteVector32())
49+ assertNotNull(payment)
50+ assertEquals(origin, payment.origin)
51+ assertNotNull(payment.received)
52+ assertEquals(receivedWith, payment.received?.receivedWith)
53+ }
54+
3755 @Test
3856 fun `reject duplicate payment hash` () = runSuspendTest {
3957 val (db, preimage, pr) = createFixture()
@@ -73,7 +91,7 @@ class PaymentsDbTestsCommon : EclairTestSuite() {
7391
7492 val preimage2 = randomBytes32()
7593 val received2 = createInvoice(preimage2)
76- db.addIncomingPayment(preimage2, IncomingPayment .Origin .SwapIn (150_000 .msat, " 1PwLgmRdDjy5GAKWyp8eyAC4SFzWuboLLb" , received2 ))
94+ db.addIncomingPayment(preimage2, IncomingPayment .Origin .SwapIn (" 1PwLgmRdDjy5GAKWyp8eyAC4SFzWuboLLb" ))
7795 db.receivePayment(received2.paymentHash, 180_000 .msat, IncomingPayment .ReceivedWith .NewChannel (100 .msat, channelId = null ), 60 )
7896 val payment2 = db.getIncomingPayment(received2.paymentHash)!!
7997
@@ -279,7 +297,7 @@ class PaymentsDbTestsCommon : EclairTestSuite() {
279297
280298 val (preimage1, preimage2, preimage3, preimage4) = listOf (randomBytes32(), randomBytes32(), randomBytes32(), randomBytes32())
281299 val incoming1 = IncomingPayment (preimage1, IncomingPayment .Origin .Invoice (createInvoice(preimage1)), null , createdAt = 20 )
282- val incoming2 = IncomingPayment (preimage2, IncomingPayment .Origin .SwapIn (20_000 .msat, " 1PwLgmRdDjy5GAKWyp8eyAC4SFzWuboLLb" , null ), null , createdAt = 21 )
300+ val incoming2 = IncomingPayment (preimage2, IncomingPayment .Origin .SwapIn (" 1PwLgmRdDjy5GAKWyp8eyAC4SFzWuboLLb" ), null , createdAt = 21 )
283301 val incoming3 = IncomingPayment (preimage3, IncomingPayment .Origin .Invoice (createInvoice(preimage3)), null , createdAt = 22 )
284302 val incoming4 = IncomingPayment (preimage4, IncomingPayment .Origin .Invoice (createInvoice(preimage4)), null , createdAt = 23 )
285303 listOf (incoming1, incoming2, incoming3, incoming4).forEach { db.addIncomingPayment(it.preimage, it.origin, it.createdAt) }
0 commit comments