Skip to content

Commit

Permalink
fix: payment hash in invoice generation
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPurohit committed Aug 15, 2024
1 parent c956b8f commit 8ccf218
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@ jobs:
run: |
cd clients/libs/web
npm install
- name: Run web client Tests
run: |
cd clients/tests/web
sudo chmod -R 755 ./data_bitcoin_regtest
npx vitest --browser.name=chromium --browser.headless
- name: Run Client-Side Tests
run: |
cd clients/apps/nodejs
node test_basic_workflow2.js
node test_atomic_swap.js
mocha ./test/tb04-simple-lightning-latch.mjs --exit
- name: Run web client Tests
run: |
cd clients/tests/web
sudo chmod -R 755 ./data_bitcoin_regtest
npx vitest --browser.name=chromium --browser.headless
- name: Tear Down
run: |
docker-compose -f docker-compose-test.yml down
2 changes: 1 addition & 1 deletion clients/libs/web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const verifyInvoice = async (clientConfig, batchId, paymentRequest) => {

const decodedInvoice = await decodeInvoice(paymentRequest);
let paymentHash = await getPaymentHash(clientConfig, batchId);
console.log("Decoded Invoice: ", decodeInvoice);
console.log("Decoded Invoice: ", decodedInvoice);

return paymentHash === decodedInvoice.tagsObject.payment_hash;
}
Expand Down
6 changes: 3 additions & 3 deletions clients/tests/web/server-regtest.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ const payInvoice = async (paymentRequest) => {
await exec(payInvoiceCommand);
}

const payHoldInvoice = (paymentRequest) => {
const payHoldInvoice = async (paymentRequest) => {
const payInvoiceCommand = `docker exec $(docker ps -qf "name=mercurylayer-bob-1") lncli -n regtest payinvoice --force ${paymentRequest}`;
exec(payInvoiceCommand);
await exec(payInvoiceCommand);
}

const settleInvoice = async (preimage) => {
Expand Down Expand Up @@ -135,7 +135,7 @@ app.post('/pay_holdinvoice', async (req, res) => {
console.log(`Paying invoice ...`)

try {
payHoldInvoice(paymentRequest);
await payHoldInvoice(paymentRequest);
} catch (error) {
console.log(error.message);
res.status(500).send({ message: error.message })
Expand Down
6 changes: 3 additions & 3 deletions clients/tests/web/test/tb04-simple-lightning-latch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ describe('TB04 - Receiver tries to transfer invoice amount to another invoice be
const paymentHash = await mercuryweblib.paymentHash(clientConfig, wallet1.name, statechainId);

const invoice = await generateInvoice(paymentHash.hash, amount);
console.log(invoice);

await payHoldInvoice(invoice.payment_request);
console.log(invoice);

let transferAddress = await mercuryweblib.newTransferAddress(wallet2.name);

Expand Down Expand Up @@ -480,7 +480,7 @@ describe('TB04 - Receiver tries to transfer invoice amount to another invoice be

expect(hashPreImage).toEqual(paymentHash.hash);

const paymentHashSecond = "f768c404215f9fb5731c32c00fe7a057fc181d7695de447b334380d90674db34"
const paymentHashSecond = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
const invoiceSecond = await generateInvoice(paymentHashSecond, amount);

try {
Expand Down Expand Up @@ -696,7 +696,7 @@ describe('Coin receiver creates a non hold invoice, and sends to sender (i.e. an

const paymentHash = await mercuryweblib.paymentHash(clientConfig, wallet1.name, statechainId);

const paymentHashSecond = "ddddf1cd1e2ca1986e29b20401b555fbaa4a8502626a7afc37c47ae06a46d918"
const paymentHashSecond = "1f1e1d1c1b1a19181716151413121110100f0e0d0c0b0a09080706050403020100"
const invoiceSecond = await generateInvoice(paymentHashSecond, amount);

const isInvoiceValid = await mercuryweblib.verifyInvoice(clientConfig, paymentHash.batchId, invoiceSecond.payment_request);
Expand Down

0 comments on commit 8ccf218

Please sign in to comment.