Skip to content

Commit 11527ad

Browse files
authored
Merge pull request #49 from synonymdev/regtest-mine-test-mempool
Regtest mine also tests mempool tip height
2 parents 397e4c7 + be8b370 commit 11527ad

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

.github/workflows/regtest-mine.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
description: Blocktank base URL
1010
required: true
1111
default: 'https://api.stag0.blocktank.to/blocktank/api/v2'
12+
mempool_server:
13+
description: Mempool API base URL
14+
required: true
15+
default: 'https://mempool.bitkit.stag0.blocktank.to'
1216
block_count:
1317
description: Number of regtest blocks to mine
1418
required: true
@@ -20,6 +24,7 @@ jobs:
2024
env:
2125
BLOCK_COUNT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.block_count || '1' }}
2226
BLOCKTANK_SERVER: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.blocktank_server || 'https://api.stag0.blocktank.to/blocktank/api/v2' }}
27+
MEMPOOL_SERVER: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.mempool_server || 'https://mempool.bitkit.stag0.blocktank.to' }}
2328
steps:
2429
- name: Validate params
2530
run: |
@@ -39,6 +44,20 @@ jobs:
3944
echo "BLOCKTANK_SERVER is empty" >&2
4045
exit 1
4146
fi
47+
if [[ -z "${MEMPOOL_SERVER}" ]]; then
48+
echo "MEMPOOL_SERVER is empty" >&2
49+
exit 1
50+
fi
51+
- name: Capture initial tip height
52+
run: |
53+
MEMPOOL_API="${MEMPOOL_SERVER%/}/api/blocks/tip/height"
54+
TIP_BEFORE=$(curl -sS "${MEMPOOL_API}" | tr -dc '0-9')
55+
if [[ -z "${TIP_BEFORE}" ]]; then
56+
echo "Failed to obtain initial block height" >&2
57+
exit 1
58+
fi
59+
echo "Initial tip height: ${TIP_BEFORE}"
60+
echo "TIP_BEFORE=${TIP_BEFORE}" >> "${GITHUB_ENV}"
4261
- name: Mine regtest blocks
4362
run: |
4463
echo "Mining ${BLOCK_COUNT} block(s) on regtest..."
@@ -47,3 +66,26 @@ jobs:
4766
"${BLOCKTANK_SERVER}/regtest/chain/mine" \
4867
-H 'Content-Type: application/json' \
4968
-d "{\"count\": ${BLOCK_COUNT}}"
69+
- name: Verify new tip height
70+
run: |
71+
MEMPOOL_API="${MEMPOOL_SERVER%/}/api/blocks/tip/height"
72+
EXPECTED=$((TIP_BEFORE + BLOCK_COUNT))
73+
echo "Waiting up to 10 seconds for tip height to reach ${EXPECTED}..."
74+
END=$((SECONDS + 10))
75+
LAST_TIP=""
76+
while (( SECONDS < END )); do
77+
TIP_AFTER=$(curl -sS "${MEMPOOL_API}" | tr -dc '0-9')
78+
if [[ -n "${TIP_AFTER}" ]]; then
79+
LAST_TIP="${TIP_AFTER}"
80+
if (( TIP_AFTER >= EXPECTED )); then
81+
echo "New tip height: ${TIP_AFTER}"
82+
echo "Regtest height increased as expected"
83+
exit 0
84+
fi
85+
else
86+
echo "Failed to read tip height, retrying..."
87+
fi
88+
sleep 1
89+
done
90+
echo "Tip height did not reach expected value ${EXPECTED} (started at ${TIP_BEFORE}) within 10 seconds (last observed: ${LAST_TIP:-unknown})" >&2
91+
exit 1

0 commit comments

Comments
 (0)