Skip to content

Commit 7b8ae3a

Browse files
authored
Merge branch 'main' into fix/fallback-expired-ln-to-onchain
2 parents bfc5647 + e06d365 commit 7b8ae3a

21 files changed

Lines changed: 1541 additions & 199 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ aut
44
node_modules
55
docker/lnd
66
artifacts
7-
WARP.md
7+
WARP.md
8+
.ai

AGENTS.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,54 @@ Notes:
4646

4747
## Running Tests
4848

49+
**Important:** The `BACKEND` env var controls which infrastructure the tests use for deposits/mining:
50+
51+
- `BACKEND=local` (default) — Uses local docker stack (Bitcoin RPC on localhost:18443, Electrum on localhost:60001). Requires `bitkit-docker` running locally.
52+
- `BACKEND=regtest` — Uses Blocktank API over the internet (remote regtest infrastructure).
53+
54+
**The `BACKEND` must match how the app was built:**
55+
56+
- Apps built with `BACKEND=local` connect to localhost electrum → run tests with `BACKEND=local`
57+
- Apps built with `BACKEND=regtest` connect to remote electrum → run tests with `BACKEND=regtest`
58+
4959
```bash
50-
# Android
60+
# Android (local backend - default)
5161
npm run e2e:android
5262

63+
# Android (regtest backend - for apps built with BACKEND=regtest)
64+
BACKEND=regtest npm run e2e:android
65+
5366
# iOS
5467
npm run e2e:ios
68+
BACKEND=regtest npm run e2e:ios
5569
```
5670

5771
Run a single spec:
5872

5973
```bash
6074
npm run e2e:android -- --spec ./test/specs/onboarding.e2e.ts
75+
BACKEND=regtest npm run e2e:android -- --spec ./test/specs/migration.e2e.ts
6176
```
6277

6378
Run by tag:
6479

6580
```bash
6681
npm run e2e:android -- --mochaOpts.grep "@backup"
82+
BACKEND=regtest npm run e2e:android -- --mochaOpts.grep "@migration"
6783
```
6884

6985
## CI Helper Scripts
7086

7187
These wrap the `npm run e2e:*` commands and capture logs/artifacts:
7288

7389
```bash
90+
# Local backend (default)
7491
./ci_run_android.sh
7592
./ci_run_ios.sh
93+
94+
# Regtest backend
95+
BACKEND=regtest ./ci_run_android.sh
96+
BACKEND=regtest ./ci_run_ios.sh
7697
```
7798

7899
## Practical Tips

README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ If you have `bitkit-e2e-tests`, `bitkit-android`, and `bitkit-ios` checked out i
5959
# Legacy RN Android (builds ../bitkit and copies APK to ./aut/bitkit_rn_regtest.apk)
6060
./scripts/build-rn-android-apk.sh
6161

62+
# Legacy RN iOS simulator (builds ../bitkit and copies app to ./aut/bitkit_rn_regtest_ios.app)
63+
./scripts/build-rn-ios-sim.sh
64+
6265
# iOS (builds ../bitkit-ios and copies IPA to ./aut/bitkit_e2e.ipa)
6366
./scripts/build-ios-sim.sh
6467
```
@@ -73,6 +76,9 @@ BACKEND=regtest ./scripts/build-android-apk.sh
7376
# Legacy RN Android
7477
BACKEND=regtest ./scripts/build-rn-android-apk.sh
7578

79+
# Legacy RN iOS simulator
80+
BACKEND=regtest ./scripts/build-rn-ios-sim.sh
81+
7682
# iOS
7783
BACKEND=local ./scripts/build-ios-sim.sh
7884
BACKEND=regtest ./scripts/build-ios-sim.sh
@@ -82,18 +88,34 @@ BACKEND=regtest ./scripts/build-ios-sim.sh
8288

8389
### 🧪 Running tests
8490

91+
**Important:** The `BACKEND` environment variable controls which infrastructure the tests use for blockchain operations (deposits, mining blocks):
92+
93+
| Backend | Infrastructure | When to use |
94+
| ------------------------- | -------------------------------------------------------------------------------- | --------------------------------- |
95+
| `BACKEND=local` (default) | Local docker stack (Bitcoin RPC on localhost:18443, Electrum on localhost:60001) | Apps built with `BACKEND=local` |
96+
| `BACKEND=regtest` | Blocktank API over the internet (remote regtest) | Apps built with `BACKEND=regtest` |
97+
98+
> ⚠️ **The `BACKEND` must match how the app was built.** If the app connects to remote electrum, use `BACKEND=regtest`. If it connects to localhost, use `BACKEND=local`.
99+
85100
```bash
86-
# Run all tests on Android
101+
# Run all tests on Android (local backend - default)
87102
npm run e2e:android
88103

