From 6783ff359a22268700dfbf20bdce36056c045080 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 19 Nov 2026 10:22:18 +0100 Subject: [PATCH 01/15] test: wire Android E2E to local Spark --- .github/workflows/e2e.yml | 97 ++++++++++++++++++- app/build.gradle.kts | 4 + .../java/to/bitkit/services/SparkService.kt | 28 +++++- .../settings/lightning/SparkDetailScreen.kt | 1 + 4 files changed, 126 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 695d01bbea..78992c8e4f 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -3,6 +3,10 @@ name: E2E on: workflow_dispatch: inputs: + spark_only: + description: "Run only @spark_1 on pinned local Spark" + type: boolean + default: false e2e_branch: description: "Branch of synonymdev/bitkit-e2e-tests to use (main | default-feature-branch | custom branch name)" required: false @@ -40,7 +44,7 @@ jobs: build-local: needs: detect-changes - if: github.event.pull_request.draft == false && needs.detect-changes.outputs.code == 'true' + if: "!inputs.spark_only && github.event.pull_request.draft == false && needs.detect-changes.outputs.code == 'true'" runs-on: ubuntu-latest steps: @@ -268,8 +272,97 @@ jobs: if: failure() uses: jwalton/gh-docker-logs@v2 + e2e-spark: + if: inputs.spark_only + needs: e2e-branch + runs-on: ubuntu-latest + timeout-minutes: 120 + env: + COMPOSE_PROJECT_NAME: bitkit-spark-e2e + steps: + - name: Reserve regtest host ports + run: sudo sysctl -w net.ipv4.ip_local_reserved_ports=39388,43782,60001 + + - uses: actions/checkout@v7 + with: + path: bitkit-android + persist-credentials: false + + - name: Resolve E2E tests ref + id: e2e-ref + uses: synonymdev/bitkit-e2e-tests/.github/actions/resolve-e2e-ref@main + with: + selected: ${{ needs.e2e-branch.outputs.branch }} + e2e_branch_input: ${{ inputs.e2e_branch }} + + - uses: actions/checkout@v7 + with: + repository: synonymdev/bitkit-e2e-tests + ref: ${{ steps.e2e-ref.outputs.ref }} + path: bitkit-e2e-tests + persist-credentials: false + + - uses: actions/setup-java@v6 + with: + java-version: "17" + distribution: temurin + + - uses: gradle/actions/setup-gradle@v6 + + - uses: actions/setup-node@v7 + with: + node-version: 22 + cache: npm + cache-dependency-path: bitkit-e2e-tests/package-lock.json + + - name: Install Appium dependencies + working-directory: bitkit-e2e-tests + run: npm ci + + - name: Start pinned Spark fixture + working-directory: bitkit-e2e-tests + run: | + ./scripts/local-backend spark-up + ./scripts/local-backend spark-env >> "$GITHUB_ENV" + + - name: Build Android Spark app + working-directory: bitkit-e2e-tests + env: + GITHUB_ACTOR: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./scripts/build-android-apk.sh + + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: Run @spark_1 + uses: reactivecircus/android-emulator-runner@v2 + with: + profile: pixel_6 + api-level: 33 + arch: x86_64 + avd-name: Pixel_6 + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none + script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android + + - name: Collect Spark logs + if: failure() + working-directory: bitkit-e2e-tests + run: | + mkdir -p artifacts + ./scripts/local-backend spark-logs --tail 200 > artifacts/spark-docker.log 2>&1 || true + + - uses: actions/upload-artifact@v7 + if: always() + with: + name: spark-android-${{ github.run_number }} + path: bitkit-e2e-tests/artifacts/ + e2e-status: - if: always() && github.event.pull_request.draft == false + if: always() && !inputs.spark_only && github.event.pull_request.draft == false name: e2e-status runs-on: ubuntu-latest needs: [detect-changes, e2e-tests-local] diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 29f5252abb..8f15f629e9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -131,6 +131,8 @@ val bcp47Locales = listOf( ) val e2eEnv = envFlag("E2E", default = false) val e2eBackendEnv = providers.environmentVariable("E2E_BACKEND").orElse("local") +val sparkLocalConfigEnv = providers.environmentVariable("SPARK_LOCAL_CONFIG_B64").orElse("") +val sparkLocalChainUrlEnv = providers.environmentVariable("SPARK_LOCAL_CHAIN_URL").orElse("") val e2eLocalHostEnv = providers.environmentVariable("E2E_LOCAL_HOST").orElse("10.0.2.2") val e2eHomegateUrlEnv = providers.environmentVariable("E2E_HOMEGATE_URL") .orElse(e2eLocalHostEnv.map { "http://$it:6288" }) @@ -417,6 +419,8 @@ androidComponents { buildConfigFields.put("ESPLORA_URL", localProp("ESPLORA_URL").orElse("").stringField()) buildConfigFields.put("E2E", e2eEnv.booleanField()) buildConfigFields.put("E2E_BACKEND", e2eBackendEnv.stringField()) + buildConfigFields.put("SPARK_LOCAL_CONFIG_B64", sparkLocalConfigEnv.stringField()) + buildConfigFields.put("SPARK_LOCAL_CHAIN_URL", sparkLocalChainUrlEnv.stringField()) buildConfigFields.put("E2E_LOCAL_HOST", e2eLocalHostEnv.stringField()) buildConfigFields.put("E2E_HOMEGATE_URL", e2eHomegateUrlEnv.stringField()) buildConfigFields.put("E2E_HOMESERVER_PUBKY", e2eHomeserverPubkyEnv.stringField()) diff --git a/app/src/main/java/to/bitkit/services/SparkService.kt b/app/src/main/java/to/bitkit/services/SparkService.kt index 594bc11371..e88dcd24e7 100644 --- a/app/src/main/java/to/bitkit/services/SparkService.kt +++ b/app/src/main/java/to/bitkit/services/SparkService.kt @@ -43,6 +43,7 @@ import breez_sdk_spark.SendPaymentOptions import breez_sdk_spark.SendPaymentRequest import breez_sdk_spark.SyncWalletRequest import breez_sdk_spark.defaultConfig +import breez_sdk_spark.parseSparkConfig import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.asSharedFlow @@ -50,6 +51,7 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import org.lightningdevkit.ldknode.Bolt11Invoice import org.lightningdevkit.ldknode.Network +import to.bitkit.BuildConfig import to.bitkit.data.keychain.Keychain import to.bitkit.env.Env import to.bitkit.ext.runSuspendCatching @@ -60,6 +62,7 @@ import to.bitkit.utils.Logger import to.bitkit.utils.ServiceError import java.io.File import java.math.BigInteger +import java.util.Base64 import javax.inject.Inject import javax.inject.Singleton import breez_sdk_spark.Network as SparkNetwork @@ -179,10 +182,18 @@ class SparkService @Inject constructor( val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name) val config = configure(defaultConfig(network), Env.breezApiKey, isExiting) val storageDir = File(Env.sparkStoragePath(walletIndex)).apply { mkdirs() }.path - val chainServiceUrl = Env.sparkChainServiceUrl(Env.network) + val localChainUrl = if (Env.isDebug && Env.isLocalE2eBackend && network == SparkNetwork.REGTEST) { + localSparkChainUrl(config) + } else { + null + } + val chainServiceUrl = localChainUrl ?: Env.sparkChainServiceUrl(Env.network) val connected = SdkBuilder(config, Seed.Mnemonic(mnemonic, passphrase)).use { builder -> builder.withDefaultStorage(storageDir) - chainServiceUrl?.let { builder.withRestChainService(it, ChainApiType.ESPLORA, null) } + chainServiceUrl?.let { + val apiType = if (localChainUrl != null) ChainApiType.MEMPOOL_SPACE else ChainApiType.ESPLORA + builder.withRestChainService(it, apiType, null) + } builder.build() } listenerId = connected.addEventListener( @@ -198,6 +209,19 @@ class SparkService @Inject constructor( true } + private fun localSparkChainUrl(config: Config): String? { + val encoded = BuildConfig.SPARK_LOCAL_CONFIG_B64 + val chainUrl = BuildConfig.SPARK_LOCAL_CHAIN_URL + if (encoded.isBlank() && chainUrl.isBlank()) return null + require(encoded.isNotBlank() && chainUrl.isNotBlank()) { + "Local Spark requires SPARK_LOCAL_CONFIG_B64 and SPARK_LOCAL_CHAIN_URL" + } + config.sparkConfig = parseSparkConfig(Base64.getDecoder().decode(encoded).decodeToString()) + // The pinned regtest operators require anchored refunds. + config.watchtowerFeeLadderEnabled = false + return chainUrl + } + suspend fun disconnect() = mutex.withLock { val current = sdk ?: return@withLock try { diff --git a/app/src/main/java/to/bitkit/ui/settings/lightning/SparkDetailScreen.kt b/app/src/main/java/to/bitkit/ui/settings/lightning/SparkDetailScreen.kt index 53df70e275..9cfa727125 100644 --- a/app/src/main/java/to/bitkit/ui/settings/lightning/SparkDetailScreen.kt +++ b/app/src/main/java/to/bitkit/ui/settings/lightning/SparkDetailScreen.kt @@ -135,6 +135,7 @@ private fun Content( SectionRow( name = stringResource(R.string.lightning__spending_label), valueContent = { MoneyCaptionB(sats = spark.balanceSats.toLong(), symbol = true) }, + modifier = Modifier.testTag("SparkBalance"), ) if (spark.pendingDeposits.isNotEmpty()) { From f201a863586bf73f4113df5567713eb340c430d5 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 19 Nov 2026 10:27:27 +0100 Subject: [PATCH 02/15] ci: isolate Spark and regular Android dispatches --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 78992c8e4f..5b0875d10e 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -19,7 +19,7 @@ env: FORCE_COLOR: 1 concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }}${{ inputs.spark_only && '-spark' || '' }} cancel-in-progress: true jobs: From 0b86febdc65052baa1a28b6cbba915a84cb1a4d8 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 19 Nov 2026 12:54:26 +0100 Subject: [PATCH 03/15] ci: run Spark in the local E2E nightly --- .github/workflows/e2e-local-nightly.yml | 104 ++++++++++++++++++++++++ .github/workflows/e2e.yml | 99 +--------------------- 2 files changed, 107 insertions(+), 96 deletions(-) create mode 100644 .github/workflows/e2e-local-nightly.yml diff --git a/.github/workflows/e2e-local-nightly.yml b/.github/workflows/e2e-local-nightly.yml new file mode 100644 index 0000000000..334a31cfa5 --- /dev/null +++ b/.github/workflows/e2e-local-nightly.yml @@ -0,0 +1,104 @@ +name: Local E2E Nightly (Android) + +on: + schedule: + - cron: "35 5 * * *" + workflow_dispatch: + inputs: + e2e_branch: + description: "Ref in synonymdev/bitkit-e2e-tests" + type: string + default: main + +permissions: + contents: read + packages: read + +env: + TERM: xterm-256color + FORCE_COLOR: 1 + +concurrency: + group: bitkit-local-e2e-nightly-${{ github.ref }} + cancel-in-progress: false + +jobs: + e2e-spark: + runs-on: ubuntu-latest + timeout-minutes: 120 + env: + COMPOSE_PROJECT_NAME: bitkit-spark-e2e + steps: + - name: Reserve regtest host ports + run: sudo sysctl -w net.ipv4.ip_local_reserved_ports=39388,43782,60001 + + - uses: actions/checkout@v7 + with: + path: bitkit-android + persist-credentials: false + + - uses: actions/checkout@v7 + with: + repository: synonymdev/bitkit-e2e-tests + ref: ${{ inputs.e2e_branch || 'main' }} + path: bitkit-e2e-tests + persist-credentials: false + + - uses: actions/setup-java@v6 + with: + java-version: "17" + distribution: temurin + + - uses: gradle/actions/setup-gradle@v6 + + - uses: actions/setup-node@v7 + with: + node-version: 22 + cache: npm + cache-dependency-path: bitkit-e2e-tests/package-lock.json + + - name: Install Appium dependencies + working-directory: bitkit-e2e-tests + run: npm ci + + - name: Start pinned Spark fixture + working-directory: bitkit-e2e-tests + run: | + ./scripts/local-backend spark-up + ./scripts/local-backend spark-env >> "$GITHUB_ENV" + + - name: Build Android Spark app + working-directory: bitkit-e2e-tests + env: + GITHUB_ACTOR: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./scripts/build-android-apk.sh + + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: Run @spark_1 + uses: reactivecircus/android-emulator-runner@v2 + with: + profile: pixel_6 + api-level: 33 + arch: x86_64 + avd-name: Pixel_6 + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none + script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android + + - name: Collect Spark logs + if: failure() + working-directory: bitkit-e2e-tests + run: | + mkdir -p artifacts + ./scripts/local-backend spark-logs --tail 200 > artifacts/spark-docker.log 2>&1 || true + + - uses: actions/upload-artifact@v7 + if: always() + with: + name: spark-android-${{ github.run_number }} + path: bitkit-e2e-tests/artifacts/ diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 5b0875d10e..695d01bbea 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -3,10 +3,6 @@ name: E2E on: workflow_dispatch: inputs: - spark_only: - description: "Run only @spark_1 on pinned local Spark" - type: boolean - default: false e2e_branch: description: "Branch of synonymdev/bitkit-e2e-tests to use (main | default-feature-branch | custom branch name)" required: false @@ -19,7 +15,7 @@ env: FORCE_COLOR: 1 concurrency: - group: ${{ github.workflow }}-${{ github.ref }}${{ inputs.spark_only && '-spark' || '' }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: @@ -44,7 +40,7 @@ jobs: build-local: needs: detect-changes - if: "!inputs.spark_only && github.event.pull_request.draft == false && needs.detect-changes.outputs.code == 'true'" + if: github.event.pull_request.draft == false && needs.detect-changes.outputs.code == 'true' runs-on: ubuntu-latest steps: @@ -272,97 +268,8 @@ jobs: if: failure() uses: jwalton/gh-docker-logs@v2 - e2e-spark: - if: inputs.spark_only - needs: e2e-branch - runs-on: ubuntu-latest - timeout-minutes: 120 - env: - COMPOSE_PROJECT_NAME: bitkit-spark-e2e - steps: - - name: Reserve regtest host ports - run: sudo sysctl -w net.ipv4.ip_local_reserved_ports=39388,43782,60001 - - - uses: actions/checkout@v7 - with: - path: bitkit-android - persist-credentials: false - - - name: Resolve E2E tests ref - id: e2e-ref - uses: synonymdev/bitkit-e2e-tests/.github/actions/resolve-e2e-ref@main - with: - selected: ${{ needs.e2e-branch.outputs.branch }} - e2e_branch_input: ${{ inputs.e2e_branch }} - - - uses: actions/checkout@v7 - with: - repository: synonymdev/bitkit-e2e-tests - ref: ${{ steps.e2e-ref.outputs.ref }} - path: bitkit-e2e-tests - persist-credentials: false - - - uses: actions/setup-java@v6 - with: - java-version: "17" - distribution: temurin - - - uses: gradle/actions/setup-gradle@v6 - - - uses: actions/setup-node@v7 - with: - node-version: 22 - cache: npm - cache-dependency-path: bitkit-e2e-tests/package-lock.json - - - name: Install Appium dependencies - working-directory: bitkit-e2e-tests - run: npm ci - - - name: Start pinned Spark fixture - working-directory: bitkit-e2e-tests - run: | - ./scripts/local-backend spark-up - ./scripts/local-backend spark-env >> "$GITHUB_ENV" - - - name: Build Android Spark app - working-directory: bitkit-e2e-tests - env: - GITHUB_ACTOR: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./scripts/build-android-apk.sh - - - name: Enable KVM - run: | - echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules - sudo udevadm control --reload-rules - sudo udevadm trigger --name-match=kvm - - - name: Run @spark_1 - uses: reactivecircus/android-emulator-runner@v2 - with: - profile: pixel_6 - api-level: 33 - arch: x86_64 - avd-name: Pixel_6 - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none - script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android - - - name: Collect Spark logs - if: failure() - working-directory: bitkit-e2e-tests - run: | - mkdir -p artifacts - ./scripts/local-backend spark-logs --tail 200 > artifacts/spark-docker.log 2>&1 || true - - - uses: actions/upload-artifact@v7 - if: always() - with: - name: spark-android-${{ github.run_number }} - path: bitkit-e2e-tests/artifacts/ - e2e-status: - if: always() && !inputs.spark_only && github.event.pull_request.draft == false + if: always() && github.event.pull_request.draft == false name: e2e-status runs-on: ubuntu-latest needs: [detect-changes, e2e-tests-local] From a45899162e29d8dac5db443e074900f3493b61e1 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 19 Nov 2026 12:57:59 +0100 Subject: [PATCH 04/15] ci: retry Spark nightly tests and retain attempt artifacts --- .github/workflows/e2e-local-nightly.yml | 45 +++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-local-nightly.yml b/.github/workflows/e2e-local-nightly.yml index 334a31cfa5..ca9d7d0d72 100644 --- a/.github/workflows/e2e-local-nightly.yml +++ b/.github/workflows/e2e-local-nightly.yml @@ -80,15 +80,54 @@ jobs: sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm - - name: Run @spark_1 + - name: Run @spark_1 (attempt 1) + continue-on-error: true + id: test1 uses: reactivecircus/android-emulator-runner@v2 with: profile: pixel_6 api-level: 33 arch: x86_64 avd-name: Pixel_6 - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none + force-avd-creation: false + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android + env: + RECORD_VIDEO: true + ATTEMPT: 1 + + - name: Run @spark_1 (attempt 2) + continue-on-error: true + id: test2 + if: steps.test1.outcome != 'success' + uses: reactivecircus/android-emulator-runner@v2 + with: + profile: pixel_6 + api-level: 33 + arch: x86_64 + avd-name: Pixel_6 + force-avd-creation: false + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none + script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android + env: + RECORD_VIDEO: true + ATTEMPT: 2 + + - name: Run @spark_1 (attempt 3) + id: test3 + if: steps.test1.outcome != 'success' && steps.test2.outcome != 'success' + uses: reactivecircus/android-emulator-runner@v2 + with: + profile: pixel_6 + api-level: 33 + arch: x86_64 + avd-name: Pixel_6 + force-avd-creation: false + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none + script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android + env: + RECORD_VIDEO: true + ATTEMPT: 3 - name: Collect Spark logs if: failure() @@ -97,8 +136,10 @@ jobs: mkdir -p artifacts ./scripts/local-backend spark-logs --tail 200 > artifacts/spark-docker.log 2>&1 || true + # Preserve logs and recordings from failed attempts even when a retry passes. - uses: actions/upload-artifact@v7 if: always() with: name: spark-android-${{ github.run_number }} path: bitkit-e2e-tests/artifacts/ + retention-days: 7 From 5982d421f223001805e695e90af243b1032ea8b1 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 19 Nov 2026 13:25:00 +0100 Subject: [PATCH 05/15] ci: restore pinned Spark images before nightly setup --- .github/workflows/e2e-local-nightly.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/e2e-local-nightly.yml b/.github/workflows/e2e-local-nightly.yml index ca9d7d0d72..a4d6d18a09 100644 --- a/.github/workflows/e2e-local-nightly.yml +++ b/.github/workflows/e2e-local-nightly.yml @@ -61,8 +61,16 @@ jobs: working-directory: bitkit-e2e-tests run: npm ci + - name: Cache pinned Spark images + uses: actions/cache@v6 + with: + path: ${{ runner.temp }}/bitkit-spark-images.tar + key: spark-images-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('bitkit-e2e-tests/BITKIT_DOCKER_REVISION') }} + - name: Start pinned Spark fixture working-directory: bitkit-e2e-tests + env: + SPARK_IMAGE_CACHE: ${{ runner.temp }}/bitkit-spark-images.tar run: | ./scripts/local-backend spark-up ./scripts/local-backend spark-env >> "$GITHUB_ENV" From 74c7d7af9345f458b31537a60b172d04f97112f2 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 20 Nov 2026 09:06:35 +0100 Subject: [PATCH 06/15] ci: summarize local E2E nightly in Slack --- .github/workflows/e2e-local-nightly.yml | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/.github/workflows/e2e-local-nightly.yml b/.github/workflows/e2e-local-nightly.yml index a4d6d18a09..136c286158 100644 --- a/.github/workflows/e2e-local-nightly.yml +++ b/.github/workflows/e2e-local-nightly.yml @@ -9,6 +9,10 @@ on: description: "Ref in synonymdev/bitkit-e2e-tests" type: string default: main + post_to_slack: + description: "Post Local E2E Nightly summary to Slack (#bitkit-staging-nightly)" + type: boolean + default: false permissions: contents: read @@ -26,6 +30,15 @@ jobs: e2e-spark: runs-on: ubuntu-latest timeout-minutes: 120 + outputs: + spark-case: >- + ${{ (steps.test1.outputs.spark-case == 'passed' || steps.test2.outputs.spark-case == 'passed' || + steps.test3.outputs.spark-case == 'passed') && 'success' || + (steps.test1.outputs.spark-case == 'started' || steps.test2.outputs.spark-case == 'started' || + steps.test3.outputs.spark-case == 'started') && 'failure' || '' }} + spark-fixture: ${{ steps.spark.outcome }} + e2e-sha: ${{ steps.e2e-source.outputs.commit }} + app-build: ${{ steps.app-build.outcome }} env: COMPOSE_PROJECT_NAME: bitkit-spark-e2e steps: @@ -38,6 +51,7 @@ jobs: persist-credentials: false - uses: actions/checkout@v7 + id: e2e-source with: repository: synonymdev/bitkit-e2e-tests ref: ${{ inputs.e2e_branch || 'main' }} @@ -68,6 +82,7 @@ jobs: key: spark-images-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('bitkit-e2e-tests/BITKIT_DOCKER_REVISION') }} - name: Start pinned Spark fixture + id: spark working-directory: bitkit-e2e-tests env: SPARK_IMAGE_CACHE: ${{ runner.temp }}/bitkit-spark-images.tar @@ -76,6 +91,7 @@ jobs: ./scripts/local-backend spark-env >> "$GITHUB_ENV" - name: Build Android Spark app + id: app-build working-directory: bitkit-e2e-tests env: GITHUB_ACTOR: ${{ github.actor }} @@ -151,3 +167,35 @@ jobs: name: spark-android-${{ github.run_number }} path: bitkit-e2e-tests/artifacts/ retention-days: 7 + + slack-report: + if: >- + always() && + (github.event_name == 'schedule' || + (github.event_name == 'workflow_dispatch' && inputs.post_to_slack == true)) + needs: e2e-spark + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read + steps: + - name: Checkout shared Slack reporter + uses: actions/checkout@v7 + with: + repository: synonymdev/bitkit-e2e-tests + ref: main + persist-credentials: false + + - name: Post Slack summary + run: python3 scripts/slack_summary.py e2e-local-nightly + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_STAGING }} + PLATFORM: android + LOCAL_NIGHTLY_RESULT: ${{ needs.e2e-spark.result }} + BUILD_RESULT: ${{ needs.e2e-spark.outputs.app-build }} + E2E_TESTS_REF: ${{ needs.e2e-spark.outputs.e2e-sha || inputs.e2e_branch || 'main' }} + SPARK_FIXTURE_RESULT: ${{ needs.e2e-spark.outputs.spark-fixture }} + E2E_TESTS_RESULT: ${{ needs.e2e-spark.result }} + SPARK_CASE_RESULT: ${{ needs.e2e-spark.outputs.spark-case }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + RUN_ATTEMPT: ${{ github.run_attempt }} From 946b139eb20670bb7ee138ee2d6ecc205e10553b Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 20 Nov 2026 09:10:13 +0100 Subject: [PATCH 07/15] ci: preserve explicit Spark case outcomes --- .github/workflows/e2e-local-nightly.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e-local-nightly.yml b/.github/workflows/e2e-local-nightly.yml index 136c286158..4d6c93e1e8 100644 --- a/.github/workflows/e2e-local-nightly.yml +++ b/.github/workflows/e2e-local-nightly.yml @@ -32,10 +32,10 @@ jobs: timeout-minutes: 120 outputs: spark-case: >- - ${{ (steps.test1.outputs.spark-case == 'passed' || steps.test2.outputs.spark-case == 'passed' || - steps.test3.outputs.spark-case == 'passed') && 'success' || - (steps.test1.outputs.spark-case == 'started' || steps.test2.outputs.spark-case == 'started' || - steps.test3.outputs.spark-case == 'started') && 'failure' || '' }} + ${{ contains(steps.*.outputs.spark-case, 'passed') && 'passed' || + contains(steps.*.outputs.spark-case, 'failed') && 'failed' || + contains(steps.*.outputs.spark-case, 'started') && 'started' || + contains(steps.*.outputs.spark-case, 'setup') && 'setup' || '' }} spark-fixture: ${{ steps.spark.outcome }} e2e-sha: ${{ steps.e2e-source.outputs.commit }} app-build: ${{ steps.app-build.outcome }} From ac3c8c46b2c1af82735b193de0776124ea02ee75 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 20 Nov 2026 09:13:30 +0100 Subject: [PATCH 08/15] ci: report Spark app setup failures across retries --- .github/workflows/e2e-local-nightly.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-local-nightly.yml b/.github/workflows/e2e-local-nightly.yml index 4d6c93e1e8..cf9e362ee4 100644 --- a/.github/workflows/e2e-local-nightly.yml +++ b/.github/workflows/e2e-local-nightly.yml @@ -34,8 +34,10 @@ jobs: spark-case: >- ${{ contains(steps.*.outputs.spark-case, 'passed') && 'passed' || contains(steps.*.outputs.spark-case, 'failed') && 'failed' || - contains(steps.*.outputs.spark-case, 'started') && 'started' || - contains(steps.*.outputs.spark-case, 'setup') && 'setup' || '' }} + contains(steps.*.outputs.spark-case, 'started') && 'started' || '' }} + spark-app-setup: >- + ${{ contains(steps.*.outputs.spark-case, 'setup-failed') && 'failure' || + contains(steps.*.outputs.spark-case, 'setup') && 'interrupted' || '' }} spark-fixture: ${{ steps.spark.outcome }} e2e-sha: ${{ steps.e2e-source.outputs.commit }} app-build: ${{ steps.app-build.outcome }} @@ -195,6 +197,7 @@ jobs: BUILD_RESULT: ${{ needs.e2e-spark.outputs.app-build }} E2E_TESTS_REF: ${{ needs.e2e-spark.outputs.e2e-sha || inputs.e2e_branch || 'main' }} SPARK_FIXTURE_RESULT: ${{ needs.e2e-spark.outputs.spark-fixture }} + SPARK_APP_SETUP_RESULT: ${{ needs.e2e-spark.outputs.spark-app-setup }} E2E_TESTS_RESULT: ${{ needs.e2e-spark.result }} SPARK_CASE_RESULT: ${{ needs.e2e-spark.outputs.spark-case }} RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} From 5fb7d15991180f76dff8f7c3f4e4b61c568336d8 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 20 Nov 2026 10:49:01 +0100 Subject: [PATCH 09/15] ci: temporarily dispatch the Spark nightly from the draft branch --- .github/workflows/e2e.yml | 316 ++++++++++++++------------------------ 1 file changed, 116 insertions(+), 200 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 695d01bbea..d481ba7c32 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,212 +1,112 @@ -name: E2E +name: Local E2E Nightly (Android) on: + schedule: + - cron: "35 5 * * *" workflow_dispatch: inputs: e2e_branch: - description: "Branch of synonymdev/bitkit-e2e-tests to use (main | default-feature-branch | custom branch name)" - required: false - default: "default-feature-branch" - pull_request: - types: [ opened, synchronize, reopened, ready_for_review ] + description: "Ref in synonymdev/bitkit-e2e-tests" + type: string + default: main + post_to_slack: + description: "Post Local E2E Nightly summary to Slack (#bitkit-staging-nightly)" + type: boolean + default: false + +permissions: + contents: read + packages: read env: TERM: xterm-256color FORCE_COLOR: 1 concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + group: bitkit-local-e2e-nightly-${{ github.ref }} + cancel-in-progress: false jobs: - detect-changes: - if: github.event.pull_request.draft == false + e2e-spark: runs-on: ubuntu-latest + timeout-minutes: 120 outputs: - code: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.code == 'true' }} + spark-case: >- + ${{ contains(steps.*.outputs.spark-case, 'passed') && 'passed' || + contains(steps.*.outputs.spark-case, 'failed') && 'failed' || + contains(steps.*.outputs.spark-case, 'started') && 'started' || '' }} + spark-app-setup: >- + ${{ contains(steps.*.outputs.spark-case, 'setup-failed') && 'failure' || + contains(steps.*.outputs.spark-case, 'setup') && 'interrupted' || '' }} + spark-fixture: ${{ steps.spark.outcome }} + e2e-sha: ${{ steps.e2e-source.outputs.commit }} + app-build: ${{ steps.app-build.outcome }} + env: + COMPOSE_PROJECT_NAME: bitkit-spark-e2e steps: - - uses: actions/checkout@v7 - - uses: dorny/paths-filter@v4 - if: github.event_name == 'pull_request' - id: filter - with: - filters: | - code: - - 'app/**' - - 'gradle/**' - - '*.gradle.kts' - - 'gradle.properties' - - '.github/workflows/e2e.yml' - - build-local: - needs: detect-changes - if: github.event.pull_request.draft == false && needs.detect-changes.outputs.code == 'true' - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v7 - - - name: Setup Java - uses: actions/setup-java@v6 - with: - java-version: "17" - distribution: "temurin" - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v6 - - - name: Decode google-services.json - run: | - set -euo pipefail - if [ -z "${GOOGLE_SERVICES_JSON_BASE64:-}" ]; then - echo "GOOGLE_SERVICES_JSON_BASE64 is empty; using checked-in placeholder." - exit 0 - fi - mkdir -p app/src/debug - printf '%s' "$GOOGLE_SERVICES_JSON_BASE64" | base64 -d > app/src/debug/google-services.json - env: - GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} - - - name: Build debug app (local) - env: - GITHUB_ACTOR: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CHATWOOT_API: ${{ secrets.CHATWOOT_API }} - E2E: true - run: ./gradlew assembleDevDebug - - - name: Rename APK - run: | - apk=$(find app/build/outputs/bitkit/devDebug -name 'bitkit-dev-debug-*-universal.apk') - mv "$apk" app/build/outputs/bitkit/devDebug/bitkit_e2e.apk - - - name: Upload APK (local) - uses: actions/upload-artifact@v7 - with: - name: bitkit-e2e-apk_${{ github.run_number }} - path: app/build/outputs/bitkit/devDebug/bitkit_e2e.apk - - e2e-branch: - needs: detect-changes - if: github.event.pull_request.draft == false && needs.detect-changes.outputs.code == 'true' - uses: synonymdev/bitkit-e2e-tests/.github/workflows/determine-e2e-branch.yml@main - with: - app_branch: ${{ github.head_ref || github.ref_name }} - e2e_branch_input: ${{ github.event.inputs.e2e_branch || 'default-feature-branch' }} - - e2e-tests-local: - if: github.event.pull_request.draft == false && needs.detect-changes.outputs.code == 'true' - runs-on: ubuntu-latest - needs: [detect-changes, build-local, e2e-branch] - - strategy: - fail-fast: false - matrix: - shard: - - { name: onboarding_backup_numberpad, grep: "@onboarding|@backup|@numberpad" } - - { name: onchain_boost_receive_widgets, grep: "@onchain|@boost|@receive|@widgets" } - - { name: settings, grep: "@settings" } - - { name: send, grep: "@send" } - - { name: lightning_security, grep: "@lightning|@security" } - - { name: lnurl_transfer, grep: "@lnurl|@transfer_2" } - - { name: multi_address_local, grep: "@multi_address_1|@multi_address_3|@multi_address_4" } - - name: e2e-tests-local - ${{ matrix.shard.name }} - - steps: - # The regtest stack publishes 39388 (bitcoind P2P), 43782 (bitcoind RPC) and 60001 (electrs) on the host. - # They sit in Linux's ephemeral range, so an outbound connection made before `docker compose up` - # (npm ci, image pulls) can take one and fail the bind. Reserve them before any network step. - name: Reserve regtest host ports - run: sudo sysctl -w net.ipv4.ip_local_reserved_ports=23009,23180,23735,39388,43782,60001 + run: sudo sysctl -w net.ipv4.ip_local_reserved_ports=39388,43782,60001 - - name: Resolve E2E tests ref - id: e2e-ref - uses: synonymdev/bitkit-e2e-tests/.github/actions/resolve-e2e-ref@main + - uses: actions/checkout@v7 with: - selected: ${{ needs.e2e-branch.outputs.branch }} - e2e_branch_input: ${{ github.event.inputs.e2e_branch || 'default-feature-branch' }} + path: bitkit-android + persist-credentials: false - - name: Clone E2E tests - uses: actions/checkout@v7 + - uses: actions/checkout@v7 + id: e2e-source with: repository: synonymdev/bitkit-e2e-tests + ref: ${{ inputs.e2e_branch || 'main' }} path: bitkit-e2e-tests - ref: ${{ steps.e2e-ref.outputs.ref }} - - - name: Enable KVM - run: | - echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules - sudo udevadm control --reload-rules - sudo udevadm trigger --name-match=kvm + persist-credentials: false - - name: AVD cache - uses: actions/cache@v6 - id: avd-cache + - uses: actions/setup-java@v6 with: - path: | - ~/.android/avd/* - ~/.android/adb* - key: avd-33-x86_64-pixel_6 - - - name: Create AVD and generate snapshot for caching - if: steps.avd-cache.outputs.cache-hit != 'true' - uses: reactivecircus/android-emulator-runner@v2 - with: - profile: pixel_6 - api-level: 33 - arch: x86_64 - avd-name: Pixel_6 - force-avd-creation: false - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none - disable-animations: false - script: echo "Generated AVD snapshot for caching." - - - name: Download APK - uses: actions/download-artifact@v8 - with: - name: bitkit-e2e-apk_${{ github.run_number }} - path: bitkit-e2e-tests/aut + java-version: "17" + distribution: temurin - - name: List APK directory contents - run: ls -l bitkit-e2e-tests/aut + - uses: gradle/actions/setup-gradle@v6 - - name: Setup Node.js - uses: actions/setup-node@v7 + - uses: actions/setup-node@v7 with: node-version: 22 + cache: npm + cache-dependency-path: bitkit-e2e-tests/package-lock.json + + - name: Install Appium dependencies + working-directory: bitkit-e2e-tests + run: npm ci - - name: Cache npm cache + - name: Cache pinned Spark images uses: actions/cache@v6 with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('bitkit-e2e-tests/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- + path: ${{ runner.temp }}/bitkit-spark-images.tar + key: spark-images-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('bitkit-e2e-tests/BITKIT_DOCKER_REVISION') }} - - name: Install dependencies + - name: Start pinned Spark fixture + id: spark working-directory: bitkit-e2e-tests - run: npm ci + env: + SPARK_IMAGE_CACHE: ${{ runner.temp }}/bitkit-spark-images.tar + run: | + ./scripts/local-backend spark-up + ./scripts/local-backend spark-env >> "$GITHUB_ENV" - - name: Run regtest setup + - name: Build Android Spark app + id: app-build working-directory: bitkit-e2e-tests - timeout-minutes: 10 + env: + GITHUB_ACTOR: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./scripts/build-android-apk.sh + + - name: Enable KVM run: | - if [[ -x ./scripts/local-backend ]]; then - ./scripts/local-backend up - ./scripts/local-backend github-env >> "$GITHUB_ENV" - else - # Older E2E refs still use their bundled Compose stack. - mkdir -p docker/lnd - chmod 777 docker/lnd - (cd docker && docker compose pull --quiet && docker compose up -d) - while ! nc -z '127.0.0.1' 60001; do sleep 1; done - sudo bash -c "while [ ! -f docker/lnd/data/chain/bitcoin/regtest/admin.macaroon ]; do sleep 1; done" - sudo chmod -R 777 docker/lnd - fi + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm - - name: Run E2E Tests 1 (${{ matrix.shard.name }}) + - name: Run @spark_1 (attempt 1) continue-on-error: true id: test1 uses: reactivecircus/android-emulator-runner@v2 @@ -217,12 +117,12 @@ jobs: avd-name: Pixel_6 force-avd-creation: false emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none - script: cd bitkit-e2e-tests && ./ci_run_android.sh --mochaOpts.grep "${{ matrix.shard.grep }}" + script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android env: RECORD_VIDEO: true ATTEMPT: 1 - - name: Run E2E Tests 2 (${{ matrix.shard.name }}) + - name: Run @spark_1 (attempt 2) continue-on-error: true id: test2 if: steps.test1.outcome != 'success' @@ -234,12 +134,12 @@ jobs: avd-name: Pixel_6 force-avd-creation: false emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none - script: cd bitkit-e2e-tests && ./ci_run_android.sh --mochaOpts.grep "${{ matrix.shard.grep }}" + script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android env: RECORD_VIDEO: true ATTEMPT: 2 - - name: Run E2E Tests 3 (${{ matrix.shard.name }}) + - name: Run @spark_1 (attempt 3) id: test3 if: steps.test1.outcome != 'success' && steps.test2.outcome != 'success' uses: reactivecircus/android-emulator-runner@v2 @@ -250,39 +150,55 @@ jobs: avd-name: Pixel_6 force-avd-creation: false emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none - script: cd bitkit-e2e-tests && ./ci_run_android.sh --mochaOpts.grep "${{ matrix.shard.grep }}" + script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android env: RECORD_VIDEO: true ATTEMPT: 3 - - name: Upload E2E Artifacts (${{ matrix.shard.name }}) - # Preserve failed-attempt evidence even when a retry passes. + - name: Collect Spark logs + if: failure() + working-directory: bitkit-e2e-tests + run: | + mkdir -p artifacts + ./scripts/local-backend spark-logs --tail 200 > artifacts/spark-docker.log 2>&1 || true + + # Preserve logs and recordings from failed attempts even when a retry passes. + - uses: actions/upload-artifact@v7 if: always() - uses: actions/upload-artifact@v7 with: - name: e2e-artifacts_${{ matrix.shard.name }}_${{ github.run_number }} + name: spark-android-${{ github.run_number }} path: bitkit-e2e-tests/artifacts/ retention-days: 7 - - name: Dump docker logs on failure (${{ matrix.shard.name }}) - if: failure() - uses: jwalton/gh-docker-logs@v2 - - e2e-status: - if: always() && github.event.pull_request.draft == false - name: e2e-status - runs-on: ubuntu-latest - needs: [detect-changes, e2e-tests-local] + slack-report: + if: >- + always() && + (github.event_name == 'schedule' || + (github.event_name == 'workflow_dispatch' && inputs.post_to_slack == true)) + needs: e2e-spark + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read steps: - - name: E2E skipped - no code changes - if: needs.detect-changes.outputs.code != 'true' - run: echo "✅ E2E skipped - no code changes" + - name: Checkout shared Slack reporter + uses: actions/checkout@v7 + with: + repository: synonymdev/bitkit-e2e-tests + ref: b7e445ad080827421f427fd26ae04b1782d8409c + persist-credentials: false - - name: Verify all E2E shards succeeded - if: needs.detect-changes.outputs.code == 'true' - run: | - if [ "${{ needs.e2e-tests-local.result }}" != "success" ]; then - echo "❌ Some E2E shards failed." - exit 1 - fi - echo "✅ All E2E shards passed!" + - name: Post Slack summary + run: python3 scripts/slack_summary.py e2e-local-nightly + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_STAGING }} + PLATFORM: android + LOCAL_NIGHTLY_RESULT: ${{ needs.e2e-spark.result }} + BUILD_RESULT: ${{ needs.e2e-spark.outputs.app-build }} + E2E_TESTS_REF: ${{ needs.e2e-spark.outputs.e2e-sha || inputs.e2e_branch || 'main' }} + SPARK_FIXTURE_RESULT: ${{ needs.e2e-spark.outputs.spark-fixture }} + SPARK_APP_SETUP_RESULT: ${{ needs.e2e-spark.outputs.spark-app-setup }} + E2E_TESTS_RESULT: ${{ needs.e2e-spark.result }} + SPARK_CASE_RESULT: ${{ needs.e2e-spark.outputs.spark-case }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + RUN_ATTEMPT: ${{ github.run_attempt }} From 5945b8d373ff89d5eed769be7b612ab023dd53b7 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 20 Nov 2026 10:49:02 +0100 Subject: [PATCH 10/15] ci: restore the regular E2E workflow after Spark dispatch --- .github/workflows/e2e.yml | 316 ++++++++++++++++++++++++-------------- 1 file changed, 200 insertions(+), 116 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index d481ba7c32..695d01bbea 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,112 +1,212 @@ -name: Local E2E Nightly (Android) +name: E2E on: - schedule: - - cron: "35 5 * * *" workflow_dispatch: inputs: e2e_branch: - description: "Ref in synonymdev/bitkit-e2e-tests" - type: string - default: main - post_to_slack: - description: "Post Local E2E Nightly summary to Slack (#bitkit-staging-nightly)" - type: boolean - default: false - -permissions: - contents: read - packages: read + description: "Branch of synonymdev/bitkit-e2e-tests to use (main | default-feature-branch | custom branch name)" + required: false + default: "default-feature-branch" + pull_request: + types: [ opened, synchronize, reopened, ready_for_review ] env: TERM: xterm-256color FORCE_COLOR: 1 concurrency: - group: bitkit-local-e2e-nightly-${{ github.ref }} - cancel-in-progress: false + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: - e2e-spark: + detect-changes: + if: github.event.pull_request.draft == false runs-on: ubuntu-latest - timeout-minutes: 120 outputs: - spark-case: >- - ${{ contains(steps.*.outputs.spark-case, 'passed') && 'passed' || - contains(steps.*.outputs.spark-case, 'failed') && 'failed' || - contains(steps.*.outputs.spark-case, 'started') && 'started' || '' }} - spark-app-setup: >- - ${{ contains(steps.*.outputs.spark-case, 'setup-failed') && 'failure' || - contains(steps.*.outputs.spark-case, 'setup') && 'interrupted' || '' }} - spark-fixture: ${{ steps.spark.outcome }} - e2e-sha: ${{ steps.e2e-source.outputs.commit }} - app-build: ${{ steps.app-build.outcome }} - env: - COMPOSE_PROJECT_NAME: bitkit-spark-e2e + code: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.code == 'true' }} steps: + - uses: actions/checkout@v7 + - uses: dorny/paths-filter@v4 + if: github.event_name == 'pull_request' + id: filter + with: + filters: | + code: + - 'app/**' + - 'gradle/**' + - '*.gradle.kts' + - 'gradle.properties' + - '.github/workflows/e2e.yml' + + build-local: + needs: detect-changes + if: github.event.pull_request.draft == false && needs.detect-changes.outputs.code == 'true' + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v7 + + - name: Setup Java + uses: actions/setup-java@v6 + with: + java-version: "17" + distribution: "temurin" + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Decode google-services.json + run: | + set -euo pipefail + if [ -z "${GOOGLE_SERVICES_JSON_BASE64:-}" ]; then + echo "GOOGLE_SERVICES_JSON_BASE64 is empty; using checked-in placeholder." + exit 0 + fi + mkdir -p app/src/debug + printf '%s' "$GOOGLE_SERVICES_JSON_BASE64" | base64 -d > app/src/debug/google-services.json + env: + GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} + + - name: Build debug app (local) + env: + GITHUB_ACTOR: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CHATWOOT_API: ${{ secrets.CHATWOOT_API }} + E2E: true + run: ./gradlew assembleDevDebug + + - name: Rename APK + run: | + apk=$(find app/build/outputs/bitkit/devDebug -name 'bitkit-dev-debug-*-universal.apk') + mv "$apk" app/build/outputs/bitkit/devDebug/bitkit_e2e.apk + + - name: Upload APK (local) + uses: actions/upload-artifact@v7 + with: + name: bitkit-e2e-apk_${{ github.run_number }} + path: app/build/outputs/bitkit/devDebug/bitkit_e2e.apk + + e2e-branch: + needs: detect-changes + if: github.event.pull_request.draft == false && needs.detect-changes.outputs.code == 'true' + uses: synonymdev/bitkit-e2e-tests/.github/workflows/determine-e2e-branch.yml@main + with: + app_branch: ${{ github.head_ref || github.ref_name }} + e2e_branch_input: ${{ github.event.inputs.e2e_branch || 'default-feature-branch' }} + + e2e-tests-local: + if: github.event.pull_request.draft == false && needs.detect-changes.outputs.code == 'true' + runs-on: ubuntu-latest + needs: [detect-changes, build-local, e2e-branch] + + strategy: + fail-fast: false + matrix: + shard: + - { name: onboarding_backup_numberpad, grep: "@onboarding|@backup|@numberpad" } + - { name: onchain_boost_receive_widgets, grep: "@onchain|@boost|@receive|@widgets" } + - { name: settings, grep: "@settings" } + - { name: send, grep: "@send" } + - { name: lightning_security, grep: "@lightning|@security" } + - { name: lnurl_transfer, grep: "@lnurl|@transfer_2" } + - { name: multi_address_local, grep: "@multi_address_1|@multi_address_3|@multi_address_4" } + + name: e2e-tests-local - ${{ matrix.shard.name }} + + steps: + # The regtest stack publishes 39388 (bitcoind P2P), 43782 (bitcoind RPC) and 60001 (electrs) on the host. + # They sit in Linux's ephemeral range, so an outbound connection made before `docker compose up` + # (npm ci, image pulls) can take one and fail the bind. Reserve them before any network step. - name: Reserve regtest host ports - run: sudo sysctl -w net.ipv4.ip_local_reserved_ports=39388,43782,60001 + run: sudo sysctl -w net.ipv4.ip_local_reserved_ports=23009,23180,23735,39388,43782,60001 - - uses: actions/checkout@v7 + - name: Resolve E2E tests ref + id: e2e-ref + uses: synonymdev/bitkit-e2e-tests/.github/actions/resolve-e2e-ref@main with: - path: bitkit-android - persist-credentials: false + selected: ${{ needs.e2e-branch.outputs.branch }} + e2e_branch_input: ${{ github.event.inputs.e2e_branch || 'default-feature-branch' }} - - uses: actions/checkout@v7 - id: e2e-source + - name: Clone E2E tests + uses: actions/checkout@v7 with: repository: synonymdev/bitkit-e2e-tests - ref: ${{ inputs.e2e_branch || 'main' }} path: bitkit-e2e-tests - persist-credentials: false + ref: ${{ steps.e2e-ref.outputs.ref }} + + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm - - uses: actions/setup-java@v6 + - name: AVD cache + uses: actions/cache@v6 + id: avd-cache with: - java-version: "17" - distribution: temurin + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-33-x86_64-pixel_6 - - uses: gradle/actions/setup-gradle@v6 + - name: Create AVD and generate snapshot for caching + if: steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + profile: pixel_6 + api-level: 33 + arch: x86_64 + avd-name: Pixel_6 + force-avd-creation: false + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none + disable-animations: false + script: echo "Generated AVD snapshot for caching." - - uses: actions/setup-node@v7 + - name: Download APK + uses: actions/download-artifact@v8 with: - node-version: 22 - cache: npm - cache-dependency-path: bitkit-e2e-tests/package-lock.json + name: bitkit-e2e-apk_${{ github.run_number }} + path: bitkit-e2e-tests/aut - - name: Install Appium dependencies - working-directory: bitkit-e2e-tests - run: npm ci + - name: List APK directory contents + run: ls -l bitkit-e2e-tests/aut + + - name: Setup Node.js + uses: actions/setup-node@v7 + with: + node-version: 22 - - name: Cache pinned Spark images + - name: Cache npm cache uses: actions/cache@v6 with: - path: ${{ runner.temp }}/bitkit-spark-images.tar - key: spark-images-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('bitkit-e2e-tests/BITKIT_DOCKER_REVISION') }} + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('bitkit-e2e-tests/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- - - name: Start pinned Spark fixture - id: spark + - name: Install dependencies working-directory: bitkit-e2e-tests - env: - SPARK_IMAGE_CACHE: ${{ runner.temp }}/bitkit-spark-images.tar - run: | - ./scripts/local-backend spark-up - ./scripts/local-backend spark-env >> "$GITHUB_ENV" + run: npm ci - - name: Build Android Spark app - id: app-build + - name: Run regtest setup working-directory: bitkit-e2e-tests - env: - GITHUB_ACTOR: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./scripts/build-android-apk.sh - - - name: Enable KVM + timeout-minutes: 10 run: | - echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules - sudo udevadm control --reload-rules - sudo udevadm trigger --name-match=kvm + if [[ -x ./scripts/local-backend ]]; then + ./scripts/local-backend up + ./scripts/local-backend github-env >> "$GITHUB_ENV" + else + # Older E2E refs still use their bundled Compose stack. + mkdir -p docker/lnd + chmod 777 docker/lnd + (cd docker && docker compose pull --quiet && docker compose up -d) + while ! nc -z '127.0.0.1' 60001; do sleep 1; done + sudo bash -c "while [ ! -f docker/lnd/data/chain/bitcoin/regtest/admin.macaroon ]; do sleep 1; done" + sudo chmod -R 777 docker/lnd + fi - - name: Run @spark_1 (attempt 1) + - name: Run E2E Tests 1 (${{ matrix.shard.name }}) continue-on-error: true id: test1 uses: reactivecircus/android-emulator-runner@v2 @@ -117,12 +217,12 @@ jobs: avd-name: Pixel_6 force-avd-creation: false emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none - script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android + script: cd bitkit-e2e-tests && ./ci_run_android.sh --mochaOpts.grep "${{ matrix.shard.grep }}" env: RECORD_VIDEO: true ATTEMPT: 1 - - name: Run @spark_1 (attempt 2) + - name: Run E2E Tests 2 (${{ matrix.shard.name }}) continue-on-error: true id: test2 if: steps.test1.outcome != 'success' @@ -134,12 +234,12 @@ jobs: avd-name: Pixel_6 force-avd-creation: false emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none - script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android + script: cd bitkit-e2e-tests && ./ci_run_android.sh --mochaOpts.grep "${{ matrix.shard.grep }}" env: RECORD_VIDEO: true ATTEMPT: 2 - - name: Run @spark_1 (attempt 3) + - name: Run E2E Tests 3 (${{ matrix.shard.name }}) id: test3 if: steps.test1.outcome != 'success' && steps.test2.outcome != 'success' uses: reactivecircus/android-emulator-runner@v2 @@ -150,55 +250,39 @@ jobs: avd-name: Pixel_6 force-avd-creation: false emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-front none - script: cd bitkit-e2e-tests && ./scripts/run-spark-e2e.sh android + script: cd bitkit-e2e-tests && ./ci_run_android.sh --mochaOpts.grep "${{ matrix.shard.grep }}" env: RECORD_VIDEO: true ATTEMPT: 3 - - name: Collect Spark logs - if: failure() - working-directory: bitkit-e2e-tests - run: | - mkdir -p artifacts - ./scripts/local-backend spark-logs --tail 200 > artifacts/spark-docker.log 2>&1 || true - - # Preserve logs and recordings from failed attempts even when a retry passes. - - uses: actions/upload-artifact@v7 + - name: Upload E2E Artifacts (${{ matrix.shard.name }}) + # Preserve failed-attempt evidence even when a retry passes. if: always() + uses: actions/upload-artifact@v7 with: - name: spark-android-${{ github.run_number }} + name: e2e-artifacts_${{ matrix.shard.name }}_${{ github.run_number }} path: bitkit-e2e-tests/artifacts/ retention-days: 7 - slack-report: - if: >- - always() && - (github.event_name == 'schedule' || - (github.event_name == 'workflow_dispatch' && inputs.post_to_slack == true)) - needs: e2e-spark - runs-on: ubuntu-24.04 - timeout-minutes: 5 - permissions: - contents: read + - name: Dump docker logs on failure (${{ matrix.shard.name }}) + if: failure() + uses: jwalton/gh-docker-logs@v2 + + e2e-status: + if: always() && github.event.pull_request.draft == false + name: e2e-status + runs-on: ubuntu-latest + needs: [detect-changes, e2e-tests-local] steps: - - name: Checkout shared Slack reporter - uses: actions/checkout@v7 - with: - repository: synonymdev/bitkit-e2e-tests - ref: b7e445ad080827421f427fd26ae04b1782d8409c - persist-credentials: false + - name: E2E skipped - no code changes + if: needs.detect-changes.outputs.code != 'true' + run: echo "✅ E2E skipped - no code changes" - - name: Post Slack summary - run: python3 scripts/slack_summary.py e2e-local-nightly - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_STAGING }} - PLATFORM: android - LOCAL_NIGHTLY_RESULT: ${{ needs.e2e-spark.result }} - BUILD_RESULT: ${{ needs.e2e-spark.outputs.app-build }} - E2E_TESTS_REF: ${{ needs.e2e-spark.outputs.e2e-sha || inputs.e2e_branch || 'main' }} - SPARK_FIXTURE_RESULT: ${{ needs.e2e-spark.outputs.spark-fixture }} - SPARK_APP_SETUP_RESULT: ${{ needs.e2e-spark.outputs.spark-app-setup }} - E2E_TESTS_RESULT: ${{ needs.e2e-spark.result }} - SPARK_CASE_RESULT: ${{ needs.e2e-spark.outputs.spark-case }} - RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - RUN_ATTEMPT: ${{ github.run_attempt }} + - name: Verify all E2E shards succeeded + if: needs.detect-changes.outputs.code == 'true' + run: | + if [ "${{ needs.e2e-tests-local.result }}" != "success" ]; then + echo "❌ Some E2E shards failed." + exit 1 + fi + echo "✅ All E2E shards passed!" From e7a035dd12eb0ddcefe0269dfc95749dd16f3767 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 20 Nov 2026 11:47:05 +0100 Subject: [PATCH 11/15] ci: report local nightly results by job --- .github/workflows/e2e-local-nightly.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/workflows/e2e-local-nightly.yml b/.github/workflows/e2e-local-nightly.yml index cf9e362ee4..5b753e2b86 100644 --- a/.github/workflows/e2e-local-nightly.yml +++ b/.github/workflows/e2e-local-nightly.yml @@ -31,16 +31,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 120 outputs: - spark-case: >- - ${{ contains(steps.*.outputs.spark-case, 'passed') && 'passed' || - contains(steps.*.outputs.spark-case, 'failed') && 'failed' || - contains(steps.*.outputs.spark-case, 'started') && 'started' || '' }} - spark-app-setup: >- - ${{ contains(steps.*.outputs.spark-case, 'setup-failed') && 'failure' || - contains(steps.*.outputs.spark-case, 'setup') && 'interrupted' || '' }} - spark-fixture: ${{ steps.spark.outcome }} e2e-sha: ${{ steps.e2e-source.outputs.commit }} - app-build: ${{ steps.app-build.outcome }} env: COMPOSE_PROJECT_NAME: bitkit-spark-e2e steps: @@ -84,7 +75,6 @@ jobs: key: spark-images-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('bitkit-e2e-tests/BITKIT_DOCKER_REVISION') }} - name: Start pinned Spark fixture - id: spark working-directory: bitkit-e2e-tests env: SPARK_IMAGE_CACHE: ${{ runner.temp }}/bitkit-spark-images.tar @@ -93,7 +83,6 @@ jobs: ./scripts/local-backend spark-env >> "$GITHUB_ENV" - name: Build Android Spark app - id: app-build working-directory: bitkit-e2e-tests env: GITHUB_ACTOR: ${{ github.actor }} @@ -194,11 +183,7 @@ jobs: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_STAGING }} PLATFORM: android LOCAL_NIGHTLY_RESULT: ${{ needs.e2e-spark.result }} - BUILD_RESULT: ${{ needs.e2e-spark.outputs.app-build }} E2E_TESTS_REF: ${{ needs.e2e-spark.outputs.e2e-sha || inputs.e2e_branch || 'main' }} - SPARK_FIXTURE_RESULT: ${{ needs.e2e-spark.outputs.spark-fixture }} - SPARK_APP_SETUP_RESULT: ${{ needs.e2e-spark.outputs.spark-app-setup }} E2E_TESTS_RESULT: ${{ needs.e2e-spark.result }} - SPARK_CASE_RESULT: ${{ needs.e2e-spark.outputs.spark-case }} RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} RUN_ATTEMPT: ${{ github.run_attempt }} From bf713999d281a7624fd232bece05e47f3e83b2c3 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 20 Nov 2026 12:02:51 +0100 Subject: [PATCH 12/15] ci: use reusable E2E retry step names --- .github/workflows/e2e-local-nightly.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-local-nightly.yml b/.github/workflows/e2e-local-nightly.yml index 5b753e2b86..18c6e0dc43 100644 --- a/.github/workflows/e2e-local-nightly.yml +++ b/.github/workflows/e2e-local-nightly.yml @@ -95,7 +95,7 @@ jobs: sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm - - name: Run @spark_1 (attempt 1) + - name: Run E2E tests (attempt 1) continue-on-error: true id: test1 uses: reactivecircus/android-emulator-runner@v2 @@ -111,7 +111,7 @@ jobs: RECORD_VIDEO: true ATTEMPT: 1 - - name: Run @spark_1 (attempt 2) + - name: Run E2E tests (attempt 2) continue-on-error: true id: test2 if: steps.test1.outcome != 'success' @@ -128,7 +128,7 @@ jobs: RECORD_VIDEO: true ATTEMPT: 2 - - name: Run @spark_1 (attempt 3) + - name: Run E2E tests (attempt 3) id: test3 if: steps.test1.outcome != 'success' && steps.test2.outcome != 'success' uses: reactivecircus/android-emulator-runner@v2 From 02aeced20fc27cbf6a45fe1557094efeab3f473f Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 20 Nov 2026 13:27:28 +0100 Subject: [PATCH 13/15] test: align local Spark chain access and retain nightly diagnostics --- .github/workflows/e2e-local-nightly.yml | 30 ++++++++++++++-- .../java/to/bitkit/data/SparkPayoutChain.kt | 5 ++- app/src/main/java/to/bitkit/env/Env.kt | 36 +++++++++++++++---- .../to/bitkit/repositories/SparkExitChain.kt | 7 ++-- .../java/to/bitkit/services/SparkService.kt | 34 +++++++----------- .../settings/lightning/SparkDetailScreen.kt | 2 +- .../to/bitkit/env/SparkChainServiceTest.kt | 25 ++++++++++--- .../bitkit/repositories/SparkExitChainTest.kt | 14 +++++--- .../repositories/SparkExitRegtestTest.kt | 6 +++- .../to/bitkit/services/SparkServiceTest.kt | 36 +++++++++++++++++++ 10 files changed, 149 insertions(+), 46 deletions(-) diff --git a/.github/workflows/e2e-local-nightly.yml b/.github/workflows/e2e-local-nightly.yml index 18c6e0dc43..75b042b775 100644 --- a/.github/workflows/e2e-local-nightly.yml +++ b/.github/workflows/e2e-local-nightly.yml @@ -51,6 +51,14 @@ jobs: path: bitkit-e2e-tests persist-credentials: false + - name: Check shared E2E branch for cache writes + id: cache-source + working-directory: bitkit-e2e-tests + run: | + if [[ "$(git symbolic-ref --quiet HEAD)" == refs/heads/main ]]; then + echo 'save-cache=true' >> "$GITHUB_OUTPUT" + fi + - uses: actions/setup-java@v6 with: java-version: "17" @@ -68,19 +76,35 @@ jobs: working-directory: bitkit-e2e-tests run: npm ci - - name: Cache pinned Spark images - uses: actions/cache@v6 + - name: Restore pinned Spark images + id: spark-cache + uses: actions/cache/restore@v6 + continue-on-error: true with: path: ${{ runner.temp }}/bitkit-spark-images.tar key: spark-images-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('bitkit-e2e-tests/BITKIT_DOCKER_REVISION') }} - name: Start pinned Spark fixture + id: fixture working-directory: bitkit-e2e-tests env: SPARK_IMAGE_CACHE: ${{ runner.temp }}/bitkit-spark-images.tar run: | ./scripts/local-backend spark-up ./scripts/local-backend spark-env >> "$GITHUB_ENV" + if [[ -s "$SPARK_IMAGE_CACHE" ]]; then + echo 'cache-ready=true' >> "$GITHUB_OUTPUT" + fi + + - name: Save pinned Spark images + if: >- + steps.cache-source.outputs.save-cache == 'true' && steps.fixture.outputs.cache-ready == 'true' && + steps.spark-cache.outputs.cache-hit != 'true' && steps.spark-cache.outputs.cache-primary-key != '' + uses: actions/cache/save@v6 + continue-on-error: true + with: + path: ${{ runner.temp }}/bitkit-spark-images.tar + key: ${{ steps.spark-cache.outputs.cache-primary-key }} - name: Build Android Spark app working-directory: bitkit-e2e-tests @@ -145,7 +169,7 @@ jobs: ATTEMPT: 3 - name: Collect Spark logs - if: failure() + if: failure() || steps.test1.outcome == 'failure' || steps.test2.outcome == 'failure' working-directory: bitkit-e2e-tests run: | mkdir -p artifacts diff --git a/app/src/main/java/to/bitkit/data/SparkPayoutChain.kt b/app/src/main/java/to/bitkit/data/SparkPayoutChain.kt index eb0a2b55c3..dfc78f3728 100644 --- a/app/src/main/java/to/bitkit/data/SparkPayoutChain.kt +++ b/app/src/main/java/to/bitkit/data/SparkPayoutChain.kt @@ -26,13 +26,12 @@ class SparkPayoutChain @Inject constructor( ) { companion object { private const val TAG = "SparkPayoutChain" - private const val SPARK_REGTEST_ESPLORA_URL = "https://regtest-mempool.us-west-2.sparkinfra.net/api" private val json = Json { ignoreUnknownKeys = true } /** The Esplora to ask on [network]: the one Spark reads there, or null where the app knows none. */ - fun esploraUrl(network: Network): String? = when (network) { + fun esploraUrl(network: Network, regtestUrl: String? = Env.sparkRegtestEsploraUrl()): String? = when (network) { Network.BITCOIN -> Env.bitkitEsploraUrl - Network.REGTEST -> SPARK_REGTEST_ESPLORA_URL + Network.REGTEST -> regtestUrl else -> null } } diff --git a/app/src/main/java/to/bitkit/env/Env.kt b/app/src/main/java/to/bitkit/env/Env.kt index da2b17ec7d..7a3bbcb3d9 100644 --- a/app/src/main/java/to/bitkit/env/Env.kt +++ b/app/src/main/java/to/bitkit/env/Env.kt @@ -12,6 +12,10 @@ import java.io.File import kotlin.io.path.Path import com.synonym.bitkitcore.Network as BitkitCoreNetwork +internal data class LocalSparkSettings(val configBase64: String, val chainUrl: String) { + val isComplete: Boolean get() = configBase64.isNotBlank() && chainUrl.isNotBlank() +} + @Suppress("ConstPropertyName", "KotlinConstantConditions", "SimplifyBooleanWithConstants") internal object Env { val isUsdtEnabled: Boolean get() = (network == Network.BITCOIN || isDebug) && @@ -51,6 +55,12 @@ internal object Env { const val e2eHomegateUrl = BuildConfig.E2E_HOMEGATE_URL val e2eHomeserverPubky = BuildConfig.E2E_HOMESERVER_PUBKY.takeIf { isLocalE2eBackend && it.isNotBlank() } val network = Network.valueOf(BuildConfig.NETWORK) + val localSparkSettings = if (isDebug && isLocalE2eBackend && network == Network.REGTEST) { + LocalSparkSettings(BuildConfig.SPARK_LOCAL_CONFIG_B64, BuildConfig.SPARK_LOCAL_CHAIN_URL.trimEnd('/')) + .takeIf { it.configBase64.isNotBlank() || it.chainUrl.isNotBlank() } + } else { + null + } val locales = BuildConfig.LOCALES.split(",") const val walletSyncIntervalSecs = 10_uL const val walletSyncTimeoutSecs = 10_uL @@ -145,20 +155,32 @@ internal object Env { /** * Whether the node's chain is the one Spark watches, so an on-chain funding of Spark from Savings or a hardware - * wallet reaches it. On regtest Spark runs on Lightspark's own chain, which the node joins only through the - * Spark regtest Esplora proxy. + * wallet reaches it. Hosted regtest supports the node's Spark Esplora proxy. The local fixture config selects + * Spark's chain only; the node and hardware wallet can use independently configured Electrum servers. */ - fun sparkSharesNodeChain(network: Network, regtestEsploraUrl: String?): Boolean = - network != Network.REGTEST || regtestEsploraUrl != null + fun sparkSharesNodeChain(network: Network, regtestEsploraUrl: String?, localSpark: LocalSparkSettings?): Boolean = + network != Network.REGTEST || (localSpark == null && regtestEsploraUrl != null) - val sparkSharesNodeChain: Boolean get() = sparkSharesNodeChain(network, regtestEsploraUrl) + val sparkSharesNodeChain: Boolean get() = sparkSharesNodeChain(network, regtestEsploraUrl, localSparkSettings) - /** Esplora REST that Spark reads the chain from; null keeps the SDK's default, on staging and regtest. */ - fun sparkChainServiceUrl(network: Network): String? = when (network) { + /** REST endpoint for the Spark SDK. An unconfigured regtest uses the SDK's hosted default. */ + fun sparkChainServiceUrl( + network: Network, + localSpark: LocalSparkSettings? = localSparkSettings, + ): String? = when (network) { Network.BITCOIN -> bitkitEsploraUrl + Network.REGTEST -> localSpark?.takeIf { it.isComplete }?.chainUrl else -> null } + /** Regtest endpoint for app-side payout reads and emergency-exit reads and broadcasts. */ + fun sparkRegtestEsploraUrl(localSpark: LocalSparkSettings? = localSparkSettings): String? = + if (localSpark == null) { + "https://regtest-mempool.us-west-2.sparkinfra.net/api" + } else { + sparkChainServiceUrl(Network.REGTEST, localSpark) + } + val blocktankBaseUrl get() = when (network) { Network.BITCOIN -> "https://api1.blocktank.to" diff --git a/app/src/main/java/to/bitkit/repositories/SparkExitChain.kt b/app/src/main/java/to/bitkit/repositories/SparkExitChain.kt index f779833419..b10aae9379 100644 --- a/app/src/main/java/to/bitkit/repositories/SparkExitChain.kt +++ b/app/src/main/java/to/bitkit/repositories/SparkExitChain.kt @@ -171,7 +171,10 @@ class EsploraSparkExitChain( * The chain the Spark SDK reads per network. Mainnet reads Bitkit's own esplora alone, which takes a package * on `/txs/package` only, and broadcasts there first, then through the SDK's former default hosts. */ - fun defaultHosts(sparkNetwork: String?): SparkExitHosts? = when (sparkNetwork) { + fun defaultHosts( + sparkNetwork: String?, + regtestUrl: String? = Env.sparkRegtestEsploraUrl(), + ): SparkExitHosts? = when (sparkNetwork) { "mainnet" -> SparkExitHosts( reads = listOf(Env.bitkitEsploraUrl), broadcasts = listOf( @@ -180,7 +183,7 @@ class EsploraSparkExitChain( SparkExitBroadcastHost("https://blockstream.info/api"), ), ) - "regtest" -> SparkExitHosts.of("https://regtest-mempool.us-west-2.sparkinfra.net/api") + "regtest" -> regtestUrl?.let { SparkExitHosts.of(it) } else -> null } diff --git a/app/src/main/java/to/bitkit/services/SparkService.kt b/app/src/main/java/to/bitkit/services/SparkService.kt index e88dcd24e7..874b43c4f6 100644 --- a/app/src/main/java/to/bitkit/services/SparkService.kt +++ b/app/src/main/java/to/bitkit/services/SparkService.kt @@ -51,9 +51,9 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import org.lightningdevkit.ldknode.Bolt11Invoice import org.lightningdevkit.ldknode.Network -import to.bitkit.BuildConfig import to.bitkit.data.keychain.Keychain import to.bitkit.env.Env +import to.bitkit.env.LocalSparkSettings import to.bitkit.ext.runSuspendCatching import to.bitkit.models.safe import to.bitkit.repositories.SparkExitRecovering @@ -100,6 +100,16 @@ class SparkService @Inject constructor( leafOptimizationConfig = leafOptimizationConfig.copy(autoEnabled = !isExiting) } + /** Applies the pinned operator settings and selects the fixture's mempool.space REST API. */ + internal fun configureLocalSpark(config: Config, settings: LocalSparkSettings?): ChainApiType { + if (settings == null) return ChainApiType.ESPLORA + require(settings.isComplete) { "Local Spark requires SPARK_LOCAL_CONFIG_B64 and SPARK_LOCAL_CHAIN_URL" } + config.sparkConfig = parseSparkConfig(Base64.getDecoder().decode(settings.configBase64).decodeToString()) + // The pinned regtest operators require anchored refunds. + config.watchtowerFeeLadderEnabled = false + return ChainApiType.MEMPOOL_SPACE + } + /** Leeway in sat/vB over the recommended fee that an automatic deposit claim may pay. */ private const val DEPOSIT_CLAIM_FEE_LEEWAY_SAT_PER_VB = 2uL @@ -182,16 +192,11 @@ class SparkService @Inject constructor( val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name) val config = configure(defaultConfig(network), Env.breezApiKey, isExiting) val storageDir = File(Env.sparkStoragePath(walletIndex)).apply { mkdirs() }.path - val localChainUrl = if (Env.isDebug && Env.isLocalE2eBackend && network == SparkNetwork.REGTEST) { - localSparkChainUrl(config) - } else { - null - } - val chainServiceUrl = localChainUrl ?: Env.sparkChainServiceUrl(Env.network) + val apiType = configureLocalSpark(config, Env.localSparkSettings) + val chainServiceUrl = Env.sparkChainServiceUrl(Env.network) val connected = SdkBuilder(config, Seed.Mnemonic(mnemonic, passphrase)).use { builder -> builder.withDefaultStorage(storageDir) chainServiceUrl?.let { - val apiType = if (localChainUrl != null) ChainApiType.MEMPOOL_SPACE else ChainApiType.ESPLORA builder.withRestChainService(it, apiType, null) } builder.build() @@ -209,19 +214,6 @@ class SparkService @Inject constructor( true } - private fun localSparkChainUrl(config: Config): String? { - val encoded = BuildConfig.SPARK_LOCAL_CONFIG_B64 - val chainUrl = BuildConfig.SPARK_LOCAL_CHAIN_URL - if (encoded.isBlank() && chainUrl.isBlank()) return null - require(encoded.isNotBlank() && chainUrl.isNotBlank()) { - "Local Spark requires SPARK_LOCAL_CONFIG_B64 and SPARK_LOCAL_CHAIN_URL" - } - config.sparkConfig = parseSparkConfig(Base64.getDecoder().decode(encoded).decodeToString()) - // The pinned regtest operators require anchored refunds. - config.watchtowerFeeLadderEnabled = false - return chainUrl - } - suspend fun disconnect() = mutex.withLock { val current = sdk ?: return@withLock try { diff --git a/app/src/main/java/to/bitkit/ui/settings/lightning/SparkDetailScreen.kt b/app/src/main/java/to/bitkit/ui/settings/lightning/SparkDetailScreen.kt index 9cfa727125..56169eeb7e 100644 --- a/app/src/main/java/to/bitkit/ui/settings/lightning/SparkDetailScreen.kt +++ b/app/src/main/java/to/bitkit/ui/settings/lightning/SparkDetailScreen.kt @@ -135,7 +135,7 @@ private fun Content( SectionRow( name = stringResource(R.string.lightning__spending_label), valueContent = { MoneyCaptionB(sats = spark.balanceSats.toLong(), symbol = true) }, - modifier = Modifier.testTag("SparkBalance"), + modifier = Modifier.testTag("SparkBalance") ) if (spark.pendingDeposits.isNotEmpty()) { diff --git a/app/src/test/java/to/bitkit/env/SparkChainServiceTest.kt b/app/src/test/java/to/bitkit/env/SparkChainServiceTest.kt index 86eb15a492..ebb1765be3 100644 --- a/app/src/test/java/to/bitkit/env/SparkChainServiceTest.kt +++ b/app/src/test/java/to/bitkit/env/SparkChainServiceTest.kt @@ -2,12 +2,15 @@ package to.bitkit.env import org.junit.Test import org.lightningdevkit.ldknode.Network +import to.bitkit.data.SparkPayoutChain import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertNull import kotlin.test.assertTrue class SparkChainServiceTest { + private val local = LocalSparkSettings("encoded", "http://127.0.0.1:23090/api") + @Test fun `spark reads the chain from bitkit electrs on mainnet`() { assertEquals("https://bitkit.to/electrs", Env.sparkChainServiceUrl(Network.BITCOIN)) @@ -15,15 +18,29 @@ class SparkChainServiceTest { @Test fun `spark keeps the sdk default chain service off mainnet`() { - assertNull(Env.sparkChainServiceUrl(Network.REGTEST)) + assertNull(Env.sparkChainServiceUrl(Network.REGTEST, localSpark = null)) assertNull(Env.sparkChainServiceUrl(Network.TESTNET)) assertNull(Env.sparkChainServiceUrl(Network.SIGNET)) } + @Test + fun `a complete fixture routes only regtest to its chain`() { + assertEquals(local.chainUrl, Env.sparkChainServiceUrl(Network.REGTEST, local)) + assertEquals(local.chainUrl, SparkPayoutChain.esploraUrl(Network.REGTEST, Env.sparkRegtestEsploraUrl(local))) + assertEquals(Env.bitkitEsploraUrl, Env.sparkChainServiceUrl(Network.BITCOIN, local)) + assertNull(Env.sparkChainServiceUrl(Network.SIGNET, local)) + assertNull(Env.sparkChainServiceUrl(Network.REGTEST, local.copy(configBase64 = ""))) + assertNull(Env.sparkRegtestEsploraUrl(local.copy(chainUrl = ""))) + } + @Test fun `on-chain spark funding needs the spark regtest chain on regtest`() { - assertFalse(Env.sparkSharesNodeChain(Network.REGTEST, regtestEsploraUrl = null)) - assertTrue(Env.sparkSharesNodeChain(Network.REGTEST, regtestEsploraUrl = "http://10.0.2.2:3999")) - assertTrue(Env.sparkSharesNodeChain(Network.BITCOIN, regtestEsploraUrl = null)) + assertFalse(Env.sparkSharesNodeChain(Network.REGTEST, regtestEsploraUrl = null, localSpark = null)) + assertTrue(Env.sparkSharesNodeChain(Network.REGTEST, "http://10.0.2.2:3999", localSpark = null)) + assertTrue(Env.sparkSharesNodeChain(Network.BITCOIN, regtestEsploraUrl = null, localSpark = null)) + assertFalse(Env.sparkSharesNodeChain(Network.REGTEST, regtestEsploraUrl = null, localSpark = local)) + assertFalse(Env.sparkSharesNodeChain(Network.REGTEST, local.chainUrl, local)) + assertFalse(Env.sparkSharesNodeChain(Network.REGTEST, "http://10.0.2.2:3999", local)) + assertFalse(Env.sparkSharesNodeChain(Network.REGTEST, null, local.copy(configBase64 = ""))) } } diff --git a/app/src/test/java/to/bitkit/repositories/SparkExitChainTest.kt b/app/src/test/java/to/bitkit/repositories/SparkExitChainTest.kt index 7bb8a1b1d7..5d55a2cd2a 100644 --- a/app/src/test/java/to/bitkit/repositories/SparkExitChainTest.kt +++ b/app/src/test/java/to/bitkit/repositories/SparkExitChainTest.kt @@ -14,6 +14,7 @@ import io.ktor.http.HttpStatusCode import io.ktor.http.contentType import io.ktor.utils.io.errors.IOException import org.junit.Test +import to.bitkit.env.Env import to.bitkit.test.BaseUnitTest import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -429,10 +430,15 @@ class SparkExitChainTest : BaseUnitTest() { } @Test - fun `regtest reads and broadcasts on the sdk host`() { - val regtest = "https://regtest-mempool.us-west-2.sparkinfra.net/api" - - assertEquals(SparkExitHosts.of(regtest), EsploraSparkExitChain.defaultHosts("regtest")) + fun `regtest reads and broadcasts on the selected spark chain`() { + val fixture = "http://127.0.0.1:23090/api" + assertEquals(SparkExitHosts.of(fixture), EsploraSparkExitChain.defaultHosts("regtest", fixture)) + val hosted = "https://regtest-mempool.us-west-2.sparkinfra.net/api" + assertEquals( + SparkExitHosts.of(hosted), + EsploraSparkExitChain.defaultHosts("regtest", Env.sparkRegtestEsploraUrl(null)), + ) + assertEquals(null, EsploraSparkExitChain.defaultHosts("regtest", regtestUrl = null)) assertEquals(null, EsploraSparkExitChain.defaultHosts("signet")) } } diff --git a/app/src/test/java/to/bitkit/repositories/SparkExitRegtestTest.kt b/app/src/test/java/to/bitkit/repositories/SparkExitRegtestTest.kt index 77d3f1f62e..eb5c2909ef 100644 --- a/app/src/test/java/to/bitkit/repositories/SparkExitRegtestTest.kt +++ b/app/src/test/java/to/bitkit/repositories/SparkExitRegtestTest.kt @@ -4,6 +4,7 @@ import io.ktor.client.HttpClient import org.junit.Assume.assumeTrue import org.junit.Before import org.junit.Test +import to.bitkit.env.Env import to.bitkit.test.BaseUnitTest import kotlin.test.assertIs import kotlin.test.assertTrue @@ -13,7 +14,10 @@ import kotlin.test.assertTrue * `SPARK_EXIT_REGTEST=1` in the environment of `just test file SparkExitRegtestTest`. */ class SparkExitRegtestTest : BaseUnitTest() { - private val chain = EsploraSparkExitChain(checkNotNull(EsploraSparkExitChain.defaultHosts("regtest")), HttpClient()) + private val chain = EsploraSparkExitChain( + checkNotNull(EsploraSparkExitChain.defaultHosts("regtest", Env.sparkRegtestEsploraUrl(localSpark = null))), + HttpClient(), + ) @Before fun requireOptIn() { diff --git a/app/src/test/java/to/bitkit/services/SparkServiceTest.kt b/app/src/test/java/to/bitkit/services/SparkServiceTest.kt index 4671099654..422e11b8b3 100644 --- a/app/src/test/java/to/bitkit/services/SparkServiceTest.kt +++ b/app/src/test/java/to/bitkit/services/SparkServiceTest.kt @@ -1,20 +1,27 @@ package to.bitkit.services +import breez_sdk_spark.ChainApiType import breez_sdk_spark.Config import breez_sdk_spark.LeafOptimizationConfig import breez_sdk_spark.Network import breez_sdk_spark.SendPaymentOptions +import breez_sdk_spark.SparkConfig import breez_sdk_spark.TokenOptimizationConfig +import breez_sdk_spark.parseSparkConfig import kotlinx.coroutines.test.runTest import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder +import org.mockito.Mockito.mockStatic import org.mockito.kotlin.mock import org.mockito.kotlin.verifyNoInteractions import to.bitkit.data.keychain.Keychain import to.bitkit.env.Env +import to.bitkit.env.LocalSparkSettings import java.io.File +import java.util.Base64 import kotlin.test.assertEquals +import kotlin.test.assertFailsWith import kotlin.test.assertFalse import kotlin.test.assertIs import kotlin.test.assertNull @@ -124,6 +131,35 @@ class SparkServiceTest { } } + @Test + fun `local spark selects the fixture operators and mempool API together`() { + val config = defaults(Network.REGTEST) + val json = """{"threshold":2}""" + val settings = LocalSparkSettings(Base64.getEncoder().encodeToString(json.toByteArray()), "http://fixture/api") + val operators = mock() + + mockStatic(Class.forName("breez_sdk_spark.Breez_sdk_spark_jvmKt")).use { native -> + native.`when` { parseSparkConfig(json) }.thenReturn(operators) + assertEquals(ChainApiType.MEMPOOL_SPACE, SparkService.configureLocalSpark(config, settings)) + assertEquals(operators, config.sparkConfig) + assertEquals(false, config.watchtowerFeeLadderEnabled) + } + } + + @Test + fun `local spark requires both fixture values and leaves defaults untouched without a fixture`() { + val config = defaults(Network.REGTEST) + assertEquals(ChainApiType.ESPLORA, SparkService.configureLocalSpark(config, null)) + for (settings in listOf(LocalSparkSettings("encoded", ""), LocalSparkSettings("", "http://fixture/api"))) { + assertFailsWith { SparkService.configureLocalSpark(config, settings) } + } + assertFailsWith { + SparkService.configureLocalSpark(config, LocalSparkSettings("invalid base64", "http://fixture/api")) + } + assertNull(config.sparkConfig) + assertNull(config.watchtowerFeeLadderEnabled) + } + @Test fun `invoices carry no spark address on any network, so every payment is a lightning payment bitkit records`() { Network.entries.forEach { network -> From 4909f8dadff1c81fe2d1e1d6a77439b84b0f33b2 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 20 Nov 2026 18:01:07 +0100 Subject: [PATCH 14/15] test: preserve complete Spark retry logs and reject incomplete fixture input --- .github/workflows/e2e-local-nightly.yml | 2 +- app/src/main/java/to/bitkit/env/Env.kt | 10 ++++++++-- .../test/java/to/bitkit/env/SparkChainServiceTest.kt | 9 +++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-local-nightly.yml b/.github/workflows/e2e-local-nightly.yml index 75b042b775..9fdd32d14c 100644 --- a/.github/workflows/e2e-local-nightly.yml +++ b/.github/workflows/e2e-local-nightly.yml @@ -173,7 +173,7 @@ jobs: working-directory: bitkit-e2e-tests run: | mkdir -p artifacts - ./scripts/local-backend spark-logs --tail 200 > artifacts/spark-docker.log 2>&1 || true + ./scripts/local-backend spark-logs --timestamps > artifacts/spark-docker.log 2>&1 || true # Preserve logs and recordings from failed attempts even when a retry passes. - uses: actions/upload-artifact@v7 diff --git a/app/src/main/java/to/bitkit/env/Env.kt b/app/src/main/java/to/bitkit/env/Env.kt index 7a3bbcb3d9..071d7c4b36 100644 --- a/app/src/main/java/to/bitkit/env/Env.kt +++ b/app/src/main/java/to/bitkit/env/Env.kt @@ -14,6 +14,13 @@ import com.synonym.bitkitcore.Network as BitkitCoreNetwork internal data class LocalSparkSettings(val configBase64: String, val chainUrl: String) { val isComplete: Boolean get() = configBase64.isNotBlank() && chainUrl.isNotBlank() + + companion object { + fun fromInputs(configBase64: String, chainUrl: String): LocalSparkSettings? { + if (configBase64.isBlank() && chainUrl.isBlank()) return null + return LocalSparkSettings(configBase64, chainUrl.trimEnd('/')) + } + } } @Suppress("ConstPropertyName", "KotlinConstantConditions", "SimplifyBooleanWithConstants") @@ -56,8 +63,7 @@ internal object Env { val e2eHomeserverPubky = BuildConfig.E2E_HOMESERVER_PUBKY.takeIf { isLocalE2eBackend && it.isNotBlank() } val network = Network.valueOf(BuildConfig.NETWORK) val localSparkSettings = if (isDebug && isLocalE2eBackend && network == Network.REGTEST) { - LocalSparkSettings(BuildConfig.SPARK_LOCAL_CONFIG_B64, BuildConfig.SPARK_LOCAL_CHAIN_URL.trimEnd('/')) - .takeIf { it.configBase64.isNotBlank() || it.chainUrl.isNotBlank() } + LocalSparkSettings.fromInputs(BuildConfig.SPARK_LOCAL_CONFIG_B64, BuildConfig.SPARK_LOCAL_CHAIN_URL) } else { null } diff --git a/app/src/test/java/to/bitkit/env/SparkChainServiceTest.kt b/app/src/test/java/to/bitkit/env/SparkChainServiceTest.kt index ebb1765be3..38c762e855 100644 --- a/app/src/test/java/to/bitkit/env/SparkChainServiceTest.kt +++ b/app/src/test/java/to/bitkit/env/SparkChainServiceTest.kt @@ -11,6 +11,15 @@ import kotlin.test.assertTrue class SparkChainServiceTest { private val local = LocalSparkSettings("encoded", "http://127.0.0.1:23090/api") + @Test + fun `a supplied slash-only fixture URL cannot fall back to hosted regtest`() { + assertNull(LocalSparkSettings.fromInputs("", " ")) + val incomplete = requireNotNull(LocalSparkSettings.fromInputs("", "/")) + assertFalse(incomplete.isComplete) + assertNull(Env.sparkRegtestEsploraUrl(incomplete)) + assertEquals(local, LocalSparkSettings.fromInputs(local.configBase64, local.chainUrl + "/")) + } + @Test fun `spark reads the chain from bitkit electrs on mainnet`() { assertEquals("https://bitkit.to/electrs", Env.sparkChainServiceUrl(Network.BITCOIN)) From b87435edbe79cffcfb188dcc6bc03e2b75f8da90 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 20 Nov 2026 19:27:17 +0100 Subject: [PATCH 15/15] style: put the local Spark settings companion first --- app/src/main/java/to/bitkit/env/Env.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/to/bitkit/env/Env.kt b/app/src/main/java/to/bitkit/env/Env.kt index 071d7c4b36..608ae18813 100644 --- a/app/src/main/java/to/bitkit/env/Env.kt +++ b/app/src/main/java/to/bitkit/env/Env.kt @@ -13,14 +13,14 @@ import kotlin.io.path.Path import com.synonym.bitkitcore.Network as BitkitCoreNetwork internal data class LocalSparkSettings(val configBase64: String, val chainUrl: String) { - val isComplete: Boolean get() = configBase64.isNotBlank() && chainUrl.isNotBlank() - companion object { fun fromInputs(configBase64: String, chainUrl: String): LocalSparkSettings? { if (configBase64.isBlank() && chainUrl.isBlank()) return null return LocalSparkSettings(configBase64, chainUrl.trimEnd('/')) } } + + val isComplete: Boolean get() = configBase64.isNotBlank() && chainUrl.isNotBlank() } @Suppress("ConstPropertyName", "KotlinConstantConditions", "SimplifyBooleanWithConstants")