...
authoralex <[email protected]>
Fri, 24 Jun 2022 19:56:08 +0000 (12:56 -0700)
committeralex <[email protected]>
Fri, 24 Jun 2022 19:56:08 +0000 (12:56 -0700)
cold-setup
test/bitcoin_core_start.tests.sh [new file with mode: 0755]
test/bitcoin_core_stop.tests.sh [new file with mode: 0755]
test/depends.tests.sh [new file with mode: 0755]
test/detect.tests.sh [new file with mode: 0755]
test/function_replace.tests.sh [new file with mode: 0755]
test/multisig_create.tests.sh [new file with mode: 0644]

index ea16733658153a6d847d3b7fc5ef385eedc0bd9c..559b83fe058e28367f8c559891ab09a1f0e91f60 100755 (executable)
@@ -14,6 +14,12 @@ USB_PATH_PRE_DECRYPT=
 BITCOIN_CLI="bitcoin-cli -datadir=$DATA_DIRECTORY -chain=regtest"
 
 bitcoin_core_start() {
+       RUNNING=`ps -A | ( grep bitcoind > /dev/null && echo "1" ) || echo "0"`
+       if [[ "$RUNNING" -gt 0 ]]; then
+               log_error "ERROR: bitcoin core already running\nexitting..."
+               exit 1
+       fi
+
        log_info "starting bitcoin core..."
        mkdir -p "$DATA_DIRECTORY"
        bitcoind -daemonwait -datadir="$DATA_DIRECTORY" -chain=regtest &> /dev/null
@@ -21,6 +27,12 @@ bitcoin_core_start() {
 }
 
 bitcoin_core_stop() {
+       RUNNING=`ps -A | ( grep bitcoind > /dev/null && echo "1" ) || echo "0"`
+       if [[ "$RUNNING" -eq 0 ]]; then
+               log_error "ERROR: bitcoin core not running\nexitting..."
+               exit 1
+       fi
+
        log_info "stopping bitcoin core..."
        local CMD="$BITCOIN_CLI stop"
        eval "$CMD" &> /dev/null
@@ -29,16 +41,18 @@ bitcoin_core_stop() {
 }
 
 depends() {
+       PATH="$PATH:/sbin"
+
        detect base64
        detect bitcoind
        detect bitcoin-cli
-#      detect cryptsetup
+       detect cryptsetup
        detect eject
        detect jq
-#      detect mkfs.ext4
+       detect mkfs.ext4
        detect nmcli
        detect shred
-#      detect wipefs
+       detect wipefs
 }
 
 detect() {
@@ -102,8 +116,7 @@ multisig_create() {
 }
 
 network_off() {
-       echo "turn networking off"
-       exit 1
+       nmcli networking off
 }
 
 parse_arguments() {
@@ -397,6 +410,8 @@ main() {
 
        bitcoin_core_start
 
+       network_off
+
        wallets
        multisig_create
 
diff --git a/test/bitcoin_core_start.tests.sh b/test/bitcoin_core_start.tests.sh
new file mode 100755 (executable)
index 0000000..dc8a133
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+mkdir "$TEST_DIR"
+cd "$TEST_DIR"
+
+(bitcoin_core_start > result)
+EXPECTED=$'starting bitcoin core...\nbitcoin core started'
+RESULT=$(<result)
+assert "$EXPECTED" "$RESULT"
+
+set +e
+(bitcoin_core_start > result 2>&1)
+assert "1" "$?"
+set -e
+EXPECTED=$'ERROR: bitcoin core already running\nexitting...'
+RESULT=$(<result)
+assert "$EXPECTED" "$RESULT"
+
+clean_env
+
+test_succeeded
diff --git a/test/bitcoin_core_stop.tests.sh b/test/bitcoin_core_stop.tests.sh
new file mode 100755 (executable)
index 0000000..b5102ef
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+(bitcoin_core_stop > result)
+EXPECTED=$'stopping bitcoin core...\nbitcoin core stopped'
+RESULT=$(<result)
+assert "$EXPECTED" "$RESULT"
+
+set +e
+(bitcoin_core_stop > result 2>&1)
+assert "1" "$?"
+set -e
+EXPECTED=$'ERROR: bitcoin core not running\nexitting...'
+RESULT=$(<result)
+
+cd ..
+rm -rf "$TEST_DIR"
+
+test_succeeded
diff --git a/test/depends.tests.sh b/test/depends.tests.sh
new file mode 100755 (executable)
index 0000000..628a513
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+(depends > result)
+
+clean_env
+
+test_succeeded
diff --git a/test/detect.tests.sh b/test/detect.tests.sh
new file mode 100755 (executable)
index 0000000..0d21ebb
--- /dev/null
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+(detect "ls" > result)
+(detect "cp" > result)
+(detect "mkdir" > result)
+
+set +e
+(detect "masodifsoidfnaiosdnfokdir" > result 2>&1)
+assert "1" "$?"
+set -e
+EXPECTED="masodifsoidfnaiosdnfokdir: command not found"
+RESULT=$(<result)
+assert "$EXPECTED" "$RESULT"
+
+clean_env
+
+test_succeeded
diff --git a/test/function_replace.tests.sh b/test/function_replace.tests.sh
new file mode 100755 (executable)
index 0000000..52a3b02
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+mkdir "function_replace_test"
+
+echo "help!" > function_replace_test/foo
+
+(ls function_replace_test > result)
+EXPECTED="foo"
+RESULT=$(<result)
+assert "$EXPECTED" "$RESULT"
+
+ls() {
+       echo "replaced ls function"
+}
+
+(ls function_replace_test > result)
+EXPECTED="replaced ls function"
+RESULT=$(<result)
+assert "$EXPECTED" "$RESULT"
+
+clean_env
+
+test_succeeded
diff --git a/test/multisig_create.tests.sh b/test/multisig_create.tests.sh
new file mode 100644 (file)
index 0000000..e4471f3
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+test_failed
+
+clean_env
+
+test_succeeded