Skip to content

test(dpp): improve coverage for cbor canonical, json utils, and document accessors#3383

Merged
QuantumExplorer merged 1 commit into
v3.1-devfrom
test/dpp-utils-coverage
Mar 18, 2026
Merged

test(dpp): improve coverage for cbor canonical, json utils, and document accessors#3383
QuantumExplorer merged 1 commit into
v3.1-devfrom
test/dpp-utils-coverage

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

Improves unit test coverage for four DPP utility modules that had low coverage:

  • util/cbor_value/canonical.rs (28.8% -> improved)
  • util/json_value/mod.rs (22.8% -> improved)
  • document/specialized_document_factory/v0/mod.rs (8.2% -> improved)
  • data_contract/document_type/accessors/mod.rs (42.6% -> improved)

What was done?

Added 160 new unit tests across four files:

canonical.rs (55 new tests):

  • CborCanonicalMap construction (new, default, from_vector, from_serializable)
  • Insert, remove, get, get_mut, set operations
  • Canonical sorting per RFC 7049 (shorter keys first, then lexicographic)
  • Recursive sorting of nested maps and maps inside arrays
  • Serialization to bytes and round-trip deserialization
  • to_value_unsorted, to_value_sorted, to_value_clone
  • TryFrom<CborValue> and From impls for Vec and BTreeMap
  • ValuesCollection trait (get, get_mut, remove)
  • ReplacePaths trait (replace_paths, replace_path, get_path_mut)
  • value_to_bytes with Bytes, Text (base58), Array, and error cases
  • value_to_hash with Bytes, Text (base58), Array, and error cases

json_value/mod.rs (52 new tests):

  • All JsonValueExt trait methods: push, insert, remove, remove_into
  • Numeric getters: get_u8, get_u32, get_u64, get_i64, get_f64
  • Other getters: get_string, get_bytes, get_bool
  • Path navigation: get_value, get_value_mut, get_value_by_path, get_value_by_path_mut
  • Mutation: remove_u32, add_protocol_version, remove_value_at_path_into
  • Free functions: get_value_mut, get_value_from_json_path, get_value_from_json_path_mut
  • insert_with_path for deeply nested structure creation
  • Error cases for all methods (missing property, wrong type, non-object/array)

document_type/accessors/mod.rs (37 new tests):

  • All DocumentTypeV0Getters methods on DocumentType, DocumentTypeRef, DocumentTypeMutRef
  • DocumentTypeV0Setters (set_data_contract_id) on DocumentType and DocumentTypeMutRef
  • DocumentTypeV0MutGetters (schema_mut)
  • DocumentTypeV1Getters on V0 variants (verify None/empty defaults)
  • DocumentTypeV1Setters on V0 variants (verify no-op behavior)
  • Tests with multiple fixture document types (indexedDocument, noTimeDocument, withByteArrays, niceDocument)
  • to_owned_document_type from ref

specialized_document_factory/v0/mod.rs (10 new tests):

  • Factory construction with default and custom entropy generators
  • Document creation with valid and invalid document type names
  • Document creation without time-based properties
  • Extended document creation (valid and invalid)
  • is_ownership_the_same helper with same, different, single, and empty ID sets

How Has This Been Tested?

All 164 tests pass with cargo test -p dpp:

test result: ok. 164 passed; 0 failed; 0 ignored; 0 measured; 904 filtered out

Code was formatted with cargo fmt -p dpp and compiles without warnings.

Breaking Changes

None. This PR only adds tests.

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

…ent accessors

Add comprehensive unit tests for four DPP utility modules with low
coverage:

- canonical.rs: Tests for CborCanonicalMap construction, insert/remove/
  get/set operations, canonical sorting (RFC 7049), serialization
  round-trips, TryFrom/From impls, ValuesCollection trait, ReplacePaths
  trait, value_to_bytes, and value_to_hash with various CBOR value types.

- json_value/mod.rs: Tests for all JsonValueExt trait methods including
  push, insert, remove, remove_into, get_string/u8/u32/u64/i64/f64/
  bytes/bool, get_value/get_value_mut path navigation, get_value_by_path,
  remove_u32, add_protocol_version, remove_value_at_path_into, and free
  functions get_value_mut/get_value_from_json_path.

- document_type/accessors/mod.rs: Tests for DocumentTypeV0Getters,
  DocumentTypeV0Setters, DocumentTypeV0MutGetters on DocumentType,
  DocumentTypeRef, and DocumentTypeMutRef. Also covers DocumentTypeV1Getters
  and DocumentTypeV1Setters on V0 variants (None/no-op behavior).

- specialized_document_factory/v0/mod.rs: Tests for document creation
  with valid/invalid types, extended document creation, factory
  construction, and is_ownership_the_same helper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added this to the v3.1.0 milestone Mar 18, 2026
@codecov

codecov Bot commented Mar 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.90756% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.87%. Comparing base (2fb112c) to head (5c4082f).
⚠️ Report is 19 commits behind head on v3.1-dev.

Files with missing lines Patch % Lines
packages/rs-dpp/src/util/cbor_value/canonical.rs 97.28% 13 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3383      +/-   ##
============================================
+ Coverage     75.87%   76.87%   +1.00%     
============================================
  Files          2912     2914       +2     
  Lines        283860   287443    +3583     
============================================
+ Hits         215375   220975    +5600     
+ Misses        68485    66468    -2017     
Components Coverage Δ
dpp 69.00% <98.90%> (+3.28%) ⬆️
drive 81.66% <ø> (+0.01%) ⬆️
drive-abci 85.98% <ø> (-0.01%) ⬇️
sdk 31.25% <ø> (ø)
dapi-client 79.06% <ø> (ø)
platform-version ∅ <ø> (∅)
platform-value 73.84% <ø> (+15.38%) ⬆️
platform-wallet 60.40% <ø> (ø)
drive-proof-verifier 48.00% <ø> (ø)
🚀 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 3f253a0 into v3.1-dev Mar 18, 2026
38 checks passed
@QuantumExplorer QuantumExplorer deleted the test/dpp-utils-coverage branch March 18, 2026 19: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.

1 participant