Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Integration: broadcast a withdrawal #351

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f10143e
format
CAGS295 Sep 14, 2023
71507e5
auto port mapping, auto container name
CAGS295 Sep 18, 2023
df89449
Testing container
CAGS295 Sep 18, 2023
d3639af
move integration container
CAGS295 Oct 2, 2023
7c365af
target integration tests
CAGS295 Oct 2, 2023
ba011c8
Init readme
CAGS295 Oct 3, 2023
8d855c2
Add clarinet deployments
CAGS295 Oct 4, 2023
33b81f5
Single filter as placeholder
CAGS295 Oct 4, 2023
0526168
mount entrypoint
CAGS295 Oct 5, 2023
b380ed5
Contract deployment
CAGS295 Oct 5, 2023
2270cb4
Ignore integration tests in coverage
CAGS295 Oct 13, 2023
44fc0b7
Integration: mine empty block
CAGS295 Oct 5, 2023
9643231
use romeo as library
CAGS295 Oct 11, 2023
7cf8564
fetch stacks height
CAGS295 Oct 9, 2023
5703949
init deposit test
CAGS295 Oct 11, 2023
c57bfac
fix duplicated integration tests
CAGS295 Oct 11, 2023
c87d5e2
aggresive mining
CAGS295 Oct 11, 2023
63848e8
Remove trivial check
CAGS295 Oct 11, 2023
bfe68e3
Reduce initial mining blocks to 100
CAGS295 Oct 12, 2023
6cd5587
simplify service addresses
CAGS295 Oct 12, 2023
13ea79b
Add a quickstart section to the readme.
CAGS295 Oct 12, 2023
2043c83
static wallets
CAGS295 Nov 3, 2023
c885ed8
add no capture to integration entrypoint
CAGS295 Nov 6, 2023
94d0d22
fund example
CAGS295 Nov 6, 2023
4276756
wait for confirmation
CAGS295 Nov 6, 2023
78adfc3
fund example
CAGS295 Nov 6, 2023
1c866f2
assert on balances
CAGS295 Nov 10, 2023
7e96195
format
CAGS295 Nov 11, 2023
4171fab
integration: broadcast withdrawal
CAGS295 Nov 3, 2023
805cba5
withdrawal test + example
CAGS295 Nov 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
url = "2.4.1"
wsts = "1.2"
blockstack-core = { git = "https://github.com/stacks-network/stacks-blockchain/", branch = "master" }
6 changes: 4 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST_FRAMEWORK = "nextest"
[env.github-actions]
# TODO: use nexttest when testing becomes too much to do in series.
# Installing nexttest takes > 5 minutes on github workflow machines.
TEST_FRAMEWORK = "test"
TEST_FRAMEWORK = "nextest"

# Installations
# --------------
Expand Down Expand Up @@ -86,7 +86,9 @@ args = [
"llvm-cov",
"${TEST_FRAMEWORK}",
"--all-features",
"--no-report"
"--no-report",
"-E",
"not (kind(test))",
]

