ripple-binary-codec 1.2.0-beta.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/dist/binary.d.ts +6 -6
  2. package/dist/binary.js.map +1 -1
  3. package/dist/coretypes.d.ts +8 -8
  4. package/dist/coretypes.js.map +1 -1
  5. package/dist/enums/index.d.ts +6 -5
  6. package/dist/enums/index.js +3 -2
  7. package/dist/enums/index.js.map +1 -1
  8. package/dist/enums/utils-renumber.js +12 -12
  9. package/dist/enums/utils-renumber.js.map +1 -1
  10. package/dist/hash-prefixes.d.ts +1 -1
  11. package/dist/hash-prefixes.js.map +1 -1
  12. package/dist/hashes.d.ts +3 -3
  13. package/dist/hashes.js +5 -4
  14. package/dist/hashes.js.map +1 -1
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +13 -13
  17. package/dist/index.js.map +1 -1
  18. package/dist/ledger-hashes.d.ts +3 -3
  19. package/dist/ledger-hashes.js +5 -5
  20. package/dist/ledger-hashes.js.map +1 -1
  21. package/dist/quality.d.ts +2 -2
  22. package/dist/quality.js +4 -4
  23. package/dist/quality.js.map +1 -1
  24. package/dist/serdes/binary-parser.d.ts +3 -3
  25. package/dist/serdes/binary-parser.js +10 -10
  26. package/dist/serdes/binary-parser.js.map +1 -1
  27. package/dist/serdes/binary-serializer.d.ts +5 -5
  28. package/dist/serdes/binary-serializer.js +13 -8
  29. package/dist/serdes/binary-serializer.js.map +1 -1
  30. package/dist/shamap.d.ts +3 -3
  31. package/dist/shamap.js +5 -3
  32. package/dist/shamap.js.map +1 -1
  33. package/dist/types/account-id.d.ts +2 -2
  34. package/dist/types/account-id.js +12 -10
  35. package/dist/types/account-id.js.map +1 -1
  36. package/dist/types/amount.d.ts +3 -3
  37. package/dist/types/amount.js +23 -21
  38. package/dist/types/amount.js.map +1 -1
  39. package/dist/types/blob.d.ts +3 -3
  40. package/dist/types/blob.js +6 -4
  41. package/dist/types/blob.js.map +1 -1
  42. package/dist/types/currency.d.ts +2 -2
  43. package/dist/types/currency.js +14 -12
  44. package/dist/types/currency.js.map +1 -1
  45. package/dist/types/hash-128.d.ts +2 -2
  46. package/dist/types/hash-128.js +3 -1
  47. package/dist/types/hash-128.js.map +1 -1
  48. package/dist/types/hash-160.d.ts +2 -2
  49. package/dist/types/hash-160.js +3 -1
  50. package/dist/types/hash-160.js.map +1 -1
  51. package/dist/types/hash-256.d.ts +2 -2
  52. package/dist/types/hash-256.js +3 -1
  53. package/dist/types/hash-256.js.map +1 -1
  54. package/dist/types/hash.d.ts +3 -3
  55. package/dist/types/hash.js +7 -5
  56. package/dist/types/hash.js.map +1 -1
  57. package/dist/types/index.d.ts +15 -15
  58. package/dist/types/index.js +3 -3
  59. package/dist/types/index.js.map +1 -1
  60. package/dist/types/path-set.d.ts +2 -2
  61. package/dist/types/path-set.js +5 -3
  62. package/dist/types/path-set.js.map +1 -1
  63. package/dist/types/serialized-type.d.ts +4 -4
  64. package/dist/types/serialized-type.js +7 -5
  65. package/dist/types/serialized-type.js.map +1 -1
  66. package/dist/types/st-array.d.ts +2 -2
  67. package/dist/types/st-array.js +6 -4
  68. package/dist/types/st-array.js.map +1 -1
  69. package/dist/types/st-object.d.ts +2 -2
  70. package/dist/types/st-object.js +25 -14
  71. package/dist/types/st-object.js.map +1 -1
  72. package/dist/types/uint-16.d.ts +3 -3
  73. package/dist/types/uint-16.js +5 -3
  74. package/dist/types/uint-16.js.map +1 -1
  75. package/dist/types/uint-32.d.ts +3 -3
  76. package/dist/types/uint-32.js +6 -4
  77. package/dist/types/uint-32.js.map +1 -1
  78. package/dist/types/uint-64.d.ts +4 -4
  79. package/dist/types/uint-64.js +12 -10
  80. package/dist/types/uint-64.js.map +1 -1
  81. package/dist/types/uint-8.d.ts +3 -3
  82. package/dist/types/uint-8.js +5 -3
  83. package/dist/types/uint-8.js.map +1 -1
  84. package/dist/types/uint.d.ts +3 -3
  85. package/dist/types/uint.js +4 -2
  86. package/dist/types/uint.js.map +1 -1
  87. package/dist/types/vector-256.d.ts +3 -3
  88. package/dist/types/vector-256.js +7 -5
  89. package/dist/types/vector-256.js.map +1 -1
  90. package/package.json +14 -29
  91. package/test/amount.test.js +29 -29
  92. package/test/binary-json.test.js +24 -26
  93. package/test/binary-parser.test.js +225 -227
  94. package/test/binary-serializer.test.js +194 -169
  95. package/test/fixtures/negative-unl.json +4 -4
  96. package/test/fixtures/nf-token.json +547 -0
  97. package/test/hash.test.js +85 -78
  98. package/test/ledger.test.js +19 -19
  99. package/test/lower-case-hex.test.js +28 -28
  100. package/test/pseudo-transaction.test.js +26 -26
  101. package/test/quality.test.js +13 -13
  102. package/test/shamap.test.js +54 -54
  103. package/test/signing-data-encoding.test.js +79 -79
  104. package/test/tx-encode-decode.test.js +63 -63
  105. package/test/types.test.js +23 -23
  106. package/test/uint.test.js +107 -107
  107. package/test/x-address.test.js +106 -106
  108. package/dist/ShaMap/ShaMap.d.ts +0 -3
  109. package/dist/ShaMap/ShaMap.js +0 -25
  110. package/dist/ShaMap/ShaMap.js.map +0 -1
  111. package/dist/ShaMap/ShaMapInner.d.ts +0 -66
  112. package/dist/ShaMap/ShaMapInner.js +0 -145
  113. package/dist/ShaMap/ShaMapInner.js.map +0 -1
  114. package/dist/ShaMap/ShaMapLeaf.d.ts +0 -42
  115. package/dist/ShaMap/ShaMapLeaf.js +0 -84
  116. package/dist/ShaMap/ShaMapLeaf.js.map +0 -1
  117. package/dist/ShaMap/ShaMapNode.d.ts +0 -13
  118. package/dist/ShaMap/ShaMapNode.js +0 -12
  119. package/dist/ShaMap/ShaMapNode.js.map +0 -1
  120. package/dist/ShaMap/index.d.ts +0 -3
  121. package/dist/ShaMap/index.js +0 -9
  122. package/dist/ShaMap/index.js.map +0 -1
  123. package/dist/enums/Bytes.d.ts +0 -10
  124. package/dist/enums/Bytes.js +0 -30
  125. package/dist/enums/Bytes.js.map +0 -1
  126. package/dist/enums/BytesLookup.d.ts +0 -8
  127. package/dist/enums/BytesLookup.js +0 -29
  128. package/dist/enums/BytesLookup.js.map +0 -1
  129. package/dist/enums/Field.d.ts +0 -3
  130. package/dist/enums/Field.js +0 -9
  131. package/dist/enums/Field.js.map +0 -1
  132. package/dist/enums/FieldInfo.d.ts +0 -7
  133. package/dist/enums/FieldInfo.js +0 -3
  134. package/dist/enums/FieldInfo.js.map +0 -1
  135. package/dist/enums/FieldInstance.d.ts +0 -14
  136. package/dist/enums/FieldInstance.js +0 -3
  137. package/dist/enums/FieldInstance.js.map +0 -1
  138. package/dist/enums/FieldLookup.d.ts +0 -11
  139. package/dist/enums/FieldLookup.js +0 -102
  140. package/dist/enums/FieldLookup.js.map +0 -1
  141. package/dist/serdes/BinaryParser.d.ts +0 -100
  142. package/dist/serdes/BinaryParser.js +0 -200
  143. package/dist/serdes/BinaryParser.js.map +0 -1
  144. package/dist/serdes/BinarySerializer.d.ts +0 -50
  145. package/dist/serdes/BinarySerializer.js +0 -105
  146. package/dist/serdes/BinarySerializer.js.map +0 -1
  147. package/dist/serdes/BytesList.d.ts +0 -28
  148. package/dist/serdes/BytesList.js +0 -48
  149. package/dist/serdes/BytesList.js.map +0 -1
  150. package/dist/types/Comparable.d.ts +0 -18
  151. package/dist/types/Comparable.js +0 -43
  152. package/dist/types/Comparable.js.map +0 -1
  153. package/dist/types/PathSet/Hop.d.ts +0 -41
  154. package/dist/types/PathSet/Hop.js +0 -116
  155. package/dist/types/PathSet/Hop.js.map +0 -1
  156. package/dist/types/PathSet/Path.d.ts +0 -33
  157. package/dist/types/PathSet/Path.js +0 -83
  158. package/dist/types/PathSet/Path.js.map +0 -1
  159. package/dist/types/PathSet/index.d.ts +0 -29
  160. package/dist/types/PathSet/index.js +0 -98
  161. package/dist/types/PathSet/index.js.map +0 -1
  162. package/dist/types/SerializedType.d.ts +0 -47
  163. package/dist/types/SerializedType.js +0 -69
  164. package/dist/types/SerializedType.js.map +0 -1
