Skip to content

Conversation

@thephez
Copy link
Collaborator

@thephez thephez commented Oct 7, 2025

Issue being fixed or feature implemented

Adds tests to cover more scenarios such as one being addressed by #2794 per discussion in #2791 (comment).

Note: one test case is skipped until the SDK is fixedexpected to fail until the versioning fix in 2794 is merged.

What was done?

Expanded data contract testing including:

  • Add comprehensive platform version compatibility testing for V0/V1 contracts
  • Test V0 contracts across all platform versions (1-10)
  • Test V1 contracts work on v9+ and fail on v1-8
  • Add edge case testing for invalid version numbers
  • Use LATEST_KNOWN_VERSION for future-proof invalid version testing

How Has This Been Tested?

Running tests locally

Breaking Changes

N/A

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

  • Tests
    • Expanded data contract test coverage across platform versions (V0 and V1) with compatibility matrix and boundary checks.
    • Added comprehensive fixture covering documents, tokens, groups, keywords, and metadata.
    • Added cross-version validation, round‑trip JSON integrity, and edge-case/invalid-input tests.
    • Included scenarios for document-only, token-only contracts and memory/stability checks with multiple contracts.

thephez and others added 6 commits October 7, 2025 15:21
- Add comprehensive property validation for V0 and V1 contracts
- Test document schemas, config, and metadata fields
- Add memory management tests with multiple contract instances
- Include JSON round-trip preservation tests
- Add defensive assertions for V1-specific features
- Comment out problematic assertions for WASM layer investigation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…alues

- Add comprehensive platform version compatibility testing for V0/V1 contracts
- Test V0 contracts across all platform versions (1-10)
- Test V1 contracts work on v9+ and fail on v1-8
- Add edge case testing for invalid version numbers
- Replace magic values with dynamic version detection
- Use LATEST_KNOWN_VERSION for future-proof invalid version testing
- Reorganize tests into logical categories with nested describe blocks

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Should pass once the 2794 is merged
Copy link
Collaborator Author

@thephez thephez left a comment

Choose a reason for hiding this comment

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

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

Walkthrough

Adds comprehensive versioned data-contract unit tests covering V0 and V1, platform-version constants and ranges, a compatibility-testing helper, expanded validation/preservation/memory checks, and a new V1 fixture with documents, groups, tokens, and governance rules.

Changes

Cohort / File(s) Change summary
Unit Tests: Data Contract Spec
packages/wasm-sdk/tests/unit/data-contract.spec.mjs
Replaces single fixture import with V0 and V1 fixtures; introduces platform-version constants, compatibility ranges, and a testContractAcrossVersions helper; restructures tests into nested suites for creation, validation, data preservation, memory, and a platform-version compatibility matrix including boundary and invalid-version cases.
Fixtures: V1 Contract
packages/wasm-sdk/tests/unit/fixtures/data-contract-v1-with-docs-tokens-groups.mjs
Adds a new V1 data-contract fixture object containing metadata, config, document schema(s), groups, tokens (distribution, governance/control rules, localization), keywords, description, and exports it as the default fixture for tests.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Runner as Test Runner
  participant Spec as data-contract.spec.mjs
  participant Helper as testContractAcrossVersions
  participant Matrix as Version Matrix Resolver
  participant SDK as WASM SDK (builder/validator)
  participant Assert as Assertions

  Runner->>Spec: run test suites
  Spec->>Helper: request compatibility verification for contract
  Helper->>Matrix: resolve target platform versions (V0..latest, V1 start)
  loop per target version
    Helper->>SDK: build/validate contract for version N
    alt compatible
      SDK-->>Helper: success + normalized contract JSON
      Helper->>Assert: verify properties, IDs, round-trip equality
    else incompatible
      SDK-->>Helper: error/exception
      Helper->>Assert: expect failure
    end
  end
  Note over Spec,SDK: Additional flows: invalid inputs, memory tests with multiple contracts
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I nibble bytes and hop through tests,
V0 tunnels, V1 quests.
Tokens, groups, the schema hums—
Versions checked, the matrix drums.
A rabbit cheers: green lights and rests 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title “test(wasm-sdk): expand data contract test coverage” clearly identifies the affected component and the primary change, succinctly summarizing the pull request’s intent. It uses conventional commit formatting, avoids vague wording, and directly reflects the expanded test coverage for data contracts in the wasm-sdk. A teammate scanning the history would immediately understand the main focus without extraneous detail.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch wasm-sdk-test-contract-expanded

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.

