[BE-062] Yield API: Validation unit tests - #513
Conversation
Adds coverage for /api/yield input validation and format checks: non-positive amounts, insufficient balance, malformed JSON syntax, missing/wrong-typed fields, and pagination clamping/rejection on /history, /deposit, /withdraw, and /toggle-auto. Closes Fracverse#480 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@Meemlahsabi Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@Meemlahsabi |
… tests
Two real bugs found while verifying this PR against the actual codebase
(neither could have passed CI as written):
1. `let _ = AuthUser;` referenced a 3-field struct by its bare type name,
which is not a valid Rust expression (E0533-class error) — the test
binary did not compile. AuthUser was never actually used as a type
anywhere in this file; removed both the import and the dead reference.
2. Every seeded test address (e.g. "GVALIDNONPOS{run}XXXX...X") was 61
characters, but `users.address` is `VARCHAR(56)`
(backend/migrations/0001_schema.sql:6) — every `seed_user()` call in
every new validation test would have failed with a Postgres
"value too long for type character varying(56)" error. Added a
`test_address(prefix, run)` helper that always produces exactly 56
characters and replaced all nine manual constructions with it.
Also calls `zaps_backend::db::run_migrations` in `test_pool()` so the test
binary applies the schema itself rather than requiring it pre-applied out
of band, and ran `rustfmt` on this file only (cargo fmt --check now passes
for it; unrelated pre-existing formatting drift in yield.rs, stellar.rs,
notifications.rs, and yield_calc.rs is untouched).
I could not run `cargo test`/`cargo clippy` locally (no Postgres/Redis
instance or MSVC-equivalent toolchain available in this environment) — I
verified this by reading the current backend/src/api/yield.rs handlers
line by line and confirming every status code, error string, and field
name this file asserts against still matches (Amount must be greater than
zero, Insufficient available/earning balance + available/earning fields,
Axum's default Json extractor 400-syntax/422-data split, HistoryQuery's
clamp(1,100)/max(0) logic).
|
Addressed the review feedback: "Make sure your implementation passes CI Checks" — the test file did not actually compile. Separately (found while double-checking against the actual schema): every seeded test address in the new validation tests was 61 characters, but Also had "Sync with master branch" — I couldn't fully rebase this branch onto current upstream I could not run |
|
@Meemlahsabi |
|
@Meemlahsabi |
Resolve conflict in yield_api_tests.rs by keeping master SWEEP/REWARD history coverage and the BE-062 validation tests, without the unused AuthUser stub.
|
@ONEONUORA Updated — branch is synced with latest What changed
PR is now mergeable (no conflicts). CI should re-run on the merge commit. |
ONEONUORA
left a comment
There was a problem hiding this comment.
Great job @Meemlahsabi
Summary
/api/yieldendpoints inbackend/tests/yield_api_tests.rsamountrejection on/depositand/withdraw/depositand/withdraw/deposit,/withdraw, and/toggle-auto/historypaginationlimit/offsetclamping and rejection of non-numeric query paramsCloses #480
Test plan
cargo test --test yield_api_testsagainst a PostgreSQL instance with the Zaps schema applied (TEST_DATABASE_URLorDATABASE_URLset)🤖 Generated with Claude Code