Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions .github/workflows/e2e-local-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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: 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"

- 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 (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
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()
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()
with:
name: spark-android-${{ github.run_number }}
path: bitkit-e2e-tests/artifacts/
retention-days: 7
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
Expand Down Expand Up @@ -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())
Expand Down
28 changes: 26 additions & 2 deletions app/src/main/java/to/bitkit/services/SparkService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ 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
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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down