@@ -1,71 +1,69 @@
1
- /* eslint-disable func-style */
1
+ const { coreTypes } = require('../dist/types')
2
+ const Decimal = require('decimal.js')
2
3
 
3
- const { coreTypes } = require("../dist/types");
4
- const Decimal = require("decimal.js");
4
+ const { encodeAccountID } = require('ripple-address-codec')
5
+ const { binary } = require('../dist/coretypes')
6
+ const { Amount, Hash160 } = coreTypes
7
+ const { makeParser, readJSON } = binary
8
+ const { Field, TransactionType } = require('./../dist/enums')
9
+ const { parseHexOnly, hexOnly, loadFixture } = require('./utils')
10
+ const fixtures = loadFixture('data-driven-tests.json')
11
+ const { BytesList } = require('../dist/serdes/binary-serializer')
12
+ const { Buffer } = require('buffer/')
5
13
 
6
- const { encodeAccountID } = require("ripple-address-codec");
7
- const { binary } = require("../dist/coretypes");
8
- const { Amount, Hash160 } = coreTypes;
9
- const { makeParser, readJSON } = binary;
10
- const { Field, TransactionType } = require("./../dist/enums");
11
- const { parseHexOnly, hexOnly, loadFixture } = require("./utils");
12
- const fixtures = loadFixture("data-driven-tests.json");
13
- const { BytesList } = require("../dist/serdes/binary-serializer");
14
- const { Buffer } = require("buffer/");
15
-
16
- const __ = hexOnly;
14
+ const __ = hexOnly
17
15
  function toJSON(v) {
18
- return v.toJSON ? v.toJSON() : v;
16
+ return v.toJSON ? v.toJSON() : v
19
17
  }
