|
| 1 | +IMAGE_NAME = icp-cli-network-launcher-bitcoin |
| 2 | +# Find the running container built from our custom image |
| 3 | +BITCOIN_CONTAINER = $(shell docker ps --filter "ancestor=$(IMAGE_NAME)" --format "{{.ID}}" | head -1) |
| 4 | + |
| 5 | +.PHONY: build-image test topup |
| 6 | + |
| 7 | +build-image: |
| 8 | + # Because we're building off of :latest, use --pull to fetch the latest image. |
| 9 | + # Remove `--pull` if the Dockerfile is updated to pin the base image version. |
| 10 | + docker build --pull -t $(IMAGE_NAME) . |
| 11 | + |
| 12 | +topup: |
| 13 | + icp canister top-up --amount 30t backend |
| 14 | + |
| 15 | +test: |
| 16 | + @echo "=== Test 1: get_p2pkh_address returns a valid Bitcoin address ===" |
| 17 | + @result=$$(icp canister call backend get_p2pkh_address '()') && \ |
| 18 | + echo "$$result" && \ |
| 19 | + echo "$$result" | grep -q '"' && \ |
| 20 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 21 | + |
| 22 | + @echo "=== Test 2: get_p2tr_key_only_address returns a valid Bitcoin address ===" |
| 23 | + @result=$$(icp canister call backend get_p2tr_key_only_address '()') && \ |
| 24 | + echo "$$result" && \ |
| 25 | + echo "$$result" | grep -q '"' && \ |
| 26 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 27 | + |
| 28 | + @echo "=== Test 3: get_p2tr_address returns a valid Bitcoin address ===" |
| 29 | + @result=$$(icp canister call backend get_p2tr_address '()') && \ |
| 30 | + echo "$$result" && \ |
| 31 | + echo "$$result" | grep -q '"' && \ |
| 32 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 33 | + |
| 34 | + @echo "=== Test 4: get_current_fee_percentiles returns a vec ===" |
| 35 | + @result=$$(icp canister call backend get_current_fee_percentiles '()') && \ |
| 36 | + echo "$$result" && \ |
| 37 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 38 | + |
| 39 | + @echo "=== Mining 101 blocks to fund test address ===" |
| 40 | + @[ -n "$(BITCOIN_CONTAINER)" ] || (echo "ERROR: network launcher container not running — run 'icp network start -d' first" && exit 1) |
| 41 | + @addr=$$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \ |
| 42 | + docker exec $(BITCOIN_CONTAINER) bitcoin-cli -regtest \ |
| 43 | + -rpcuser=ic-btc-integration -rpcpassword=ic-btc-integration \ |
| 44 | + generatetoaddress 101 "$$addr" > /dev/null && \ |
| 45 | + echo "mined 101 blocks to $$addr" |
| 46 | + |
| 47 | + @echo "=== Waiting for IC to sync Bitcoin blocks ===" |
| 48 | + @sleep 5 |
| 49 | + |
| 50 | + @echo "=== Test 5: get_balance returns non-zero after mining ===" |
| 51 | + @addr=$$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \ |
| 52 | + result=$$(icp canister call backend get_balance "(\"$$addr\")") && \ |
| 53 | + echo "$$result" && \ |
| 54 | + echo "$$result" | grep -qE '[1-9]' && \ |
| 55 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 56 | + |
| 57 | + @echo "=== Test 6: get_utxos returns synced chain state after mining ===" |
| 58 | + @addr=$$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \ |
| 59 | + result=$$(icp canister call backend get_utxos "(\"$$addr\")") && \ |
| 60 | + echo "$$result" && \ |
| 61 | + echo "$$result" | grep -q 'tip_height = 101' && \ |
| 62 | + echo "PASS" || (echo "FAIL" && exit 1) |
0 commit comments