feat(listener): add event payload version handling (#784) - #818
Open
Jessepriase wants to merge 2 commits into
Open
Jessepriase wants to merge 2 commits into
Jessepriase wants to merge 2 commits into
Conversation
Introduce version-aware event payload parsing so future contract event
schema changes can be handled without breaking existing integrations.
Changes
-------
- event-utils.ts: add CURRENT_EVENT_VERSION, SUPPORTED_EVENT_VERSIONS,
EventVersionParseResult, parseEventVersion(), validateEventVersion()
- notification-fixture-builder.ts: add StellarEventBuilder.withPayloadVersion()
- event-utils.test.ts: 31 new tests covering version parsing and validation
- __mocks__/@stellar/stellar-sdk.ts: re-export real xdr and scValToNative
so ScVal fixture helpers work correctly in all tests
Details
-------
parseEventVersion() extracts payload_version from:
- ScvMap payloads (NotificationScheduled contract event shape)
- Bare integer ScVals (ScvU32/ScvU64)
- Returns found=false for pre-versioned events (backward compatible)
- Catches XDR decode failures gracefully without throwing
validateEventVersion() wraps the parser result into EventValidationResult:
- No version field -> valid (backward compatibility preserved)
- Version in SUPPORTED_EVENT_VERSIONS -> valid
- Unknown/future version -> valid=false with actionable reason including
the unsupported version number and the list of supported versions
- Malformed version value -> valid=false with descriptive reason
StellarEventBuilder.withPayloadVersion(version) sets event.value to an
ScvMap with a payload_version key, matching the on-chain NotificationScheduled
event shape for realistic test fixtures.
The @stellar/stellar-sdk mock fix re-exports xdr and scValToNative from the
real installed package. The prior mock wiped out the entire SDK namespace,
making xdr.ScVal undefined in every test that constructed ScVal fixtures —
a pre-existing breakage now resolved.
Acceptance criteria met
-----------------------
- Supported versions are parsed correctly: version 1 accepted from both
ScvMap and bare ScvU32 payloads
- Unsupported versions generate actionable errors: reason includes the
rejected version number and the supported versions list
- Existing event formats remain supported: all pre-versioned (no version
field) payloads continue to be accepted unchanged
|
@Jessepriase Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce version-aware event payload parsing so future contract event schema changes can be handled without breaking existing integrations.
Changes
Details
parseEventVersion() extracts payload_version from:
validateEventVersion() wraps the parser result into EventValidationResult:
StellarEventBuilder.withPayloadVersion(version) sets event.value to an ScvMap with a payload_version key, matching the on-chain NotificationScheduled event shape for realistic test fixtures.
The @stellar/stellar-sdk mock fix re-exports xdr and scValToNative from the real installed package. The prior mock wiped out the entire SDK namespace, making xdr.ScVal undefined in every test that constructed ScVal fixtures — a pre-existing breakage now resolved.
Acceptance criteria met
Overview
Related Issue
Closes #
Changes
Verification
How to Test
Checklist
maincargo fmt --allrun (if Rust changes)npm run lintpasses (if TypeScript changes)closes Add Event Payload Version Handling #784