@psf/bch-js 4.21.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/bch-js.js +3 -4
- package/src/psf-slp-indexer.js +370 -0
- package/src/slp/utils.js +1 -1
- package/src/transaction.js +11 -2
- package/src/utxo.js +150 -6
- package/test/integration/chains/bchn/psf-slp-indexer.integration.js +121 -0
- package/test/integration/chains/bchn/slp.js +229 -225
- package/test/integration/chains/bchn/utxo-integration.js +35 -1
- package/test/integration/slp.js +907 -901
- package/test/integration/transaction-integration.js +58 -55
- package/test/unit/fixtures/psf-slp-indexer-mock.js +153 -0
- package/test/unit/fixtures/utxo-mocks.js +91 -1
- package/test/unit/psf-slp-indexer.js +339 -0
- package/test/unit/transaction-unit.js +19 -8
- package/test/unit/utxo-unit.js +51 -7
- package/src/ninsight.js +0 -319
- package/test/unit/fixtures/ninsight-mock.js +0 -170
- package/test/unit/ninsight.js +0 -255
|
@@ -0,0 +1,339 @@
|
|
|
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/psf-slp-indexer-mock')
|
|
10
|
+
|
|
11
|
+
describe('#PsfSlpIndexer', () => {
|
|
12
|
+
let sandbox
|
|
13
|
+
beforeEach(() => (sandbox = sinon.createSandbox()))
|
|
14
|
+
afterEach(() => sandbox.restore())
|
|
15
|
+
|
|
16
|
+
describe('#status', () => {
|
|
17
|
+
it('should GET status', async () => {
|
|
18
|
+
// Stub the network call.
|
|
19
|
+
sandbox.stub(axios, 'get').resolves({ data: mockData.status })
|
|
20
|
+
|
|
21
|
+
const result = await bchjs.PsfSlpIndexer.status()
|
|
22
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
23
|
+
assert.property(result, 'status')
|
|
24
|
+
assert.property(result.status, 'startBlockHeight')
|
|
25
|
+
assert.property(result.status, 'syncedBlockHeight')
|
|
26
|
+
assert.property(result.status, 'chainBlockHeight')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should handle axios error', async () => {
|
|
30
|
+
try {
|
|
31
|
+
// Stub the network call.
|
|
32
|
+
sandbox.stub(axios, 'get').throws(new Error('test error'))
|
|
33
|
+
|
|
34
|
+
await bchjs.PsfSlpIndexer.status()
|
|
35
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
36
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
37
|
+
} catch (err) {
|
|
38
|
+
assert.include(err.message, 'test error')
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should handle request error', async () => {
|
|
43
|
+
try {
|
|
44
|
+
// Stub the network call.
|
|
45
|
+
const testErr = new Error()
|
|
46
|
+
testErr.response = { data: { status: 422 } }
|
|
47
|
+
sandbox.stub(axios, 'get').throws(testErr)
|
|
48
|
+
|
|
49
|
+
await bchjs.PsfSlpIndexer.status()
|
|
50
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
51
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
52
|
+
} catch (err) {
|
|
53
|
+
assert.equal(err.status, 422)
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
describe('#balance', () => {
|
|
59
|
+
it('should GET balance', async () => {
|
|
60
|
+
// Stub the network call.
|
|
61
|
+
sandbox.stub(axios, 'post').resolves({ data: mockData.balance })
|
|
62
|
+
const addr = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
|
63
|
+
const result = await bchjs.PsfSlpIndexer.balance(addr)
|
|
64
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
65
|
+
assert.property(result, 'balance')
|
|
66
|
+
|
|
67
|
+
assert.property(result.balance, 'utxos')
|
|
68
|
+
assert.property(result.balance, 'txs')
|
|
69
|
+
assert.property(result.balance, 'balances')
|
|
70
|
+
assert.isArray(result.balance.utxos)
|
|
71
|
+
assert.isArray(result.balance.txs)
|
|
72
|
+
assert.isArray(result.balance.balances)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('should throw an error for improper input', async () => {
|
|
76
|
+
try {
|
|
77
|
+
const addr = 12345
|
|
78
|
+
|
|
79
|
+
await bchjs.PsfSlpIndexer.balance(addr)
|
|
80
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
81
|
+
} catch (err) {
|
|
82
|
+
// console.log(`err: `, err)
|
|
83
|
+
assert.include(err.message, 'Input address must be a string.')
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('should handle axios error', async () => {
|
|
88
|
+
try {
|
|
89
|
+
// Stub the network call.
|
|
90
|
+
sandbox.stub(axios, 'post').throws(new Error('test error'))
|
|
91
|
+
|
|
92
|
+
const addr = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
|
93
|
+
|
|
94
|
+
await bchjs.PsfSlpIndexer.balance(addr)
|
|
95
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
96
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
97
|
+
} catch (err) {
|
|
98
|
+
assert.include(err.message, 'test error')
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('should handle request error', async () => {
|
|
103
|
+
try {
|
|
104
|
+
// Stub the network call.
|
|
105
|
+
const testErr = new Error()
|
|
106
|
+
testErr.response = { data: { status: 422 } }
|
|
107
|
+
sandbox.stub(axios, 'post').throws(testErr)
|
|
108
|
+
|
|
109
|
+
const addr = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
|
110
|
+
|
|
111
|
+
await bchjs.PsfSlpIndexer.balance(addr)
|
|
112
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
113
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
114
|
+
} catch (err) {
|
|
115
|
+
assert.equal(err.status, 422)
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
describe('#tokenStats', () => {
|
|
121
|
+
it('should GET token stats', async () => {
|
|
122
|
+
// Stub the network call.
|
|
123
|
+
sandbox.stub(axios, 'post').resolves({ data: mockData.tokenStats })
|
|
124
|
+
|
|
125
|
+
const tokenId =
|
|
126
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
127
|
+
const result = await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
|
128
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
129
|
+
assert.property(result, 'tokenData')
|
|
130
|
+
assert.property(result.tokenData, 'type')
|
|
131
|
+
assert.property(result.tokenData, 'ticker')
|
|
132
|
+
assert.property(result.tokenData, 'name')
|
|
133
|
+
assert.property(result.tokenData, 'tokenId')
|
|
134
|
+
assert.property(result.tokenData, 'documentUri')
|
|
135
|
+
assert.property(result.tokenData, 'documentHash')
|
|
136
|
+
assert.property(result.tokenData, 'decimals')
|
|
137
|
+
assert.property(result.tokenData, 'mintBatonIsActive')
|
|
138
|
+
assert.property(result.tokenData, 'tokensInCirculationBN')
|
|
139
|
+
assert.property(result.tokenData, 'tokensInCirculationStr')
|
|
140
|
+
assert.property(result.tokenData, 'blockCreated')
|
|
141
|
+
assert.property(result.tokenData, 'totalBurned')
|
|
142
|
+
assert.property(result.tokenData, 'totalMinted')
|
|
143
|
+
assert.property(result.tokenData, 'txs')
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('should throw an error for improper input', async () => {
|
|
147
|
+
try {
|
|
148
|
+
const tokenId = 12345
|
|
149
|
+
|
|
150
|
+
await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
|
151
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
152
|
+
} catch (err) {
|
|
153
|
+
// console.log(`err: `, err)
|
|
154
|
+
assert.include(err.message, 'Input tokenId must be a string.')
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('should handle axios error', async () => {
|
|
159
|
+
try {
|
|
160
|
+
// Stub the network call.
|
|
161
|
+
sandbox.stub(axios, 'post').throws(new Error('test error'))
|
|
162
|
+
|
|
163
|
+
const tokenId =
|
|
164
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
165
|
+
await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
|
166
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
167
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
168
|
+
} catch (err) {
|
|
169
|
+
assert.include(err.message, 'test error')
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
it('should handle request error', async () => {
|
|
174
|
+
try {
|
|
175
|
+
// Stub the network call.
|
|
176
|
+
const testErr = new Error()
|
|
177
|
+
testErr.response = { data: { status: 422 } }
|
|
178
|
+
sandbox.stub(axios, 'post').throws(testErr)
|
|
179
|
+
|
|
180
|
+
const tokenId =
|
|
181
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
182
|
+
await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
|
183
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
184
|
+
} catch (err) {
|
|
185
|
+
assert.equal(err.status, 422)
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
describe('#tx', () => {
|
|
191
|
+
it('should GET transaction data', async () => {
|
|
192
|
+
// Stub the network call.
|
|
193
|
+
sandbox.stub(axios, 'post').resolves({ data: mockData.txData })
|
|
194
|
+
|
|
195
|
+
const txid =
|
|
196
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
197
|
+
const result = await bchjs.PsfSlpIndexer.tx(txid)
|
|
198
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
199
|
+
assert.property(result, 'txData')
|
|
200
|
+
assert.property(result.txData, 'txid')
|
|
201
|
+
assert.property(result.txData, 'hash')
|
|
202
|
+
assert.property(result.txData, 'version')
|
|
203
|
+
assert.property(result.txData, 'size')
|
|
204
|
+
assert.property(result.txData, 'locktime')
|
|
205
|
+
assert.property(result.txData, 'vin')
|
|
206
|
+
assert.property(result.txData, 'vout')
|
|
207
|
+
assert.property(result.txData, 'hex')
|
|
208
|
+
assert.property(result.txData, 'blockhash')
|
|
209
|
+
assert.property(result.txData, 'confirmations')
|
|
210
|
+
assert.property(result.txData, 'time')
|
|
211
|
+
assert.property(result.txData, 'blocktime')
|
|
212
|
+
assert.property(result.txData, 'blockheight')
|
|
213
|
+
assert.property(result.txData, 'isSlpTx')
|
|
214
|
+
assert.property(result.txData, 'tokenTxType')
|
|
215
|
+
assert.property(result.txData, 'tokenId')
|
|
216
|
+
assert.property(result.txData, 'tokenType')
|
|
217
|
+
assert.property(result.txData, 'tokenTicker')
|
|
218
|
+
assert.property(result.txData, 'tokenName')
|
|
219
|
+
assert.property(result.txData, 'tokenDecimals')
|
|
220
|
+
assert.property(result.txData, 'tokenUri')
|
|
221
|
+
assert.property(result.txData, 'tokenDocHash')
|
|
222
|
+
assert.property(result.txData, 'isValidSlp')
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('should throw an error for improper input', async () => {
|
|
226
|
+
try {
|
|
227
|
+
const txid = 12345
|
|
228
|
+
|
|
229
|
+
await bchjs.PsfSlpIndexer.tx(txid)
|
|
230
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
231
|
+
} catch (err) {
|
|
232
|
+
// console.log(`err: `, err)
|
|
233
|
+
assert.include(err.message, 'Input txid must be a string.')
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
it('should handle axios error', async () => {
|
|
238
|
+
try {
|
|
239
|
+
// Stub the network call.
|
|
240
|
+
sandbox.stub(axios, 'post').throws(new Error('test error'))
|
|
241
|
+
|
|
242
|
+
const txid =
|
|
243
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
244
|
+
await bchjs.PsfSlpIndexer.tx(txid)
|
|
245
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
246
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
247
|
+
} catch (err) {
|
|
248
|
+
assert.include(err.message, 'test error')
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
it('should get tx from full node if not available from slp indexer', async () => {
|
|
253
|
+
// Stub the call to the SLP indexer.
|
|
254
|
+
const testErr = {
|
|
255
|
+
response: { data: { error: 'Key not found in database' } }
|
|
256
|
+
}
|
|
257
|
+
sandbox.stub(axios, 'post').rejects(testErr)
|
|
258
|
+
|
|
259
|
+
// Stub the call to the full node
|
|
260
|
+
sandbox.stub(bchjs.PsfSlpIndexer, 'checkBlacklist').resolves(false)
|
|
261
|
+
sandbox
|
|
262
|
+
.stub(bchjs.PsfSlpIndexer.rawTransaction, 'getTxData')
|
|
263
|
+
.resolves({ txid: 'fakeTxid' })
|
|
264
|
+
|
|
265
|
+
const txid =
|
|
266
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
267
|
+
const result = await bchjs.PsfSlpIndexer.tx(txid)
|
|
268
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
269
|
+
|
|
270
|
+
assert.equal(result.txData.txid, 'fakeTxid')
|
|
271
|
+
assert.equal(result.txData.isValidSlp, false)
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('should return isValidSlp=null for blacklisted token', async () => {
|
|
275
|
+
// Stub the call to the SLP indexer.
|
|
276
|
+
const testErr = {
|
|
277
|
+
response: { data: { error: 'Key not found in database' } }
|
|
278
|
+
}
|
|
279
|
+
sandbox.stub(axios, 'post').rejects(testErr)
|
|
280
|
+
|
|
281
|
+
// Stub the call to the full node
|
|
282
|
+
sandbox.stub(bchjs.PsfSlpIndexer, 'checkBlacklist').resolves(true)
|
|
283
|
+
sandbox
|
|
284
|
+
.stub(bchjs.PsfSlpIndexer.rawTransaction, 'getTxData')
|
|
285
|
+
.resolves({ txid: 'fakeTxid' })
|
|
286
|
+
|
|
287
|
+
const txid =
|
|
288
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
289
|
+
const result = await bchjs.PsfSlpIndexer.tx(txid)
|
|
290
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
291
|
+
|
|
292
|
+
assert.equal(result.txData.txid, 'fakeTxid')
|
|
293
|
+
assert.equal(result.txData.isValidSlp, null)
|
|
294
|
+
})
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
describe('#checkBlacklist', () => {
|
|
298
|
+
it('should return true if txid contains token in blacklist', async () => {
|
|
299
|
+
// Mock dependencies
|
|
300
|
+
sandbox
|
|
301
|
+
.stub(bchjs.PsfSlpIndexer.slpUtils, 'decodeOpReturn')
|
|
302
|
+
.resolves(mockData.tokenData01)
|
|
303
|
+
|
|
304
|
+
const txid =
|
|
305
|
+
'302113c11b90edc5f36c073d2f8a75e1e0eaf59b56235491a843d3819cd6a85f'
|
|
306
|
+
|
|
307
|
+
const result = await bchjs.PsfSlpIndexer.checkBlacklist(txid)
|
|
308
|
+
// console.log('result: ', result)
|
|
309
|
+
|
|
310
|
+
assert.equal(result, true)
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
it('should return false if there is an error', async () => {
|
|
314
|
+
// Force an error
|
|
315
|
+
sandbox
|
|
316
|
+
.stub(bchjs.PsfSlpIndexer.slpUtils, 'decodeOpReturn')
|
|
317
|
+
.rejects(new Error('test error'))
|
|
318
|
+
|
|
319
|
+
const result = await bchjs.PsfSlpIndexer.checkBlacklist()
|
|
320
|
+
|
|
321
|
+
assert.equal(result, false)
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
it('should return false if there is no tokenId match', async () => {
|
|
325
|
+
// Mock dependencies
|
|
326
|
+
mockData.tokenData01.tokenId = 'abc123'
|
|
327
|
+
sandbox
|
|
328
|
+
.stub(bchjs.PsfSlpIndexer.slpUtils, 'decodeOpReturn')
|
|
329
|
+
.resolves(mockData.tokenData01)
|
|
330
|
+
|
|
331
|
+
const txid =
|
|
332
|
+
'302113c11b90edc5f36c073d2f8a75e1e0eaf59b56235491a843d3819cd6a85f'
|
|
333
|
+
|
|
334
|
+
const result = await bchjs.PsfSlpIndexer.checkBlacklist(txid)
|
|
335
|
+
|
|
336
|
+
assert.equal(result, false)
|
|
337
|
+
})
|
|
338
|
+
})
|
|
339
|
+
})
|
|
@@ -22,10 +22,10 @@ describe('#TransactionLib', () => {
|
|
|
22
22
|
})
|
|
23
23
|
afterEach(() => sandbox.restore())
|
|
24
24
|
|
|
25
|
-
describe('#
|
|
25
|
+
describe('#getOld', () => {
|
|
26
26
|
it('should throw an error if txid is not specified', async () => {
|
|
27
27
|
try {
|
|
28
|
-
await bchjs.Transaction.
|
|
28
|
+
await bchjs.Transaction.getOld()
|
|
29
29
|
|
|
30
30
|
assert.fail('Unexpected code path!')
|
|
31
31
|
} catch (err) {
|
|
@@ -45,7 +45,7 @@ describe('#TransactionLib', () => {
|
|
|
45
45
|
.stub(bchjs.Transaction.rawTransaction, 'getTxData')
|
|
46
46
|
.resolves(mockData.nonSlpTxDetails)
|
|
47
47
|
|
|
48
|
-
const result = await bchjs.Transaction.
|
|
48
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
49
49
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
50
50
|
|
|
51
51
|
// Assert that there are stanardized properties.
|
|
@@ -84,7 +84,7 @@ describe('#TransactionLib', () => {
|
|
|
84
84
|
const txid =
|
|
85
85
|
'266844d53e46bbd7dd37134688dffea6e54d944edff27a0add63dd0908839bc1'
|
|
86
86
|
|
|
87
|
-
const result = await bchjs.Transaction.
|
|
87
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
88
88
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
89
89
|
|
|
90
90
|
// Assert that there are stanardized properties.
|
|
@@ -114,7 +114,7 @@ describe('#TransactionLib', () => {
|
|
|
114
114
|
.stub(bchjs.Transaction.rawTransaction, 'getTxData')
|
|
115
115
|
.rejects(new Error('test error'))
|
|
116
116
|
|
|
117
|
-
await bchjs.Transaction.
|
|
117
|
+
await bchjs.Transaction.getOld(txid)
|
|
118
118
|
|
|
119
119
|
assert.fail('Unexpected code path')
|
|
120
120
|
} catch (err) {
|
|
@@ -147,7 +147,7 @@ describe('#TransactionLib', () => {
|
|
|
147
147
|
const txid =
|
|
148
148
|
'874306bda204d3a5dd15e03ea5732cccdca4c33a52df35162cdd64e30ea7f04e'
|
|
149
149
|
|
|
150
|
-
const result = await bchjs.Transaction.
|
|
150
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
151
151
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
152
152
|
|
|
153
153
|
// Assert that there are stanardized properties.
|
|
@@ -195,7 +195,7 @@ describe('#TransactionLib', () => {
|
|
|
195
195
|
const txid =
|
|
196
196
|
'4640a734063ea79fa587a3cac38a70a2f6f3db0011e23514024185982110d0fa'
|
|
197
197
|
|
|
198
|
-
const result = await bchjs.Transaction.
|
|
198
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
199
199
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
200
200
|
|
|
201
201
|
// Assert that there are stanardized properties.
|
|
@@ -246,7 +246,7 @@ describe('#TransactionLib', () => {
|
|
|
246
246
|
const txid =
|
|
247
247
|
'6bc111fbf5b118021d68355ca19a0e77fa358dd931f284b2550f79a51ab4792a'
|
|
248
248
|
|
|
249
|
-
const result = await bchjs.Transaction.
|
|
249
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
250
250
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
251
251
|
|
|
252
252
|
// Assert that there are stanardized properties.
|
|
@@ -705,4 +705,15 @@ describe('#TransactionLib', () => {
|
|
|
705
705
|
assert.equal(result.isSlpTx, true)
|
|
706
706
|
})
|
|
707
707
|
})
|
|
708
|
+
|
|
709
|
+
describe('#get', () => {
|
|
710
|
+
it('should proxy psf-slp-indexer', async () => {
|
|
711
|
+
// console.log('bchjs.Transaction: ', bchjs.Transaction)
|
|
712
|
+
sandbox.stub(bchjs.Transaction.psfSlpIndexer, 'tx').resolves('test data')
|
|
713
|
+
|
|
714
|
+
const result = await bchjs.Transaction.get()
|
|
715
|
+
|
|
716
|
+
assert.equal(result, 'test data')
|
|
717
|
+
})
|
|
718
|
+
})
|
|
708
719
|
})
|
package/test/unit/utxo-unit.js
CHANGED
|
@@ -15,7 +15,7 @@ describe('#utxo', () => {
|
|
|
15
15
|
beforeEach(() => (sandbox = sinon.createSandbox()))
|
|
16
16
|
afterEach(() => sandbox.restore())
|
|
17
17
|
|
|
18
|
-
describe('#
|
|
18
|
+
describe('#getOld', () => {
|
|
19
19
|
it('should get hydrated and filtered UTXOs for an address', async () => {
|
|
20
20
|
// Mock dependencies.
|
|
21
21
|
sandbox.stub(bchjs.Utxo.electrumx, 'utxo').resolves(mockData.mockUtxoData)
|
|
@@ -25,7 +25,7 @@ describe('#utxo', () => {
|
|
|
25
25
|
|
|
26
26
|
const addr = 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
|
|
27
27
|
|
|
28
|
-
const result = await bchjs.Utxo.
|
|
28
|
+
const result = await bchjs.Utxo.getOld(addr)
|
|
29
29
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
30
30
|
|
|
31
31
|
assert.isArray(result)
|
|
@@ -46,7 +46,7 @@ describe('#utxo', () => {
|
|
|
46
46
|
|
|
47
47
|
const addr = 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
|
|
48
48
|
|
|
49
|
-
await bchjs.Utxo.
|
|
49
|
+
await bchjs.Utxo.getOld(addr)
|
|
50
50
|
|
|
51
51
|
assert.fail('Unexpected code path')
|
|
52
52
|
} catch (err) {
|
|
@@ -66,7 +66,7 @@ describe('#utxo', () => {
|
|
|
66
66
|
'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9'
|
|
67
67
|
]
|
|
68
68
|
|
|
69
|
-
const result = await bchjs.Utxo.
|
|
69
|
+
const result = await bchjs.Utxo.getOld(addr)
|
|
70
70
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
71
71
|
|
|
72
72
|
assert.isArray(result)
|
|
@@ -88,7 +88,7 @@ describe('#utxo', () => {
|
|
|
88
88
|
addrs.push(addr)
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
await bchjs.Utxo.
|
|
91
|
+
await bchjs.Utxo.getOld(addrs)
|
|
92
92
|
|
|
93
93
|
assert.fail('Unexpected code path')
|
|
94
94
|
} catch (err) {
|
|
@@ -105,7 +105,7 @@ describe('#utxo', () => {
|
|
|
105
105
|
|
|
106
106
|
const addr = 'simpleledger:qrm0c67wwqh0w7wjxua2gdt2xggnm90xwsr5k22euj'
|
|
107
107
|
|
|
108
|
-
const result = await bchjs.Utxo.
|
|
108
|
+
const result = await bchjs.Utxo.getOld(addr)
|
|
109
109
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
110
110
|
|
|
111
111
|
assert.isArray(result)
|
|
@@ -133,7 +133,7 @@ describe('#utxo', () => {
|
|
|
133
133
|
const addr = 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
|
|
134
134
|
const useWhitelist = true
|
|
135
135
|
|
|
136
|
-
const result = await bchjs.Utxo.
|
|
136
|
+
const result = await bchjs.Utxo.getOld(addr, useWhitelist)
|
|
137
137
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
138
138
|
|
|
139
139
|
assert.isArray(result)
|
|
@@ -188,4 +188,48 @@ describe('#utxo', () => {
|
|
|
188
188
|
assert.equal(result.satoshis, 800)
|
|
189
189
|
})
|
|
190
190
|
})
|
|
191
|
+
|
|
192
|
+
describe('#get', () => {
|
|
193
|
+
it('should throw an error if input is not a string', async () => {
|
|
194
|
+
try {
|
|
195
|
+
const addr = 123
|
|
196
|
+
|
|
197
|
+
await bchjs.Utxo.get(addr)
|
|
198
|
+
|
|
199
|
+
assert.fail('Unexpected code path')
|
|
200
|
+
} catch (err) {
|
|
201
|
+
assert.include(err.message, 'address input must be a string')
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('should return UTXO information', async () => {
|
|
206
|
+
// mock dependencies
|
|
207
|
+
sandbox
|
|
208
|
+
.stub(bchjs.Utxo.electrumx, 'utxo')
|
|
209
|
+
.resolves(mockData.fulcrumUtxos01)
|
|
210
|
+
sandbox
|
|
211
|
+
.stub(bchjs.Utxo.psfSlpIndexer, 'balance')
|
|
212
|
+
.resolves(mockData.psfSlpIndexerUtxos01)
|
|
213
|
+
|
|
214
|
+
const addr = 'simpleledger:qrm0c67wwqh0w7wjxua2gdt2xggnm90xwsr5k22euj'
|
|
215
|
+
|
|
216
|
+
const result = await bchjs.Utxo.get(addr)
|
|
217
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
218
|
+
|
|
219
|
+
// Assert expected properties exist
|
|
220
|
+
assert.property(result, 'address')
|
|
221
|
+
assert.property(result, 'bchUtxos')
|
|
222
|
+
assert.property(result, 'slpUtxos')
|
|
223
|
+
assert.property(result.slpUtxos, 'type1')
|
|
224
|
+
assert.property(result.slpUtxos.type1, 'tokens')
|
|
225
|
+
assert.property(result.slpUtxos.type1, 'mintBatons')
|
|
226
|
+
assert.property(result.slpUtxos, 'nft')
|
|
227
|
+
assert.property(result, 'nullUtxos')
|
|
228
|
+
|
|
229
|
+
assert.equal(result.bchUtxos.length, 4)
|
|
230
|
+
assert.equal(result.slpUtxos.type1.tokens.length, 1)
|
|
231
|
+
assert.equal(result.slpUtxos.type1.mintBatons.length, 1)
|
|
232
|
+
assert.equal(result.nullUtxos.length, 0)
|
|
233
|
+
})
|
|
234
|
+
})
|
|
191
235
|
})
|