Skip to content

Conversation

@thephez
Copy link
Collaborator

@thephez thephez commented Oct 27, 2025

Issue being fixed or feature implemented

The WASM SDK data contract test suite used hard-coded version arrays that required manual updates across multiple locations when adding new contract format versions or platform versions. This made the codebase harder to maintain and error-prone.

Fixes #2803 comment.

What was done?

Refactored the data contract test configuration to be fully data-driven and self-expanding:

  • Introduced CONTRACT_FORMAT_VERSIONS config object mapping format versions to their introduction platform version and fixtures
  • Created FORMATS object that auto-generates compatibility arrays, incompatibility arrays, and platform version constants for all defined formats
  • Updated test suite to dynamically iterate over all contract formats instead of hard-coded test blocks
  • Removed redundant backward compatibility constants in favor of direct FORMATS references

Adding a new contract format (e.g., V2) now requires:

  1. Updating PLATFORM_VERSIONS.MAX to the new version
  2. Adding V2: { introduced: X, fixture: contractFixtureV2 } to CONTRACT_FORMAT_VERSIONS
  3. Importing a V2 contract fixture

All compatibility arrays, test suites, and constants are automatically generated.

How Has This Been Tested?

  • Ran existing WASM SDK test suite: all 84 tests passing
  • Verified V0 and V1 contract compatibility tests work correctly across all platform versions
  • Confirmed dynamic test iteration generates proper test suites for both formats
  • Validated that generated arrays match previous hard-coded values

Breaking Changes

None. This is a pure refactoring with no API or behavior 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

  • Tests
    • Replaced hard-coded version constants with dynamic configuration so tests derive per-format compatibility automatically.
    • Introduced an auto-generated compatibility matrix and per-format platform version values used across tests.
    • Test suite now iterates all defined contract formats, using a shared test helper and a generalized "latest known" version, covering creation, validation, round-trip, and memory checks.

Refactor platform version compatibility test configuration to be data-driven and auto-generate test suites. Makes adding new contract format versions easier by centralizing configuration.
…dynamic

Replace hardcoded version arrays with auto-generated compatibility data from CONTRACT_FORMAT_VERSIONS config. Tests now dynamically iterate over all defined formats, eliminating need for manual updates when adding new contract versions.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 27, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Replaces hard-coded platform-version constants in the data-contract unit tests with dynamic PLATFORM_VERSIONS and CONTRACT_FORMAT_VERSIONS, auto-generates a per-format FORMATS compatibility matrix, and updates tests to iterate over formats and use PLATFORM_VERSIONS.MAX for latest-version checks.

Changes

Cohort / File(s) Change Summary
Test Configuration Refactor
packages/wasm-sdk/tests/unit/data-contract.spec.mjs
Replaced static PLATFORM_VERSION_CONTRACT_V0/V1 with dynamic PLATFORM_VERSIONS and CONTRACT_FORMAT_VERSIONS. Introduced auto-generated FORMATS (per-format platformVersion, compatibleVersions, incompatibleVersions), updated tests to iterate over FORMATS, generalized compatibility and round‑trip checks, and set LATEST_KNOWN_VERSION to PLATFORM_VERSIONS.MAX.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify correctness of the FORMATS generation logic and compatibility matrices.
  • Confirm tests still cover previous V0/V1 scenarios and boundary/version-edge cases.
  • Ensure PLATFORM_VERSIONS.MAX usage aligns with other test assumptions.

Possibly related PRs

Suggested reviewers

  • shumkov

Poem

