fix(dpp): populate transferred_at in random_document_with_params when required#3517
Conversation
… 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>
|
Warning Rate limit exceeded
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 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 (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Review GateCommit:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
Issue being fixed or feature implemented
packages/rs-dpp/src/data_contract/document_type/random_document.rs:206
DocumentType::random_document_with_paramsunconditionally settransferred_at,transferred_at_block_height, andtransferred_at_core_block_heighttoNone— even when those fields were listed in the document type'srequired_fields.Callers that subsequently serialized the returned
Document(e.g. any test that writes it to grove) hit:This was surfaced while writing uniqueness-violation tests against DPNS
domainin #3516.All other
random_*methods delegate torandom_document_with_params, so the bug affected every random-document helper in theCreateRandomDocumenttrait.What was done?
Mirror the existing
$createdAt/$createdAtBlockHeight/$createdAtCoreBlockHeightlogic for the three$transferredAtfields:transferred_at— usetime_msif provided, elsecreated_at, else wall clock. Matches theupdated_atfallback chain.transferred_at_block_height— useblock_heightif provided, elseSome(0). Matchesupdated_at_block_height.transferred_at_core_block_height— usecore_block_heightif provided, elseSome(0). Matchesupdated_at_core_block_height.Added three regression tests using DPNS as fixture data:
random_document_populates_transferred_at_when_required— DPNSdomainrequires$transferredAt, so the generated doc must have it populated fromtime_ms.random_document_leaves_transferred_at_none_when_not_required— DPNSpreorderrequires none of the three$transferredAt*fields, so all three must beNone.transferred_at_falls_back_to_created_at_when_no_time_provided— whentime_msis not provided,transferred_atshould fall back tocreated_at.How Has This Been Tested?
cargo test -p dpp --lib 'data_contract::document_type::random_document'— 3/3 passcargo check --tests -p dpp— cleancargo fmt -p dpp— cleanBreaking Changes
None. The fix only changes behavior when the document type lists a
$transferredAt*field as required — the old code produced aDocumentthat would fail serialization in that case. Callers that were relying on the old behavior for non-required cases see no change.Checklist
For repository code-owners and collaborators only