@psf/bch-js 6.8.3 → 7.0.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 (112) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +10 -28
  3. package/fix-docs-contrast.sh +38 -0
  4. package/package.json +38 -47
  5. package/src/address.js +12 -23
  6. package/src/bch-js.js +81 -48
  7. package/src/bitcoincash.js +10 -11
  8. package/src/blockchain.js +57 -68
  9. package/src/control.js +11 -22
  10. package/src/crypto.js +3 -3
  11. package/src/dsproof.js +6 -17
  12. package/src/ecash.js +1 -1
  13. package/src/ecpair.js +3 -3
  14. package/src/electrumx.js +32 -44
  15. package/src/encryption.js +8 -17
  16. package/src/generating.js +8 -19
  17. package/src/hdnode.js +5 -5
  18. package/src/mining.js +11 -22
  19. package/src/mnemonic.js +8 -11
  20. package/src/price.js +7 -108
  21. package/src/psf-slp-indexer.js +21 -32
  22. package/src/raw-transactions.js +22 -35
  23. package/src/schnorr.js +5 -16
  24. package/src/script.js +4 -2
  25. package/src/slp/address.js +4 -4
  26. package/src/slp/ecpair.js +4 -4
  27. package/src/slp/nft1.js +6 -6
  28. package/src/slp/slp.js +11 -22
  29. package/src/slp/tokentype1.js +11 -22
  30. package/src/slp/utils.js +9 -19
  31. package/src/transaction-builder.js +5 -5
  32. package/src/transaction.js +5 -5
  33. package/src/util.js +5 -98
  34. package/src/utxo.js +6 -6
  35. package/test/e2e/bch-js-e2e-tests.js +4 -3
  36. package/test/e2e/ipfs/ipfs-e2e.js +8 -2
  37. package/test/e2e/rate-limits/anonymous-rate-limits.js +5 -4
  38. package/test/e2e/rate-limits/basic-auth-rate-limits.js +4 -3
  39. package/test/e2e/rate-limits/free-rate-limits.js +4 -3
  40. package/test/e2e/rate-limits/full-node-rate-limits.js +4 -3
  41. package/test/e2e/rate-limits/indexer-rate-limits.js +4 -3
  42. package/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js +28 -18
  43. package/test/e2e/send-raw-transaction-single/sendrawtransaction.js +28 -18
  44. package/test/e2e/send-token/send-token.js +4 -4
  45. package/test/e2e/util/e2e-util.js +6 -3
  46. package/test/e2e/utxo/unsynced-indexer.js +1 -1
  47. package/test/integration/blockchain.js +5 -5
  48. package/test/integration/control.js +2 -2
  49. package/test/integration/{chains/bchn/dsproof.js → dsproof.js} +6 -2
  50. package/test/integration/electrumx.js +5 -12
  51. package/test/integration/price.js +3 -39
  52. package/test/integration/{chains/bchn/psf-slp-indexer.integration.js → psf-slp-indexer.integration.js} +5 -6
  53. package/test/integration/rawtransaction.js +39 -5
  54. package/test/integration/slp.js +147 -5
  55. package/test/integration/transaction-integration.js +27 -2
  56. package/test/integration/{chains/bchn/utxo-integration.js → utxo-integration.js} +3 -2
  57. package/test/unit/address.js +7 -4
  58. package/test/unit/bitcoin-cash.js +5 -3
  59. package/test/unit/blockchain.js +23 -22
  60. package/test/unit/control.js +6 -6
  61. package/test/unit/crypto.js +5 -3
  62. package/test/unit/dsproof.js +5 -4
  63. package/test/unit/ecash.js +3 -2
  64. package/test/unit/ecpairs.js +6 -4
  65. package/test/unit/electrumx.js +7 -7
  66. package/test/unit/encryption.js +6 -5
  67. package/test/unit/fixtures/bitcore-mock.js +1 -1
  68. package/test/unit/fixtures/block-mock.js +1 -1
  69. package/test/unit/fixtures/blockchain-mock.js +1 -1
  70. package/test/unit/fixtures/dsproof-mock.js +1 -1
  71. package/test/unit/fixtures/electrumx-mock.js +1 -1
  72. package/test/unit/fixtures/encryption-mock.js +1 -1
  73. package/test/unit/fixtures/ipfs-mock.js +1 -1
  74. package/test/unit/fixtures/openbazaar-mock.js +1 -1
  75. package/test/unit/fixtures/price-mocks.js +1 -1
  76. package/test/unit/fixtures/psf-slp-indexer-mock.js +1 -1
  77. package/test/unit/fixtures/rawtransaction-mock.js +1 -1
  78. package/test/unit/fixtures/slp/mock-utils.js +1 -1
  79. package/test/unit/fixtures/transaction-mock.js +1 -1
  80. package/test/unit/fixtures/utxo-mocks.js +1 -1
  81. package/test/unit/generating.js +5 -5
  82. package/test/unit/hdnode.js +6 -4
  83. package/test/unit/mining.js +8 -8
  84. package/test/unit/mnemonic.js +4 -2
  85. package/test/unit/price.js +5 -14
  86. package/test/unit/psf-slp-indexer.js +7 -7
  87. package/test/unit/raw-tranactions.js +14 -13
  88. package/test/unit/scripts.js +8 -6
  89. package/test/unit/slp-address.js +6 -4
  90. package/test/unit/slp-ecpair.js +5 -3
  91. package/test/unit/slp-nft1.js +7 -6
  92. package/test/unit/slp-tokentype1.js +7 -6
  93. package/test/unit/slp-utils.js +8 -7
  94. package/test/unit/transaction-builder.js +7 -4
  95. package/test/unit/transaction-unit.js +5 -4
  96. package/test/unit/util.js +11 -32
  97. package/test/unit/utxo-unit.js +6 -5
  98. package/test/unit/x402.js +193 -0
  99. package/test/integration/chains/abc/psf-slp-indexer-integration.js +0 -38
  100. package/test/integration/chains/abc/rawtransaction.js +0 -73
  101. package/test/integration/chains/abc/utxo-integration.js +0 -38
  102. package/test/integration/chains/bchn/rawtransaction.js +0 -71
  103. package/test/integration/chains/bchn/slp.js +0 -301
  104. package/test/integration/chains/bchn/transaction-integration.js +0 -37
  105. package/test/integration/chains/bchn/util.js +0 -103
  106. package/test/integration/chains/testnet/blockchain.js +0 -260
  107. package/test/integration/chains/testnet/control.js +0 -32
  108. package/test/integration/chains/testnet/electrumx.js +0 -376
  109. package/test/integration/chains/testnet/rawtransaction.js +0 -296
  110. package/test/integration/chains/testnet/slp.js +0 -172
  111. package/test/integration/chains/testnet/test-free-tier.sh +0 -9
  112. package/test/integration/chains/testnet/util.js +0 -109
