From 24ad1e307cdf4eef6b38414d34a5a23bfc6bccc1 Mon Sep 17 00:00:00 2001 From: DhananjayPurohit Date: Thu, 15 Aug 2024 15:01:47 +0530 Subject: [PATCH] fix: import error --- clients/libs/web/lightning-latch.js | 10 +++++++++- .../tests/web/test/tb04-simple-lightning-latch.test.js | 10 +++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/clients/libs/web/lightning-latch.js b/clients/libs/web/lightning-latch.js index f105890d..87c426f9 100644 --- a/clients/libs/web/lightning-latch.js +++ b/clients/libs/web/lightning-latch.js @@ -132,4 +132,12 @@ const getPaymentHash = async (clientConfig, batchId) => { } -export default { createPreImage, confirmPendingInvoice, retrievePreImage, getPaymentHash }; +const verifyInvoice = async (clientConfig, batchId, paymentRequest) => { + + const decodedInvoice = lightningPayReq.decode(paymentRequest); + let paymentHash = await getPaymentHash(clientConfig, batchId); + + return paymentHash === decodedInvoice.tagsObject.payment_hash; +} + +export default { createPreImage, confirmPendingInvoice, retrievePreImage, getPaymentHash, verifyInvoice }; diff --git a/clients/tests/web/test/tb04-simple-lightning-latch.test.js b/clients/tests/web/test/tb04-simple-lightning-latch.test.js index 78938797..fac285cd 100644 --- a/clients/tests/web/test/tb04-simple-lightning-latch.test.js +++ b/clients/tests/web/test/tb04-simple-lightning-latch.test.js @@ -280,7 +280,7 @@ describe('TB04 - Statecoin sender can recover (resend their coin) after batch ti let transferAddress2 = await mercuryweblib.newTransferAddress(wallet1.name); await mercuryweblib.transferSend(clientConfig, wallet1.name, statechainId1, transferAddress1.transfer_receive, false, paymentHash1.batchId ); - await mercuryweblib.transferSend(clientConfig, wallet2.name, statechainId2, transferAddress2.transfer_receive, false, paymentHash2.batchId); + await mercuryweblib.transferSend(clientConfig, wallet2.name, statechainId2, transferAddress2.transfer_receive, false, paymentHash1.batchId); let transferReceive = await mercuryweblib.transferReceive(clientConfig, wallet2.name); @@ -552,7 +552,7 @@ describe('Statecoin sender sends coin without batch_id (receiver should still be let transferReceive = await mercuryweblib.transferReceive(clientConfig, wallet2.name); - expect(transferReceive.isThereBatchLocked).toBe(true); + expect(transferReceive.isThereBatchLocked).toBe(false); await mercuryweblib.confirmPendingInvoice(clientConfig, wallet1.name, statechainId); @@ -645,10 +645,6 @@ describe('TB04 - Sender sends coin without batch_id, and then resends to a diffe expect(transferReceive.isThereBatchLocked).toBe(false); - let toAddress = "bcrt1q805t9k884s5qckkxv7l698hqlz7t6alsfjsqym"; - - await mercuryweblib.withdrawCoin(clientConfig, wallet2.name, statechainId, toAddress, null, null); - try { const { preimage } = await mercuryweblib.retrievePreImage(clientConfig, wallet1.name, statechainId, paymentHash.batchId); } catch (error) { @@ -709,7 +705,7 @@ describe('Coin receiver creates a non hold invoice, and sends to sender (i.e. an const paymentHashSecond = "b4eab5e663aebe5fc645865b27b33c04c4e057e7c844fa61519df6de1398cdb3" const invoiceSecond = await generateInvoice(paymentHashSecond, amount); - const isInvoiceValid = await mercurynodejslib.verifyInvoice(clientConfig, paymentHash.batchId, invoiceSecond.payment_request); + const isInvoiceValid = await mercuryweblib.verifyInvoice(clientConfig, paymentHash.batchId, invoiceSecond.payment_request); expect(isInvoiceValid).is.false; }); }, 50000);