feat: add live data pull for opengradient token#55
Open
Conversation
…ation
Replaces the hardcoded Decimal("1") mock with a real CoinGecko ETH/USD
price fetch (ETH used as OPG proxy until OPG is listed). Caches the
price for 2 minutes so at most one network call is made per TTL window.
Falls back to last-known-good price on refresh failure, or a hard-coded
$2000 floor if no price has ever been fetched.
Config constants (TTL, CoinGecko ID, fallback price) are centralised in
config.py so switching to real OPG requires only a one-line change.
Adds test_util.py with 18 tests covering the fetch, cache, fallback,
and full dynamic_session_cost_calculator pipeline.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
test_pricing.py was relying on the old Decimal("1") mock price; patch
get_token_a_price_usd to $1 via setUpModule/tearDownModule so the
hardcoded expected wei values remain valid as pure USD pricing unit tests.
Add tests/test_integration.py (pytest -m integration) with 4 live tests:
- _fetch_opg_price_usd returns a positive Decimal from real CoinGecko
- ETH price falls within a sanity range ($100–$100 000)
- Second call within TTL returns cached value (no second network call)
- Full dynamic_session_cost_calculator pipeline with live price
Add a separate integration-tests CI job in test.yml and register the
integration marker in pyproject.toml. Also add pythonpath = ["."] to
pytest config so tests/ can import tee_gateway when run standalone.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add OPG_PRICE_SANITY_MIN_USD / OPG_PRICE_SANITY_MAX_USD to config.py ($0.000001–$1 000 000) so the integration test stays in sync when switching from the ETH proxy to real OPG without touching test code. Widen lower bound from $100 to $0.000001 to accommodate a potentially low OPG token price. Rename test to test_price_is_within_sanity_bounds. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
All mentions of ETH/ethereum in comments, log messages, error strings, and test helpers now refer to OPG_PRICE_COINGECKO_ID so that switching to the real OPG token requires only a one-line change in config.py. - util.py: docstring, error message, and log line use the coin ID var - test_util.py: mock response body and URL assertion key off the config - test_integration.py: comments and print output use the coin ID var - config.py: comments no longer mention ETH specifically Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
That method no longer exists in the current og-x402 library — the patch was a no-op and mypy flagged it as attr-defined on PaymentMiddleware. In the current library the session_cost_calculator is called inside _accumulate_session_cost(), which is wrapped by a broad try/except in StreamingSessionResponse.close(). Replace the dead code with a comment explaining the current behaviour and where to patch if stricter error propagation is needed in future. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Uh oh!
There was an error while loading. Please reload this page.