@psf/bch-js 5.4.0 → 5.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psf/bch-js",
3
- "version": "5.4.0",
3
+ "version": "5.4.1",
4
4
  "description": "The FullStack.cash JavaScript library for Bitcoin Cash and SLP Tokens",
5
5
  "author": "Chris Troutner <chris.troutner@gmail.com>",
6
6
  "contributors": [
@@ -15,113 +15,6 @@ describe('#UTXO', () => {
15
15
  if (process.env.IS_USING_FREE_TIER) await sleep(3000)
16
16
  })
17
17
 
18
- if (process.env.TESTSLP) {
19
- describe('#getOld', () => {
20
- it('should get hydrated and filtered UTXOs for an address', async () => {
21
- // const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9'
22
- const addr = 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
23
-
24
- const result = await bchjs.Utxo.getOld(addr)
25
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
26
-
27
- assert.isArray(result)
28
- assert.property(result[0], 'address')
29
- assert.property(result[0], 'bchUtxos')
30
- assert.property(result[0], 'nullUtxos')
31
- assert.property(result[0], 'slpUtxos')
32
- assert.isArray(result[0].bchUtxos)
33
- assert.isArray(result[0].nullUtxos)
34
- })
35
-
36
- it('should handle an array of addresses', async () => {
37
- const addr = [
38
- 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9',
39
- 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9'
40
- ]
41
-
42
- const result = await bchjs.Utxo.getOld(addr)
43
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
44
-
45
- assert.isArray(result)
46
- assert.property(result[0], 'address')
47
- assert.property(result[0], 'bchUtxos')
48
- assert.property(result[0], 'nullUtxos')
49
- assert.property(result[0], 'slpUtxos')
50
- assert.isArray(result[0].bchUtxos)
51
- assert.isArray(result[0].nullUtxos)
52
- })
53
-
54
- it('should handle NFTs and minting batons', async () => {
55
- const addr = 'simpleledger:qrm0c67wwqh0w7wjxua2gdt2xggnm90xwsr5k22euj'
56
-
57
- const result = await bchjs.Utxo.getOld(addr)
58
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
59
-
60
- assert.isArray(result)
61
- assert.property(result[0], 'address')
62
- assert.property(result[0], 'bchUtxos')
63
- assert.property(result[0], 'nullUtxos')
64
- assert.property(result[0], 'slpUtxos')
65
- assert.isArray(result[0].bchUtxos)
66
- assert.isArray(result[0].nullUtxos)
67
-
68
- assert.isArray(result[0].slpUtxos.type1.mintBatons)
69
- assert.isArray(result[0].slpUtxos.type1.tokens)
70
- assert.isArray(result[0].slpUtxos.nft.groupMintBatons)
71
- assert.isArray(result[0].slpUtxos.nft.groupTokens)
72
- assert.isArray(result[0].slpUtxos.nft.tokens)
73
- })
74
-
75
- it('should use the whitelist when flag is set', async () => {
76
- const addr = 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
77
- const useWhitelist = true
78
-
79
- const result = await bchjs.Utxo.getOld(addr, useWhitelist)
80
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
81
-
82
- assert.isArray(result)
83
- assert.property(result[0], 'address')
84
- assert.property(result[0], 'bchUtxos')
85
- assert.property(result[0], 'nullUtxos')
86
- assert.property(result[0], 'slpUtxos')
87
- assert.isArray(result[0].bchUtxos)
88
- assert.isArray(result[0].nullUtxos)
89
-
90
- // Most token UTXOs should end up in the nullUtxos array.
91
- assert.isAbove(result[0].bchUtxos.length, 0)
92
- assert.isAbove(result[0].nullUtxos.length, 1)
93
- })
94
- })
95
-
96
- describe('#findBiggestUtxo', () => {
97
- it('should sort UTXOs from Electrumx', async () => {
98
- const addr = 'bitcoincash:qq54fgjn3hz0357n8a6guy4demw9xfkjk5jcj0xr0z'
99
-
100
- const electrumxUtxos = await bchjs.Electrumx.utxo(addr)
101
- // console.log(`Electrumx utxos: ${JSON.stringify(electrumxUtxos, null, 2)}`)
102
-
103
- const result = bchjs.Utxo.findBiggestUtxo(electrumxUtxos.utxos)
104
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
105
-
106
- assert.property(result, 'satoshis')
107
- assert.equal(result.satoshis, 800)
108
- })
109
-
110
- it('should sort UTXOs from Utxos.get()', async () => {
111
- const addr = 'bitcoincash:qq54fgjn3hz0357n8a6guy4demw9xfkjk5jcj0xr0z'
112
-
113
- const utxos = await bchjs.Utxo.getOld(addr)
114
- // console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
115
-
116
- const result = bchjs.Utxo.findBiggestUtxo(utxos[0].bchUtxos)
117
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
118
-
119
- assert.property(result, 'satoshis')
120
- assert.equal(result.satoshis, 800)
121
- })
122
- })
123
- }
124
-
125
18
  describe('#hydrateTokenData', () => {
126
19
  it('should hydrate token UTXOs', async () => {
127
20
  const utxos = [
@@ -1,226 +0,0 @@
1
- /*
2
- Integration tests for the bchjs covering SLP tokens.
3
- These tests are specific to the ABC chain.
4
- */
5
-
6
- const chai = require('chai')
7
- const assert = chai.assert
8
-
9
- const BCHJS = require('../../../../src/bch-js')
10
- let bchjs
11
-
12
- // Inspect utility used for debugging.
13
- const util = require('util')
14
- util.inspect.defaultOptions = {
15
- showHidden: true,
16
- colors: true,
17
- depth: 1
18
- }
19
-
20
- describe('#SLP', () => {
21
- // before(() => {
22
- // console.log(`bchjs.SLP.restURL: ${bchjs.SLP.restURL}`)
23
- // console.log(`bchjs.SLP.apiToken: ${bchjs.SLP.apiToken}`)
24
- // })
25
-
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
- bchjs = new BCHJS({ restURL: process.env.RESTURL })
31
- })
32
-
33
- describe('#util', () => {
34
- describe('#tokenUtxoDetails', () => {
35
- it('should handle a range of UTXO types', async () => {
36
- const utxos = [
37
- // Malformed SLP tx
38
- {
39
- note: 'Malformed SLP tx',
40
- tx_hash:
41
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
42
- tx_pos: 1,
43
- value: 546
44
- },
45
- // Normal TX (non-SLP)
46
- {
47
- note: 'Normal TX (non-SLP)',
48
- tx_hash:
49
- '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
50
- tx_pos: 0,
51
- value: 400000
52
- },
53
- // Valid PSF SLP tx
54
- {
55
- note: 'Valid PSF SLP tx',
56
- tx_hash:
57
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
58
- tx_pos: 1,
59
- value: 546
60
- },
61
- // Valid SLP token not in whitelist
62
- {
63
- note: 'Valid SLP token not in whitelist',
64
- tx_hash:
65
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
66
- tx_pos: 1,
67
- value: 546
68
- },
69
- // Token send on BCHN network.
70
- {
71
- note: 'Token send on BCHN network',
72
- tx_hash:
73
- '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019',
74
- tx_pos: 1,
75
- value: 546
76
- },
77
- // Token send on ABC network.
78
- {
79
- note: 'Token send on ABC network',
80
- tx_hash:
81
- '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d',
82
- tx_pos: 1,
83
- value: 546
84
- },
85
- // Known invalid SLP token send of PSF tokens.
86
- {
87
- note: 'Known invalid SLP token send of PSF tokens',
88
- tx_hash:
89
- '2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74',
90
- tx_pos: 1,
91
- value: 546
92
- }
93
- ]
94
-
95
- const data = await bchjs.SLP.Utils.tokenUtxoDetails(utxos)
96
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
97
-
98
- // Malformed SLP tx
99
- assert.equal(data[0].tx_hash, utxos[0].tx_hash)
100
- assert.equal(data[0].isValid, false)
101
-
102
- // Normal TX (non-SLP)
103
- assert.equal(data[1].tx_hash, utxos[1].tx_hash)
104
- assert.equal(data[1].isValid, false)
105
-
106
- // Valid PSF SLP tx
107
- assert.equal(data[2].tx_hash, utxos[2].tx_hash)
108
- assert.equal(data[2].isValid, true)
109
-
110
- // Valid SLP token not in whitelist
111
- assert.equal(data[3].tx_hash, utxos[3].tx_hash)
112
- assert.equal(data[3].isValid, true)
113
-
114
- // Token send on BCHN network
115
- assert.equal(data[4].tx_hash, utxos[4].tx_hash)
116
- // assert.equal(data[4].isValid, true)
117
- assert.equal(data[4].isValid, null)
118
-
119
- // Token send on ABC network
120
- assert.equal(data[5].tx_hash, utxos[5].tx_hash)
121
- assert.equal(data[5].isValid, true)
122
-
123
- // Known invalid SLP token send of PSF tokens
124
- assert.equal(data[6].tx_hash, utxos[6].tx_hash)
125
- assert.equal(data[6].isValid, false)
126
- })
127
- })
128
-
129
- describe('#validateTxid3', () => {
130
- it('should invalidate a known invalid TXID', async () => {
131
- const txid =
132
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a'
133
-
134
- const result = await bchjs.SLP.Utils.validateTxid3(txid)
135
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
136
-
137
- assert.isArray(result)
138
-
139
- assert.property(result[0], 'txid')
140
- assert.equal(result[0].txid, txid)
141
-
142
- assert.property(result[0], 'valid')
143
- assert.equal(result[0].valid, null)
144
- })
145
-
146
- it('should validate a known valid TXID', async () => {
147
- const txid =
148
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd'
149
-
150
- const result = await bchjs.SLP.Utils.validateTxid3(txid)
151
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
152
-
153
- assert.isArray(result)
154
-
155
- assert.property(result[0], 'txid')
156
- assert.equal(result[0].txid, txid)
157
-
158
- assert.property(result[0], 'valid')
159
- assert.equal(result[0].valid, true)
160
- })
161
-
162
- it('should handle a mix of valid, invalid, and non-SLP txs', async () => {
163
- const txids = [
164
- // Malformed SLP tx
165
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
166
- // Normal TX (non-SLP)
167
- '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
168
- // Valid PSF SLP tx
169
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
170
- // Valid SLP token not in whitelist
171
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
172
- // Unprocessed SLP TX
173
- // "a0d6406eecfd8634158efa9314ff15b4cbf451938e9dc7b5678c46b41eabc6ed" // Mint baton
174
- '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019'
175
- ]
176
-
177
- const result = await bchjs.SLP.Utils.validateTxid3(txids)
178
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
179
-
180
- assert.isArray(result)
181
- assert.equal(result[0].valid, null)
182
- assert.equal(result[1].valid, null)
183
- assert.equal(result[2].valid, true)
184
- // assert.equal(result[2].valid, null)
185
- assert.equal(result[3].valid, true)
186
- assert.equal(result[4].valid, null)
187
- })
188
- })
189
-
190
- describe('#validateTxid', () => {
191
- it('should handle a mix of valid, invalid, and non-SLP txs', async () => {
192
- const txids = [
193
- // Malformed SLP tx
194
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
195
- // Normal TX (non-SLP)
196
- '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
197
- // Valid PSF SLP tx
198
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
199
- // Valid SLP token not in whitelist
200
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
201
- // Token send on BCHN network.
202
- '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019',
203
- // Token send on ABC network.
204
- '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d'
205
- ]
206
-
207
- const result = await bchjs.SLP.Utils.validateTxid(txids)
208
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
209
-
210
- assert.isArray(result)
211
- assert.equal(result[0].valid, null)
212
- assert.equal(result[1].valid, null)
213
- assert.equal(result[2].valid, true)
214
- // assert.equal(result[2].valid, null)
215
- assert.equal(result[3].valid, true)
216
- assert.equal(result[4].valid, null)
217
- assert.equal(result[5].valid, true)
218
- })
219
- })
220
- })
221
- })
222
-
223
- // Promise-based sleep function
224
- function sleep (ms) {
225
- return new Promise(resolve => setTimeout(resolve, ms))
226
- }
@@ -1,71 +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
- const BCHJS = require('../../../../src/bch-js')
11
- const bchjs = new BCHJS()
12
-
13
- // Inspect utility used for debugging.
14
- const util = require('util')
15
- util.inspect.defaultOptions = {
16
- showHidden: true,
17
- colors: true,
18
- depth: 3
19
- }
20
-
21
- describe('#rawtransaction', () => {
22
- beforeEach(async () => {
23
- if (process.env.IS_USING_FREE_TIER) await sleep(3000)
24
- })
25
-
26
- /*
27
- Testing sentRawTransaction isn't really possible with an integration test,
28
- as the endpoint really needs an e2e test to be properly tested. The tests
29
- below expect error messages returned from the server, but at least test
30
- that the server is responding on those endpoints, and responds consistently.
31
- */
32
- describe('sendRawTransaction', () => {
33
- it('should send a single transaction hex', async () => {
34
- try {
35
- const hex =
36
- '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
37
-
38
- await bchjs.RawTransactions.sendRawTransaction(hex)
39
- // console.log(`result ${JSON.stringify(result, null, 2)}`)
40
-
41
- assert.equal(true, false, 'Unexpected result!')
42
- } catch (err) {
43
- // console.log(`err: ${util.inspect(err)}`)
44
-
45
- assert.hasAllKeys(err, ['error'])
46
- assert.include(err.error, 'Missing inputs')
47
- }
48
- })
49
-
50
- it('should send an array of tx hexes', async () => {
51
- try {
52
- const hexes = [
53
- '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000',
54
- '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
55
- ]
56
-
57
- const result = await bchjs.RawTransactions.sendRawTransaction(hexes)
58
- console.log(`result ${JSON.stringify(result, null, 2)}`)
59
- } catch (err) {
60
- // console.log(`err: ${util.inspect(err)}`)
61
-
62
- assert.hasAllKeys(err, ['error'])
63
- assert.include(err.error, 'Missing inputs')
64
- }
65
- })
66
- })
67
- })
68
-
69
- function sleep (ms) {
70
- return new Promise(resolve => setTimeout(resolve, ms))
71
- }
@@ -1,273 +0,0 @@
1
- /*
2
- Integration tests for the bchjs covering SLP tokens.
3
- These tests are specific to the ABC chain.
4
- */
5
-
6
- const chai = require('chai')
7
- const assert = chai.assert
8
-
9
- const BCHJS = require('../../../../src/bch-js')
10
- let bchjs
11
-
12
- // Inspect utility used for debugging.
13
- const util = require('util')
14
- util.inspect.defaultOptions = {
15
- showHidden: true,
16
- colors: true,
17
- depth: 1
18
- }
19
-
20
- describe('#SLP', () => {
21
- // before(() => {
22
- // console.log(`bchjs.SLP.restURL: ${bchjs.SLP.restURL}`)
23
- // console.log(`bchjs.SLP.apiToken: ${bchjs.SLP.apiToken}`)
24
- // })
25
-
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(3000)
29
-
30
- bchjs = new BCHJS()
31
- })
32
-
33
- describe('#util', () => {
34
- describe('#decodeOpReturn', () => {
35
- it('should decode a NFT Child transaction', async () => {
36
- const txid =
37
- 'eeddccc4d716f04157ea132ac93a48040fea34a6b57f3d8f0cccb7d1a731ab2b'
38
-
39
- const data = await bchjs.SLP.Utils.decodeOpReturn(txid)
40
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
41
-
42
- assert.property(data, 'tokenType')
43
- assert.property(data, 'txType')
44
- assert.property(data, 'ticker')
45
- assert.property(data, 'name')
46
- assert.property(data, 'tokenId')
47
- assert.property(data, 'documentUri')
48
- assert.property(data, 'documentHash')
49
- assert.property(data, 'decimals')
50
- assert.property(data, 'mintBatonVout')
51
- assert.property(data, 'qty')
52
-
53
- assert.equal(data.tokenType, 65)
54
- assert.equal(data.mintBatonVout, 0)
55
- assert.equal(data.qty, '1')
56
- })
57
- })
58
-
59
- describe('#tokenUtxoDetails', () => {
60
- it('should handle a range of UTXO types', async () => {
61
- const utxos = [
62
- // Malformed SLP tx
63
- {
64
- note: 'Malformed SLP tx',
65
- tx_hash:
66
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
67
- tx_pos: 1,
68
- value: 546
69
- },
70
- // Normal TX (non-SLP)
71
- {
72
- note: 'Normal TX (non-SLP)',
73
- tx_hash:
74
- '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
75
- tx_pos: 0,
76
- value: 400000
77
- },
78
- // Valid PSF SLP tx
79
- {
80
- note: 'Valid PSF SLP tx',
81
- tx_hash:
82
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
83
- tx_pos: 1,
84
- value: 546
85
- },
86
- // Valid SLP token not in whitelist
87
- {
88
- note: 'Valid SLP token not in whitelist',
89
- tx_hash:
90
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
91
- tx_pos: 1,
92
- value: 546
93
- },
94
- // Token send on BCHN network.
95
- {
96
- note: 'Token send on BCHN network',
97
- tx_hash:
98
- '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019',
99
- tx_pos: 1,
100
- value: 546
101
- },
102
- // Token send on ABC network.
103
- {
104
- note: 'Token send on ABC network',
105
- tx_hash:
106
- '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d',
107
- tx_pos: 1,
108
- value: 546
109
- },
110
- // Known invalid SLP token send of PSF tokens.
111
- {
112
- note: 'Known invalid SLP token send of PSF tokens',
113
- tx_hash:
114
- '2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74',
115
- tx_pos: 1,
116
- value: 546
117
- }
118
- ]
119
-
120
- const data = await bchjs.SLP.Utils.tokenUtxoDetails(utxos)
121
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
122
-
123
- // Malformed SLP tx
124
- assert.equal(data[0].tx_hash, utxos[0].tx_hash)
125
- assert.equal(data[0].isValid, false)
126
-
127
- // Normal TX (non-SLP)
128
- assert.equal(data[1].tx_hash, utxos[1].tx_hash)
129
- assert.equal(data[1].isValid, false)
130
-
131
- // Valid PSF SLP tx
132
- assert.equal(data[2].tx_hash, utxos[2].tx_hash)
133
- assert.equal(data[2].isValid, true)
134
-
135
- // Valid SLP token not in whitelist
136
- assert.equal(data[3].tx_hash, utxos[3].tx_hash)
137
- assert.equal(data[3].isValid, true)
138
-
139
- // Token send on BCHN network
140
- assert.equal(data[4].tx_hash, utxos[4].tx_hash)
141
- assert.equal(data[4].isValid, true)
142
-
143
- // Token send on ABC network
144
- assert.equal(data[5].tx_hash, utxos[5].tx_hash)
145
- assert.equal(data[5].isValid, null)
146
-
147
- // Known invalid SLP token send of PSF tokens
148
- assert.equal(data[6].tx_hash, utxos[6].tx_hash)
149
- assert.equal(data[6].isValid, false)
150
- })
151
- })
152
-
153
- describe('#validateTxid3', () => {
154
- it('should invalidate a known invalid TXID', async () => {
155
- const txid =
156
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a'
157
-
158
- const result = await bchjs.SLP.Utils.validateTxid3(txid)
159
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
160
-
161
- assert.isArray(result)
162
-
163
- assert.property(result[0], 'txid')
164
- assert.equal(result[0].txid, txid)
165
-
166
- assert.property(result[0], 'valid')
167
- assert.equal(result[0].valid, null)
168
- })
169
-
170
- it('should validate a known valid TXID', async () => {
171
- const txid =
172
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd'
173
-
174
- const result = await bchjs.SLP.Utils.validateTxid3(txid)
175
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
176
-
177
- assert.isArray(result)
178
-
179
- assert.property(result[0], 'txid')
180
- assert.equal(result[0].txid, txid)
181
-
182
- assert.property(result[0], 'valid')
183
- assert.equal(result[0].valid, true)
184
- })
185
-
186
- it('should handle a mix of valid, invalid, and non-SLP txs', async () => {
187
- const txids = [
188
- // Malformed SLP tx
189
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
190
- // Normal TX (non-SLP)
191
- '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
192
- // Valid PSF SLP tx
193
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
194
- // Valid SLP token not in whitelist
195
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
196
- // Unprocessed SLP TX
197
- '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019'
198
- ]
199
-
200
- const result = await bchjs.SLP.Utils.validateTxid3(txids)
201
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
202
-
203
- assert.isArray(result)
204
-
205
- assert.equal(result[0].txid, txids[0])
206
- assert.equal(result[0].valid, null)
207
-
208
- assert.equal(result[1].txid, txids[1])
209
- assert.equal(result[1].valid, null)
210
-
211
- assert.equal(result[2].txid, txids[2])
212
- assert.equal(result[2].valid, true)
213
-
214
- // True in validateTxid() (no whitelist SLPDB) but null in validateTxid3()
215
- assert.equal(result[3].txid, txids[3])
216
- assert.equal(result[3].valid, true)
217
-
218
- // Note: This should change from null to true once SLPDB finishes indexing.
219
- assert.equal(result[4].txid, txids[4])
220
- // True when no whitelist SLPDB is used.
221
- assert.equal(result[4].valid, true)
222
- })
223
- })
224
-
225
- describe('#validateTxid', () => {
226
- it('should handle a mix of valid, invalid, and non-SLP txs', async () => {
227
- const txids = [
228
- // Malformed SLP tx
229
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
230
- // Normal TX (non-SLP)
231
- '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
232
- // Valid PSF SLP tx
233
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
234
- // Valid SLP token not in whitelist
235
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
236
- // Token send on BCHN network.
237
- '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019',
238
- // Token send on ABC network.
239
- '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d'
240
- ]
241
-
242
- const result = await bchjs.SLP.Utils.validateTxid(txids)
243
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
244
-
245
- assert.isArray(result)
246
-
247
- assert.equal(result[0].txid, txids[0])
248
- assert.equal(result[0].valid, null)
249
-
250
- assert.equal(result[1].txid, txids[1])
251
- assert.equal(result[1].valid, null)
252
-
253
- assert.equal(result[2].txid, txids[2])
254
- assert.equal(result[2].valid, true)
255
-
256
- // True in validateTxid() but null in validateTxid3()
257
- assert.equal(result[3].txid, txids[3])
258
- assert.equal(result[3].valid, true)
259
-
260
- assert.equal(result[4].txid, txids[4])
261
- assert.equal(result[4].valid, true)
262
-
263
- assert.equal(result[5].txid, txids[5])
264
- assert.equal(result[5].valid, null)
265
- })
266
- })
267
- })
268
- })
269
-
270
- // Promise-based sleep function
271
- function sleep (ms) {
272
- return new Promise(resolve => setTimeout(resolve, ms))
273
- }
@@ -1,105 +0,0 @@
1
- /*
2
- Integration tests for the utxo.js library.
3
- */
4
-
5
- const assert = require('chai').assert
6
-
7
- const BCHJS = require('../../../../src/bch-js')
8
- const bchjs = new BCHJS()
9
-
10
- describe('#UTXO', () => {
11
- beforeEach(async () => {
12
- // sandbox = sinon.createSandbox()
13
-
14
- if (process.env.IS_USING_FREE_TIER) await sleep(3000)
15
- })
16
-
17
- describe('#get', () => {
18
- it('should get hydrated and filtered UTXOs for an address', async () => {
19
- // const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9'
20
- const addr = 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
21
-
22
- const result = await bchjs.Utxo.get(addr)
23
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
24
-
25
- assert.isArray(result)
26
- assert.property(result[0], 'address')
27
- assert.property(result[0], 'bchUtxos')
28
- assert.property(result[0], 'nullUtxos')
29
- assert.property(result[0], 'slpUtxos')
30
- assert.isArray(result[0].bchUtxos)
31
- assert.isArray(result[0].nullUtxos)
32
- })
33
-
34
- it('should handle an array of addresses', async () => {
35
- const addr = [
36
- 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9',
37
- 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9'
38
- ]
39
-
40
- const result = await bchjs.Utxo.get(addr)
41
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
42
-
43
- assert.isArray(result)
44
- assert.property(result[0], 'address')
45
- assert.property(result[0], 'bchUtxos')
46
- assert.property(result[0], 'nullUtxos')
47
- assert.property(result[0], 'slpUtxos')
48
- assert.isArray(result[0].bchUtxos)
49
- assert.isArray(result[0].nullUtxos)
50
- })
51
-
52
- it('should handle NFTs and minting batons', async () => {
53
- const addr = 'simpleledger:qrm0c67wwqh0w7wjxua2gdt2xggnm90xwsr5k22euj'
54
-
55
- const result = await bchjs.Utxo.get(addr)
56
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
57
-
58
- assert.isArray(result)
59
- assert.property(result[0], 'address')
60
- assert.property(result[0], 'bchUtxos')
61
- assert.property(result[0], 'nullUtxos')
62
- assert.property(result[0], 'slpUtxos')
63
- assert.isArray(result[0].bchUtxos)
64
- assert.isArray(result[0].nullUtxos)
65
-
66
- assert.isArray(result[0].slpUtxos.type1.mintBatons)
67
- assert.isArray(result[0].slpUtxos.type1.tokens)
68
- assert.isArray(result[0].slpUtxos.nft.groupMintBatons)
69
- assert.isArray(result[0].slpUtxos.nft.groupTokens)
70
- assert.isArray(result[0].slpUtxos.nft.tokens)
71
- })
72
- })
73
-
74
- describe('#findBiggestUtxo', () => {
75
- it('should sort UTXOs from Electrumx', async () => {
76
- const addr = 'bitcoincash:qq54fgjn3hz0357n8a6guy4demw9xfkjk5jcj0xr0z'
77
-
78
- const electrumxUtxos = await bchjs.Electrumx.utxo(addr)
79
- // console.log(`Electrumx utxos: ${JSON.stringify(electrumxUtxos, null, 2)}`)
80
-
81
- const result = bchjs.Utxo.findBiggestUtxo(electrumxUtxos.utxos)
82
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
83
-
84
- assert.property(result, 'satoshis')
85
- assert.equal(result.satoshis, 800)
86
- })
87
-
88
- it('should sort UTXOs from Utxos.get()', async () => {
89
- const addr = 'bitcoincash:qq54fgjn3hz0357n8a6guy4demw9xfkjk5jcj0xr0z'
90
-
91
- const utxos = await bchjs.Utxo.get(addr)
92
- // console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
93
-
94
- const result = bchjs.Utxo.findBiggestUtxo(utxos[0].bchUtxos)
95
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
96
-
97
- assert.property(result, 'satoshis')
98
- assert.equal(result.satoshis, 800)
99
- })
100
- })
101
- })
102
-
103
- function sleep (ms) {
104
- return new Promise(resolve => setTimeout(resolve, ms))
105
- }