Skip to content

Commit

Permalink
test: new onchain e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
limpbrains committed Feb 15, 2023
1 parent 9732628 commit d7ac0bd
Show file tree
Hide file tree
Showing 30 changed files with 444 additions and 62 deletions.
16 changes: 16 additions & 0 deletions .env.development.template
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ BACKUPS_SERVER_SLASHTAG=slash:3phbmj4jkzs7b6e6t1h8jwy1u6o9w9y39nscsc6r1q89t1mxcs
DISABLE_SLASHTAGS=false
SLASHTAGS_SEEDER_BASE_URL=
SLASHTAGS_SEEDER_TOPIC=

# Network
ELECTRUM_BITCOIN_HOST = 35.187.18.233
ELECTRUM_BITCOIN_SSL_PORT = 8912
ELECTRUM_BITCOIN_TCP_PORT = 8911
ELECTRUM_BITCOIN_PROTO = tcp

ELECTRUM_REGTEST_HOST = 35.233.47.252
ELECTRUM_REGTEST_SSL_PORT = 18484
ELECTRUM_REGTEST_TCP_PORT = 18483
ELECTRUM_REGTEST_PROTO = tcp

WALLET_DEFAULT_SELECTED_NETWORK = bitcoin

DISABLE_PERIODIC_REMINDERS=false
DISABLE_LOOP_ANIMATION=false
42 changes: 42 additions & 0 deletions .env.test.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# middleware for redux-flipper plugin
ENABLE_REDUX_FLIPPER=true

# middleware for redux-logger
ENABLE_REDUX_LOGGER=true

# middleware for immutable-state-invariant (disable if things are slow in development)
ENABLE_REDUX_IMMUTABLE_CHECK=true

# react-native-mmkv-flipper-plugin
ENABLE_MMKV_FLIPPER=false

# i18next debug mode
ENABLE_I18NEXT_DEBUGGER=false

# redux-persist migration debug mode
ENABLE_MIGRATION_DEBUG=false

# Backup server (development)
BACKUPS_SHARED_SECRET=6dabb95493023d5c45229331490a9a67fcde2a618798f9dea5c1247eabb13451
BACKUPS_SERVER_SLASHTAG=slash:3phbmj4jkzs7b6e6t1h8jwy1u6o9w9y39nscsc6r1q89t1mxcsuy

# Slashtags
DISABLE_SLASHTAGS=false
SLASHTAGS_SEEDER_BASE_URL=
SLASHTAGS_SEEDER_TOPIC=

# Network
ELECTRUM_BITCOIN_HOST = 35.187.18.233
ELECTRUM_BITCOIN_SSL_PORT = 8912
ELECTRUM_BITCOIN_TCP_PORT = 8911
ELECTRUM_BITCOIN_PROTO = tcp

ELECTRUM_REGTEST_HOST = 127.0.0.1
ELECTRUM_REGTEST_SSL_PORT = 60001
ELECTRUM_REGTEST_TCP_PORT = 60001
ELECTRUM_REGTEST_PROTO = tcp

WALLET_DEFAULT_SELECTED_NETWORK = bitcoinRegtest

DISABLE_PERIODIC_REMINDERS=true
DISABLE_LOOP_ANIMATION=true
45 changes: 39 additions & 6 deletions .github/workflows/e2e-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ jobs:
with:
fetch-depth: 1

- name: Setup Docker on macOS
uses: docker-practice/actions-setup-docker@master

- name: Run regtest setup
run: |
cd __tests__ && docker-compose up -d
- name: Wait for bitcoind
timeout-minutes: 2
run: |
while ! nc -z '127.0.0.1' 43782; do sleep 1; done
- name: Wait for electrum server
timeout-minutes: 2
run: while ! nc -z '127.0.0.1' 60001; do sleep 1; done

- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
Expand Down Expand Up @@ -50,9 +66,12 @@ jobs:
if: steps.cache-nm.outputs.cache-hit != 'true'
run: yarn install

- name: Activate enviroment variables
run: cp .env.test.template .env

- name: Activate react-native-skia-stup
run: |
yarn add @shopify/react-native-skia@0.1.156 git+ssh://git@github.com/limpbrains/react-native-skia-stub
yarn add @shopify/react-native-skia@0.1.156 github:limpbrains/react-native-skia-stub
patch -p1 < .github/workflows/react-native-skia-stub.patch
- name: Cache Pods
Expand All @@ -75,14 +94,28 @@ jobs:
- name: Build
run: yarn e2e:build:ios-release

- name: Test
run: |
yarn e2e:test:ios-release --record-videos all --take-screenshots all --record-logs all || \
yarn e2e:test:ios-release --record-videos all --take-screenshots all --record-logs all || \
yarn e2e:test:ios-release --record-videos all --take-screenshots all --record-logs all
- name: Test attempt 1
continue-on-error: true
id: test1
run: yarn e2e:test:ios-release --record-videos all --take-screenshots all --record-logs all

- name: Test attempt 2
continue-on-error: true
id: test2
if: steps.test1.outcome != 'success'
run: yarn e2e:test:ios-release --record-videos all --take-screenshots all --record-logs all

- name: Test attempt 3
id: test3
if: steps.test2.outcome != 'success'
run: yarn e2e:test:ios-release --record-videos all --take-screenshots all --record-logs all

