|
1 | | -.PHONY: all |
2 | | -all: deploy |
3 | | - |
4 | | -.PHONY: deploy |
5 | | -.SILENT: deploy |
6 | | -deploy: |
7 | | - dfx deploy basic_bitcoin --argument '(variant { regtest })' |
8 | | - |
9 | | -.PHONY: regtest_topup |
10 | | -.SILENT: regtest_topup |
11 | | -regtest_topup: |
12 | | - P2PKH_ADDR=$(shell dfx canister call basic_bitcoin get_p2pkh_address | tr -d '()') && \ |
13 | | - P2TR_ADDR=$(shell dfx canister call basic_bitcoin get_p2tr_address | tr -d '()') && \ |
14 | | - P2TR_KEY_ONLY_ADDR=$(shell dfx canister call basic_bitcoin get_p2tr_key_only_address | tr -d '()') && \ |
15 | | - TOPUP_CMD_P2PKH_ADDR="bitcoin-cli -regtest -rpcport=8333 sendtoaddress $${P2PKH_ADDR} 1" && \ |
16 | | - TOPUP_CMD_P2TR_ADDR="bitcoin-cli -regtest -rpcport=8333 sendtoaddress $${P2TR_ADDR} 1" && \ |
17 | | - TOPUP_CMD_P2TR_KEY_ONLY_ADDR="bitcoin-cli -regtest -rpcport=8333 sendtoaddress $${P2TR_KEY_ONLY_ADDR} 1" && \ |
18 | | - eval "$${TOPUP_CMD_P2PKH_ADDR}" && \ |
19 | | - eval "$${TOPUP_CMD_P2PKH_ADDR}" && \ |
20 | | - eval "$${TOPUP_CMD_P2PKH_ADDR}" && \ |
21 | | - eval "$${TOPUP_CMD_P2TR_ADDR}" && \ |
22 | | - eval "$${TOPUP_CMD_P2TR_ADDR}" && \ |
23 | | - eval "$${TOPUP_CMD_P2TR_ADDR}" && \ |
24 | | - eval "$${TOPUP_CMD_P2TR_KEY_ONLY_ADDR}" && \ |
25 | | - eval "$${TOPUP_CMD_P2TR_KEY_ONLY_ADDR}" && \ |
26 | | - eval "$${TOPUP_CMD_P2TR_KEY_ONLY_ADDR}" && \ |
27 | | - bitcoin-cli -regtest -rpcport=8333 -generate 6 |
28 | | - |
29 | | -.PHONY: test |
30 | | -.SILENT: test |
31 | | -# No tests yet. This target exists so CI doesn't fail when it runs `make test`. |
| 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 | + |
32 | 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_p2wpkh_address returns a valid Bitcoin address ===" |
| 23 | + @result=$$(icp canister call backend get_p2wpkh_address '()') && \ |
| 24 | + echo "$$result" && \ |
| 25 | + echo "$$result" | grep -q '"' && \ |
| 26 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 27 | + |
| 28 | + @echo "=== Test 3: get_p2tr_key_path_only_address returns a valid Bitcoin address ===" |
| 29 | + @result=$$(icp canister call backend get_p2tr_key_path_only_address '()') && \ |
| 30 | + echo "$$result" && \ |
| 31 | + echo "$$result" | grep -q '"' && \ |
| 32 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 33 | + |
| 34 | + @echo "=== Test 4: get_p2tr_script_path_enabled_address returns a valid Bitcoin address ===" |
| 35 | + @result=$$(icp canister call backend get_p2tr_script_path_enabled_address '()') && \ |
| 36 | + echo "$$result" && \ |
| 37 | + echo "$$result" | grep -q '"' && \ |
| 38 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 39 | + |
| 40 | + @echo "=== Test 5: get_current_fee_percentiles returns a vec ===" |
| 41 | + @result=$$(icp canister call backend get_current_fee_percentiles '()') && \ |
| 42 | + echo "$$result" && \ |
| 43 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 44 | + |
| 45 | + @echo "=== Mining 101 blocks to fund test address ===" |
| 46 | + @[ -n "$(BITCOIN_CONTAINER)" ] || (echo "ERROR: network launcher container not running — run 'icp network start -d' first" && exit 1) |
| 47 | + @addr=$$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \ |
| 48 | + docker exec $(BITCOIN_CONTAINER) bitcoin-cli -regtest \ |
| 49 | + -rpcuser=ic-btc-integration -rpcpassword=ic-btc-integration \ |
| 50 | + generatetoaddress 101 "$$addr" > /dev/null && \ |
| 51 | + echo "mined 101 blocks to $$addr" |
| 52 | + |
| 53 | + @echo "=== Waiting for IC to sync Bitcoin blocks ===" |
| 54 | + @sleep 5 |
| 55 | + |
| 56 | + @echo "=== Test 6: get_balance returns non-zero after mining ===" |
| 57 | + @addr=$$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \ |
| 58 | + result=$$(icp canister call backend get_balance "(\"$$addr\")") && \ |
| 59 | + echo "$$result" && \ |
| 60 | + echo "$$result" | grep -qE '[1-9]' && \ |
| 61 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 62 | + |
| 63 | + @echo "=== Test 7: get_utxos returns synced chain state after mining ===" |
| 64 | + @addr=$$(icp canister call backend get_p2pkh_address '()' | grep -o '"[^"]*"' | tr -d '"') && \ |
| 65 | + result=$$(icp canister call backend get_utxos "(\"$$addr\")") && \ |
| 66 | + echo "$$result" && \ |
| 67 | + echo "$$result" | grep -q 'tip_height = 101' && \ |
| 68 | + echo "PASS" || (echo "FAIL" && exit 1) |
| 69 | + |
| 70 | + @echo "=== Test 8: get_blockchain_info returns tip_height ===" |
| 71 | + @result=$$(icp canister call backend get_blockchain_info '()') && \ |
| 72 | + echo "$$result" && \ |
| 73 | + echo "$$result" | grep -q 'height' && \ |
| 74 | + echo "PASS" || (echo "FAIL" && exit 1) |
33 | 75 |
|
34 | | -.PHONY: clean |
35 | | -.SILENT: clean |
36 | | -clean: |
37 | | - rm -rf .dfx |
38 | | - rm -rf dist |
39 | | - rm -rf node_modules |
40 | | - rm -rf src/declarations |
41 | | - rm -f .env |
42 | | - cargo clean |
| 76 | + @echo "=== Test 9: get_block_headers returns headers ===" |
| 77 | + @result=$$(icp canister call backend get_block_headers '(0: nat32, null)') && \ |
| 78 | + echo "$$result" && \ |
| 79 | + echo "$$result" | grep -q 'tip_height' && \ |
| 80 | + echo "PASS" || (echo "FAIL" && exit 1) |
0 commit comments