@@ -1,71 +0,0 @@
1
- /*
2
- Integration tests for the bchjs. Only covers calls made to
3
- rest.bitcoin.com.
4
-
5
- TODO
6
- */
7
-
8
- const chai = require('chai')
9
- const assert = chai.assert
10
- const BCHJS = require('../../../../src/bch-js')
11
- const bchjs = new BCHJS()
12
-
13
- // Inspect utility used for debugging.
14
- const util = require('util')
15
- util.inspect.defaultOptions = {
16
- showHidden: true,
17
- colors: true,
18
- depth: 3
19
- }
20
-
21
- describe('#rawtransaction', () => {
22
- beforeEach(async () => {
23
- if (process.env.IS_USING_FREE_TIER) await sleep(3000)
24
- })
25
-
26
- /*
27
- Testing sentRawTransaction isn't really possible with an integration test,
28
- as the endpoint really needs an e2e test to be properly tested. The tests
29
- below expect error messages returned from the server, but at least test
30
- that the server is responding on those endpoints, and responds consistently.
31
- */
32
- describe('sendRawTransaction', () => {
33
- it('should send a single transaction hex', async () => {
34
- try {
35
- const hex =
36
- '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
37
-
38
- await bchjs.RawTransactions.sendRawTransaction(hex)
39
- // console.log(`result ${JSON.stringify(result, null, 2)}`)
40
-
41
- assert.equal(true, false, 'Unexpected result!')
42
- } catch (err) {
43
- // console.log(`err: ${util.inspect(err)}`)
44
-
45
- assert.hasAllKeys(err, ['error'])
46
- assert.include(err.error, 'Missing inputs')
47
- }
48
- })
49
-
50
- it('should send an array of tx hexes', async () => {
51
- try {
52
- const hexes = [
53
- '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000',
54
- '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
55
- ]
56
-
57
- const result = await bchjs.RawTransactions.sendRawTransaction(hexes)
58
- console.log(`result ${JSON.stringify(result, null, 2)}`)
59
- } catch (err) {
60
- // console.log(`err: ${util.inspect(err)}`)
61
-
62
- assert.hasAllKeys(err, ['error'])
63
- assert.include(err.error, 'Missing inputs')
64
- }
65
- })
66
- })
67
- })
68
-
69
- function sleep (ms) {
70
- return new Promise(resolve => setTimeout(resolve, ms))
71
- }
@@ -1,301 +0,0 @@
1
- /*
2
- Integration tests for the bchjs covering SLP tokens.
3
- These tests are specific to the ABC chain.
4
- */
5
-
6
- const chai = require('chai')
7
- const assert = chai.assert
8
-
9
- const BCHJS = require('../../../../src/bch-js')
10
- let bchjs
11
-
12
- // Inspect utility used for debugging.
13
- const util = require('util')
14
- util.inspect.defaultOptions = {
15
- showHidden: true,
16
- colors: true,
17
- depth: 1
18
- }
19
-
20
- describe('#SLP', () => {
21
- // before(() => {
22
- // console.log(`bchjs.SLP.restURL: ${bchjs.SLP.restURL}`)
23
- // console.log(`bchjs.SLP.apiToken: ${bchjs.SLP.apiToken}`)
24
- // })
25
-
26
- beforeEach(async () => {
27
- // Introduce a delay so that the BVT doesn't trip the rate limits.
28
- if (process.env.IS_USING_FREE_TIER) await sleep(3000)
29
-
30
- bchjs = new BCHJS()
31
- })
32
-
33
- if (process.env.TESTSLP) {
34
- describe('#util', () => {
35
- describe('#decodeOpReturn', () => {
36
- it('should decode a NFT Child transaction', async () => {
37
- const txid =
38
- 'eeddccc4d716f04157ea132ac93a48040fea34a6b57f3d8f0cccb7d1a731ab2b'
39
-
40
- const data = await bchjs.SLP.Utils.decodeOpReturn(txid)
41
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
42
-
43
- assert.property(data, 'tokenType')
44
- assert.property(data, 'txType')
45
- assert.property(data, 'ticker')
46
- assert.property(data, 'name')
47
- assert.property(data, 'tokenId')
48
- assert.property(data, 'documentUri')
49
- assert.property(data, 'documentHash')
50
- assert.property(data, 'decimals')
51
- assert.property(data, 'mintBatonVout')
52
- assert.property(data, 'qty')
53
-
54
- assert.equal(data.tokenType, 65)
55
- assert.equal(data.mintBatonVout, 0)
56
- assert.equal(data.qty, '1')
57
- })
58
- })
59
-
60
- describe('#tokenUtxoDetails', () => {
61
- it('should handle a range of UTXO types', async () => {
62
- const utxos = [
63
- // Malformed SLP tx
64
- {
65
- note: 'Malformed SLP tx',
66
- tx_hash:
67
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
68
- tx_pos: 1,
69
- value: 546
70
- },
71
- // Normal TX (non-SLP)
72
- {
73
- note: 'Normal TX (non-SLP)',
74
- tx_hash:
75
- '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
76
- tx_pos: 0,
77
- value: 400000
78
- },
79
- // Valid PSF SLP tx
80
- {
81
- note: 'Valid PSF SLP tx',
82
- tx_hash:
83
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
84
- tx_pos: 1,
85
- value: 546
86
- },
87
- // Valid SLP token not in whitelist
88
- {
89
- note: 'Valid SLP token not in whitelist',
90
- tx_hash:
91
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
92
- tx_pos: 1,
93
- value: 546
94
- },
95
- // Token send on BCHN network.
96
- {
97
- note: 'Token send on BCHN network',
98
- tx_hash:
99
- '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019',
100
- tx_pos: 1,
101
- value: 546
102
- },
103
- // Token send on ABC network.
104
- {
105
- note: 'Token send on ABC network',
106
- tx_hash:
107
- '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d',
108
- tx_pos: 1,
109
- value: 546
110
- },
111
- // Known invalid SLP token send of PSF tokens.
112
- {
113
- note: 'Known invalid SLP token send of PSF tokens',
114
- tx_hash:
115
- '2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74',
116
- tx_pos: 1,
117
- value: 546
118
- }
119
- ]
120
-
121
- const data = await bchjs.SLP.Utils.tokenUtxoDetails(utxos)
122
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
123
-
124
- // Malformed SLP tx
125
- assert.equal(data[0].tx_hash, utxos[0].tx_hash)
126
- assert.equal(data[0].isValid, false)
127
-
128
- // Normal TX (non-SLP)
129
- assert.equal(data[1].tx_hash, utxos[1].tx_hash)
130
- assert.equal(data[1].isValid, false)
131
-
132
- // Valid PSF SLP tx
133
- assert.equal(data[2].tx_hash, utxos[2].tx_hash)
134
- assert.equal(data[2].isValid, true)
135
-
136
- // Valid SLP token not in whitelist
137
- assert.equal(data[3].tx_hash, utxos[3].tx_hash)
138
- assert.equal(data[3].isValid, true)
139
-
140
- // Token send on BCHN network
141
- assert.equal(data[4].tx_hash, utxos[4].tx_hash)
142
- assert.equal(data[4].isValid, true)
143
-
144
- // Token send on ABC network
145
- assert.equal(data[5].tx_hash, utxos[5].tx_hash)
146
- assert.equal(data[5].isValid, null)
147
-
148
- // Known invalid SLP token send of PSF tokens
149
- assert.equal(data[6].tx_hash, utxos[6].tx_hash)
150
- assert.equal(data[6].isValid, false)
151
- })
152
- })
153
-
154
- describe('#validateTxid3', () => {
155
- it('should invalidate a known invalid TXID', async () => {
156
- const txid =
157
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a'
158
-
159
- const result = await bchjs.SLP.Utils.validateTxid3(txid)
160
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
161
-
162
- assert.isArray(result)
163
-
164
- assert.property(result[0], 'txid')
165
- assert.equal(result[0].txid, txid)
166
-
167
- assert.property(result[0], 'valid')
168
- assert.equal(result[0].valid, null)
169
- })
170
-
171
- it('should validate a known valid TXID', async () => {
172
- const txid =
173
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd'
174
-
175
- const result = await bchjs.SLP.Utils.validateTxid3(txid)
176
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
177
-
178
- assert.isArray(result)
179
-
180
- assert.property(result[0], 'txid')
181
- assert.equal(result[0].txid, txid)
182
-
183
- assert.property(result[0], 'valid')
184
- assert.equal(result[0].valid, true)
185
- })
186
-
187
- it('should handle a mix of valid, invalid, and non-SLP txs', async () => {
188
- const txids = [
189
- // Malformed SLP tx
190
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
191
- // Normal TX (non-SLP)
192
- '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
193
- // Valid PSF SLP tx
194
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
195
- // Valid SLP token not in whitelist
196
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
197
- // Unprocessed SLP TX
198
- '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019'
199
- ]
200
-
201
- const result = await bchjs.SLP.Utils.validateTxid3(txids)
202
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
203
-
204
- assert.isArray(result)
205
-
206
- assert.equal(result[0].txid, txids[0])
207
- assert.equal(result[0].valid, null)
208
-
209
- assert.equal(result[1].txid, txids[1])
210
- assert.equal(result[1].valid, null)
211
-
212
- assert.equal(result[2].txid, txids[2])
213
- assert.equal(result[2].valid, true)
214
-
215
- // True in validateTxid() but null in validateTxid3()
216
- assert.equal(result[3].txid, txids[3])
217
- assert.equal(result[3].valid, null)
218
-
219
- // Note: This should change from null to true once SLPDB finishes indexing.
220
- assert.equal(result[4].txid, txids[4])
221
- assert.equal(result[4].valid, null)
222
- })
223
- })
224
-
225
- describe('#validateTxid', () => {
226
- it('should handle a mix of valid, invalid, and non-SLP txs', async () => {
227
- const txids = [
228
- // Malformed SLP tx
229
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
230
- // Normal TX (non-SLP)
231
- '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
232
- // Valid PSF SLP tx
233
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
234
- // Valid SLP token not in whitelist
235
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
236
- // Token send on BCHN network.
237
- '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019',
238
- // Token send on ABC network.
239
- '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d'
240
- ]
241
-
242
- const result = await bchjs.SLP.Utils.validateTxid(txids)
243
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
244
-
245
- assert.isArray(result)
246
-
247
- assert.equal(result[0].txid, txids[0])
248
- assert.equal(result[0].valid, null)
249
-
250
- assert.equal(result[1].txid, txids[1])
251
- assert.equal(result[1].valid, null)
252
-
253
- assert.equal(result[2].txid, txids[2])
254
- assert.equal(result[2].valid, true)
255
-
256
- // True in validateTxid() but null in validateTxid3()
257
- assert.equal(result[3].txid, txids[3])
258
- assert.equal(result[3].valid, true)
259
-
260
- assert.equal(result[4].txid, txids[4])
261
- assert.equal(result[4].valid, true)
262
-
263
- assert.equal(result[5].txid, txids[5])
264
- assert.equal(result[5].valid, null)
265
- })
266
- })
267
- })
268
- describe('#nft1', () => {
269
- describe('#listNFTGroupChildren', () => {
270
- it('should return array of children GENESIS transactions IDs', async () => {
271
- const groupId =
272
- '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a'
273
- const result = await bchjs.SLP.NFT1.listNFTGroupChildren(groupId)
274
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
275
- assert.property(result, 'nftChildren')
276
- assert.isArray(result.nftChildren)
277
- })
278
- })
279
- describe('#parentNFTGroup', () => {
280
- it('should return parent NFT group information', async () => {
281
- const tokenId =
282
- '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9'
283
- const result = await bchjs.SLP.NFT1.parentNFTGroup(tokenId)
284
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
285
- assert.property(result, 'nftGroup')
286
- assert.property(result.nftGroup, 'id')
287
- assert.property(result.nftGroup, 'name')
288
- assert.property(result.nftGroup, 'symbol')
289
- assert.property(result.nftGroup, 'documentUri')
290
- assert.property(result.nftGroup, 'versionType')
291
- assert.property(result.nftGroup, 'initialTokenQty')
292
- })
293
- })
294
- })
295
- }
296
- })
297
-
298
- // Promise-based sleep function
299
- function sleep (ms) {
300
- return new Promise(resolve => setTimeout(resolve, ms))
301
- }
@@ -1,37 +0,0 @@
1
- /*
2
- Integration tests for the transaction.js library.
3
- */
4
-
5
- const assert = require('chai').assert
6
- const BCHJS = require('../../../../src/bch-js')
7
- const bchjs = new BCHJS()
8
-
9
- describe('#Transaction', () => {
10
- beforeEach(async () => {
11
- if (process.env.IS_USING_FREE_TIER) await bchjs.Util.sleep(1000)
12
- })
13
-
14
- describe('#get', () => {
15
- it('should get a tx details for a non-SLP TX with an OP_RETURN', async () => {
16
- const txid =
17
- '01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b'
18
-
19
- const result = await bchjs.Transaction.get(txid)
20
- // console.log('result: ', result)
21
-
22
- assert.property(result.txData, 'txid')
23
- assert.property(result.txData, 'vin')
24
- assert.property(result.txData, 'vout')
25
- assert.equal(result.txData.isValidSlp, false)
26
- })
27
-
28
- it('should handle a coinbase transaction', async () => {
29
- const txid = 'cca1d2dd3a533d2f501448dec03face2cb2814afd59a533a611e9a2909f2302b'
30
-
31
- const details = await bchjs.Transaction.get(txid)
32
- // console.log(`details: ${JSON.stringify(details, null, 2)}`)
33
-
34
- assert.property(details.txData, 'txid')
35
- })
36
- })
37
- })
@@ -1,103 +0,0 @@
1
- /*
2
- Integration tests for the bchjs. Only covers calls made to
3
- rest.bitcoin.com.
4
- */
5
-
6
- const chai = require('chai')
7
- const assert = chai.assert
8
- const BCHJS = require('../../../../src/bch-js')
9
- const bchjs = new BCHJS()
10
-
11
- // Inspect utility used for debugging.
12
- const util = require('util')
13
- util.inspect.defaultOptions = {
14
- showHidden: true,
15
- colors: true,
16
- depth: 3
17
- }
18
-
19
- describe('#util', () => {
20
- beforeEach(async () => {
21
- if (process.env.IS_USING_FREE_TIER) await sleep(1500)
22
- })
23
-
24
- describe('#validateAddress', () => {
25
- it('should return false for testnet addr on mainnet', async () => {
26
- const address = 'bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y'
27
-
28
- const result = await bchjs.Util.validateAddress(address)
29
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
30
-
31
- assert.hasAllKeys(result, ['isvalid'])
32
- assert.equal(result.isvalid, false)
33
- })
34
-
35
- it('should return false for bad address', async () => {
36
- const address = 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peu'
37
-
38
- const result = await bchjs.Util.validateAddress(address)
39
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
40
-
41
- assert.hasAllKeys(result, ['isvalid'])
42
- assert.equal(result.isvalid, false)
43
- })
44
-
45
- it('should validate valid address', async () => {
46
- const address = 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z'
47
-
48
- const result = await bchjs.Util.validateAddress(address)
49
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
50
-
51
- assert.hasAnyKeys(result, [
52
- 'isvalid',
53
- 'address',
54
- 'scriptPubKey',
55
- // "ismine",
56
- // "iswatchonly",
57
- 'isscript'
58
- ])
59
- assert.equal(result.isvalid, true)
60
- })
61
-
62
- it('should validate an array of addresses', async () => {
63
- const address = [
64
- 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z',
65
- 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z'
66
- ]
67
-
68
- const result = await bchjs.Util.validateAddress(address)
69
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
70
-
71
- assert.isArray(result)
72
- assert.hasAnyKeys(result[0], [
73
- 'isvalid',
74
- 'address',
75
- 'scriptPubKey',
76
- // "ismine",
77
- // "iswatchonly",
78
- 'isscript'
79
- ])
80
- })
81
-
82
- it('should throw error on array size rate limit', async () => {
83
- try {
84
- const dataMock =
85
- 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z'
86
- const data = []
87
- for (let i = 0; i < 25; i++) data.push(dataMock)
88
-
89
- const result = await bchjs.Util.validateAddress(data)
90
-
91
- console.log(`result: ${util.inspect(result)}`)
92
- assert.equal(true, false, 'Unexpected result!')
93
- } catch (err) {
94
- assert.hasAnyKeys(err, ['error'])
95
- assert.include(err.error, 'Array too large')
96
- }
97
- })
98
- })
99
- })
100
-
101
- function sleep (ms) {
102
- return new Promise(resolve => setTimeout(resolve, ms))
103
- }