Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
26 changes: 24 additions & 2 deletions scripts/build-ios-sim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -51,21 +53,41 @@ 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 \
-project "$IOS_ROOT/Bitkit.xcodeproj" \
-scheme Bitkit \
-configuration Debug \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,OS=latest,name=iPhone 17' \
-destination 'generic/platform=iOS Simulator' \
Comment thread
piotr-iohk marked this conversation as resolved.
Resolved
-derivedDataPath "$IOS_ROOT/build" \
"${XCODE_EXTRA_ARGS[@]}" \
clean build
Expand Down
167 changes: 165 additions & 2 deletions scripts/local-backend
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/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)"
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
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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 <image-archive>' >&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 <regtest-invoice>' >&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 "$@"
Expand All @@ -116,7 +279,7 @@ case "${1:-}" in
exec "$@"
;;
*)
echo 'Usage: ./scripts/local-backend {prepare|path|up|down|ps|logs|github-env|run <command>}' >&2
echo 'Usage: ./scripts/local-backend {prepare|path|up|down|ps|logs|github-env|run <command>|spark-pack <image-archive>|spark-up|spark-image-fingerprint|spark-init-env|spark-env|spark-pay <invoice>|spark-down|spark-logs}' >&2
exit 2
;;
esac
23 changes: 23 additions & 0 deletions scripts/run-spark-e2e.sh
Original file line number Diff line number Diff line change
@@ -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'
Loading