diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 52bb3a5094..fe853ab157 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -3337,7 +3337,7 @@ "isSigningField": true, "isVLEncoded": false, "nth": 1, - "type": "Datatype" + "type": "DataType" } ], [ @@ -3719,7 +3719,7 @@ "Blob": 7, "Currency": 26, "Data": 27, - "Datatype": 28, + "DataType": 28, "Done": -1, "Hash128": 4, "Hash160": 17, diff --git a/packages/ripple-binary-codec/src/types/data.ts b/packages/ripple-binary-codec/src/types/data.ts index a1a38cad2f..8cfafb85ac 100644 --- a/packages/ripple-binary-codec/src/types/data.ts +++ b/packages/ripple-binary-codec/src/types/data.ts @@ -65,8 +65,8 @@ type DataValue = * It's encoded as a 2-byte type ID followed by the serialized data. * * Usage: - * Data.from({ type: "AMOUNT", value: "1000000" }) - * Data.from({ type: "UINT64", value: "123456789" }) + * Data.from({ type: "Amount", value: "1000000" }) + * Data.from({ type: "UInt64", value: "123456789" }) * Data.fromParser(parser) */ class Data extends SerializedType { @@ -134,8 +134,8 @@ class Data extends SerializedType { typeof json.value === 'string' ? parseInt(json.value, 10) : typeof json.value === 'number' - ? json.value - : Number(json.value) + ? json.value + : Number(json.value) if ( typeof val !== 'number' || Number.isNaN(val) || @@ -154,8 +154,8 @@ class Data extends SerializedType { typeof json.value === 'string' ? parseInt(json.value, 10) : typeof json.value === 'number' - ? json.value - : Number(json.value) + ? json.value + : Number(json.value) if ( typeof val !== 'number' || Number.isNaN(val) || @@ -174,8 +174,8 @@ class Data extends SerializedType { typeof json.value === 'string' ? parseInt(json.value, 10) : typeof json.value === 'number' - ? json.value - : Number(json.value) + ? json.value + : Number(json.value) dataValue = UInt32.from(val) dataBytes = (dataValue as UInt32).toBytes() break diff --git a/packages/ripple-binary-codec/src/types/dataType.ts b/packages/ripple-binary-codec/src/types/dataType.ts index d01c44ec8a..907d425451 100644 --- a/packages/ripple-binary-codec/src/types/dataType.ts +++ b/packages/ripple-binary-codec/src/types/dataType.ts @@ -23,8 +23,8 @@ interface DataTypeJSON extends JsonObject { * the inner type. * * Usage: - * DataType.from({ type: "AMOUNT" }) - * DataType.from("UINT64") + * DataType.from({ type: "Amount" }) + * DataType.from("UInt64") * DataType.fromParser(parser) */ class DataType extends SerializedType { @@ -64,7 +64,7 @@ class DataType extends SerializedType { * @param value - Can be: * - DataType instance (returns as-is) * - DataTypeJSON object with 'type' field - * - String type name (e.g., "AMOUNT", "UINT64") + * - String type name (e.g., "Amount", "UInt64") * - SerializedTypeID enum value * @returns DataType instance * @throws Error if value type is not supported or type string is unknown @@ -95,7 +95,7 @@ class DataType extends SerializedType { /** * Construct from a type string * - * @param typeStr - Type string like "AMOUNT", "UINT64", etc. + * @param typeStr - Type string like "Amount", "UInt64", etc. * @returns DataType instance * @throws Error if type string is not recognized */ diff --git a/packages/ripple-binary-codec/src/types/serialized-type.ts b/packages/ripple-binary-codec/src/types/serialized-type.ts index ef25cfaadc..61befbb0a5 100644 --- a/packages/ripple-binary-codec/src/types/serialized-type.ts +++ b/packages/ripple-binary-codec/src/types/serialized-type.ts @@ -2,6 +2,7 @@ import { BytesList } from '../serdes/binary-serializer' import { BinaryParser } from '../serdes/binary-parser' import { XrplDefinitionsBase } from '../enums' import { bytesToHex } from '@transia/isomorphic/utils' +import definitions from '../enums/definitions.json' /** * Enum for SerializedTypeID values used in XRPL @@ -41,111 +42,28 @@ export enum SerializedTypeID { } /** - * Map of type strings to SerializedTypeID values + * Maps built dynamically from definitions.json TYPES. + * This ensures type string names (e.g. "Hash256", "Hash128") stay in sync + * with the canonical definitions rather than using hardcoded uppercase variants. */ -export const TYPE_STRING_TO_ID: Record = { - NOTPRESENT: SerializedTypeID.STI_NOTPRESENT, - UINT16: SerializedTypeID.STI_UINT16, - UINT32: SerializedTypeID.STI_UINT32, - UINT64: SerializedTypeID.STI_UINT64, - UINT128: SerializedTypeID.STI_UINT128, - UINT256: SerializedTypeID.STI_UINT256, - AMOUNT: SerializedTypeID.STI_AMOUNT, - VL: SerializedTypeID.STI_VL, - ACCOUNT: SerializedTypeID.STI_ACCOUNT, - NUMBER: SerializedTypeID.STI_NUMBER, - INT32: SerializedTypeID.STI_INT32, - INT64: SerializedTypeID.STI_INT64, - OBJECT: SerializedTypeID.STI_OBJECT, - ARRAY: SerializedTypeID.STI_ARRAY, +// Map of type name strings to SerializedTypeID values +export const TYPE_STRING_TO_ID: Record = {} - UINT8: SerializedTypeID.STI_UINT8, - UINT160: SerializedTypeID.STI_UINT160, - PATHSET: SerializedTypeID.STI_PATHSET, - VECTOR256: SerializedTypeID.STI_VECTOR256, - UINT96: SerializedTypeID.STI_UINT96, - UINT192: SerializedTypeID.STI_UINT192, - UINT384: SerializedTypeID.STI_UINT384, - UINT512: SerializedTypeID.STI_UINT512, - ISSUE: SerializedTypeID.STI_ISSUE, - XCHAIN_BRIDGE: SerializedTypeID.STI_XCHAIN_BRIDGE, - CURRENCY: SerializedTypeID.STI_CURRENCY, - DATA: SerializedTypeID.STI_DATA, - DATATYPE: SerializedTypeID.STI_DATATYPE, - JSON: SerializedTypeID.STI_JSON, -} - -/** - * Map of type strings to SerializedTypeID values - */ -export const TYPE_NUMBER_TO_ID: Record = { - 0: SerializedTypeID.STI_NOTPRESENT, - 1: SerializedTypeID.STI_UINT16, - 2: SerializedTypeID.STI_UINT32, - 3: SerializedTypeID.STI_UINT64, - 4: SerializedTypeID.STI_UINT128, - 5: SerializedTypeID.STI_UINT256, - 6: SerializedTypeID.STI_AMOUNT, - 7: SerializedTypeID.STI_VL, - 8: SerializedTypeID.STI_ACCOUNT, - 9: SerializedTypeID.STI_NUMBER, - 10: SerializedTypeID.STI_INT32, - 11: SerializedTypeID.STI_INT64, - - 14: SerializedTypeID.STI_OBJECT, - 15: SerializedTypeID.STI_ARRAY, +// Map of numeric type codes to SerializedTypeID values +export const TYPE_NUMBER_TO_ID: Record = {} - 16: SerializedTypeID.STI_UINT8, - 17: SerializedTypeID.STI_UINT160, - 18: SerializedTypeID.STI_PATHSET, - 19: SerializedTypeID.STI_VECTOR256, - 20: SerializedTypeID.STI_UINT96, - 21: SerializedTypeID.STI_UINT192, - 22: SerializedTypeID.STI_UINT384, - 23: SerializedTypeID.STI_UINT512, - 24: SerializedTypeID.STI_ISSUE, - 25: SerializedTypeID.STI_XCHAIN_BRIDGE, - 26: SerializedTypeID.STI_CURRENCY, - 27: SerializedTypeID.STI_DATA, - 28: SerializedTypeID.STI_DATATYPE, - 29: SerializedTypeID.STI_JSON, -} +// Map of SerializedTypeID values to type name strings +export const TYPE_ID_TO_STRING: Record = {} -/** - * Map of SerializedTypeID values to type strings - */ -export const TYPE_ID_TO_STRING: Record = { - [SerializedTypeID.STI_NOTPRESENT]: '', - [SerializedTypeID.STI_UINT16]: 'UINT16', - [SerializedTypeID.STI_UINT32]: 'UINT32', - [SerializedTypeID.STI_UINT64]: 'UINT64', - [SerializedTypeID.STI_UINT128]: 'UINT128', - [SerializedTypeID.STI_UINT256]: 'UINT256', - [SerializedTypeID.STI_AMOUNT]: 'AMOUNT', - [SerializedTypeID.STI_VL]: 'VL', - [SerializedTypeID.STI_ACCOUNT]: 'ACCOUNT', - [SerializedTypeID.STI_NUMBER]: 'NUMBER', - [SerializedTypeID.STI_INT32]: 'INT32', - [SerializedTypeID.STI_INT64]: 'INT64', - - [SerializedTypeID.STI_OBJECT]: 'OBJECT', - [SerializedTypeID.STI_ARRAY]: 'ARRAY', - - [SerializedTypeID.STI_UINT8]: 'UINT8', - [SerializedTypeID.STI_UINT160]: 'UINT160', - [SerializedTypeID.STI_PATHSET]: 'PATHSET', - [SerializedTypeID.STI_VECTOR256]: 'VECTOR256', - [SerializedTypeID.STI_UINT96]: 'UINT96', - [SerializedTypeID.STI_UINT192]: 'UINT192', - [SerializedTypeID.STI_UINT384]: 'UINT384', - [SerializedTypeID.STI_UINT512]: 'UINT512', - [SerializedTypeID.STI_ISSUE]: 'ISSUE', - [SerializedTypeID.STI_XCHAIN_BRIDGE]: 'XCHAIN_BRIDGE', - [SerializedTypeID.STI_CURRENCY]: 'CURRENCY', - [SerializedTypeID.STI_DATA]: 'DATA', - [SerializedTypeID.STI_DATATYPE]: 'DATATYPE', - [SerializedTypeID.STI_JSON]: 'JSON', +// Populate all three maps from definitions.json TYPES +for (const [name, id] of Object.entries(definitions.TYPES)) { + if (id >= 0) { + const typeId = id as SerializedTypeID + TYPE_STRING_TO_ID[name] = typeId + TYPE_NUMBER_TO_ID[id] = typeId + TYPE_ID_TO_STRING[typeId] = name + } } type JSON = string | number | boolean | null | undefined | JSON[] | JsonObject diff --git a/packages/ripple-binary-codec/test/fixtures/contract-call-tx.json b/packages/ripple-binary-codec/test/fixtures/contract-call-tx.json index 0213c80409..16a8634a9a 100644 --- a/packages/ripple-binary-codec/test/fixtures/contract-call-tx.json +++ b/packages/ripple-binary-codec/test/fixtures/contract-call-tx.json @@ -9,7 +9,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "UINT8", + "type": "UInt8", "value": 255 } } @@ -18,7 +18,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "UINT16", + "type": "UInt16", "value": 65535 } } @@ -27,7 +27,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "UINT32", + "type": "UInt32", "value": 4294967295 } } @@ -36,7 +36,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "UINT64", + "type": "UInt64", "value": "7FFFFFFFFFFFFFFF" } } @@ -45,7 +45,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "UINT128", + "type": "Hash128", "value": "00000000000000000000000000000001" } } @@ -54,7 +54,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "UINT160", + "type": "Hash160", "value": "0000000000000000000000000000000000000001" } } @@ -63,7 +63,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "UINT192", + "type": "Hash192", "value": "000000000000000000000000000000000000000000000001" } } @@ -72,7 +72,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "UINT256", + "type": "Hash256", "value": "D955DAC2E77519F05AD151A5D3C99FC8125FB39D58FF9F106F1ACA4491902C25" } } @@ -81,7 +81,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "VL", + "type": "Blob", "value": "DEADBEEF" } } @@ -90,7 +90,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "ACCOUNT", + "type": "AccountID", "value": "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn" } } @@ -99,7 +99,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "AMOUNT", + "type": "Amount", "value": "1000000" } } @@ -108,7 +108,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "AMOUNT", + "type": "Amount", "value": { "currency": "USD", "issuer": "rExKpRKXNz25UAjbckCRtQsJFcSfjL9Er3", @@ -121,7 +121,7 @@ "Parameter": { "ParameterFlag": 0, "ParameterValue": { - "type": "NUMBER", + "type": "Number", "value": "1.2" } } diff --git a/packages/ripple-binary-codec/test/st-data.test.ts b/packages/ripple-binary-codec/test/st-data.test.ts index 7719fe3182..865c4fbc5f 100644 --- a/packages/ripple-binary-codec/test/st-data.test.ts +++ b/packages/ripple-binary-codec/test/st-data.test.ts @@ -5,197 +5,197 @@ import { coreTypes } from '../src/types' const { Data } = coreTypes describe('Data Type with all STTypes', () => { - describe('UINT8', () => { - it('should encode and decode UINT8', () => { - const data = Data.from({ type: 'UINT8', value: 255 }) + describe('UInt8', () => { + it('should encode and decode UInt8', () => { + const data = Data.from({ type: 'UInt8', value: 255 }) const hex = data.toHex() - expect(hex).toBe('0010FF') // 0010 = type ID for UINT8, FF = 255 + expect(hex).toBe('0010FF') // 0010 = type ID for UInt8, FF = 255 const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'UINT8', value: 255 }) + expect(parsed.toJSON()).toEqual({ type: 'UInt8', value: 255 }) }) - it('should handle UINT8 zero', () => { - const data = Data.from({ type: 'UINT8', value: 0 }) + it('should handle UInt8 zero', () => { + const data = Data.from({ type: 'UInt8', value: 0 }) expect(data.toHex()).toBe('001000') - expect(data.toJSON()).toEqual({ type: 'UINT8', value: 0 }) + expect(data.toJSON()).toEqual({ type: 'UInt8', value: 0 }) }) - it('should handle UINT8 from string', () => { - const data = Data.from({ type: 'UINT8', value: '128' }) + it('should handle UInt8 from string', () => { + const data = Data.from({ type: 'UInt8', value: '128' }) expect(data.toHex()).toBe('001080') - expect(data.toJSON()).toEqual({ type: 'UINT8', value: 128 }) + expect(data.toJSON()).toEqual({ type: 'UInt8', value: 128 }) }) }) - describe('UINT16', () => { - it('should encode and decode UINT16', () => { - const data = Data.from({ type: 'UINT16', value: 65535 }) + describe('UInt16', () => { + it('should encode and decode UInt16', () => { + const data = Data.from({ type: 'UInt16', value: 65535 }) const hex = data.toHex() - expect(hex).toBe('0001FFFF') // 0001 = type ID for UINT16, FFFF = 65535 + expect(hex).toBe('0001FFFF') // 0001 = type ID for UInt16, FFFF = 65535 const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'UINT16', value: 65535 }) + expect(parsed.toJSON()).toEqual({ type: 'UInt16', value: 65535 }) }) - it('should handle UINT16 zero', () => { - const data = Data.from({ type: 'UINT16', value: 0 }) + it('should handle UInt16 zero', () => { + const data = Data.from({ type: 'UInt16', value: 0 }) expect(data.toHex()).toBe('00010000') }) }) - describe('UINT32', () => { - it('should encode and decode UINT32', () => { - const data = Data.from({ type: 'UINT32', value: 4294967295 }) + describe('UInt32', () => { + it('should encode and decode UInt32', () => { + const data = Data.from({ type: 'UInt32', value: 4294967295 }) const hex = data.toHex() - expect(hex).toBe('0002FFFFFFFF') // 0002 = type ID for UINT32 + expect(hex).toBe('0002FFFFFFFF') // 0002 = type ID for UInt32 const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'UINT32', value: 4294967295 }) + expect(parsed.toJSON()).toEqual({ type: 'UInt32', value: 4294967295 }) }) }) - describe('UINT64', () => { - it('should encode and decode UINT64', () => { - const data = Data.from({ type: 'UINT64', value: '7fffffffffffffff' }) + describe('UInt64', () => { + it('should encode and decode UInt64', () => { + const data = Data.from({ type: 'UInt64', value: '7fffffffffffffff' }) const hex = data.toHex() - expect(hex).toBe('00037FFFFFFFFFFFFFFF') // 0003 = type ID for UINT64 + expect(hex).toBe('00037FFFFFFFFFFFFFFF') // 0003 = type ID for UInt64 const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) expect(parsed.toJSON()).toEqual({ - type: 'UINT64', + type: 'UInt64', value: '7FFFFFFFFFFFFFFF', }) }) - // it('should handle UINT64 as number string', () => { - // const data = Data.from({ type: 'UINT64', value: '123456789' }) + // it('should handle UInt64 as number string', () => { + // const data = Data.from({ type: 'UInt64', value: '123456789' }) // const parser = new BinaryParser(data.toHex()) // const parsed = Data.fromParser(parser) // expect(parsed.getValue().toJSON()).toBe('123456789') // }) }) - describe('UINT128 (Hash128)', () => { - it('should encode and decode UINT128', () => { + describe('Hash128', () => { + it('should encode and decode Hash128', () => { const value = '00000000000000000000000000000001' - const data = Data.from({ type: 'UINT128', value }) + const data = Data.from({ type: 'Hash128', value }) const hex = data.toHex() - expect(hex).toBe('0004' + value) // 0004 = type ID for UINT128 + expect(hex).toBe('0004' + value) // 0004 = type ID for Hash128 const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) expect(parsed.toJSON()).toEqual({ - type: 'UINT128', + type: 'Hash128', value: value.toUpperCase(), }) }) }) - describe('UINT160 (Hash160)', () => { - it('should encode and decode UINT160', () => { + describe('Hash160', () => { + it('should encode and decode Hash160', () => { const value = '0000000000000000000000000000000000000001' - const data = Data.from({ type: 'UINT160', value }) + const data = Data.from({ type: 'Hash160', value }) const hex = data.toHex() - expect(hex).toBe('0011' + value) // 0011 = type ID for UINT160 + expect(hex).toBe('0011' + value) // 0011 = type ID for Hash160 const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) expect(parsed.toJSON()).toEqual({ - type: 'UINT160', + type: 'Hash160', value: value.toUpperCase(), }) }) }) - describe('UINT192 (Hash192)', () => { - it('should encode and decode UINT192', () => { + describe('Hash192', () => { + it('should encode and decode Hash192', () => { const value = '000000000000000000000000000000000000000000000001' - const data = Data.from({ type: 'UINT192', value }) + const data = Data.from({ type: 'Hash192', value }) const hex = data.toHex() - expect(hex).toBe('0015' + value) // 0015 = type ID for UINT192 + expect(hex).toBe('0015' + value) // 0015 = type ID for Hash192 const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) expect(parsed.toJSON()).toEqual({ - type: 'UINT192', + type: 'Hash192', value: value.toUpperCase(), }) }) }) - describe('UINT256 (Hash256)', () => { - it('should encode and decode UINT256', () => { + describe('Hash256', () => { + it('should encode and decode Hash256', () => { const value = 'D955DAC2E77519F05AD151A5D3C99FC8125FB39D58FF9F106F1ACA4491902C25' - const data = Data.from({ type: 'UINT256', value }) + const data = Data.from({ type: 'Hash256', value }) const hex = data.toHex() - expect(hex).toBe('0005' + value) // 0005 = type ID for UINT256 + expect(hex).toBe('0005' + value) // 0005 = type ID for Hash256 const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'UINT256', value }) + expect(parsed.toJSON()).toEqual({ type: 'Hash256', value }) }) }) - describe('VL (Variable Length Blob)', () => { - it('should encode and decode VL with hex string', () => { + describe('Blob (Variable Length)', () => { + it('should encode and decode Blob with hex string', () => { const value = 'DEADBEEF' - const data = Data.from({ type: 'VL', value }) + const data = Data.from({ type: 'Blob', value }) const hex = data.toHex() - // VL encoding: type ID (0007) + length prefix (04 for 4 bytes) + data + // Blob encoding: type ID (0007) + length prefix (04 for 4 bytes) + data expect(hex).toBe('000704DEADBEEF') const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'VL', value }) + expect(parsed.toJSON()).toEqual({ type: 'Blob', value }) }) - it('should handle empty VL', () => { - const data = Data.from({ type: 'VL', value: '' }) + it('should handle empty Blob', () => { + const data = Data.from({ type: 'Blob', value: '' }) const hex = data.toHex() expect(hex).toBe('000700') // 00 = length 0 const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'VL', value: '' }) + expect(parsed.toJSON()).toEqual({ type: 'Blob', value: '' }) }) - it('should handle longer VL data', () => { + it('should handle longer Blob data', () => { const value = 'DEADBEEFCAFE' + '00'.repeat(100) // Long hex string - const data = Data.from({ type: 'VL', value }) + const data = Data.from({ type: 'Blob', value }) const parser = new BinaryParser(data.toHex()) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'VL', value }) + expect(parsed.toJSON()).toEqual({ type: 'Blob', value }) }) }) - describe('ACCOUNT', () => { - it('should encode and decode ACCOUNT', () => { + describe('AccountID', () => { + it('should encode and decode AccountID', () => { const value = 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn' - const data = Data.from({ type: 'ACCOUNT', value }) + const data = Data.from({ type: 'AccountID', value }) const hex = data.toHex() - // ACCOUNT encoding: type ID (0008) + (14) + 20 bytes of account ID + // AccountID encoding: type ID (0008) + (14) + 20 bytes of account ID expect(hex.substring(0, 4)).toBe('0008') expect(hex.length).toBe(6 + 40) // 2 bytes type + 1 byte length + 20 bytes account const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'ACCOUNT', value }) + expect(parsed.toJSON()).toEqual({ type: 'AccountID', value }) }) it('should handle different account format', () => { const value = 'rExKpRKXNz25UAjbckCRtQsJFcSfjL9Er3' - const data = Data.from({ type: 'ACCOUNT', value }) + const data = Data.from({ type: 'AccountID', value }) const parser = new BinaryParser(data.toHex()) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'ACCOUNT', value }) + expect(parsed.toJSON()).toEqual({ type: 'AccountID', value }) }) }) @@ -283,51 +283,51 @@ describe('Data Type with all STTypes', () => { // }) // }) - describe('NUMBER (STNumber)', () => { - it('should encode and decode positive decimal NUMBER', () => { + describe('Number (STNumber)', () => { + it('should encode and decode positive decimal Number', () => { const value = '1.2' - const data = Data.from({ type: 'NUMBER', value }) + const data = Data.from({ type: 'Number', value }) const hex = data.toHex() - // NUMBER encoding: type ID (0009) + serialized number + // Number encoding: type ID (0009) + serialized number expect(hex.substring(0, 4)).toBe('0009') const parser = new BinaryParser(hex) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'NUMBER', value }) + expect(parsed.toJSON()).toEqual({ type: 'Number', value }) }) - it('should handle integer NUMBER', () => { + it('should handle integer Number', () => { const value = '123456789' - const data = Data.from({ type: 'NUMBER', value }) + const data = Data.from({ type: 'Number', value }) const parser = new BinaryParser(data.toHex()) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'NUMBER', value }) + expect(parsed.toJSON()).toEqual({ type: 'Number', value }) }) - it('should handle negative NUMBER', () => { + it('should handle negative Number', () => { const value = '-987.654' - const data = Data.from({ type: 'NUMBER', value }) + const data = Data.from({ type: 'Number', value }) const parser = new BinaryParser(data.toHex()) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'NUMBER', value }) + expect(parsed.toJSON()).toEqual({ type: 'Number', value }) }) - it('should handle zero NUMBER', () => { + it('should handle zero Number', () => { const value = '0' - const data = Data.from({ type: 'NUMBER', value }) + const data = Data.from({ type: 'Number', value }) const parser = new BinaryParser(data.toHex()) const parsed = Data.fromParser(parser) - expect(parsed.toJSON()).toEqual({ type: 'NUMBER', value }) + expect(parsed.toJSON()).toEqual({ type: 'Number', value }) }) - it('should handle scientific notation NUMBER', () => { + it('should handle scientific notation Number', () => { const value = '1.23e5' - const data = Data.from({ type: 'NUMBER', value }) + const data = Data.from({ type: 'Number', value }) const parser = new BinaryParser(data.toHex()) const parsed = Data.fromParser(parser) // STNumber normalizes scientific notation to decimal - expect(parsed.toJSON()).toEqual({ type: 'NUMBER', value: '123000' }) + expect(parsed.toJSON()).toEqual({ type: 'Number', value: '123000' }) }) }) diff --git a/packages/ripple-binary-codec/tools/generateDefinitions.js b/packages/ripple-binary-codec/tools/generateDefinitions.js index 5f970f694b..21330a0af0 100644 --- a/packages/ripple-binary-codec/tools/generateDefinitions.js +++ b/packages/ripple-binary-codec/tools/generateDefinitions.js @@ -104,6 +104,7 @@ async function main() { VL: 'Blob', DIR_NODE: 'DirectoryNode', PAYCHAN: 'PayChannel', + DATATYPE: 'DataType', } if (nonstandardRenames[inp] != null) return nonstandardRenames[inp]