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
package/test/hash.test.js CHANGED
@@ -1,87 +1,94 @@
1
- const { coreTypes } = require("../dist/types");
2
- const { Hash160, Hash256, AccountID, Currency } = coreTypes;
3
- const { Buffer } = require("buffer/");
1
+ const { coreTypes } = require('../dist/types')
2
+ const { Hash160, Hash256, AccountID, Currency } = coreTypes
3
+ const { Buffer } = require('buffer/')
4
4
 
5
- describe("Hash160", function () {
6
- test("has a static width member", function () {
7
- expect(Hash160.width).toBe(20);
8
- });
9
- test("inherited by subclasses", function () {
10
- expect(AccountID.width).toBe(20);
11
- expect(Currency.width).toBe(20);
12
- });
13
- test("can be compared against another", function () {
14
- const h1 = Hash160.from("1000000000000000000000000000000000000000");
15
- const h2 = Hash160.from("2000000000000000000000000000000000000000");
16
- const h3 = Hash160.from("0000000000000000000000000000000000000003");
17
- expect(h1.lt(h2)).toBe(true);
18
- expect(h3.lt(h2)).toBe(true);
19
- });
20
- test("throws when constructed from invalid hash length", () => {
5
+ describe('Hash160', function () {
6
+ test('has a static width member', function () {
7
+ expect(Hash160.width).toBe(20)
8
+ })
9
+ test('inherited by subclasses', function () {
10
+ expect(AccountID.width).toBe(20)
11
+ expect(Currency.width).toBe(20)
12
+ })
13
+ test('can be compared against another', function () {
14
+ const h1 = Hash160.from('1000000000000000000000000000000000000000')
15
+ const h2 = Hash160.from('2000000000000000000000000000000000000000')
16
+ const h3 = Hash160.from('0000000000000000000000000000000000000003')
17
+ expect(h1.lt(h2)).toBe(true)
18
+ expect(h3.lt(h2)).toBe(true)
19
+ })
20
+ test('throws when constructed from invalid hash length', () => {
21
21
  expect(() =>
22
- Hash160.from("10000000000000000000000000000000000000")
23
- ).toThrow("Invalid Hash length 19");
22
+ Hash160.from('10000000000000000000000000000000000000'),
23
+ ).toThrow('Invalid Hash length 19')
24
24
  expect(() =>
25
- Hash160.from("100000000000000000000000000000000000000000")
26
- ).toThrow("Invalid Hash length 21");
27
- });
28
- });
25
+ Hash160.from('100000000000000000000000000000000000000000'),
26
+ ).toThrow('Invalid Hash length 21')
27
+ })
28
+ })
29
29
 
30
- describe("Hash256", function () {
31
- test("has a static width member", function () {
32
- expect(Hash256.width).toBe(32);
33
- });
34
- test("has a ZERO_256 member", function () {
30
+ describe('Hash256', function () {
31
+ test('has a static width member', function () {
32
+ expect(Hash256.width).toBe(32)
33
+ })
34
+ test('has a ZERO_256 member', function () {
35
35
  expect(Hash256.ZERO_256.toJSON()).toBe(
36
- "0000000000000000000000000000000000000000000000000000000000000000"
37
- );
38
- });
39
- test("supports getting the nibblet values at given positions", function () {
36
+ '0000000000000000000000000000000000000000000000000000000000000000',
37
+ )
38
+ })
39
+ test('supports getting the nibblet values at given positions', function () {
40
40
  const h = Hash256.from(
41
- "1359BD0000000000000000000000000000000000000000000000000000000000"
42
- );
43
- expect(h.nibblet(0)).toBe(0x1);
44
- expect(h.nibblet(1)).toBe(0x3);
45
- expect(h.nibblet(2)).toBe(0x5);
46
- expect(h.nibblet(3)).toBe(0x9);
47
- expect(h.nibblet(4)).toBe(0x0b);
48
- expect(h.nibblet(5)).toBe(0xd);
49
- });
50
- });
41
+ '1359BD0000000000000000000000000000000000000000000000000000000000',
42
+ )
43
+ expect(h.nibblet(0)).toBe(0x1)
44
+ expect(h.nibblet(1)).toBe(0x3)
45
+ expect(h.nibblet(2)).toBe(0x5)
46
+ expect(h.nibblet(3)).toBe(0x9)
47
+ expect(h.nibblet(4)).toBe(0x0b)
48
+ expect(h.nibblet(5)).toBe(0xd)
49
+ })
50
+ })
51
51
 
