|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +IMAGE_NAME=icp-cli-network-launcher-bitcoin |
| 5 | +# Find the running container built from our custom image |
| 6 | +BITCOIN_CONTAINER=$(docker ps --filter "ancestor=${IMAGE_NAME}" --format "{{.ID}}" | head -1) |
| 7 | + |
| 8 | +echo "=== Test 1: get_p2pkh_address returns a valid Bitcoin address ===" |
| 9 | +result=$(icp canister call backend get_p2pkh_address '()') && \ |
| 10 | + echo "$result" && \ |
| 11 | + echo "$result" | grep -q '"' && \ |
| 12 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 13 | + |
| 14 | +echo "=== Test 2: get_p2wpkh_address returns a valid Bitcoin address ===" |
| 15 | +result=$(icp canister call backend get_p2wpkh_address '()') && \ |
| 16 | + echo "$result" && \ |
| 17 | + echo "$result" | grep -q '"' && \ |
| 18 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 19 | + |
| 20 | +echo "=== Test 3: get_p2tr_key_path_only_address returns a valid Bitcoin address ===" |
| 21 | +result=$(icp canister call backend get_p2tr_key_path_only_address '()') && \ |
| 22 | + echo "$result" && \ |
| 23 | + echo "$result" | grep -q '"' && \ |
| 24 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 25 | + |
| 26 | +echo "=== Test 4: get_p2tr_script_path_enabled_address returns a valid Bitcoin address ===" |
| 27 | +result=$(icp canister call backend get_p2tr_script_path_enabled_address '()') && \ |
| 28 | + echo "$result" && \ |
| 29 | + echo "$result" | grep -q '"' && \ |
| 30 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 31 | + |
| 32 | +echo "=== Test 5: get_current_fee_percentiles returns a vec ===" |
| 33 | +result=$(icp canister call backend get_current_fee_percentiles '()') && \ |
| 34 | + echo "$result" && \ |
| 35 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 36 | + |
| 37 | +echo "=== Mining 101 blocks to fund test address ===" |
| 38 | +[ -n "$BITCOIN_CONTAINER" ] || (echo "ERROR: network launcher container not running — run 'icp network start -d' first" && exit 1) |
| 39 | +addr=$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \ |
| 40 | + docker exec "$BITCOIN_CONTAINER" bitcoin-cli -regtest \ |
| 41 | + -rpcuser=ic-btc-integration -rpcpassword=ic-btc-integration \ |
| 42 | + generatetoaddress 101 "$addr" > /dev/null && \ |
| 43 | + echo "mined 101 blocks to $addr" |
| 44 | + |
| 45 | +echo "=== Waiting for IC to sync Bitcoin blocks ===" |
| 46 | +sleep 5 |
| 47 | + |
| 48 | +echo "=== Test 6: get_balance returns non-zero after mining ===" |
| 49 | +addr=$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \ |
| 50 | + result=$(icp canister call backend get_balance "(\"$addr\")") && \ |
| 51 | + echo "$result" && \ |
| 52 | + echo "$result" | grep -qE '[1-9]' && \ |
| 53 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 54 | + |
| 55 | +echo "=== Test 7: get_utxos returns synced chain state after mining ===" |
| 56 | +addr=$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \ |
| 57 | + result=$(icp canister call backend get_utxos "(\"$addr\")") && \ |
| 58 | + echo "$result" && \ |
| 59 | + echo "$result" | grep -q 'tip_height = 101' && \ |
| 60 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 61 | + |
| 62 | +echo "=== Test 8: get_blockchain_info returns tip_height ===" |
| 63 | +result=$(icp canister call backend get_blockchain_info '()') && \ |
| 64 | + echo "$result" && \ |
| 65 | + echo "$result" | grep -q 'height' && \ |
| 66 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 67 | + |
| 68 | +echo "=== Test 9: get_block_headers returns headers ===" |
| 69 | +result=$(icp canister call backend get_block_headers '(0: nat32, null)') && \ |
| 70 | + echo "$result" && \ |
| 71 | + echo "$result" | grep -q 'tip_height' && \ |
| 72 | + echo "PASS" || (echo "FAIL" && exit 1) |
0 commit comments