diff --git a/README.md b/README.md index dffe7766..88cd2d09 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,27 @@ To build from a worktree instead of `../bitkit-android` / `../bitkit-ios` (dirty --- +### Spark receive on local regtest + +The `@spark_1` spec uses the Spark operators and Lightning payer from the repository's `BITKIT_DOCKER_REVISION`. Start the fixture before building either app so both builds embed the fixture's Spark settings. + +```bash +./scripts/local-backend spark-up +spark_settings=$(./scripts/local-backend spark-env) +while IFS= read -r setting; do export "$setting"; done <<< "$spark_settings" + +BACKEND=local ./scripts/build-android-apk.sh +BACKEND=local ./scripts/build-ios-sim.sh + +./scripts/run-spark-e2e.sh android +./scripts/run-spark-e2e.sh ios +``` + +Use a dedicated emulator and simulator because the test reinstalls Bitkit and creates a new wallet. Set `SIMULATOR_NAME` to the dedicated simulator's unique name and `SIMULATOR_OS_VERSION` to its installed runtime so Appium requests the matching capability. The Docker images build from source on the first start. Run `./scripts/local-backend spark-down` to stop the Spark services when done. + +The **Local E2E Nightly** workflows run this case on Android and iOS at 05:35 UTC against E2E `main`. To run it on demand, dispatch the workflow in the app repository. Set `e2e_branch` if the spec is on another ref. The job makes up to three attempts and uploads logs and diagnostics by attempt. +CI caches the Spark images by Docker pin and runner architecture. The iOS workflow prepares ARM64 images and wallet settings on hosted Linux, then builds the app on hosted macOS. The self-hosted Mac reuses matching Docker images when available, starts a fresh fixture, and verifies its wallet settings before running the test. + ### USDT local execution [USDT E2E setup](docs/usdt-e2e.md) starts a pinned fixture from `bitkit-docker`, diff --git a/scripts/build-ios-sim.sh b/scripts/build-ios-sim.sh index b16af63d..7d77290b 100755 --- a/scripts/build-ios-sim.sh +++ b/scripts/build-ios-sim.sh @@ -4,6 +4,7 @@ # Inputs/roots: # - E2E root: this repo (bitkit-e2e-tests) # - iOS root: $IOS_ROOT, or ../bitkit-ios if unset +# - Simulator architecture: $IOS_SIMULATOR_ARCH, defaulting to arm64 for BitkitCore # # Output: # - Copies Debug iphonesimulator build: Bitkit.app -> aut/Bitkit.app @@ -38,6 +39,7 @@ else fi XCODE_EXTRA_ARGS+=( + "ARCHS=${IOS_SIMULATOR_ARCH:-arm64}" "E2E_BACKEND=$E2E_BACKEND" "E2E_NETWORK=$E2E_NETWORK" "TREZOR_BRIDGE=$TREZOR_BRIDGE" @@ -51,13 +53,33 @@ if [[ -n "$TREZOR_ELECTRUM_URL" ]]; then XCODE_EXTRA_ARGS+=("TREZOR_ELECTRUM_URL=$TREZOR_ELECTRUM_URL") fi +if [[ -n "${SOURCE_PACKAGES:-}" ]]; then + XCODE_EXTRA_ARGS+=( + -clonedSourcePackagesDirPath "$SOURCE_PACKAGES" + -disablePackageRepositoryCache + -disableAutomaticPackageResolution + -skipPackageUpdates + ) +fi + # Embed fixture endpoints so they survive Appium reinstalls and app relaunches. -for key in USDT_RPC_URL USDT_BUNDLER_URL USDT_DEPOSITS_URL USDT_BRIDGES_URL USDT_BRIDGE_NETWORKS; do +for key in USDT_RPC_URL USDT_BUNDLER_URL USDT_DEPOSITS_URL USDT_BRIDGES_URL USDT_BRIDGE_NETWORKS \ + SPARK_LOCAL_CONFIG_B64 SPARK_LOCAL_CHAIN_URL; do if [[ -n "${!key+x}" ]]; then XCODE_EXTRA_ARGS+=("$key=${!key}") fi done +if [[ -n "${SPARK_LOCAL_CONFIG_B64:-}" ]]; then + xcode_version="$(xcodebuild -version)" + if [[ "$xcode_version" =~ ^Xcode[[:space:]]26\.0([.]|[[:space:]]) ]]; then + # Xcode 26.0 omits swift-secp256k1's default C traits when building the package. + XCODE_EXTRA_ARGS+=( + 'GCC_PREPROCESSOR_DEFINITIONS=$(inherited) ENABLE_MODULE_ECDH=1 ENABLE_MODULE_MUSIG=1 ENABLE_MODULE_RECOVERY=1 ENABLE_MODULE_SCHNORRSIG=1' + ) + fi +fi + echo "Building iOS simulator app (BACKEND=$BACKEND, E2E_BACKEND=$E2E_BACKEND, TREZOR_BRIDGE=$TREZOR_BRIDGE, TREZOR_BRIDGE_URL=$TREZOR_BRIDGE_URL)..." xcodebuild \ @@ -65,7 +87,7 @@ xcodebuild \ -scheme Bitkit \ -configuration Debug \ -sdk iphonesimulator \ - -destination 'platform=iOS Simulator,OS=latest,name=iPhone 17' \ + -destination 'generic/platform=iOS Simulator' \ -derivedDataPath "$IOS_ROOT/build" \ "${XCODE_EXTRA_ARGS[@]}" \ clean build diff --git a/scripts/local-backend b/scripts/local-backend index a0ad162f..a4958648 100755 --- a/scripts/local-backend +++ b/scripts/local-backend @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Android Appium's pinned Bitcoin, Electrum and LND fixture. +# Pinned regtest fixtures for Appium. set -euo pipefail root="$(cd "$(dirname "$0")/.." && pwd)" @@ -7,6 +7,7 @@ cache="$root/.cache/local-backend" stack="${BITKIT_LOCAL_BACKEND_ROOT:-$cache/infra}" credentials="$cache/lnd" revision="$(tr -d '[:space:]' < "$root/BITKIT_DOCKER_REVISION")" +spark_base_services=(bitcoind bitcoinsetup electrs) if [[ ! "$revision" =~ ^[0-9a-f]{40}$ ]]; then echo 'BITKIT_DOCKER_REVISION must contain a full Git SHA.' >&2 @@ -51,6 +52,137 @@ compose() ( docker compose "$@" ) +spark() ( + cd "$stack" + ./spark "$@" +) + +spark_services() { + compose --profile spark config --services | awk '/^spark-/' +} + +spark_fixture_services() { + printf '%s\n' "${spark_base_services[@]}" + spark_services +} + +spark_fixture_images() { + compose --profile spark config --images "$@" | LC_ALL=C sort -u +} + +spark_image_fingerprint() { + local service_list service image_list image image_id + local services=() image_ids=() + service_list="$(spark_fixture_services)" || return + while IFS= read -r service; do services+=("$service"); done <<< "$service_list" + image_list="$(spark_fixture_images "${services[@]}")" || return + while IFS= read -r image; do + image_id="$(docker image inspect --format '{{.Id}}' "$image")" || return + image_ids+=("$image $image_id") + done <<< "$image_list" + printf '%s\n' "${image_ids[@]}" | shasum -a 256 | awk '{print $1}' +} + +spark_build() { + # Some Spark services use the same tag. Select one target per image. + local targets=(spark-so-0 spark-migrations-0 spark-ldk-server spark-sspd spark-ready spark-lnurl spark-data-sync) + if [[ -z "${SPARK_IMAGE_CACHE:-}" ]]; then + compose --profile spark build "${targets[@]}" + return + fi + + local definitions target image archive + local images=() + definitions="$(compose --profile spark config --format json)" + for target in "${targets[@]}"; do + image="$(jq -er --arg target "$target" '.services[$target].image | strings | select(length > 0)' <<< "$definitions")" + images+=("$image") + done + + if [[ -s "$SPARK_IMAGE_CACHE" ]] && + docker image load --input "$SPARK_IMAGE_CACHE" && + docker image inspect "${images[@]}" >/dev/null; then + echo 'Loaded pinned Spark images from cache.' + return + fi + + compose --profile spark build "${targets[@]}" + if archive="$(mktemp "${SPARK_IMAGE_CACHE}.XXXXXX")"; then + if docker image save --output "$archive" "${images[@]}" && mv "$archive" "$SPARK_IMAGE_CACHE"; then + echo 'Saved pinned Spark images for caching.' + return + fi + rm -f "$archive" + fi + echo 'Could not save the Spark image cache. Continuing with the built images.' >&2 +} + +spark_pack() { + local archive="$1" + prepare + local services service image_list image + local targets=() + local images=() + services="$(spark_fixture_services)" + while IFS= read -r service; do targets+=("$service"); done <<< "$services" + + SPARK_IMAGE_CACHE= spark_build + compose --profile spark pull --ignore-buildable "${targets[@]}" + image_list="$(spark_fixture_images "${targets[@]}")" + while IFS= read -r image; do images+=("$image"); done <<< "$image_list" + docker image save --output "$archive" "${images[@]}" +} + +spark_up() { + prepare + local SPARK_PUBLIC_HOST=127.0.0.1 + export SPARK_PUBLIC_HOST + local services service + local profile_services=() + local start_args=(-d) + local base_args=(--no-recreate) + services="$(spark_services)" + while IFS= read -r service; do profile_services+=("$service"); done <<< "$services" + if [[ -n "${SPARK_IMAGE_ARCHIVE:-}" ]]; then + docker image load --input "$SPARK_IMAGE_ARCHIVE" + fi + if [[ -n "${SPARK_IMAGE_FINGERPRINT:-}" ]]; then + if [[ "$(spark_image_fingerprint)" != "$SPARK_IMAGE_FINGERPRINT" ]]; then + echo 'The local Docker images do not match the pinned Spark fixture archive.' >&2 + return 1 + fi + fi + if [[ -n "${SPARK_IMAGE_ARCHIVE:-}${SPARK_IMAGE_FINGERPRINT:-}" ]]; then + start_args+=(--pull never) + base_args+=(--no-build) + fi + compose up "${start_args[@]}" "${base_args[@]}" "${spark_base_services[@]}" + if [[ -z "${SPARK_IMAGE_ARCHIVE:-}${SPARK_IMAGE_FINGERPRINT:-}" ]]; then spark_build; fi + # Let Compose refresh Spark services when their advertised host changes. + compose --profile spark up "${start_args[@]}" --no-build "${profile_services[@]}" + local status=0 + compose --profile spark wait spark-ready || status=$? + compose --profile spark logs --no-log-prefix spark-ready + return "$status" +} + +spark_env() { + check_revision + local config + config="$(spark config --base64)" + [[ -n "$config" ]] || { echo 'Local Spark config is empty.' >&2; return 1; } + printf 'SPARK_LOCAL_CONFIG_B64=%s\n' "$config" + printf 'SPARK_LOCAL_CHAIN_URL=http://127.0.0.1:23090/api\n' +} + +spark_init_env() { + prepare + local SPARK_PUBLIC_HOST=127.0.0.1 + export SPARK_PUBLIC_HOST + compose --profile spark up --no-deps --no-build --pull never --exit-code-from spark-init spark-init >&2 + spark_env +} + set_runner_env() { export BITKIT_LOCAL_BACKEND_ROOT="$stack" export ELECTRUM_PORT="${ELECTRUM_PORT:-60001}" @@ -97,6 +229,37 @@ case "${1:-}" in printf '%s\n' "$stack" ;; up) up ;; + spark-pack) + [[ "$#" -eq 2 && -n "$2" ]] || { + echo 'Usage: ./scripts/local-backend spark-pack ' >&2 + exit 2 + } + spark_pack "$2" + ;; + spark-up) spark_up ;; + spark-image-fingerprint) + check_revision + spark_image_fingerprint + ;; + spark-init-env) spark_init_env ;; + spark-env) spark_env ;; + spark-pay) + check_revision + [[ "${2:-}" =~ ^lnbcrt[a-z0-9]+$ && "$#" -eq 2 ]] || { + echo 'Usage: ./scripts/local-backend spark-pay ' >&2 + exit 2 + } + spark pay "$2" + ;; + spark-down) + check_revision + spark down + ;; + spark-logs) + check_revision + shift + compose --profile spark logs "$@" + ;; down|ps|logs) check_revision compose "$@" @@ -116,7 +279,7 @@ case "${1:-}" in exec "$@" ;; *) - echo 'Usage: ./scripts/local-backend {prepare|path|up|down|ps|logs|github-env|run }' >&2 + echo 'Usage: ./scripts/local-backend {prepare|path|up|down|ps|logs|github-env|run |spark-pack |spark-up|spark-image-fingerprint|spark-init-env|spark-env|spark-pay |spark-down|spark-logs}' >&2 exit 2 ;; esac diff --git a/scripts/run-spark-e2e.sh b/scripts/run-spark-e2e.sh new file mode 100755 index 00000000..9c00f5b0 --- /dev/null +++ b/scripts/run-spark-e2e.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail + +case "${1:-}" in + android|ios) ;; + *) + echo 'Usage: ./scripts/run-spark-e2e.sh {android|ios}' >&2 + exit 2 + ;; +esac + +cd "$(dirname "$0")/.." +./scripts/local-backend path >/dev/null +curl --fail --silent --show-error --max-time 5 http://127.0.0.1:23090/api/blocks/tip/height >/dev/null +if [[ "$1" == android ]]; then + for port in 23535 23536 23537 23049 23090; do + adb reverse "tcp:$port" "tcp:$port" + done +fi + +# Each dedicated run must execute the payment even on a reused runner. +exec ./scripts/local-backend run env -u CI BITKIT_LOCAL_SPARK=1 "./ci_run_$1.sh" \ + --spec ./test/specs/spark.e2e.ts --mochaOpts.grep '@spark_1\b' diff --git a/scripts/slack_summary.py b/scripts/slack_summary.py index 25a6aff7..eab253a6 100755 --- a/scripts/slack_summary.py +++ b/scripts/slack_summary.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 """ -Slack summary script for Bitkit E2E staging and migration workflows. +Slack summary script for Bitkit E2E staging, migration and local nightly workflows. Renders a summary message from environment variables and posts it to a Slack webhook. Modeled on synonymdev/bitkit-nightly slack_summary.py style. @@ -8,12 +8,11 @@ Usage: python3 scripts/slack_summary.py e2e-staging python3 scripts/slack_summary.py e2e-migration + python3 scripts/slack_summary.py e2e-local-nightly Required env vars: SLACK_WEBHOOK_URL - Slack incoming webhook URL (skips gracefully if unset) PLATFORM - ios|android - BUILD_RESULT - build job result - E2E_BRANCH_RESULT - e2e-branch job result E2E_TESTS_RESULT - e2e-tests job result RUN_URL - GitHub Actions run URL RUN_ATTEMPT - Current run attempt number @@ -21,13 +20,19 @@ Mode-specific env vars: STAGING_RESULT - Overall result for e2e-staging MIGRATION_RESULT - Overall result for e2e-migration + BUILD_RESULT - App build result + E2E_BRANCH_RESULT - e2e-branch result for staging and migration PREPARE_WALLETS_RESULT - Optional iOS migration job result + LOCAL_NIGHTLY_RESULT - Overall result for e2e-local-nightly + SPARK_IMAGES_RESULT - Optional iOS image preparation result Optional env vars: E2E_TESTS_REF - Resolved e2e-tests branch/ref GITHUB_REPOSITORY - Repository name (e.g. synonymdev/bitkit-ios) """ +from __future__ import annotations + import json import os import sys @@ -35,7 +40,7 @@ import urllib.request from datetime import datetime, timezone -MODES = ("e2e-staging", "e2e-migration") +MODES = ("e2e-staging", "e2e-migration", "e2e-local-nightly") def get_status_icon(status: str) -> str: @@ -74,14 +79,9 @@ def _render_message( *, kind: str, overall_result: str, - build_job: str, - tests_job: str, + jobs: dict[str, str], ) -> str: platform = os.environ.get("PLATFORM", "") - build_result = os.environ.get("BUILD_RESULT", "unknown") - e2e_branch_result = os.environ.get("E2E_BRANCH_RESULT", "unknown") - e2e_tests_result = os.environ.get("E2E_TESTS_RESULT", "unknown") - prepare_wallets_result = os.environ.get("PREPARE_WALLETS_RESULT", "") run_url = os.environ.get("RUN_URL", "") run_attempt = os.environ.get("RUN_ATTEMPT", "1") e2e_tests_ref = os.environ.get("E2E_TESTS_REF", "") @@ -108,22 +108,29 @@ def _render_message( lines.append("") lines.append("Jobs:") - lines.append(f" {build_job}: {format_status(build_result)}") - lines.append(f" e2e-branch: {format_status(e2e_branch_result)}") - if prepare_wallets_result: - lines.append(f" prepare-wallets: {format_status(prepare_wallets_result)}") - lines.append(f" {tests_job}: {format_status(e2e_tests_result)}") + lines.extend(f" {job}: {format_status(result)}" for job, result in jobs.items()) return "\n".join(lines) +def _standard_jobs(build_job: str, tests_job: str) -> dict[str, str]: + jobs = { + build_job: os.environ.get("BUILD_RESULT", "unknown"), + "e2e-branch": os.environ.get("E2E_BRANCH_RESULT", "unknown"), + } + prepare_wallets = os.environ.get("PREPARE_WALLETS_RESULT", "") + if prepare_wallets: + jobs["prepare-wallets"] = prepare_wallets + jobs[tests_job] = os.environ.get("E2E_TESTS_RESULT", "unknown") + return jobs + + def render_e2e_staging_message() -> str: """Render the E2E staging summary message from environment variables.""" return _render_message( kind="staging", overall_result=os.environ.get("STAGING_RESULT", "unknown"), - build_job="build-staging", - tests_job="e2e-tests-staging", + jobs=_standard_jobs("build-staging", "e2e-tests-staging"), ) @@ -132,8 +139,21 @@ def render_e2e_migration_message() -> str: return _render_message( kind="migration", overall_result=os.environ.get("MIGRATION_RESULT", "unknown"), - build_job="build", - tests_job="e2e-tests", + jobs=_standard_jobs("build", "e2e-tests"), + ) + + +def render_e2e_local_nightly_message() -> str: + jobs = {} + for job, variable in (("spark-images", "SPARK_IMAGES_RESULT"), ("build-spark-ios", "BUILD_RESULT")): + result = os.environ.get(variable) + if result: + jobs[job] = result + jobs["e2e-spark"] = os.environ.get("E2E_TESTS_RESULT", "unknown") + return _render_message( + kind="local nightly", + overall_result=os.environ.get("LOCAL_NIGHTLY_RESULT", "unknown"), + jobs=jobs, ) @@ -187,6 +207,8 @@ def main() -> int: message = render_e2e_staging_message() elif mode == "e2e-migration": message = render_e2e_migration_message() + elif mode == "e2e-local-nightly": + message = render_e2e_local_nightly_message() else: print(f"Unknown mode: {mode}", file=sys.stderr) print(f"Available modes: {', '.join(MODES)}", file=sys.stderr) diff --git a/scripts/test_slack_summary.py b/scripts/test_slack_summary.py index e49abe33..cad6f4a5 100644 --- a/scripts/test_slack_summary.py +++ b/scripts/test_slack_summary.py @@ -11,7 +11,9 @@ format_status, get_platform_display, get_status_icon, + main, post_to_slack, + render_e2e_local_nightly_message, render_e2e_migration_message, render_e2e_staging_message, ) @@ -200,6 +202,55 @@ def test_android_success_omits_prepare_wallets(self): self.assertNotIn("prepare-wallets", message) +class TestRenderLocalNightlyMessage(unittest.TestCase): + def setUp(self): + env_patcher = patch.dict(os.environ, {}, clear=True) + env_patcher.start() + self.addCleanup(env_patcher.stop) + + def test_android_summary_has_one_job(self): + os.environ.update({ + "PLATFORM": "android", + "LOCAL_NIGHTLY_RESULT": "success", + "E2E_TESTS_RESULT": "success", + "RUN_URL": "https://github.com/synonymdev/bitkit-android/actions/runs/123", + "RUN_ATTEMPT": "2", + "E2E_TESTS_REF": "abc123", + }) + message = render_e2e_local_nightly_message() + self.assertIn(":white_check_mark: Bitkit Android E2E local nightly: success", message) + self.assertIn("Run: https://github.com/synonymdev/bitkit-android/actions/runs/123", message) + self.assertIn("Run attempt: 2", message) + self.assertIn("E2E tests ref: abc123", message) + self.assertEqual(message.split("Jobs:\n", 1)[1], " e2e-spark: :white_check_mark: success") + + def test_ios_summary_distinguishes_failed_setup_from_skipped_e2e(self): + os.environ.update({ + "PLATFORM": "ios", + "LOCAL_NIGHTLY_RESULT": "failure", + "SPARK_IMAGES_RESULT": "success", + "BUILD_RESULT": "failure", + "E2E_TESTS_RESULT": "skipped", + }) + message = render_e2e_local_nightly_message() + self.assertIn(":x: Bitkit iOS E2E local nightly: failure", message) + self.assertEqual( + message.split("Jobs:\n", 1)[1].splitlines(), + [" spark-images: :white_check_mark: success", + " build-spark-ios: :x: failure", + " e2e-spark: :fast_forward: skipped"], + ) + + def test_cli_posts_one_summary(self): + os.environ.update({"LOCAL_NIGHTLY_RESULT": "success", "E2E_TESTS_RESULT": "success"}) + with patch("sys.argv", ["slack_summary.py", "e2e-local-nightly"]), \ + patch("sys.stdout", new=io.StringIO()), \ + patch("slack_summary.post_to_slack", return_value=True) as post: + self.assertEqual(main(), 0) + post.assert_called_once() + self.assertIn("e2e-spark: :white_check_mark: success", post.call_args.args[0]) + + class TestPostToSlack(unittest.TestCase): """Tests for webhook posting.""" diff --git a/test/helpers/receive-invoice.ts b/test/helpers/receive-invoice.ts index dbb9d065..3a1ad37e 100644 --- a/test/helpers/receive-invoice.ts +++ b/test/helpers/receive-invoice.ts @@ -1,7 +1,7 @@ import { actAndExpect, tapAndExpect } from './outcome'; /** Edit the newly generated invoice, not a cached/placeholder Receive subtree. */ -export async function editGateLightningInvoice(paidInvoice: string) { +export async function editGateLightningInvoice(paidInvoice?: string) { const outcome = { anyVisible: [{ id: 'ReceiveNumberPadTextField' }] }; if (!driver.isAndroid) { await tapAndExpect({ id: 'SpecifyInvoiceButton' }, outcome); @@ -32,7 +32,7 @@ export async function editGateLightningInvoice(paidInvoice: string) { ).toLowerCase(); if ( !/^lnbcrt(?:\d+[munp]?)?1[02-9ac-hj-np-z]+$/.test(invoice) || - invoice === paidInvoice.toLowerCase() + invoice === paidInvoice?.toLowerCase() ) continue; // Pager pages repeat these tags. Resolve Edit from this QR's nearest shared diff --git a/test/specs/spark.e2e.ts b/test/specs/spark.e2e.ts new file mode 100644 index 00000000..67f36a6d --- /dev/null +++ b/test/specs/spark.e2e.ts @@ -0,0 +1,68 @@ +import { execFile } from 'node:child_process'; +import { resolve } from 'node:path'; +import { promisify } from 'node:util'; +import { + acknowledgeReceivedPayment, + completeOnboarding, + elementById, + expectSpendingBalance, + expectTextWithin, + getAddressFromQRCode, + getAmountUnder, + getReceiveAddress, + multiTap, + swipeFullScreen, +} from '../helpers/actions'; +import { doNavigationClose, openSettings } from '../helpers/navigation'; +import { tapAndExpect } from '../helpers/outcome'; +import { editGateLightningInvoice } from '../helpers/receive-invoice'; +import { reinstallApp } from '../helpers/setup'; +import { ciIt } from '../helpers/suite'; + +const runCommand = promisify(execFile); +const describeSpark = process.env.BITKIT_LOCAL_SPARK === '1' ? describe : describe.skip; + +async function openSparkConnection() { + await openSettings('advanced'); + await tapAndExpect({ id: 'Channels' }, { anyVisible: [{ id: 'SparkConnection' }] }); + await tapAndExpect( + { id: 'SparkConnection' }, + { anyVisible: [{ id: 'SparkBalance' }, { id: 'SparkDepositAddress' }] } + ); + if (!(await elementById('SparkBalance').isDisplayed())) { + await swipeFullScreen('up', { upStartYPercent: 0.68, upEndYPercent: 0.34 }); + } +} + +describeSpark('Spark on local regtest', () => { + ciIt('@spark_1 - Receive a Lightning payment into Spark', async () => { + await reinstallApp(); + await completeOnboarding(); + + await openSparkConnection(); + expect(await getAmountUnder('SparkBalance')).toBe(0); + await doNavigationClose(); + + const originalInvoice = await getReceiveAddress('lightning'); + await editGateLightningInvoice(); + await tapAndExpect({ id: 'ReceiveNumberPadTextField' }, { anyVisible: [{ id: 'N1' }] }); + await tapAndExpect({ id: 'N1' }, { anyVisible: [{ id: 'N0' }] }); + await multiTap('N0', 4); + await tapAndExpect({ id: 'ReceiveNumberPadSubmit' }, { anyVisible: [{ id: 'ShowQrReceive' }] }); + await tapAndExpect({ id: 'ShowQrReceive' }, { anyVisible: [{ id: 'QRCode' }] }); + const invoice = await getAddressFromQRCode('lightning'); + expect(invoice).not.toBe(originalInvoice); + await swipeFullScreen('down'); + + await runCommand(resolve(__dirname, '../../scripts/local-backend'), ['spark-pay', invoice], { + timeout: 120_000, + }); + await acknowledgeReceivedPayment({ timeout: 90_000 }); + await expectSpendingBalance(10_000); + await expectTextWithin('ActivityShort-0', '+'); + await expectTextWithin('ActivityShort-0', '10 000'); + + await openSparkConnection(); + expect(await getAmountUnder('SparkBalance')).toBe(10_000); + }); +});