@thephez
Copy link
Collaborator Author

thephez commented Oct 7, 2025

@coderabbitai review

@thephez thephez marked this pull request as ready for review October 7, 2025 20:45
@thephez thephez added this to the v2.1.0 milestone Oct 7, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

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

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: 0

🧹 Nitpick comments (1)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (1)

18-35: Use the contractName label in the test titles (optional).

contractName is currently unused, so the generated test names don’t reveal which fixture regressed. Threading the label into the it titles cleans up the unused parameter and makes failures easier to triage.

-    it(`should work with platform version ${version}`, () => {
+    it(`(${contractName}) should work with platform version ${version}`, () => {
       const contract = sdk.DataContract.fromJSON(contractFixture, version);
@@
-  incompatibleVersions.forEach(version => {
-    it(`should fail with platform version ${version}`, () => {
+  incompatibleVersions.forEach(version => {
+    it(`(${contractName}) should fail with platform version ${version}`, () => {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6f9d9e and 021862e.

📒 Files selected for processing (2)
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs (1 hunks)
  • packages/wasm-sdk/tests/unit/fixtures/data-contract-v1-with-docs-tokens-groups.mjs (1 hunks)
🧰 Additional context used
🪛 Gitleaks (8.28.0)
packages/wasm-sdk/tests/unit/fixtures/data-contract-v1-with-docs-tokens-groups.mjs

[high] 175-175: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Rust packages (wasm-sdk) / Formatting
  • GitHub Check: Rust packages (wasm-sdk) / Unused dependencies
  • GitHub Check: Rust packages (wasm-sdk) / Linting
  • GitHub Check: Rust packages (wasm-sdk) / Tests
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Rust crates security audit

@thephez thephez marked this pull request as draft October 8, 2025 13:20
@thephez thephez requested a review from shumkov October 8, 2025 13:30
Once the SDK is fixed, test can be enabled.
@thephez thephez marked this pull request as ready for review October 15, 2025 14:05
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: 0

🧹 Nitpick comments (4)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (4)

16-21: Consider removing or utilizing the unused parameter.

The contractName parameter is declared but never used in the function body. You could either:

  1. Remove it if it's not needed
  2. Use it to enhance test descriptions: it(`should work with ${contractName} contract on platform version ${version}`, () => {

Apply this diff to remove the unused parameter:

 const testContractAcrossVersions = (
   contractFixture,
-  contractName,
   compatibleVersions,
   incompatibleVersions = [],
 ) => {

Or apply this diff to use it in test descriptions:

   compatibleVersions.forEach((version) => {
-    it(`should work with platform version ${version}`, () => {
+    it(`should work with ${contractName} contract on platform version ${version}`, () => {
       const contract = sdk.DataContract.fromJSON(contractFixture, version);

76-104: Skipped test is acknowledged in PR description.

The skipped V1 test is appropriately marked with a TODO comment indicating it's waiting on PR #2794. The test structure looks comprehensive and ready to be enabled once the fix is merged.

However, consider tracking this TODO with a link to the related PR:

-    // TODO: enable test once an SDK fix to support this is merged
+    // TODO: enable test once PR #2794 is merged (https://github.com/dashpay/platform/pull/2794)
     it.skip('should create a V1 contract from JSON and expose all properties including tokens and groups', async () => {

137-141: Consider a more flexible error assertion.

The highly specific regex pattern could make the test brittle if the error message format changes. Consider matching just the essential parts:

       expect(() => {
         sdk.DataContract.fromJSON(contractFixtureV1, PLATFORM_VERSION_CONTRACT_V0);
-      }).to.throw(/dpp unknown version.*known versions.*\[0\].*received.*1/);
+      }).to.throw(/unknown version/);
     });

185-198: Consider a more flexible error assertion.

The test correctly validates an important business rule (contracts must have at least one document type or token). However, the specific error message pattern could make the test brittle:

       expect(() => {
         sdk.DataContract.fromJSON(contractWithEmptySchemas, PLATFORM_VERSION_CONTRACT_V0);
-      }).to.throw(/must have at least one document type or token defined/);
+      }).to.throw(/at least one document type or token/);
     });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 430be3c and 83b0785.

📒 Files selected for processing (1)
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
packages/wasm-sdk/**

📄 CodeRabbit inference engine (CLAUDE.md)

Keep WASM SDK docs in sync (run generate_docs.py) when updating the WASM SDK

Files:

  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
packages/**/tests/**

📄 CodeRabbit inference engine (AGENTS.md)

Place unit and integration tests alongside each package in packages//tests

Files:

  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
🧬 Code graph analysis (1)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (2)
packages/wasm-sdk/tests/unit/fixtures/data-contract-v1-with-docs-tokens-groups.mjs (1)
  • contract (1-281)
packages/wasm-sdk/tests/unit/fixtures/data-contract-v0-crypto-card-game.mjs (1)
  • contract (1-96)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Rust packages (wasm-sdk) / Tests
  • GitHub Check: Rust packages (wasm-sdk) / Unused dependencies
  • GitHub Check: Rust packages (wasm-sdk) / Linting
  • GitHub Check: Rust packages (wasm-sdk) / Formatting
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Rust crates security audit
🔇 Additional comments (9)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (9)

1-3: LGTM!

The imports are well-organized and appropriate for the expanded test coverage.


5-13: LGTM!

The platform version constants and compatibility ranges are well-organized and self-documenting. Using arrays for version ranges makes the test logic clear and maintainable.


50-73: LGTM!

The V0 contract creation test is comprehensive and thoroughly validates:

  • Contract instantiation
  • Property exposure (id, ownerId, version, config, documentSchemas)
  • JSON round-trip integrity
  • Document schema structure including properties, enums, and indices

Excellent coverage of the V0 contract behavior.


106-133: LGTM!

The edge case tests for contracts with only documents or only tokens are well-designed and validate important scenarios:

  • Line 106-115: Confirms V0 contracts can exist with only document schemas
  • Line 117-133: Confirms V1 contracts can exist with only tokens (no documents)

These tests ensure flexibility in contract composition.


145-183: LGTM!

The validation tests provide excellent coverage of error conditions:

  • Null and empty object inputs
  • Invalid Base58 ID format
  • Negative version numbers
  • Invalid ownerId format

These tests ensure robust error handling for invalid inputs.


201-229: LGTM!

The data preservation tests are critical for ensuring contract integrity through serialization/deserialization cycles. The dual round-trip approach (create → serialize → deserialize → serialize → compare) provides strong validation of data preservation for both V0 and V1 contracts.


232-241: LGTM!

Memory management testing is crucial for WASM bindings where resources must be manually freed. This test validates that multiple contract instances can coexist and be properly cleaned up, preventing memory leaks.


244-286: LGTM!

The Platform Version Compatibility Matrix is exceptionally comprehensive:

  • V0 Compatibility: Tests across all versions 1-10
  • V1 Compatibility: Tests success on v9-10 and failure on v1-8
  • Edge Cases: Validates behavior with zero, negative, and beyond-range versions
  • Boundary Testing: Specifically validates the V9 transition point where V1 support was introduced

This test suite provides excellent coverage of the version compatibility requirements mentioned in the PR objectives. The use of the helper function keeps the tests DRY while maintaining clarity.


1-287: Verify documentation requirements.

The coding guidelines state: "Keep WASM SDK docs in sync (run generate_docs.py) when updating the WASM SDK." Since this PR adds comprehensive test coverage without modifying SDK functionality, documentation updates are likely not required. However, please confirm whether any documentation should be updated to reflect the expanded test coverage.

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: 0

🧹 Nitpick comments (1)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (1)

5-13: Consider calculating LATEST_KNOWN_VERSION from both compatibility ranges.

Currently, LATEST_KNOWN_VERSION is calculated from only V0_COMPATIBLE_VERSIONS. While this works today since V1_COMPATIBLE_VERSIONS is a subset, it could become incorrect if future platform versions are added to V1_COMPATIBLE_VERSIONS but not V0_COMPATIBLE_VERSIONS.

Apply this diff to make the calculation more robust:

-const LATEST_KNOWN_VERSION = Math.max(...V0_COMPATIBLE_VERSIONS);
+const LATEST_KNOWN_VERSION = Math.max(...V0_COMPATIBLE_VERSIONS, ...V1_COMPATIBLE_VERSIONS);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 430be3c and 83b0785.

📒 Files selected for processing (1)
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
packages/wasm-sdk/**

📄 CodeRabbit inference engine (CLAUDE.md)

Keep WASM SDK docs in sync (run generate_docs.py) when updating the WASM SDK

Files:

  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
packages/**/tests/**

📄 CodeRabbit inference engine (AGENTS.md)

Place unit and integration tests alongside each package in packages//tests

Files:

  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs
🧬 Code graph analysis (1)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (2)
packages/wasm-sdk/tests/unit/fixtures/data-contract-v0-crypto-card-game.mjs (1)
  • contract (1-96)
packages/wasm-sdk/tests/unit/fixtures/data-contract-v1-with-docs-tokens-groups.mjs (1)
  • contract (1-281)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (8)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (8)

1-3: LGTM!

The fixture imports correctly bring in both V0 and V1 test contracts, supporting the expanded test coverage described in the PR objectives.


15-42: Excellent helper function for reducing test duplication.

The testContractAcrossVersions helper effectively tests contract compatibility across multiple platform versions, properly handles both success and failure cases, and ensures correct memory cleanup with .free() calls.


49-134: Comprehensive contract creation tests with good edge-case coverage.

The tests thoroughly validate:

  • V0 contract creation with nested property verification
  • V1 contract creation (intentionally skipped until PR #2794 merge, as noted in PR objectives)
  • Contracts with only documents (no tokens)
  • Contracts with only tokens (no documents)

All tests properly manage WASM memory with .free() calls.


136-142: LGTM!

The version compatibility test correctly validates that V1 contracts fail when attempting to use V0 platform versions, with appropriate error message verification.


144-199: Thorough validation test coverage.

The validation tests comprehensively cover:

  • Invalid JSON inputs (null, empty objects, malformed structures)
  • Invalid property values (Base58 IDs, negative versions, invalid ownerIds)
  • Business constraints (requiring at least one document type or token)

201-229: Excellent round-trip data preservation tests.

The tests ensure complete data fidelity through multiple JSON serialization/deserialization cycles for both V0 and V1 contracts, which is critical for contract integrity. Memory management is correct with proper .free() calls.


231-242: LGTM!

The memory management test correctly verifies that multiple WASM contract instances can coexist without interference and are properly freed, which is essential for real-world usage scenarios.


244-286: Comprehensive platform version compatibility testing.

The test suite systematically validates:

  • V0 contracts work across all platform versions (1–10)
  • V1 contracts work from version 9 onwards
  • Invalid version numbers (0, negative, beyond known range) are properly rejected
  • V9 boundary behavior (backward compatibility for V0, first supported version for V1)

The use of LATEST_KNOWN_VERSION in edge-case testing makes the tests future-proof, as highlighted in the PR objectives.

Based on the coding guidelines for packages/wasm-sdk/**, verify whether documentation needs to be updated. The guideline states to "Keep WASM SDK docs in sync (run generate_docs.py) when updating the WASM SDK." Since this PR only updates tests and not the SDK implementation itself, documentation updates may not be required. However, please confirm whether the expanded test coverage warrants any documentation changes.

@thephez
Copy link
Collaborator Author

thephez commented Oct 20, 2025

The one currently failing test case is due to an upstream bug (rs-dapi not returning expected data for GetStatus).

@thephez
Copy link
Collaborator Author

thephez commented Oct 21, 2025

All tests passing now 👍


// Platform version compatibility ranges
const V0_COMPATIBLE_VERSIONS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // V0 works across all versions
const V1_COMPATIBLE_VERSIONS = [9, 10]; // V1 only works from version 9+
Copy link
Member

Choose a reason for hiding this comment

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

I would do a 9+ instead of a 9, 10, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@QuantumExplorer QuantumExplorer merged commit aa3e1cf into v2.1-dev Oct 24, 2025
27 checks passed
@QuantumExplorer QuantumExplorer deleted the wasm-sdk-test-contract-expanded branch October 24, 2025 18:22
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