mirror of
https://github.com/cryptoadvance/specter-desktop.git
synced 2026-08-13 12:33:29 +02:00
Docs: run tests and avoid elm-tests if you don't want them (#1326)
* fixes #1323 * fixing unintended deletion * polishing
This commit is contained in:
parent
8079556d9b
commit
1ae8b8b1a3
6 changed files with 76 additions and 27 deletions
|
|
@ -117,6 +117,13 @@ _note: you may need to add `$HOME/.cargo/bin` to your path in `.env/bin/activate
|
|||
## How to run the tests
|
||||
_TODO: Need more thorough tests!_
|
||||
|
||||
In order to run the tests, you need bitcoind and elementsd binaries available. For Linux/Mac, there is some support for installing/compiling them. So you can:
|
||||
* `./tests/install_bitcoind.sh --bitcoin binary` will install bitcoind in tests/bitcoin
|
||||
* `./tests/install_bitcoind.sh --bitcoin compile` will compile bitcoind in tests/bitcoin
|
||||
* `./tests/install_bitcoind.sh --elements compile` will compile elements in tests/elements
|
||||
|
||||
If you're not interested in elements, you can skip the liquid specific tests as described below.
|
||||
|
||||
Set up the dependencies:
|
||||
```sh
|
||||
pip3 install -r test_requirements.txt
|
||||
|
|
@ -129,13 +136,16 @@ If you have a local bitcoind already installed:
|
|||
pytest
|
||||
```
|
||||
|
||||
OR run against bitcoind in Docker:
|
||||
OR run against bitcoind in Docker (deprecated):
|
||||
```
|
||||
# Pull the bitcoind image if you haven't already:
|
||||
docker pull registry.gitlab.com/cryptoadvance/specter-desktop/python-bitcoind:v0.20.1
|
||||
|
||||
# install prerequisites
|
||||
pip3 install docker
|
||||
|
||||
# Run all the tests against the docker bitcoind image
|
||||
pytest --docker
|
||||
pytest -m "no elm" --docker
|
||||
```
|
||||
|
||||
Running specific test subsets:
|
||||
|
|
@ -143,6 +153,12 @@ Running specific test subsets:
|
|||
# Run all tests but not the slow ones
|
||||
pytest -m "not slow"
|
||||
|
||||
# Run all tests but not the elements
|
||||
pytest -m "not elm"
|
||||
|
||||
# Run all tests but not the slow ones and not the slow ones
|
||||
pytest -m "not elm and not slow"
|
||||
|
||||
# Run all the tests in a specific test file
|
||||
pytest tests/test_specter.py
|
||||
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@ log_format = [%(levelname)8s] %(message)s %(name)s (%(filename)s:%(lineno)s)
|
|||
addopts = --bitcoind-version v0.20.1 --elementsd-version v0.20.99
|
||||
markers =
|
||||
slow: mark test as slow.
|
||||
elm: mark test as elementsd dependent
|
||||
#log_cli = 1
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
# fail early
|
||||
set -o pipefail
|
||||
|
||||
# chenage to the directory the script is located in
|
||||
# change to the directory the script is located in
|
||||
cd "$( dirname "${BASH_SOURCE[0]}" )/."
|
||||
|
||||
function checkout {
|
||||
|
|
@ -13,9 +13,9 @@ function checkout {
|
|||
node_setup_needed=false
|
||||
if [ ! -d "./${node_impl}/.git" ]; then
|
||||
echo " --> cloning $node_impl"
|
||||
if [ $node_impl = "elements" ]; then
|
||||
if [ "$node_impl" = "elements" ]; then
|
||||
clone_url=https://github.com/ElementsProject/elements.git
|
||||
elif [ $node_impl= "bitcoin" ]; then
|
||||
elif [ "$node_impl" = "bitcoin" ]; then
|
||||
clone_url=https://github.com/bitcoin/bitcoin.git
|
||||
else
|
||||
echo "unknown node_impl $node_impl"
|
||||
|
|
@ -52,15 +52,15 @@ function maybe_update {
|
|||
if [ -z $PINNED ]; then
|
||||
REMOTE=$(git rev-parse "$UPSTREAM")
|
||||
BASE=$(git merge-base @ "$UPSTREAM")
|
||||
if [ $LOCAL = $REMOTE ]; then
|
||||
if [ "$LOCAL" = "$REMOTE" ]; then
|
||||
echo "Up-to-date"
|
||||
elif [ $LOCAL = $BASE ]; then
|
||||
elif [ "$LOCAL" = "$BASE" ]; then
|
||||
git pull
|
||||
git reset --hard origin/master
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if [ $LOCAL = $PINNED ]; then
|
||||
if [ "$LOCAL" = "$PINNED" ]; then
|
||||
echo " --> Pinned: $PINNED! Checkout not needed!"
|
||||
else
|
||||
echo " --> Pinned: $PINNED! Checkout needed!"
|
||||
|
|
@ -76,6 +76,24 @@ function maybe_update {
|
|||
fi
|
||||
}
|
||||
|
||||
function calc_pytestinit_nodeimpl_version {
|
||||
|
||||
# returns the version of $node_impl from pytest.ini from a line which looks like:
|
||||
# addopts = --bitcoind-version v0.21.1 --elementsd-version v0.20.99
|
||||
local node_impl=$1
|
||||
if cat ../pytest.ini | grep -q "addopts = --${node_impl}d-version" ; then
|
||||
# in this case, we use the expected version from the test also as the tag to be checked out
|
||||
# i admit that this is REALLY ugly. Happy for any recommendations to do that more easy
|
||||
PINNED=$(cat ../pytest.ini | grep "addopts = " | cut -d'=' -f2 | sed 's/--/+/g' | tr '+' '\n' | grep ${node_impl} | cut -d' ' -f2)
|
||||
|
||||
if [ "$node_impl" = "elements" ]; then
|
||||
# in the case of elements, the tags have a "elements-" prefix
|
||||
PINNED=$(echo "$PINNED" | sed 's/v//' | sed 's/^/elements-/')
|
||||
fi
|
||||
fi
|
||||
echo $PINNED
|
||||
}
|
||||
|
||||
function build_node_impl {
|
||||
node_impl=$1 # either bitcoin or elements
|
||||
nodeimpl_setup_needed=$2
|
||||
|
|
@ -99,9 +117,9 @@ function build_node_impl {
|
|||
# This is for reducing mem-footprint as for some reason cirrus fails even though it has 4GB Mem
|
||||
# CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768 -O2"
|
||||
|
||||
if [ $node_impl = "elements" ]; then
|
||||
if [ "$node_impl" = "elements" ]; then
|
||||
./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include"
|
||||
elif [ $node_impl= "bitcoin" ]; then
|
||||
elif [ "$node_impl" = "bitcoin" ]; then
|
||||
./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include" CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768 -O2" --with-miniupnpc=no --without-gui --disable-zmq --disable-tests --disable-bench --with-libs=no --with-utils=no
|
||||
else
|
||||
echo "unknown node_impl $node_impl"
|
||||
|
|
@ -128,7 +146,7 @@ function sub_help {
|
|||
echo "$ ./install_node.sh --bitcoin compile"
|
||||
echo "$ ./install_node.sh --elements compile"
|
||||
echo "$ ./install_node.sh binary # only works for bitcoind currently, no binaries for elements"
|
||||
|
||||
echo "For more context, see https://github.com/cryptoadvance/specter-desktop/blob/master/DEVELOPMENT.md#how-to-run-the-tests"
|
||||
}
|
||||
|
||||
function check_compile_prerequisites {
|
||||
|
|
@ -165,27 +183,37 @@ function sub_compile {
|
|||
}
|
||||
|
||||
function sub_binary {
|
||||
if [ "$node_impl" = "elements" ]; then
|
||||
echo " --> binary installation of elements not supported, exiting"
|
||||
exit 2
|
||||
fi
|
||||
echo " --> install_noded.sh Start $(date) (binary)"
|
||||
START=$(date +%s.%N)
|
||||
cd tests
|
||||
# todo: Parametrize this
|
||||
version=0.20.1
|
||||
wget https://bitcoincore.org/bin/bitcoin-core-${version}/bitcoin-${version}-x86_64-linux-gnu.tar.gz
|
||||
tar -xzf bitcoin-${version}-x86_64-linux-gnu.tar.gz
|
||||
if [[ -f ./bitcoin ]]; then
|
||||
echo "bitcoin -directory exists"
|
||||
return
|
||||
version=$(calc_pytestinit_nodeimpl_version $node_impl)
|
||||
# remove the v-prefix
|
||||
version=$(echo $version | sed -e 's/v//')
|
||||
if [[ ! -f bitcoin-${version}-x86_64-linux-gnu.tar.gz ]]; then
|
||||
wget https://bitcoincore.org/bin/bitcoin-core-${version}/bitcoin-${version}-x86_64-linux-gnu.tar.gz
|
||||
fi
|
||||
mv ./bitcoin-${version} bitcoin
|
||||
cd .. #cirrus is sourcing this script
|
||||
tar -xzf bitcoin-${version}-x86_64-linux-gnu.tar.gz
|
||||
if [[ -d ./bitcoin ]]; then
|
||||
if [[ -d ./bitcoin/src ]]; then
|
||||
mv ./bitcoin ./bitcoin-src
|
||||
else
|
||||
rm -rf ./bitcoin
|
||||
fi
|
||||
fi
|
||||
ln -s ./bitcoin-${version} bitcoin
|
||||
echo " --> Listing binaries"
|
||||
find tests/bitcoin/bin -maxdepth 1 -type f -executable -exec ls -ld {} \;
|
||||
find ./bitcoin/bin -maxdepth 1 -type f -executable -exec ls -ld {} \;
|
||||
echo " --> Finished installing bitcoind binary"
|
||||
END=$(date +%s.%N)
|
||||
DIFF=$(echo "$END - $START" | bc)
|
||||
echo " --> install_noded.sh End $(date) took $DIFF"
|
||||
}
|
||||
|
||||
|
||||
function parse_and_execute() {
|
||||
if [[ $# = 0 ]]; then
|
||||
sub_default
|
||||
|
|
@ -197,7 +225,7 @@ function parse_and_execute() {
|
|||
arg="$1"
|
||||
case $arg in
|
||||
"" | "-h" | "--help")
|
||||
sub_default
|
||||
sub_help
|
||||
shift
|
||||
;;
|
||||
--debug)
|
||||
|
|
@ -227,14 +255,11 @@ function parse_and_execute() {
|
|||
;;
|
||||
*)
|
||||
shift
|
||||
sub_${arg} $@
|
||||
ret_value=$?
|
||||
if [ $ret_value = 127 ]; then
|
||||
sub_${arg} $@ && ret=0 || ret=$?
|
||||
if [ "$ret" = 127 ]; then
|
||||
echo "Error: '$arg' is not a known subcommand." >&2
|
||||
echo " Run '$progname --help' for a list of known subcommands." >&2
|
||||
exit 1
|
||||
elif [ $ret_value = 0 ]; then
|
||||
exit 0
|
||||
else
|
||||
exit $ret_value
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import pytest
|
||||
from cryptoadvance.specter.liquid.rpc import LiquidRPC
|
||||
|
||||
|
||||
@pytest.mark.elm
|
||||
def test_LiquidRpc(elements_elreg):
|
||||
rpc = elements_elreg.get_rpc()
|
||||
default_rpc = rpc.wallet("")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from enum import auto
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
from cryptoadvance.specter.managers.node_manager import NodeManager
|
||||
from cryptoadvance.specter.process_controller.bitcoind_controller import (
|
||||
BitcoindPlainController,
|
||||
|
|
@ -9,6 +11,7 @@ from cryptoadvance.specter.process_controller.elementsd_controller import (
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.elm
|
||||
def test_NodeManager(
|
||||
bitcoin_regtest: BitcoindPlainController, elements_elreg: ElementsPlainController
|
||||
):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import pytest
|
||||
import tempfile
|
||||
|
||||
from cryptoadvance.specter.node import Node
|
||||
|
|
@ -62,6 +63,7 @@ def test_Node_btc(bitcoin_regtest):
|
|||
assert node.network_info["warnings"] == ""
|
||||
|
||||
|
||||
@pytest.mark.elm
|
||||
def test_Node_elm(elements_elreg):
|
||||
with tempfile.TemporaryDirectory("_some_datafolder_tmp") as data_folder:
|
||||
node = Node.from_json(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue