Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

binary-json.test.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const fixtures = require('./fixtures/codec-fixtures.json')
  2. const { decode, encode, decodeLedgerData } = require('../src')
  3. function json(object) {
  4. return JSON.stringify(object)
  5. }
  6. function truncateForDisplay(longStr) {
  7. return `${longStr.slice(0, 10)} ... ${longStr.slice(-10)}`
  8. }
  9. describe('ripple-binary-codec', function () {
  10. function makeSuite(name, entries) {
  11. describe(name, function () {
  12. entries.forEach((t, testN) => {
  13. test(`${name}[${testN}] can encode ${truncateForDisplay(
  14. json(t.json),
  15. )} to ${truncateForDisplay(t.binary)}`, () => {
  16. expect(encode(t.json)).toEqual(t.binary)
  17. })
  18. test(`${name}[${testN}] can decode ${truncateForDisplay(
  19. t.binary,
  20. )} to ${truncateForDisplay(json(t.json))}`, () => {
  21. const decoded = decode(t.binary)
  22. expect(decoded).toEqual(t.json)
  23. })
  24. })
  25. })
  26. }
  27. makeSuite('transactions', fixtures.transactions)
  28. makeSuite('accountState', fixtures.accountState)
  29. describe('ledgerData', function () {
  30. if (fixtures.ledgerData) {
  31. fixtures.ledgerData.forEach((t, testN) => {
  32. test(`ledgerData[${testN}] can decode ${t.binary} to ${json(
  33. t.json,
  34. )}`, () => {
  35. const decoded = decodeLedgerData(t.binary)
  36. expect(t.json).toEqual(decoded)
  37. })
  38. })
  39. }
  40. })
  41. })