🐰
I hopped through constants, loose and fleet,
Turned hard‑coded stones to a matrix neat,
Formats numbered, versions set free,
Tests now loop with gentle glee,
A rabbit's cheer for tidy harmony.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "refactor: make wasm-sdk contract version test config dynamic" directly and clearly summarizes the primary change in the pull request. The title accurately reflects the core refactoring objective of converting hard-coded platform version constants and test configurations into a dynamic, data-driven system. It is concise, specific, and avoids vague terminology, making it immediately clear to reviewers what the changeset addresses without excessive detail.
Linked Issues Check ✅ Passed The pull request successfully fulfills the coding requirements from linked issue #2803. It establishes a dynamic, self-expanding configuration system via PLATFORM_VERSIONS, CONTRACT_FORMAT_VERSIONS, and an auto-generated FORMATS object, enabling comprehensive V0/V1 contract compatibility testing across platform versions. The refactoring makes it straightforward to test V0 contracts across all versions, ensure V1 contracts succeed on v9+ and fail on v1–8, implement LATEST_KNOWN_VERSION-based edge-case testing, and maintain comprehensive fixture coverage. The PR summary confirms that existing tests pass (84 tests) and compatibility verification was validated, demonstrating that the implementation meets the issue's objectives of expanding data contract test coverage with platform-version compatibility matrix support.

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 27, 2025

@coderabbitai review

@thephez thephez changed the base branch from v2.2-dev to master October 27, 2025 17:24
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 27, 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 (3)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (3)

35-40: Consider removing the redundant platformVersion property.

The platformVersion property is a direct copy of config.introduced, creating unnecessary duplication. Tests could reference FORMATS.V0.introduced directly instead of FORMATS.V0.platformVersion.

If the intent is to provide a more semantic property name for test readability, consider adding a comment explaining this design choice.

Apply this diff to remove the redundancy:

   acc[formatKey] = {
     ...config,
     compatibleVersions,
     incompatibleVersions,
-    platformVersion: config.introduced,
   };

Then update all test references from FORMATS.V0.platformVersion to FORMATS.V0.introduced (and similarly for V1).


28-33: Optional: Simplify incompatible versions generation.

The allVersions array is created solely to filter it for incompatibleVersions. While this is clear and works fine for test configuration, you could simplify it:

-  const allVersions = Array.from(
-    { length: PLATFORM_VERSIONS.MAX - PLATFORM_VERSIONS.MIN + 1 },
-    (_, i) => i + PLATFORM_VERSIONS.MIN
-  );
-
-  const incompatibleVersions = allVersions.filter(v => v < config.introduced);
+  const incompatibleVersions = Array.from(
+    { length: Math.max(0, config.introduced - PLATFORM_VERSIONS.MIN) },
+    (_, i) => i + PLATFORM_VERSIONS.MIN
+  );

6-19: Optional: Consider adding configuration validation.

The configuration system doesn't validate constraints such as:

  • PLATFORM_VERSIONS.MIN < PLATFORM_VERSIONS.MAX
  • Format introduced versions fall within the MIN-MAX range
  • Format introduced versions are unique

While misconfiguration would likely cause obvious test failures, early validation could provide clearer error messages. However, for test configuration, the current approach prioritizing simplicity is acceptable.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f49390f and 4bf18f7.

📒 Files selected for processing (1)
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs (11 hunks)
🔇 Additional comments (2)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (2)

277-287: Excellent refactor to dynamic test iteration!

Replacing hard-coded test blocks with dynamic iteration over FORMATS is a solid improvement. This eliminates duplication and automatically extends test coverage when new format versions are added to the configuration.


83-83: Consistent and correct usage of FORMATS throughout tests.

All test cases correctly use FORMATS.V0.platformVersion and FORMATS.V1.platformVersion instead of hard-coded constants. This ensures tests automatically adapt when platform version configurations change.

Also applies to: 109-109, 140-140, 158-158, 171-171, 179-179, 183-183, 187-187, 197-197, 205-205, 213-213, 228-228, 235-235, 239-239, 249-249, 253-253, 265-266

@thephez thephez marked this pull request as ready for review October 27, 2025 17:42
@thephez thephez added this to the v2.1.x milestone Oct 27, 2025
@thephez
Copy link
Collaborator Author

