Repository: bibajz/bitcoin-python-async-rpc (language: python)

Issue:
Create a custom image for `regtest`
As noted in #5 , it would be nice to have a way to test this library.

Easiest way is to test it is pointing it to a fresh `regtest` node.

I have not surveyed the current state of Bitcoin `regtest` images and how up-to-date they are, but even if they were OK, I believe it's still worth having a knowledge how Bitcoin node is compiled and configured.

Also, having the `Docker/Containerfile` around means giving other contributors a way to audit against what version the tests are run as well as inspiration for their further experiments. 


Discussion / hints:

Fix patch:
diff --git a/Containerfile b/Containerfile
new file mode 100644
index 0000000..c5ca3f2
--- /dev/null
+++ b/Containerfile
@@ -0,0 +1,54 @@
+FROM docker.io/debian:11.7-slim
+
+ARG BTC_VERSION=v24.1
+
+RUN apt-get update && \
+  apt-get install -y \
+    build-essential \
+    libtool \
+    autotools-dev \
+    automake \
+    pkg-config \
+    bsdmainutils \
+    python3 \
+    libevent-dev \
+    libboost-dev \
+    libsqlite3-dev \
+    libminiupnpc-dev \
+    libnatpmp-dev \
+    libzmq3-dev \
+    systemtap-sdt-dev \
+    git && \
+  rm -rf /var/lib/apt/lists/*
+
+WORKDIR /opt
+
+RUN git clone --depth 1 --branch ${BTC_VERSION} https://github.com/bitcoin/bitcoin && \
+  cd bitcoin && \
+  ./autogen.sh && \
+  ./configure \
+    --enable-debug \
+    --enable-usdt \
+    --with-sqlite=yes \
+    --without-bdb \
+    --with-miniupnpc \
+    --with-natpmp \
+    --with-utils \
+    --with-daemon \
+    --with-gui=no && \
+  make -j$(nproc) && \
+  make install  && \
+  cd .. && \
+  rm -rf bitcoin
+
+RUN useradd --user-group --create-home rpc
+
+USER rpc
+
+WORKDIR /home/rpc
+
+# Default data directory when running the bitcoin daemon on regtest
+RUN mkdir -p .bitcoin/regtest
+
+ENTRYPOINT ["/usr/local/bin/bitcoind", "-server"]
+
diff --git a/README.md b/README.md
index c571c46..02540b2 100644
--- a/README.md
+++ b/README.md
@@ -90,10 +90,76 @@ $ python btc_rpc_minimal.py
 10
 ```
 
+## Testing
+
+A `Containerfile` is provided as a means to build an OCI image of a Bitcoin `regtest` node.
+Build the image (`podman` is used, but `docker` should be fine too):
+
+```
+$ podman build \
+  -f Containerfile \
+  --build-arg BTC_VERSION=v24.1 \
+  -t bitcoin-regtest:v24.1 \
+  -t bitcoin-regtest:latest \
+  .
+```
+
+and run it afterwards:
+
+```
+$ podman run \
+  --rm \
+  -it \
+  --mount=type=bind,src=./tests/bitcoin-regtest.conf,target=/home/rpc/.bitcoin/bitcoin.conf \
+  -p 127.0.0.1:18443:18443 \
+  --name bitcoin-regtest \
+  localhost/bitcoin-regtest:v24.1
+```
+
+which will expose the Bitcoin `regtest` node on port 18443, accesible from localhost only, with RPC user/password `rpc_user/rpc_password`.
+
+After you are done testing, stop the container via:
+
+```
+$ podman stop bitcoin-regtest
+```
+
+---
+
+If you want to test against a different version of Bitcoin node, pass a different [tag](https://github.com/bitcoin/bitcoin/tags) in the build stage:
+
+```
+$ podman build \
+  -f Containerfile \
+  --build-arg BTC_VERSION=v25.0 \
+  -t bitcoin-regtest:v25.0 \
+  -t bitcoin-regtest:latest \
+  .
+```
+
+---
+
+Different settings of the Bitcoin node may be passed via mounting your custom configuration file, or optionally as "arguments" to `podman run`:
+
+
+```
+$ podman run \
+  --rm \
+  -it \
+  --mount=type=bind,src=<path/to/your/config_file>,target=/home/rpc/.bitcoin/bitcoin.conf \
+  -p 127.0.0.1:18443:18443 \
+  --name bitcoin-regtest \
+  localhost/bitcoin-regtest:v24.1 <your> <args> ...
+```
+
+---
+
+Please, keep in mind that Bitcoin node compiled in the image is intended for testing & debugging purposes only! It may serve you as an inspiration for building
+your own, production-ready Bitcoin node, but its intended usage is testing!
+
 ## Changelog
 
 - **2021/12/28 - 0.5.0** change the signature of `BitcoinRPC` from `host, port, ...` to `url, ...`, delegating the creation of the node url to the caller.
 
-
 ## License
 MIT


Test patch:
diff --git a/tests/bitcoin-regtest.conf b/tests/bitcoin-regtest.conf
new file mode 100644
index 0000000..07f6e72
--- /dev/null
+++ b/tests/bitcoin-regtest.conf
@@ -0,0 +1,9 @@
+regtest=1
+
+[regtest]
+rpcallowip=127.0.0.1
+rpcallowip=10.0.0.0/8
+rpcallowip=192.168.0.0/16
+rpcbind=0.0.0.0:18443
+rpcuser=rpc_user
+rpcpassword=rpc_password