]> infiniteadaptability.org Git - cold/commitdiff
...
authoralex <[email protected]>
Sun, 26 Jun 2022 07:55:57 +0000 (00:55 -0700)
committeralex <[email protected]>
Sun, 26 Jun 2022 07:55:57 +0000 (00:55 -0700)
cold-setup
test/setup.sh
test/usb_detect.tests.sh
test/wallet_multisig_correctness.tests.sh [new file with mode: 0755]
test/wallet_multisig_spend_correctness.tests.sh [new file with mode: 0755]

index a256a5a55416b4200a4465d7ee07c4c393d1ba57..62afaf9df05bdf52f8e2dafafe4fe09c9ac25dee 100755 (executable)
@@ -113,7 +113,7 @@ multisig_create() {
 
        echo -n '{"desc": "' >> "$DUMPFILE"
        eval "$CMD" >> "$DUMPFILE"
-       echo -n '", "active": true, "timestamp": "now"}]' >> "$DUMPFILE"
+       echo -n '", "active": true, "timestamp": "now", "internal": true}]' >> "$DUMPFILE"
 }
 
 network_off() {
@@ -215,7 +215,6 @@ usb_crypt_close() {
 
 usb_detect() {
        local DEVNAME
-       log_msg "plug in usb drive now.\ndetecting..."
 
        coproc udevadm monitor -s block/disk -u -p
 
@@ -236,7 +235,6 @@ usb_detect() {
 
        kill $COPROC_PID
 
-       log_msg "found usb drive: $DEVNAME"
        echo "$DEVNAME"
 }
 
index adbda6e3d4a02a04b6efae680c69985fc6ec7d24..36c6bfd47428683cc95ac7b0da58912ddcfe344e 100644 (file)
@@ -4,6 +4,14 @@ TEST_DIR=".testdir"
 
 source source.sh
 
+assert() {
+       if [[ "$1" != "$2" ]]; then
+               echo -e "Expected:\n$1\nResult:\n$2"
+               echo -e "${BASH_SOURCE[1]}:${BASH_LINENO[0]} \e[31mFAILED\e[0m"
+               exit 1
+       fi
+}
+
 clean_env() {
        bitcoin_core_stop
        cd ..
@@ -16,7 +24,7 @@ setup_env() {
        bitcoin_core_start
 } > /dev/null 2>&1
 
-setup_test_wallets() {
+setup_test_descriptors() {
        cat > wallet1.descriptors << EOF
 {
   "wallet_name": "wallet1",
@@ -688,6 +696,10 @@ EOF
   ]
 }
 EOF
+}
+
+setup_test_wallets() {
+       setup_test_descriptors
 
        for((i = 1; i<= 7; i++)); do
                (wallet_load "$i" "wallet$i.descriptors" > result 2>&1)
@@ -729,14 +741,6 @@ reset_env() {
        setup_env
 }
 
-assert() {
-       if [[ "$1" != "$2" ]]; then
-               echo -e "Expected:\n$1\nResult:\n$2"
-               echo -e "${BASH_SOURCE[1]}:${BASH_LINENO[0]} \e[31mFAILED\e[0m"
-               exit 1
-       fi
-}
-
 test_failed() {
        echo -e "${BASH_SOURCE[1]}:${BASH_LINENO[0]} \e[31mFAILED\e[0m"
        exit 1
index 252e259d92ddafadb17caba298e7cc6c13637c82..30abada3b61cc6be8900ac644eeb86f8de324022 100755 (executable)
@@ -7,7 +7,90 @@ source setup.sh
 mkdir "$TEST_DIR"
 cd "$TEST_DIR"
 
-test_failed
+udevadm() {
+       # remove event for /dev/sdf
+       echo "UDEV  [1787.032378] remove   /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sdf (block)
+ACTION=remove
+DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sdf
+SUBSYSTEM=block
+DEVNAME=/dev/sdf
+DEVTYPE=disk
+SEQNUM=3185
+USEC_INITIALIZED=1778132471
+ID_VENDOR=Flash
+ID_VENDOR_ENC=Flash\x20\x20\x20
+ID_VENDOR_ID=1221
+ID_MODEL=USB_Disk
+ID_MODEL_ENC=USB\x20Disk\x20\x20\x20\x20\x20\x20\x20\x20
+ID_MODEL_ID=3234
+ID_REVISION=2.F0
+ID_SERIAL=Flash_USB_Disk_37270108153C451042955-0:0
+ID_SERIAL_SHORT=37270108153C451042955
+ID_TYPE=disk
+ID_INSTANCE=0:0
+ID_BUS=usb
+ID_USB_INTERFACES=:080650:
+ID_USB_INTERFACE_NUM=00
+ID_USB_DRIVER=usb-storage
+ID_PATH=pci-0000:00:14.0-usb-0:2:1.0-scsi-0:0:0:0
+ID_PATH_TAG=pci-0000_00_14_0-usb-0_2_1_0-scsi-0_0_0_0
+ID_PART_TABLE_UUID=00203954
+ID_PART_TABLE_TYPE=dos
+.ID_FS_TYPE_NEW=
+ID_FS_TYPE=
+MAJOR=8
+MINOR=80
+DEVLINKS=/dev/disk/by-id/usb-Flash_USB_Disk_37270108153C451042955-0:0 /dev/disk/by-path/pci-0000:00:14.0-usb-0:2:1.0-scsi-0:0:0:0
+TAGS=:systemd:
+CURRENT_TAGS=:systemd:
+"
+       # add event for /dev/sdz
+       echo "monitor will print the received events for:
+UDEV - the event which udev sends out after rule processing
+
+UDEV  [1778.138888] add      /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sdz (block)
+ACTION=add
+DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sdf
+SUBSYSTEM=block
+DEVNAME=/dev/sdz
+DEVTYPE=disk
+SEQNUM=3176
+USEC_INITIALIZED=1778132471
+ID_VENDOR=Flash
+ID_VENDOR_ENC=Flash\x20\x20\x20
+ID_VENDOR_ID=1221
+ID_MODEL=USB_Disk
+ID_MODEL_ENC=USB\x20Disk\x20\x20\x20\x20\x20\x20\x20\x20
+ID_MODEL_ID=3234
+ID_REVISION=2.F0
+ID_SERIAL=Flash_USB_Disk_37270108153C451042955-0:0
+ID_SERIAL_SHORT=37270108153C451042955
+ID_TYPE=disk
+ID_INSTANCE=0:0
+ID_BUS=usb
+ID_USB_INTERFACES=:080650:
+ID_USB_INTERFACE_NUM=00
+ID_USB_DRIVER=usb-storage
+ID_PATH=pci-0000:00:14.0-usb-0:2:1.0-scsi-0:0:0:0
+ID_PATH_TAG=pci-0000_00_14_0-usb-0_2_1_0-scsi-0_0_0_0
+ID_PART_TABLE_UUID=00203954
+ID_PART_TABLE_TYPE=dos
+.ID_FS_TYPE_NEW=
+ID_FS_TYPE=
+MAJOR=8
+MINOR=80
+DEVLINKS=/dev/disk/by-id/usb-Flash_USB_Disk_37270108153C451042955-0:0 /dev/disk/by-path/pci-0000:00:14.0-usb-0:2:1.0-scsi-0:0:0:0
+TAGS=:systemd:
+CURRENT_TAGS=:systemd:
+"
+       while true; do
+               echo "here" > /dev/null
+       done
+}
+
+(usb_detect > result)
+EXPECTED="/dev/sdz"
+assert "$EXPECTED" "$(<result)"
 
 cd ..
 rm -rf "$TEST_DIR"
diff --git a/test/wallet_multisig_correctness.tests.sh b/test/wallet_multisig_correctness.tests.sh
new file mode 100755 (executable)
index 0000000..2d9bc7e
--- /dev/null
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+setup_test_wallets
+
+multisig_create
+
+assert "c7f64e597a1a36e00eacd8683dd235cb5a27718b93020a450ef8dfaadcadc971944cf9ecb222523f45aab629e07d0b30432811ebcec1a93f7c9185feadf7d722  $DATA_DIRECTORY/descriptors.txt" "`b2sum $DATA_DIRECTORY/descriptors.txt`"
+
+(eval "$BITCOIN_CLI -named createwallet wallet_name=wallet8 descriptors=true blank=true disable_private_keys=true" > result)
+EXPECTED='{
+  "name": "wallet8",
+  "warning": ""
+}'
+assert "$EXPECTED" "$(<result)"
+
+(cat "$DATA_DIRECTORY/descriptors.txt" | eval "$BITCOIN_CLI -stdin -rpcwallet=wallet8 importdescriptors" > result)
+EXPECTED='[
+  {
+    "success": true,
+    "warnings": [
+      "Range not given, using default keypool range"
+    ]
+  },
+  {
+    "success": true,
+    "warnings": [
+      "Range not given, using default keypool range"
+    ]
+  }
+]'
+assert "$EXPECTED" "$(<result)"
+
+(eval "$BITCOIN_CLI -rpcwallet=wallet8 getwalletinfo" > result)
+EXPECTED='{
+  "walletname": "wallet8",
+  "walletversion": 169900,
+  "format": "sqlite",
+  "balance": 0.00000000,
+  "unconfirmed_balance": 0.00000000,
+  "immature_balance": 0.00000000,
+  "txcount": 0,
+  "keypoolsize": 1000,
+  "keypoolsize_hd_internal": 1000,
+  "paytxfee": 0.00000000,
+  "private_keys_enabled": false,
+  "avoid_reuse": false,
+  "scanning": false,
+  "descriptors": true,
+  "external_signer": false
+}'
+assert "$EXPECTED" "$(<result)"
+
+
+for((i = 1; i<=1000; i++)); do
+       echo "`$BITCOIN_CLI -rpcwallet=wallet8 getnewaddress`" >> addresses
+done
+
+assert "b9890d9705e771dc84061e4b119bb21c87d200fac02957d2e3f71be4fc6694111dc56e8a259bc1151b3bf7bb3d77e6239f1ecd606fd1f798ad5c915968e2d20f  addresses" "`b2sum addresses`"
+
+clean_env
+
+test_succeeded
diff --git a/test/wallet_multisig_spend_correctness.tests.sh b/test/wallet_multisig_spend_correctness.tests.sh
new file mode 100755 (executable)
index 0000000..8eb67c8
--- /dev/null
@@ -0,0 +1,226 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+setup_env
+
+setup_test_wallets
+
+multisig_create
+
+delete_wallet() {
+       eval "$BITCOIN_CLI unloadwallet wallet$1" > /dev/null
+       rm -rf "$DATA_DIRECTORY/regtest/wallets/wallet$1"
+}
+
+load() {
+       (wallet_load "$1" "wallet$1.descriptors" > result 2>&1)
+       EXPECTED="created blank wallet: wallet$1
+[
+  {
+    \"success\": true
+  },
+  {
+    \"success\": true
+  },
+  {
+    \"success\": true
+  },
+  {
+    \"success\": true
+  },
+  {
+    \"success\": true
+  },
+  {
+    \"success\": true
+  },
+  {
+    \"success\": true
+  },
+  {
+    \"success\": true
+  }
+]
+loaded descriptors for wallet$1 from wallet$1.descriptors"
+               RESULT=$(<result)
+               assert "$EXPECTED" "$RESULT"
+}
+
+sign() {
+       local CMD="$BITCOIN_CLI -rpcwallet=wallet$2 -stdin walletprocesspsbt"
+       local SIGNED="`echo "$1" | eval "$CMD" | jq -r '.psbt'`"
+       echo "$SIGNED"
+}
+
+spend() {
+       local CMD="$BITCOIN_CLI -rpcwallet=live walletcreatefundedpsbt '[]' '[{\"$1\":$2}]'"
+       local UNSIGNED="`eval "$CMD" | jq -r '.psbt'`"
+       local WALLETS=($(shuf -n "$M" -e {1..7}))
+       for i in "${WALLETS[@]}"; do
+               load "$i"
+               UNSIGNED="`sign "$UNSIGNED" $i`"
+               delete_wallet "$i"
+       done
+
+       local FINALIZED="`echo "$UNSIGNED" | eval "$BITCOIN_CLI -stdin finalizepsbt"`"
+
+       assert "true" "`echo "$FINALIZED" | jq '.complete'`"
+
+       echo "$FINALIZED" | jq -r '.hex' | eval "$BITCOIN_CLI -stdin sendrawtransaction" > /dev/null
+}
+
+assert "c7f64e597a1a36e00eacd8683dd235cb5a27718b93020a450ef8dfaadcadc971944cf9ecb222523f45aab629e07d0b30432811ebcec1a93f7c9185feadf7d722  $DATA_DIRECTORY/descriptors.txt" "`b2sum $DATA_DIRECTORY/descriptors.txt`"
+MULTISIG_DESCRIPTORS="`cat "$DATA_DIRECTORY/descriptors.txt"`"
+
+reset_env
+
+setup_test_descriptors
+
+(eval "$BITCOIN_CLI -named createwallet wallet_name=live descriptors=true blank=true disable_private_keys=true" > result)
+EXPECTED='{
+  "name": "live",
+  "warning": ""
+}'
+assert "$EXPECTED" "$(<result)"
+
+(eval "$BITCOIN_CLI -named createwallet wallet_name=dummy descriptors=true" > result)
+EXPECTED='{
+  "name": "dummy",
+  "warning": ""
+}'
+assert "$EXPECTED" "$(<result)"
+
+(echo "$MULTISIG_DESCRIPTORS" | eval "$BITCOIN_CLI -stdin -rpcwallet=live importdescriptors" > result)
+EXPECTED='[
+  {
+    "success": true,
+    "warnings": [
+      "Range not given, using default keypool range"
+    ]
+  },
+  {
+    "success": true,
+    "warnings": [
+      "Range not given, using default keypool range"
+    ]
+  }
+]'
+assert "$EXPECTED" "$(<result)"
+
+(eval "$BITCOIN_CLI -rpcwallet=live getwalletinfo" > result)
+EXPECTED='{
+  "walletname": "live",
+  "walletversion": 169900,
+  "format": "sqlite",
+  "balance": 0.00000000,
+  "unconfirmed_balance": 0.00000000,
+  "immature_balance": 0.00000000,
+  "txcount": 0,
+  "keypoolsize": 1000,
+  "keypoolsize_hd_internal": 1000,
+  "paytxfee": 0.00000000,
+  "private_keys_enabled": false,
+  "avoid_reuse": false,
+  "scanning": false,
+  "descriptors": true,
+  "external_signer": false
+}'
+assert "$EXPECTED" "$(<result)"
+
+eval "$BITCOIN_CLI -rpcwallet=dummy -generate 100" > /dev/null
+eval "$BITCOIN_CLI -rpcwallet=dummy -generate 100" > /dev/null
+
+(eval "$BITCOIN_CLI -rpcwallet=dummy getwalletinfo | jq .balance" > result)
+assert "5000" "$(<result)"
+
+for((i = 1; i<=1000; i++)); do
+       ADDRESS="`$BITCOIN_CLI -rpcwallet=live getnewaddress`"
+       eval "$BITCOIN_CLI -rpcwallet=dummy -named send outputs='{\"$ADDRESS\":1}' fee_rate=1" > /dev/null
+done
+
+eval "$BITCOIN_CLI -rpcwallet=dummy -generate 100" > /dev/null
+
+(eval "$BITCOIN_CLI -rpcwallet=live getwalletinfo" > result)
+EXPECTED='{
+  "walletname": "live",
+  "walletversion": 169900,
+  "format": "sqlite",
+  "balance": 1000.00000000,
+  "unconfirmed_balance": 0.00000000,
+  "immature_balance": 0.00000000,
+  "txcount": 1000,
+  "keypoolsize": 1000,
+  "keypoolsize_hd_internal": 1000,
+  "paytxfee": 0.00000000,
+  "private_keys_enabled": false,
+  "avoid_reuse": false,
+  "scanning": false,
+  "descriptors": true,
+  "external_signer": false
+}'
+assert "$EXPECTED" "$(<result)"
+
+ADDRESS="`$BITCOIN_CLI -rpcwallet=dummy getnewaddress`"
+for((j = 1; j<=1000; j++)); do
+       spend "$ADDRESS" 0.5
+       echo "$j transactions done..."
+done
+
+eval "$BITCOIN_CLI -rpcwallet=dummy -generate 100" > /dev/null
+
+(eval "$BITCOIN_CLI -rpcwallet=live getwalletinfo" > result)
+EXPECTED='{
+  "walletname": "live",
+  "walletversion": 169900,
+  "format": "sqlite",
+  "balance": 499.99758000,
+  "unconfirmed_balance": 0.00000000,
+  "immature_balance": 0.00000000,
+  "txcount": 2000,
+  "keypoolsize": 1000,
+  "keypoolsize_hd_internal": 1000,
+  "paytxfee": 0.00000000,
+  "private_keys_enabled": false,
+  "avoid_reuse": false,
+  "scanning": false,
+  "descriptors": true,
+  "external_signer": false
+}'
+assert "$EXPECTED" "$(<result)"
+
+ADDRESS="`$BITCOIN_CLI -rpcwallet=dummy getnewaddress`"
+
+spend "$ADDRESS" 100
+spend "$ADDRESS" 100
+spend "$ADDRESS" 100
+spend "$ADDRESS" 100
+spend "$ADDRESS" 99.99758
+
+eval "$BITCOIN_CLI -rpcwallet=dummy -generate 100" > /dev/null
+
+(eval "$BITCOIN_CLI -rpcwallet=live getwalletinfo" > result)
+EXPECTED='{
+  "walletname": "live",
+  "walletversion": 169900,
+  "format": "sqlite",
+  "balance": 0.00000000,
+  "unconfirmed_balance": 0.00000000,
+  "immature_balance": 0.00000000,
+  "txcount": 2005,
+  "keypoolsize": 1000,
+  "keypoolsize_hd_internal": 1000,
+  "paytxfee": 0.00000000,
+  "private_keys_enabled": false,
+  "avoid_reuse": false,
+  "scanning": false,
+  "descriptors": true,
+  "external_signer": false
+}'
+assert "$EXPECTED" "$(<result)"
+
+clean_env
+
+test_succeeded