Repository navigation
test(drive): improve document module test coverage - #3333
Conversation
Add 17 new tests targeting genuinely uncovered code paths in the drive document module, focusing on public API endpoints and error branches that had 0% coverage from drive-only tests: Delete module: - delete_document_for_contract_id (stateful + estimated costs) - delete of history-keeping documents returns correct error Insert module: - add_document via contract_id API - add_document_for_contract with history-keeping documents (apply + estimated) - add_document_for_contract_apply_and_add_to_operations non-unique batch path Query module: - query_documents dry_run, with epoch fee, without epoch - query_documents_with_flags (stateful, dry_run, with epoch) Update module: - add_update_multiple_documents_operations (non-empty + empty) - update immutable document type returns error - update_document_with_serialization_for_contract - update_document_for_contract_id Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
Codecov Report❌ Patch coverage is Additional details and impacted files
🚀 New features to boost your workflow:
|
QuantumExplorer
left a comment
There was a problem hiding this comment.
Audit Review
Good coverage additions targeting previously untested API variants (contract-id-based APIs, estimation paths, dry-run, with-flags queries). Error-path tests are particularly well done. The main pattern issue across the PR is tests that perform write operations but never read back the data to verify correctness.
Good practices observed
- Strong error-variant matching with
matches!()and.expect_err() - Covers alternative API surfaces (
*_for_contract_idvariants) not just the primary APIs - Covers estimation/dry-run paths consistently
- No test duplication with existing tests
- Consistent style with existing test code
Production code observation
In add_document/v0/mod.rs, the drive_operations variable created at line 29 for contract fetch is shadowed by a second drive_operations at line 51. The contract fetch operations are discarded and not included in fee calculation. This is pre-existing, not introduced by this PR.
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Test-only PR adding 17 unit tests to drive/document. All tests compile and exercise real code paths, but several only assert 'no error' or 'fee > 0' without verifying actual state changes. The dry-run query tests are effectively vacuous because they query an empty contract. No blocking issues — these are coverage-improving tests that would benefit from stronger assertions.
🟡 4 suggestion(s)
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `packages/rs-drive/src/drive/document/update/mod.rs`:
- [SUGGESTION] line 2234: Update tests only assert fee, never verify the document was actually updated
Both `test_update_document_with_serialization_for_contract` (line 2234) and `test_update_document_for_contract_id` (line 2312) set displayName from "Alice" to "Bob", call the update API, then only assert `processing_fee > 0`. Neither test queries the document afterward to confirm the stored value changed. A serialization bug that charged fees but wrote stale data would pass both tests. Adding a read-back assertion (e.g., query the profile and check displayName == "Bob") would make these tests catch real regressions.
- [SUGGESTION] lines 2058-2071: Multi-update test only counts the outer vector, not the batch contents
`test_add_update_multiple_documents_operations` creates 2 documents, calls `add_update_multiple_documents_operations`, and asserts `drive_operations.len() == 1`. This correctly verifies batching (multiple docs → one operation), but doesn't inspect the operation variant or confirm both documents are represented inside it. A regression that emitted a wrong variant or silently dropped one document would still pass. Destructure the emitted `DriveOperation` and assert the variant and number of nested update operations.
In `packages/rs-drive/src/drive/document/query/mod.rs`:
- [SUGGESTION] lines 526-543: Dry-run query tests are vacuous — they query an empty contract
`test_query_documents_dry_run` and `test_query_documents_with_flags_dry_run` never insert any documents before querying. `setup_dashpay()` only applies the contract, so asserting 0 results / 0 skipped / 0 cost is the same outcome you'd get from a non-dry-run query on an empty document type. These tests don't actually verify that the dry_run flag short-circuits storage access — they only prove that querying an empty type returns nothing. Insert at least one document before querying so the dry-run path diverges from the normal path (dry run should still return 0 results, but the non-dry-run would return 1).
In `packages/rs-drive/src/drive/document/insert/mod.rs`:
- [SUGGESTION] lines 1011-1099: History insert test doesn't verify any history-specific behavior
`test_add_document_with_history` inserts two documents under a history-enabled contract, asserts `storage_fee > 0` for the first, and commits the transaction. It never queries back to confirm the documents are retrievable or that the history tree structure was created. Since the stated goal is to cover the history code path, this test currently proves only that the calls returned `Ok` — a bug where history storage silently fell back to non-history storage would pass. Consider querying the inserted documents or comparing the storage structure against a non-history contract.
- Add fetch-back verification to insert, update, and delete tests - Verify document content after operations (not just fees) - Insert documents before calling update operations - Replace .unwrap() with .expect() for better diagnostics - Remove unused variable Co-Authored-By: Claude Opus 4.6 <[email protected]>
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Test-only PR adding 17 unit tests to drive/document. All tests compile and exercise real code paths, but several only assert 'no error' or 'fee > 0' without verifying actual state changes. The dry-run query tests are effectively vacuous because they query an empty contract. No blocking issues — these are coverage-improving tests that would benefit from stronger assertions.
🟡 4 suggestion(s) | 💬 1 nitpick(s)
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `packages/rs-drive/src/drive/document/update/mod.rs`:
- [SUGGESTION] line 2234: Update tests only assert fee, never verify the document was actually updated
Both `test_update_document_with_serialization_for_contract` and `test_update_document_for_contract_id` set displayName from "Alice" to "Bob", call the update API, then only assert `processing_fee > 0`. Neither test queries the document afterward to confirm the stored value changed. A serialization bug that charged fees but wrote stale data would pass both tests. Adding a read-back assertion (e.g., query the profile and check displayName == "Bob") would make these tests catch real regressions.
- [SUGGESTION] lines 2058-2071: Multi-update test only counts the outer vector, not the batch contents
`test_add_update_multiple_documents_operations` creates 2 documents, calls `add_update_multiple_documents_operations`, and asserts `drive_operations.len() == 1`. This correctly verifies batching (multiple docs to one operation), but doesn't inspect the operation variant or confirm both documents are represented inside it. A regression that emitted a wrong variant or silently dropped one document would still pass.
In `packages/rs-drive/src/drive/document/query/mod.rs`:
- [SUGGESTION] lines 526-543: Dry-run query tests are vacuous — they query an empty contract
`test_query_documents_dry_run` and `test_query_documents_with_flags_dry_run` never insert any documents before querying. `setup_dashpay()` only applies the contract, so asserting 0 results / 0 skipped / 0 cost is the same outcome you'd get from a non-dry-run query on an empty document type. These tests don't actually verify that the dry_run flag short-circuits storage access — they only prove that querying an empty type returns nothing. Insert at least one document before querying so the dry-run path diverges from the normal path (dry run should still return 0 results, but the non-dry-run would return 1).
In `packages/rs-drive/src/drive/document/insert/mod.rs`:
- [SUGGESTION] lines 1011-1099: History insert test doesn't verify any history-specific behavior
`test_add_document_with_history` inserts two documents under a history-enabled contract, asserts `storage_fee > 0` for the first, and commits the transaction. It never queries back to confirm the documents are retrievable or that the history tree structure was created. A bug where history storage silently fell back to non-history storage would pass. Consider querying the inserted documents or comparing the storage structure against a non-history contract.
Issue being fixed or feature implemented
Improve test coverage for the
packages/rs-drive/src/drive/document/module by targeting code paths with 0% coverage from drive-only tests.What was done?
Added 17 new unit tests targeting genuinely uncovered code paths in the drive document module. Coverage analysis was performed using
cargo llvm-covto identify specific files and functions with the lowest coverage.Delete module (3 tests):
test_delete_document_for_contract_id- exercises thedelete_document_for_contract_idpublic API (was 0% covered)test_delete_document_for_contract_id_estimated_costs- exercises the estimation (apply=false) pathtest_delete_document_keeps_history_returns_error- covers theInvalidDeletionOfDocumentThatKeepsHistoryerror branchInsert module (4 tests):
test_add_document_by_contract_id- exercises theadd_documentpublic API (was 0% covered)test_add_document_with_history- covers thedocuments_keep_history()branch inadd_document_to_primary_storage(was ~50% covered)test_add_document_with_history_estimated_costs- covers the estimation path for history-keeping documentstest_add_document_for_contract_with_non_unique_batch- covers thedocument_is_unique_for_document_type_in_batch=falsebranchQuery module (6 tests):
test_query_documents_dry_run- covers the dry_run early return pathtest_query_documents_with_epoch_fee- covers the epoch fee calculation branchtest_query_documents_without_epoch_zero_cost- covers the no-epoch zero-cost pathtest_query_documents_with_flags- exercisesquery_documents_with_flags(was 0% covered)test_query_documents_with_flags_dry_run- dry_run path for flags querytest_query_documents_with_flags_with_epoch- epoch fee calculation for flags queryUpdate module (4 tests):
test_add_update_multiple_documents_operations- exercises batch update operations (was 0% covered)test_add_update_multiple_documents_operations_empty- covers empty documents guardtest_update_document_for_contract_immutable_error- coversUpdatingReadOnlyImmutableDocumenterrortest_update_document_with_serialization_for_contract- exercises the serialization update API (was 0% covered)test_update_document_for_contract_id- exercises the contract_id update API (was 0% covered)How Has This Been Tested?
All 17 new tests pass:
Full drive test suite passes with all existing tests (1374+ unit tests, 30 query tests, 3 history query tests).
Breaking Changes
None. This PR adds tests only.
Checklist: