From 5ba166439eb583ecca41bd9721da786fc02951eb Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 24 Jun 2022 20:51:08 -0700 Subject: [PATCH] ... --- cold-setup | 24 +++++++++++++++++++++--- test/wallet_change_descriptors.tests.sh | 22 ++++++++++++++++++++++ test/wallet_create.tests.sh | 13 +++++++++---- test/wallet_create_blank.tests.sh | 16 ++++++++++++---- test/wallet_descriptors.tests.sh | 22 ++++++++++++++++++++++ test/wallet_exists.tests.sh | 22 ++++++++++++++++++++++ test/wallet_load.tests.sh | 7 +++++++ test/wallet_missing.tests.sh | 22 ++++++++++++++++++++++ test/wallets.tests.sh | 21 +++++++++++++++++++++ test/wallets_clean.tests.sh | 17 +++++++++++++++++ 10 files changed, 175 insertions(+), 11 deletions(-) create mode 100755 test/wallet_change_descriptors.tests.sh create mode 100755 test/wallet_descriptors.tests.sh create mode 100755 test/wallet_exists.tests.sh create mode 100755 test/wallet_missing.tests.sh create mode 100755 test/wallets.tests.sh create mode 100755 test/wallets_clean.tests.sh diff --git a/cold-setup b/cold-setup index ce70753..a256a5a 100755 --- a/cold-setup +++ b/cold-setup @@ -354,12 +354,16 @@ wallet_change_descriptors() { } 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" @@ -387,15 +391,17 @@ wallet_exists() { 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 @@ -407,6 +413,18 @@ wallet_load() { 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" @@ -414,7 +432,7 @@ wallets() { } wallets_clean() { - find "$DATA_DIRECTORY" -name "wallet.dat" -exec shred {} \; + find "$DATA_DIRECTORY" -name "wallet.dat" -exec shred -u {} \; } main() { diff --git a/test/wallet_change_descriptors.tests.sh b/test/wallet_change_descriptors.tests.sh new file mode 100755 index 0000000..2fc5762 --- /dev/null +++ b/test/wallet_change_descriptors.tests.sh @@ -0,0 +1,22 @@ +#!/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" "$( /dev/null + +clean_env + +test_succeeded diff --git a/test/wallet_create.tests.sh b/test/wallet_create.tests.sh index fee78df..1284001 100755 --- a/test/wallet_create.tests.sh +++ b/test/wallet_create.tests.sh @@ -8,13 +8,18 @@ setup_env (wallet_create 1 > result 2>&1) EXPECTED="created wallet: wallet1" -RESULT=$( result 2>&1) EXPECTED="created wallet: wallet2" -RESULT=$( result 2>&1) +assert "1" "$?" +set -e +EXPECTED="ERROR: wallet1 already exists" +assert "$EXPECTED" "$( result 2>&1) EXPECTED="created blank wallet: wallet1" -RESULT=$( result) +assert "true" "`cat result | jq '.private_keys_enabled'`" (wallet_create_blank 2 > result 2>&1) EXPECTED="created blank wallet: wallet2" -RESULT=$( result 2>&1) +assert "1" "$?" +set -e +EXPECTED="ERROR: wallet1 already exists" +assert "$EXPECTED" "$( result 2>&1) +assert "1" "$?" +set -e +EXPECTED="ERROR: wallet1 doesn't exist" +assert "$EXPECTED" "$( /dev/null + +clean_env + +test_succeeded diff --git a/test/wallet_exists.tests.sh b/test/wallet_exists.tests.sh new file mode 100755 index 0000000..934631d --- /dev/null +++ b/test/wallet_exists.tests.sh @@ -0,0 +1,22 @@ +#!/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" "$( /dev/null + +clean_env + +test_succeeded diff --git a/test/wallet_load.tests.sh b/test/wallet_load.tests.sh index 3097cc3..b72ae66 100755 --- a/test/wallet_load.tests.sh +++ b/test/wallet_load.tests.sh @@ -144,6 +144,13 @@ loaded descriptors for wallet2 from wallet2.descriptors" RESULT=$( result 2>&1) +assert "1" "$?" +set -e +EXPECTED="ERROR: wallet2 already exists" +assert "$EXPECTED" "$( /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) +EXPECTED="created wallet: wallet1 +created wallet: wallet2 +created wallet: wallet3 +created wallet: wallet4 +created wallet: wallet5 +created wallet: wallet6 +created wallet: wallet7" +assert "$EXPECTED" "$(