Skip to content

fix(dpp): add missing #[test] attribute to should_set_empty_schema_defs#3101

Merged
shumkov merged 2 commits intodashpay:v3.1-devfrom
thepastaclaw:fix/missing-test-attributes
Feb 22, 2026
Merged

fix(dpp): add missing #[test] attribute to should_set_empty_schema_defs#3101
shumkov merged 2 commits intodashpay:v3.1-devfrom
thepastaclaw:fix/missing-test-attributes

Conversation

@thepastaclaw
Copy link
Collaborator

@thepastaclaw thepastaclaw commented Feb 18, 2026

Problem

should_set_empty_schema_defs() exists in both v0 and v1 DataContract schema test modules inside #[cfg(test)] mod tests, but was shipped without the #[test] attribute. The test runner silently skips these functions — they compile but never execute.

Introduced in #3077 (d6f4eb9, @shumkov) — the function was added to the test module but the #[test] attribute was never included. The test was DOA from day one. 🍝

Additionally, the test body used document_schemas: Default::default() (empty BTreeMap), which now fails validation with DocumentTypesAreMissingError. Fixed by adding a minimal document schema matching the pattern from the adjacent should_set_a_new_schema_defs test.

Fix

  1. Add #[test] attribute to both v0 and v1 versions
  2. Add a dummy document schema so contract creation doesn't fail validation
  3. Both tests now pass: cargo test -p dpp --lib -- should_set_empty_schema_defs

Files changed

2 files — packages/rs-dpp/src/data_contract/{v0,v1}/methods/schema.rs

