Skip to content

Commit a991376

Browse files
committed
fix: add conditional check for PermissionValue definition (#3018)
* add conditional check for PermissionValue * update HISTORY * remove release date * add unit test
1 parent 096da68 commit a991376

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

packages/ripple-binary-codec/HISTORY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
### Added
66
* Support for `Single Asset Vault` (XLS-65)
77

8+
### Fixed
9+
* Adds conditional check for `PermissionValue` so custom definitions (based on previous v2.x versions) don't break.
10+
811
## 2.4.0 (2025-6-09)
912

1013
### Added

packages/ripple-binary-codec/src/enums/xrpl-definitions-base.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ class XrplDefinitionsBase {
129129
this.field['TransactionType'].associatedType = this.transactionType
130130
this.field['TransactionResult'].associatedType = this.transactionResult
131131
this.field['LedgerEntryType'].associatedType = this.ledgerEntryType
132-
this.field['PermissionValue'].associatedType = this.delegatablePermissions
132+
if (this.field['PermissionValue']) {
133+
this.field['PermissionValue'].associatedType = this.delegatablePermissions
134+
}
133135
}
134136

135137
public getAssociatedTypes(): Record<string, typeof SerializedType> {

packages/ripple-binary-codec/test/definitions.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,33 @@ describe('encode and decode using new types as a parameter', function () {
157157
const decoded = decode(encoded, newDefs)
158158
expect(decoded).toEqual(tx)
159159
})
160+
161+
it('removing PermissionValue does not break encoding/decoding', function () {
162+
// Make a deep copy of definitions
163+
const definitions = JSON.parse(JSON.stringify(normalDefinitionsJson))
164+
165+
const originalFieldsLength = definitions.FIELDS.length
166+
167+
// Remove PermissionValue from definitions
168+
if (definitions.FIELDS) {
169+
definitions.FIELDS = definitions.FIELDS.filter(
170+
(fieldTuple: [string, object]) => fieldTuple[0] !== 'PermissionValue',
171+
)
172+
}
173+
174+
// Verify it was deleted
175+
const expectedFieldsLength = originalFieldsLength - 1
176+
expect(definitions.FIELDS.length).toBe(expectedFieldsLength)
177+
178+
// Create new custom definitions
179+
const customDefs = new XrplDefinitions(definitions)
180+
181+
const tx = { ...txJson }
182+
183+
// It should encode and decode normally, even with PermissionValue missing
184+
const encoded = encode(tx, customDefs)
185+
const decoded = decode(encoded, customDefs)
186+
187+
expect(decoded).toEqual(tx)
188+
})
160189
})

0 commit comments

Comments
 (0)