[tasks._calculated-coverage-clean]
Expand Down
2 changes: 1 addition & 1 deletion devenv/bitcoin/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG VERSION=25.0
RUN apt-get update && apt-get install -y \
wget \
file \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/*

RUN file /bin/bash | grep -q x86-64 && echo x86_64-linux-gnu > /tmp/arch || true
RUN file /bin/bash | grep -q aarch64 && echo aarch64-linux-gnu > /tmp/arch || true
Expand Down
5 changes: 0 additions & 5 deletions devenv/bitcoin/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@

set -x

#-rpcuser=${BTC_RPCUSER} -rpcpassword=${BTC_RPCPASSWORD}

# bitcoind needs creds set in the conf file for remote RPC auth
#echo '[regtest]' > ${BITCOIN_CONF}

nginx
bitcoind -chain=${BTC_NETWORK} -txindex=${BTC_TXINDEX} -rpcuser=${BTC_RPCUSER} -rpcpassword=${BTC_RPCPASSWORD} -printtoconsole=${BTC_PRINTTOCONSOLE} -disablewallet=${BTC_DISABLEWALLET} -rpcbind=${BTC_RPCBIND} -rpcallowip=${BTC_RPCALLOWIP}
52 changes: 19 additions & 33 deletions devenv/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ version: '3.2'
services:
bitcoin:
image: bitcoin:latest
container_name: bitcoin
stop_grace_period: 5s
build:
context: ./bitcoin/docker
args:
VERSION: '25.0'
ports:
- 18444:18444
- 18443:18443
- 18433:18433
- 18444
- 18443
- 18433
environment:
- 'BTC_NETWORK=regtest'
- 'BTC_DISABLEWALLET=0'
Expand All @@ -23,48 +22,43 @@ services:
- 'BTC_RPCUSER=devnet'
postgres:
image: postgres:15-alpine
container_name: postgres
stop_grace_period: 5s
ports:
- 5432:5432
- 5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
mongodb:
image: mongo:6.0
container_name: mongodb
stop_grace_period: 5s
ports:
- 27017:27017
- 27017
environment:
MONGO_INITDB_ROOT_USERNAME: devnet
MONGO_INITDB_ROOT_PASSWORD: devnet
MONGO_INITDB_DATABASE: devnet
mempool-db:
image: mariadb:10.5.21
container_name: mempool-db
stop_grace_period: 5s
ports:
- 3306:3306
- 3306
environment:
MYSQL_DATABASE: "mempool"
MYSQL_USER: "mempool"
MYSQL_PASSWORD: "mempool"
MYSQL_ROOT_PASSWORD: "admin"
miner:
image: miner:latest
container_name: miner
stop_grace_period: 5s
build:
context: ./miner/docker
depends_on:
- bitcoin
environment:
INIT_BTC_BLOCKS: 200
BTC_BLOCK_GEN_TIME: 10
INIT_BTC_BLOCKS: 101
BTC_BLOCK_GEN_TIME: 5
stacks:
image: stacks:latest
container_name: stacks
stop_grace_period: 5s
build:
context: ./stacks/docker
Expand All @@ -73,8 +67,8 @@ services:
GIT_URI: https://github.com/stacks-network/stacks-blockchain.git
GIT_BRANCH: develop
ports:
- 20444:20444
- 20443:20443
- 20444
- 20443
depends_on:
- bitcoin
- miner
Expand All @@ -83,16 +77,15 @@ services:
- STACKS_LOG_JSON=0
stacks-api:
image: stacks-api:latest
container_name: stacks-api
stop_grace_period: 5s
build:
context: ./stacks-api/docker
args:
GIT_URI: 'https://github.com/hirosystems/stacks-blockchain-api.git'
GIT_BRANCH: 'v7.3.0'
ports:
- 3999:3999
- 3700:3700
- 3999
- 3700
depends_on:
- postgres
- stacks
Expand All @@ -115,7 +108,6 @@ services:
- API_DOCS_URL=http://localhost:3999/doc
stacks-explorer:
image: stacks-explorer
container_name: stacks-explorer
stop_grace_period: 5s
build:
context: ./stacks-explorer/docker
Expand All @@ -124,7 +116,7 @@ services:
GIT_URI: https://github.com/hirosystems/explorer.git
GIT_BRANCH: v1.119.0
ports:
- 3020:3000
- 3000
depends_on:
- bitcoin
- stacks
Expand All @@ -134,21 +126,19 @@ services:
- NEXT_PUBLIC_MAINNET_API_SERVER=http://127.0.0.1:3999
electrs:
image: electrs:latest
container_name: electrs
stop_grace_period: 5s
build:
context: ./electrs/docker
ports:
- 60401:60401
- 3002:3002
- 60401
- 3002
depends_on:
- bitcoin
- miner
environment:
RUST_BACKTRACE: 1
sbtc:
image: sbtc:latest
container_name: sbtc
stop_grace_period: 5s
restart: on-failure
build:
Expand All @@ -167,7 +157,6 @@ services:
- $PWD/sbtc/docker/config.json:/romeo/config.json
sbtc-bridge-api:
image: sbtc-bridge-api:latest
container_name: sbtc-bridge-api
stop_grace_period: 5s
build:
context: ./sbtc-bridge-api/docker
Expand All @@ -185,7 +174,7 @@ services:
- mongodb
- sbtc
ports:
- 3010:3010
- 3010
environment:
NODE_ENV: dev
btcNode: bitcoin:18443
Expand All @@ -202,7 +191,6 @@ services:
mongoPwd: devnet
sbtc-bridge-web:
image: sbtc-bridge-web:latest
container_name: sbtc-bridge-web
stop_grace_period: 5s
build:
context: ./sbtc-bridge-web/docker
Expand All @@ -216,33 +204,31 @@ services:
- sbtc
- sbtc-bridge-api
ports:
- 8080:8080
- 8080
mempool-web:
image: mempool/frontend:latest
container_name: mempool-web
stop_grace_period: 5s
depends_on:
- mempool-api
- mempool-db
user: "1000:1000"
restart: on-failure
ports:
- 8083:8083
- 8083
environment:
FRONTEND_HTTP_PORT: "8083"
BACKEND_MAINNET_HTTP_HOST: "mempool-api"
command: "./wait-for mempool-db:3306 --timeout=720 -- nginx -g 'daemon off;'"
mempool-api:
image: mempool/backend:latest
container_name: mempool-api
stop_grace_period: 5s
depends_on:
- electrs
- mempool-db
user: "1000:1000"
restart: on-failure
ports:
- 8999:8999
- 8999
environment:
# Connect to electrs host
MEMPOOL_BACKEND: "electrum"
Expand Down
133 changes: 133 additions & 0 deletions devenv/integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
## Containerized integration testing

Hi! Congratulations on making it this far. By now, you should know how to launch
a full node for local development using devnev. To take a step further, these
are the steps you need to follow to run and implement integration tests using
devenv.

## Quickstart

1. Build the testbed image with the source and binaries to execute the
integration tests.
2. Run the testing script.

```bash
> devenv$ cd integration
> devenv/integration$ ./bin/build
> cd -
> devenv$ ./integration/bin/test
```

You will see lines like the one below if your tests are completed successfully.

```
Runner: 71c1beca7261e2c1b706fa0e9eeb3823ad56977c4846c89b25a315a48a1bbda5 exited with err_no: 0
Runner: fb2da5362115b5ae37874d39831bbf249b2928c58296dfb23af94b7083d8455b exited with err_no: 0
```

Use the container id to inspect the runner for more details.

```
> devenv$ ./logs.sh 71c1beca7261e2c1b706fa0e9eeb3823ad56977c4846c89b25a315a48a1bbda5
```

The script will abort the moment a container fails. The script will print the
logs from the first failed container. You must stop the nodes with
`docker stop $(docker ps -q)`. You can also rerun `test` to 'down' and 'up' any
dangling container and re-execute tests once you have fixed and rebuilt the
testbed image.

## QuickStart

1. Build the testbed image that has the source and binaries to execute the integration tests.
2. Run the testing script.

```bash
> devenv$ cd integration
> devenv/integration$ ./bin/build
> cd -
> devenv$ ./integration/bin/test
```

You will see lines like below if your tests completed succesfully.

```
Runner: 71c1beca7261e2c1b706fa0e9eeb3823ad56977c4846c89b25a315a48a1bbda5 exited with err_no: 0
Runner: fb2da5362115b5ae37874d39831bbf249b2928c58296dfb23af94b7083d8455b exited with err_no: 0
```

Use the container id to inspect the runner for more details.

```
> devenv$ ./logs.sh 71c1beca7261e2c1b706fa0e9eeb3823ad56977c4846c89b25a315a48a1bbda5
```

the script will abort the moment a container fails. The script will print the
logs from the first failed container. You will need to stop the nodes yourself
with `docker stop $(docker ps -qa)`. You can also run `test` again to down and
up again any dangling container and reexecute tests once you have fixed and
rebuilt the testbed image.

### Running integration tests.

Start at devenv, `pushd` integration. You will find scripts in the `bin` folder
in this directory. The ones you will be using are `build` and `test`. `Test` is
how you are expected to run the suite. Run `bin/build` and `popd,` back in
devenv, and run `integration/bin/test`.

### Adding grouping filters

In /devenv/integration/test, there is a filter array that determines how many
nodes will be spun and what tests will run in parallel inside the node.

```bash
filters=("package(romeo)" "test(deposit_parse)" "test(deposit_output)")
```

Use Nextest's DSL to group up your integration tests. Add new filters as you see
fit.

### Adding node readiness checks.

In `devenv/integration/docker/entrypoint`, you can add checks to wait until a
node is ready to take tests.

In this snip, we wait until the stacks api is responsive and the burchain block
height is 205.

```bash
STACKS=$PROJECT_NAME-stacks-1
API_URL=http://$STACKS:20443/v2/info

# it makes sure the node is ready before proceeding
# stacks node get info
echo "Waiting on Stacks API"
while ! curl -s $API_URL >/dev/null; do
sleep 1
done

DEV_READY_HEIGHT=205

# bitcoind get info
echo "Waiting on burn block height $DEV_READY_HEIGHT"
while [ "$(curl -s $API_URL | jq '.burn_block_height')" -lt $DEV_READY_HEIGHT ]; do
sleep 2
done
```

### Troubleshooting.

- If a fresh network fails to be created or you spot a line like the one below, you need
to stop all containers and prune the network.

```
! Network test_deposit__default Resource is still in use 0.0s
```

```
> docker stop $(docker ps -q)
> docker network prune
```

- The order of magnitude for the tests should be in **minutes**. It took 4mins
in my system last time I checked.
3 changes: 3 additions & 0 deletions devenv/integration/bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

docker compose -f docker-compose.yml build
8 changes: 8 additions & 0 deletions devenv/integration/bin/down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env sh

if [ -z "$2" ]; then
echo "Use: down <full-node-compose.yml> <project_name>"
exit 1
fi

docker compose -f $1 -p $2 down
Loading
Loading