Skip to content

add PythOracle tests#278

Merged
thedavidmeister merged 7 commits intomainfrom
pyth-oracle-tests
Apr 13, 2026
Merged

add PythOracle tests#278
thedavidmeister merged 7 commits intomainfrom
pyth-oracle-tests

Conversation

@thedavidmeister
Copy link
Copy Markdown
Collaborator

@thedavidmeister thedavidmeister commented Apr 12, 2026

Summary

  • Add 7 tests for PythOracle covering price conversion, confidence subtraction, non-positive price revert, positive/negative exponents, and constructor immutables
  • Uses vm.mockCall for the Pyth contract — no mock contract needed

Closes #254

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive tests for the price oracle covering: decimal scaling to 18 decimals, confidence-adjusted pricing (including subtraction of confidence), explicit revert conditions when conservative price is non-positive (with revert payload checks), positive and large-magnitude negative exponent handling, and constructor/configuration validations using a mocked external price feed.

Test price conversion, confidence subtraction, non-positive price
revert, positive and negative exponents, and constructor immutables.
Uses vm.mockCall for the Pyth contract.

Closes #254

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bab50242-88a8-411d-b268-ef2dacd6accd

📥 Commits

Reviewing files that changed from the base of the PR and between f666b34 and 1a13f4c.

📒 Files selected for processing (1)
  • test/src/concrete/oracle/PythOracle.t.sol

Walkthrough

Adds a new Forge test contract that mocks IPyth responses to validate PythOracle price conversion, confidence subtraction, exponent scaling, revert cases for non-positive conservative prices, and constructor/getter values.

Changes

Cohort / File(s) Summary
PythOracle Test Suite
test/src/concrete/oracle/PythOracle.t.sol
Added PythOracleTest contract with helpers (buildOracle, mockPrice) and tests covering: normal price scaling to 18 decimals, conservative price (price − confidence) behavior, reverts for non-positive conservative values (including revert data checks), exponent handling (positive and large negative), and constructor/getter assertions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add PythOracle tests' directly and clearly describes the main change: adding test cases for the PythOracle contract.
Linked Issues check ✅ Passed The PR successfully adds 7 comprehensive tests for PythOracle covering price conversion, confidence subtraction, revert behavior, exponent handling, and constructor validation as required by issue #254.
Out of Scope Changes check ✅ Passed All changes are scoped to adding test cases for PythOracle in a single test file; no unrelated or out-of-scope modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pyth-oracle-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/src/concrete/oracle/PythOracle.t.sol`:
- Around line 82-83: The doc comment for the test function testConstruction is
inaccurate: it claims the test verifies event emission and immutables but the
implementation only checks immutables. Either update the comment to only state
that immutables are validated, or extend testConstruction by adding
expectEmit/emit expectations and assertions for the constructor event (use the
contract/event name used in deployment) so the test actually asserts event
emission as described.
- Around line 85-87: The test assertions call non-existent getters
I_PRICE_FEED_ID, I_STALE_AFTER, and I_PYTH_CONTRACT; update the assertions in
PythOracle.t.sol to use the actual auto-generated immutable getters
iPriceFeedId, iStaleAfter, and iPythContract (refer to the PythOracle contract's
public immutables iPriceFeedId, iStaleAfter, iPythContract) so the assertEq
lines compare the correct fields.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4479e6cc-dda0-498d-8496-271e95b92881

📥 Commits

Reviewing files that changed from the base of the PR and between 8326b77 and 3ede77e.

📒 Files selected for processing (1)
  • test/src/concrete/oracle/PythOracle.t.sol

Comment on lines +82 to +83
/// Construction emits event and sets immutables.
function testConstruction() external {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Doc comment overstates test scope.

Line 82 says construction test validates event emission, but the test only checks immutables. Either add expectEmit assertions or adjust the comment.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/src/concrete/oracle/PythOracle.t.sol` around lines 82 - 83, The doc
comment for the test function testConstruction is inaccurate: it claims the test
verifies event emission and immutables but the implementation only checks
immutables. Either update the comment to only state that immutables are
validated, or extend testConstruction by adding expectEmit/emit expectations and
assertions for the constructor event (use the contract/event name used in
deployment) so the test actually asserts event emission as described.

Comment thread test/src/concrete/oracle/PythOracle.t.sol Outdated
thedavidmeister and others added 4 commits April 13, 2026 08:19
Update immutable getter references to camelCase names.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
test/src/concrete/oracle/PythOracle.t.sol (1)

82-83: ⚠️ Potential issue | 🟡 Minor

Doc comment is still overstating test scope.

Line 82 says event emission is validated, but testConstruction only asserts immutables. Update the comment (or add expectEmit + event assertions).

✏️ Minimal fix
-    /// Construction emits event and sets immutables.
+    /// Construction sets immutables.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/src/concrete/oracle/PythOracle.t.sol` around lines 82 - 83, The doc
comment for testConstruction incorrectly claims it validates event emission;
either update the comment to only state that immutables are asserted or extend
testConstruction to call expectEmit and assert the expected event (use
expectEmit before the action and then assert the specific PythOracle
construction event via its parameters). Locate function testConstruction and
either change its comment text to remove the event-emission claim or add
expectEmit + assertions for the construction event to match the comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@test/src/concrete/oracle/PythOracle.t.sol`:
- Around line 82-83: The doc comment for testConstruction incorrectly claims it
validates event emission; either update the comment to only state that
immutables are asserted or extend testConstruction to call expectEmit and assert
the expected event (use expectEmit before the action and then assert the
specific PythOracle construction event via its parameters). Locate function
testConstruction and either change its comment text to remove the event-emission
claim or add expectEmit + assertions for the construction event to match the
comment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9b0bddd8-cf99-401a-aaca-6b36ac068ed1

📥 Commits

Reviewing files that changed from the base of the PR and between 3ede77e and f666b34.

📒 Files selected for processing (1)
  • test/src/concrete/oracle/PythOracle.t.sol

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@thedavidmeister thedavidmeister merged commit 7b852af into main Apr 13, 2026
4 checks passed
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.

tests for pyth oracle

1 participant