Skip to content

Commit

Permalink
chore: sync with master
Browse files Browse the repository at this point in the history
  • Loading branch information
limpbrains committed Aug 7, 2023
2 parents 76530b7 + d7eb591 commit 31f9d1b
Show file tree
Hide file tree
Showing 97 changed files with 1,072 additions and 762 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: HOMEBREW_NO_AUTO_UPDATE=1 brew tap wix/brew && brew install applesimutils

- name: Run regtest setup
run: cd __tests__ && mkdir lnd && chmod 777 lnd && docker-compose up -d
run: cd docker && mkdir lnd && chmod 777 lnd && docker-compose up -d

- name: Wait for bitcoind
timeout-minutes: 2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fetch-depth: 1

- name: Run regtest setup
run: cd __tests__ && docker compose up -d
run: cd docker && docker compose up -d

- name: Wait for bitcoind
run: |
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ android/app/pepk.jar

# testing
coverage/
__tests__/bitcoin_datadir/
__tests__/lnd/
artifacts/

# docker
docker/lnd/

#Build
android/app/release/
22 changes: 9 additions & 13 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ Make sure you have [setup your environment for React Native](https://reactnative
git clone [email protected]:synonymdev/bitkit.git && cd bitkit
```

2. Switch Node version

Switch to the Node.js version defined in `.nvmrc`. If `nvm` (or similiar) is installed on your system you can run `nvm use`.

3. Install dependencies
2. Install dependencies

```shell
yarn install
```

4. Setup iOS or Android dependencies
3. Setup iOS or Android dependencies

```shell
yarn setup-ios
Expand All @@ -32,7 +28,7 @@ or
yarn setup-android
```

5. Start the project
4. Start the project

On iOS Simulator:

Expand All @@ -50,18 +46,18 @@ yarn android

Bitkit uses two types of testing: unit and end-to-end (E2E) tests.

### 1. Unit tests

Before running unit tests, you need to install Docker and run bitcoind and the electrum server in regtest mode. You can do this by using the docker-compose.yml file from the **tests** directory:
Before running tests, you need to install [Docker](https://docs.docker.com/get-docker/) and run bitcoind and the electrum server in regtest mode. You can do this by using the `docker-compose.yml` file from the **docker** directory:

```sh
cd __tests__
```shell
cd docker
docker compose up
```

After that, you are ready to run the tests:

```sh
### 1. Unit tests

```shell
yarn test
```

Expand Down
1 change: 1 addition & 0 deletions __tests__/backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ describe('Remote backups', () => {
txType: EPaymentType.received,
message: '',
address: 'invoice',
confirmed: true,
value: 1,
timestamp: new Date().getTime(),
});
Expand Down
165 changes: 165 additions & 0 deletions docker/bitcoin-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/usr/bin/env bash

set -euo pipefail

CLI_NAME="$(basename $0)"
CLI_DIR="$(dirname "$(readlink -f "$0")")"
CONTAINER="bitcoind"
RPC_USER=polaruser
RPC_PASS=polarpass
RPC_PORT=43782

BASE_COMMAND=(docker compose exec $CONTAINER bitcoin-cli -rpcport=$RPC_PORT -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS)

DEFAULT_AMOUNT=0.001

show_help() {
cat <<EOF
Shortcuts for bitcoin-cli.
Usage: ${CLI_NAME} <command> [options]
Flags:
-h, --help Show this help message
Commands:
fund <amount> Fund the wallet
mine <amount> [--auto] Generate a number of blocks
send <address> <amount> Send to address or BIP21 URI
getInvoice <amount> Get a new BIP21 URI with a bech32 address
EOF
}

if [ -z ${1+x} ]; then
command=""
else
command="$1"
fi

# Fund the wallet
if [[ "$command" = "fund" ]]; then
"${BASE_COMMAND[@]}" -generate 101
exit
fi

# Mine some blocks
if [[ "$command" = "mine" ]]; then
shift

if [ -z ${1+x} ]; then
echo "Specify the number of blocks to generate."
echo "Usage: \`$CLI_NAME $command <amount>\`"
exit 1
fi

POSITIONAL_ARGS=()

auto=false

while [[ $# -gt 0 ]]; do
case $1 in
-l | --auto)
auto=true
shift
;;
-* | --*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done

set -- "${POSITIONAL_ARGS[@]}"

# default to 5 seconds
interval=${2:-5}

if $auto; then
printf "Generating a block every $interval seconds. Press [CTRL+C] to stop...\n\n"

while true; do
"${BASE_COMMAND[@]}" -generate 1
sleep $interval
done
else
"${BASE_COMMAND[@]}" -generate "$@"
fi

exit
fi

# Send to a transaction
if [[ "$command" = "send" ]]; then
shift

if [ -z ${1+x} ]; then
read -p "Enter a BIP21 URI or address: " uri
echo
else
uri="$1"
fi

if [ -z ${2+x} ]; then
amount=$DEFAULT_AMOUNT
else
amount="$2"
fi

protocol=$(echo "${uri%%:*}")

if [[ "$protocol" == "bitcoin" ]]; then
# BIP21 URI
# Remove the protocol
url_no_protocol=$(echo "${uri/$protocol/}" | cut -d":" -f2-)

address=$(echo $url_no_protocol | grep "?" | cut -d"/" -f1 | rev | cut -d"?" -f2- | rev || echo $url_no_protocol)
uri_amount=$(echo $url_no_protocol | cut -d'?' -f 2 | cut -d'=' -f 2 | cut -d'&' -f 1)

if echo "$uri_amount" | grep -qE '^[0-9]*\.?[0-9]+$'; then
amount=$uri_amount
fi
else
address=$uri
fi

tx_id=$("${BASE_COMMAND[@]}" -named sendtoaddress address="$address" amount="$amount" fee_rate="25")

echo "Sent $amount BTC to $address"
echo "Transaction ID: $tx_id"

exit
fi

# Get a new BIP21 URI
if [[ "$command" = "getInvoice" ]]; then
shift

if [ -z ${1+x} ]; then
amount=$DEFAULT_AMOUNT
else
amount="$1"
fi

address=$("${BASE_COMMAND[@]}" getnewaddress -addresstype bech32 | tr -d '\r')
uri="bitcoin:$address?amount=$amount"

# print URI
echo $uri

# copy to clipboard (MacOS)
echo $uri | pbcopy
echo "Copied to clipboard."

exit
fi

# Show usage information for this CLI
if [[ "$command" = "--help" ]] || [[ "$command" = "-h" ]]; then
show_help
exit
fi

# If no command specified pass all args straight to bitcoin-cli
"${BASE_COMMAND[@]}" "$@"
exit
File renamed without changes.
3 changes: 3 additions & 0 deletions __tests__/docker-compose.yml → docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: '3'
services:
bitcoind:
container_name: bitcoin
image: btcpayserver/bitcoin:25.0
restart: unless-stopped
expose:
Expand Down Expand Up @@ -46,6 +47,7 @@ services:
]

electrs:
container_name: electrum
image: getumbrel/electrs:v0.9.10
restart: unless-stopped
depends_on:
Expand Down Expand Up @@ -84,6 +86,7 @@ services:
- '/www'

lnd:
container_name: lnd
image: polarlightning/lnd:0.16.2-beta
restart: unless-stopped
depends_on:
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions e2e/lightning.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ d('Lightning', () => {
// send funds to LND node and open a channel
const lnd = await createLndRpc({
server: 'localhost:10009',
tls: `${__dirname}/../__tests__/lnd/tls.cert`,
macaroonPath: `${__dirname}/../__tests__/lnd/data/chain/bitcoin/regtest/admin.macaroon`,
tls: `${__dirname}/../docker/lnd/tls.cert`,
macaroonPath: `${__dirname}/../docker/lnd/data/chain/bitcoin/regtest/admin.macaroon`,
});
const { address: lndAddress } = await lnd.newAddress();
await rpc.sendToAddress(lndAddress, '1');
Expand Down
8 changes: 4 additions & 4 deletions e2e/settings.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ d('Settings', () => {
// switch to Bitcoins
await element(by.id('Settings')).tap();
await element(by.id('GeneralSettings')).tap();
await element(by.id('BitcoinUnitSettings')).tap();
await element(by.id('UnitSettings')).tap();
await element(by.id('Bitcoin')).tap();
await expect(
element(by.id('Value').withAncestor(by.id('BitcoinUnitSettings'))),
element(by.id('Value').withAncestor(by.id('UnitSettings'))),
).toHaveText('Bitcoin');

// switch back to Satoshis
await element(by.id('BitcoinUnitSettings')).tap();
await element(by.id('UnitSettings')).tap();
await element(by.id('Satoshis')).tap();
await expect(
element(by.id('Value').withAncestor(by.id('BitcoinUnitSettings'))),
element(by.id('Value').withAncestor(by.id('UnitSettings'))),
).toHaveText('Satoshis');
markComplete('settings-2');
});
Expand Down
16 changes: 8 additions & 8 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ PODS:
- lottie-react-native (5.1.6):
- lottie-ios (~> 3.4.0)
- React-Core
- MMKV (1.2.15):
- MMKVCore (~> 1.2.15)
- MMKVCore (1.2.15)
- MMKV (1.3.0):
- MMKVCore (~> 1.3.0)
- MMKVCore (1.3.0)
- nodejs-mobile-react-native (0.8.1):
- React-Core
- OpenSSL-Universal (1.1.1100)
Expand Down Expand Up @@ -396,7 +396,7 @@ PODS:
- React-Core
- react-native-keep-awake (1.2.0):
- React-Core
- react-native-ldk (0.0.102):
- react-native-ldk (0.0.103):
- React
- react-native-libsodium (0.7.0):
- React-Core
Expand Down Expand Up @@ -749,7 +749,7 @@ EXTERNAL SOURCES:
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
hermes-engine:
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
:tag: ''
:tag: hermes-2023-03-20-RNv0.72.0-49794cfc7c81fb8f69fd60c3bbf85a7480cc5a77
lottie-react-native:
:path: "../node_modules/lottie-react-native"
nodejs-mobile-react-native:
Expand Down Expand Up @@ -909,8 +909,8 @@ SPEC CHECKSUMS:
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
lottie-ios: 8f97d3271e155c2d688875c29cd3c74908aef5f8
lottie-react-native: 8f9d4be452e23f6e5ca0fdc11669dc99ab52be81
MMKV: 7f34558bbb5a33b0eaefae2de4b6a20a2ffdad6f
MMKVCore: ddf41b9d9262f058419f9ba7598719af56c02cd3
MMKV: 9c6c3fa4ddd849f28c7b9a5c9d23aab84f14ee35
MMKVCore: 9bb7440b170181ac5b81f542ac258103542e693d
nodejs-mobile-react-native: e35e7ed7ecfca168f168983e9557f1c5278d864b
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
Expand All @@ -934,7 +934,7 @@ SPEC CHECKSUMS:
react-native-flipper: 5d8dcbcb905a7e8076c9a61a3709944c23cf48ee
react-native-image-picker: db60857e03d63721f19b6f4027de20429ddd9cba
react-native-keep-awake: caee3ff89eaa21dfe29010f0d143566874a04441
react-native-ldk: 68471c25f1e36ae5b2f59f3002016a815f781480
react-native-ldk: e31bd28e7e29fb4dd99b86bceed14025f8bf53eb
react-native-libsodium: 2834a805c906aef4b7609019bcc87e7d9eb86b23
react-native-mmkv: dea675cf9697ad35940f1687e98e133e1358ef9f
react-native-netinfo: 22c082970cbd99071a4e5aa7a612ac20d66b08f0
Expand Down
Loading

0 comments on commit 31f9d1b

Please sign in to comment.