Skip to content

feat: add live data pull for opengradient token#55

Open
kylexqian wants to merge 16 commits intomainfrom
claude/admiring-goldberg
Open

feat: add live data pull for opengradient token#55
kylexqian wants to merge 16 commits intomainfrom
claude/admiring-goldberg

Conversation

@kylexqian
Copy link
Copy Markdown
Collaborator

@kylexqian kylexqian commented Apr 16, 2026

  • Add live data pull for opengradient token. Currently set to ETH as our token is not yet listed
  • Added more CI/CD tests surrounding pulling data from coingecko
  • This also includes a TTL of the coin check time as 2 minutes

dixitaniket and others added 16 commits April 1, 2026 18:53
…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>
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