You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uint.test.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. const { coreTypes } = require('../src/types')
  2. const { UInt8, UInt64 } = coreTypes
  3. const { encode } = require('../src')
  4. const binary =
  5. '11007222000300003700000000000000003800000000000000006280000000000000000000000000000000000000005553440000000000000000000000000000000000000000000000000166D5438D7EA4C680000000000000000000000000005553440000000000AE123A8556F3CF91154711376AFB0F894F832B3D67D5438D7EA4C680000000000000000000000000005553440000000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90F'
  6. const json = {
  7. Balance: {
  8. currency: 'USD',
  9. issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
  10. value: '0',
  11. },
  12. Flags: 196608,
  13. HighLimit: {
  14. currency: 'USD',
  15. issuer: 'rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK',
  16. value: '1000',
  17. },
  18. HighNode: '0',
  19. LedgerEntryType: 'RippleState',
  20. LowLimit: {
  21. currency: 'USD',
  22. issuer: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn',
  23. value: '1000',
  24. },
  25. LowNode: '0',
  26. }
  27. const binaryEntry0 =
  28. '11007222001100002501EC24873700000000000000003800000000000000A35506FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA62D44BF89AC2A40B800000000000000000000000004A50590000000000000000000000000000000000000000000000000166D6C38D7EA4C680000000000000000000000000004A5059000000000047C1258B4B79774B28176324068F759EDE226F686780000000000000000000000000000000000000004A505900000000005BBC0F22F61D9224A110650CFE21CC0C4BE13098'
  29. const jsonEntry0 = {
  30. Balance: {
  31. currency: 'JPY',
  32. issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
  33. value: '0.3369568318',
  34. },
  35. Flags: 1114112,
  36. HighLimit: {
  37. currency: 'JPY',
  38. issuer: 'r94s8px6kSw1uZ1MV98dhSRTvc6VMPoPcN',
  39. value: '0',
  40. },
  41. HighNode: 'a3',
  42. LedgerEntryType: 'RippleState',
  43. LowLimit: {
  44. currency: 'JPY',
  45. issuer: 'rfYQMgj3g3Qp8VLoZNvvU35mEuuJC8nCmY',
  46. value: '1000000000',
  47. },
  48. LowNode: '0',
  49. PreviousTxnID:
  50. '06FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA',
  51. PreviousTxnLgrSeq: 32253063,
  52. index: '000319BAE0A618A7D3BB492F17E98E5D92EA0C6458AFEBED44206B5B4798A840',
  53. }
  54. const binaryEntry1 =
  55. '1100642200000000320000000000000002580CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E7528214BA53D10260FFCC968ACD16BA30F7CEABAD6E5D92011340A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6AE1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F'
  56. const jsonEntry1 = {
  57. Flags: 0,
  58. IndexPrevious: '2',
  59. Indexes: [
  60. 'A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6A',
  61. 'E1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F',
  62. ],
  63. LedgerEntryType: 'DirectoryNode',
  64. Owner: 'rHzDaMNybxQppiE3uWyt2N265KvAKdiRdP',
  65. RootIndex: '0CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E752',
  66. index: '0B4A2E68C111F7E42FAEEE405F7344560C8240840B151D9D04131EB79D080167',
  67. }
  68. const binaryEntry2 =
  69. '1100722200210000250178D1CA37000000000000000038000000000000028355C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D66946280000000000000000000000000000000000000004743420000000000000000000000000000000000000000000000000166D6071AFD498D000000000000000000000000000047434200000000002599D1D255BCA61189CA64C84528F2FCBE4BFC3867800000000000000000000000000000000000000047434200000000006EEBB1D1852CE667876A0B3630861FB6C6AB358E'
  70. const jsonEntry2 = {
  71. Balance: {
  72. currency: 'GCB',
  73. issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
  74. value: '0',
  75. },
  76. Flags: 2162688,
  77. HighLimit: {
  78. currency: 'GCB',
  79. issuer: 'rBfVgTnsdh8ckC19RM8aVGNuMZnpwrMP6n',
  80. value: '0',
  81. },
  82. HighNode: '283',
  83. LedgerEntryType: 'RippleState',
  84. LowLimit: {
  85. currency: 'GCB',
  86. issuer: 'rhRFGCy2RJTA8oxkjjtYTvofPVGqcgvXWj',
  87. value: '2000000',
  88. },
  89. LowNode: '0',
  90. PreviousTxnID:
  91. 'C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D6694',
  92. PreviousTxnLgrSeq: 24695242,
  93. index: '0000041EFD027808D3F78C8352F97E324CB816318E00B977C74ECDDC7CD975B2',
  94. }
  95. test('compareToTests[0]', () => {
  96. expect(UInt8.from(124).compareTo(UInt64.from(124))).toBe(0)
  97. })
  98. test('compareToTest[1]', () => {
  99. expect(UInt64.from(124).compareTo(UInt8.from(124))).toBe(0)
  100. })
  101. test('compareToTest[2]', () => {
  102. expect(UInt64.from(124).compareTo(UInt8.from(123))).toBe(1)
  103. })
  104. test('compareToTest[3]', () => {
  105. expect(UInt8.from(124).compareTo(UInt8.from(13))).toBe(1)
  106. })
  107. test('compareToTest[4]', () => {
  108. expect(UInt8.from(124).compareTo(124)).toBe(0)
  109. })
  110. test('compareToTest[5]', () => {
  111. expect(UInt64.from(124).compareTo(124)).toBe(0)
  112. })
  113. test('compareToTest[6]', () => {
  114. expect(UInt64.from(124).compareTo(123)).toBe(1)
  115. })
  116. test('compareToTest[7]', () => {
  117. expect(UInt8.from(124).compareTo(13)).toBe(1)
  118. })
  119. test('UInt64 from string zero', () => {
  120. expect(UInt64.from('0')).toEqual(UInt64.from(0))
  121. expect(encode(json)).toEqual(binary)
  122. })
  123. test('UInt64 from non 16 length hex', () => {
  124. expect(encode(jsonEntry0)).toEqual(binaryEntry0)
  125. expect(encode(jsonEntry1)).toEqual(binaryEntry1)
  126. expect(encode(jsonEntry2)).toEqual(binaryEntry2)
  127. })
  128. test('valueOfTests', () => {
  129. let val = UInt8.from(1)
  130. val |= 0x2
  131. expect(val).toBe(3)
  132. })