Skip to content

fix(dpp): populate transferred_at in random_document_with_params when required#3517

Merged
QuantumExplorer merged 1 commit into
v3.1-devfrom
fix/dpp-random-document-transferred-at
Apr 23, 2026
Merged

fix(dpp): populate transferred_at in random_document_with_params when required#3517
QuantumExplorer merged 1 commit into
v3.1-devfrom
fix/dpp-random-document-transferred-at

Conversation

@QuantumExplorer
Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

packages/rs-dpp/src/data_contract/document_type/random_document.rs:206 DocumentType::random_document_with_params unconditionally set transferred_at, transferred_at_block_height, and transferred_at_core_block_height to None — even when those fields were listed in the document type's required_fields.

Callers that subsequently serialized the returned Document (e.g. any test that writes it to grove) hit:

DataContractError(MissingRequiredKey("transferred at field is not present"))

This was surfaced while writing uniqueness-violation tests against DPNS domain in #3516.

All other random_* methods delegate to random_document_with_params, so the bug affected every random-document helper in the CreateRandomDocument trait.

What was done?

Mirror the existing $createdAt / $createdAtBlockHeight / $createdAtCoreBlockHeight logic for the three $transferredAt fields:

  • transferred_at — use time_ms if provided, else created_at, else wall clock. Matches the updated_at fallback chain.
  • transferred_at_block_height — use block_height if provided, else Some(0). Matches updated_at_block_height.
  • transferred_at_core_block_height — use core_block_height if provided, else Some(0). Matches updated_at_core_block_height.

Added three regression tests using DPNS as fixture data:

  1. random_document_populates_transferred_at_when_required — DPNS domain requires $transferredAt, so the generated doc must have it populated from time_ms.
  2. random_document_leaves_transferred_at_none_when_not_required — DPNS preorder requires none of the three $transferredAt* fields, so all three must be None.
  3. transferred_at_falls_back_to_created_at_when_no_time_provided — when time_ms is not provided, transferred_at should fall back to created_at.

How Has This Been Tested?

  • cargo test -p dpp --lib 'data_contract::document_type::random_document' — 3/3 pass
  • cargo check --tests -p dpp — clean
  • cargo fmt -p dpp — clean

Breaking Changes

None. The fix only changes behavior when the document type lists a $transferredAt* field as required — the old code produced a Document that would fail serialization in that case. Callers that were relying on the old behavior for non-required cases see no change.

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

… required

`DocumentType::random_document_with_params` unconditionally set
`transferred_at`, `transferred_at_block_height`, and
`transferred_at_core_block_height` to `None`, even when those fields
were listed in the document type's `required_fields`. Any caller
that subsequently serialized the returned `Document` hit
`DataContractError(MissingRequiredKey("transferred at field is not
present"))`.

Mirror the existing CREATED_AT/CREATED_AT_BLOCK_HEIGHT/
CREATED_AT_CORE_BLOCK_HEIGHT logic:
- `transferred_at`: use `time_ms` if provided, else `created_at`,
  else wall clock — matching `updated_at`'s fallback chain.
- `transferred_at_block_height`: use `block_height` if provided,
  else `Some(0)` — matching `updated_at_block_height`.
- `transferred_at_core_block_height`: use `core_block_height` if
  provided, else `Some(0)` — matching `updated_at_core_block_height`.

Three regression tests via DPNS:
- `domain` requires `$transferredAt`: generated doc has it populated
  from `time_ms`.
- `preorder` does not require any `$transferredAt*`: generated doc
  has all three `None`.
- `domain` with no `time_ms` provided: `transferred_at` falls back
  to `created_at` as specified by the matching `updated_at` logic.

All `random_*` sibling methods delegate to
`random_document_with_params`, so this fix covers every caller
(`random_document`, `random_document_with_rng`, `random_documents*`,
`random_document_with_identifier_and_entropy`,
`random_documents_with_params`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

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

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 27 minutes and 0 seconds.

⌛ 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2aeed56c-da39-4d05-91ed-09a7a9c0be06

📥 Commits

Reviewing files that changed from the base of the PR and between 3eaf388 and f7ae526.

📒 Files selected for processing (1)
  • packages/rs-dpp/src/data_contract/document_type/random_document.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dpp-random-document-transferred-at

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.

@github-actions github-actions Bot added this to the v3.1.0 milestone Apr 23, 2026
@thepastaclaw
Copy link
Copy Markdown
Collaborator

thepastaclaw commented Apr 23, 2026

Review Gate

Commit: f7ae526c

  • Debounce: 12m ago (need 30m)

  • CI checks: build failure: JS packages (@dashevo/wasm-sdk) / Tests, JS packages (@dashevo/wallet-lib) / Tests, JS packages (@dashevo/wasm-dpp) / Tests

  • CodeRabbit review: comment found

  • Off-peak hours: off-peak (09:30 PM PT Wednesday)

  • Run review now (check to override)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.08%. Comparing base (3eaf388) to head (f7ae526).
⚠️ Report is 2 commits behind head on v3.1-dev.

Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3517      +/-   ##
============================================
+ Coverage     87.04%   87.08%   +0.03%     
============================================
  Files          2474     2474              
  Lines        283604   283604              
============================================
+ Hits         246863   246963     +100     
+ Misses        36741    36641     -100     
Components Coverage Δ
dpp 86.26% <ø> (+0.02%) ⬆️
drive 86.25% <ø> (+0.02%) ⬆️
drive-abci 89.09% <ø> (+0.06%) ⬆️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 92.10% <ø> (ø)
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 55.66% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@QuantumExplorer QuantumExplorer merged commit 4aa73ca into v3.1-dev Apr 23, 2026
36 of 39 checks passed
@QuantumExplorer QuantumExplorer deleted the fix/dpp-random-document-transferred-at branch April 23, 2026 04:38
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