20
18
 
21
19
  function assertEqualAmountJSON(actual, expected) {
22
- expect(typeof actual === typeof expected).toBe(true);
23
- if (typeof actual === "string") {
24
- expect(actual).toEqual(expected);
25
- return;
20
+ expect(typeof actual === typeof expected).toBe(true)
21
+ if (typeof actual === 'string') {
22
+ expect(actual).toEqual(expected)
23
+ return
26
24
  }
27
- expect(actual.currency).toEqual(expected.currency);
28
- expect(actual.issuer).toEqual(expected.issuer);
25
+ expect(actual.currency).toEqual(expected.currency)
26
+ expect(actual.issuer).toEqual(expected.issuer)
29
27
  expect(
30
28
  actual.value === expected.value ||
31
- new Decimal(actual.value).equals(new Decimal(expected.value))
32
- ).toBe(true);
29
+ new Decimal(actual.value).equals(new Decimal(expected.value)),
30
+ ).toBe(true)
33
31
  }
34
32
 
35
33
  function basicApiTests() {
36
- const bytes = parseHexOnly("00,01020304,0506", Uint8Array);
37
- test("can read slices of bytes", () => {
38
- const parser = makeParser(bytes);
39
- expect(parser.bytes instanceof Buffer).toBe(true);
40
- const read1 = parser.read(1);
41
- expect(read1 instanceof Buffer).toBe(true);
42
- expect(read1).toEqual(Buffer.from([0]));
43
- expect(parser.read(4)).toEqual(Buffer.from([1, 2, 3, 4]));
44
- expect(parser.read(2)).toEqual(Buffer.from([5, 6]));
45
- expect(() => parser.read(1)).toThrow();
46
- });
47
- test("can read a Uint32 at full", () => {
48
- const parser = makeParser("FFFFFFFF");
49
- expect(parser.readUInt32()).toEqual(0xffffffff);
50
- });
34
+ const bytes = parseHexOnly('00,01020304,0506', Uint8Array)
35
+ test('can read slices of bytes', () => {
36
+ const parser = makeParser(bytes)
37
+ expect(parser.bytes instanceof Buffer).toBe(true)
38
+ const read1 = parser.read(1)
39
+ expect(read1 instanceof Buffer).toBe(true)
40
+ expect(read1).toEqual(Buffer.from([0]))
41
+ expect(parser.read(4)).toEqual(Buffer.from([1, 2, 3, 4]))
42
+ expect(parser.read(2)).toEqual(Buffer.from([5, 6]))
43
+ expect(() => parser.read(1)).toThrow()
44
+ })
45
+ test('can read a Uint32 at full', () => {
46
+ const parser = makeParser('FFFFFFFF')
47
+ expect(parser.readUInt32()).toEqual(0xffffffff)
48
+ })
51
49
  }
