@alexbosworth/blockchain 4.8.0 → 4.10.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +34 -0
  3. package/index.js +2 -0
  4. package/package.json +12 -2
  5. package/script/conf/networks.json +27 -0
  6. package/script/index.js +2 -0
  7. package/script/output_script_for_address.js +96 -0
  8. package/.gitattributes +0 -1
  9. package/.tm_properties +0 -1
  10. package/test/5bit/test_bytes_as_words.js +0 -49
  11. package/test/5bit/test_words_as_bytes.js +0 -79
  12. package/test/addresses/test_bech32_type.js +0 -29
  13. package/test/addresses/test_decode_base58.js +0 -109
  14. package/test/addresses/test_decode_base58_address.js +0 -94
  15. package/test/addresses/test_decode_bech32.js +0 -49
  16. package/test/addresses/test_decode_bech32_address.js +0 -188
  17. package/test/addresses/test_encode_base58_address.js +0 -127
  18. package/test/addresses/test_encode_bech32.js +0 -69
  19. package/test/addresses/test_encode_bech32_address.js +0 -167
  20. package/test/fixtures/tx_invalid.json +0 -397
  21. package/test/fixtures/tx_valid.json +0 -528
  22. package/test/hashes/test_hash_for_p2pkh.js +0 -54
  23. package/test/hashes/test_hash_for_p2wpkh.js +0 -54
  24. package/test/hashes/test_id_for_block.js +0 -38
  25. package/test/hashes/test_no_locktime_id_for_transaction.js +0 -56
  26. package/test/hashes/test_previous_block_id.js +0 -38
  27. package/test/numbers/test_compact_int_as_number.js +0 -104
  28. package/test/numbers/test_encode_push_bytes_count.js +0 -82
  29. package/test/numbers/test_number_as_compact_int.js +0 -77
  30. package/test/numbers/test_number_as_little_endian.js +0 -77
  31. package/test/numbers/test_parse_push_bytes_count.js +0 -67
  32. package/test/script/test_p2ms_script.js +0 -106
  33. package/test/script/test_p2pkh_output_script.js +0 -41
  34. package/test/script/test_p2sh_output_script.js +0 -41
  35. package/test/script/test_p2tr_output_script.js +0 -43
  36. package/test/script/test_p2wpkh_output_script.js +0 -41
  37. package/test/script/test_p2wsh_output_script.js +0 -43
  38. package/test/script/test_script_as_script_elements.js +0 -84
  39. package/test/script/test_script_elements_as_script.js +0 -72
  40. package/test/transactions/test_components_of_transaction.js +0 -352
  41. package/test/transactions/test_core_tx_vectors.js +0 -70
  42. package/test/transactions/test_id_for_transaction.js +0 -72
  43. package/test/transactions/test_non_witness_hash_to_sign.js +0 -404
  44. package/test/transactions/test_query_transactions.js +0 -87
  45. package/test/transactions/test_size_of_transaction.js +0 -84
  46. package/test/transactions/test_transaction_from_components.js +0 -281
  47. package/test/transactions/test_unsigned_tx_from_psbt.js +0 -89
  48. package/test/transactions/test_v0_hash_to_sign.js +0 -262
