Skip to content

Commit

Permalink
ci: run integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyhodl committed Dec 12, 2024
1 parent 5fe16dd commit 6ee1558
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 41 deletions.
105 changes: 64 additions & 41 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,86 @@
name: Format, clippy, and test dlcdevkit
#
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
env:
CARGO_TERM_COLOR: always

jobs:
clippy_check:
clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- name: Install Protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
override: true
toolchain: nightly
components: clippy
override: true
- name: Check clippy
run: cargo clippy -- -D warnings
fmt_check:
format:
name: format
runs-on: ubuntu-latest
steps:
- name: Install Protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt
override: true
toolchain: nightly
components: rustfmt
override: true
- name: Check format
run: cargo fmt --check

# test:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
#
# - name: Install just
# uses: extractions/setup-just@v1
#
# - name: Install Protoc
# run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
#
# - uses: actions-rs/toolchain@v1
# with:
# toolchain: stable
#
# - name: Start dependencies
# run: just ci-deps
#
# - name: Setup Bitcoin Node
# run: |
# docker logs bitcoin
# chmod +x ./testconfig/scripts/setup-bitcoind.sh
# ./testconfig/scripts/setup-bitcoind.sh
#
# - name: Run tests
# run: cargo test --all-features --verbose
#
# - name: Stop dependencies
# run: just deps-down
integration_tests_prepare:
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Install Protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt
override: true
- uses: actions/cache@v3
env:
cache-name: test-cache
with:
path: target/debug/deps
key: test-cache-${{ github.run_id }}-${{ github.run_number }}
- uses: actions/checkout@v4
- id: set-matrix
run: cargo test --no-run && echo "::set-output name=matrix::$(testconfig/scripts/get_test_list.sh manager_execution manager_tests contract_updater)"
integration_tests:
name: integration tests
needs: integration_tests_prepare
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
tests: ${{ fromJson(needs.integration_tests_prepare.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
env:
cache-name: test-cache
with:
path: target/debug/deps
key: test-cache-${{ github.run_id }}-${{ github.run_number }}
- name: Start bitcoin node
run: docker compose up -d
- name: Wait for container to run
run: ./scripts/wait_for_container.sh bitcoin
- name: Wait for electrs to be ready
run: ./scripts/wait_for_electrs.sh
- name: Run test
run: RUST_BACKTRACE=1 ${{ matrix.tests }} --ignored
- name: Stop bitcoin node
run: docker compose down -v
18 changes: 18 additions & 0 deletions testconfig/scripts/get_test_list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

OS=$(uname -s)

for TEST_PREFIX in "$@"; do
TEST_BIN=$(ls ./target/debug/deps/${TEST_PREFIX}* | grep -v '\.d\|\.o')

if [ "$OS" = "Darwin" ]; then # macOS
LIST=$(${TEST_BIN} --list --format=terse | sed 's/: test$/,/' | sed "s|\([^,]*\)|\"${TEST_BIN} \1\"|g")
else # Linux
LIST=$(${TEST_BIN} --list --format=terse | sed 's/: test$/,/' | sed 's/[^[:space:],][^[:space:],]*/"'${TEST_BIN}' &"/g')
fi

RES+=(${LIST})
done

# Use BSD-compatible sed syntax for the final output
echo $(echo [${RES[@]}] | sed 's/,]/]/')
5 changes: 5 additions & 0 deletions testconfig/scripts/wait_for_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

while [ "`docker inspect -f {{.State.Status}} $1`" != "running" ]; do
sleep 2;
done
7 changes: 7 additions & 0 deletions testconfig/scripts/wait_for_electrs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

until $(curl --output /dev/null --silent --fail http://localhost:3004/blocks/tip/height); do
printf 'waiting for electrs to start'
curl --user testuser:lq6zequb-gYTdF2_ZEUtr8ywTXzLYtknzWU4nV8uVoo= --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "generatetoaddress", "params": [1, "bcrt1qzqaernqlwetvahu59fwt3p38ezww7w95jqlxkg"]}' -H 'content-type: text/plain;' http://127.0.0.1:18443/
sleep 5
done

0 comments on commit 6ee1558

Please sign in to comment.