52
- describe("Currency", function () {
53
- test("Will throw an error for dodgy XRP ", function () {
52
+ describe('Currency', function () {
53
+ test('Will throw an error for dodgy XRP ', function () {
54
54
  expect(() =>
55
- Currency.from("0000000000000000000000005852500000000000")
56
- ).toThrow();
57
- });
58
- test("Currency with lowercase letters decode to hex", () => {
59
- expect(Currency.from("xRp").toJSON()).toBe(
60
- "0000000000000000000000007852700000000000"
61
- );
62
- });
63
- test("Currency codes with symbols decode to hex", () => {
64
- expect(Currency.from("x|p").toJSON()).toBe(
65
- "000000000000000000000000787C700000000000"
66
- );
67
- });
68
- test("Currency codes with uppercase and 0-9 decode to ISO codes", () => {
69
- expect(Currency.from("X8P").toJSON()).toBe("X8P");
70
- expect(Currency.from("USD").toJSON()).toBe("USD");
71
- });
72
- test("can be constructed from a Buffer", function () {
73
- const xrp = new Currency(Buffer.alloc(20));
74
- expect(xrp.iso()).toBe("XRP");
75
- });
76
- test("Can handle non-standard currency codes", () => {
77
- const currency = "015841551A748AD2C1F76FF6ECB0CCCD00000000";
78
- expect(Currency.from(currency).toJSON()).toBe(currency);
79
- });
80
- test("throws on invalid reprs", function () {
81
- expect(() => Currency.from(Buffer.alloc(19))).toThrow();
82
- expect(() => Currency.from(1)).toThrow();
55
+ Currency.from('0000000000000000000000005852500000000000'),
56
+ ).toThrow()
57
+ })
58
+ test('Currency with lowercase letters decode to hex', () => {
59
+ expect(Currency.from('xRp').toJSON()).toBe(
60
+ '0000000000000000000000007852700000000000',
61
+ )
62
+ })
63
+ test('Currency codes with symbols decode to hex', () => {
64
+ expect(Currency.from('x|p').toJSON()).toBe(
65
+ '000000000000000000000000787C700000000000',
66
+ )
67
+ })
68
+ test('Currency codes with uppercase and 0-9 decode to ISO codes', () => {
69
+ expect(Currency.from('X8P').toJSON()).toBe('X8P')
70
+ expect(Currency.from('USD').toJSON()).toBe('USD')
71
+ })
72
+
73
+ test('can be constructed from a Buffer', function () {
74
+ const xrp = new Currency(Buffer.alloc(20))
75
+ expect(xrp.iso()).toBe('XRP')
76
+ })
77
+ test('Can handle non-standard currency codes', () => {
78
+ const currency = '015841551A748AD2C1F76FF6ECB0CCCD00000000'
79
+ expect(Currency.from(currency).toJSON()).toBe(currency)
80
+ })
81
+
82
+ test('Can handle other non-standard currency codes', () => {
83
+ const currency = '0000000000414C6F676F30330000000000000000'
84
+ expect(Currency.from(currency).toJSON()).toBe(currency)
85
+ })
86
+
87
+ test('throws on invalid reprs', function () {
88
+ expect(() => Currency.from(Buffer.alloc(19))).toThrow()
89
+ expect(() => Currency.from(1)).toThrow()
83
90
  expect(() =>
84
- Currency.from("00000000000000000000000000000000000000m")
85
- ).toThrow();
86
- });
87
- });
91
+ Currency.from('00000000000000000000000000000000000000m'),
92
+ ).toThrow()
93
+ })
94
+ })
@@ -1,29 +1,29 @@
1
- const { loadFixture } = require("./utils");
1
+ const { loadFixture } = require('./utils')
2
2
  const {
3
3
  transactionTreeHash,
4
4
  ledgerHash,
5
5
  accountStateHash,
6
- } = require("../dist/ledger-hashes");
6
+ } = require('../dist/ledger-hashes')
7
7
 
8
- describe("Ledger Hashes", function () {
8
+ describe('Ledger Hashes', function () {
9
9
  function testFactory(ledgerFixture) {
10
10
  describe(`can calculate hashes for ${ledgerFixture}`, function () {
11
- const ledger = loadFixture(ledgerFixture);
12
- test("computes correct account state hash", function () {
11
+ const ledger = loadFixture(ledgerFixture)
12
+ test('computes correct account state hash', function () {
13
13
  expect(accountStateHash(ledger.accountState).toHex()).toBe(
14
- ledger.account_hash
15
- );
16
- });
17
- test("computes correct transaction tree hash", function () {
14
+ ledger.account_hash,
15
+ )
16
+ })
17
+ test('computes correct transaction tree hash', function () {
18
18
  expect(transactionTreeHash(ledger.transactions).toHex()).toBe(
19
- ledger.transaction_hash
20
- );
21
- });
22
- test("computes correct ledger header hash", function () {
23
- expect(ledgerHash(ledger).toHex()).toBe(ledger.hash);
24
- });
25
- });
19
+ ledger.transaction_hash,
20
+ )
21
+ })
22
+ test('computes correct ledger header hash', function () {
23
+ expect(ledgerHash(ledger).toHex()).toBe(ledger.hash)
24
+ })
25
+ })
26
26
  }