52
50
 
53
51
  function transactionParsingTests() {
54
52
  const transaction = {
55
53
  json: {
56
- Account: "raD5qJMAShLeHZXf9wjUmo6vRK4arj9cF3",
57
- Fee: "10",
54
+ Account: 'raD5qJMAShLeHZXf9wjUmo6vRK4arj9cF3',
55
+ Fee: '10',
58
56
  Flags: 0,
59
57
  Sequence: 103929,
60
58
  SigningPubKey:
61
- "028472865AF4CB32AA285834B57576B7290AA8C31B459047DB27E16F418D6A7166",
59
+ '028472865AF4CB32AA285834B57576B7290AA8C31B459047DB27E16F418D6A7166',
62
60
  TakerGets: {
63
- currency: "ILS",
64
- issuer: "rNPRNzBB92BVpAhhZr4iXDTveCgV5Pofm9",
65
- value: "1694.768",
61
+ currency: 'ILS',
62
+ issuer: 'rNPRNzBB92BVpAhhZr4iXDTveCgV5Pofm9',
63
+ value: '1694.768',
66
64
  },
67
- TakerPays: "98957503520",
68
- TransactionType: "OfferCreate",
65
+ TakerPays: '98957503520',
66
+ TransactionType: 'OfferCreate',
69
67
  TxnSignature: __(`
70
68
  304502202ABE08D5E78D1E74A4C18F2714F64E87B8BD57444AF
71
69
  A5733109EB3C077077520022100DB335EE97386E4C0591CAC02
@@ -80,208 +78,208 @@ function transactionParsingTests() {
80
78
  8BD57444AFA5733109EB3C077077520022100DB335EE97386E4C059
81
79
  1CAC024D50E9230D8F171EEB901B5E5E4BD6D1E0AEF98C811439408
82
80
  A69F0895E62149CFCC006FB89FA7D1E6E5D`),
83
- };
81
+ }
84
82
 
85
- const tx_json = transaction.json;
83
+ const tx_json = transaction.json
86
84
  // These tests are basically development logs
87
85
 
88
- test("can be done with low level apis", () => {
89
- const parser = makeParser(transaction.binary);
86
+ test('can be done with low level apis', () => {
87
+ const parser = makeParser(transaction.binary)
90
88
 
91
- expect(parser.readField()).toEqual(Field.TransactionType);
92
- expect(parser.readUInt16()).toEqual(7);
93
- expect(parser.readField()).toEqual(Field.Flags);
94
- expect(parser.readUInt32()).toEqual(0);
95
- expect(parser.readField()).toEqual(Field.Sequence);
96
- expect(parser.readUInt32()).toEqual(103929);
97
- expect(parser.readField()).toEqual(Field.TakerPays);
98
- parser.read(8);
99
- expect(parser.readField()).toEqual(Field.TakerGets);
89
+ expect(parser.readField()).toEqual(Field.TransactionType)
90
+ expect(parser.readUInt16()).toEqual(7)
91
+ expect(parser.readField()).toEqual(Field.Flags)
92
+ expect(parser.readUInt32()).toEqual(0)
93
+ expect(parser.readField()).toEqual(Field.Sequence)
94
+ expect(parser.readUInt32()).toEqual(103929)
95
+ expect(parser.readField()).toEqual(Field.TakerPays)
96
+ parser.read(8)
97
+ expect(parser.readField()).toEqual(Field.TakerGets)
100
98
  // amount value
101
- expect(parser.read(8)).not.toBe([]);
99
+ expect(parser.read(8)).not.toBe([])
102
100
  // amount currency
103
- expect(Hash160.fromParser(parser)).not.toBe([]);
104
- expect(encodeAccountID(parser.read(20))).toEqual(tx_json.TakerGets.issuer);
105
- expect(parser.readField()).toEqual(Field.Fee);
106
- expect(parser.read(8)).not.toEqual([]);
107
- expect(parser.readField()).toEqual(Field.SigningPubKey);
108
- expect(parser.readVariableLengthLength()).toBe(33);
109
- expect(parser.read(33).toString("hex").toUpperCase()).toEqual(
110
- tx_json.SigningPubKey
111
- );
112
- expect(parser.readField()).toEqual(Field.TxnSignature);
113
- expect(parser.readVariableLength().toString("hex").toUpperCase()).toEqual(
114
- tx_json.TxnSignature
115
- );
116
- expect(parser.readField()).toEqual(Field.Account);
101
+ expect(Hash160.fromParser(parser)).not.toBe([])
102
+ expect(encodeAccountID(parser.read(20))).toEqual(tx_json.TakerGets.issuer)
103
+ expect(parser.readField()).toEqual(Field.Fee)
104
+ expect(parser.read(8)).not.toEqual([])
105
+ expect(parser.readField()).toEqual(Field.SigningPubKey)
106
+ expect(parser.readVariableLengthLength()).toBe(33)
107
+ expect(parser.read(33).toString('hex').toUpperCase()).toEqual(
108
+ tx_json.SigningPubKey,
109
+ )
110
+ expect(parser.readField()).toEqual(Field.TxnSignature)
111
+ expect(parser.readVariableLength().toString('hex').toUpperCase()).toEqual(
112
+ tx_json.TxnSignature,
113
+ )
114
+ expect(parser.readField()).toEqual(Field.Account)
117
115
  expect(encodeAccountID(parser.readVariableLength())).toEqual(
118
- tx_json.Account
119
- );
120
- expect(parser.end()).toBe(true);
121
- });
116
+ tx_json.Account,
117
+ )
118
+ expect(parser.end()).toBe(true)
119
+ })
122
120
 
