@psf/bch-js 6.8.3 → 7.0.1

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 (111) hide show
  1. package/README.md +10 -28
  2. package/fix-docs-contrast.sh +38 -0
  3. package/package.json +37 -46
  4. package/src/address.js +12 -23
  5. package/src/bch-js.js +81 -48
  6. package/src/bitcoincash.js +10 -11
  7. package/src/blockchain.js +57 -68
  8. package/src/control.js +11 -22
  9. package/src/crypto.js +3 -3
  10. package/src/dsproof.js +6 -17
  11. package/src/ecash.js +1 -1
  12. package/src/ecpair.js +3 -3
  13. package/src/electrumx.js +32 -44
  14. package/src/encryption.js +8 -17
  15. package/src/generating.js +8 -19
  16. package/src/hdnode.js +5 -5
  17. package/src/mining.js +11 -22
  18. package/src/mnemonic.js +8 -11
  19. package/src/price.js +7 -108
  20. package/src/psf-slp-indexer.js +21 -32
  21. package/src/raw-transactions.js +22 -35
  22. package/src/schnorr.js +5 -16
  23. package/src/script.js +4 -2
  24. package/src/slp/address.js +4 -4
  25. package/src/slp/ecpair.js +4 -4
  26. package/src/slp/nft1.js +6 -6
  27. package/src/slp/slp.js +11 -22
  28. package/src/slp/tokentype1.js +11 -22
  29. package/src/slp/utils.js +9 -19
  30. package/src/transaction-builder.js +5 -5
  31. package/src/transaction.js +5 -5
  32. package/src/util.js +5 -98
  33. package/src/utxo.js +6 -6
  34. package/test/e2e/bch-js-e2e-tests.js +4 -3
  35. package/test/e2e/ipfs/ipfs-e2e.js +8 -2
  36. package/test/e2e/rate-limits/anonymous-rate-limits.js +5 -4
  37. package/test/e2e/rate-limits/basic-auth-rate-limits.js +4 -3
  38. package/test/e2e/rate-limits/free-rate-limits.js +4 -3
  39. package/test/e2e/rate-limits/full-node-rate-limits.js +4 -3
  40. package/test/e2e/rate-limits/indexer-rate-limits.js +4 -3
  41. package/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js +28 -18
  42. package/test/e2e/send-raw-transaction-single/sendrawtransaction.js +28 -18
  43. package/test/e2e/send-token/send-token.js +4 -4
  44. package/test/e2e/util/e2e-util.js +6 -3
  45. package/test/e2e/utxo/unsynced-indexer.js +1 -1
  46. package/test/integration/blockchain.js +5 -5
  47. package/test/integration/control.js +2 -2
  48. package/test/integration/{chains/bchn/dsproof.js → dsproof.js} +6 -2
  49. package/test/integration/electrumx.js +5 -12
  50. package/test/integration/price.js +3 -39
  51. package/test/integration/{chains/bchn/psf-slp-indexer.integration.js → psf-slp-indexer.integration.js} +5 -6
  52. package/test/integration/rawtransaction.js +39 -5
  53. package/test/integration/slp.js +147 -5
  54. package/test/integration/transaction-integration.js +27 -2
  55. package/test/integration/{chains/bchn/utxo-integration.js → utxo-integration.js} +3 -2
  56. package/test/unit/address.js +7 -4
  57. package/test/unit/bitcoin-cash.js +5 -3
  58. package/test/unit/blockchain.js +23 -22
  59. package/test/unit/control.js +6 -6
  60. package/test/unit/crypto.js +5 -3
  61. package/test/unit/dsproof.js +5 -4
  62. package/test/unit/ecash.js +3 -2
  63. package/test/unit/ecpairs.js +6 -4
  64. package/test/unit/electrumx.js +7 -7
  65. package/test/unit/encryption.js +6 -5
  66. package/test/unit/fixtures/bitcore-mock.js +1 -1
  67. package/test/unit/fixtures/block-mock.js +1 -1
  68. package/test/unit/fixtures/blockchain-mock.js +1 -1
  69. package/test/unit/fixtures/dsproof-mock.js +1 -1
  70. package/test/unit/fixtures/electrumx-mock.js +1 -1
  71. package/test/unit/fixtures/encryption-mock.js +1 -1
  72. package/test/unit/fixtures/ipfs-mock.js +1 -1
  73. package/test/unit/fixtures/openbazaar-mock.js +1 -1
  74. package/test/unit/fixtures/price-mocks.js +1 -1
  75. package/test/unit/fixtures/psf-slp-indexer-mock.js +1 -1
  76. package/test/unit/fixtures/rawtransaction-mock.js +1 -1
  77. package/test/unit/fixtures/slp/mock-utils.js +1 -1
  78. package/test/unit/fixtures/transaction-mock.js +1 -1
  79. package/test/unit/fixtures/utxo-mocks.js +1 -1
  80. package/test/unit/generating.js +5 -5
  81. package/test/unit/hdnode.js +6 -4
  82. package/test/unit/mining.js +8 -8
  83. package/test/unit/mnemonic.js +4 -2
  84. package/test/unit/price.js +5 -14
  85. package/test/unit/psf-slp-indexer.js +7 -7
  86. package/test/unit/raw-tranactions.js +14 -13
  87. package/test/unit/scripts.js +8 -6
  88. package/test/unit/slp-address.js +6 -4
  89. package/test/unit/slp-ecpair.js +5 -3
  90. package/test/unit/slp-nft1.js +7 -6
  91. package/test/unit/slp-tokentype1.js +7 -6
  92. package/test/unit/slp-utils.js +8 -7
  93. package/test/unit/transaction-builder.js +7 -4
  94. package/test/unit/transaction-unit.js +5 -4
  95. package/test/unit/util.js +11 -32
  96. package/test/unit/utxo-unit.js +6 -5
  97. package/test/unit/x402.js +193 -0
  98. package/test/integration/chains/abc/psf-slp-indexer-integration.js +0 -38
  99. package/test/integration/chains/abc/rawtransaction.js +0 -73
  100. package/test/integration/chains/abc/utxo-integration.js +0 -38
  101. package/test/integration/chains/bchn/rawtransaction.js +0 -71
  102. package/test/integration/chains/bchn/slp.js +0 -301
  103. package/test/integration/chains/bchn/transaction-integration.js +0 -37
  104. package/test/integration/chains/bchn/util.js +0 -103
  105. package/test/integration/chains/testnet/blockchain.js +0 -260
  106. package/test/integration/chains/testnet/control.js +0 -32
  107. package/test/integration/chains/testnet/electrumx.js +0 -376
  108. package/test/integration/chains/testnet/rawtransaction.js +0 -296
  109. package/test/integration/chains/testnet/slp.js +0 -172
  110. package/test/integration/chains/testnet/test-free-tier.sh +0 -9
  111. package/test/integration/chains/testnet/util.js +0 -109
