diff --git a/core/api/src/services/lnd/index.ts b/core/api/src/services/lnd/index.ts index 957a0b5d56..9d9ea936e2 100644 --- a/core/api/src/services/lnd/index.ts +++ b/core/api/src/services/lnd/index.ts @@ -96,10 +96,11 @@ export const LndService = (): ILightningService | LightningServiceError => { const defaultLnd = activeNode.lnd const defaultPubkey = activeNode.pubkey as Pubkey - const activeOnchainNode = getActiveOnchainLnd() - if (activeOnchainNode instanceof Error) return activeOnchainNode - - const defaultOnchainLnd = activeOnchainNode.lnd + const defaultOnchainLnd = () => { + const activeOnchainNode = getActiveOnchainLnd() + if (activeOnchainNode instanceof Error) return activeOnchainNode + return activeOnchainNode.lnd + } const isLocal = (pubkey: Pubkey): boolean | LightningServiceError => getLnds({ type: "offchain" }).some((item) => item.pubkey === pubkey) @@ -131,7 +132,7 @@ export const LndService = (): ILightningService | LightningServiceError => { pubkey?: Pubkey, ): Promise => { try { - const lndInstance = pubkey ? getLndFromPubkey({ pubkey }) : defaultOnchainLnd + const lndInstance = pubkey ? getLndFromPubkey({ pubkey }) : defaultOnchainLnd() if (lndInstance instanceof Error) return lndInstance const { chain_balance } = await getChainBalance({ lnd: lndInstance }) @@ -145,7 +146,7 @@ export const LndService = (): ILightningService | LightningServiceError => { pubkey?: Pubkey, ): Promise => { try { - const lndInstance = pubkey ? getLndFromPubkey({ pubkey }) : defaultOnchainLnd + const lndInstance = pubkey ? getLndFromPubkey({ pubkey }) : defaultOnchainLnd() if (lndInstance instanceof Error) return lndInstance const { pending_chain_balance } = await getPendingChainBalance({ lnd: lndInstance }) @@ -183,8 +184,11 @@ export const LndService = (): ILightningService | LightningServiceError => { // this is necessary for tests, otherwise `after` may be negative const after = Math.max(0, blockHeight - scanDepth) + const lnd = defaultOnchainLnd() + if (lnd instanceof Error) return lnd + const txs = await getChainTransactions({ - lnd: defaultOnchainLnd, + lnd, after, }) diff --git a/core/api/test/bats/helpers/ln.bash b/core/api/test/bats/helpers/ln.bash index e773663ff5..0c19b2e98c 100644 --- a/core/api/test/bats/helpers/ln.bash +++ b/core/api/test/bats/helpers/ln.bash @@ -168,12 +168,12 @@ lnd_cli() { lnd_start() { started() { state="$(lnd_cli state | jq -r '.state')" - is_synced="$(lnd_outside_cli getinfo | jq -r '.synced_to_graph')" + is_synced="$(lnd_cli getinfo | jq -r '.synced_to_graph')" [[ "$state" == "SERVER_ACTIVE" && "$is_synced" == "true" ]] || exit 1 } docker start "${COMPOSE_PROJECT_NAME}-lnd1-1" - retry 20 3 started + retry 10 5 started } lnd_stop() { diff --git a/core/api/test/bats/invoices.bats b/core/api/test/bats/invoices.bats index 9aa333d3ab..2b22ec0786 100644 --- a/core/api/test/bats/invoices.bats +++ b/core/api/test/bats/invoices.bats @@ -53,6 +53,30 @@ setup() { reset_redis } +@test "invoices: get invoices for account" { + token_name="$ALICE_TOKEN_NAME" + + exec_graphql "$token_name" 'invoices' '{"first": 3}' + + invoice_count="$(graphql_output '.data.me.defaultAccount.invoices.edges | length')" + [[ "$invoice_count" -eq "3" ]] || exit 1 +} + +@test "invoices: get invoices for wallet" { + token_name="$ALICE_TOKEN_NAME" + btc_wallet_name="$token_name.btc_wallet_id" + + variables=$( + jq -n \ + --arg wallet_id "$(read_value $btc_wallet_name)" \ + '{walletId: $wallet_id, first: 2}' + ) + exec_graphql "$token_name" 'invoices-by-wallet' "$variables" + + invoice_count="$(graphql_output '.data.me.defaultAccount.walletById.invoices.edges | length')" + [[ "$invoice_count" -eq "2" ]] || exit 1 +} + @test "invoices: create invoices from alternate node" { lnd1_pubkey=$(lnd_cli getinfo | jq -r '.identity_pubkey') lnd2_pubkey=$(lnd2_cli getinfo | jq -r '.identity_pubkey') @@ -93,27 +117,3 @@ setup() { destination_node="$(lnd2_cli decodepayreq $payment_request | jq -r '.destination')" [[ "${destination_node}" == "${lnd2_pubkey}" ]] || exit 1 } - -@test "invoices: get invoices for account" { - token_name="$ALICE_TOKEN_NAME" - - exec_graphql "$token_name" 'invoices' '{"first": 3}' - - invoice_count="$(graphql_output '.data.me.defaultAccount.invoices.edges | length')" - [[ "$invoice_count" -eq "3" ]] || exit 1 -} - -@test "invoices: get invoices for wallet" { - token_name="$ALICE_TOKEN_NAME" - btc_wallet_name="$token_name.btc_wallet_id" - - variables=$( - jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ - '{walletId: $wallet_id, first: 2}' - ) - exec_graphql "$token_name" 'invoices-by-wallet' "$variables" - - invoice_count="$(graphql_output '.data.me.defaultAccount.walletById.invoices.edges | length')" - [[ "$invoice_count" -eq "2" ]] || exit 1 -}