- uses: actions/upload-artifact@v3
if: failure()
with:
name: e2e-test-videos
path: ./artifacts/

- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2
12 changes: 6 additions & 6 deletions .github/workflows/jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:
- name: Run regtest setup
run: cd __tests__ && docker compose up -d

- name: Wait for bitcoind and chmod 777 cookie file
# because bitcoind and electrs has different user ids and bitcoind creates cookie file with chmod 700
# electrum server can't read it, that is why we chmod 777 it
- name: Wait for bitcoind
run: |
sudo apt install wait-for-it
wait-for-it -h 127.0.0.1 -p 43782 -t 60
sudo chmod 777 __tests__/bitcoin_datadir/regtest/.cookie
- name: Wait for electrum server
run: wait-for-it -h 127.0.0.1 -p 60001 -t 60

- name: Set up Node.js
uses: actions/setup-node@v3
Expand All @@ -50,8 +50,8 @@ jobs:
- name: Install Node.js dependencies
run: yarn install

- name: Wait for electrum server
run: wait-for-it -h 127.0.0.1 -p 60001 -t 60
- name: Activate enviroment variables
run: cp .env.development.template .env

- name: Run Tests
run: yarn test
Expand Down
26 changes: 12 additions & 14 deletions __tests__/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
version: '3'
services:
bitcoind:
restart: unless-stopped
container_name: btcpayserver_bitcoind
image: btcpayserver/bitcoin:24.0.1
restart: unless-stopped
expose:
- '43782'
- '39388'
ports:
- '43782:43782'
- '39388:39388'
volumes:
- 'bitcoin_datadir:/data'
- 'bitcoin_wallet_datadir:/walletdata'
environment:
BITCOIN_NETWORK: ${NBITCOIN_NETWORK:-regtest}
CREATE_WALLET: 'true'
Expand All @@ -18,18 +26,9 @@ services:
rpcauth=electrumx:7d8ee47c089e6072635f82b34796e878$$13649d99453ccdf78e85007286422599c00e6953289f41bf8e92961076ba14db
txindex=1
fallbackfee=0.00001
expose:
- '43782'
- '39388'
ports:
- '43782:43782'
- '39388:39388'
volumes:
- './bitcoin_datadir:/data'
- 'bitcoin_wallet_datadir:/walletdata'
electrs:
image: getumbrel/electrs:v0.9.9
image: getumbrel/electrs:v0.9.10
restart: unless-stopped
depends_on:
- bitcoind
Expand All @@ -38,7 +37,7 @@ services:
ports:
- '60001:60001'
volumes:
- './bitcoin_datadir:/data/.bitcoin'
- './electrs.toml:/data/electrs.toml'
- 'electrs_datadir:/data'
environment:
- ELECTRS_NETWORK=regtest
Expand All @@ -50,7 +49,6 @@ services:
volumes:
bitcoin_datadir:
bitcoin_wallet_datadir:
electrumx_datadir:
electrs_datadir:

networks: {}
1 change: 1 addition & 0 deletions __tests__/electrs.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auth = "electrumx:1VmSUVGBuLNWvZl0LExRDW0tvl6196-47RfXIzS384g="
6 changes: 5 additions & 1 deletion __tests__/utils/wait-for-electrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import net from 'net';
import BitcoinJsonRpc from 'bitcoin-json-rpc';
import ElectrumClient from 'electrum-client';

import { sleep } from '../../src/utils/helpers';
const sleep = (ms = 1000): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, ms));
};

// tracks blocks count in electrum and when it maches bitcoin core resolves the promise
const initWaitForElectrumToSync = async (
Expand Down Expand Up @@ -71,6 +73,8 @@ const initWaitForElectrumToSync = async (
});
};

waitForElectrum.close = (): void => electrum?.close();

return waitForElectrum;
};

Expand Down
27 changes: 27 additions & 0 deletions e2e/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import fs from 'fs';
import path from 'path';

const LOCK_PATH = '/tmp/';

export const checkComplete = (name) => {
if (!process.env.CI) {
return;
}

if (fs.existsSync(path.join(LOCK_PATH, 'lock-' + name))) {
console.warn('skipping', name, 'as it previously passed on CI');
return true;
}

return false;
};

export const markComplete = (name) => {
if (!process.env.CI) {
return;
}

fs.writeFileSync(path.join(LOCK_PATH, 'lock-' + name), '1');
};

export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7 changes: 7 additions & 0 deletions e2e/newWallet.e2e.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { checkComplete, markComplete } from './helpers';

describe('New Wallet', () => {
beforeAll(async () => {
await device.launchApp();
Expand All @@ -8,6 +10,10 @@ describe('New Wallet', () => {
// });

it('should create new wallet', async () => {
if (checkComplete('n1')) {
return;
}

// TOS and PP
await waitFor(element(by.id('Check1'))).toBeVisible();

Expand All @@ -20,5 +26,6 @@ describe('New Wallet', () => {

// wat for wallet to be created
await waitFor(element(by.id('ToGetStartedClose'))).toBeVisible();
markComplete('n1');
});
});
Loading

0 comments on commit d7ac0bd

Please sign in to comment.