Found during SDK test quality audit (tracker thepastaclaw/tracker#12).

Summary by CodeRabbit

  • Tests
    • Added test coverage for data contract schema operations to validate behavior when clearing schema definitions and handling empty schema states.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

Warning

Rate limit exceeded

@thepastaclaw has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 59 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📝 Walkthrough

Walkthrough

Both v0 and v1 schema modules add a test verifying behavior when schema_defs is set to None with pre-populated document_schemas. The test confirms that calling set_schema_defs(None, ...) clears schema_defs to None.

Changes

Cohort / File(s) Summary
Schema Test Additions
packages/rs-dpp/src/data_contract/v0/methods/schema.rs, packages/rs-dpp/src/data_contract/v1/methods/schema.rs
Add new test should_set_empty_schema_defs to verify that calling set_schema_defs(None, ...) correctly clears schema_defs while document_schemas remains populated.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 Schemas test their empty states with care,
Setting defs to None, the contract bare,
V0 and V1 in harmony align,
Tests confirm the clearing works just fine! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding missing #[test] attributes to the should_set_empty_schema_defs functions across both v0 and v1 modules.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@thepastaclaw thepastaclaw force-pushed the fix/missing-test-attributes branch from 3fa4706 to 2935852 Compare February 18, 2026 18:12
Copy link
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.

🧹 Nitpick comments (2)
packages/rs-dpp/src/data_contract/v1/methods/schema.rs (1)

179-213: Consider asserting document_types are still populated after clearing defs.

The test verifies that schema_defs becomes None, but does not confirm that document_types remains intact — which is the other observable side-effect of set_schema_defs. Adding this assertion would close a small coverage gap and guard against future regressions in the set_document_schemas call inside set_schema_defs.

💡 Suggested additional assertion
         data_contract
             .set_schema_defs(None, true, &mut vec![], platform_version)
             .expect("should set defs");

         assert_eq!(None, data_contract.schema_defs())
+        assert_eq!(1, data_contract.document_types().len(), "document_types should be preserved after clearing schema_defs");
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-dpp/src/data_contract/v1/methods/schema.rs` around lines 179 -
213, The test currently only asserts that schema_defs() becomes None after
calling DataContractV1::set_schema_defs, but doesn't assert that
document_schemas remain populated; update the test to also assert the
document_schemas (or document_types) are still present on the data_contract
after set_schema_defs returns (e.g., call data_contract.document_schemas() or
the appropriate getter on the DataContractV1 instance and assert it contains the
previously inserted "document_type_name" schema), so
set_schema_defs/DataContractV1::set_document_schemas behavior is covered.
packages/rs-dpp/src/data_contract/v0/methods/schema.rs (1)

208-213: Consider asserting document type integrity after clearing defs.

The current assertion only verifies the schema_defs postcondition. Adding a check that document_types / document_schemas() are still intact after the set_schema_defs(None, …) call would make the test more comprehensive and guard against an accidental wipe of document types.

➕ Proposed additional assertion
         data_contract
             .set_schema_defs(None, true, &mut vec![], platform_version)
             .expect("should set defs");

+        assert_eq!(1, data_contract.document_types().len(), "document types should be preserved after clearing schema defs");
         assert_eq!(None, data_contract.schema_defs())
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-dpp/src/data_contract/v0/methods/schema.rs` around lines 208 -
213, The test currently only checks that schema_defs() is None after calling
data_contract.set_schema_defs(None, true, &mut vec![], platform_version); add an
assertion to also verify that document type schemas remain intact — e.g.,
capture the pre-call document_schemas()/document_types() state, call
set_schema_defs(...), then assert equality with data_contract.document_schemas()
(or data_contract.document_types()) so clearing defs does not accidentally wipe
document schemas; reference the methods set_schema_defs, schema_defs(), and
document_schemas()/document_types() to locate where to add this assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/rs-dpp/src/data_contract/v0/methods/schema.rs`:
- Around line 208-213: The test currently only checks that schema_defs() is None
after calling data_contract.set_schema_defs(None, true, &mut vec![],
platform_version); add an assertion to also verify that document type schemas
remain intact — e.g., capture the pre-call document_schemas()/document_types()
state, call set_schema_defs(...), then assert equality with
data_contract.document_schemas() (or data_contract.document_types()) so clearing
defs does not accidentally wipe document schemas; reference the methods
set_schema_defs, schema_defs(), and document_schemas()/document_types() to
locate where to add this assertion.

In `@packages/rs-dpp/src/data_contract/v1/methods/schema.rs`:
- Around line 179-213: The test currently only asserts that schema_defs()
becomes None after calling DataContractV1::set_schema_defs, but doesn't assert
that document_schemas remain populated; update the test to also assert the
document_schemas (or document_types) are still present on the data_contract
after set_schema_defs returns (e.g., call data_contract.document_schemas() or
the appropriate getter on the DataContractV1 instance and assert it contains the
previously inserted "document_type_name" schema), so
set_schema_defs/DataContractV1::set_document_schemas behavior is covered.

@thepastaclaw thepastaclaw force-pushed the fix/missing-test-attributes branch from 397720f to b4ee514 Compare February 20, 2026 21:39
thepastaclaw added a commit to thepastaclaw/platform that referenced this pull request Feb 20, 2026
The #[test] attribute fix and schema_defs test improvements for
should_set_empty_schema_defs are already covered by PR dashpay#3101.
Removing duplicates to keep PRs independent.
@thepastaclaw
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Both v0 and v1 DataContract schema test modules had
should_set_empty_schema_defs() defined inside #[cfg(test)] but
missing the #[test] attribute. The test runner silently skipped them.
Address CodeRabbit nitpick: add assertions that document_types remain
intact after set_schema_defs(None, ...) in both v0 and v1 tests.
@thepastaclaw thepastaclaw force-pushed the fix/missing-test-attributes branch from b4ee514 to 3762dc7 Compare February 21, 2026 18:02
thepastaclaw added a commit to thepastaclaw/platform that referenced this pull request Feb 21, 2026
The #[test] attribute fix and schema_defs test improvements for
should_set_empty_schema_defs are already covered by PR dashpay#3101.
Removing duplicates to keep PRs independent.
@shumkov shumkov merged commit 7441443 into dashpay:v3.1-dev Feb 22, 2026
76 of 78 checks passed
thepastaclaw added a commit to thepastaclaw/platform that referenced this pull request Feb 25, 2026
The #[test] attribute fix and schema_defs test improvements for
should_set_empty_schema_defs are already covered by PR dashpay#3101.
Removing duplicates to keep PRs independent.
thepastaclaw added a commit to thepastaclaw/platform that referenced this pull request Mar 12, 2026
The #[test] attribute fix and schema_defs test improvements for
should_set_empty_schema_defs are already covered by PR dashpay#3101.
Removing duplicates to keep PRs independent.
thepastaclaw added a commit to thepastaclaw/platform that referenced this pull request Mar 12, 2026
The #[test] attribute fix and schema_defs test improvements for
should_set_empty_schema_defs are already covered by PR dashpay#3101.
Removing duplicates to keep PRs independent.
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.

3 participants