Skip to content

Commit

Permalink
fix: test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPurohit committed Aug 1, 2024
1 parent a3a4ee3 commit 8767ede
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
22 changes: 12 additions & 10 deletions clients/apps/nodejs/test/tb04-simple-lightning-latch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import client_config from '../client_config.js';
import mercurynodejslib from 'mercurynodejslib';
import { CoinStatus } from 'mercurynodejslib/coin_enum.js';
import crypto from 'crypto';
import { createWallet, depositCoin, generateInvoice } from '../test_utils.js';
import { createWallet, depositCoin, generateInvoice, payInvoice } from '../test_utils.js';

describe('TB04 - Lightning Latch', function() {
this.timeout(30000);
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('TB04 - Lightning Latch', function() {

const transferAddress = await mercurynodejslib.newTransferAddress(clientConfig, wallet_2_name, null);

await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin.statechain_id, transferAddress.transfer_receive, paymentHash.batchId);
await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin.statechain_id, transferAddress.transfer_receive, false, paymentHash.batchId);

let transferReceiveResult = await mercurynodejslib.transferReceive(clientConfig, wallet_2_name);

Expand Down Expand Up @@ -131,8 +131,8 @@ describe('TB04 - Lightning Latch', function() {
const transferAddress1 = await mercurynodejslib.newTransferAddress(clientConfig, wallet_1_name, null);
const transferAddress2 = await mercurynodejslib.newTransferAddress(clientConfig, wallet_2_name, null);

await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin1.statechain_id, transferAddress1.transfer_receive, paymentHash1.batchId);
await mercurynodejslib.transferSend(clientConfig, wallet_2_name, coin2.statechain_id, transferAddress2.transfer_receive, paymentHash2.batchId);
await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin1.statechain_id, transferAddress1.transfer_receive, false, paymentHash1.batchId);
await mercurynodejslib.transferSend(clientConfig, wallet_2_name, coin2.statechain_id, transferAddress2.transfer_receive, false, paymentHash2.batchId);

let transferReceiveResult = await mercurynodejslib.transferReceive(clientConfig, wallet_1_name);

Expand Down Expand Up @@ -229,8 +229,8 @@ describe('TB04 - Lightning Latch', function() {
const transferAddress1 = await mercurynodejslib.newTransferAddress(clientConfig, wallet_1_name, null);
const transferAddress2 = await mercurynodejslib.newTransferAddress(clientConfig, wallet_2_name, null);

await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin1.statechain_id, transferAddress1.transfer_receive, paymentHash1.batchId);
await mercurynodejslib.transferSend(clientConfig, wallet_2_name, coin2.statechain_id, transferAddress2.transfer_receive, paymentHash1.batchId);
await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin1.statechain_id, transferAddress1.transfer_receive, false, paymentHash1.batchId);
await mercurynodejslib.transferSend(clientConfig, wallet_2_name, coin2.statechain_id, transferAddress2.transfer_receive, false, paymentHash1.batchId);

let transferReceiveResult = await mercurynodejslib.transferReceive(clientConfig, wallet_1_name);

Expand All @@ -256,8 +256,8 @@ describe('TB04 - Lightning Latch', function() {
const transferAddress3 = await mercurynodejslib.newTransferAddress(clientConfig, wallet_1_name, null);
const transferAddress4 = await mercurynodejslib.newTransferAddress(clientConfig, wallet_2_name, null);

await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin1.statechain_id, transferAddress3.transfer_receive, paymentHash2.batchId);
await mercurynodejslib.transferSend(clientConfig, wallet_2_name, coin2.statechain_id, transferAddress4.transfer_receive, paymentHash2.batchId);
await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin1.statechain_id, transferAddress3.transfer_receive, false, paymentHash2.batchId);
await mercurynodejslib.transferSend(clientConfig, wallet_2_name, coin2.statechain_id, transferAddress4.transfer_receive, false, paymentHash2.batchId);

transferReceiveResult = await mercurynodejslib.transferReceive(clientConfig, wallet_1_name);

Expand All @@ -284,8 +284,8 @@ describe('TB04 - Lightning Latch', function() {

// await removeDatabase();
const clientConfig = client_config.load();
let wallet_1_name = "w_ln_1";
let wallet_2_name = "w_ln_2";
let wallet_1_name = "w_ln_7";
let wallet_2_name = "w_ln_8";
await createWallet(clientConfig, wallet_1_name);
await createWallet(clientConfig, wallet_2_name);

Expand Down Expand Up @@ -314,6 +314,8 @@ describe('TB04 - Lightning Latch', function() {

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

await payInvoice(invoice.payment_request);

const transferAddress = await mercurynodejslib.newTransferAddress(clientConfig, wallet_2_name, null);

await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin.statechain_id, transferAddress.transfer_receive, false, paymentHash.batchId);
Expand Down
18 changes: 15 additions & 3 deletions clients/apps/nodejs/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ const connectElectr = async () => {
await exec("docker network connect mercurylayer_default mercurylayer_electrs_1");
}

async function generateInvoice(paymentHash, amountInSats) {
const generateInvoice = async (paymentHash, amountInSats) => {

const generateInvoiceCommand = `docker exec $(docker ps -qf "name=mercurylayer_alice_1") lncli addinvoice ${paymentHash} --amt ${amountInSats}`;
const generateInvoiceCommand = `docker exec $(docker ps -qf "name=mercurylayer_alice_1") lncli -n regtest addholdinvoice ${paymentHash} --amt ${amountInSats}`;
const { stdout, stderr } = await exec(generateInvoiceCommand);
if (stderr) {
console.error('Error:', stderr);
Expand All @@ -111,6 +111,17 @@ async function generateInvoice(paymentHash, amountInSats) {
return stdout.trim();
}

const payInvoice = async (paymentRequest) => {

const payInvoiceCommand = `docker exec $(docker ps -qf "name=mercurylayer_bob_1") lncli -n regtest payinvoice ${paymentRequest}`;
const { stdout, stderr } = await exec(payInvoiceCommand);
if (stderr) {
console.error('Error:', stderr);
return null;
}
return stdout.trim();
}

module.exports = {
removeDatabase,
getDatabase,
Expand All @@ -123,5 +134,6 @@ module.exports = {
disconnectElectr,
connectMercuryServer,
disconnectMercuryServer ,
generateInvoice
generateInvoice,
payInvoice
};

0 comments on commit 8767ede

Please sign in to comment.