@alexbosworth/blockchain 4.7.2 → 4.9.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/CHANGELOG.md +8 -0
- package/README.md +51 -0
- package/addresses/decode_base58.js +119 -0
- package/addresses/decode_base58_address.js +3 -95
- package/addresses/index.js +2 -0
- package/index.js +4 -0
- package/package.json +12 -2
- package/script/conf/networks.json +22 -0
- package/script/index.js +2 -0
- package/script/output_script_for_address.js +96 -0
- package/.gitattributes +0 -1
- package/.tm_properties +0 -1
- package/test/5bit/test_bytes_as_words.js +0 -49
- package/test/5bit/test_words_as_bytes.js +0 -79
- package/test/addresses/test_bech32_type.js +0 -29
- package/test/addresses/test_decode_base58_address.js +0 -70
- package/test/addresses/test_decode_bech32.js +0 -49
- package/test/addresses/test_decode_bech32_address.js +0 -188
- package/test/addresses/test_encode_base58_address.js +0 -127
- package/test/addresses/test_encode_bech32.js +0 -69
- package/test/addresses/test_encode_bech32_address.js +0 -167
- package/test/fixtures/tx_invalid.json +0 -397
- package/test/fixtures/tx_valid.json +0 -528
- package/test/hashes/test_hash_for_p2pkh.js +0 -54
- package/test/hashes/test_hash_for_p2wpkh.js +0 -54
- package/test/hashes/test_id_for_block.js +0 -38
- package/test/hashes/test_no_locktime_id_for_transaction.js +0 -56
- package/test/hashes/test_previous_block_id.js +0 -38
- package/test/numbers/test_compact_int_as_number.js +0 -104
- package/test/numbers/test_encode_push_bytes_count.js +0 -82
- package/test/numbers/test_number_as_compact_int.js +0 -77
- package/test/numbers/test_number_as_little_endian.js +0 -77
- package/test/numbers/test_parse_push_bytes_count.js +0 -67
- package/test/script/test_p2ms_script.js +0 -106
- package/test/script/test_p2pkh_output_script.js +0 -41
- package/test/script/test_p2sh_output_script.js +0 -41
- package/test/script/test_p2tr_output_script.js +0 -43
- package/test/script/test_p2wpkh_output_script.js +0 -41
- package/test/script/test_p2wsh_output_script.js +0 -43
- package/test/script/test_script_as_script_elements.js +0 -84
- package/test/script/test_script_elements_as_script.js +0 -72
- package/test/transactions/test_components_of_transaction.js +0 -352
- package/test/transactions/test_core_tx_vectors.js +0 -70
- package/test/transactions/test_id_for_transaction.js +0 -72
- package/test/transactions/test_non_witness_hash_to_sign.js +0 -404
- package/test/transactions/test_query_transactions.js +0 -87
- package/test/transactions/test_size_of_transaction.js +0 -84
- package/test/transactions/test_transaction_from_components.js +0 -281
- package/test/transactions/test_unsigned_tx_from_psbt.js +0 -89
- package/test/transactions/test_v0_hash_to_sign.js +0 -262
|
@@ -1,404 +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 {nonWitnessHashToSign} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const anyOnePaysP2pkScriptCode = '21035e7f0d4d0841bcd56c39337ed086b1a633ee770c1ffdd94ac552a95ac2ce0efcac';
|
|
8
|
-
const anyOnePaysTransaction = '010000000200010000000000000000000000000000000000000000000000000000000000000000000049483045022100d180fd2eb9140aeb4210c9204d3f358766eb53842b2a9473db687fa24b12a3cc022079781799cd4f038b85135bbe49ec2b57f306b2bb17101b17f71f000fcab2b6fb01ffffffff0002000000000000000000000000000000000000000000000000000000000000000000004847304402205f7530653eea9b38699e476320ab135b74771e1c48b81a5d041e2ca84b9be7a802200ac8d1f40fb026674fe5a5edd3dea715c27baa9baca51ed45ea750ac9dc0a55e81ffffffff010100000000000000015100000000';
|
|
9
|
-
const changedSequenceTransaction = '01000000020001000000000000000000000000000000000000000000000000000000000000000000004948304502203a0f5f0e1f2bdbcd04db3061d18f3af70e07f4f467cbc1b8116f267025f5360b022100c792b6e215afc5afc721a351ec413e714305cb749aae3d7fee76621313418df101010000000002000000000000000000000000000000000000000000000000000000000000000000004847304402205f7530653eea9b38699e476320ab135b74771e1c48b81a5d041e2ca84b9be7a802200ac8d1f40fb026674fe5a5edd3dea715c27baa9baca51ed45ea750ac9dc0a55e81ffffffff010100000000000000015100000000';
|
|
10
|
-
const p2pkhScriptCode = '76a9141d0f172a0ecb48aee1be1f2687d2963ae33f71a188ac';
|
|
11
|
-
const singleAnyOnePaysP2pkScriptCode = '2103596d3451025c19dbbdeb932d6bf8bfb4ad499b95b6f88db8899efac102e5fc71ac';
|
|
12
|
-
const singleAnyOnePaysP2pkTransaction = '01000000020001000000000000000000000000000000000000000000000000000000000000000000004847304402202a0b4b1294d70540235ae033d78e64b4897ec859c7b6f1b2b1d8a02e1d46006702201445e756d2254b0f1dfda9ab8e1e1bc26df9668077403204f32d16a49a36eb6983ffffffff00010000000000000000000000000000000000000000000000000000000000000100000049483045022100acb96cfdbda6dc94b489fd06f2d720983b5f350e31ba906cdbd800773e80b21c02200d74ea5bdf114212b4bbe9ed82c36d2e369e302dff57cb60d01c428f0bd3daab83ffffffff02e8030000000000000151e903000000000000015100000000';
|
|
13
|
-
const singleAnyOnePaysTransaction = '010000000390d31c6107013d754529d8818eff285fe40a3e7635f6930fec5d12eb02107a43010000006b483045022100f40815ae3c81a0dd851cc8d376d6fd226c88416671346a9033468cca2cdcc6c202204f764623903e6c4bed1b734b75d82c40f1725e4471a55ad4f51218f86130ac038321033d710ab45bb54ac99618ad23b3c1da661631aa25f23bfe9d22b41876f1d46e4effffffff3ff04a68e22bdd52e7c8cb848156d2d158bd5515b3c50adabc87d0ca2cd3482d010000006a4730440220598d263c107004008e9e26baa1e770be30fd31ee55ded1898f7c00da05a75977022045536bead322ca246779698b9c3df3003377090f41afeca7fb2ce9e328ec4af2832102b738b531def73020bd637f32935924cc88549c8206976226d968edd3a42fc2d7ffffffff46a8dc8970eb96622f27a516adcf40e0fcec5731e7556e174f2a271aef6861c7010000006b483045022100c5b90a777a9fdc90c208dbef7290d1fc1be651f47151ee4ccff646872a454cf90220640cfbc4550446968fbbe9d12528f3adf7d87b31541569c59e790db8a220482583210391332546e22bbe8fe3af54addfad6f8b83d05fa4f5e047593d4c07ae938795beffffffff028036be26000000001976a914ddfb29efad43a667465ac59ff14dc6442a1adfca88ac3d5cba01000000001976a914b64dde7a505a13ca986c40e86e984a8dc81368b688ac00000000';
|
|
14
|
-
const singleScriptCode = '76a914dcf72c4fd02f5a987cf9b02f2fabfcac3341a87d88ac';
|
|
15
|
-
const singleTransaction = '010000000370ac0a1ae588aaf284c308d67ca92c69a39e2db81337e563bf40c59da0a5cf63000000006a4730440220360d20baff382059040ba9be98947fd678fb08aab2bb0c172efa996fd8ece9b702201b4fb0de67f015c90e7ac8a193aeab486a1f587e0f54d0fb9552ef7f5ce6caec032103579ca2e6d107522f012cd00b52b9a65fb46f0c57b9b8b6e377c48f526a44741affffffff7d815b6447e35fbea097e00e028fb7dfbad4f3f0987b4734676c84f3fcd0e804010000006b483045022100c714310be1e3a9ff1c5f7cacc65c2d8e781fc3a88ceb063c6153bf950650802102200b2d0979c76e12bb480da635f192cc8dc6f905380dd4ac1ff35a4f68f462fffd032103579ca2e6d107522f012cd00b52b9a65fb46f0c57b9b8b6e377c48f526a44741affffffff3f1f097333e4d46d51f5e77b53264db8f7f5d2e18217e1099957d0f5af7713ee010000006c493046022100b663499ef73273a3788dea342717c2640ac43c5a1cf862c9e09b206fcb3f6bb8022100b09972e75972d9148f2bdd462e5cb69b57c1214b88fc55ca638676c07cfc10d8032103579ca2e6d107522f012cd00b52b9a65fb46f0c57b9b8b6e377c48f526a44741affffffff0380841e00000000001976a914bfb282c70c4191f45b5a6665cad1682f2c9cfdfb88ac80841e00000000001976a9149857cc07bed33a5cf12b9c5e0500b675d500c81188ace0fd1c00000000001976a91443c52850606c872403c0601e69fa34b26f62db4a88ac00000000';
|
|
16
|
-
const twoInTwoOutTransaction = '0100000002fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f0000000000eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a0100000000ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093510d000000001976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac11000000';
|
|
17
|
-
|
|
18
|
-
const tests = [
|
|
19
|
-
{
|
|
20
|
-
args: {script: undefined},
|
|
21
|
-
description: 'A script code hex string is required',
|
|
22
|
-
error: 'ExpectedScriptCodeHexToCalculateNonWitnessHashToSign',
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
args: {script: '00', sighash: 0x04},
|
|
26
|
-
description: 'A known signature hash type is required',
|
|
27
|
-
error: 'ExpectedValidSigHashTypeForNonWitnessHashToSign',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
args: {script: '00', sighash: 0x01},
|
|
31
|
-
description: 'A transaction hex string is required',
|
|
32
|
-
error: 'ExpectedTransactionHexToCalculateNonWitnessHashToSign',
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
args: {script: '00', sighash: 0x01, transaction: twoInTwoOutTransaction},
|
|
36
|
-
description: 'An input index number is required',
|
|
37
|
-
error: 'ExpectedInputIndexToCalculateNonWitnessHashToSign',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
args: {
|
|
41
|
-
script: '00',
|
|
42
|
-
sighash: 0x01,
|
|
43
|
-
transaction: twoInTwoOutTransaction,
|
|
44
|
-
vin: 2,
|
|
45
|
-
},
|
|
46
|
-
description: 'A matching input is required',
|
|
47
|
-
error: 'ExpectedMatchingInputToCalculateNonWitnessHashToSign',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
args: {
|
|
51
|
-
script: '76a91434fea2c5a75414fd945273ae2d029ce1f28dafcf88ac',
|
|
52
|
-
sighash: 0x83,
|
|
53
|
-
transaction: singleAnyOnePaysTransaction,
|
|
54
|
-
vin: 2,
|
|
55
|
-
},
|
|
56
|
-
description: 'A single input past the outputs is refused not signed as one',
|
|
57
|
-
error: 'ExpectedMatchingOutputForSingleNonWitnessHashToSign',
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
args: {
|
|
61
|
-
script: '4c',
|
|
62
|
-
sighash: 0x01,
|
|
63
|
-
transaction: twoInTwoOutTransaction,
|
|
64
|
-
vin: 0,
|
|
65
|
-
},
|
|
66
|
-
description: 'A well formed script code is required',
|
|
67
|
-
error: 'ExpectedValidScriptCodeForNonWitnessHashToSign',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
args: {
|
|
71
|
-
script: '02ab',
|
|
72
|
-
sighash: 0x01,
|
|
73
|
-
transaction: twoInTwoOutTransaction,
|
|
74
|
-
vin: 0,
|
|
75
|
-
},
|
|
76
|
-
description: 'Complete script code push data bytes are required',
|
|
77
|
-
error: 'ExpectedValidScriptCodeForNonWitnessHashToSign',
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
args: {
|
|
81
|
-
script: '410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac',
|
|
82
|
-
sighash: 0x01,
|
|
83
|
-
transaction: '0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000',
|
|
84
|
-
vin: 0,
|
|
85
|
-
},
|
|
86
|
-
description: 'The first ever transaction signature hash is calculated',
|
|
87
|
-
expected: {
|
|
88
|
-
hash: '7a05c6145f10101e9d6325494245adf1297d80f8f38d4d576d57cdba220bcb19',
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
args: {
|
|
93
|
-
script: singleScriptCode,
|
|
94
|
-
sighash: 0x03,
|
|
95
|
-
transaction: singleTransaction,
|
|
96
|
-
vin: 0,
|
|
97
|
-
},
|
|
98
|
-
description: 'A mainnet single hash is calculated for the first input',
|
|
99
|
-
expected: {
|
|
100
|
-
hash: '465f0318f9801d56aeb1737d1e9af8e27d841a493b11494a9283477a1fdccc1e',
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
args: {
|
|
105
|
-
script: singleScriptCode,
|
|
106
|
-
sighash: 0x03,
|
|
107
|
-
transaction: singleTransaction,
|
|
108
|
-
vin: 1,
|
|
109
|
-
},
|
|
110
|
-
description: 'A mainnet single hash is calculated for the second input',
|
|
111
|
-
expected: {
|
|
112
|
-
hash: '3b8eee7ff2be39a1d7a69cfdfda487985caa090f33858a60de0b4df67ae84319',
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
args: {
|
|
117
|
-
script: singleScriptCode,
|
|
118
|
-
sighash: 0x03,
|
|
119
|
-
transaction: singleTransaction,
|
|
120
|
-
vin: 2,
|
|
121
|
-
},
|
|
122
|
-
description: 'A mainnet single hash is calculated for the third input',
|
|
123
|
-
expected: {
|
|
124
|
-
hash: 'd694785005d3292d4771695034ee3f07b4dc8a3bacfdb0ecf221a7a68d061f1c',
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
args: {
|
|
129
|
-
script: '76a914383fb81cb0a3fc724b5e08cf8bbd404336d711f688ac',
|
|
130
|
-
sighash: 0x83,
|
|
131
|
-
transaction: singleAnyOnePaysTransaction,
|
|
132
|
-
vin: 0,
|
|
133
|
-
},
|
|
134
|
-
description: 'A p2pkh single anyone can pay hash is calculated',
|
|
135
|
-
expected: {
|
|
136
|
-
hash: 'dc8584ae65a4ee4485d402bfadebb501077579adda20de321a1cbfb2a7dcff5b',
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
args: {
|
|
141
|
-
script: '76a914275ec2a233e5b23d43fa19e7bf9beb0cb399611788ac',
|
|
142
|
-
sighash: 0x83,
|
|
143
|
-
transaction: singleAnyOnePaysTransaction,
|
|
144
|
-
vin: 1,
|
|
145
|
-
},
|
|
146
|
-
description: 'A p2pkh single anyone can pay hash blanks the first output',
|
|
147
|
-
expected: {
|
|
148
|
-
hash: '2c0c915ab013457e84e8fedbd834d9c2c659c15caacb501c22eae52e65bd06da',
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
args: {
|
|
153
|
-
script: anyOnePaysP2pkScriptCode,
|
|
154
|
-
sighash: 0x01,
|
|
155
|
-
transaction: anyOnePaysTransaction,
|
|
156
|
-
vin: 0,
|
|
157
|
-
},
|
|
158
|
-
description: 'A p2pk hash is calculated for all beside an anyone can pay',
|
|
159
|
-
expected: {
|
|
160
|
-
hash: 'f69b639c5d2ee6f886701efaf4616daa84793a48d851d19434bb6a13dd6225cc',
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
args: {
|
|
165
|
-
script: anyOnePaysP2pkScriptCode,
|
|
166
|
-
sighash: 0x81,
|
|
167
|
-
transaction: anyOnePaysTransaction,
|
|
168
|
-
vin: 1,
|
|
169
|
-
},
|
|
170
|
-
description: 'A p2pk hash is calculated for all anyone can pay',
|
|
171
|
-
expected: {
|
|
172
|
-
hash: '57f5a54d548db73fa8ef7a43d011120f9935fe792f0a0630d28ee70b4c72a7e8',
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
args: {
|
|
177
|
-
script: anyOnePaysP2pkScriptCode,
|
|
178
|
-
sighash: 0x81,
|
|
179
|
-
transaction: changedSequenceTransaction,
|
|
180
|
-
vin: 1,
|
|
181
|
-
},
|
|
182
|
-
description: 'An anyone can pay hash ignores other input sequence changes',
|
|
183
|
-
expected: {
|
|
184
|
-
hash: '57f5a54d548db73fa8ef7a43d011120f9935fe792f0a0630d28ee70b4c72a7e8',
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
args: {
|
|
189
|
-
script: singleAnyOnePaysP2pkScriptCode,
|
|
190
|
-
sighash: 0x83,
|
|
191
|
-
transaction: singleAnyOnePaysP2pkTransaction,
|
|
192
|
-
vin: 0,
|
|
193
|
-
},
|
|
194
|
-
description: 'A single anyone can pay hash commits to the input position',
|
|
195
|
-
expected: {
|
|
196
|
-
hash: 'e67f282e8931e966e29d467b36d974cc67fa8cfbf8b230673e7dfa04d8213a95',
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
args: {
|
|
201
|
-
script: singleAnyOnePaysP2pkScriptCode,
|
|
202
|
-
sighash: 0x83,
|
|
203
|
-
transaction: singleAnyOnePaysP2pkTransaction,
|
|
204
|
-
vin: 1,
|
|
205
|
-
},
|
|
206
|
-
description: 'A single anyone can pay hash differs for the second input',
|
|
207
|
-
expected: {
|
|
208
|
-
hash: '63df76233203400e0af3395d8eba7fe3f98095bf1a0c0f5ac0d356981fb6033a',
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
args: {
|
|
213
|
-
script: 'ad',
|
|
214
|
-
sighash: 0x01,
|
|
215
|
-
transaction: '010000000169c12106097dc2e0526493ef67f21269fe888ef05c7a3a5dacab38e1ac8387f1581b0000b64830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0121037a3fb04bcdb09eba90f69961ba1692a3528e45e67c85b200df820212d7594d334aad4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01ffffffff0101000000000000000000000000',
|
|
216
|
-
vin: 0,
|
|
217
|
-
},
|
|
218
|
-
description: 'A p2sh redeem script code with a deleted signature is hashed',
|
|
219
|
-
expected: {
|
|
220
|
-
hash: '1ba1fe3bc90c5d1265460e684ce6774e324f0fabdf67619eda729e64e8b6bc08',
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
args: {
|
|
225
|
-
script: '52af75',
|
|
226
|
-
sighash: 0x01,
|
|
227
|
-
transaction: '01000000019275cb8d4a485ce95741c013f7c0d28722160008021bb469a11982d47a662896581b0000fd6f01004830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c03959601522102cd74a2809ffeeed0092bc124fd79836706e41f048db3f6ae9df8708cefb83a1c2102e615999372426e46fd107b76eaf007156a507584aa2cc21de9eee3bdbd26d36c4c9552af4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c0395960175ffffffff0101000000000000000000000000',
|
|
228
|
-
vin: 0,
|
|
229
|
-
},
|
|
230
|
-
description: 'A multisig redeem script code with deleted signatures is hashed',
|
|
231
|
-
expected: {
|
|
232
|
-
hash: '1d50f00ba4db2917b903b0ec5002e017343bb38876398c9510570f5dce099295',
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
args: {
|
|
237
|
-
script: p2pkhScriptCode,
|
|
238
|
-
sighash: 0x01,
|
|
239
|
-
transaction: twoInTwoOutTransaction,
|
|
240
|
-
vin: 0,
|
|
241
|
-
},
|
|
242
|
-
description: 'A non witness hash to sign is calculated for all',
|
|
243
|
-
expected: {
|
|
244
|
-
hash: '47194bc3c303a30aa5f78e45c7c2980b3be1284a9d69b1ea9ec0d29aac5f6848',
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
args: {
|
|
249
|
-
script: p2pkhScriptCode,
|
|
250
|
-
transaction: twoInTwoOutTransaction,
|
|
251
|
-
vin: 0,
|
|
252
|
-
},
|
|
253
|
-
description: 'A non witness hash to sign defaults to signing for all',
|
|
254
|
-
expected: {
|
|
255
|
-
hash: '47194bc3c303a30aa5f78e45c7c2980b3be1284a9d69b1ea9ec0d29aac5f6848',
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
args: {
|
|
260
|
-
script: p2pkhScriptCode,
|
|
261
|
-
sighash: 0x02,
|
|
262
|
-
transaction: twoInTwoOutTransaction,
|
|
263
|
-
vin: 1,
|
|
264
|
-
},
|
|
265
|
-
description: 'A non witness hash to sign is calculated for none',
|
|
266
|
-
expected: {
|
|
267
|
-
hash: 'ffbbcf554debe55f76a79db7d205edc891f194184a93a660366bb8f7facb89e2',
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
args: {
|
|
272
|
-
script: p2pkhScriptCode,
|
|
273
|
-
sighash: 0x03,
|
|
274
|
-
transaction: twoInTwoOutTransaction,
|
|
275
|
-
vin: 1,
|
|
276
|
-
},
|
|
277
|
-
description: 'A non witness hash to sign is calculated for single',
|
|
278
|
-
expected: {
|
|
279
|
-
hash: '33cd468bd6b82f04bcef180b748c521d6fdee3b11711a2f27b2e465915afaec2',
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
args: {
|
|
284
|
-
script: p2pkhScriptCode,
|
|
285
|
-
sighash: 0x81,
|
|
286
|
-
transaction: twoInTwoOutTransaction,
|
|
287
|
-
vin: 0,
|
|
288
|
-
},
|
|
289
|
-
description: 'A non witness hash is calculated for all anyone can pay',
|
|
290
|
-
expected: {
|
|
291
|
-
hash: '4e7de48ff097d47bb87912759ec9380049a160289f2b89d48a28887ee30a41d4',
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
args: {
|
|
296
|
-
script: p2pkhScriptCode,
|
|
297
|
-
sighash: 0x82,
|
|
298
|
-
transaction: twoInTwoOutTransaction,
|
|
299
|
-
vin: 1,
|
|
300
|
-
},
|
|
301
|
-
description: 'A non witness hash is calculated for none anyone can pay',
|
|
302
|
-
expected: {
|
|
303
|
-
hash: 'bd8ca4cb1ab60a8db8451bd58bc068a9abd5ea20a08029b38934c9d50c1d6721',
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
args: {
|
|
308
|
-
script: p2pkhScriptCode,
|
|
309
|
-
sighash: 0x83,
|
|
310
|
-
transaction: twoInTwoOutTransaction,
|
|
311
|
-
vin: 1,
|
|
312
|
-
},
|
|
313
|
-
description: 'A non witness hash is calculated for single anyone can pay',
|
|
314
|
-
expected: {
|
|
315
|
-
hash: '865c7791b88917498a4c402176c302f146c53a6c2f50ecda08548f515237dca6',
|
|
316
|
-
},
|
|
317
|
-
},
|
|
318
|
-
{
|
|
319
|
-
args: {
|
|
320
|
-
script: '00ab' + p2pkhScriptCode,
|
|
321
|
-
sighash: 0x01,
|
|
322
|
-
transaction: twoInTwoOutTransaction,
|
|
323
|
-
vin: 0,
|
|
324
|
-
},
|
|
325
|
-
description: 'A zero op code is kept in the committed script code',
|
|
326
|
-
expected: {
|
|
327
|
-
hash: 'bc2a4d64ca999408ad71506b90d27225e59e3bf3f1308a9f43e67c04a8515fbc',
|
|
328
|
-
},
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
args: {
|
|
332
|
-
script: '4c50' + 'ab'.repeat(80) + '75' + p2pkhScriptCode + 'ab',
|
|
333
|
-
sighash: 0x01,
|
|
334
|
-
transaction: twoInTwoOutTransaction,
|
|
335
|
-
vin: 0,
|
|
336
|
-
},
|
|
337
|
-
description: 'Separator bytes inside a push data 1 push are kept',
|
|
338
|
-
expected: {
|
|
339
|
-
hash: '64b2d0421e77f95ee403ff7eec49c2066af6fcfcbb8822e32a3813fe6878afd9',
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
{
|
|
343
|
-
args: {
|
|
344
|
-
script: 'ab4d0001' + 'ab'.repeat(256) + '75' + p2pkhScriptCode + 'ab',
|
|
345
|
-
sighash: 0x01,
|
|
346
|
-
transaction: twoInTwoOutTransaction,
|
|
347
|
-
vin: 0,
|
|
348
|
-
},
|
|
349
|
-
description: 'Separator bytes inside a push data 2 push are kept',
|
|
350
|
-
expected: {
|
|
351
|
-
hash: '778dffb8dc7acbbece56410ca48e663ba2e2c10ecb13509575d30f74a0a77f27',
|
|
352
|
-
},
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
args: {
|
|
356
|
-
script: p2pkhScriptCode,
|
|
357
|
-
sighash: 0x03,
|
|
358
|
-
transaction: twoInTwoOutTransaction,
|
|
359
|
-
vin: 0,
|
|
360
|
-
},
|
|
361
|
-
description: 'A single hash for the first input blanks no outputs',
|
|
362
|
-
expected: {
|
|
363
|
-
hash: '0d8ad17ba098be7eaf7efff778bb22e234805b5d370c996271a7f5ff7416f263',
|
|
364
|
-
},
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
args: {
|
|
368
|
-
script: p2pkhScriptCode,
|
|
369
|
-
sighash: 0x01,
|
|
370
|
-
transaction: 'ffffffff' + twoInTwoOutTransaction.slice(8),
|
|
371
|
-
vin: 0,
|
|
372
|
-
},
|
|
373
|
-
description: 'A negative version number is committed to as signed bytes',
|
|
374
|
-
expected: {
|
|
375
|
-
hash: '19ed79919ad5a3f911dec0e134b52ba4d9ac5a6b15bcbdd685ff146a8690c024',
|
|
376
|
-
},
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
args: {
|
|
380
|
-
script: 'ab' + p2pkhScriptCode + 'ab',
|
|
381
|
-
sighash: 0x01,
|
|
382
|
-
transaction: twoInTwoOutTransaction,
|
|
383
|
-
vin: 0,
|
|
384
|
-
},
|
|
385
|
-
description: 'Code separators are removed from the script code',
|
|
386
|
-
expected: {
|
|
387
|
-
hash: '47194bc3c303a30aa5f78e45c7c2980b3be1284a9d69b1ea9ec0d29aac5f6848',
|
|
388
|
-
},
|
|
389
|
-
},
|
|
390
|
-
];
|
|
391
|
-
|
|
392
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
393
|
-
return test(description, (t, end) => {
|
|
394
|
-
if (!!error) {
|
|
395
|
-
throws(() => nonWitnessHashToSign(args), new Error(error), 'Got error');
|
|
396
|
-
} else {
|
|
397
|
-
const res = nonWitnessHashToSign(args);
|
|
398
|
-
|
|
399
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
return end();
|
|
403
|
-
});
|
|
404
|
-
});
|
|
@@ -1,87 +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 {queryTransactions} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
{
|
|
11
|
-
args: {},
|
|
12
|
-
description: 'A block is required',
|
|
13
|
-
error: 'ExpectedHexEncodedBlockToQueryTransactions',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
args: {block: '00'.repeat(80), outputs: []},
|
|
17
|
-
description: 'A block with transaction data is required',
|
|
18
|
-
error: 'ExpectedBlockHeaderAndTransactionsToQueryTransactions',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
args: {
|
|
22
|
-
block: '00'.repeat(80) + 'fdffff' + '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff010100000000000000016a00000000',
|
|
23
|
-
outputs: [],
|
|
24
|
-
},
|
|
25
|
-
description: 'A block claiming more txs than the data holds is rejected',
|
|
26
|
-
error: 'UnexpectedTransactionCountForBlockDataLength',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
args: {
|
|
30
|
-
block: '00'.repeat(80) + '01' + '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff010100000000000000016a00000000' + 'ff',
|
|
31
|
-
outputs: [],
|
|
32
|
-
},
|
|
33
|
-
description: 'A block with extra data after the transactions is rejected',
|
|
34
|
-
error: 'UnexpectedDataAfterBlockTransactions',
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
args: {
|
|
38
|
-
block: '00'.repeat(80) + 'fd0201' + '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff010100000000000000016a00000000'.repeat(258),
|
|
39
|
-
outputs: ['6a'],
|
|
40
|
-
},
|
|
41
|
-
description: 'A block with a multi-byte transaction count is queried',
|
|
42
|
-
expected: {
|
|
43
|
-
outputs: Array.from({length: 258}, () => ({
|
|
44
|
-
script: '6a',
|
|
45
|
-
tokens: 1,
|
|
46
|
-
transaction_id: 'ac73f5333d533da8ff546e9e9fa255977fe117d025eef4bcf3f88b7010ca960d',
|
|
47
|
-
transaction_vout: 0,
|
|
48
|
-
})),
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
args: {
|
|
53
|
-
block: '00008020b43ebc848b8a78430f745b58dd0cfecb5a41fda1f9a0793833a98dad00000000cbbb00aa6ab7ea52d99e87088d2d80e7ca27f217f4cb8bc7ac635f17a1ff336900ccd364f4422e1906713cdb07010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff1a03bcb725012013090909200909200904686700c4ee5902000000ffffffff022162250000000000160014820d4a343a44e915c36494995c2899abe37418930000000000000000266a24aa21a9ed78afc412c2c7c1b3135c2a2473a6837068c5ea891e5068d396041057114a749501200000000000000000000000000000000000000000000000000000000000000000000000000100000001ce99c6498760022c4a268bb2bd553b71c5dd7e705ad47704ca2b8cdf72b2d755030000006b483045022100ca65bd58a725c83c3420874e4e0017562ef451f1df17eb42cfd35ee9dd28f98902204a6aafb47a2e1492e50cb0c7038000741d952e3770f9a1f9c9a6229c124e5e790121037435c194e9b01b3d7f7a2802d6684a3af68d05bbf4ec8f17021980d777691f1dfdffffff040000000000000000536a4c5054325bb3a276c4f8c7ecdccd704cf9a0e691db1364e66648672e23871de8b005816f3ec0ecda15e15dbec4e7f2be15f1e4e52e72c187deb36bd3b89d9793ea0e7c71e00025b7b9000f0025b12400114a10270000000000001976a914000000000000000000000000000000000000000088ac10270000000000001976a914000000000000000000000000000000000000000088acb2e8ae08000000001976a914ba27f99e007c7f605a8305e318c1abde3cd220ac88ac00000000010000000001014d4f50b9002361be3b82382e628e41ec29ffb5a28abec8a59ebbf4f28ba4675401000000171600142642be55762762143195a7eb3b965fcc47df9000ffffffff013b0d0000000000001600146ad03f5c84f201cbcbae045ffb9a8b9d769f83d40247304402205993d5c216bcb968c8ed1a99d67a3e4bcf54434c29ffc1bd72c49769d4814f6302200a40821effc9c1fb00d6de454b35244cb70f294b7f3971fee796b9a302f7efa1012103eadead8e5b3a54e36ad936096bd4ca8960ef753b2d81db9afb4ce7a458155e2e0000000002000000000101a4a1f7f07d0d95cd22e7039646133cb29d7b3c5ec55f86720f9cfbd0aa5d155001000000000000000002102700000000000017a91423269e856a01136288e09d8ea5049f5e64d56399872ca218000000000016001456ddc1cec4c3cf468646d6cc2d531d232d43dd4502473044022069f7f79e6c8cfe3ad43e9a5e3da0d77f93169bd4d98a9ef1f5d521340510d688022053b18b1914a40b2b60cb453d8421fa8f2d1c05c9f084b90f38092379276281c701210216243ae4738f200518bf8f0204f6b95e408aadd65f553bad98f0f8a9fd7472eb0000000002000000000102c9f48fe21843a24377835106e94e3ecee80e128027a4fa84d9371df56464b0190000000000fdffffffc9f48fe21843a24377835106e94e3ecee80e128027a4fa84d9371df56464b0190100000000fdffffff01e7170000000000001976a91459cada50314c829e19f5a7786f8ee0d4987f429d88ac0247304402204d578466dad41a451ac42a58bfb15b4ede988181ca384d3d7dfc158289dc369402205b35dd90b83ed4b02ccd300b370d57d3f919d4a100280ba9b2b68feef6f75e720121039757fd1ca6e33c3433cd8de13178dfd50f5688b688301a932cc4eba38e85e80c02473044022052dbdb28b87d8bed9edb8abc664452ad4bd85dd0c068f61a4bffa92a66748d090220674e642420b027c00dc3a0fcec74f53fdd31b9bcd76d20397ef9c8f61a45788c01210251db63b01e13ff7656cb606d732970b4760466162c83e041e018846c627760a1bab7250002000000011e43091d1b554f7e3ce175241aba175bf797996dda991bfdc34fc5cb8298ee5e010000006a473044022027af54aec1a603c1260312241f6cc27d49db4d79cb946a3fb56aff6c8e5e4132022022d3954e49699d369480624c3e8397fd361d9baffdd700d1e9882b465e523b670121021bc2b79284dca29127ed41021571fd3026157c01b4fef8824e94976592b165b3fdffffff0280d725000000000016001475f1d3e5088db87f9a336287cb55142d2062ada3ab72000000000000160014f5e5e9b3af38635bf6992f9732206d0ccb421e9ebbb7250001000000017c1194e8b17d9d26aaba8a78c2cd84490d96d5405619da3b2a9f454860b18911010000006b483045022100e1a219e719575a51e70ccfb06a1968dfd6d2055a3c46664ede399b8a3aab7f8902204b7994dec9e0a6f74e4db0d5a0a06738bd608476160c530392f8f220ad3cb4c6012103ef3f06ff6ea92d1b0a4693ed3f83ad45740b02259739e6427209cb88581416a0ffffffff0278350000000000001976a914e830afe90f87e5c561df7e66ef530d4dd8ea182088ac55d61300000000001976a914fe0f6279060ba6bc6a8b4375d7de8cf8b35a683788ac00000000',
|
|
54
|
-
},
|
|
55
|
-
description: 'An outputs array is required',
|
|
56
|
-
error: 'ExpectedArrayOfOutputsToQueryTransactionsInBlock',
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
args: {
|
|
60
|
-
block: '00008020b43ebc848b8a78430f745b58dd0cfecb5a41fda1f9a0793833a98dad00000000cbbb00aa6ab7ea52d99e87088d2d80e7ca27f217f4cb8bc7ac635f17a1ff336900ccd364f4422e1906713cdb07010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff1a03bcb725012013090909200909200904686700c4ee5902000000ffffffff022162250000000000160014820d4a343a44e915c36494995c2899abe37418930000000000000000266a24aa21a9ed78afc412c2c7c1b3135c2a2473a6837068c5ea891e5068d396041057114a749501200000000000000000000000000000000000000000000000000000000000000000000000000100000001ce99c6498760022c4a268bb2bd553b71c5dd7e705ad47704ca2b8cdf72b2d755030000006b483045022100ca65bd58a725c83c3420874e4e0017562ef451f1df17eb42cfd35ee9dd28f98902204a6aafb47a2e1492e50cb0c7038000741d952e3770f9a1f9c9a6229c124e5e790121037435c194e9b01b3d7f7a2802d6684a3af68d05bbf4ec8f17021980d777691f1dfdffffff040000000000000000536a4c5054325bb3a276c4f8c7ecdccd704cf9a0e691db1364e66648672e23871de8b005816f3ec0ecda15e15dbec4e7f2be15f1e4e52e72c187deb36bd3b89d9793ea0e7c71e00025b7b9000f0025b12400114a10270000000000001976a914000000000000000000000000000000000000000088ac10270000000000001976a914000000000000000000000000000000000000000088acb2e8ae08000000001976a914ba27f99e007c7f605a8305e318c1abde3cd220ac88ac00000000010000000001014d4f50b9002361be3b82382e628e41ec29ffb5a28abec8a59ebbf4f28ba4675401000000171600142642be55762762143195a7eb3b965fcc47df9000ffffffff013b0d0000000000001600146ad03f5c84f201cbcbae045ffb9a8b9d769f83d40247304402205993d5c216bcb968c8ed1a99d67a3e4bcf54434c29ffc1bd72c49769d4814f6302200a40821effc9c1fb00d6de454b35244cb70f294b7f3971fee796b9a302f7efa1012103eadead8e5b3a54e36ad936096bd4ca8960ef753b2d81db9afb4ce7a458155e2e0000000002000000000101a4a1f7f07d0d95cd22e7039646133cb29d7b3c5ec55f86720f9cfbd0aa5d155001000000000000000002102700000000000017a91423269e856a01136288e09d8ea5049f5e64d56399872ca218000000000016001456ddc1cec4c3cf468646d6cc2d531d232d43dd4502473044022069f7f79e6c8cfe3ad43e9a5e3da0d77f93169bd4d98a9ef1f5d521340510d688022053b18b1914a40b2b60cb453d8421fa8f2d1c05c9f084b90f38092379276281c701210216243ae4738f200518bf8f0204f6b95e408aadd65f553bad98f0f8a9fd7472eb0000000002000000000102c9f48fe21843a24377835106e94e3ecee80e128027a4fa84d9371df56464b0190000000000fdffffffc9f48fe21843a24377835106e94e3ecee80e128027a4fa84d9371df56464b0190100000000fdffffff01e7170000000000001976a91459cada50314c829e19f5a7786f8ee0d4987f429d88ac0247304402204d578466dad41a451ac42a58bfb15b4ede988181ca384d3d7dfc158289dc369402205b35dd90b83ed4b02ccd300b370d57d3f919d4a100280ba9b2b68feef6f75e720121039757fd1ca6e33c3433cd8de13178dfd50f5688b688301a932cc4eba38e85e80c02473044022052dbdb28b87d8bed9edb8abc664452ad4bd85dd0c068f61a4bffa92a66748d090220674e642420b027c00dc3a0fcec74f53fdd31b9bcd76d20397ef9c8f61a45788c01210251db63b01e13ff7656cb606d732970b4760466162c83e041e018846c627760a1bab7250002000000011e43091d1b554f7e3ce175241aba175bf797996dda991bfdc34fc5cb8298ee5e010000006a473044022027af54aec1a603c1260312241f6cc27d49db4d79cb946a3fb56aff6c8e5e4132022022d3954e49699d369480624c3e8397fd361d9baffdd700d1e9882b465e523b670121021bc2b79284dca29127ed41021571fd3026157c01b4fef8824e94976592b165b3fdffffff0280d725000000000016001475f1d3e5088db87f9a336287cb55142d2062ada3ab72000000000000160014f5e5e9b3af38635bf6992f9732206d0ccb421e9ebbb7250001000000017c1194e8b17d9d26aaba8a78c2cd84490d96d5405619da3b2a9f454860b18911010000006b483045022100e1a219e719575a51e70ccfb06a1968dfd6d2055a3c46664ede399b8a3aab7f8902204b7994dec9e0a6f74e4db0d5a0a06738bd608476160c530392f8f220ad3cb4c6012103ef3f06ff6ea92d1b0a4693ed3f83ad45740b02259739e6427209cb88581416a0ffffffff0278350000000000001976a914e830afe90f87e5c561df7e66ef530d4dd8ea182088ac55d61300000000001976a914fe0f6279060ba6bc6a8b4375d7de8cf8b35a683788ac00000000',
|
|
61
|
-
outputs: ['00146ad03f5c84f201cbcbae045ffb9a8b9d769f83d4'],
|
|
62
|
-
},
|
|
63
|
-
description: 'A block is queried for transaction outputs',
|
|
64
|
-
expected: {
|
|
65
|
-
outputs: [{
|
|
66
|
-
script: '00146ad03f5c84f201cbcbae045ffb9a8b9d769f83d4',
|
|
67
|
-
tokens: 3387,
|
|
68
|
-
transaction_id: 'e3a79c31b81c2852ff7eaf170900842e8060dba9afc1613f09a4b387793d56e0',
|
|
69
|
-
transaction_vout: 0,
|
|
70
|
-
}],
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
76
|
-
return test(description, (t, end) => {
|
|
77
|
-
if (!!error) {
|
|
78
|
-
throws(() => queryTransactions(args), new Error(error), 'Got err');
|
|
79
|
-
} else {
|
|
80
|
-
const res = queryTransactions(args);
|
|
81
|
-
|
|
82
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return end();
|
|
86
|
-
});
|
|
87
|
-
});
|
|
@@ -1,84 +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 {sizeOfTransaction} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const legacyTransaction = [
|
|
8
|
-
'02000000',
|
|
9
|
-
'01',
|
|
10
|
-
'0000000000000000000000000000000000000000000000000000000000000000',
|
|
11
|
-
'00000000',
|
|
12
|
-
'00',
|
|
13
|
-
'ffffffff',
|
|
14
|
-
'01',
|
|
15
|
-
'0100000000000000',
|
|
16
|
-
'01',
|
|
17
|
-
'51',
|
|
18
|
-
'00000000',
|
|
19
|
-
].join('');
|
|
20
|
-
|
|
21
|
-
const witnessTransaction = [
|
|
22
|
-
'02000000',
|
|
23
|
-
'0001',
|
|
24
|
-
'01',
|
|
25
|
-
'0000000000000000000000000000000000000000000000000000000000000000',
|
|
26
|
-
'00000000',
|
|
27
|
-
'00',
|
|
28
|
-
'ffffffff',
|
|
29
|
-
'01',
|
|
30
|
-
'0100000000000000',
|
|
31
|
-
'01',
|
|
32
|
-
'51',
|
|
33
|
-
'01',
|
|
34
|
-
'01',
|
|
35
|
-
'00',
|
|
36
|
-
'00000000',
|
|
37
|
-
].join('');
|
|
38
|
-
|
|
39
|
-
const tests = [
|
|
40
|
-
{
|
|
41
|
-
args: {transaction: ''},
|
|
42
|
-
description: 'A transaction is required',
|
|
43
|
-
error: 'ExpectedHexEncodedTransactionToGetSize',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
args: {transaction: '00f'},
|
|
47
|
-
description: 'An even-length transaction is required',
|
|
48
|
-
error: 'ExpectedHexEncodedTransactionToGetSize',
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
args: {transaction: 'not hex'},
|
|
52
|
-
description: 'A hex-encoded transaction is required',
|
|
53
|
-
error: 'ExpectedHexEncodedTransactionToGetSize',
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
args: {transaction: `${legacyTransaction}00`},
|
|
57
|
-
description: 'Data after the transaction is not accepted',
|
|
58
|
-
error: 'UnexpectedDataAfterTransactionToGetSize',
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
args: {transaction: legacyTransaction},
|
|
62
|
-
description: 'The size of a legacy transaction is returned',
|
|
63
|
-
expected: {vsize: 61, weight: 244},
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
args: {transaction: witnessTransaction},
|
|
67
|
-
description: 'The size of a witness transaction is returned',
|
|
68
|
-
expected: {vsize: 63, weight: 249},
|
|
69
|
-
},
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
73
|
-
return test(description, (t, end) => {
|
|
74
|
-
if (!!error) {
|
|
75
|
-
throws(() => sizeOfTransaction(args), new Error(error), 'Got error');
|
|
76
|
-
} else {
|
|
77
|
-
const res = sizeOfTransaction(args);
|
|
78
|
-
|
|
79
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return end();
|
|
83
|
-
});
|
|
84
|
-
});
|