]> infiniteadaptability.org Git - cold/commitdiff
...
authoralex <[email protected]>
Sat, 25 Jun 2022 03:51:08 +0000 (20:51 -0700)
committeralex <[email protected]>
Sat, 25 Jun 2022 03:51:08 +0000 (20:51 -0700)
cold-setup
test/wallet_change_descriptors.tests.sh [new file with mode: 0755]
test/wallet_create.tests.sh
test/wallet_create_blank.tests.sh
test/wallet_descriptors.tests.sh [new file with mode: 0755]
test/wallet_exists.tests.sh [new file with mode: 0755]
test/wallet_load.tests.sh
test/wallet_missing.tests.sh [new file with mode: 0755]
test/wallets.tests.sh [new file with mode: 0755]
test/wallets_clean.tests.sh [new file with mode: 0755]

index ce7075332422e764467d004123882b7f1324daf8..a256a5a55416b4200a4465d7ee07c4c393d1ba57 100755 (executable)
@@ -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 (executable)
index 0000000..2fc5762
--- /dev/null
@@ -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" "$(<result)"
+
+setup_test_wallets
+
+wallet_change_descriptors 1 > /dev/null
+
+clean_env
+
+test_succeeded
index fee78dff71e7bf8acbc51cdde39cfc2122d7db67..1284001f5d8a13682e9cf47857e920e0c80bc67f 100755 (executable)
@@ -8,13 +8,18 @@ setup_env
 
 (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
 
index 10230b375ba8b1a2192be03a6432c4fdf57743ce..97227f58e602adbe0c7a4b83b7a15ae9e09be860 100755 (executable)
@@ -8,13 +8,21 @@ setup_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
 
diff --git a/test/wallet_descriptors.tests.sh b/test/wallet_descriptors.tests.sh
new file mode 100755 (executable)
index 0000000..88e6db6
--- /dev/null
@@ -0,0 +1,22 @@
+#!/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
diff --git a/test/wallet_exists.tests.sh b/test/wallet_exists.tests.sh
new file mode 100755 (executable)
index 0000000..934631d
--- /dev/null
@@ -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" "$(<result)"
+
+setup_test_wallets
+
+wallet_exists 1 > /dev/null
+
+clean_env
+
+test_succeeded
index 3097cc31bb6ea1c559f8e5794cca685c220e18ac..b72ae6615f83a099b766ebaa54afd41aa729d248 100755 (executable)
@@ -144,6 +144,13 @@ loaded descriptors for wallet2 from wallet2.descriptors"
 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
diff --git a/test/wallet_missing.tests.sh b/test/wallet_missing.tests.sh
new file mode 100755 (executable)
index 0000000..24935ae
--- /dev/null
@@ -0,0 +1,22 @@
+#!/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
diff --git a/test/wallets.tests.sh b/test/wallets.tests.sh
new file mode 100755 (executable)
index 0000000..aeae37a
--- /dev/null
@@ -0,0 +1,21 @@
+#!/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
diff --git a/test/wallets_clean.tests.sh b/test/wallets_clean.tests.sh
new file mode 100755 (executable)
index 0000000..94f23cf
--- /dev/null
@@ -0,0 +1,17 @@
+#!/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