Test twap underflow possibility#169
Conversation
WalkthroughA new test function Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Focus areas for review:
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
x/oracle/keeper/keeper_test.go (1)
724-724: Remove redundant block time setting.The block time was already set to
time.Unix(200, 0)at line 615, and the same context is used throughout the test. This line is redundant.Apply this diff:
- ctx = ctx.WithBlockTime(time.Unix(200, 0)) twaps, err := oracleKeeper.CalculateTwaps(ctx, 200)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
x/oracle/keeper/keeper_test.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
x/oracle/keeper/keeper_test.go (5)
x/oracle/keeper/test_utils.go (1)
CreateTestInput(130-294)x/feeabstraction/types/expected_keepers.go (1)
OracleKeeper(39-43)x/oracle/utils/assets.go (1)
KiiDenom(5-5)x/oracle/types/params.pb.go (9)
Denom(113-116)Denom(119-119)Denom(120-122)OracleExchangeRate(229-233)OracleExchangeRate(236-236)OracleExchangeRate(237-239)PriceSnapshot(322-325)PriceSnapshot(329-329)PriceSnapshot(330-332)x/oracle/types/snapshots.go (3)
NewPriceSnapshotItem(22-27)NewPriceSnapshot(14-19)PriceSnapshotItems(4-4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: tests
- GitHub Check: golangci-lint
- GitHub Check: Analyze
- GitHub Check: test-e2e
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
x/oracle/keeper/keeper_test.go (1)
654-658: Fix contradictory error handling logic.The code uses
t.Errorfto fail the test when an error occurs, but the comments suggest this is meant to "demonstrate the vulnerability." This creates contradictory behavior:
- If the vulnerability exists and causes an error, the test fails (line 657)
- If the vulnerability is fixed with validation, the test also fails (line 657)
- The test can only pass if the function succeeds despite invalid input
Additionally, this issue was already flagged in the previous review comment (lines 623-664) but remains unaddressed. The test still lacks assertions to validate the expected behavior.
Apply this diff to remove the unconditional failure:
if err != nil { t.Logf(" RESULT: CalculateTwaps returned error: %v", err) t.Logf(" This demonstrates the function can fail due to timing issues") - t.Errorf("Failed with: %s", err) } else {Then follow one of the approaches suggested in the previous review to add proper assertions (assert error for fixed vulnerability, assert success for unfixed, or skip test).
🧹 Nitpick comments (1)
x/oracle/keeper/keeper_test.go (1)
692-692: Remove redundant block time setting.The block time is already set to
time.Unix(200, 0)at line 615 and doesn't change between subtests. This line is redundant.Apply this diff to remove the redundancy:
- ctx = ctx.WithBlockTime(time.Unix(200, 0)) twaps2, err := oracleKeeper.CalculateTwaps(ctx, 200)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
x/oracle/keeper/keeper_test.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
x/oracle/keeper/keeper_test.go (5)
x/oracle/keeper/test_utils.go (1)
CreateTestInput(130-294)x/feeabstraction/types/expected_keepers.go (1)
OracleKeeper(39-43)x/oracle/utils/assets.go (1)
KiiDenom(5-5)x/oracle/types/params.pb.go (9)
Denom(113-116)Denom(119-119)Denom(120-122)OracleExchangeRate(229-233)OracleExchangeRate(236-236)OracleExchangeRate(237-239)PriceSnapshot(322-325)PriceSnapshot(329-329)PriceSnapshot(330-332)x/oracle/types/snapshots.go (4)
OracleTwaps(10-10)NewPriceSnapshotItem(22-27)NewPriceSnapshot(14-19)PriceSnapshotItems(4-4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: golangci-lint
- GitHub Check: tests
- GitHub Check: liveness-test
- GitHub Check: test-e2e
- GitHub Check: Analyze
🔇 Additional comments (1)
x/oracle/keeper/keeper_test.go (1)
606-622: Test setup is correct, but be aware of cross-subtest dependency.The setup properly initializes the test environment and sets block time. The
twapsvariable is declared at line 622 to enable comparison between subtests, but this creates a dependency where the second subtest assumes the first succeeded.
Description
Type of change