-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·88 lines (76 loc) · 3.94 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·88 lines (76 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
set -e
IMAGE_NAME=icp-cli-network-launcher-bitcoin
# Find the running container built from our custom image
BITCOIN_CONTAINER=$(docker ps --filter "ancestor=${IMAGE_NAME}" --format "{{.ID}}" | head -1)
echo "=== Test 1: get_p2pkh_address returns a valid Bitcoin address ==="
result=$(icp canister call backend get_p2pkh_address '()') && \
echo "$result" && \
echo "$result" | grep -q '"' && \
echo "PASS" || (echo "FAIL" && exit 1)
echo "=== Test 2: get_p2wpkh_address returns a valid Bitcoin address ==="
result=$(icp canister call backend get_p2wpkh_address '()') && \
echo "$result" && \
echo "$result" | grep -q '"' && \
echo "PASS" || (echo "FAIL" && exit 1)
echo "=== Test 3: get_p2tr_key_path_only_address returns a valid Bitcoin address ==="
result=$(icp canister call backend get_p2tr_key_path_only_address '()') && \
echo "$result" && \
echo "$result" | grep -q '"' && \
echo "PASS" || (echo "FAIL" && exit 1)
echo "=== Test 4: get_p2tr_script_path_enabled_address returns a valid Bitcoin address ==="
result=$(icp canister call backend get_p2tr_script_path_enabled_address '()') && \
echo "$result" && \
echo "$result" | grep -q '"' && \
echo "PASS" || (echo "FAIL" && exit 1)
echo "=== Test 5: get_current_fee_percentiles returns a vec ==="
result=$(icp canister call backend get_current_fee_percentiles '()') && \
echo "$result" && \
echo "PASS" || (echo "FAIL" && exit 1)
echo "=== Mining 101 blocks to fund test address ==="
[ -n "$BITCOIN_CONTAINER" ] || (echo "ERROR: network launcher container not running — run 'icp network start -d' first" && exit 1)
addr=$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \
docker exec "$BITCOIN_CONTAINER" bitcoin-cli -regtest \
-rpcuser=ic-btc-integration -rpcpassword=ic-btc-integration \
generatetoaddress 101 "$addr" > /dev/null && \
echo "mined 101 blocks to $addr"
echo "=== Waiting for IC to sync Bitcoin blocks ==="
_sync_addr=$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"')
# Poll get_utxos until it succeeds AND reports a non-zero tip_height.
# Using get_utxos (not get_balance) because it reflects the definitive sync state:
# get_balance can return stale non-zero values from previous runs while the bitcoin
# integration canister is still syncing new blocks and rejecting all fresh calls.
# The || { sleep; continue; } pattern retries on both rejection errors and zero height.
_synced=false
for _i in $(seq 1 60); do
_result=$(icp canister call backend get_utxos "(\"$_sync_addr\")" 2>/dev/null) \
|| { sleep 1; continue; }
echo "$_result" | grep -qE 'tip_height = [1-9][0-9]*' \
|| { sleep 1; continue; }
echo "IC synced after ${_i}s"
_synced=true
break
done
[ "$_synced" = true ] || { echo "FAIL: IC did not sync within 60s"; exit 1; }
echo "=== Test 6: get_balance returns non-zero after mining ==="
addr=$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \
result=$(icp canister call backend get_balance "(\"$addr\")") && \
echo "$result" && \
echo "$result" | grep -qE '^\([1-9]' && \
echo "PASS" || (echo "FAIL" && exit 1)
echo "=== Test 7: get_utxos returns synced chain state after mining ==="
addr=$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \
result=$(icp canister call backend get_utxos "(\"$addr\")") && \
echo "$result" && \
echo "$result" | grep -qE 'tip_height = [1-9][0-9]*' && \
echo "PASS" || (echo "FAIL" && exit 1)
echo "=== Test 8: get_blockchain_info returns tip_height ==="
result=$(icp canister call backend get_blockchain_info '()') && \
echo "$result" && \
echo "$result" | grep -q 'height' && \
echo "PASS" || (echo "FAIL" && exit 1)
echo "=== Test 9: get_block_headers returns headers ==="
result=$(icp canister call backend get_block_headers '(0: nat32, null)') && \
echo "$result" && \
echo "$result" | grep -q 'tip_height' && \
echo "PASS" || (echo "FAIL" && exit 1)