104+
# Run all tests on Android (regtest backend)
105+
BACKEND=regtest npm run e2e:android
106+
89107
# Run all tests on iOS
90108
npm run e2e:ios
109+
BACKEND=regtest npm run e2e:ios
91110
```
92111

93112
To run a **specific test file**:
94113

95114
```bash
96115
npm run e2e:android -- --spec ./test/specs/onboarding.e2e.ts
116+
117+
# With regtest backend
118+
BACKEND=regtest npm run e2e:android -- --spec ./test/specs/migration.e2e.ts
97119
```
98120

99121
To run a **specific test case**:
@@ -142,19 +164,25 @@ These helper scripts wrap the regular `npm run e2e:*` commands and add CI-friend
142164
The Android script will:
143165

144166
- Clear and capture `adb logcat` output into `./artifacts/logcat.txt`.
145-
- Reverse the regtest port (`60001`).
167+
- Reverse the regtest port (`60001`) for local backend.
146168
- Run the Android E2E tests.
147169
- Forward any arguments directly to Mocha/WebdriverIO.
148170

149171
**Usage examples:**
150172

151173
```bash
152-
# Run all Android tests (with logcat capture)
174+
# Run all Android tests with local backend (default)
153175
./ci_run_android.sh
154176

177+
# Run all Android tests with regtest backend (for apps built with BACKEND=regtest)
178+
BACKEND=regtest ./ci_run_android.sh
179+
155180
# Run only @backup tests
156181
./ci_run_android.sh --mochaOpts.grep "@backup"
157182

183+
# Run migration tests (typically need regtest backend for RN app)
184+
BACKEND=regtest ./ci_run_android.sh --mochaOpts.grep "@migration"
185+
158186
# Run backup OR onboarding OR onchain tests
159187
./ci_run_android.sh --mochaOpts.grep "@backup|@onboarding|@onchain"
160188

@@ -177,9 +205,12 @@ The iOS helper mirrors the Android workflow but tailors it for the Apple Simulat
177205
**Usage examples:**
178206

