readBuffer.spec.js 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const Helpers = require('../../gramjs/Helpers')
  2. describe('readBufferFromBigInt 8 bytes function', () => {
  3. test('it should return 0x20a13b25e1726bfc', () => {
  4. const input = BigInt('-257986242325798624')
  5. const output = Buffer.from('20a13b25e1726bfc', 'hex')
  6. expect(Helpers.readBufferFromBigInt(input, 8, true, true)).toEqual(output)
  7. })
  8. test('it should return 0xe05ec4da1e8d9403', () => {
  9. const input = BigInt('257986242325798624')
  10. const output = Buffer.from('e05ec4da1e8d9403', 'hex')
  11. expect(Helpers.readBufferFromBigInt(input, 8, true, false)).toEqual(output)
  12. })
  13. test('it should return 0xfc6b72e1253ba120', () => {
  14. const input = BigInt('-257986242325798624')
  15. const output = Buffer.from('fc6b72e1253ba120', 'hex')
  16. expect(Helpers.readBufferFromBigInt(input, 8, false, true)).toEqual(output)
  17. })
  18. test('it should return 0x03948d1edac45ee0', () => {
  19. const input = BigInt('257986242325798624')
  20. const output = Buffer.from('03948d1edac45ee0', 'hex')
  21. expect(Helpers.readBufferFromBigInt(input, 8, false, false)).toEqual(output)
  22. })
  23. })
  24. describe('readBufferFromBigInt 16 bytes function', () => {
  25. test('it should return 0x8416c07962dac053b4346df39e5d97ec', () => {
  26. const input = BigInt('-25798624232579862436622316998984984956')
  27. const output = Buffer.from('8416c07962dac053b4346df39e5d97ec', 'hex')
  28. expect(Helpers.readBufferFromBigInt(input, 16, true, true)).toEqual(output)
  29. })
  30. test('it should return 0x7ce93f869d253fac4bcb920c61a26813', () => {
  31. const input = BigInt('25798624232579862436622316998984984956')
  32. const output = Buffer.from('7ce93f869d253fac4bcb920c61a26813', 'hex')
  33. expect(Helpers.readBufferFromBigInt(input, 16, true, false)).toEqual(output)
  34. })
  35. test('it should return 0xec975d9ef36d34b453c0da6279c01684', () => {
  36. const input = BigInt('-25798624232579862436622316998984984956')
  37. const output = Buffer.from('ec975d9ef36d34b453c0da6279c01684', 'hex')
  38. expect(Helpers.readBufferFromBigInt(input, 16, false, true)).toEqual(output)
  39. })
  40. test('it should return 0x1368a2610c92cb4bac3f259d863fe97c', () => {
  41. const input = BigInt('25798624232579862436622316998984984956')
  42. const output = Buffer.from('1368a2610c92cb4bac3f259d863fe97c', 'hex')
  43. expect(Helpers.readBufferFromBigInt(input, 16, false, false)).toEqual(output)
  44. })
  45. })
  46. describe('readBufferFromBigInt 32 bytes function', () => {
  47. test('it should return 0x7f113f5e2096936ec90cc4c73cc7bd3c96d20c115bf9ceb05c34232c037ff6c6', () => {
  48. const input = BigInt('-25798624232579862436622316998984984912345482145214526587420145210501554564737')
  49. const output = Buffer.from('7f113f5e2096936ec90cc4c73cc7bd3c96d20c115bf9ceb05c34232c037ff6c6', 'hex')
  50. expect(Helpers.readBufferFromBigInt(input, 32, true, true)).toEqual(output)
  51. })
  52. test('it should return 0x81eec0a1df696c9136f33b38c33842c3692df3eea406314fa3cbdcd3fc800939', () => {
  53. const input = BigInt('25798624232579862436622316998984984912345482145214526587420145210501554564737')
  54. const output = Buffer.from('81eec0a1df696c9136f33b38c33842c3692df3eea406314fa3cbdcd3fc800939', 'hex')
  55. expect(Helpers.readBufferFromBigInt(input, 32, true, false)).toEqual(output)
  56. })
  57. test('it should return 0xc6f67f032c23345cb0cef95b110cd2963cbdc73cc7c40cc96e9396205e3f117f', () => {
  58. const input = BigInt('-25798624232579862436622316998984984912345482145214526587420145210501554564737')
  59. const output = Buffer.from('c6f67f032c23345cb0cef95b110cd2963cbdc73cc7c40cc96e9396205e3f117f', 'hex')
  60. expect(Helpers.readBufferFromBigInt(input, 32, false, true)).toEqual(output)
  61. })
  62. test('it should return 0x390980fcd3dccba34f3106a4eef32d69c34238c3383bf336916c69dfa1c0ee81', () => {
  63. const input = BigInt('25798624232579862436622316998984984912345482145214526587420145210501554564737')
  64. const output = Buffer.from('390980fcd3dccba34f3106a4eef32d69c34238c3383bf336916c69dfa1c0ee81', 'hex')
  65. expect(Helpers.readBufferFromBigInt(input, 32, false, false)).toEqual(output)
  66. })
  67. })