Skip to content

Conversation

@lklimek
Copy link
Contributor

@lklimek lklimek commented Jan 29, 2026

Issue being fixed or feature implemented

What was done?

How Has This Been Tested?

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Documents can be restricted to "Any group member" via a new creation mode (value 3) and an associated group index.
    • Creation now enforces group membership: only members of the specified group can create documents.
  • Chores

    • Platform contract/version support updated to recognize the new document type version and schema changes.
  • Tests

    • Added tests covering group-restricted creation success/failure and schema validation.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added this to the v3.1.0 milestone Jan 29, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

Adds support for creationRestrictionMode = 3 ("Any group member") with an optional creationRestrictionGroup index across schema, DocumentTypeV2, validation, tests, and platform-versioning; enforces presence/absence of the group index and checks group membership during document creation.

Changes

Cohort / File(s) Summary
Schema & Enum Foundation
TODO.md, packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json, packages/rs-dpp/src/data_contract/document_type/restricted_creation/mod.rs
Added creationRestrictionGroup (u16) to document meta schema, extended creationRestrictionMode enum with value 3 (AnyGroupMember), added conditional schema rules requiring the group when mode=3, and updated enum parsing/display/tests.
DocumentType V2 Definition & Conversion
packages/rs-dpp/src/data_contract/document_type/v2/mod.rs, packages/rs-dpp/src/data_contract/document_type/v2/random_document_type.rs, packages/rs-dpp/src/data_contract/document_type/v2/accessors.rs
Introduced DocumentTypeV2 with creation_restriction_group: Option<GroupContractPosition>, From conversion, random generators delegating to V1, and V2-specific getters/setters implementations.
DocumentType Public API Integration
packages/rs-dpp/src/data_contract/document_type/mod.rs, packages/rs-dpp/src/data_contract/document_type/accessors/mod.rs, packages/rs-dpp/src/data_contract/document_type/accessors/v2/mod.rs, packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs, packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v2/mod.rs, packages/rs-dpp/src/data_contract/document_type/methods/versioned_methods.rs
Wired V2 into DocumentType enums and accessors, added V2 try_from_schema (enforces creationRestrictionGroup presence/absence), exposed V2 getters/setters and versioned method impls.
Drive: Creation Validation (Runtime)
packages/rs-drive-abci/src/execution/validation/.../document_create_transition_action/advanced_structure_v0/mod.rs
On creation with mode=3, resolve creationRestrictionGroup, validate group position exists, check creator membership via group.member_power; return specific errors (IdentityNotMemberOfGroupError, GroupPositionDoesNotExistError) as appropriate.
Drive: Contract Schema Validation (create/update)
packages/rs-drive-abci/src/execution/validation/.../data_contract_create/basic_structure/v0/mod.rs, packages/rs-drive-abci/src/execution/validation/.../data_contract_update/basic_structure/v0/mod.rs
Validate document schemas so mode=3 requires creationRestrictionGroup, ensure referenced group position exists, and return GroupPositionDoesNotExistError or InvalidContractStructure when missing/invalid.
Tests & Fixtures
packages/rs-drive-abci/src/execution/validation/.../batch/tests/document/creation.rs, packages/rs-drive-abci/tests/supporting_files/contract/crypto-card-game/crypto-card-game-direct-purchase-creation-restricted-to-group.json
Added contract fixture with creationRestrictionMode=3 and creationRestrictionGroup, and tests for member success, non-member rejection, and missing group position error.
Schema Compatibility & Platform
packages/rs-json-schema-compatibility-validator/src/rules/rule_set.rs, packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/mod.rs, packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v4.rs, packages/rs-platform-version/src/version/v12.rs
Added compatibility rule for creationRestrictionGroup; introduced CONTRACT_VERSIONS_V4 (DocumentTypeV2 support) and switched platform v12 to use v4.
Misc: Tests / Small Fixes
packages/rs-drive-abci/src/execution/platform_events/.../test/tokens.rs, packages/rs-drive-abci/tests/strategy_tests/test_cases/*.rs
Cleaned unused import, dropped unused verification tuple element, and added stack_size attributes to heavy tests.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Validator as Validator (Document Create)
    participant DocType as DocumentType V2
    participant Contract as Data Contract
    participant Group as Group

    Client->>Validator: Submit CreateDocument(owner_id)
    Validator->>DocType: creation_restriction_mode()
    DocType-->>Validator: AnyGroupMember (3)
    Validator->>DocType: creation_restriction_group()
    DocType-->>Validator: group_position
    Validator->>Contract: resolve_group_at_position(group_position)
    alt group exists
        Contract-->>Validator: Group ref
        Validator->>Group: member_power(owner_id)
        alt member_power > 0
            Group-->>Validator: member_power > 0
            Validator-->>Client: success (creation allowed)
        else not member
            Group-->>Validator: GroupMemberNotFound / ProtocolError
            Validator-->>Client: IdentityNotMemberOfGroupError
        end
    else position invalid
        Contract-->>Validator: not found
        Validator-->>Client: GroupPositionDoesNotExistError
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 A tiny hop to version two,

Mode three gathers group of true,
Members write where others can't,
Group index guides the access grant,
V2 stands ready — carrots, chant! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.20% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: document creation restriction by group membership' is clear, specific, and directly describes the main feature being implemented across the changeset—adding support for mode 3 creation restrictions based on group membership.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

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.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@packages/rs-drive-abci/tests/strategy_tests/test_cases/address_tests.rs`:
- Around line 3523-3524: Rename the test function
run_chain_high_throughput_address_operations so its identifier begins with
"should" to comply with the tests naming convention; update the function
declaration #[stack_size(4 * 1024 * 1024)] fn
run_chain_high_throughput_address_operations() to a descriptive name starting
with "should", e.g. #[stack_size(4 * 1024 * 1024)] fn
should_run_chain_high_throughput_address_operations(), and update any references
to this function in the test module accordingly (keep the stack_size attribute
and body unchanged).

In
`@packages/rs-drive-abci/tests/strategy_tests/test_cases/identity_and_document_tests.rs`:
- Around line 670-672: Rename the test function
run_chain_insert_one_new_identity_per_block_and_one_new_document to start with
"should" (e.g., should_insert_one_new_identity_per_block_and_one_new_document)
while preserving the #[test] and #[stack_size(4 * 1024 * 1024)] attributes and
any references; update any references or uses of the function name in the test
module so the new name compiles and continues to run under the same test
harness.
- Around line 760-762: The test function
run_chain_insert_one_new_identity_per_block_and_a_document_with_epoch_change
should be renamed to follow the convention starting with "should"; update the
test function name (the #[test] function
run_chain_insert_one_new_identity_per_block_and_a_document_with_epoch_change) to
a descriptive name beginning with "should" (e.g.,
should_insert_one_new_identity_per_block_and_document_with_epoch_change) and
update any references to that symbol in the test module; keep the
#[stack_size(...)] attribute and function body unchanged.
🧹 Nitpick comments (3)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/basic_structure/v0/mod.rs (1)

72-100: Consider using a named constant or the CreationRestrictionMode enum instead of magic number 3.

The value 3 represents AnyGroupMember mode but is unclear without context. The CreationRestrictionMode enum exists in the dpp crate and is already available through your imports. Using CreationRestrictionMode::AnyGroupMember as u8 or defining a constant would improve readability and prevent silent breakage if the enum values change. The same pattern appears in data_contract_create/basic_structure/v0/mod.rs at line 86.

TODO.md (1)

15-26: TODO items reference V0/V1, but implementation uses V2.

The tracking items suggest adding creation_restriction_group to DocumentTypeV0 and DocumentTypeV1, but based on the PR changes, the field is only being added to the new DocumentTypeV2. Consider updating the TODO to reflect the actual implementation approach (V2-only) to avoid confusion.

packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/basic_structure/v0/mod.rs (1)

328-385: Align the test name with the exercised scenario (nonexistent group).
The test sets creationRestrictionGroup: 1, so it validates a missing group position, not a missing field. Consider renaming and optionally adding a separate test that omits the field to exercise the “required” path.

✏️ Rename suggestion
-        fn should_return_invalid_result_when_creation_restriction_group_missing() {
+        fn should_return_invalid_result_when_creation_restriction_group_does_not_exist() {

Comment on lines +3523 to 3524
#[stack_size(4 * 1024 * 1024)]
fn run_chain_high_throughput_address_operations() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Rename test to start with should ….
The test name doesn’t follow the required naming convention.

Suggested rename
-    fn run_chain_high_throughput_address_operations() {
+    fn should_handle_high_throughput_address_operations() {

As per coding guidelines, **/tests/**/*.{js,jsx,ts,tsx,rs}: Name tests descriptively, starting with 'should …'.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[stack_size(4 * 1024 * 1024)]
fn run_chain_high_throughput_address_operations() {
#[stack_size(4 * 1024 * 1024)]
fn should_handle_high_throughput_address_operations() {
🤖 Prompt for AI Agents
In `@packages/rs-drive-abci/tests/strategy_tests/test_cases/address_tests.rs`
around lines 3523 - 3524, Rename the test function
run_chain_high_throughput_address_operations so its identifier begins with
"should" to comply with the tests naming convention; update the function
declaration #[stack_size(4 * 1024 * 1024)] fn
run_chain_high_throughput_address_operations() to a descriptive name starting
with "should", e.g. #[stack_size(4 * 1024 * 1024)] fn
should_run_chain_high_throughput_address_operations(), and update any references
to this function in the test module accordingly (keep the stack_size attribute
and body unchanged).

Comment on lines 670 to 672
#[test]
#[stack_size(4 * 1024 * 1024)]
fn run_chain_insert_one_new_identity_per_block_and_one_new_document() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Rename test to start with should ….
The test name doesn’t follow the required naming convention.

Suggested rename
-    fn run_chain_insert_one_new_identity_per_block_and_one_new_document() {
+    fn should_insert_one_new_identity_per_block_and_one_new_document() {

As per coding guidelines, **/tests/**/*.{js,jsx,ts,tsx,rs}: Name tests descriptively, starting with 'should …'.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[test]
#[stack_size(4 * 1024 * 1024)]
fn run_chain_insert_one_new_identity_per_block_and_one_new_document() {
#[test]
#[stack_size(4 * 1024 * 1024)]
fn should_insert_one_new_identity_per_block_and_one_new_document() {
🤖 Prompt for AI Agents
In
`@packages/rs-drive-abci/tests/strategy_tests/test_cases/identity_and_document_tests.rs`
around lines 670 - 672, Rename the test function
run_chain_insert_one_new_identity_per_block_and_one_new_document to start with
"should" (e.g., should_insert_one_new_identity_per_block_and_one_new_document)
while preserving the #[test] and #[stack_size(4 * 1024 * 1024)] attributes and
any references; update any references or uses of the function name in the test
module so the new name compiles and continues to run under the same test
harness.

Comment on lines 760 to 762
#[test]
#[stack_size(4 * 1024 * 1024)]
fn run_chain_insert_one_new_identity_per_block_and_a_document_with_epoch_change() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Rename test to start with should ….
The test name doesn’t follow the required naming convention.

Suggested rename
-    fn run_chain_insert_one_new_identity_per_block_and_a_document_with_epoch_change() {
+    fn should_insert_one_new_identity_per_block_and_a_document_with_epoch_change() {

As per coding guidelines, **/tests/**/*.{js,jsx,ts,tsx,rs}: Name tests descriptively, starting with 'should …'.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[test]
#[stack_size(4 * 1024 * 1024)]
fn run_chain_insert_one_new_identity_per_block_and_a_document_with_epoch_change() {
#[test]
#[stack_size(4 * 1024 * 1024)]
fn should_insert_one_new_identity_per_block_and_a_document_with_epoch_change() {
🤖 Prompt for AI Agents
In
`@packages/rs-drive-abci/tests/strategy_tests/test_cases/identity_and_document_tests.rs`
around lines 760 - 762, The test function
run_chain_insert_one_new_identity_per_block_and_a_document_with_epoch_change
should be renamed to follow the convention starting with "should"; update the
test function name (the #[test] function
run_chain_insert_one_new_identity_per_block_and_a_document_with_epoch_change) to
a descriptive name beginning with "should" (e.g.,
should_insert_one_new_identity_per_block_and_document_with_epoch_change) and
update any references to that symbol in the test module; keep the
#[stack_size(...)] attribute and function body unchanged.

@lklimek lklimek marked this pull request as draft January 29, 2026 15:56
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.

2 participants