179207
```bash
180-
# Run all iOS tests (with simulator log capture)
208+
# Run all iOS tests with local backend (default)
181209
./ci_run_ios.sh
182210

211+
# Run all iOS tests with regtest backend
212+
BACKEND=regtest ./ci_run_ios.sh
213+
183214
# Run only @onboarding-tagged tests
184215
./ci_run_ios.sh --mochaOpts.grep "@onboarding"
185216

scripts/build-rn-android-apk.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set -euo pipefail
1717
E2E_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
1818
RN_ROOT="$(cd "$E2E_ROOT/../bitkit" && pwd)"
1919

20-
BUILD_TYPE="${1:-debug}"
20+
BUILD_TYPE="${1:-release}"
2121
BACKEND="${BACKEND:-regtest}"
2222

2323
if [[ "$BUILD_TYPE" != "debug" && "$BUILD_TYPE" != "release" ]]; then
@@ -27,7 +27,7 @@ fi
2727

2828
if [[ -z "${ENV_FILE:-}" ]]; then
2929
if [[ "$BACKEND" == "regtest" ]]; then
30-
ENV_FILE=".env.test.template"
30+
ENV_FILE=".env.development.template"
3131
else
3232
ENV_FILE=".env.development"
3333
fi

scripts/build-rn-ios-sim.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
# Build the legacy Bitkit RN iOS simulator app from ../bitkit and copy into aut/
3+
#
4+
# Inputs/roots:
5+
# - E2E root: this repo (bitkit-e2e-tests)
6+
# - RN root: ../bitkit (resolved relative to this script)
7+
#
8+
# Output:
9+
# - Copies .app -> aut/bitkit_rn_regtest_ios.app
10+
#
11+
# Usage:
12+
# ./scripts/build-rn-ios-sim.sh [debug|release]
13+
# BACKEND=regtest ./scripts/build-rn-ios-sim.sh
14+
# ENV_FILE=.env.test.template ./scripts/build-rn-ios-sim.sh
15+
set -euo pipefail
16+
17+
E2E_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
18+
RN_ROOT="$(cd "$E2E_ROOT/../bitkit" && pwd)"
19+
20+
BUILD_TYPE="${1:-release}"
21+
BACKEND="${BACKEND:-regtest}"
22+
23+
if [[ "$BUILD_TYPE" != "debug" && "$BUILD_TYPE" != "release" ]]; then
24+
echo "ERROR: Unsupported build type: $BUILD_TYPE (expected debug|release)" >&2
25+
exit 1
26+
fi
27+
28+
if [[ -z "${ENV_FILE:-}" ]]; then
29+
if [[ "$BACKEND" == "regtest" ]]; then
30+
ENV_FILE=".env.development.template"
31+
else
32+
ENV_FILE=".env.development"
33+
fi
34+
fi
35+
36+
if [[ ! -f "$RN_ROOT/$ENV_FILE" ]]; then
37+
echo "ERROR: Env file not found: $RN_ROOT/$ENV_FILE" >&2
38+
exit 1
39+
fi
40+
41+
echo "Building RN iOS simulator app (BACKEND=$BACKEND, ENV_FILE=$ENV_FILE, BUILD_TYPE=$BUILD_TYPE)..."
42+
43+
pushd "$RN_ROOT" >/dev/null
44+
if [[ -f .env ]]; then
45+
cp .env .env.bak
46+
fi
47+
cp "$ENV_FILE" .env
48+
E2E_TESTS=true yarn "e2e:build:ios-$BUILD_TYPE"
49+
if [[ -f .env.bak ]]; then
50+
mv .env.bak .env
51+
else
52+
rm -f .env
53+
fi
54+
popd >/dev/null
55+
56+
if [[ "$BUILD_TYPE" == "debug" ]]; then
57+
IOS_CONFIG="Debug"
58+
else
59+
IOS_CONFIG="Release"
60+
fi
61+
62+
APP_PATH="$RN_ROOT/ios/build/Build/Products/${IOS_CONFIG}-iphonesimulator/bitkit.app"
63+
if [[ ! -d "$APP_PATH" ]]; then
64+
echo "ERROR: iOS .app not found at: $APP_PATH" >&2
65+
exit 1
66+
fi
67+
68+
OUT="$E2E_ROOT/aut"
69+
mkdir -p "$OUT"
70+
OUT_APP="$OUT/bitkit_rn_${BACKEND}_ios.app"
71+
rm -rf "$OUT_APP"
72+
cp -R "$APP_PATH" "$OUT_APP"
73+
echo "RN iOS simulator app copied to: $OUT_APP"

scripts/mine-blocks.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
#
3+
# Mine blocks on regtest via Blocktank API
4+
#
5+
# Usage:
6+
# ./scripts/mine-blocks.sh [count]
7+
#
8+
# Examples:
9+
# ./scripts/mine-blocks.sh # mines 1 block
10+
# ./scripts/mine-blocks.sh 6 # mines 6 blocks
11+
#
12+
13+
set -e
14+
15+
COUNT="${1:-1}"
16+
BLOCKTANK_URL="${BLOCKTANK_URL:-https://api.stag0.blocktank.to/blocktank/api/v2}"
17+
ENDPOINT="${BLOCKTANK_URL}/regtest/chain/mine"
18+
19+
echo "→ Mining ${COUNT} block(s) via Blocktank..."
20+
21+
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$ENDPOINT" \
22+
-H "Content-Type: application/json" \
23+
-d "{\"count\": ${COUNT}}")
24+
25+
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
26+
BODY=$(echo "$RESPONSE" | sed '$d')
27+
28+
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
29+
echo "✓ Mined ${COUNT} block(s)"
30+
else
31+
echo "✗ Failed to mine blocks: HTTP $HTTP_CODE"
32+
echo "$BODY"
33+
exit 1
34+
fi

0 commit comments

Comments
 (0)