tests: mock miner price-fetch, drop validator-side PYTH_API_KEY#269
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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_pricein tests/fixtures that callgenerate_simulations()to prevent live Lazer network calls. - Default
PYTH_BACKEND=prointests/conftest.pyso local runs match CI, and dropPYTH_API_KEYfrom the CI workflow env. - Clarify in
.env.examplethatPYTH_API_KEYis miner-only (validators don’t need it onpro).
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 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, | ||
| ): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 throughgenerate_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 stdoutError 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_pricein the fixtures/tests that callgenerate_simulations:tests/utils.pyprepare_random_predictions(coverstest_forward,test_miner_data_handler,test_rewards)tests/test_forward.pytests/test_simulations.pyThe 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_KEYfrom the CI workflow env; keepPYTH_BACKEND=pro.Default
PYTH_BACKEND=proinconftest.pyso local runs match CI. The scoring tests fetch real prices live from Pyth; the legacyhermes/benchmarks endpoint rate-limits (429) under the suite's call volume, the public Pro router does not.setdefaultleaves an explicit override untouched.Clarify
.env.examplethatPYTH_API_KEYis miner-only (validators onprouse the public history endpoint).Out of scope
synth/miner/price_simulation.pyand the miner's own tests — miners legitimately needPYTH_API_KEYfor Lazer.PYTH_API_KEYfrom the validator k8s secret bundle (tracked separately on synth-subnet-ops).Test plan
PYTH_BACKEND=proand noPYTH_API_KEY:149 passed, 13 subtests.generate_simulationsverified offline (network calls rigged to raise) — output shape unchanged (tuple len 102, sub-arrays len 289).black --check+flake8clean on changed files.🤖 Generated with Claude Code