Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python tests in justfile with nix #331

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions .github/workflows/functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'poetry'
cache-dependency-path: './poetry.lock'
python-version: "3.12"
cache: "poetry"
cache-dependency-path: "./poetry.lock"

- name: Prepare environment
run: poetry install --no-root
Expand All @@ -34,8 +34,8 @@ jobs:
- name: Cache Rust
uses: Swatinem/rust-cache@v2

- name: Build Floresta
run: cargo build
- name: Tests Setup
run: bash tests/prepare.sh

- name: Run functional tests tasks
run: poetry run poe tests
run: bash tests/run.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/target
/builds
/result
/bin

# Temporary files and generated data
tmp/
Expand Down
63 changes: 50 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,55 @@
floresta-node = self.packages.${final.system}.default;
});

devShells.default =
let
_shellHook = (self.checks.${system}.pre-commit-check.shellHook or "");
in
mkShell {
inherit buildInputs;
inherit devTools;

shellHook = ''
${ _shellHook}
echo "Floresta Nix-shell"
'';
};
devShells = {
pythonTests =
let
_scriptSetup = ''
mkdir -p ./bin

cd bin

# Download and build utreexod
ls -la utreexod &>/dev/null

if [ $? -ne 0 ]
then
git clone https://github.com/utreexo/utreexod
fi
cd utreexod

go build . &>/dev/null
echo "All done!"
'';
_scriptRun = "poetry run poe tests";
in
pkgs.mkShell {
buildInputs = with pkgs; [
cargo
python312
poetry
go
] ++ [ self.packages.${system}.default ];
shellHook = ''
${_scriptSetup}
${_scriptRun}

exit
'';
};
default =
let
_shellHook = (self.checks.${system}.pre-commit-check.shellHook or "");
in
mkShell {
inherit buildInputs;
inherit devTools;

shellHook = ''
${ _shellHook}
echo "Floresta Nix-shell"
'';
};
};
});
}
24 changes: 21 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ clean:
test name="":
@just test-doc {{name}}
@just test-unit {{name}}
@just test-int
@just test-wkspc

# Execute doc tests
test-doc name="":
Expand All @@ -36,10 +36,28 @@ test-doc name="":
test-unit name="":
cargo test --lib {{name}} -- --nocapture

# Execute integration tests
test-int:
# Execute workspace-related tests
test-wkspc:
cargo test --workspace -- --nocapture

# Execute our python integration tests inside /tests using nix for all setup needed.
test-int-nix:
nix develop .#pythonTests

# Execute tests/prepare.sh.
test-int-setup:
jaoleal marked this conversation as resolved.
Show resolved Hide resolved
bash tests/prepare.sh

# Execute tests/run.sh
test-int-run:
bash tests/run.sh

# Execute our python integration tests inside /tests.
#
# Make sure you have done the necessary setup explained in our README.md in the root of the folder.
test-int:
poetry run poe tests

# Generate documentation for all crates
doc:
@just test-doc
Expand Down
74 changes: 59 additions & 15 deletions tests/prepare.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,41 +1,85 @@
# Prepares our environment to run our tests
#!/bin/bash
# Prepares a temporary environment to run our tests
#
# This script shold be executed once, before running our functinal test
# for the first time. It'll download and build all needed dependencies
# to make sure we are not missing anything during our tests.
# This script should be executed once, before running our functinal test
# for the first time we are testing a specific commit or in a session, since all the created files are temporary.
#
# It'll download and build only utreexod and florestad, since we are not testing the other binaries.
#
# Make sure to have python(for the tests), golang(for building utreexod) and rust(for building florestad) installed.
#


# We expect the current dir is the root dir of the project.
FLORESTA_PROJ_DIR=$(pwd)
# This helps us to keep track of the actual version being tested without conflicting with any already installed binaries.
HEAD_COMMIT_HASH=$(git rev-parse HEAD)

TEMP_DIR="/tmp/floresta-integration-tests.${HEAD_COMMIT_HASH}"


# Check for dependencies, we need Golang for Utreexod and Rust for Floresta
go version &>/dev/null

if [ $? -ne 0 ]
then
echo "You must have golang installed to run those tests!"
exit 1
fi


cargo version &>/dev/null

if [ $? -ne 0 ]
then
echo "You must have cargo installed to run those tests!"
echo "You must have rust with cargo installed to run those tests!"
exit 1
fi

poetry -V &>/dev/null

if [ $? -ne 0 ]
then
echo "You must have poetry installed to run those tests!"
exit 1
fi


mkdir -p ./bin

cd bin
ls $TEMP_DIR &>/dev/null
if [ $? -ne 0 ]
then
echo "The tests dir for the tests does not exist. Creating it..."
# Dont use mktemp so we can have deterministic results for each version of floresta.
mkdir -p "$TEMP_DIR"
fi

echo "$TEMP_DIR exists. Delete it with"
echo "$ rm -rf $TEMP_DIR"
Davidson-Souza marked this conversation as resolved.
Show resolved Hide resolved
echo "if you want to start fresh."

cd $TEMP_DIR/

# Download and build utreexod
ls -la utreexod &>/dev/null
if [ $? -ne 0 ]
then
git clone https://github.com/utreexo/utreexod
echo "Utreexo not found on $TEMP_DIR/utreexod."
echo "Downloading utreexod..."
git clone https://github.com/utreexo/utreexod &>/dev/null
echo "Building utreexod..."
cd utreexod
go build . &>/dev/null
fi

cd utreexod
go build . &>/dev/null

# build floresta
cd ../../
cargo build --bin florestad --features json-rpc &>/dev/null
# Checks if needed and build floresta setting the specific version of this build to the one we are testing
ls -la florestad &>/dev/null
if [ $? -ne 0 ]
then
echo "Floresta not found on $TEMP_DIR/florestad."
echo "Building florestad..."
cd $FLORESTA_PROJ_DIR
cargo build --bin florestad --features json-rpc --target-dir $TEMP_DIR/florestad &>/dev/null
fi

echo "All done!"
exit 0
31 changes: 31 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# We expect the current dir is the root dir of the project.
FLORESTA_PROJ_DIR=$(pwd)

# This helps us to keep track of the actual version being tested without conflicting with any already installed binaries.
HEAD_COMMIT_HASH=$(git rev-parse HEAD)


# Since its deterministic how we make the setup, we already know where to search for the binaries to be testing.
TEMP_DIR="/tmp/floresta-integration-tests.${HEAD_COMMIT_HASH}"

FLORESTA_BIN_DIR="$TEMP_DIR/florestad/debug"
UTREEXO_BIN_DIR="$TEMP_DIR/utreexod"

ls $TEMP_DIR &>/dev/null
if [ $? -ne 0 ]
then
echo "The expected test dir for this version of floresta isnt setted yet."
echo "Did you run prepare.sh? Please read the README.md file."
exit 1
fi
# Here we save the original path from the bash session to restore it later. Cmon, we are not savages.
ORIGINAL_PATH=$PATH
# We add the generated binaries for testing to the PATH.
export PATH="$FLORESTA_BIN_DIR:$UTREEXO_BIN_DIR:$PATH"

# Actually runs the tests
poetry run poe tests
# Restores the original PATH
export PATH=$ORIGINAL_PATH
7 changes: 1 addition & 6 deletions tests/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,11 @@ def add_node_settings(
(see florestad --help for a list of available commands)

"""

setting = {
"chain": chain,
"config": [
"cargo",
"run",
"--features",
"json-rpc",
"--bin",
"florestad",
"--",
"--network",
chain,
"--no-ssl",
Expand Down
Loading