-
Notifications
You must be signed in to change notification settings - Fork 435
chore: add ic env + build-image.sh to motoko/basic_bitcoin #1429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,4 +40,4 @@ jobs: | |
| run: | | ||
| icp network start -d | ||
| icp deploy --cycles 30t | ||
| make test | ||
| bash test.sh | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
| # Uses --pull to always fetch the latest base image. | ||
| # Remove --pull if the Dockerfile is updated to pin the base image version. | ||
| docker build --pull -t icp-cli-network-launcher-bitcoin . | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #!/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_p2tr_key_only_address returns a valid Bitcoin address ===" | ||
| result=$(icp canister call backend get_p2tr_key_only_address '()') && \ | ||
| echo "$result" && \ | ||
| echo "$result" | grep -q '"' && \ | ||
| echo "PASS" || (echo "FAIL" && exit 1) | ||
|
|
||
| echo "=== Test 3: get_p2tr_address returns a valid Bitcoin address ===" | ||
| result=$(icp canister call backend get_p2tr_address '()') && \ | ||
| echo "$result" && \ | ||
| echo "$result" | grep -q '"' && \ | ||
| echo "PASS" || (echo "FAIL" && exit 1) | ||
|
|
||
| echo "=== Test 4: 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 5: 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 6: 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 "=== All tests passed ===" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.