123
- test("can be done with high level apis", () => {
124
- const parser = makeParser(transaction.binary);
121
+ test('can be done with high level apis', () => {
122
+ const parser = makeParser(transaction.binary)
125
123
  function readField() {
126
- return parser.readFieldAndValue();
124
+ return parser.readFieldAndValue()
127
125
  }
128
126
  {
129
- const [field, value] = readField();
130
- expect(field).toEqual(Field.TransactionType);
131
- expect(value).toEqual(TransactionType.OfferCreate);
127
+ const [field, value] = readField()
128
+ expect(field).toEqual(Field.TransactionType)
129
+ expect(value).toEqual(TransactionType.OfferCreate)
132
130
  }
133
131
  {
134
- const [field, value] = readField();
135
- expect(field).toEqual(Field.Flags);
136
- expect(value.valueOf()).toEqual(0);
132
+ const [field, value] = readField()
133
+ expect(field).toEqual(Field.Flags)
134
+ expect(value.valueOf()).toEqual(0)
137
135
  }
138
136
  {
139
- const [field, value] = readField();
140
- expect(field).toEqual(Field.Sequence);
141
- expect(value.valueOf()).toEqual(103929);
137
+ const [field, value] = readField()
138
+ expect(field).toEqual(Field.Sequence)
139
+ expect(value.valueOf()).toEqual(103929)
142
140
  }
143
141
  {
144
- const [field, value] = readField();
145
- expect(field).toEqual(Field.TakerPays);
146
- expect(value.isNative()).toEqual(true);
147
- expect(value.toJSON()).toEqual("98957503520");
142
+ const [field, value] = readField()
143
+ expect(field).toEqual(Field.TakerPays)
144
+ expect(value.isNative()).toEqual(true)
145
+ expect(value.toJSON()).toEqual('98957503520')
148
146
  }
149
147
  {
150
- const [field, value] = readField();
151
- expect(field).toEqual(Field.TakerGets);
152
- expect(value.isNative()).toEqual(false);
153
- expect(value.toJSON().issuer).toEqual(tx_json.TakerGets.issuer);
148
+ const [field, value] = readField()
149
+ expect(field).toEqual(Field.TakerGets)
150
+ expect(value.isNative()).toEqual(false)
151
+ expect(value.toJSON().issuer).toEqual(tx_json.TakerGets.issuer)
154
152
  }
155
153
  {
156
- const [field, value] = readField();
157
- expect(field).toEqual(Field.Fee);
158
- expect(value.isNative()).toEqual(true);
154
+ const [field, value] = readField()
155
+ expect(field).toEqual(Field.Fee)
156
+ expect(value.isNative()).toEqual(true)
159
157
  }
160
158
  {
161
- const [field, value] = readField();
162
- expect(field).toEqual(Field.SigningPubKey);
163
- expect(value.toJSON()).toEqual(tx_json.SigningPubKey);
159
+ const [field, value] = readField()
160
+ expect(field).toEqual(Field.SigningPubKey)
161
+ expect(value.toJSON()).toEqual(tx_json.SigningPubKey)
164
162
  }
165
163
  {
166
- const [field, value] = readField();
167
- expect(field).toEqual(Field.TxnSignature);
168
- expect(value.toJSON()).toEqual(tx_json.TxnSignature);
164
+ const [field, value] = readField()
165
+ expect(field).toEqual(Field.TxnSignature)
166
+ expect(value.toJSON()).toEqual(tx_json.TxnSignature)
169
167
  }
170
168
  {
171
- const [field, value] = readField();
172
- expect(field).toEqual(Field.Account);
173
- expect(value.toJSON()).toEqual(tx_json.Account);
169
+ const [field, value] = readField()
170
+ expect(field).toEqual(Field.Account)
171
+ expect(value.toJSON()).toEqual(tx_json.Account)
174
172
  }
175
- expect(parser.end()).toBe(true);
176
- });
173
+ expect(parser.end()).toBe(true)
174
+ })
177
175
 
