Skip to content

Latest commit

 

History

History
118 lines (74 loc) · 4.14 KB

README.md

File metadata and controls

118 lines (74 loc) · 4.14 KB

Trading Market-Sim End-To-End Tests

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.

Prerequisites

Ensure you have the following installed:

Setup

1. Install Dependencies

2. Configure Your Environment

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

3. Prepare Binaries and Docker Images

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

4. Build a Docker Image of Your Locally Built Trading App

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 .

Running Tests

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 set local_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.

Test Strategy and Container Cleanup

Strategy

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.

Cleanup Procedure

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

Running Tests in Parallel

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

Troubleshooting

If IntelliSense is not working in VSCode, follow these steps:

  1. Find the Poetry environment's Python binary: poetry run which python
  2. In VSCode, open the command menu (cmd + shift + p), search for Python: Select Interpreter, select Enter interpreter path, and paste the path from step 1.

Maintenance

Running against different versions of VEGA

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.