thephez commented Oct 27, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 27, 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 (2)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (2)

5-54: LGTM! Excellent refactoring to dynamic configuration.

The configuration setup is well-structured and the validation logic is solid. The auto-generated compatibility arrays correctly compute which platform versions support each contract format.

However, one minor observation:

At line 48, the platformVersion field duplicates config.introduced. While this might be intentional for clarity or to match a specific naming convention in tests, consider either:

  • Removing the redundant field and using introduced directly in tests, or
  • Adding a comment explaining why both fields exist

Apply this diff if you'd like to remove the redundancy:

  acc[formatKey] = {
    ...config,
    compatibleVersions,
    incompatibleVersions,
-   platformVersion: config.introduced,
  };

Then update test references from FORMATS.V0.platformVersion to FORMATS.V0.introduced.


314-329: Refactor hard-coded version numbers to use dynamic configuration.

The edge case test "should handle version boundary correctly at V9 transition" uses hard-coded version numbers (9, 8) at lines 316, 321, and 327. For consistency with the dynamic configuration approach throughout the rest of the file, consider using FORMATS.V1.platformVersion and FORMATS.V1.platformVersion - 1.

Apply this diff to align with the dynamic configuration:

      it('should handle version boundary correctly at V9 transition', () => {
        // V0 contract should work in V9 (backward compatibility)
-       const contract = sdk.DataContract.fromJSON(contractFixtureV0, 9);
+       const contract = sdk.DataContract.fromJSON(contractFixtureV0, FORMATS.V1.platformVersion);
        expect(contract.id()).to.equal(contractFixtureV0.id);
        contract.free();

        // V1 contract should work in V9 (first supported version)
-       const contractV1 = sdk.DataContract.fromJSON(contractFixtureV1, 9);
+       const contractV1 = sdk.DataContract.fromJSON(contractFixtureV1, FORMATS.V1.platformVersion);
        expect(contractV1.id()).to.equal(contractFixtureV1.id);
        contractV1.free();

        // V1 contract should fail in V8 (last unsupported version)
        expect(() => {
-         sdk.DataContract.fromJSON(contractFixtureV1, 8);
+         sdk.DataContract.fromJSON(contractFixtureV1, FORMATS.V1.platformVersion - 1);
        }).to.throw(/dpp unknown version/);
      });

Alternatively, if you want to keep the test description more generic, you could rename the test to reference the format dynamically or update the description to use template literals.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4bf18f7 and aa5b754.

📒 Files selected for processing (1)
  • packages/wasm-sdk/tests/unit/data-contract.spec.mjs (11 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
🔇 Additional comments (2)
packages/wasm-sdk/tests/unit/data-contract.spec.mjs (2)

92-283: LGTM! Tests correctly use dynamic configuration.

All test cases have been properly updated to use FORMATS.V0.platformVersion and FORMATS.V1.platformVersion instead of hard-coded constants. The refactoring maintains test coverage while improving maintainability.


285-296: LGTM! Dynamic test generation is well-implemented.

The dynamic iteration over all defined formats is excellent. This achieves the PR objective of making the test suite fully data-driven and self-expanding. Adding a new contract format now only requires updating the CONTRACT_FORMAT_VERSIONS configuration.

The "should handle version boundary correctly at V9 transition" test duplicated coverage already provided by the dynamic compatibility matrix. The matrix already tests V0/V1 contracts at version 9 and V1 failure at version 8 through the auto-generated compatible/incompatible version loops.
@shumkov
Copy link
Collaborator

shumkov commented Oct 30, 2025

Conflicting with #2800

@thephez thephez removed this from the v2.1.x milestone Oct 30, 2025
@thephez thephez marked this pull request as draft October 30, 2025 14:25
@thephez
Copy link
Collaborator Author

thephez commented Oct 30, 2025

Conflicting with #2800

I'll mark this as draft for now to possibly revisit later.

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