178
- test("can be done with higher level apis", () => {
179
- const parser = makeParser(transaction.binary);
180
- const jsonFromBinary = readJSON(parser);
181
- expect(jsonFromBinary).toEqual(tx_json);
182
- });
176
+ test('can be done with higher level apis', () => {
177
+ const parser = makeParser(transaction.binary)
178
+ const jsonFromBinary = readJSON(parser)
179
+ expect(jsonFromBinary).toEqual(tx_json)
180
+ })
183
181
 
184
- test("readJSON (binary.decode) does not return STObject ", () => {
185
- const parser = makeParser(transaction.binary);
186
- const jsonFromBinary = readJSON(parser);
187
- expect(jsonFromBinary instanceof coreTypes.STObject).toBe(false);
188
- expect(jsonFromBinary instanceof Object).toBe(true);
189
- expect(jsonFromBinary.prototype).toBe(undefined);
190
- });
182
+ test('readJSON (binary.decode) does not return STObject ', () => {
183
+ const parser = makeParser(transaction.binary)
184
+ const jsonFromBinary = readJSON(parser)
185
+ expect(jsonFromBinary instanceof coreTypes.STObject).toBe(false)
186
+ expect(jsonFromBinary instanceof Object).toBe(true)
187
+ expect(jsonFromBinary.prototype).toBe(undefined)
188
+ })
191
189
  }
192
190
 