@@ -1,352 +0,0 @@
1
- const {deepStrictEqual} = require('node:assert').strict;
2
- const {throws} = require('node:assert').strict;
3
- const test = require('node:test');
4
-
5
- const {componentsOfTransaction} = require('./../../');
6
-
7
- const hexAsBuffer = hex => Buffer.from(hex, 'hex');
8
-
9
- const tests = [
10
- {
11
- args: {transaction: ''},
12
- description: 'A transaction hex is required',
13
- error: 'ExpectedHexEncodedTransactionToGetComponentsOf',
14
- },
15
- {
16
- args: {
17
- transaction: '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff0101000000000000000000000000deadbeef',
18
- },
19
- description: 'A tx with extra data on the end is rejected',
20
- error: 'UnexpectedDataAfterTransactionToGetComponentsOf',
21
- },
22
- {
23
- args: {
24
- transaction: '01000000010000000000000000000000000000000000000000000000000000000000000000fffffffffd0000ffffffff0101000000000000000000000000',
25
- },
26
- description: 'A tx with a non-minimal script length encoding is rejected',
27
- error: 'ExpectedMinimallyEncodedCompactIntegerNumber',
28
- },
29
- {
30
- args: {
31
- transaction: '0100',
32
- },
33
- description: 'A tx cut short in the version is rejected',
34
- error: 'ExpectedAdditionalTransactionDataToParse',
35
- },
36
- {
37
- args: {
38
- transaction: '0100000000',
39
- },
40
- description: 'A tx cut short after a zero marker byte is rejected',
41
- error: 'ExpectedAdditionalTransactionDataToParse',
42
- },
43
- {
44
- args: {
45
- transaction: '01000000fdffff0000000000000000000000000000000000000000',
46
- },
47
- description: 'A tx claiming more inputs than the data holds is rejected',
48
- error: 'UnexpectedInputCountForTransactionDataLength',
49
- },
50
- {
51
- args: {
52
- transaction: '01000000010000000000000000000000000000000000000000000000000000000000000000fffffffffc0000000000000000000000000000000000000000000000',
53
- },
54
- description: 'A tx claiming a script larger than the data is rejected',
55
- error: 'ExpectedAdditionalTransactionDataToParse',
56
- },
57
- {
58
- args: {
59
- transaction: '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00fffffffffdffff0000000000000000',
60
- },
61
- description: 'A tx claiming more outputs than the data holds is rejected',
62
- error: 'UnexpectedOutputCountForTransactionDataLength',
63
- },
64
- {
65
- args: {
66
- transaction: '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff010100000000000000fc',
67
- },
68
- description: 'A tx claiming an output script larger than data is rejected',
69
- error: 'ExpectedAdditionalTransactionDataToParse',
70
- },
71
- {
72
- args: {
73
- transaction: '010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff01010000000000000000fc00000000',
74
- },
75
- description: 'A tx claiming more witness elements than data is rejected',
76
- error: 'UnexpectedWitnessCountForTransactionDataLength',
77
- },
78
- {
79
- args: {
80
- transaction: '010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff0101000000000000000001fc00000000',
81
- },
82
- description: 'A tx claiming a witness element larger than data is rejected',
83
- error: 'ExpectedAdditionalTransactionDataToParse',
84
- },
85
- {
86
- args: {
87
- transaction: '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff010100000000000000000000',
88
- },
89
- description: 'A tx cut short in the locktime is rejected',
90
- error: 'ExpectedAdditionalTransactionDataToParse',
91
- },
92
- {
93
- args: {
94
- transaction: '010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff0101000000000000000000' + '00000000',
95
- },
96
- description: 'A witness serialized tx with no witness data is rejected',
97
- error: 'UnexpectedSuperfluousWitnessDataInTransaction',
98
- },
99
- {
100
- args: {
101
- transaction: '010000000002010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff010100000000000000000101510000' + '0000',
102
- },
103
- description: 'A zero marker with unknown flag is legacy and has extra data',
104
- error: 'UnexpectedDataAfterTransactionToGetComponentsOf',
105
- },
106
- {
107
- args: {
108
- transaction: '0100000000' + '02' + '01000000000000000151' + '020000000000000000' + '00000000',
109
- },
110
- description: 'A zero inputs tx with a non-witness flag byte is parsed as legacy',
111
- expected: {
112
- inputs: [],
113
- locktime: 0,
114
- outputs: [{script: '51', tokens: 1}, {script: '', tokens: 2}],
115
- version: 1,
116
- },
117
- },
118
- {
119
- args: {
120
- transaction: '0100000001' + '00'.repeat(32) + 'ffffffff00ffffffff' + '01' + '0000000000002000' + '00' + '00000000',
121
- },
122
- description: 'A tx with an output value beyond safe integer range is rejected',
123
- error: 'UnexpectedOutputValueInTransaction',
124
- },
125
- {
126
- args: {
127
- transaction: '0100000001' + '00'.repeat(32) + 'ffffffff00ffffffff' + '01' + 'ffffffffffff1f00' + '00' + '00000000',
128
- },
129
- description: 'A tx with the max safe integer output value is parsed',
130
- expected: {
131
- inputs: [{
132
- id: '00'.repeat(32),
133
- script: '',
134
- sequence: 4294967295,
135
- vout: 4294967295,
136
- witness: undefined,
137
- }],
138
- locktime: 0,
139
- outputs: [{script: '', tokens: 9007199254740991}],
140
- version: 1,
141
- },
142
- },
143
- {
144
- args: {
145
- transaction: '0100000000' + '00' + '00000000',
146
- },
147
- description: 'A zero inputs and zero outputs legacy tx is parsed',
148
- expected: {inputs: [], locktime: 0, outputs: [], version: 1},
149
- },
150
- {
151
- args: {
152
- transaction: '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000',
153
- },
154
- description: 'A coinbase transaction is parsed',
155
- expected: {
156
- inputs: [{
157
- id: '0000000000000000000000000000000000000000000000000000000000000000',
158
- script: '04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73',
159
- sequence: 4294967295,
160
- vout: 4294967295,
161
- witness: undefined,
162
- }],
163
- locktime: 0,
164
- outputs: [{
165
- script: '4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac',
166
- tokens: 5000000000,
167
- }],
168
- version: 1,
169
- },
170
- },
171
- {
172
- args: {
173
- transaction: '01000000019ac03d5ae6a875d970128ef9086cef276a1919684a6988023cc7254691d97e6d010000006b4830450221009d41dc793ba24e65f571473d40b299b6459087cea1509f0d381740b1ac863cb6022039c425906fcaf51b2b84d8092569fb3213de43abaff2180e2a799d4fcb4dd0aa012102d5ede09a8ae667d0f855ef90325e27f6ce35bbe60a1e6e87af7f5b3c652140fdffffffff080100000000000000010101000000000000000202010100000000000000014c0100000000000000034c02010100000000000000014d0100000000000000044dffff010100000000000000014e0100000000000000064effffffff0100000000',
174
- },
175
- description: 'invalid script',
176
- expected: {
177
- inputs: [{
178
- id: '6d7ed9914625c73c0288694a6819196a27ef6c08f98e1270d975a8e65a3dc09a',
179
- script: '4830450221009d41dc793ba24e65f571473d40b299b6459087cea1509f0d381740b1ac863cb6022039c425906fcaf51b2b84d8092569fb3213de43abaff2180e2a799d4fcb4dd0aa012102d5ede09a8ae667d0f855ef90325e27f6ce35bbe60a1e6e87af7f5b3c652140fd',
180
- sequence: 4294967295,
181
- vout: 1,
182
- witness: undefined,
183
- }],
184
- locktime: 0,
185
- outputs: [
186
- {
187
- script: '01',
188
- tokens: 1,
189
- },
190
- {
191
- script: '0201',
192
- tokens: 1,
193
- },
194
- {
195
- script: '4c',
196
- tokens: 1,
197
- },
198
- {
199
- script: '4c0201',
200
- tokens: 1,
201
- },
202
- {
203
- script: '4d',
204
- tokens: 1,
205
- },
206
- {
207
- script: '4dffff01',
208
- tokens: 1,
209
- },
210
- {
211
- script: '4e',
212
- tokens: 1,
213
- },
214
- {
215
- script: '4effffffff01',
216
- tokens: 1,
217
- },
218
- ],
219
- version: 1,
220
- },
221
- },
222
- {
223
- args: {
224
- transaction: '02000000000103ae8caf3aad8861142597a29d6377f524a55f4542d5294c8292ce123a956d3e520000000000ffffffff9cbb1c5531a677b90c489d75a198a14f02d49e554ab9cdaa17bd956b127724570200000000ffffffff9cbb1c5531a677b90c489d75a198a14f02d49e554ab9cdaa17bd956b127724570100000000ffffffff0640420f0000000000160014eaa9b76637b1ad340b6efadf773a73b53637d5b6de91f62901000000225120f4c82416bcb08422c195af995e1d248d1378d8b48dafa9f45bc213b83101d49240420f00000000001600148729d17b2aa507ab19051a028384bc6e0ce25e455e368900000000002251200249ccc5af06fa5642f12d42d2a34bfbb08688d54a9b99d07b98619b35df03b440420f0000000000160014d2d59a8a59f997cbc8888411010faf1658e0e3465e368900000000002251207febd720c78518b52aa1a2443823cc8f55e373910f616e112d5d7bd622fe1ab2024830450221008ac71eff4d7e298941be012fc14f0ac9bf62ae6ffeac13522bb27b5b4108d3aa0220192a69ad6fdb86b1e09c7fdcaaafeb58d25060e44199c734dc0d7d385b5d800d0121029943eaccd3987fa495a6b4f47f2fafeb0521e4e12f39498d9465a564ef75329602483045022100f9cde9adb00c0a6c62dae8604ca750039201288c0dafff952461da3caf05e3ae0220679c01f2518413951de3b62531b1cf36bb92562e3bd4197f0fa6e6e3e231272e0121027326b48c9f2729597e328ab6d05f5af75866e1ffa203fadf78387a3b202ff80d0247304402202550beec478845af2df929abf85708f9fcceaae31377f2e01d803e2acf7b426f022036c312b1e38ca333fe70aa37d3093387ac7486f08438eb8eed323699594468cb012102275a197f7ccfece19cf0532b068b6e38ceceda146e791875ecbdc55500bb7efe00000000',
225
- },
226
- description: 'Transaction with witnesses and P2TR and P2WPKH outputs',
227
- expected: {
228
- inputs: [
229
- {
230
- id: '523e6d953a12ce92824c29d542455fa524f577639da29725146188ad3aaf8cae',
231
- script: '',
232
- sequence: 4294967295,
233
- vout: 0,
234
- witness: [
235
- '30450221008ac71eff4d7e298941be012fc14f0ac9bf62ae6ffeac13522bb27b5b4108d3aa0220192a69ad6fdb86b1e09c7fdcaaafeb58d25060e44199c734dc0d7d385b5d800d01',
236
- '029943eaccd3987fa495a6b4f47f2fafeb0521e4e12f39498d9465a564ef753296',
237
- ],
238
- },
239
- {
240
- id: '572477126b95bd17aacdb94a559ed4024fa198a1759d480cb977a631551cbb9c',
241
- script: '',
242
- sequence: 4294967295,
243
- vout: 2,
244
- witness: [
245
- '3045022100f9cde9adb00c0a6c62dae8604ca750039201288c0dafff952461da3caf05e3ae0220679c01f2518413951de3b62531b1cf36bb92562e3bd4197f0fa6e6e3e231272e01',
246
- '027326b48c9f2729597e328ab6d05f5af75866e1ffa203fadf78387a3b202ff80d',
247
- ],
248
- },
249
- {
250
- id: '572477126b95bd17aacdb94a559ed4024fa198a1759d480cb977a631551cbb9c',
251
- script: '',
252
- sequence: 4294967295,
253
- vout: 1,
254
- witness: [
255
- '304402202550beec478845af2df929abf85708f9fcceaae31377f2e01d803e2acf7b426f022036c312b1e38ca333fe70aa37d3093387ac7486f08438eb8eed323699594468cb01',
256
- '02275a197f7ccfece19cf0532b068b6e38ceceda146e791875ecbdc55500bb7efe'
257
- ],
258
- }
259
- ],
260
- locktime: 0,
261
- outputs: [
262
- {
263
- script: '0014eaa9b76637b1ad340b6efadf773a73b53637d5b6',
264
- tokens: 1000000,
265
- },
266
- {
267
- script: '5120f4c82416bcb08422c195af995e1d248d1378d8b48dafa9f45bc213b83101d492',
268
- tokens: 4998992350,
269
- },
270
- {
271
- script: '00148729d17b2aa507ab19051a028384bc6e0ce25e45',
272
- tokens: 1000000,
273
- },
274
- {
275
- script: '51200249ccc5af06fa5642f12d42d2a34bfbb08688d54a9b99d07b98619b35df03b4',
276
- tokens: 8992350,
277
- },
278
- {
279
- script: '0014d2d59a8a59f997cbc8888411010faf1658e0e346',
280
- tokens: 1000000,
281
- },
282
- {
283
- script: '51207febd720c78518b52aa1a2443823cc8f55e373910f616e112d5d7bd622fe1ab2',
284
- tokens: 8992350,
285
- },
286
- ],
287
- version: 2,
288
- },
289
- },
290
- {
291
- args: {
292
- transaction: '0100000001f709fa82596e4f908ee331cb5e0ed46ab331d7dcfaf697fe95891e73dac4ebcb000000008c20ca42095840735e89283fec298e62ac2ddea9b5f34a8cbb7097ad965b87568100201b1b01dc829177da4a14551d2fc96a9db00c6501edfa12f22cd9cefd335c227f483045022100a9df60536df5733dd0de6bc921fab0b3eee6426501b43a228afa2c90072eb5ca02201c78b74266fac7d1db5deff080d8a403743203f109fbcabf6d5a760bf87386d20100ffffffff01c075790000000000232103611f9a45c18f28f06f19076ad571c344c82ce8fcfe34464cf8085217a2d294a6ac00000000',
293
- },
294
- description: 'A non-segwit transaction is read',
295
- expected: {
296
- inputs: [{
297
- id: 'cbebc4da731e8995fe97f6fadcd731b36ad40e5ecb31e38e904f6e5982fa09f7',
298
- script: '20ca42095840735e89283fec298e62ac2ddea9b5f34a8cbb7097ad965b87568100201b1b01dc829177da4a14551d2fc96a9db00c6501edfa12f22cd9cefd335c227f483045022100a9df60536df5733dd0de6bc921fab0b3eee6426501b43a228afa2c90072eb5ca02201c78b74266fac7d1db5deff080d8a403743203f109fbcabf6d5a760bf87386d20100',
299
- sequence: 4294967295,
300
- vout: 0,
301
- witness: undefined,
302
- }],
303
- locktime: 0,
304
- outputs: [{
305
- script: '2103611f9a45c18f28f06f19076ad571c344c82ce8fcfe34464cf8085217a2d294a6ac',
306
- tokens: 7960000,
307
- }],
308
- version: 1,
309
- },
310
- },
311
- {
312
- args: {
313
- transaction: '0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000',
314
- },
315
- description: 'A P2PK transaction is read',
316
- expected: {
317
- inputs: [{
318
- id: '0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9',
319
- script: '47304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901',
320
- sequence: 4294967295,
321
- vout: 0,
322
- witness: undefined,
323
- }],
324
- locktime: 0,
325
- outputs: [
326
- {
327
- script: '4104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac',
328
- tokens: 1000000000,
329
- },
330
- {
331
- script: '410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac',
332
- tokens: 4000000000,
333
- },
334
- ],
335
- version: 1,
336
- },
337
- },
338
- ];
339
-
340
- tests.forEach(({args, description, error, expected}) => {
341
- return test(description, (t, end) => {
342
- if (!!error) {
343
- throws(() => componentsOfTransaction(args), new Error(error), 'Got err');
344
- } else {
345
- const res = componentsOfTransaction(args);
346
-
347
- deepStrictEqual(res, expected, 'Got expected result');
348
- }
349
-
350
- return end();
351
- });
352
- });
@@ -1,70 +0,0 @@
1
- const {equal} = require('node:assert').strict;
2
- const {throws} = require('node:assert').strict;
3
- const {readFileSync} = require('node:fs');
4
- const {join} = require('node:path');
5
- const test = require('node:test');
6
-
7
- const {componentsOfTransaction} = require('./../../');
8
- const {sizeOfTransaction} = require('./../../');
9
- const {transactionFromComponents} = require('./../../');
10
-
11
- // Vectors that Core deserializes but that cannot be represented as Numbers
12
- const expectedErrors = {
13
- 'tx_invalid #24: Negative output': 'UnexpectedOutputValueInTransaction',
14
- };
15
- const fixtures = ['tx_valid', 'tx_invalid'];
16
- const fixturesDir = join(__dirname, '..', 'fixtures');
17
- const isVector = entry => entry.length > 1;
18
- const readJson = name => JSON.parse(readFileSync(join(fixturesDir, name)));
19
- const vectorTx = vector => vector[1];
20
-
21
- // Bitcoin Core test vectors: every entry, valid or invalid at the consensus
22
- // level, is required to deserialize, so every entry is expected to parse and
23
- // to re-serialize back to the exact same bytes.
24
- fixtures.forEach(fixture => {
25
- const entries = readJson(`${fixture}.json`);
26
-
27
- let comment = fixture;
28
-
29
- return entries.forEach((entry, i) => {
30
- // Single string entries are comments describing the following vectors
31
- if (!isVector(entry)) {
32
- comment = entry[0];
33
-
34
- return;
35
- }
36
-
37
- const transaction = vectorTx(entry);
38
-
39
- const description = `${fixture} #${i}: ${comment}`;
40
-
41
- return test(description, (t, end) => {
42
- if (!!expectedErrors[description]) {
43
- const error = new Error(expectedErrors[description]);
44
-
45
- throws(() => componentsOfTransaction({transaction}), error, 'Got err');
46
-
47
- return end();
48
- }
49
-
50
- const components = componentsOfTransaction({transaction});
51
-
52
- const roundTrip = transactionFromComponents(components).transaction;
53
-
54
- equal(roundTrip, transaction, 'Transaction round trips through components');
55
-
56
- const {vsize, weight} = sizeOfTransaction({transaction});
57
-
58
- const size = transaction.length / 2;
59
-
60
- const hasWitness = components.inputs.some(input => !!input.witness);
61
-
62
- // A legacy tx has weight of 4x its size, a witness tx weighs less
63
- equal(weight, hasWitness ? weight : size * 4, 'Legacy weight is 4x size');
64
- equal(weight <= size * 4, true, 'Weight is bounded by 4x the size');
65
- equal(vsize, Math.ceil(weight / 4), 'Virtual size is weight over 4');
66
-
67
- return end();
68
- });
69
- });
70
- });
@@ -1,72 +0,0 @@
1
- const {deepStrictEqual} = require('node:assert').strict;
2
- const {throws} = require('node:assert').strict;
3
- const test = require('node:test');
4
-
5
- const {idForTransaction} = require('./../../');
6
-
7
- const tests = [
8
- {
9
- args: {transaction: ''},
10
- description: 'A transaction hex is required',
11
- error: 'ExpectedHexEncodedTransactionToGetComponentsOf',
12
- },
13
- {
14
- args: {
15
- transaction: '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000',
16
- },
17
- description: 'A coinbase transaction',
18
- expected: {
19
- id: '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b',
20
- },
21
- },
22
- {
23
- args: {
24
- transaction: '01000000019ac03d5ae6a875d970128ef9086cef276a1919684a6988023cc7254691d97e6d010000006b4830450221009d41dc793ba24e65f571473d40b299b6459087cea1509f0d381740b1ac863cb6022039c425906fcaf51b2b84d8092569fb3213de43abaff2180e2a799d4fcb4dd0aa012102d5ede09a8ae667d0f855ef90325e27f6ce35bbe60a1e6e87af7f5b3c652140fdffffffff080100000000000000010101000000000000000202010100000000000000014c0100000000000000034c02010100000000000000014d0100000000000000044dffff010100000000000000014e0100000000000000064effffffff0100000000',
25
- },
26
- description: 'invalid script',
27
- expected: {
28
- id: 'ebc9fa1196a59e192352d76c0f6e73167046b9d37b8302b6bb6968dfd279b767',
29
- },
30
- },
31
- {
32
- args: {
33
- transaction: '02000000000103ae8caf3aad8861142597a29d6377f524a55f4542d5294c8292ce123a956d3e520000000000ffffffff9cbb1c5531a677b90c489d75a198a14f02d49e554ab9cdaa17bd956b127724570200000000ffffffff9cbb1c5531a677b90c489d75a198a14f02d49e554ab9cdaa17bd956b127724570100000000ffffffff0640420f0000000000160014eaa9b76637b1ad340b6efadf773a73b53637d5b6de91f62901000000225120f4c82416bcb08422c195af995e1d248d1378d8b48dafa9f45bc213b83101d49240420f00000000001600148729d17b2aa507ab19051a028384bc6e0ce25e455e368900000000002251200249ccc5af06fa5642f12d42d2a34bfbb08688d54a9b99d07b98619b35df03b440420f0000000000160014d2d59a8a59f997cbc8888411010faf1658e0e3465e368900000000002251207febd720c78518b52aa1a2443823cc8f55e373910f616e112d5d7bd622fe1ab2024830450221008ac71eff4d7e298941be012fc14f0ac9bf62ae6ffeac13522bb27b5b4108d3aa0220192a69ad6fdb86b1e09c7fdcaaafeb58d25060e44199c734dc0d7d385b5d800d0121029943eaccd3987fa495a6b4f47f2fafeb0521e4e12f39498d9465a564ef75329602483045022100f9cde9adb00c0a6c62dae8604ca750039201288c0dafff952461da3caf05e3ae0220679c01f2518413951de3b62531b1cf36bb92562e3bd4197f0fa6e6e3e231272e0121027326b48c9f2729597e328ab6d05f5af75866e1ffa203fadf78387a3b202ff80d0247304402202550beec478845af2df929abf85708f9fcceaae31377f2e01d803e2acf7b426f022036c312b1e38ca333fe70aa37d3093387ac7486f08438eb8eed323699594468cb012102275a197f7ccfece19cf0532b068b6e38ceceda146e791875ecbdc55500bb7efe00000000',
34
- },
35
- description: 'Transaction with witnesses and P2TR and P2WPKH outputs',
36
- expected: {
37
- id: 'ab940e8efd07f7f85f907e36f8e6509ab795de91bbd3e0fa69781549464506a4',
38
- },
39
- },
40
- {
41
- args: {
42
- transaction: '0100000001f709fa82596e4f908ee331cb5e0ed46ab331d7dcfaf697fe95891e73dac4ebcb000000008c20ca42095840735e89283fec298e62ac2ddea9b5f34a8cbb7097ad965b87568100201b1b01dc829177da4a14551d2fc96a9db00c6501edfa12f22cd9cefd335c227f483045022100a9df60536df5733dd0de6bc921fab0b3eee6426501b43a228afa2c90072eb5ca02201c78b74266fac7d1db5deff080d8a403743203f109fbcabf6d5a760bf87386d20100ffffffff01c075790000000000232103611f9a45c18f28f06f19076ad571c344c82ce8fcfe34464cf8085217a2d294a6ac00000000',
43
- },
44
- description: 'A non-segwit transaction is read',
45
- expected: {
46
- id: 'cc60b1f899ec0a69b7c3f25ddf32c4524096a9c5b01cbd84c6d0312a0c478984',
47
- },
48
- },
49
- {
50
- args: {
51
- transaction: '0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000',
52
- },
53
- description: 'A P2PK transaction is read',
54
- expected: {
55
- id: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16',
56
- },
57
- },
58
- ];
59
-
60
- tests.forEach(({args, description, error, expected}) => {
61
- return test(description, (t, end) => {
62
- if (!!error) {
63
- throws(() => idForTransaction(args), new Error(error), 'Got err');
64
- } else {
65
- const res = idForTransaction(args);
66
-
67
- deepStrictEqual(res, expected, 'Got expected result');
68
- }
69
-
70
- return end();
71
- });
72
- });