Repository navigation
Conversation
The oracle price-aggregation helpers (calculateMedian, calculateTWAP, calculateDeviationBps) compute the aggregated AKT/USD price that gates the BME mint circuit breaker and the escrow AKT settlement fallback, but had no test coverage. Add internal (package keeper) unit tests pinning their behaviour: - calculateMedian: empty -> zero; odd -> middle; even -> average of the two middle values (unsorted input exercises the sort). - calculateDeviationBps: zero-min guard; (max-min)/min in basis points; no deviation -> 0. - calculateTWAP: empty -> error; single point -> that price; descending points time-weighted; identical timestamps fall back to the simple average. Test-only; the helpers are unchanged. Signed-off-by: parthod0x <parthms.id@gmail.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Calculation test cases x/oracle/keeper/aggregation_math_test.go |
Added test data setup and tests for median, deviation in basis points, and TWAP calculations. The tests cover empty inputs, unsorted values, time weighting, and identical timestamps. |
Priority:
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Other
Suggested reviewers: boz
Merge Risk: 
Minimal · up to f3a16
-
No actionable merge-blocking risk was identified.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed -
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
🔧 golangci-lint (2.14.0)
-
golangci-lint skipped: reviews.tools.golangci-lint.config_file must be a repository-relative path.
A rabbit checks the median line
Then weighs the prices, neat and fine
The timestamps hop into a row
The weighted totals start to glow
Tests pass; the rabbit nibbles clover
Comment @coderabbitai help to get the list of available commands.
What
Adds unit tests for the oracle price-aggregation helpers, which had no coverage.
x/oracle/keepercomputes the aggregated AKT/USD price viacalculateMedian,calculateTWAPandcalculateDeviationBps. That price gates two consensus-critical paths — the BME mint circuit breaker (mintStatusUpdate/calculateCR) and the escrow AKT settlement fallback (settleFromAktFallback) — yet none of the three helpers were tested.I reviewed the three functions and they are correct, so this is a pinning/regression test, not a bug fix.
Coverage
calculateMedian: empty → zero; odd → middle; even → average of the two middle values (unsorted input exercises the sort).calculateDeviationBps: zero-min guard;(max-min)/minin basis points; no-deviation → 0.calculateTWAP: empty → error; single point → that price; descending points time-weighted ((100·10s + 220·20s)/30s = 180); identical timestamps fall back to the simple average.Internal test (package
keeper) so it can exercise the unexported helpers.go test ./x/oracle/keeper/passes;go vet ./x/oracle/keeper/is clean.