lower-case-hex.test.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const { encode, decode } = require('../dist')
  2. let str =
  3. '1100612200000000240000000125000068652D0000000055B6632D6376A2D9319F20A1C6DCCB486432D1E4A79951229D4C3DE2946F51D56662400009184E72A00081140DD319918CD5AE792BF7EC80D63B0F01B4573BBC'
  4. let lower = str.toLowerCase()
  5. let bin =
  6. '1100612200000000240000000125000000082D00000000550735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E56240000002540BE400811479927BAFFD3D04A26096C0C97B1B0D45B01AD3C0'
  7. let json = {
  8. OwnerCount: 0,
  9. Account: 'rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK',
  10. PreviousTxnLgrSeq: 8,
  11. LedgerEntryType: 'AccountRoot',
  12. PreviousTxnID:
  13. '0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5'.toLowerCase(),
  14. Flags: 0,
  15. Sequence: 1,
  16. Balance: '10000000000',
  17. }
  18. let jsonUpper = {
  19. OwnerCount: 0,
  20. Account: 'rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK',
  21. PreviousTxnLgrSeq: 8,
  22. LedgerEntryType: 'AccountRoot',
  23. PreviousTxnID:
  24. '0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5',
  25. Flags: 0,
  26. Sequence: 1,
  27. Balance: '10000000000',
  28. }
  29. describe('Lowercase hex test', () => {
  30. test('Correctly decodes', () => {
  31. expect(decode(lower)).toEqual(decode(str))
  32. })
  33. test('Re-encodes to uppercase hex', () => {
  34. expect(encode(decode(lower))).toEqual(str)
  35. })
  36. test('Encode when hex field lowercase', () => {
  37. expect(encode(json)).toBe(bin)
  38. })
  39. test('Re-decodes to uppercase hex', () => {
  40. expect(decode(encode(json))).toEqual(jsonUpper)
  41. })
  42. })