27
- testFactory("ledger-full-40000.json");
28
- testFactory("ledger-full-38129.json");
29
- });
27
+ testFactory('ledger-full-40000.json')
28
+ testFactory('ledger-full-38129.json')
29
+ })
@@ -1,46 +1,46 @@
1
- const { encode, decode } = require("../dist");
1
+ const { encode, decode } = require('../dist')
2
2
 
3
3
  let str =
4
- "1100612200000000240000000125000068652D0000000055B6632D6376A2D9319F20A1C6DCCB486432D1E4A79951229D4C3DE2946F51D56662400009184E72A00081140DD319918CD5AE792BF7EC80D63B0F01B4573BBC";
5
- let lower = str.toLowerCase();
4
+ '1100612200000000240000000125000068652D0000000055B6632D6376A2D9319F20A1C6DCCB486432D1E4A79951229D4C3DE2946F51D56662400009184E72A00081140DD319918CD5AE792BF7EC80D63B0F01B4573BBC'
5
+ let lower = str.toLowerCase()
6
6
 
7
7
  let bin =
8
- "1100612200000000240000000125000000082D00000000550735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E56240000002540BE400811479927BAFFD3D04A26096C0C97B1B0D45B01AD3C0";
8
+ '1100612200000000240000000125000000082D00000000550735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E56240000002540BE400811479927BAFFD3D04A26096C0C97B1B0D45B01AD3C0'
9
9
  let json = {
10
10
  OwnerCount: 0,
11
- Account: "rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK",
11
+ Account: 'rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK',
12
12
  PreviousTxnLgrSeq: 8,
13
- LedgerEntryType: "AccountRoot",
13
+ LedgerEntryType: 'AccountRoot',
14
14
  PreviousTxnID:
15
- "0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5".toLowerCase(),
15
+ '0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5'.toLowerCase(),
16
16
  Flags: 0,
17
17
  Sequence: 1,
18
- Balance: "10000000000",
19
- };
18
+ Balance: '10000000000',
19
+ }
20
20
 
21
21
  let jsonUpper = {
22
22
  OwnerCount: 0,
23
- Account: "rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK",
23
+ Account: 'rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK',
24
24
  PreviousTxnLgrSeq: 8,
25
- LedgerEntryType: "AccountRoot",
25
+ LedgerEntryType: 'AccountRoot',
26
26
  PreviousTxnID:
27
- "0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5",
27
+ '0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5',
28
28
  Flags: 0,
29
29
  Sequence: 1,
30
- Balance: "10000000000",
31
- };
30
+ Balance: '10000000000',
31
+ }
32
32
 
33
- describe("Lowercase hex test", () => {
34
- test("Correctly decodes", () => {
35
- expect(decode(lower)).toEqual(decode(str));
36
- });
37
- test("Re-encodes to uppercase hex", () => {
38
- expect(encode(decode(lower))).toEqual(str);
39
- });
40
- test("Encode when hex field lowercase", () => {
41
- expect(encode(json)).toBe(bin);
42
- });
43
- test("Re-decodes to uppercase hex", () => {
44
- expect(decode(encode(json))).toEqual(jsonUpper);
45
- });
46
- });
33
+ describe('Lowercase hex test', () => {
34
+ test('Correctly decodes', () => {
35
+ expect(decode(lower)).toEqual(decode(str))
36
+ })
37
+ test('Re-encodes to uppercase hex', () => {
38
+ expect(encode(decode(lower))).toEqual(str)
39
+ })
40
+ test('Encode when hex field lowercase', () => {
41
+ expect(encode(json)).toBe(bin)
42
+ })
43
+ test('Re-decodes to uppercase hex', () => {
44
+ expect(decode(encode(json))).toEqual(jsonUpper)
45
+ })
46
+ })
@@ -1,38 +1,38 @@
1
- const { encode, decode } = require("../dist");
1
+ const { encode, decode } = require('../dist')
2
2
 
