@psf/bch-js 4.22.0 → 5.2.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.
@@ -1,170 +0,0 @@
1
- /*
2
- Mocking data for unit tests for the Ninsight library.
3
- */
4
-
5
- const utxo = {
6
- utxos: [
7
- {
8
- txid: '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7',
9
- vout: 0,
10
- amount: 0.00001,
11
- satoshis: 1000,
12
- height: 602405,
13
- confirmations: 36459
14
- }
15
- ],
16
- legacyAddress: '15NCRBJsHaJy8As5bX1oh2YauRejnZ1MKF',
17
- cashAddress: 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9',
18
- slpAddress: 'simpleledger:qqh793x9au6ehvh7r2zflzguanlme760wuwzunhjfm',
19
- scriptPubKey: '76a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788ac',
20
- asm:
21
- 'OP_DUP OP_HASH160 2fe2c4c5ef359bb2fe1a849f891cecffbcfb4f77 OP_EQUALVERIFY OP_CHECKSIG'
22
- }
23
-
24
- const unconfirmed = {
25
- utxos: [
26
- {
27
- txid: '3904ffe6f8fba4ceda5e887130f60fcb18bdc7dcee10392a57f89475c5c108f1',
28
- vout: 0,
29
- amount: 0.03608203,
30
- satoshis: 3608203,
31
- confirmations: 0,
32
- ts: 1559670801
33
- }
34
- ],
35
- legacyAddress: '1AyWs8U4HUnTLmxxFiGoJbsXauRsvBrcKW',
36
- cashAddress: 'bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5',
37
- slpAddress: 'simpleledger:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rkuk8mdxlf2',
38
- scriptPubKey: '76a9146d695af951760b837c8e58b045b098f9c17e23b788ac'
39
- }
40
-
41
- const utxoPost = [utxo, utxo]
42
- const unconfirmedPost = [unconfirmed, unconfirmed]
43
-
44
- const transactions = {
45
- pagesTotal: 1,
46
- txs: [
47
- {
48
- txid: 'ec7bc8349386e3e1939bbdc4f8092fdbdd6a380734e68486b558cd594c451d5b',
49
- version: 2,
50
- locktime: 0,
51
- vin: [
52
- {
53
- txid:
54
- '4f1fc57c33659628938db740449bf92fb75799e1d5750a4aeef80eb52d6df1e0',
55
- vout: 0,
56
- sequence: 4294967295,
57
- n: 0,
58
- scriptSig: {
59
- hex:
60
- '483045022100a3662a19ae384a1ceddea57765e425e61b04823e976d574da3911ac6b55d7f9b02200e571d985bce987675a2d58587a346fa40c39f4df13dc88548a92c52d5b24422412103f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f',
61
- asm:
62
- '3045022100a3662a19ae384a1ceddea57765e425e61b04823e976d574da3911ac6b55d7f9b02200e571d985bce987675a2d58587a346fa40c39f4df13dc88548a92c52d5b24422[ALL|FORKID] 03f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f'
63
- },
64
- addr: '17HPz8RQ4XM6mjre6aspvqyj1j648CZidM',
65
- valueSat: 1111,
66
- value: 0.00001111,
67
- doubleSpentTxID: null
68
- },
69
- {
70
- txid:
71
- '126d62c299e7e14c66fe0b485d13082c23641f003690462046bc24ad2d1180c1',
72
- vout: 0,
73
- sequence: 4294967295,
74
- n: 1,
75
- scriptSig: {
76
- hex:
77
- '47304402203e3f923207111ff9bbd2fb5ab1a49a9145ad809ee0cad0e0ddaed64bfe38dc16022012ee288fb413bd500c63f8bb95e46b6b57d34762decd46b7188478a1c398eeda412103f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f',
78
- asm:
79
- '304402203e3f923207111ff9bbd2fb5ab1a49a9145ad809ee0cad0e0ddaed64bfe38dc16022012ee288fb413bd500c63f8bb95e46b6b57d34762decd46b7188478a1c398eeda[ALL|FORKID] 03f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f'
80
- },
81
- addr: '17HPz8RQ4XM6mjre6aspvqyj1j648CZidM',
82
- valueSat: 1000,
83
- value: 0.00001,
84
- doubleSpentTxID: null
85
- }
86
- ],
87
- vout: [
88
- {
89
- value: '0.00001736',
90
- n: 0,
91
- scriptPubKey: {
92
- hex: '76a914d96ac75ca8df9729d278da50ccd7355c5785444e88ac',
93
- asm:
94
- 'OP_DUP OP_HASH160 d96ac75ca8df9729d278da50ccd7355c5785444e OP_EQUALVERIFY OP_CHECKSIG',
95
- addresses: ['1LpbYkEM5cryfhs58tH8c93p4SGzit7UrP'],
96
- type: 'pubkeyhash'
97
- },
98
- spentTxId: null,
99
- spentIndex: null,
100
- spentHeight: null
101
- }
102
- ],
103
- blockheight: -1,
104
- confirmations: 0,
105
- time: 1559673337,
106
- valueOut: 0.00001736,
107
- size: 339,
108
- valueIn: 0.00002111,
109
- fees: 0.00000375
110
- }
111
- ],
112
- legacyAddress: '1LpbYkEM5cryfhs58tH8c93p4SGzit7UrP',
113
- cashAddress: 'bitcoincash:qrvk436u4r0ew2wj0rd9pnxhx4w90p2yfc29ta0d2n',
114
- currentPage: 0
115
- }
116
-
117
- const transactionsPost = [transactions, transactions]
118
-
119
- const details = {
120
- txid: 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33',
121
- version: 1,
122
- locktime: 0,
123
- vin: [
124
- {
125
- coinbase: '04ffff001d02fd04',
126
- sequence: 4294967295,
127
- n: 0
128
- }
129
- ],
130
- vout: [
131
- {
132
- value: '50.00000000',
133
- n: 0,
134
- scriptPubKey: {
135
- hex:
136
- '4104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac',
137
- asm:
138
- '04f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446a OP_CHECKSIG',
139
- addresses: ['1BW18n7MfpU35q4MTBSk8pse3XzQF8XvzT'],
140
- type: 'pubkeyhash',
141
- cashAddrs: ['bitcoincash:qpej6mkrwca4tvy2snq4crhrf88v4ljspysx0ueetk']
142
- },
143
- spentTxId: null,
144
- spentIndex: null,
145
- spentHeight: null
146
- }
147
- ],
148
- blockhash:
149
- '00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09',
150
- blockheight: 1000,
151
- confirmations: 585610,
152
- time: 1232346882,
153
- blocktime: 1232346882,
154
- isCoinBase: true,
155
- valueOut: 50,
156
- size: 135
157
- }
158
-
159
- const detailsPost = [details, details]
160
-
161
- module.exports = {
162
- utxo,
163
- utxoPost,
164
- unconfirmed,
165
- unconfirmedPost,
166
- transactions,
167
- transactionsPost,
168
- details,
169
- detailsPost
170
- }
@@ -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
- })