@psf/bch-js 5.1.0 → 5.2.3
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/package.json +2 -2
- package/src/bch-js.js +0 -4
- package/src/psf-slp-indexer.js +46 -7
- package/src/slp/utils.js +1 -1
- package/src/utxo.js +219 -6
- package/test/integration/chains/abc/utxo-integration.js +5 -3
- package/test/integration/chains/bchn/psf-slp-indexer.integration.js +20 -4
- package/test/integration/chains/bchn/transaction-integration.js +28 -0
- package/test/integration/chains/bchn/utxo-integration.js +179 -78
- package/test/integration/transaction-integration.js +58 -56
- package/test/unit/fixtures/psf-slp-indexer-mock.js +37 -14
- package/test/unit/fixtures/utxo-mocks.js +205 -1
- package/test/unit/psf-slp-indexer.js +75 -0
- package/test/unit/utxo-unit.js +117 -7
- package/src/ninsight.js +0 -319
- package/test/unit/fixtures/ninsight-mock.js +0 -170
- package/test/unit/ninsight.js +0 -255
package/test/unit/ninsight.js
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
const chai = require('chai')
|
|
2
|
-
const assert = chai.assert
|
|
3
|
-
const axios = require('axios')
|
|
4
|
-
const sinon = require('sinon')
|
|
5
|
-
|
|
6
|
-
const BCHJS = require('../../src/bch-js')
|
|
7
|
-
const bchjs = new BCHJS()
|
|
8
|
-
|
|
9
|
-
const mockData = require('./fixtures/ninsight-mock')
|
|
10
|
-
|
|
11
|
-
describe('#Ninsight', () => {
|
|
12
|
-
let sandbox
|
|
13
|
-
beforeEach(() => (sandbox = sinon.createSandbox()))
|
|
14
|
-
afterEach(() => sandbox.restore())
|
|
15
|
-
|
|
16
|
-
describe('#utxo', () => {
|
|
17
|
-
it('should throw an error for improper input', async () => {
|
|
18
|
-
try {
|
|
19
|
-
const addr = 12345
|
|
20
|
-
|
|
21
|
-
await bchjs.Ninsight.utxo(addr)
|
|
22
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
23
|
-
} catch (err) {
|
|
24
|
-
// console.log(`err: `, err)
|
|
25
|
-
assert.include(
|
|
26
|
-
err.message,
|
|
27
|
-
'Input address must be a string or array of strings.'
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('should GET utxos for a single address', async () => {
|
|
33
|
-
// Stub the network call.
|
|
34
|
-
sandbox.stub(axios, 'post').resolves({ data: mockData.utxo })
|
|
35
|
-
|
|
36
|
-
const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9'
|
|
37
|
-
|
|
38
|
-
const result = await bchjs.Ninsight.utxo(addr)
|
|
39
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
40
|
-
|
|
41
|
-
assert.property(result, 'utxos')
|
|
42
|
-
assert.property(result, 'legacyAddress')
|
|
43
|
-
assert.property(result, 'cashAddress')
|
|
44
|
-
assert.property(result, 'slpAddress')
|
|
45
|
-
assert.property(result, 'scriptPubKey')
|
|
46
|
-
assert.property(result, 'asm')
|
|
47
|
-
|
|
48
|
-
assert.isArray(result.utxos)
|
|
49
|
-
|
|
50
|
-
assert.property(result.utxos[0], 'txid')
|
|
51
|
-
assert.property(result.utxos[0], 'vout')
|
|
52
|
-
assert.property(result.utxos[0], 'amount')
|
|
53
|
-
assert.property(result.utxos[0], 'satoshis')
|
|
54
|
-
assert.property(result.utxos[0], 'height')
|
|
55
|
-
assert.property(result.utxos[0], 'confirmations')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('should POST utxo details for an array of addresses', async () => {
|
|
59
|
-
// Mock the network call.
|
|
60
|
-
sandbox.stub(axios, 'post').resolves({ data: mockData.utxoPost })
|
|
61
|
-
|
|
62
|
-
const addr = [
|
|
63
|
-
'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7',
|
|
64
|
-
'bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr'
|
|
65
|
-
]
|
|
66
|
-
|
|
67
|
-
const result = await bchjs.Ninsight.utxo(addr)
|
|
68
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
69
|
-
|
|
70
|
-
assert.isArray(result)
|
|
71
|
-
assert.isArray(result[0].utxos)
|
|
72
|
-
|
|
73
|
-
assert.property(result[0], 'utxos')
|
|
74
|
-
assert.property(result[0], 'legacyAddress')
|
|
75
|
-
assert.property(result[0], 'cashAddress')
|
|
76
|
-
assert.property(result[0], 'slpAddress')
|
|
77
|
-
assert.property(result[0], 'scriptPubKey')
|
|
78
|
-
assert.property(result[0], 'asm')
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
describe('#unconfirmed', () => {
|
|
83
|
-
it('should throw an error for improper input', async () => {
|
|
84
|
-
try {
|
|
85
|
-
const addr = 12345
|
|
86
|
-
|
|
87
|
-
await bchjs.Ninsight.unconfirmed(addr)
|
|
88
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
89
|
-
} catch (err) {
|
|
90
|
-
assert.include(
|
|
91
|
-
err.message,
|
|
92
|
-
'Input address must be a string or array of strings.'
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('should POST utxos for a single address', async () => {
|
|
98
|
-
// Stub the network call.
|
|
99
|
-
sandbox.stub(axios, 'post').resolves({ data: mockData.unconfirmed })
|
|
100
|
-
|
|
101
|
-
const addr = 'bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5'
|
|
102
|
-
|
|
103
|
-
const result = await bchjs.Ninsight.unconfirmed(addr)
|
|
104
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
105
|
-
|
|
106
|
-
assert.property(result, 'utxos')
|
|
107
|
-
assert.property(result, 'legacyAddress')
|
|
108
|
-
assert.property(result, 'cashAddress')
|
|
109
|
-
assert.property(result, 'slpAddress')
|
|
110
|
-
assert.property(result, 'scriptPubKey')
|
|
111
|
-
|
|
112
|
-
assert.isArray(result.utxos)
|
|
113
|
-
|
|
114
|
-
assert.property(result.utxos[0], 'txid')
|
|
115
|
-
assert.property(result.utxos[0], 'vout')
|
|
116
|
-
assert.property(result.utxos[0], 'amount')
|
|
117
|
-
assert.property(result.utxos[0], 'satoshis')
|
|
118
|
-
assert.property(result.utxos[0], 'confirmations')
|
|
119
|
-
assert.property(result.utxos[0], 'ts')
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
it('should POST utxo details for an array of addresses', async () => {
|
|
123
|
-
// Mock the network call.
|
|
124
|
-
sandbox.stub(axios, 'post').resolves({ data: mockData.unconfirmedPost })
|
|
125
|
-
|
|
126
|
-
const addr = [
|
|
127
|
-
'bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5',
|
|
128
|
-
'bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr'
|
|
129
|
-
]
|
|
130
|
-
|
|
131
|
-
const result = await bchjs.Ninsight.unconfirmed(addr)
|
|
132
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
133
|
-
|
|
134
|
-
assert.isArray(result)
|
|
135
|
-
assert.isArray(result[0].utxos)
|
|
136
|
-
|
|
137
|
-
assert.property(result[0], 'utxos')
|
|
138
|
-
assert.property(result[0], 'legacyAddress')
|
|
139
|
-
assert.property(result[0], 'cashAddress')
|
|
140
|
-
assert.property(result[0], 'slpAddress')
|
|
141
|
-
assert.property(result[0], 'scriptPubKey')
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
describe('#transactions', () => {
|
|
146
|
-
it('should throw an error for improper input', async () => {
|
|
147
|
-
try {
|
|
148
|
-
const addr = 12345
|
|
149
|
-
|
|
150
|
-
await bchjs.Ninsight.transactions(addr)
|
|
151
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
152
|
-
} catch (err) {
|
|
153
|
-
// console.log(`err: `, err)
|
|
154
|
-
assert.include(
|
|
155
|
-
err.message,
|
|
156
|
-
'Input address must be a string or array of strings.'
|
|
157
|
-
)
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
it('should POST transaction history for a single address', async () => {
|
|
161
|
-
// Stub the network call.
|
|
162
|
-
sandbox.stub(axios, 'post').resolves({ data: mockData.transactionsPost })
|
|
163
|
-
|
|
164
|
-
const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9'
|
|
165
|
-
|
|
166
|
-
const result = await bchjs.Ninsight.transactions(addr)
|
|
167
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
168
|
-
|
|
169
|
-
assert.isArray(result)
|
|
170
|
-
assert.property(result[0], 'cashAddress')
|
|
171
|
-
assert.property(result[0], 'legacyAddress')
|
|
172
|
-
assert.property(result[0], 'txs')
|
|
173
|
-
assert.isArray(result[0].txs)
|
|
174
|
-
assert.property(result[0].txs[0], 'txid')
|
|
175
|
-
assert.property(result[0].txs[0], 'vin')
|
|
176
|
-
assert.property(result[0].txs[0], 'vout')
|
|
177
|
-
})
|
|
178
|
-
it('should POST transaction history for an array of addresses', async () => {
|
|
179
|
-
// Mock the network call.
|
|
180
|
-
sandbox.stub(axios, 'post').resolves({ data: mockData.transactionsPost })
|
|
181
|
-
|
|
182
|
-
const addr = [
|
|
183
|
-
'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7',
|
|
184
|
-
'bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr'
|
|
185
|
-
]
|
|
186
|
-
|
|
187
|
-
const result = await bchjs.Ninsight.transactions(addr)
|
|
188
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
189
|
-
|
|
190
|
-
assert.isArray(result)
|
|
191
|
-
assert.property(result[0], 'cashAddress')
|
|
192
|
-
assert.property(result[0], 'legacyAddress')
|
|
193
|
-
assert.property(result[0], 'txs')
|
|
194
|
-
assert.isArray(result[0].txs)
|
|
195
|
-
assert.property(result[0].txs[0], 'txid')
|
|
196
|
-
})
|
|
197
|
-
})
|
|
198
|
-
describe('#txDetails', () => {
|
|
199
|
-
it('should throw an error for improper input', async () => {
|
|
200
|
-
try {
|
|
201
|
-
const txid = 12345
|
|
202
|
-
|
|
203
|
-
await bchjs.Ninsight.txDetails(txid)
|
|
204
|
-
assert.equal(true, false, 'Unexpected result!')
|
|
205
|
-
} catch (err) {
|
|
206
|
-
// console.log(`err: `, err)
|
|
207
|
-
assert.include(
|
|
208
|
-
err.message,
|
|
209
|
-
'Transaction ID must be a string or array of strings.'
|
|
210
|
-
)
|
|
211
|
-
}
|
|
212
|
-
})
|
|
213
|
-
it('should POST transaction details for a single TxID', async () => {
|
|
214
|
-
// Stub the network call.
|
|
215
|
-
sandbox.stub(axios, 'post').resolves({ data: mockData.detailsPost })
|
|
216
|
-
|
|
217
|
-
const txid = 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33'
|
|
218
|
-
|
|
219
|
-
const result = await bchjs.Ninsight.txDetails(txid)
|
|
220
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
221
|
-
|
|
222
|
-
assert.isArray(result)
|
|
223
|
-
assert.property(result[0], 'txid')
|
|
224
|
-
assert.property(result[0], 'version')
|
|
225
|
-
assert.property(result[0], 'locktime')
|
|
226
|
-
assert.property(result[0], 'vin')
|
|
227
|
-
assert.property(result[0], 'vout')
|
|
228
|
-
assert.property(result[0], 'blockhash')
|
|
229
|
-
assert.property(result[0], 'blockheight')
|
|
230
|
-
assert.property(result[0], 'confirmations')
|
|
231
|
-
assert.property(result[0], 'time')
|
|
232
|
-
assert.property(result[0], 'blocktime')
|
|
233
|
-
assert.property(result[0], 'isCoinBase')
|
|
234
|
-
assert.property(result[0], 'valueOut')
|
|
235
|
-
assert.property(result[0], 'size')
|
|
236
|
-
})
|
|
237
|
-
it('should POST transaction details for an array of TxIDs', async () => {
|
|
238
|
-
// Stub the network call.
|
|
239
|
-
sandbox.stub(axios, 'post').resolves({ data: mockData.detailsPost })
|
|
240
|
-
|
|
241
|
-
const txid = [
|
|
242
|
-
'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33',
|
|
243
|
-
'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33'
|
|
244
|
-
]
|
|
245
|
-
|
|
246
|
-
const result = await bchjs.Ninsight.txDetails(txid)
|
|
247
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
248
|
-
|
|
249
|
-
assert.isArray(result)
|
|
250
|
-
assert.property(result[0], 'txid')
|
|
251
|
-
assert.property(result[0], 'vin')
|
|
252
|
-
assert.property(result[0], 'vout')
|
|
253
|
-
})
|
|
254
|
-
})
|
|
255
|
-
})
|