]> infiniteadaptability.org Git - cold/commitdiff
...
authoralex <[email protected]>
Wed, 18 May 2022 05:54:26 +0000 (22:54 -0700)
committeralex <[email protected]>
Wed, 18 May 2022 05:54:26 +0000 (22:54 -0700)
.gitignore
Makefile.am
cold-setup [new file with mode: 0755]
test/setup.sh [new file with mode: 0644]

index 0baa996821d659014b302ba4747caa5288e61407..9e90fea36687db62dea6bb6b494f3b04f15de41d 100644 (file)
@@ -27,5 +27,9 @@ tags
 *.trs
 *.tests
 
+# test objects
+test/source.sh
+test/.testdir
+
 # binaries
 cold
index 1634c27894950e310d996d20d14a307121a2ed7e..51cfa4d0740ec725090a5fbc04d7f49a2dae6859 100644 (file)
@@ -15,3 +15,12 @@ cold_SOURCES = \
 
 cold_SOURCES += \
        inc/main.h
+
+check-local:
+       @head -n `grep -n "main()" cold-setup | cut -f1 -d:` cold-setup | head -n -1 > test/source.sh
+       @cd test && run-parts --exit-on-error --regex '.*\.tests\.sh' .
+
+clean-local:
+       @rm -vrf test/.testdir
+
+.PHONY: check-local clean-local
diff --git a/cold-setup b/cold-setup
new file mode 100755 (executable)
index 0000000..0f887f2
--- /dev/null
@@ -0,0 +1,119 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+M=3
+N=7
+
+bitcoin_core_start() {
+       log_msg "starting bitcoin core..."
+       bitcoind --daemon &> /dev/null
+}
+
+bitcoin_core_ready() {
+       set +e
+       for i in {1..5}; do
+               bitcoin-cli help &> /dev/null
+               if [[ $? -eq 0 ]]; then
+                       set -e
+                       log_msg "bitcoin core ready"
+                       return
+               fi
+               sleep 2
+       done
+
+       log_error "bitcoin_core start failed"
+       bitcoin_core_stop
+       exit 1
+}
+
+bitcoin_core_stop() {
+       log_msg "stopping bitcoin core..."
+       bitcoin-cli stop &> /dev/null
+       log_msg "bitcoin core stopped"
+}
+
+depends() {
+       detect base64
+       detect bitcoind
+       detect bitcoin-cli
+#      detect cryptsetup
+       detect eject
+       detect jq
+#      detect mkfs.ext4
+       detect nmcli
+       detect shred
+#      detect wipefs
+}
+
+detect() {
+       set +e
+       which "$1" > /dev/null
+       if [[ $? -ne 0 ]]; then
+               log_error "$1: command not found"
+               exit 1
+       fi
+       set -e
+}
+
+log_error() {
+       echo "$@" >&2
+}
+
+log_msg() {
+       echo "$@"
+}
+
+multisig_create() {
+       local DESCRIPTORS="wsh(sortedmulti($M,"
+
+       for((i = 1; i <= $M; i++)); do
+               DESCRIPTORS+=wallet_descriptors $i
+       done
+
+       DESCRIPTORS+="))"
+}
+
+network_off() {
+       echo "turn networking off"
+       exit 1
+}
+
+usage() {
+
+}
+
+wallet_create() {
+       bitcoin-cli -named createwallet wallet_name=\"wallet$1\" descriptors=true
+}
+
+wallet_descriptors() {
+       local DESCRIPTORS=`bitcoin-cli -rpcwallet=wallet$1 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == false)) | map(.desc | ltrimstr("wpkh")) | .[] | split(")") | .[0]'`
+}
+
+wallet_change_descriptors() {
+       local DESCRIPTORS=`bitcoin-cli -rpcwallet=wallet$1 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == true)) | map(.desc | ltrimstr("wpkh")) | .[] | split(")") | .[0]'`
+}
+
+wallet_dump_descriptors() {
+       bitcoin-cli -named -rpcwallet=wallet$1 listdescriptors private=true
+}
+
+wallets() {
+       for((i = 1; i <= $1; i++)); do
+               wallet_create "$i"
+       done
+}
+
+main() {
+       depends
+       bitcoin_core_start
+
+       bitcoin_core_ready
+
+       wallets "$M"
+
+       bitcoin_core_stop
+}
+
+main "$@"
diff --git a/test/setup.sh b/test/setup.sh
new file mode 100644 (file)
index 0000000..d2d6a64
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+
+TEST_DIR=".testdir"
+
+source source.sh
+
+clean_env() {
+       cd ..
+       rm -rf "$TEST_DIR"
+}
+
+setup_env() {
+       mkdir "$TEST_DIR"
+       cd "$TEST_DIR"
+} > /dev/null 2>&1
+
+reset_env() {
+       clean_env
+       setup_env
+}
+
+assert() {
+       if [[ "$1" != "$2" ]]; then
+               echo -e "Expected:\n$1\nResult:\n$2"
+               echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} failed"
+               exit 1
+       fi
+}
+
+test_failed() {
+       echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} failed"
+       exit 1
+}
+
+test_succeeded() {
+       echo "${BASH_SOURCE[1]} succeeded"
+       clean_env
+}