193
191
  function amountParsingTests() {
194
192
  fixtures.values_tests
195
- .filter((obj) => obj.type === "Amount")
193
+ .filter((obj) => obj.type === 'Amount')
196
194
  .forEach((f, i) => {
197
195
  if (f.error) {
198
- return;
196
+ return
199
197
  }
200
- const parser = makeParser(f.expected_hex);
198
+ const parser = makeParser(f.expected_hex)
201
199
  const testName = `values_tests[${i}] parses ${f.expected_hex.slice(
202
200
  0,
203
- 16
201
+ 16,
204
202
  )}...
205
- as ${JSON.stringify(f.test_json)}`;
203
+ as ${JSON.stringify(f.test_json)}`
206
204
  test(testName, () => {
207
- const value = parser.readType(Amount);
205
+ const value = parser.readType(Amount)
208
206
  // May not actually be in canonical form. The fixtures are to be used
209
207
  // also for json -> binary;
210
- const json = toJSON(value);
211
- assertEqualAmountJSON(json, f.test_json);
208
+ const json = toJSON(value)
209
+ assertEqualAmountJSON(json, f.test_json)
212
210
  if (f.exponent) {
213
- const exponent = new Decimal(json.value);
214
- expect(exponent.e - 15).toEqual(f.exponent);
211
+ const exponent = new Decimal(json.value)
212
+ expect(exponent.e - 15).toEqual(f.exponent)
215
213
  }
216
- });
217
- });
214
+ })
215
+ })
218
216
  }
219
217
 
220
218
  function fieldParsingTests() {
221
219
  fixtures.fields_tests.forEach((f, i) => {
222
- const parser = makeParser(f.expected_hex);
220
+ const parser = makeParser(f.expected_hex)
223
221
  test(`fields[${i}]: parses ${f.expected_hex} as ${f.name}`, () => {
224
- const field = parser.readField();
225
- expect(field.name).toEqual(f.name);
226
- expect(field.type.name).toEqual(f.type_name);
227
- });
228
- });
229
- test("Field throws when type code out of range", () => {
230
- const parser = makeParser("0101");
222
+ const field = parser.readField()
223
+ expect(field.name).toEqual(f.name)
224
+ expect(field.type.name).toEqual(f.type_name)
225
+ })
226
+ })
227
+ test('Field throws when type code out of range', () => {
228
+ const parser = makeParser('0101')
231
229
  expect(() => parser.readField()).toThrow(
232
- new Error("Cannot read FieldOrdinal, type_code out of range")
233
- );
234
- });
235
- test("Field throws when field code out of range", () => {
236
- const parser = makeParser("1001");
230
+ new Error('Cannot read FieldOrdinal, type_code out of range'),
231
+ )
232
+ })
233
+ test('Field throws when field code out of range', () => {
234
+ const parser = makeParser('1001')
237
235
  expect(() => parser.readFieldOrdinal()).toThrowError(
238
- new Error("Cannot read FieldOrdinal, field_code out of range")
239
- );
240
- });
241
- test("Field throws when both type and field code out of range", () => {
242
- const parser = makeParser("000101");
236
+ new Error('Cannot read FieldOrdinal, field_code out of range'),
237
+ )
238
+ })
239
+ test('Field throws when both type and field code out of range', () => {
240
+ const parser = makeParser('000101')
243
241
  expect(() => parser.readFieldOrdinal()).toThrowError(
244
- new Error("Cannot read FieldOrdinal, type_code out of range")
245
- );
246
- });
242
+ new Error('Cannot read FieldOrdinal, type_code out of range'),
243
+ )
244
+ })
247
245
  }
248
246
 
249
247
  function assertRecyclable(json, forField) {
250
- const Type = forField.associatedType;
251
- const recycled = Type.from(json).toJSON();
252
- expect(recycled).toEqual(json);
253
- const sink = new BytesList();
254
- Type.from(recycled).toBytesSink(sink);
255
- const recycledAgain = makeParser(sink.toHex()).readType(Type).toJSON();
256
- expect(recycledAgain).toEqual(json);
248
+ const Type = forField.associatedType
249
+ const recycled = Type.from(json).toJSON()
250
+ expect(recycled).toEqual(json)
251
+ const sink = new BytesList()
252
+ Type.from(recycled).toBytesSink(sink)
253
+ const recycledAgain = makeParser(sink.toHex()).readType(Type).toJSON()
254
+ expect(recycledAgain).toEqual(json)
257
255
  }
258
256
 
259
257
  function nestedObjectTests() {
260
258
  fixtures.whole_objects.forEach((f, i) => {
261
259
  test(`whole_objects[${i}]: can parse blob into
262
260
  ${JSON.stringify(
263
- f.tx_json
261
+ f.tx_json,
264
262
  )}`, /* */ () => {
265
- const parser = makeParser(f.blob_with_no_signing);
266
- let ix = 0;
263
+ const parser = makeParser(f.blob_with_no_signing)
264
+ let ix = 0
267
265
  while (!parser.end()) {
268
- const [field, value] = parser.readFieldAndValue();
269
- const expected = f.fields[ix];
270
- const expectedJSON = expected[1].json;
271
- const expectedField = expected[0];
272
- const actual = toJSON(value);
266
+ const [field, value] = parser.readFieldAndValue()
267
+ const expected = f.fields[ix]
268
+ const expectedJSON = expected[1].json
269
+ const expectedField = expected[0]
270
+ const actual = toJSON(value)
273
271
 
274
272
  try {
275
- expect(actual).toEqual(expectedJSON);
273
+ expect(actual).toEqual(expectedJSON)
276
274
  } catch (e) {
277
- throw new Error(`${e} ${field} a: ${actual} e: ${expectedJSON}`);
275
+ throw new Error(`${e} ${field} a: ${actual} e: ${expectedJSON}`)
278
276
  }
279
- expect(field.name).toEqual(expectedField);
280
- assertRecyclable(actual, field);
281
- ix++;
277
+ expect(field.name).toEqual(expectedField)
278
+ assertRecyclable(actual, field)
279
+ ix++
282
280
  }
283
- });
284
- });
281
+ })
282
+ })
285
283
  }
286
284
 
287
285
  function pathSetBinaryTests() {
@@ -314,85 +312,85 @@ function pathSetBinaryTests() {
314
312
  69E6DCC940CA48D82337AD000000000000000000000000425443000000000057
315
313
  180C769B66D942EE69E6DCC940CA48D82337AD10000000000000000000000000
316
314
  00000000000000003000000000000000000000000055534400000000000A20B3
317
- C85F482532A9578DBB3950B85CA06594D100`
318
- );
315
+ C85F482532A9578DBB3950B85CA06594D100`,
316
+ )
319
317
 
320
318
  const expectedJSON = [
321
319
  [
322
320
  {
323
- account: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
324
- currency: "BTC",
325
- issuer: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
321
+ account: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
322
+ currency: 'BTC',
323
+ issuer: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
326
324
  },
327
325
  {
328
- account: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
329
- currency: "BTC",
330
- issuer: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
326
+ account: 'rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo',
327
+ currency: 'BTC',
328
+ issuer: 'rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo',
331
329
  },
332
330
  {
333
- account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
334
- currency: "BTC",
335
- issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
331
+ account: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
332
+ currency: 'BTC',
333
+ issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
336
334
  },
337
335
  {
338
- currency: "USD",
339
- issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
336
+ currency: 'USD',
337
+ issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
340
338
  },
341
339
  ],
342
340
  [
343
341
  {
344
- account: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
345
- currency: "BTC",
346
- issuer: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
342
+ account: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
343
+ currency: 'BTC',
344
+ issuer: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
347
345
  },
348
346
  {
349
- account: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
350
- currency: "BTC",
351
- issuer: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
347
+ account: 'rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo',
348
+ currency: 'BTC',
349
+ issuer: 'rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo',
352
350
  },
353
351
  {
354
- account: "rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi",
355
- currency: "BTC",
356
- issuer: "rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi",
352
+ account: 'rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi',
353
+ currency: 'BTC',
354
+ issuer: 'rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi',
357
355
  },
358
356
  {
359
- currency: "USD",
360
- issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
357
+ currency: 'USD',
358
+ issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
361
359
  },
362
360
  ],
363
361
  [
364
362
  {
365
- account: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
366
- currency: "BTC",
367
- issuer: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
363
+ account: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
364
+ currency: 'BTC',
365
+ issuer: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
368
366
  },
369
367
  {
370
- account: "r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn",
371
- currency: "BTC",
372
- issuer: "r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn",
368
+ account: 'r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn',
369
+ currency: 'BTC',
370
+ issuer: 'r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn',
373
371
  },
374
- { currency: "XRP" },
372
+ { currency: 'XRP' },
375
373
  {
376
- currency: "USD",
377
- issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
374
+ currency: 'USD',
375
+ issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
378
376
  },
379
377
  ],
380
- ];
378
+ ]
381
379
 
382
- test("works with long paths", () => {
383
- const parser = makeParser(bytes);
384
- const txn = readJSON(parser);
385
- expect(txn.Paths).toEqual(expectedJSON);
380
+ test('works with long paths', () => {
381
+ const parser = makeParser(bytes)
382
+ const txn = readJSON(parser)
383
+ expect(txn.Paths).toEqual(expectedJSON)
386
384
  // TODO: this should go elsewhere
387
- expect(coreTypes.PathSet.from(txn.Paths).toJSON()).toEqual(expectedJSON);
388
- });
385
+ expect(coreTypes.PathSet.from(txn.Paths).toJSON()).toEqual(expectedJSON)
386
+ })
389
387
  }
390
388
 
391
- describe("Binary Parser", function () {
392
- describe("pathSetBinaryTests", () => pathSetBinaryTests());
393
- describe("nestedObjectTests", () => nestedObjectTests());
394
- describe("fieldParsingTests", () => fieldParsingTests());
395
- describe("amountParsingTests", () => amountParsingTests());
396
- describe("transactionParsingTests", () => transactionParsingTests());
397
- describe("basicApiTests", () => basicApiTests());
398
- });
389
+ describe('Binary Parser', function () {
390
+ describe('pathSetBinaryTests', () => pathSetBinaryTests())
391
+ describe('nestedObjectTests', () => nestedObjectTests())
392
+ describe('fieldParsingTests', () => fieldParsingTests())
393
+ describe('amountParsingTests', () => amountParsingTests())
394
+ describe('transactionParsingTests', () => transactionParsingTests())
395
+ describe('basicApiTests', () => basicApiTests())
396
+ })