Skip to content

WASM SDK: Inconsistent use of JsValue::UNDEFINED vs JsValue::NULL in proof responses #3029

@thephez

Description

@thephez

Description

Some *WithProof query methods use JsValue::UNDEFINED when there's no data to return, while others correctly use JsValue::NULL. When JsValue::UNDEFINED is used, the data property is omitted entirely from the JSON response (standard JS behavior - undefined values are not serialized).

Current behavior (inconsistent queries):

{
  "metadata": { ... },
  "proof": { ... }
}

Expected behavior (all queries should match this):

{
  "data": null,
  "metadata": { ... },
  "proof": { ... }
}

Affected Methods (using JsValue::UNDEFINED - incorrect)

File Line Method
address.rs 107 getPlatformAddressWithProof
address.rs 152, 202 getPlatformAddressesWithProof (per-address in map)
group.rs 945 getGroupMembersWithProof
token.rs 847 getTokenContractInfoWithProof
token.rs 893 getTokenPerpetualDistributionLastClaimWithProof
system.rs 967 getTotalCreditsInPlatformWithProof
system.rs 1004 getPrefundedSpecializedBalanceWithProof

Already Correct (using JsValue::NULL)

These methods already handle this correctly and can serve as reference:

  • identity.rs:354 - getIdentityWithProof
  • identity.rs:594 - getIdentityNonceWithProof
  • identity.rs:667 - getIdentityContractNonceWithProof
  • identity.rs:1041 - getIdentityBalanceWithProof
  • identity.rs:1089 - getIdentitiesBalancesWithProof
  • identity.rs:1126 - getIdentityBalanceAndRevisionWithProof
  • identity.rs:1168 - getIdentityByPublicKeyHashWithProof
  • document.rs:348, 383 - document queries
  • token.rs:659 - getTokenTotalSupplyWithProof

Suggested Fix

Change .unwrap_or(JsValue::UNDEFINED) to .unwrap_or(JsValue::NULL) in the affected locations.

Example in system.rs:1004:

// Before
.unwrap_or(JsValue::UNDEFINED)

// After
.unwrap_or(JsValue::NULL)

Impact

Consumers of the SDK cannot reliably check for "no data" vs "malformed response" when the data property is missing entirely. This was discovered via evo-sdk-website e2e tests which validate that all proof responses have { data, metadata, proof } structure.

Related to #2986

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions