Skip to content

Commit

Permalink
fix: import error
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPurohit committed Aug 15, 2024
1 parent d2deda3 commit 24ad1e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 9 additions & 1 deletion clients/libs/web/lightning-latch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
10 changes: 3 additions & 7 deletions clients/tests/web/test/tb04-simple-lightning-latch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Check failure on line 708 in clients/tests/web/test/tb04-simple-lightning-latch.test.js

View workflow job for this annotation

GitHub Actions / test

test/tb04-simple-lightning-latch.test.js > Coin receiver creates a non hold invoice, and sends to sender (i.e. an invoice with the a different payment hash). Sender should be able to determine this. > expected flow

TypeError: mercuryweblib.verifyInvoice is not a function ❯ test/tb04-simple-lightning-latch.test.js:708:52
expect(isInvoiceValid).is.false;
});
}, 50000);

0 comments on commit 24ad1e3

Please sign in to comment.