@psf/bch-js 6.8.2 → 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.
- package/README.md +10 -28
- package/fix-docs-contrast.sh +38 -0
- package/llm-bch-js.md +10451 -0
- package/package.json +37 -46
- package/src/address.js +12 -23
- package/src/bch-js.js +81 -48
- package/src/bitcoincash.js +10 -11
- package/src/blockchain.js +57 -68
- package/src/control.js +11 -22
- package/src/crypto.js +3 -3
- package/src/dsproof.js +6 -17
- package/src/ecash.js +1 -1
- package/src/ecpair.js +3 -3
- package/src/electrumx.js +32 -44
- package/src/encryption.js +8 -17
- package/src/generating.js +8 -19
- package/src/hdnode.js +5 -5
- package/src/mining.js +11 -22
- package/src/mnemonic.js +8 -11
- package/src/price.js +7 -108
- package/src/psf-slp-indexer.js +21 -32
- package/src/raw-transactions.js +22 -35
- package/src/schnorr.js +5 -16
- package/src/script.js +4 -2
- package/src/slp/address.js +4 -4
- package/src/slp/ecpair.js +4 -4
- package/src/slp/nft1.js +6 -6
- package/src/slp/slp.js +11 -22
- package/src/slp/tokentype1.js +11 -22
- package/src/slp/utils.js +9 -19
- package/src/transaction-builder.js +5 -5
- package/src/transaction.js +5 -5
- package/src/util.js +5 -98
- package/src/utxo.js +6 -6
- package/test/e2e/bch-js-e2e-tests.js +4 -3
- package/test/e2e/ipfs/ipfs-e2e.js +8 -2
- package/test/e2e/rate-limits/anonymous-rate-limits.js +5 -4
- package/test/e2e/rate-limits/basic-auth-rate-limits.js +4 -3
- package/test/e2e/rate-limits/free-rate-limits.js +4 -3
- package/test/e2e/rate-limits/full-node-rate-limits.js +4 -3
- package/test/e2e/rate-limits/indexer-rate-limits.js +4 -3
- package/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js +28 -18
- package/test/e2e/send-raw-transaction-single/sendrawtransaction.js +28 -18
- package/test/e2e/send-token/send-token.js +4 -4
- package/test/e2e/util/e2e-util.js +6 -3
- package/test/e2e/utxo/unsynced-indexer.js +1 -1
- package/test/integration/blockchain.js +5 -5
- package/test/integration/control.js +2 -2
- package/test/integration/{chains/bchn/dsproof.js → dsproof.js} +6 -2
- package/test/integration/electrumx.js +5 -12
- package/test/integration/price.js +3 -39
- package/test/integration/{chains/bchn/psf-slp-indexer.integration.js → psf-slp-indexer.integration.js} +5 -6
- package/test/integration/rawtransaction.js +39 -5
- package/test/integration/slp.js +147 -5
- package/test/integration/transaction-integration.js +27 -2
- package/test/integration/{chains/bchn/utxo-integration.js → utxo-integration.js} +3 -2
- package/test/unit/address.js +7 -4
- package/test/unit/bitcoin-cash.js +5 -3
- package/test/unit/blockchain.js +23 -22
- package/test/unit/control.js +6 -6
- package/test/unit/crypto.js +5 -3
- package/test/unit/dsproof.js +5 -4
- package/test/unit/ecash.js +3 -2
- package/test/unit/ecpairs.js +6 -4
- package/test/unit/electrumx.js +7 -7
- package/test/unit/encryption.js +6 -5
- package/test/unit/fixtures/bitcore-mock.js +1 -1
- package/test/unit/fixtures/block-mock.js +1 -1
- package/test/unit/fixtures/blockchain-mock.js +1 -1
- package/test/unit/fixtures/dsproof-mock.js +1 -1
- package/test/unit/fixtures/electrumx-mock.js +1 -1
- package/test/unit/fixtures/encryption-mock.js +1 -1
- package/test/unit/fixtures/ipfs-mock.js +1 -1
- package/test/unit/fixtures/openbazaar-mock.js +1 -1
- package/test/unit/fixtures/price-mocks.js +1 -1
- package/test/unit/fixtures/psf-slp-indexer-mock.js +1 -1
- package/test/unit/fixtures/rawtransaction-mock.js +1 -1
- package/test/unit/fixtures/slp/mock-utils.js +1 -1
- package/test/unit/fixtures/transaction-mock.js +1 -1
- package/test/unit/fixtures/utxo-mocks.js +1 -1
- package/test/unit/generating.js +5 -5
- package/test/unit/hdnode.js +6 -4
- package/test/unit/mining.js +8 -8
- package/test/unit/mnemonic.js +4 -2
- package/test/unit/price.js +5 -14
- package/test/unit/psf-slp-indexer.js +7 -7
- package/test/unit/raw-tranactions.js +14 -13
- package/test/unit/scripts.js +8 -6
- package/test/unit/slp-address.js +6 -4
- package/test/unit/slp-ecpair.js +5 -3
- package/test/unit/slp-nft1.js +7 -6
- package/test/unit/slp-tokentype1.js +7 -6
- package/test/unit/slp-utils.js +8 -7
- package/test/unit/transaction-builder.js +7 -4
- package/test/unit/transaction-unit.js +5 -4
- package/test/unit/util.js +11 -32
- package/test/unit/utxo-unit.js +6 -5
- package/test/unit/x402.js +193 -0
- package/test/integration/chains/abc/psf-slp-indexer-integration.js +0 -38
- package/test/integration/chains/abc/rawtransaction.js +0 -73
- package/test/integration/chains/abc/utxo-integration.js +0 -38
- package/test/integration/chains/bchn/rawtransaction.js +0 -71
- package/test/integration/chains/bchn/slp.js +0 -301
- package/test/integration/chains/bchn/transaction-integration.js +0 -37
- package/test/integration/chains/bchn/util.js +0 -103
- package/test/integration/chains/testnet/blockchain.js +0 -260
- package/test/integration/chains/testnet/control.js +0 -32
- package/test/integration/chains/testnet/electrumx.js +0 -376
- package/test/integration/chains/testnet/rawtransaction.js +0 -296
- package/test/integration/chains/testnet/slp.js +0 -172
- package/test/integration/chains/testnet/test-free-tier.sh +0 -9
- package/test/integration/chains/testnet/util.js +0 -109
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Integration tests for the bchjs. Only covers calls made to
|
|
3
|
-
rest.bitcoin.com.
|
|
4
|
-
|
|
5
|
-
TODO
|
|
6
|
-
- getMempoolEntry() only works on TXs in the mempool, so it needs to be part
|
|
7
|
-
of an e2e test to be properly tested.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const chai = require('chai')
|
|
11
|
-
const assert = chai.assert
|
|
12
|
-
|
|
13
|
-
const RESTURL = process.env.RESTURL
|
|
14
|
-
? process.env.RESTURL
|
|
15
|
-
: 'https://testnet3.fullstack.cash/v5/'
|
|
16
|
-
// if (process.env.RESTURL) RESTURL = process.env.RESTURL
|
|
17
|
-
|
|
18
|
-
const BCHJS = require('../../../../src/bch-js')
|
|
19
|
-
// const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v5/` })
|
|
20
|
-
const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN })
|
|
21
|
-
|
|
22
|
-
// Inspect utility used for debugging.
|
|
23
|
-
const util = require('util')
|
|
24
|
-
util.inspect.defaultOptions = {
|
|
25
|
-
showHidden: true,
|
|
26
|
-
colors: true,
|
|
27
|
-
depth: 3
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe('#blockchain', () => {
|
|
31
|
-
beforeEach(async () => {
|
|
32
|
-
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
describe('#getBestBlockHash', () => {
|
|
36
|
-
it('should GET best block hash', async () => {
|
|
37
|
-
const result = await bchjs.Blockchain.getBestBlockHash()
|
|
38
|
-
// console.log(`result: ${util.inspect(result)}`)
|
|
39
|
-
|
|
40
|
-
assert.isString(result)
|
|
41
|
-
assert.equal(result.length, 64, 'Specific hash length')
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
describe('#getBlockHeader', () => {
|
|
46
|
-
it('should GET block header for a single hash', async () => {
|
|
47
|
-
const hash =
|
|
48
|
-
'000000000000c57178ace90210289e6b5383134c5b5306e1cdd8395176e10aaf'
|
|
49
|
-
|
|
50
|
-
const result = await bchjs.Blockchain.getBlockHeader(hash)
|
|
51
|
-
|
|
52
|
-
assert.hasAllKeys(result, [
|
|
53
|
-
'hash',
|
|
54
|
-
'confirmations',
|
|
55
|
-
'height',
|
|
56
|
-
'version',
|
|
57
|
-
'versionHex',
|
|
58
|
-
'merkleroot',
|
|
59
|
-
'time',
|
|
60
|
-
'mediantime',
|
|
61
|
-
'nonce',
|
|
62
|
-
'bits',
|
|
63
|
-
'difficulty',
|
|
64
|
-
'chainwork',
|
|
65
|
-
'previousblockhash',
|
|
66
|
-
'nextblockhash',
|
|
67
|
-
'nTx'
|
|
68
|
-
])
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('should GET block headers for an array of hashes', async () => {
|
|
72
|
-
const hash = [
|
|
73
|
-
'000000000000c57178ace90210289e6b5383134c5b5306e1cdd8395176e10aaf',
|
|
74
|
-
'00000000000b7db4cbae48d852fcbef32f728014582094ad613fe12af6600ff2'
|
|
75
|
-
]
|
|
76
|
-
|
|
77
|
-
const result = await bchjs.Blockchain.getBlockHeader(hash)
|
|
78
|
-
|
|
79
|
-
assert.isArray(result)
|
|
80
|
-
assert.hasAllKeys(result[0], [
|
|
81
|
-
'hash',
|
|
82
|
-
'confirmations',
|
|
83
|
-
'height',
|
|
84
|
-
'version',
|
|
85
|
-
'versionHex',
|
|
86
|
-
'merkleroot',
|
|
87
|
-
'time',
|
|
88
|
-
'mediantime',
|
|
89
|
-
'nonce',
|
|
90
|
-
'bits',
|
|
91
|
-
'difficulty',
|
|
92
|
-
'chainwork',
|
|
93
|
-
'previousblockhash',
|
|
94
|
-
'nextblockhash',
|
|
95
|
-
'nTx'
|
|
96
|
-
])
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('should throw error on array size rate limit', async () => {
|
|
100
|
-
try {
|
|
101
|
-
const data = []
|
|
102
|
-
for (let i = 0; i < 25; i++) {
|
|
103
|
-
data.push(
|
|
104
|
-
'00000000000b7db4cbae48d852fcbef32f728014582094ad613fe12af6600ff2'
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
await bchjs.Blockchain.getBlockHeader(data)
|
|
109
|
-
|
|
110
|
-
// console.log(`result: ${util.inspect(result)}`)
|
|
111
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
112
|
-
} catch (err) {
|
|
113
|
-
assert.hasAnyKeys(err, ['error'])
|
|
114
|
-
assert.include(err.error, 'Array too large')
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
describe('#getMempoolEntry', () => {
|
|
120
|
-
/*
|
|
121
|
-
// To run this test, the txid must be unconfirmed.
|
|
122
|
-
const txid =
|
|
123
|
-
"defea04c38ee00cf73ad402984714ed22dc0dd99b2ae5cb50d791d94343ba79b"
|
|
124
|
-
|
|
125
|
-
it(`should GET single mempool entry`, async () => {
|
|
126
|
-
const result = await bchjs.Blockchain.getMempoolEntry(txid)
|
|
127
|
-
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
128
|
-
|
|
129
|
-
assert.hasAnyKeys(result, [
|
|
130
|
-
"size",
|
|
131
|
-
"fee",
|
|
132
|
-
"modifiedfee",
|
|
133
|
-
"time",
|
|
134
|
-
"height",
|
|
135
|
-
"startingpriority",
|
|
136
|
-
"currentpriority",
|
|
137
|
-
"descendantcount",
|
|
138
|
-
"descendantsize",
|
|
139
|
-
"descendantfees",
|
|
140
|
-
"ancestorcount",
|
|
141
|
-
"ancestorsize",
|
|
142
|
-
"ancestorfees",
|
|
143
|
-
"depends"
|
|
144
|
-
])
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
it(`should get an array of mempool entries`, async () => {
|
|
148
|
-
const result = await bchjs.Blockchain.getMempoolEntry([txid, txid])
|
|
149
|
-
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
150
|
-
|
|
151
|
-
assert.isArray(result)
|
|
152
|
-
assert.hasAnyKeys(result[0], [
|
|
153
|
-
"size",
|
|
154
|
-
"fee",
|
|
155
|
-
"modifiedfee",
|
|
156
|
-
"time",
|
|
157
|
-
"height",
|
|
158
|
-
"startingpriority",
|
|
159
|
-
"currentpriority",
|
|
160
|
-
"descendantcount",
|
|
161
|
-
"descendantsize",
|
|
162
|
-
"descendantfees",
|
|
163
|
-
"ancestorcount",
|
|
164
|
-
"ancestorsize",
|
|
165
|
-
"ancestorfees",
|
|
166
|
-
"depends"
|
|
167
|
-
])
|
|
168
|
-
})
|
|
169
|
-
*/
|
|
170
|
-
|
|
171
|
-
it('should throw an error if txid is not in mempool', async () => {
|
|
172
|
-
try {
|
|
173
|
-
const txid =
|
|
174
|
-
'1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04'
|
|
175
|
-
|
|
176
|
-
await bchjs.Blockchain.getMempoolEntry(txid)
|
|
177
|
-
|
|
178
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
179
|
-
} catch (err) {
|
|
180
|
-
// console.log(`err: ${util.inspect(err)}`)
|
|
181
|
-
assert.hasAnyKeys(err, ['error'])
|
|
182
|
-
assert.include(err.error, 'Transaction not in mempool')
|
|
183
|
-
}
|
|
184
|
-
})
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
describe('#getTxOutProof', () => {
|
|
188
|
-
it('should get single tx out proof', async () => {
|
|
189
|
-
const txid =
|
|
190
|
-
'1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04'
|
|
191
|
-
|
|
192
|
-
const result = await bchjs.Blockchain.getTxOutProof(txid)
|
|
193
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
194
|
-
|
|
195
|
-
assert.isString(result)
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
it('should get an array of tx out proofs', async () => {
|
|
199
|
-
const txid = [
|
|
200
|
-
'1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04',
|
|
201
|
-
'fc4f696c0ebb3d0994b3975f57d85be75ef752b9fd52c17e361ec3be2fa3e752'
|
|
202
|
-
]
|
|
203
|
-
|
|
204
|
-
const result = await bchjs.Blockchain.getTxOutProof(txid)
|
|
205
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
206
|
-
|
|
207
|
-
assert.isArray(result)
|
|
208
|
-
assert.isString(result[0])
|
|
209
|
-
})
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
describe('#verifyTxOutProof', () => {
|
|
213
|
-
const mockTxOutProof =
|
|
214
|
-
'00000020ac86ce8f2bda235c0dc135d18f6a777c44b121e8f41db8a51ca65000000000000cd4de3c49337712f3a1092c47c3bf73ec2f9b1cfd289ee991ede0b6eab4df229d5b8c5dffff001d82ce005b0700000003ec55d9142eac2c1d2229e5af24898b2590c111b62e2787fa1998d3d713fd432fd557124ed758fa156a6cdc6d317d5575aec2b86dfb159c62ecb4743f28bef1cb52e7a32fbec31e367ec152fdb952f75ee75bd8575f97b394093dbb0e6c694ffc0135'
|
|
215
|
-
|
|
216
|
-
it('should verify a single proof', async () => {
|
|
217
|
-
const result = await bchjs.Blockchain.verifyTxOutProof(mockTxOutProof)
|
|
218
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
219
|
-
|
|
220
|
-
assert.isArray(result)
|
|
221
|
-
assert.isString(result[0])
|
|
222
|
-
assert.equal(
|
|
223
|
-
result[0],
|
|
224
|
-
'fc4f696c0ebb3d0994b3975f57d85be75ef752b9fd52c17e361ec3be2fa3e752'
|
|
225
|
-
)
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
it('should verify an array of proofs', async () => {
|
|
229
|
-
const proofs = [mockTxOutProof, mockTxOutProof]
|
|
230
|
-
const result = await bchjs.Blockchain.verifyTxOutProof(proofs)
|
|
231
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
232
|
-
|
|
233
|
-
assert.isArray(result)
|
|
234
|
-
assert.isString(result[0])
|
|
235
|
-
assert.equal(
|
|
236
|
-
result[0],
|
|
237
|
-
'fc4f696c0ebb3d0994b3975f57d85be75ef752b9fd52c17e361ec3be2fa3e752'
|
|
238
|
-
)
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
it('should throw error on array size rate limit', async () => {
|
|
242
|
-
try {
|
|
243
|
-
const data = []
|
|
244
|
-
for (let i = 0; i < 25; i++) data.push(mockTxOutProof)
|
|
245
|
-
|
|
246
|
-
const result = await bchjs.Blockchain.verifyTxOutProof(data)
|
|
247
|
-
|
|
248
|
-
console.log(`result: ${util.inspect(result)}`)
|
|
249
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
250
|
-
} catch (err) {
|
|
251
|
-
assert.hasAnyKeys(err, ['error'])
|
|
252
|
-
assert.include(err.error, 'Array too large')
|
|
253
|
-
}
|
|
254
|
-
})
|
|
255
|
-
})
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
function sleep (ms) {
|
|
259
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
260
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Integration tests for bchjs control library.
|
|
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
|
-
|
|
12
|
-
const BCHJS = require('../../../../src/bch-js')
|
|
13
|
-
const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN })
|
|
14
|
-
|
|
15
|
-
describe('#control', () => {
|
|
16
|
-
beforeEach(async () => {
|
|
17
|
-
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
describe('#getNetworkInfo', () => {
|
|
21
|
-
it('should get info on the full node', async () => {
|
|
22
|
-
const result = await bchjs.Control.getNetworkInfo()
|
|
23
|
-
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
24
|
-
|
|
25
|
-
assert.property(result, 'version')
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
function sleep (ms) {
|
|
31
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
32
|
-
}
|
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
const chai = require('chai')
|
|
2
|
-
const assert = chai.assert
|
|
3
|
-
const sinon = require('sinon')
|
|
4
|
-
const util = require('util')
|
|
5
|
-
|
|
6
|
-
const RESTURL = process.env.RESTURL
|
|
7
|
-
? process.env.RESTURL
|
|
8
|
-
: 'https://testnet3.fullstack.cash/v5/'
|
|
9
|
-
|
|
10
|
-
const BCHJS = require('../../../../src/bch-js')
|
|
11
|
-
const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN })
|
|
12
|
-
|
|
13
|
-
describe('#ElectrumX', () => {
|
|
14
|
-
let sandbox
|
|
15
|
-
|
|
16
|
-
beforeEach(async () => {
|
|
17
|
-
sandbox = sinon.createSandbox()
|
|
18
|
-
|
|
19
|
-
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
afterEach(() => sandbox.restore())
|
|
23
|
-
|
|
24
|
-
describe('#utxo', () => {
|
|
25
|
-
it('should GET utxos for a single address', async () => {
|
|
26
|
-
const addr = 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2'
|
|
27
|
-
|
|
28
|
-
const result = await bchjs.Electrumx.utxo(addr)
|
|
29
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
30
|
-
|
|
31
|
-
assert.property(result, 'success')
|
|
32
|
-
assert.equal(result.success, true)
|
|
33
|
-
|
|
34
|
-
assert.property(result, 'utxos')
|
|
35
|
-
assert.isArray(result.utxos)
|
|
36
|
-
|
|
37
|
-
assert.property(result.utxos[0], 'height')
|
|
38
|
-
assert.property(result.utxos[0], 'tx_hash')
|
|
39
|
-
assert.property(result.utxos[0], 'tx_pos')
|
|
40
|
-
assert.property(result.utxos[0], 'value')
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('should POST utxo details for an array of addresses', async () => {
|
|
44
|
-
const addr = [
|
|
45
|
-
'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2',
|
|
46
|
-
'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2'
|
|
47
|
-
]
|
|
48
|
-
|
|
49
|
-
const result = await bchjs.Electrumx.utxo(addr)
|
|
50
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
51
|
-
|
|
52
|
-
assert.property(result, 'success')
|
|
53
|
-
assert.equal(result.success, true)
|
|
54
|
-
|
|
55
|
-
assert.property(result, 'utxos')
|
|
56
|
-
assert.isArray(result.utxos)
|
|
57
|
-
|
|
58
|
-
assert.property(result.utxos[0], 'utxos')
|
|
59
|
-
assert.isArray(result.utxos[0].utxos)
|
|
60
|
-
assert.property(result.utxos[0], 'address')
|
|
61
|
-
|
|
62
|
-
assert.property(result.utxos[0].utxos[0], 'height')
|
|
63
|
-
assert.property(result.utxos[0].utxos[0], 'tx_hash')
|
|
64
|
-
assert.property(result.utxos[0].utxos[0], 'tx_pos')
|
|
65
|
-
assert.property(result.utxos[0].utxos[0], 'value')
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('should throw error on array size rate limit', async () => {
|
|
69
|
-
try {
|
|
70
|
-
const addr = []
|
|
71
|
-
for (let i = 0; i < 25; i++) {
|
|
72
|
-
addr.push('bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2')
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// const result = await bchjs.Electrumx.utxo(addr)
|
|
76
|
-
// console.log(`result: ${util.inspect(result)}`)
|
|
77
|
-
await bchjs.Electrumx.utxo(addr)
|
|
78
|
-
|
|
79
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
80
|
-
} catch (err) {
|
|
81
|
-
assert.hasAnyKeys(err, ['error'])
|
|
82
|
-
assert.include(err.error, 'Array too large')
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
describe('#balance', () => {
|
|
88
|
-
it('should GET balance for a single address', async () => {
|
|
89
|
-
const addr = 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2'
|
|
90
|
-
|
|
91
|
-
const result = await bchjs.Electrumx.balance(addr)
|
|
92
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
93
|
-
|
|
94
|
-
assert.property(result, 'success')
|
|
95
|
-
assert.equal(result.success, true)
|
|
96
|
-
|
|
97
|
-
assert.property(result, 'balance')
|
|
98
|
-
assert.property(result.balance, 'confirmed')
|
|
99
|
-
assert.property(result.balance, 'unconfirmed')
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('should POST request for balances for an array of addresses', async () => {
|
|
103
|
-
const addr = [
|
|
104
|
-
'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2',
|
|
105
|
-
'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2'
|
|
106
|
-
]
|
|
107
|
-
|
|
108
|
-
const result = await bchjs.Electrumx.balance(addr)
|
|
109
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
110
|
-
|
|
111
|
-
assert.property(result, 'success')
|
|
112
|
-
assert.equal(result.success, true)
|
|
113
|
-
|
|
114
|
-
assert.property(result, 'balances')
|
|
115
|
-
assert.isArray(result.balances)
|
|
116
|
-
|
|
117
|
-
assert.property(result.balances[0], 'address')
|
|
118
|
-
assert.property(result.balances[0], 'balance')
|
|
119
|
-
assert.property(result.balances[0].balance, 'confirmed')
|
|
120
|
-
assert.property(result.balances[0].balance, 'unconfirmed')
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('should throw error on array size rate limit', async () => {
|
|
124
|
-
try {
|
|
125
|
-
const addr = []
|
|
126
|
-
for (let i = 0; i < 25; i++) {
|
|
127
|
-
addr.push('bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2')
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const result = await bchjs.Electrumx.balance(addr)
|
|
131
|
-
|
|
132
|
-
console.log(`result: ${util.inspect(result)}`)
|
|
133
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
134
|
-
} catch (err) {
|
|
135
|
-
assert.hasAnyKeys(err, ['error'])
|
|
136
|
-
assert.include(err.error, 'Array too large')
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
describe('#transactions', () => {
|
|
142
|
-
it('should GET transaction history for a single address', async () => {
|
|
143
|
-
const addr = 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2'
|
|
144
|
-
|
|
145
|
-
const result = await bchjs.Electrumx.transactions(addr)
|
|
146
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
147
|
-
|
|
148
|
-
assert.property(result, 'success')
|
|
149
|
-
assert.equal(result.success, true)
|
|
150
|
-
|
|
151
|
-
assert.property(result, 'transactions')
|
|
152
|
-
assert.isArray(result.transactions)
|
|
153
|
-
assert.property(result.transactions[0], 'height')
|
|
154
|
-
assert.property(result.transactions[0], 'tx_hash')
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
it('should POST request for transaction history for an array of addresses', async () => {
|
|
158
|
-
const addr = [
|
|
159
|
-
'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2',
|
|
160
|
-
'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2'
|
|
161
|
-
]
|
|
162
|
-
|
|
163
|
-
const result = await bchjs.Electrumx.transactions(addr)
|
|
164
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
165
|
-
|
|
166
|
-
assert.property(result, 'success')
|
|
167
|
-
assert.equal(result.success, true)
|
|
168
|
-
|
|
169
|
-
assert.property(result, 'transactions')
|
|
170
|
-
assert.isArray(result.transactions)
|
|
171
|
-
|
|
172
|
-
assert.property(result.transactions[0], 'address')
|
|
173
|
-
assert.property(result.transactions[0], 'transactions')
|
|
174
|
-
assert.isArray(result.transactions[0].transactions)
|
|
175
|
-
assert.property(result.transactions[0].transactions[0], 'height')
|
|
176
|
-
assert.property(result.transactions[0].transactions[0], 'tx_hash')
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('should throw error on array size rate limit', async () => {
|
|
180
|
-
try {
|
|
181
|
-
const addr = []
|
|
182
|
-
for (let i = 0; i < 25; i++) {
|
|
183
|
-
addr.push('bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2')
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const result = await bchjs.Electrumx.transactions(addr)
|
|
187
|
-
|
|
188
|
-
console.log(`result: ${util.inspect(result)}`)
|
|
189
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
190
|
-
} catch (err) {
|
|
191
|
-
assert.hasAnyKeys(err, ['error'])
|
|
192
|
-
assert.include(err.error, 'Array too large')
|
|
193
|
-
}
|
|
194
|
-
})
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
describe('#unconfirmed', () => {
|
|
198
|
-
// These tests won't work because unconfirmed transactions are transient in nature.
|
|
199
|
-
/*
|
|
200
|
-
it(`should GET unconfirmed UTXOs (mempool) for a single address`, async () => {
|
|
201
|
-
const addr = "bchtest:qp25k20dgcljrz4hkdz43partam3j5httyprjp23qd"
|
|
202
|
-
|
|
203
|
-
const result = await bchjs.Electrumx.unconfirmed(addr)
|
|
204
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
205
|
-
|
|
206
|
-
assert.property(result, "success")
|
|
207
|
-
assert.equal(result.success, true)
|
|
208
|
-
|
|
209
|
-
assert.property(result, "utxos")
|
|
210
|
-
assert.isArray(result.utxos)
|
|
211
|
-
|
|
212
|
-
assert.property(result.utxos[0], "height")
|
|
213
|
-
assert.property(result.utxos[0], "tx_hash")
|
|
214
|
-
assert.property(result.utxos[0], "fee")
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
it(`should POST unconfirmed UTXO details for an array of addresses`, async () => {
|
|
218
|
-
const addr = [
|
|
219
|
-
"bchtest:qp25k20dgcljrz4hkdz43partam3j5httyprjp23qd",
|
|
220
|
-
"bchtest:qpkl3xylrjx4jup6m66e7zg7whlaucsxeudxeqawdj"
|
|
221
|
-
]
|
|
222
|
-
|
|
223
|
-
const result = await bchjs.Electrumx.unconfirmed(addr)
|
|
224
|
-
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
225
|
-
|
|
226
|
-
assert.property(result, "success")
|
|
227
|
-
assert.equal(result.success, true)
|
|
228
|
-
|
|
229
|
-
assert.property(result, "utxos")
|
|
230
|
-
assert.isArray(result.utxos)
|
|
231
|
-
|
|
232
|
-
assert.property(result.utxos[0], "utxos")
|
|
233
|
-
assert.isArray(result.utxos[0].utxos)
|
|
234
|
-
assert.property(result.utxos[0], "address")
|
|
235
|
-
|
|
236
|
-
assert.property(result.utxos[0].utxos[0], "height")
|
|
237
|
-
assert.property(result.utxos[0].utxos[0], "tx_hash")
|
|
238
|
-
assert.property(result.utxos[0].utxos[0], "fee")
|
|
239
|
-
})
|
|
240
|
-
*/
|
|
241
|
-
|
|
242
|
-
it('should throw error on array size rate limit', async () => {
|
|
243
|
-
try {
|
|
244
|
-
const addr = []
|
|
245
|
-
for (let i = 0; i < 25; i++) {
|
|
246
|
-
addr.push('bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2')
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
await bchjs.Electrumx.unconfirmed(addr)
|
|
250
|
-
// console.log(`result: ${util.inspect(result)}`)
|
|
251
|
-
|
|
252
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
253
|
-
} catch (err) {
|
|
254
|
-
assert.hasAnyKeys(err, ['error'])
|
|
255
|
-
assert.include(err.error, 'Array too large')
|
|
256
|
-
}
|
|
257
|
-
})
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
describe('#blockHeader', () => {
|
|
261
|
-
it('should GET block headers for given height and count', async () => {
|
|
262
|
-
const height = 42
|
|
263
|
-
const count = 2
|
|
264
|
-
|
|
265
|
-
const result = await bchjs.Electrumx.blockHeader(height, count)
|
|
266
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
267
|
-
assert.property(result, 'success')
|
|
268
|
-
assert.equal(result.success, true)
|
|
269
|
-
|
|
270
|
-
assert.property(result, 'headers')
|
|
271
|
-
assert.isArray(result.headers)
|
|
272
|
-
assert.equal(result.headers.length, 2)
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
it('should GET block headers for given height with default count = 1', async () => {
|
|
276
|
-
const height = 42
|
|
277
|
-
|
|
278
|
-
const result = await bchjs.Electrumx.blockHeader(height)
|
|
279
|
-
assert.property(result, 'success')
|
|
280
|
-
assert.equal(result.success, true)
|
|
281
|
-
|
|
282
|
-
assert.property(result, 'headers')
|
|
283
|
-
assert.isArray(result.headers)
|
|
284
|
-
assert.equal(result.headers.length, 1)
|
|
285
|
-
})
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
describe('#txData', () => {
|
|
289
|
-
it('should GET details for a single transaction', async () => {
|
|
290
|
-
const txid =
|
|
291
|
-
'76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee'
|
|
292
|
-
|
|
293
|
-
const result = await bchjs.Electrumx.txData(txid)
|
|
294
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
295
|
-
|
|
296
|
-
assert.property(result, 'success')
|
|
297
|
-
assert.equal(result.success, true)
|
|
298
|
-
|
|
299
|
-
assert.property(result, 'details')
|
|
300
|
-
assert.isObject(result.details)
|
|
301
|
-
|
|
302
|
-
assert.property(result.details, 'blockhash')
|
|
303
|
-
assert.property(result.details, 'hash')
|
|
304
|
-
assert.property(result.details, 'hex')
|
|
305
|
-
assert.property(result.details, 'vin')
|
|
306
|
-
assert.property(result.details, 'vout')
|
|
307
|
-
assert.equal(result.details.hash, txid)
|
|
308
|
-
})
|
|
309
|
-
|
|
310
|
-
it('should POST details for an array of transactions', async () => {
|
|
311
|
-
const txids = [
|
|
312
|
-
'76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee',
|
|
313
|
-
'76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee'
|
|
314
|
-
]
|
|
315
|
-
|
|
316
|
-
const result = await bchjs.Electrumx.txData(txids)
|
|
317
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
318
|
-
|
|
319
|
-
assert.property(result, 'success')
|
|
320
|
-
assert.equal(result.success, true)
|
|
321
|
-
|
|
322
|
-
assert.property(result, 'transactions')
|
|
323
|
-
assert.isArray(result.transactions)
|
|
324
|
-
|
|
325
|
-
assert.property(result.transactions[0], 'txid')
|
|
326
|
-
assert.property(result.transactions[0], 'details')
|
|
327
|
-
|
|
328
|
-
assert.property(result.transactions[0].details, 'blockhash')
|
|
329
|
-
assert.property(result.transactions[0].details, 'hash')
|
|
330
|
-
assert.property(result.transactions[0].details, 'hex')
|
|
331
|
-
assert.property(result.transactions[0].details, 'vin')
|
|
332
|
-
assert.property(result.transactions[0].details, 'vout')
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
it('should throw error on array size rate limit', async () => {
|
|
336
|
-
try {
|
|
337
|
-
const txids = []
|
|
338
|
-
for (let i = 0; i < 25; i++) {
|
|
339
|
-
txids.push(
|
|
340
|
-
'76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee'
|
|
341
|
-
)
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
await bchjs.Electrumx.txData(txids)
|
|
345
|
-
|
|
346
|
-
// console.log(`result: ${util.inspect(result)}`)
|
|
347
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
348
|
-
} catch (err) {
|
|
349
|
-
assert.hasAnyKeys(err, ['error'])
|
|
350
|
-
assert.include(err.error, 'Array too large')
|
|
351
|
-
}
|
|
352
|
-
})
|
|
353
|
-
})
|
|
354
|
-
|
|
355
|
-
describe('#broadcast', () => {
|
|
356
|
-
it('should broadcast a single transaction', async () => {
|
|
357
|
-
const txHex =
|
|
358
|
-
'020000000265d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667010000006441dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e4121020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309ffffffff65d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667000000006441347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f774121028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954ffffffff035ac355000000000017a914189ce02e332548f4804bac65cba68202c9dbf822878dfd0800000000001976a914285bb350881b21ac89724c6fb6dc914d096cd53b88acf9ef3100000000001976a91445f1f1c4a9b9419a5088a3e9c24a293d7a150e6488ac00000000'
|
|
359
|
-
|
|
360
|
-
try {
|
|
361
|
-
await bchjs.Electrumx.broadcast(txHex)
|
|
362
|
-
} catch (err) {
|
|
363
|
-
assert.property(err, 'success')
|
|
364
|
-
assert.equal(err.success, false)
|
|
365
|
-
assert.include(
|
|
366
|
-
err.error.error,
|
|
367
|
-
'the transaction was rejected by network rules'
|
|
368
|
-
)
|
|
369
|
-
}
|
|
370
|
-
})
|
|
371
|
-
})
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
function sleep (ms) {
|
|
375
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
376
|
-
}
|