This directory contains end-to-end tests for the Trading application using Vega-market-sim. This guide will help you set up your environment and run the tests efficiently.
Ensure you have the following installed:
- Poetry for dependency management.
- Docker for running isolated application containers.
- Python, versions ">=3.9,<3.11". Install from the official Python website.
- Poetry: Follow the installation guide on the official Poetry website.
- Docker: Installation instructions are available on the official Docker website.
- Python: Install a version between 3.9 and 3.11, as detailed on the official Python website.
Ensure you're in the tests folder before executing commands.
poetry shell
poetry update vega-sim # Updates to the latest version of the market-sim branch
poetry install
playwright install chromium # Installs necessary browsers for Playwright
Download necessary binaries for the desired Vega version:
python -m vega_sim.tools.load_binaries --force --version $VEGA_VERSION
Pull Docker images for your environment:
- Development:
docker pull vegaprotocol/trading:develop
- Production:
docker pull vegaprotocol/trading:main
Ensure to enter the ENV_NAME for the environment you want to test against.
./docker/prepare-dist.sh
docker build -f docker/node-outside-docker.Dockerfile --build-arg APP=trading --build-arg ENV_NAME=stagnet1 -t vegaprotocol/trading:develop .
Ensure the Docker daemon is running. Update the .env
file with the correct trading image before proceeding.
-
Run all tests:
poetry run pytest
-
Run a specific test:
poetry run pytest -k "test_name" -s --headed
-
Run tests using your locally served console:
In one terminal window, build and serve the trading console:
Ensure to serve the environment you want to test against
yarn nx build trading yarn env-cmd -f ./apps/trading/.env.mainnet yarn nx run trading:serve
Once the console is served, update the
.env
file to setlocal_server=true
. You can then run your tests using the same commands as above. NOTE: Parallel running of tests will not work against locally served console.
We aim for each test file to use a single Vega instance to ensure test isolation and manage resources efficiently. This approach helps in maintaining test performance and reliability.
To ensure proper cleanup of containers after each test, use the following fixture pattern:
@pytest.fixture
def vega(request):
with init_vega(request) as vega_instance:
request.addfinalizer(lambda: cleanup_container(vega_instance))
yield vega_instance
For running tests in parallel:
Running more than 4 threads at a time can cause instability. If this is the case, change --numprocesses
to 2 or 4.
- Within the e2e folder:
poetry run pytest -s --numprocesses auto --dist loadfile
- From anywhere:
yarn trading:test:all
If IntelliSense is not working in VSCode, follow these steps:
- Find the Poetry environment's Python binary:
poetry run which python
- In VSCode, open the command menu (
cmd + shift + p
), search forPython: Select Interpreter
, selectEnter interpreter path
, and paste the path from step 1.
UPDATING THE .ENV FILE IS NOT ENOUGH
Vega Market Sim will need branches created for whatever version of core you want to run against.
This branch will need to be updated in the pyproject.toml
file.
This core version will then need to be specified in the .env files.