@@ -1,296 +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
-
11
- const RESTURL = process.env.RESTURL
12
- ? process.env.RESTURL
13
- : 'https://testnet3.fullstack.cash/v5/'
14
- // if (process.env.RESTURL) RESTURL = process.env.RESTURL
15
-
16
- const BCHJS = require('../../../../src/bch-js')
17
- // const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v5/` })
18
- const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN })
19
-
20
- // Inspect utility used for debugging.
21
- const util = require('util')
22
- util.inspect.defaultOptions = {
23
- showHidden: true,
24
- colors: true,
25
- depth: 3
26
- }
27
-
28
- describe('#rawtransaction', () => {
29
- beforeEach(async () => {
30
- if (process.env.IS_USING_FREE_TIER) await sleep(1500)
31
- })
32
-
33
- describe('#decodeRawTransaction', () => {
34
- it('should decode tx for a single hex', async () => {
35
- const hex =
36
- '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000'
37
-
38
- const result = await bchjs.RawTransactions.decodeRawTransaction(hex)
39
- // console.log(`result ${JSON.stringify(result, null, 2)}`)
40
-
41
- assert.hasAnyKeys(result, [
42
- 'txid',
43
- 'hash',
44
- 'size',
45
- 'version',
46
- 'locktime',
47
- 'vin',
48
- 'vout'
49
- ])
50
- assert.isArray(result.vin)
51
- assert.isArray(result.vout)
52
- })
53
-
54
- it('should decode an array of tx hexes', async () => {
55
- const hexes = [
56
- '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000',
57
- '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000'
58
- ]
59
-
60
- const result = await bchjs.RawTransactions.decodeRawTransaction(hexes)
61
- // console.log(`result ${JSON.stringify(result, null, 2)}`)
62
-
63
- assert.isArray(result)
64
- assert.hasAnyKeys(result[0], [
65
- 'txid',
66
- 'hash',
67
- 'size',
68
- 'version',
69
- 'locktime',
70
- 'vin',
71
- 'vout'
72
- ])
73
- assert.isArray(result[0].vin)
74
- assert.isArray(result[0].vout)
75
- })
76
-
77
- it('should throw error on array size rate limit', async () => {
78
- try {
79
- const data = []
80
- for (let i = 0; i < 25; i++) {
81
- data.push(
82
- '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000'
83
- )
84
- }
85
-
86
- const result = await bchjs.RawTransactions.decodeRawTransaction(data)
87
-
88
- console.log(`result: ${util.inspect(result)}`)
89
- assert.equal(true, false, 'Unexpected result!')
90
- } catch (err) {
91
- assert.hasAnyKeys(err, ['error'])
92
- assert.include(err.error, 'Array too large')
93
- }
94
- })
95
- })
96
-
97
- describe('#getRawTransaction', () => {
98
- it('should decode a single txid, with concise output', async () => {
99
- const txid =
100
- '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04'
101
- const verbose = false
102
-
103
- const result = await bchjs.RawTransactions.getRawTransaction(
104
- txid,
105
- verbose
106
- )
107
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
108
-
109
- assert.isString(result)
110
- })
111
-
112
- it('should decode a single txid, with verbose output', async () => {
113
- const txid =
114
- '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04'
115
- const verbose = true
116
-
117
- const result = await bchjs.RawTransactions.getRawTransaction(
118
- txid,
119
- verbose
120
- )
121
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
122
-
123
- assert.hasAnyKeys(result, [
124
- 'hex',
125
- 'txid',
126
- 'hash',
127
- 'size',
128
- 'version',
129
- 'locktime',
130
- 'vin',
131
- 'vout',
132
- 'blockhash',
133
- 'confirmations',
134
- 'time',
135
- 'blocktime'
136
- ])
137
- assert.isArray(result.vin)
138
- assert.isArray(result.vout)
139
- })
140
-
141
- it('should decode an array of txids, with a concise output', async () => {
142
- const txid = [
143
- '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04',
144
- '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04'
145
- ]
146
- const verbose = false
147
-
148
- const result = await bchjs.RawTransactions.getRawTransaction(
149
- txid,
150
- verbose
151
- )
152
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
153
-
154
- assert.isArray(result)
155
- assert.isString(result[0])
156
- })
157
-
158
- it('should decode an array of txids, with a verbose output', async () => {
159
- const txid = [
160
- '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04',
161
- '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04'
162
- ]
163
- const verbose = true
164
-
165
- const result = await bchjs.RawTransactions.getRawTransaction(
166
- txid,
167
- verbose
168
- )
169
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
170
-
171
- assert.isArray(result)
172
- assert.hasAnyKeys(result[0], [
173
- 'hex',
174
- 'txid',
175
- 'hash',
176
- 'size',
177
- 'version',
178
- 'locktime',
179
- 'vin',
180
- 'vout',
181
- 'blockhash',
182
- 'confirmations',
183
- 'time',
184
- 'blocktime'
185
- ])
186
- assert.isArray(result[0].vin)
187
- assert.isArray(result[0].vout)
188
- })
189
-
190
- it('should throw error on array size limit', async () => {
191
- try {
192
- const dataMock =
193
- '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04'
194
- const data = []
195
- for (let i = 0; i < 25; i++) data.push(dataMock)
196
-
197
- const result = await bchjs.RawTransactions.getRawTransaction(data)
198
-
199
- console.log(`result: ${util.inspect(result)}`)
200
- assert.equal(true, false, 'Unexpected result!')
201
- } catch (err) {
202
- assert.hasAnyKeys(err, ['error'])
203
- assert.include(err.error, 'Array too large')
204
- }
205
- })
206
- })
207
-
208
- describe('#decodeScript', () => {
209
- it('should decode script for a single hex', async () => {
210
- const hex =
211
- '4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16'
212
-
213
- const result = await bchjs.RawTransactions.decodeScript(hex)
214
- // console.log(`result ${JSON.stringify(result, null, 2)}`)
215
-
216
- assert.hasAllKeys(result, ['asm', 'type', 'p2sh'])
217
- })
218
-
219
- // CT 2/20/19 - Waiting for this PR to be merged complete the test:
220
- // https://github.com/Bitcoin-com/rest.bitcoin.com/pull/312
221
- /*
222
- it("should decode an array of tx hexes", async () => {
223
- const hexes = [
224
- "4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16",
225
- "4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16"
226
- ]
227
-
228
- const result = await bchjs.RawTransactions.decodeScript(hexes)
229
- console.log(`result ${JSON.stringify(result, null, 2)}`)
230
- })
231
- */
232
- })
233
-
234
- /*
235
- Testing sentRawTransaction isn't really possible with an integration test,
236
- as the endpoint really needs an e2e test to be properly tested. The tests
237
- below expect error messages returned from the server, but at least test
238
- that the server is responding on those endpoints, and responds consistently.
239
- */
240
- describe('sendRawTransaction', () => {
241
- it('should send a single transaction hex', async () => {
242
- try {
243
- const hex =
244
- '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
245
-
246
- await bchjs.RawTransactions.sendRawTransaction(hex)
247
- // console.log(`result ${JSON.stringify(result, null, 2)}`)
248
-
249
- assert.equal(true, false, 'Unexpected result!')
250
- } catch (err) {
251
- // console.log(`err: ${util.inspect(err)}`)
252
-
253
- assert.hasAllKeys(err, ['error'])
254
- assert.include(err.error, 'Missing inputs')
255
- }
256
- })
257
-
258
- it('should send an array of tx hexes', async () => {
259
- try {
260
- const hexes = [
261
- '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000',
262
- '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
263
- ]
264
-
265
- const result = await bchjs.RawTransactions.sendRawTransaction(hexes)
266
- console.log(`result ${JSON.stringify(result, null, 2)}`)
267
- } catch (err) {
268
- // console.log(`err: ${util.inspect(err)}`)
269
-
270
- assert.hasAllKeys(err, ['error'])
271
- assert.include(err.error, 'Missing inputs')
272
- }
273
- })
274
-
275
- it('should throw error on array size rate limit', async () => {
276
- try {
277
- const dataMock =
278
- '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
279
- const data = []
280
- for (let i = 0; i < 25; i++) data.push(dataMock)
281
-
282
- const result = await bchjs.RawTransactions.sendRawTransaction(data)
283
-
284
- console.log(`result: ${util.inspect(result)}`)
285
- assert.equal(true, false, 'Unexpected result!')
286
- } catch (err) {
287
- assert.hasAnyKeys(err, ['error'])
288
- assert.include(err.error, 'Array too large')
289
- }
290
- })
291
- })
292
- })
293
-
294
- function sleep (ms) {
295
- return new Promise(resolve => setTimeout(resolve, ms))
296
- }
@@ -1,172 +0,0 @@
1
- /*
2
- Integration tests for the bchjs covering SLP tokens.
3
- */
4
-
5
- const chai = require('chai')
6
- const assert = chai.assert
7
-
8
- const RESTURL = process.env.RESTURL
9
- ? process.env.RESTURL
10
- : 'https://testnet3.fullstack.cash/v5/'
11
- // if (process.env.RESTURL) RESTURL = process.env.RESTURL
12
-
13
- const BCHJS = require('../../../../src/bch-js')
14
- // const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v5/` })
15
- const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN })
16
-
17
- // Inspect utility used for debugging.
18
- const util = require('util')
19
- util.inspect.defaultOptions = {
20
- showHidden: true,
21
- colors: true,
22
- depth: 1
23
- }
24
-
25
- describe('#SLP', () => {
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(1500)
29
- })
30
-
31
- describe('#util', () => {
32
- it('should get information on the Oasis token', async () => {
33
- const tokenId =
34
- 'a371e9934c7695d08a5eb7f31d3bceb4f3644860cc67520cda1e149423b9ec39'
35
-
36
- const result = await bchjs.SLP.Utils.list(tokenId)
37
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
38
-
39
- assert.hasAnyKeys(result, [
40
- 'decimals',
41
- 'timestamp',
42
- 'timestamp_unix',
43
- 'versionType',
44
- 'documentUri',
45
- 'symbol',
46
- 'name',
47
- 'containsBaton',
48
- 'id',
49
- 'documentHash',
50
- 'initialTokenQty',
51
- 'blockCreated',
52
- 'blockLastActiveSend',
53
- 'blockLastActiveMint',
54
- 'txnsSinceGenesis',
55
- 'validAddress',
56
- 'totalMinted',
57
- 'totalBurned',
58
- 'circulatingSupply',
59
- 'mintingBatonStatus'
60
- ])
61
- })
62
- })
63
-
64
- describe('#decodeOpReturn', () => {
65
- it('should decode the OP_RETURN for a SEND txid', async () => {
66
- const txid =
67
- 'ad28116e0818339342dddfc5f58ca8a5379ceb9679b4e4cbd72f4de905415ec1'
68
-
69
- const result = await bchjs.SLP.Utils.decodeOpReturn(txid)
70
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
71
-
72
- assert.hasAllKeys(result, ['amounts', 'tokenType', 'tokenId', 'txType'])
73
- })
74
- })
75
-
76
- describe('#balancesForAddress', () => {
77
- it('should fetch all balances for address: slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9', async () => {
78
- const balances = await bchjs.SLP.Utils.balancesForAddress(
79
- 'slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9'
80
- )
81
- // console.log(`balances: ${JSON.stringify(balances, null, 2)}`)
82
-
83
- assert.isArray(balances)
84
- assert.hasAllKeys(balances[0], [
85
- 'tokenId',
86
- 'balanceString',
87
- 'balance',
88
- 'decimalCount',
89
- 'slpAddress'
90
- ])
91
- })
92
-
93
- it('should fetch balances for multiple addresses', async () => {
94
- const addresses = [
95
- 'slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9',
96
- 'slptest:qr5uy4h8ysyhwkp9s245scckdnc7teyjqc5ft2z43h'
97
- ]
98
-
99
- const balances = await bchjs.SLP.Utils.balancesForAddress(addresses)
100
- // console.log(`balances: ${JSON.stringify(balances, null, 2)}`)
101
-
102
- assert.isArray(balances)
103
- assert.isArray(balances[0])
104
- assert.hasAllKeys(balances[0][0], [
105
- 'tokenId',
106
- 'balanceString',
107
- 'balance',
108
- 'decimalCount',
109
- 'slpAddress'
110
- ])
111
- })
112
- })
113
-
114
- describe('#tokenUtxoDetails', () => {
115
- it('should hydrate UTXOs', async () => {
116
- const bchAddr = bchjs.SLP.Address.toCashAddress(
117
- 'slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9'
118
- )
119
-
120
- const utxos = await bchjs.Electrumx.utxo([bchAddr])
121
- // console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
122
-
123
- const utxoInfo = await bchjs.SLP.Utils.tokenUtxoDetails(
124
- utxos.utxos[0].utxos
125
- )
126
- // console.log(`utxoInfo: ${JSON.stringify(utxoInfo, null, 2)}`)
127
-
128
- assert.isArray(utxoInfo)
129
-
130
- // first UTXO should be a PSF test token.
131
- assert.equal(utxoInfo[0].isValid, true)
132
- })
133
- })
134
-
135
- describe('#hydrateUtxos', () => {
136
- // This test will error out if the LOCAL_RESTURL settings is not set properly
137
- // in bch-api.
138
- it('should hydrate UTXOs', async () => {
139
- const bchAddr = bchjs.SLP.Address.toCashAddress(
140
- 'slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9'
141
- )
142
-
143
- const utxos = await bchjs.Electrumx.utxo([bchAddr])
144
- // console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
145
-
146
- const utxoInfo = await bchjs.SLP.Utils.hydrateUtxos(utxos.utxos)
147
- // console.log(`utxoInfo: ${JSON.stringify(utxoInfo, null, 2)}`)
148
-
149
- assert.isArray(utxoInfo.slpUtxos[0].utxos)
150
-
151
- // first UTXO should be a PSF test token.
152
- assert.equal(utxoInfo.slpUtxos[0].utxos[0].isValid, true)
153
- })
154
- })
155
-
156
- describe('#validateTxid2', () => {
157
- it('should validate a token txid', async () => {
158
- const txid =
159
- 'ad28116e0818339342dddfc5f58ca8a5379ceb9679b4e4cbd72f4de905415ec1'
160
-
161
- const validated = await bchjs.SLP.Utils.validateTxid(txid)
162
- // console.log(validated)
163
-
164
- assert.equal(validated[0].valid, true)
165
- })
166
- })
167
- })
168
-
169
- // Promise-based sleep function
170
- function sleep (ms) {
171
- return new Promise(resolve => setTimeout(resolve, ms))
172
- }
@@ -1,9 +0,0 @@
1
- #!/bin/bash
2
-
3
- export RESTURL=https://free-test.fullstack.cash/v5/
4
- export NETWORK=testnet
5
- export IS_USING_FREE_TIER=true
6
-
7
- cd test/integration/testnet/
8
- mocha --timeout 30000 blockchain.js control.js electrumx.js rawtransaction.js slp.js util.js
9
- #mocha --timeout 30000 blockchain.js
@@ -1,109 +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
-
9
- const RESTURL = process.env.RESTURL
10
- ? process.env.RESTURL
11
- : 'https://testnet3.fullstack.cash/v5/'
12
- // if (process.env.RESTURL) RESTURL = process.env.RESTURL
13
-
14
- const BCHJS = require('../../../../src/bch-js')
15
- // const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v5/` })
16
- const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN })
17
-
18
- // Inspect utility used for debugging.
19
- const util = require('util')
20
- util.inspect.defaultOptions = {
21
- showHidden: true,
22
- colors: true,
23
- depth: 3
24
- }
25
-
26
- describe('#util', () => {
27
- beforeEach(async () => {
28
- if (process.env.IS_USING_FREE_TIER) await sleep(1500)
29
- })
30
-
31
- describe('#validateAddress', () => {
32
- it('should return false for testnet addr on mainnet', async () => {
33
- const address = 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peu'
34
-
35
- const result = await bchjs.Util.validateAddress(address)
36
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
37
-
38
- assert.hasAllKeys(result, ['isvalid'])
39
- assert.equal(result.isvalid, false)
40
- })
41
-
42
- it('should return false for bad address', async () => {
43
- const address = 'bchtest:qqqk4y6lsl5da64sg53xezmplyu5kmpyz2ysaa5y'
44
-
45
- const result = await bchjs.Util.validateAddress(address)
46
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
47
-
48
- assert.hasAllKeys(result, ['isvalid'])
49
- assert.equal(result.isvalid, false)
50
- })
51
-
52
- it('should validate valid address', async () => {
53
- const address = 'bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y'
54
-
55
- const result = await bchjs.Util.validateAddress(address)
56
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
57
-
58
- assert.hasAnyKeys(result, [
59
- 'isvalid',
60
- 'address',
61
- 'scriptPubKey',
62
- // "ismine",
63
- // "iswatchonly",
64
- 'isscript'
65
- ])
66
- assert.equal(result.isvalid, true)
67
- })
68
-
69
- it('should validate an array of addresses', async () => {
70
- const address = [
71
- 'bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y',
72
- 'bchtest:pq6k9969f6v6sg7a75jkru4n7wn9sknv5cztcp0dnh'
73
- ]
74
-
75
- const result = await bchjs.Util.validateAddress(address)
76
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
77
-
78
- assert.isArray(result)
79
- assert.hasAnyKeys(result[0], [
80
- 'isvalid',
81
- 'address',
82
- 'scriptPubKey',
83
- // "ismine",
84
- // "iswatchonly",
85
- 'isscript'
86
- ])
87
- })
88
-
89
- it('should throw error on array size rate limit', async () => {
90
- try {
91
- const dataMock = 'bchtest:pq6k9969f6v6sg7a75jkru4n7wn9sknv5cztcp0dnh'
92
- const data = []
93
- for (let i = 0; i < 25; i++) data.push(dataMock)
94
-
95
- const result = await bchjs.Util.validateAddress(data)
96
-
97
- console.log(`result: ${util.inspect(result)}`)
98
- assert.equal(true, false, 'Unexpected result!')
99
- } catch (err) {
100
- assert.hasAnyKeys(err, ['error'])
101
- assert.include(err.error, 'Array too large')
102
- }
103
- })
104
- })
105
- })
106
-
107
- function sleep (ms) {
108
- return new Promise(resolve => setTimeout(resolve, ms))
109
- }