ripple-binary-codec 1.1.3-beta.1 → 1.2.1-beta.0
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.
- package/README.md +3 -3
- package/dist/binary.d.ts +6 -6
- package/dist/binary.js.map +1 -1
- package/dist/coretypes.d.ts +8 -8
- package/dist/coretypes.js.map +1 -1
- package/dist/enums/definitions.json +190 -4
- package/dist/enums/index.d.ts +6 -5
- package/dist/enums/index.js +3 -2
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/utils-renumber.js +7 -7
- package/dist/enums/utils-renumber.js.map +1 -1
- package/dist/hash-prefixes.d.ts +1 -1
- package/dist/hash-prefixes.js.map +1 -1
- package/dist/hashes.d.ts +3 -3
- package/dist/hashes.js +6 -4
- package/dist/hashes.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +13 -13
- package/dist/index.js.map +1 -1
- package/dist/ledger-hashes.d.ts +3 -3
- package/dist/ledger-hashes.js +5 -5
- package/dist/ledger-hashes.js.map +1 -1
- package/dist/quality.d.ts +2 -2
- package/dist/quality.js +2 -2
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.d.ts +3 -3
- package/dist/serdes/binary-parser.js +8 -8
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.d.ts +5 -5
- package/dist/serdes/binary-serializer.js +11 -8
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.d.ts +3 -3
- package/dist/shamap.js +5 -3
- package/dist/shamap.js.map +1 -1
- package/dist/types/account-id.d.ts +2 -2
- package/dist/types/account-id.js +12 -10
- package/dist/types/account-id.js.map +1 -1
- package/dist/types/amount.d.ts +3 -3
- package/dist/types/amount.js +18 -16
- package/dist/types/amount.js.map +1 -1
- package/dist/types/blob.d.ts +3 -3
- package/dist/types/blob.js +6 -4
- package/dist/types/blob.js.map +1 -1
- package/dist/types/currency.d.ts +5 -12
- package/dist/types/currency.js +31 -30
- package/dist/types/currency.js.map +1 -1
- package/dist/types/hash-128.d.ts +2 -2
- package/dist/types/hash-128.js +3 -1
- package/dist/types/hash-128.js.map +1 -1
- package/dist/types/hash-160.d.ts +2 -2
- package/dist/types/hash-160.js +3 -1
- package/dist/types/hash-160.js.map +1 -1
- package/dist/types/hash-256.d.ts +2 -2
- package/dist/types/hash-256.js +3 -1
- package/dist/types/hash-256.js.map +1 -1
- package/dist/types/hash.d.ts +3 -3
- package/dist/types/hash.js +6 -4
- package/dist/types/hash.js.map +1 -1
- package/dist/types/index.d.ts +15 -15
- package/dist/types/index.js +3 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/path-set.d.ts +2 -2
- package/dist/types/path-set.js +5 -3
- package/dist/types/path-set.js.map +1 -1
- package/dist/types/serialized-type.d.ts +4 -4
- package/dist/types/serialized-type.js +6 -4
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/st-array.d.ts +2 -2
- package/dist/types/st-array.js +6 -4
- package/dist/types/st-array.js.map +1 -1
- package/dist/types/st-object.d.ts +2 -2
- package/dist/types/st-object.js +20 -13
- package/dist/types/st-object.js.map +1 -1
- package/dist/types/uint-16.d.ts +3 -3
- package/dist/types/uint-16.js +5 -3
- package/dist/types/uint-16.js.map +1 -1
- package/dist/types/uint-32.d.ts +3 -3
- package/dist/types/uint-32.js +6 -4
- package/dist/types/uint-32.js.map +1 -1
- package/dist/types/uint-64.d.ts +4 -4
- package/dist/types/uint-64.js +11 -9
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint-8.d.ts +3 -3
- package/dist/types/uint-8.js +5 -3
- package/dist/types/uint-8.js.map +1 -1
- package/dist/types/uint.d.ts +3 -3
- package/dist/types/uint.js +4 -2
- package/dist/types/uint.js.map +1 -1
- package/dist/types/vector-256.d.ts +3 -3
- package/dist/types/vector-256.js +7 -5
- package/dist/types/vector-256.js.map +1 -1
- package/package.json +13 -27
- package/test/amount.test.js +29 -29
- package/test/binary-json.test.js +24 -26
- package/test/binary-parser.test.js +226 -228
- package/test/binary-serializer.test.js +194 -169
- package/test/fixtures/data-driven-tests.json +2 -790
- package/test/fixtures/negative-unl.json +4 -4
- package/test/fixtures/nf-token.json +547 -0
- package/test/hash.test.js +79 -75
- package/test/ledger.test.js +19 -19
- package/test/lower-case-hex.test.js +29 -28
- package/test/pseudo-transaction.test.js +26 -26
- package/test/quality.test.js +13 -13
- package/test/shamap.test.js +54 -54
- package/test/signing-data-encoding.test.js +79 -79
- package/test/tx-encode-decode.test.js +63 -63
- package/test/types.test.js +23 -23
- package/test/uint.test.js +107 -107
- package/test/x-address.test.js +106 -106
- package/HISTORY.md +0 -86
|
@@ -1,264 +1,289 @@
|
|
|
1
|
-
|
|
1
|
+
const { binary } = require('../dist/coretypes')
|
|
2
|
+
const { encode, decode } = require('../dist')
|
|
3
|
+
const { makeParser, BytesList, BinarySerializer } = binary
|
|
4
|
+
const { coreTypes } = require('../dist/types')
|
|
5
|
+
const { UInt8, UInt16, UInt32, UInt64, STObject } = coreTypes
|
|
6
|
+
const bigInt = require('big-integer')
|
|
7
|
+
const { Buffer } = require('buffer/')
|
|
2
8
|
|
|
3
|
-
const {
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const { UInt8, UInt16, UInt32, UInt64, STObject } = coreTypes;
|
|
8
|
-
const bigInt = require("big-integer");
|
|
9
|
-
const { Buffer } = require("buffer/");
|
|
10
|
-
|
|
11
|
-
const { loadFixture } = require("./utils");
|
|
12
|
-
const fixtures = loadFixture("data-driven-tests.json");
|
|
13
|
-
const deliverMinTx = require("./fixtures/delivermin-tx.json");
|
|
14
|
-
const deliverMinTxBinary = require("./fixtures/delivermin-tx-binary.json");
|
|
9
|
+
const { loadFixture } = require('./utils')
|
|
10
|
+
const fixtures = loadFixture('data-driven-tests.json')
|
|
11
|
+
const deliverMinTx = require('./fixtures/delivermin-tx.json')
|
|
12
|
+
const deliverMinTxBinary = require('./fixtures/delivermin-tx-binary.json')
|
|
15
13
|
const SignerListSet = {
|
|
16
|
-
tx: require(
|
|
17
|
-
binary: require(
|
|
18
|
-
meta: require(
|
|
19
|
-
}
|
|
14
|
+
tx: require('./fixtures/signerlistset-tx.json'),
|
|
15
|
+
binary: require('./fixtures/signerlistset-tx-binary.json'),
|
|
16
|
+
meta: require('./fixtures/signerlistset-tx-meta-binary.json'),
|
|
17
|
+
}
|
|
20
18
|
const DepositPreauth = {
|
|
21
|
-
tx: require(
|
|
22
|
-
binary: require(
|
|
23
|
-
meta: require(
|
|
24
|
-
}
|
|
19
|
+
tx: require('./fixtures/deposit-preauth-tx.json'),
|
|
20
|
+
binary: require('./fixtures/deposit-preauth-tx-binary.json'),
|
|
21
|
+
meta: require('./fixtures/deposit-preauth-tx-meta-binary.json'),
|
|
22
|
+
}
|
|
25
23
|
const Escrow = {
|
|
26
24
|
create: {
|
|
27
|
-
tx: require(
|
|
28
|
-
binary: require(
|
|
25
|
+
tx: require('./fixtures/escrow-create-tx.json'),
|
|
26
|
+
binary: require('./fixtures/escrow-create-binary.json'),
|
|
29
27
|
},
|
|
30
28
|
finish: {
|
|
31
|
-
tx: require(
|
|
32
|
-
binary: require(
|
|
33
|
-
meta: require(
|
|
29
|
+
tx: require('./fixtures/escrow-finish-tx.json'),
|
|
30
|
+
binary: require('./fixtures/escrow-finish-binary.json'),
|
|
31
|
+
meta: require('./fixtures/escrow-finish-meta-binary.json'),
|
|
34
32
|
},
|
|
35
33
|
cancel: {
|
|
36
|
-
tx: require(
|
|
37
|
-
binary: require(
|
|
34
|
+
tx: require('./fixtures/escrow-cancel-tx.json'),
|
|
35
|
+
binary: require('./fixtures/escrow-cancel-binary.json'),
|
|
38
36
|
},
|
|
39
|
-
}
|
|
37
|
+
}
|
|
40
38
|
const PaymentChannel = {
|
|
41
39
|
create: {
|
|
42
|
-
tx: require(
|
|
43
|
-
binary: require(
|
|
40
|
+
tx: require('./fixtures/payment-channel-create-tx.json'),
|
|
41
|
+
binary: require('./fixtures/payment-channel-create-binary.json'),
|
|
44
42
|
},
|
|
45
43
|
fund: {
|
|
46
|
-
tx: require(
|
|
47
|
-
binary: require(
|
|
44
|
+
tx: require('./fixtures/payment-channel-fund-tx.json'),
|
|
45
|
+
binary: require('./fixtures/payment-channel-fund-binary.json'),
|
|
48
46
|
},
|
|
49
47
|
claim: {
|
|
50
|
-
tx: require(
|
|
51
|
-
binary: require(
|
|
48
|
+
tx: require('./fixtures/payment-channel-claim-tx.json'),
|
|
49
|
+
binary: require('./fixtures/payment-channel-claim-binary.json'),
|
|
52
50
|
},
|
|
53
|
-
}
|
|
51
|
+
}
|
|
54
52
|
|
|
55
53
|
const Ticket = {
|
|
56
54
|
create: {
|
|
57
|
-
tx: require(
|
|
58
|
-
binary: require(
|
|
55
|
+
tx: require('./fixtures/ticket-create-tx.json'),
|
|
56
|
+
binary: require('./fixtures/ticket-create-binary.json'),
|
|
59
57
|
},
|
|
60
|
-
}
|
|
58
|
+
}
|
|
61
59
|
|
|
62
60
|
let json_undefined = {
|
|
63
|
-
TakerPays:
|
|
64
|
-
Account:
|
|
65
|
-
TransactionType:
|
|
61
|
+
TakerPays: '223174650',
|
|
62
|
+
Account: 'rPk2dXr27rMw9G5Ej9ad2Tt7RJzGy8ycBp',
|
|
63
|
+
TransactionType: 'OfferCreate',
|
|
66
64
|
Memos: [
|
|
67
65
|
{
|
|
68
66
|
Memo: {
|
|
69
|
-
MemoType:
|
|
70
|
-
MemoData:
|
|
67
|
+
MemoType: '584D4D2076616C7565',
|
|
68
|
+
MemoData: '322E3230393635',
|
|
71
69
|
MemoFormat: undefined,
|
|
72
70
|
},
|
|
73
71
|
},
|
|
74
72
|
],
|
|
75
|
-
Fee:
|
|
73
|
+
Fee: '15',
|
|
76
74
|
OfferSequence: undefined,
|
|
77
75
|
TakerGets: {
|
|
78
|
-
currency:
|
|
79
|
-
value:
|
|
80
|
-
issuer:
|
|
76
|
+
currency: 'XMM',
|
|
77
|
+
value: '100',
|
|
78
|
+
issuer: 'rExAPEZvbkZqYPuNcZ7XEBLENEshsWDQc8',
|
|
81
79
|
},
|
|
82
80
|
Flags: 524288,
|
|
83
81
|
Sequence: undefined,
|
|
84
82
|
LastLedgerSequence: 6220135,
|
|
85
|
-
}
|
|
83
|
+
}
|
|
86
84
|
|
|
87
85
|
let json_omitted = {
|
|
88
|
-
TakerPays:
|
|
89
|
-
Account:
|
|
90
|
-
TransactionType:
|
|
86
|
+
TakerPays: '223174650',
|
|
87
|
+
Account: 'rPk2dXr27rMw9G5Ej9ad2Tt7RJzGy8ycBp',
|
|
88
|
+
TransactionType: 'OfferCreate',
|
|
91
89
|
Memos: [
|
|
92
90
|
{
|
|
93
91
|
Memo: {
|
|
94
|
-
MemoType:
|
|
95
|
-
MemoData:
|
|
92
|
+
MemoType: '584D4D2076616C7565',
|
|
93
|
+
MemoData: '322E3230393635',
|
|
96
94
|
},
|
|
97
95
|
},
|
|
98
96
|
],
|
|
99
|
-
Fee:
|
|
97
|
+
Fee: '15',
|
|
100
98
|
TakerGets: {
|
|
101
|
-
currency:
|
|
102
|
-
value:
|
|
103
|
-
issuer:
|
|
99
|
+
currency: 'XMM',
|
|
100
|
+
value: '100',
|
|
101
|
+
issuer: 'rExAPEZvbkZqYPuNcZ7XEBLENEshsWDQc8',
|
|
104
102
|
},
|
|
105
103
|
Flags: 524288,
|
|
106
104
|
LastLedgerSequence: 6220135,
|
|
107
|
-
}
|
|
105
|
+
}
|
|
108
106
|
|
|
109
|
-
const NegativeUNL = require(
|
|
107
|
+
const NegativeUNL = require('./fixtures/negative-unl.json')
|
|
110
108
|
|
|
111
109
|
function bytesListTest() {
|
|
112
110
|
const list = new BytesList()
|
|
113
111
|
.put(Buffer.from([0]))
|
|
114
112
|
.put(Buffer.from([2, 3]))
|
|
115
|
-
.put(Buffer.from([4, 5]))
|
|
116
|
-
test(
|
|
117
|
-
expect(Array.isArray(list.bytesArray)).toBe(true)
|
|
118
|
-
expect(list.bytesArray[0] instanceof Buffer).toBe(true)
|
|
119
|
-
})
|
|
120
|
-
test(
|
|
121
|
-
expect(list.getLength()).toBe(5)
|
|
122
|
-
})
|
|
123
|
-
test(
|
|
124
|
-
const joined = list.toBytes()
|
|
125
|
-
expect(joined).toHaveLength(5)
|
|
126
|
-
expect(joined).toEqual(Buffer.from([0, 2, 3, 4, 5]))
|
|
127
|
-
})
|
|
113
|
+
.put(Buffer.from([4, 5]))
|
|
114
|
+
test('is an Array<Buffer>', function () {
|
|
115
|
+
expect(Array.isArray(list.bytesArray)).toBe(true)
|
|
116
|
+
expect(list.bytesArray[0] instanceof Buffer).toBe(true)
|
|
117
|
+
})
|
|
118
|
+
test('keeps track of the length itself', function () {
|
|
119
|
+
expect(list.getLength()).toBe(5)
|
|
120
|
+
})
|
|
121
|
+
test('can join all arrays into one via toBytes', function () {
|
|
122
|
+
const joined = list.toBytes()
|
|
123
|
+
expect(joined).toHaveLength(5)
|
|
124
|
+
expect(joined).toEqual(Buffer.from([0, 2, 3, 4, 5]))
|
|
125
|
+
})
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
function assertRecycles(blob) {
|
|
131
|
-
const parser = makeParser(blob)
|
|
132
|
-
const so = parser.readType(STObject)
|
|
133
|
-
const out = new BytesList()
|
|
134
|
-
so.toBytesSink(out)
|
|
135
|
-
const hex = out.toHex()
|
|
136
|
-
expect(hex).toEqual(blob)
|
|
137
|
-
expect(hex +
|
|
129
|
+
const parser = makeParser(blob)
|
|
130
|
+
const so = parser.readType(STObject)
|
|
131
|
+
const out = new BytesList()
|
|
132
|
+
so.toBytesSink(out)
|
|
133
|
+
const hex = out.toHex()
|
|
134
|
+
expect(hex).toEqual(blob)
|
|
135
|
+
expect(hex + ':').not.toEqual(blob)
|
|
138
136
|
}
|
|
139
137
|
|
|
140
138
|
function nestedObjectTests() {
|
|
141
139
|
fixtures.whole_objects.forEach((f, i) => {
|
|
142
|
-
/*eslint-disable jest/expect-expect*/
|
|
143
140
|
test(`whole_objects[${i}]: can parse blob and dump out same blob`, () => {
|
|
144
|
-
assertRecycles(f.blob_with_no_signing)
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
});
|
|
141
|
+
assertRecycles(f.blob_with_no_signing)
|
|
142
|
+
})
|
|
143
|
+
})
|
|
148
144
|
}
|
|
149
145
|
|
|
150
146
|
function check(type, n, expected) {
|
|
151
147
|
test(`Uint${type.width * 8} serializes ${n} as ${expected}`, function () {
|
|
152
|
-
const bl = new BytesList()
|
|
153
|
-
const serializer = new BinarySerializer(bl)
|
|
154
|
-
if (expected ===
|
|
155
|
-
expect(() => serializer.writeType(type, n)).toThrow()
|
|
156
|
-
return
|
|
148
|
+
const bl = new BytesList()
|
|
149
|
+
const serializer = new BinarySerializer(bl)
|
|
150
|
+
if (expected === 'throws') {
|
|
151
|
+
expect(() => serializer.writeType(type, n)).toThrow()
|
|
152
|
+
return
|
|
157
153
|
}
|
|
158
|
-
serializer.writeType(type, n)
|
|
159
|
-
expect(bl.toBytes()).toEqual(Buffer.from(expected))
|
|
160
|
-
})
|
|
154
|
+
serializer.writeType(type, n)
|
|
155
|
+
expect(bl.toBytes()).toEqual(Buffer.from(expected))
|
|
156
|
+
})
|
|
161
157
|
}
|
|
162
158
|
|
|
163
|
-
check(UInt8, 5, [5])
|
|
164
|
-
check(UInt16, 5, [0, 5])
|
|
165
|
-
check(UInt32, 5, [0, 0, 0, 5])
|
|
166
|
-
check(UInt32, 0xffffffff, [255, 255, 255, 255])
|
|
167
|
-
check(UInt8, 0xfeffffff,
|
|
168
|
-
check(UInt16, 0xfeffffff,
|
|
169
|
-
check(UInt16, 0xfeffffff,
|
|
170
|
-
check(UInt64, 0xfeffffff, [0, 0, 0, 0, 254, 255, 255, 255])
|
|
171
|
-
check(UInt64, -1,
|
|
172
|
-
check(UInt64, 0, [0, 0, 0, 0, 0, 0, 0, 0])
|
|
173
|
-
check(UInt64, 1, [0, 0, 0, 0, 0, 0, 0, 1])
|
|
174
|
-
check(UInt64, bigInt(1), [0, 0, 0, 0, 0, 0, 0, 1])
|
|
159
|
+
check(UInt8, 5, [5])
|
|
160
|
+
check(UInt16, 5, [0, 5])
|
|
161
|
+
check(UInt32, 5, [0, 0, 0, 5])
|
|
162
|
+
check(UInt32, 0xffffffff, [255, 255, 255, 255])
|
|
163
|
+
check(UInt8, 0xfeffffff, 'throws')
|
|
164
|
+
check(UInt16, 0xfeffffff, 'throws')
|
|
165
|
+
check(UInt16, 0xfeffffff, 'throws')
|
|
166
|
+
check(UInt64, 0xfeffffff, [0, 0, 0, 0, 254, 255, 255, 255])
|
|
167
|
+
check(UInt64, -1, 'throws')
|
|
168
|
+
check(UInt64, 0, [0, 0, 0, 0, 0, 0, 0, 0])
|
|
169
|
+
check(UInt64, 1, [0, 0, 0, 0, 0, 0, 0, 1])
|
|
170
|
+
check(UInt64, bigInt(1), [0, 0, 0, 0, 0, 0, 0, 1])
|
|
175
171
|
|
|
176
172
|
function deliverMinTest() {
|
|
177
|
-
test(
|
|
178
|
-
expect(encode(deliverMinTx)).toEqual(deliverMinTxBinary)
|
|
179
|
-
})
|
|
173
|
+
test('can serialize DeliverMin', () => {
|
|
174
|
+
expect(encode(deliverMinTx)).toEqual(deliverMinTxBinary)
|
|
175
|
+
})
|
|
180
176
|
}
|
|
181
177
|
|
|
182
178
|
function SignerListSetTest() {
|
|
183
|
-
test(
|
|
184
|
-
expect(encode(SignerListSet.tx)).toEqual(SignerListSet.binary)
|
|
185
|
-
})
|
|
186
|
-
test(
|
|
187
|
-
expect(encode(SignerListSet.tx.meta)).toEqual(SignerListSet.meta)
|
|
188
|
-
})
|
|
179
|
+
test('can serialize SignerListSet', () => {
|
|
180
|
+
expect(encode(SignerListSet.tx)).toEqual(SignerListSet.binary)
|
|
181
|
+
})
|
|
182
|
+
test('can serialize SignerListSet metadata', () => {
|
|
183
|
+
expect(encode(SignerListSet.tx.meta)).toEqual(SignerListSet.meta)
|
|
184
|
+
})
|
|
189
185
|
}
|
|
190
186
|
|
|
191
187
|
function DepositPreauthTest() {
|
|
192
|
-
test(
|
|
193
|
-
expect(encode(DepositPreauth.tx)).toEqual(DepositPreauth.binary)
|
|
194
|
-
})
|
|
195
|
-
test(
|
|
196
|
-
expect(encode(DepositPreauth.tx.meta)).toEqual(DepositPreauth.meta)
|
|
197
|
-
})
|
|
188
|
+
test('can serialize DepositPreauth', () => {
|
|
189
|
+
expect(encode(DepositPreauth.tx)).toEqual(DepositPreauth.binary)
|
|
190
|
+
})
|
|
191
|
+
test('can serialize DepositPreauth metadata', () => {
|
|
192
|
+
expect(encode(DepositPreauth.tx.meta)).toEqual(DepositPreauth.meta)
|
|
193
|
+
})
|
|
198
194
|
}
|
|
199
195
|
|
|
200
196
|
function EscrowTest() {
|
|
201
|
-
test(
|
|
202
|
-
expect(encode(Escrow.create.tx)).toEqual(Escrow.create.binary)
|
|
203
|
-
})
|
|
204
|
-
test(
|
|
205
|
-
expect(encode(Escrow.finish.tx)).toEqual(Escrow.finish.binary)
|
|
206
|
-
expect(encode(Escrow.finish.tx.meta)).toEqual(Escrow.finish.meta)
|
|
207
|
-
})
|
|
208
|
-
test(
|
|
209
|
-
expect(encode(Escrow.cancel.tx)).toEqual(Escrow.cancel.binary)
|
|
210
|
-
})
|
|
197
|
+
test('can serialize EscrowCreate', () => {
|
|
198
|
+
expect(encode(Escrow.create.tx)).toEqual(Escrow.create.binary)
|
|
199
|
+
})
|
|
200
|
+
test('can serialize EscrowFinish', () => {
|
|
201
|
+
expect(encode(Escrow.finish.tx)).toEqual(Escrow.finish.binary)
|
|
202
|
+
expect(encode(Escrow.finish.tx.meta)).toEqual(Escrow.finish.meta)
|
|
203
|
+
})
|
|
204
|
+
test('can serialize EscrowCancel', () => {
|
|
205
|
+
expect(encode(Escrow.cancel.tx)).toEqual(Escrow.cancel.binary)
|
|
206
|
+
})
|
|
211
207
|
}
|
|
212
208
|
|
|
213
209
|
function PaymentChannelTest() {
|
|
214
|
-
test(
|
|
210
|
+
test('can serialize PaymentChannelCreate', () => {
|
|
215
211
|
expect(encode(PaymentChannel.create.tx)).toEqual(
|
|
216
|
-
PaymentChannel.create.binary
|
|
217
|
-
)
|
|
218
|
-
})
|
|
219
|
-
test(
|
|
220
|
-
expect(encode(PaymentChannel.fund.tx)).toEqual(PaymentChannel.fund.binary)
|
|
221
|
-
})
|
|
222
|
-
test(
|
|
223
|
-
expect(encode(PaymentChannel.claim.tx)).toEqual(
|
|
224
|
-
|
|
225
|
-
);
|
|
226
|
-
});
|
|
212
|
+
PaymentChannel.create.binary,
|
|
213
|
+
)
|
|
214
|
+
})
|
|
215
|
+
test('can serialize PaymentChannelFund', () => {
|
|
216
|
+
expect(encode(PaymentChannel.fund.tx)).toEqual(PaymentChannel.fund.binary)
|
|
217
|
+
})
|
|
218
|
+
test('can serialize PaymentChannelClaim', () => {
|
|
219
|
+
expect(encode(PaymentChannel.claim.tx)).toEqual(PaymentChannel.claim.binary)
|
|
220
|
+
})
|
|
227
221
|
}
|
|
228
222
|
|
|
229
223
|
function NegativeUNLTest() {
|
|
230
|
-
test(
|
|
231
|
-
expect(encode(NegativeUNL.tx)).toEqual(NegativeUNL.binary)
|
|
232
|
-
})
|
|
233
|
-
test(
|
|
234
|
-
expect(decode(NegativeUNL.binary)).toEqual(NegativeUNL.tx)
|
|
235
|
-
})
|
|
224
|
+
test('can serialize NegativeUNL', () => {
|
|
225
|
+
expect(encode(NegativeUNL.tx)).toEqual(NegativeUNL.binary)
|
|
226
|
+
})
|
|
227
|
+
test('can deserialize NegativeUNL', () => {
|
|
228
|
+
expect(decode(NegativeUNL.binary)).toEqual(NegativeUNL.tx)
|
|
229
|
+
})
|
|
236
230
|
}
|
|
237
231
|
|
|
238
232
|
function omitUndefinedTest() {
|
|
239
|
-
test(
|
|
240
|
-
let encodedOmitted = encode(json_omitted)
|
|
241
|
-
let encodedUndefined = encode(json_undefined)
|
|
242
|
-
expect(encodedOmitted).toEqual(encodedUndefined)
|
|
243
|
-
expect(decode(encodedOmitted)).toEqual(decode(encodedUndefined))
|
|
244
|
-
})
|
|
233
|
+
test('omits fields with undefined value', () => {
|
|
234
|
+
let encodedOmitted = encode(json_omitted)
|
|
235
|
+
let encodedUndefined = encode(json_undefined)
|
|
236
|
+
expect(encodedOmitted).toEqual(encodedUndefined)
|
|
237
|
+
expect(decode(encodedOmitted)).toEqual(decode(encodedUndefined))
|
|
238
|
+
})
|
|
245
239
|
}
|
|
246
240
|
|
|
247
241
|
function ticketTest() {
|
|
248
|
-
test(
|
|
249
|
-
expect(encode(Ticket.create.tx)).toEqual(Ticket.create.binary)
|
|
250
|
-
})
|
|
242
|
+
test('can serialize TicketCreate', () => {
|
|
243
|
+
expect(encode(Ticket.create.tx)).toEqual(Ticket.create.binary)
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function nfTokenTest() {
|
|
248
|
+
const fixtures = require('./fixtures/nf-token.json')
|
|
249
|
+
|
|
250
|
+
for (const txName of Object.keys(fixtures)) {
|
|
251
|
+
test(`can serialize transaction ${txName}`, () => {
|
|
252
|
+
expect(encode(fixtures[txName].tx.json)).toEqual(
|
|
253
|
+
fixtures[txName].tx.binary,
|
|
254
|
+
)
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
test(`can deserialize transaction ${txName}`, () => {
|
|
258
|
+
expect(decode(fixtures[txName].tx.binary)).toEqual(
|
|
259
|
+
fixtures[txName].tx.json,
|
|
260
|
+
)
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
test(`can serialize meta ${txName}`, () => {
|
|
264
|
+
expect(encode(fixtures[txName].meta.json)).toEqual(
|
|
265
|
+
fixtures[txName].meta.binary,
|
|
266
|
+
)
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
test(`can deserialize meta ${txName}`, () => {
|
|
270
|
+
expect(decode(fixtures[txName].meta.binary)).toEqual(
|
|
271
|
+
fixtures[txName].meta.json,
|
|
272
|
+
)
|
|
273
|
+
})
|
|
274
|
+
}
|
|
251
275
|
}
|
|
252
276
|
|
|
253
|
-
describe(
|
|
254
|
-
describe(
|
|
255
|
-
describe(
|
|
256
|
-
describe(
|
|
257
|
-
describe(
|
|
258
|
-
describe(
|
|
259
|
-
describe(
|
|
260
|
-
describe(
|
|
261
|
-
describe(
|
|
262
|
-
describe(
|
|
263
|
-
describe(
|
|
264
|
-
|
|
277
|
+
describe('Binary Serialization', function () {
|
|
278
|
+
describe('nestedObjectTests', nestedObjectTests)
|
|
279
|
+
describe('BytesList', bytesListTest)
|
|
280
|
+
describe('DeliverMin', deliverMinTest)
|
|
281
|
+
describe('DepositPreauth', DepositPreauthTest)
|
|
282
|
+
describe('SignerListSet', SignerListSetTest)
|
|
283
|
+
describe('Escrow', EscrowTest)
|
|
284
|
+
describe('PaymentChannel', PaymentChannelTest)
|
|
285
|
+
describe('NegativeUNLTest', NegativeUNLTest)
|
|
286
|
+
describe('OmitUndefined', omitUndefinedTest)
|
|
287
|
+
describe('TicketTest', ticketTest)
|
|
288
|
+
describe('NFToken', nfTokenTest)
|
|
289
|
+
})
|