3
3
  let json = {
4
- Account: "rrrrrrrrrrrrrrrrrrrrrhoLvTp",
4
+ Account: 'rrrrrrrrrrrrrrrrrrrrrhoLvTp',
5
5
  Sequence: 0,
6
- Fee: "0",
7
- SigningPubKey: "",
8
- Signature: "",
9
- };
6
+ Fee: '0',
7
+ SigningPubKey: '',
8
+ Signature: '',
9
+ }
10
10
 
11
11
  let json_blank_acct = {
12
- Account: "",
12
+ Account: '',
13
13
  Sequence: 0,
14
- Fee: "0",
15
- SigningPubKey: "",
16
- Signature: "",
17
- };
14
+ Fee: '0',
15
+ SigningPubKey: '',
16
+ Signature: '',
17
+ }
18
18
 
19
19
  let binary =
20
- "24000000006840000000000000007300760081140000000000000000000000000000000000000000";
20
+ '24000000006840000000000000007300760081140000000000000000000000000000000000000000'
21
21
 
22
- describe("Can encode Pseudo Transactions", () => {
23
- test("Correctly encodes Pseudo Transaciton", () => {
24
- expect(encode(json)).toEqual(binary);
25
- });
22
+ describe('Can encode Pseudo Transactions', () => {
23
+ test('Correctly encodes Pseudo Transaciton', () => {
24
+ expect(encode(json)).toEqual(binary)
25
+ })
26
26
 
27
- test("Can decode account objects", () => {
28
- expect(decode(encode(json))).toEqual(json);
29
- });
27
+ test('Can decode account objects', () => {
28
+ expect(decode(encode(json))).toEqual(json)
29
+ })
30
30
 
31
- test("Blank AccountID is ACCOUNT_ZERO", () => {
32
- expect(encode(json_blank_acct)).toEqual(binary);
33
- });
31
+ test('Blank AccountID is ACCOUNT_ZERO', () => {
32
+ expect(encode(json_blank_acct)).toEqual(binary)
33
+ })
34
34
 
35
- test("Decodes Blank AccountID", () => {
36
- expect(decode(encode(json_blank_acct))).toEqual(json);
37
- });
38
- });
35
+ test('Decodes Blank AccountID', () => {
36
+ expect(decode(encode(json_blank_acct))).toEqual(json)
37
+ })
38
+ })
@@ -1,15 +1,15 @@
1
- const { quality } = require("../dist/coretypes");
1
+ const { quality } = require('../dist/coretypes')
2
2
 
3
- describe("Quality encode/decode", function () {
3
+ describe('Quality encode/decode', function () {
4
4
  const bookDirectory =
5
- "4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0";
6
- const expectedQuality = "195796912.5171664";
7
- test("can decode", function () {
8
- const decimal = quality.decode(bookDirectory);
9
- expect(decimal.toString()).toBe(expectedQuality);
10
- });
11
- test("can encode", function () {
12
- const bytes = quality.encode(expectedQuality);
13
- expect(bytes.toString("hex").toUpperCase()).toBe(bookDirectory.slice(-16));
14
- });
15
- });
5
+ '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0'
6
+ const expectedQuality = '195796912.5171664'
7
+ test('can decode', function () {
8
+ const decimal = quality.decode(bookDirectory)
9
+ expect(decimal.toString()).toBe(expectedQuality)
10
+ })
11
+ test('can encode', function () {
12
+ const bytes = quality.encode(expectedQuality)
13
+ expect(bytes.toString('hex').toUpperCase()).toBe(bookDirectory.slice(-16))
14
+ })
15
+ })
@@ -1,89 +1,89 @@
1
- const { ShaMap } = require("../dist/shamap.js");
2
- const { binary, HashPrefix } = require("../dist/coretypes");
3
- const { coreTypes } = require("../dist/types");
4
- const { loadFixture } = require("./utils");
5
- const { Buffer } = require("buffer/");
1
+ const { ShaMap } = require('../dist/shamap.js')
2
+ const { binary, HashPrefix } = require('../dist/coretypes')
3
+ const { coreTypes } = require('../dist/types')
4
+ const { loadFixture } = require('./utils')
5
+ const { Buffer } = require('buffer/')
6
6
 
7
7
  function now() {
8
- return Number(Date.now()) / 1000;
8
+ return Number(Date.now()) / 1000
9
9
  }
10
10
 
11
- const ZERO = "0000000000000000000000000000000000000000000000000000000000000000";
11
+ const ZERO = '0000000000000000000000000000000000000000000000000000000000000000'
12
12
 
13
13
  function makeItem(indexArg) {
14
- let str = indexArg;
14
+ let str = indexArg
15
15
  while (str.length < 64) {
16
- str += "0";
16
+ str += '0'
17
17
  }
18
- const index = coreTypes.Hash256.from(str);
18
+ const index = coreTypes.Hash256.from(str)
19
19
  const item = {
20
20
  toBytesSink(sink) {
21
- index.toBytesSink(sink);
21
+ index.toBytesSink(sink)
22
22
  },
23
23
  hashPrefix() {
24
- return Buffer.from([1, 3, 3, 7]);
24
+ return Buffer.from([1, 3, 3, 7])
25
25
  },
26
- };
27
- return [index, item];
26
+ }
27
+ return [index, item]
28
28
  }
29
29
 
30
- describe("ShaMap", () => {
31
- now();
30
+ describe('ShaMap', () => {
31
+ now()
32
32
 
33
- test("hashes to zero when empty", () => {
34
- const map = new ShaMap();
35
- expect(map.hash().toHex()).toBe(ZERO);
36
- });
37
- test("creates the same hash no matter which order items are added", () => {
38
- let map = new ShaMap();
33
+ test('hashes to zero when empty', () => {
34
+ const map = new ShaMap()
35
+ expect(map.hash().toHex()).toBe(ZERO)
36
+ })
37
+ test('creates the same hash no matter which order items are added', () => {
38
+ let map = new ShaMap()
39
39
  const items = [
40
- "0",
41
- "1",
42
- "11",
43
- "7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E20000000000000000",
44
- "7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E21000000000000000",
45
- "7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E22000000000000000",
46
- "7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E23000000000000000",
47
- "12",
48
- "122",
49
- ];
50
- items.forEach((i) => map.addItem(...makeItem(i)));
51
- const h1 = map.hash();
52
- expect(h1.eq(h1)).toBe(true);
53
- map = new ShaMap();
54
- items.reverse().forEach((i) => map.addItem(...makeItem(i)));
55
- expect(map.hash()).toStrictEqual(h1);
56
- });
40
+ '0',
41
+ '1',
42
+ '11',
43
+ '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E20000000000000000',
44
+ '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E21000000000000000',
45
+ '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E22000000000000000',
46
+ '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E23000000000000000',
47
+ '12',
48
+ '122',
49
+ ]
50
+ items.forEach((i) => map.addItem(...makeItem(i)))
51
+ const h1 = map.hash()
52
+ expect(h1.eq(h1)).toBe(true)
53
+ map = new ShaMap()
54
+ items.reverse().forEach((i) => map.addItem(...makeItem(i)))
55
+ expect(map.hash()).toStrictEqual(h1)
56
+ })
57
57
  function factory(fixture) {
58
58
  test(`recreate account state hash from ${fixture}`, () => {
59
- const map = new ShaMap();
60
- const ledger = loadFixture(fixture);
59
+ const map = new ShaMap()
60
+ const ledger = loadFixture(fixture)
61
61
  // const t = now();
62
- const leafNodePrefix = HashPrefix.accountStateEntry;
62
+ const leafNodePrefix = HashPrefix.accountStateEntry
63
63
  ledger.accountState
64
64
  .map((e, i) => {
65
65
  if ((i > 1000) & (i % 1000 === 0)) {
66
- console.log(e.index);
67
- console.log(i);
66
+ console.log(e.index)
67
+ console.log(i)
68
68
  }
69
- const bytes = binary.serializeObject(e);
69
+ const bytes = binary.serializeObject(e)
70
70
  return {
71
71
  index: coreTypes.Hash256.from(e.index),
72
72
  hashPrefix() {
73
- return leafNodePrefix;
73
+ return leafNodePrefix
74
74
  },
75
75
  toBytesSink(sink) {
76
- sink.put(bytes);
76
+ sink.put(bytes)
77
77
  },
78
- };
78
+ }
79
79
  })
80
- .forEach((so) => map.addItem(so.index, so));
81
- expect(map.hash().toHex()).toBe(ledger.account_hash);
80
+ .forEach((so) => map.addItem(so.index, so))
81
+ expect(map.hash().toHex()).toBe(ledger.account_hash)
82
82
  // console.log('took seconds: ', (now() - t));
83
- });
83
+ })
84
84
  }
85
- factory("ledger-full-38129.json");
86
- factory("ledger-full-40000.json");
85
+ factory('ledger-full-38129.json')
86
+ factory('ledger-full-40000.json')
87
87
  // factory('ledger-4320277.json');
88
88
  // factory('14280680.json');
89
- });
89
+ })