}
wallet_create() {
+ wallet_missing $1
+
local CMD="$BITCOIN_CLI -named createwallet wallet_name=wallet$1 descriptors=true"
eval "$CMD" > /dev/null
log_info "created wallet: wallet$1"
}
wallet_create_blank() {
+ wallet_missing $1
+
local CMD="$BITCOIN_CLI -named createwallet wallet_name=wallet$1 descriptors=true blank=true"
eval "$CMD" > /dev/null
log_info "created blank wallet: wallet$1"
local CMD="$BITCOIN_CLI -named -rpcwallet=wallet$1 getwalletinfo"
set +e
- eval "$CMD" >/dev/null 2>&1
- set -e
+ eval "$CMD >/dev/null 2>&1"
if [[ "$?" -ne 0 ]]; then
log_error "ERROR: wallet$1 doesn't exist"
exit 1
fi
+ set -e
}
wallet_load() {
+ wallet_missing "$1"
+
if [[ ! -e "$2" ]]; then
log_error "file not found: $2"
exit 1
log_info "loaded descriptors for wallet$1 from $2"
}
+wallet_missing() {
+ local CMD="$BITCOIN_CLI -named -rpcwallet=wallet$1 getwalletinfo"
+
+ set +e
+ eval "$CMD >/dev/null 2>&1"
+ if [[ "$?" -eq 0 ]]; then
+ log_error "ERROR: wallet$1 already exists"
+ exit 1
+ fi
+ set -e
+}
+
wallets() {
for((i = 1; i <= $N; i++)); do
wallet_create "$i"
}
wallets_clean() {
- find "$DATA_DIRECTORY" -name "wallet.dat" -exec shred {} \;
+ find "$DATA_DIRECTORY" -name "wallet.dat" -exec shred -u {} \;
}
main() {
--- /dev/null
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+set +e
+(wallet_change_descriptors 1 > result 2>&1)
+assert "1" "$?"
+set -e
+EXPECTED="ERROR: wallet1 doesn't exist"
+assert "$EXPECTED" "$(<result)"
+
+setup_test_wallets
+
+wallet_change_descriptors 1 > /dev/null
+
+clean_env
+
+test_succeeded
(wallet_create 1 > result 2>&1)
EXPECTED="created wallet: wallet1"
-RESULT=$(<result)
-assert "$EXPECTED" "$RESULT"
+assert "$EXPECTED" "$(<result)"
(wallet_create 2 > result 2>&1)
EXPECTED="created wallet: wallet2"
-RESULT=$(<result)
-assert "$EXPECTED" "$RESULT"
+assert "$EXPECTED" "$(<result)"
+
+set +e
+(wallet_create 1 > result 2>&1)
+assert "1" "$?"
+set -e
+EXPECTED="ERROR: wallet1 already exists"
+assert "$EXPECTED" "$(<result)"
clean_env
(wallet_create_blank 1 > result 2>&1)
EXPECTED="created blank wallet: wallet1"
-RESULT=$(<result)
-assert "$EXPECTED" "$RESULT"
+assert "$EXPECTED" "$(<result)"
+
+(eval "$BITCOIN_CLI -rpcwallet=wallet1 getwalletinfo" > result)
+assert "true" "`cat result | jq '.private_keys_enabled'`"
(wallet_create_blank 2 > result 2>&1)
EXPECTED="created blank wallet: wallet2"
-RESULT=$(<result)
-assert "$EXPECTED" "$RESULT"
+assert "$EXPECTED" "$(<result)"
+
+set +e
+(wallet_create_blank 1 > result 2>&1)
+assert "1" "$?"
+set -e
+EXPECTED="ERROR: wallet1 already exists"
+assert "$EXPECTED" "$(<result)"
clean_env
--- /dev/null
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+set +e
+(wallet_descriptors 1 > result 2>&1)
+assert "1" "$?"
+set -e
+EXPECTED="ERROR: wallet1 doesn't exist"
+assert "$EXPECTED" "$(<result)"
+
+setup_test_wallets
+
+wallet_descriptors 1 > /dev/null
+
+clean_env
+
+test_succeeded
--- /dev/null
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+set +e
+(wallet_exists 1 > result 2>&1)
+assert "1" "$?"
+set -e
+EXPECTED="ERROR: wallet1 doesn't exist"
+assert "$EXPECTED" "$(<result)"
+
+setup_test_wallets
+
+wallet_exists 1 > /dev/null
+
+clean_env
+
+test_succeeded
RESULT=$(<result)
assert "$EXPECTED" "$RESULT"
+set +e
+(wallet_load 2 "wallet2.descriptors" > result 2>&1)
+assert "1" "$?"
+set -e
+EXPECTED="ERROR: wallet2 already exists"
+assert "$EXPECTED" "$(<result)"
+
clean_env
test_succeeded
--- /dev/null
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+wallet_missing 1 > /dev/null
+
+setup_test_wallets
+
+set +e
+(wallet_missing 1 > result 2>&1)
+assert "1" "$?"
+set -e
+EXPECTED="ERROR: wallet1 already exists"
+assert "$EXPECTED" "$(<result)"
+
+clean_env
+
+test_succeeded
--- /dev/null
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+(wallets > result)
+EXPECTED="created wallet: wallet1
+created wallet: wallet2
+created wallet: wallet3
+created wallet: wallet4
+created wallet: wallet5
+created wallet: wallet6
+created wallet: wallet7"
+assert "$EXPECTED" "$(<result)"
+
+clean_env
+
+test_succeeded
--- /dev/null
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+setup_test_wallets
+
+assert "7" "`find "$DATA_DIRECTORY" -name "wallet.dat" | wc -l`"
+
+wallets_clean
+
+assert "0" "`find "$DATA_DIRECTORY" -name "wallet.dat" | wc -l`"
+
+test_succeeded