Skip to content

tests: mock miner price-fetch, drop validator-side PYTH_API_KEY#269

Merged
Thykof merged 1 commit into
mainfrom
mock-pyth-price-fetch-in-tests
May 27, 2026
Merged

tests: mock miner price-fetch, drop validator-side PYTH_API_KEY#269
Thykof merged 1 commit into
mainfrom
mock-pyth-price-fetch-in-tests

Conversation

@Thykof
Copy link
Copy Markdown
Collaborator

@Thykof Thykof commented May 27, 2026

Summary

The validator never needs PYTH_API_KEY — only the miner's Lazer live-price fetch does. But CI set the key and several tests reached the live Lazer endpoint through generate_simulations(), so a transient Lazer error failed every PR regardless of what it touched (e.g. run 26459886896 on the unrelated Bigtable PR #265, with stdout Error in response of Pyth Lazer API).

This makes the test suite independent of the miner key and the Lazer endpoint.

Changes

  • Mock the miner price-fetch. Patch synth.miner.simulations.get_asset_price in the fixtures/tests that call generate_simulations:

    • tests/utils.py prepare_random_predictions (covers test_forward, test_miner_data_handler, test_rewards)
    • the three direct-call tests in tests/test_forward.py
    • both tests in tests/test_simulations.py

    The GBM math still runs on a pinned price; no network call. PriceDataProvider's history fetch is intentionally left live — it's public (no key) and is part of what scoring exercises.

  • Drop PYTH_API_KEY from the CI workflow env; keep PYTH_BACKEND=pro.

  • Default PYTH_BACKEND=pro in conftest.py so local runs match CI. The scoring tests fetch real prices live from Pyth; the legacy hermes/benchmarks endpoint rate-limits (429) under the suite's call volume, the public Pro router does not. setdefault leaves an explicit override untouched.

  • Clarify .env.example that PYTH_API_KEY is miner-only (validators on pro use the public history endpoint).

Out of scope

  • synth/miner/price_simulation.py and the miner's own tests — miners legitimately need PYTH_API_KEY for Lazer.
  • Removing PYTH_API_KEY from the validator k8s secret bundle (tracked separately on synth-subnet-ops).

Test plan

  • Full suite green with PYTH_BACKEND=pro and no PYTH_API_KEY: 149 passed, 13 subtests.
  • Mocked generate_simulations verified offline (network calls rigged to raise) — output shape unchanged (tuple len 102, sub-arrays len 289).
  • black --check + flake8 clean on changed files.

🤖 Generated with Claude Code

The validator never needs PYTH_API_KEY — only the miner's Lazer
live-price fetch does. But CI set it and tests reached the live Lazer
endpoint through generate_simulations(), so an unrelated Lazer error
failed every PR (e.g. run 26459886896).

- Mock synth.miner.simulations.get_asset_price in the test fixtures that
  call generate_simulations (tests/utils.py prepare_random_predictions,
  tests/test_simulations.py, and the three direct-call tests in
  tests/test_forward.py). The GBM math still runs on a pinned price; no
  network call.
- Drop PYTH_API_KEY from the CI workflow env; keep PYTH_BACKEND=pro.
- Default PYTH_BACKEND=pro in conftest so local runs match CI. The
  scoring tests fetch real prices live from Pyth; the legacy
  hermes/benchmarks endpoint rate-limits (429) under the suite's volume,
  the public Pro router does not. setdefault leaves an explicit override
  untouched.
- Clarify in .env.example that PYTH_API_KEY is miner-only.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes CI/test-suite dependence on the miner-only Pyth Lazer API key by mocking the miner “current price” fetch used by generate_simulations(), while keeping validator-side live history fetching via the public Pyth Pro router.

Changes:

  • Mock synth.miner.simulations.get_asset_price in tests/fixtures that call generate_simulations() to prevent live Lazer network calls.
  • Default PYTH_BACKEND=pro in tests/conftest.py so local runs match CI, and drop PYTH_API_KEY from the CI workflow env.
  • Clarify in .env.example that PYTH_API_KEY is miner-only (validators don’t need it on pro).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/utils.py Wraps generate_simulations() calls in a patch to pin the current price and avoid live Lazer calls.
tests/test_simulations.py Patches get_asset_price for simulation tests to ensure offline determinism.
tests/test_forward.py Patches get_asset_price for forward/scoring tests that directly call generate_simulations().
tests/conftest.py Sets PYTH_BACKEND default to pro for the test suite environment.
.github/workflows/ci.yaml Removes PYTH_API_KEY from CI environment variables.
.env.example Documents PYTH_API_KEY as miner-only and explains validator behavior on pro.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_forward.py
Comment on lines +182 to 186
@patch("synth.miner.simulations.get_asset_price", return_value=90000.0)
def test_calculate_moving_average_and_update_rewards_new_miner_registration(
mock_get_asset_price,
db_engine: Engine,
):
@Thykof Thykof merged commit a0996d6 into main May 27, 2026
2 checks passed
@Thykof Thykof deleted the mock-pyth-price-fetch-in-tests branch May 27, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants