@psf/bch-js 4.20.27 → 4.22.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.
@@ -30,265 +30,269 @@ describe('#SLP', () => {
30
30
  bchjs = new BCHJS()
31
31
  })
32
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')
33
+ if (process.env.TESTSLP) {
34
+ describe('#util', () => {
35
+ describe('#decodeOpReturn', () => {
36
+ it('should decode a NFT Child transaction', async () => {
37
+ const txid =
38
+ 'eeddccc4d716f04157ea132ac93a48040fea34a6b57f3d8f0cccb7d1a731ab2b'
39
+
40
+ const data = await bchjs.SLP.Utils.decodeOpReturn(txid)
41
+ // console.log(`data: ${JSON.stringify(data, null, 2)}`)
42
+
43
+ assert.property(data, 'tokenType')
44
+ assert.property(data, 'txType')
45
+ assert.property(data, 'ticker')
46
+ assert.property(data, 'name')
47
+ assert.property(data, 'tokenId')
48
+ assert.property(data, 'documentUri')
49
+ assert.property(data, 'documentHash')
50
+ assert.property(data, 'decimals')
51
+ assert.property(data, 'mintBatonVout')
52
+ assert.property(data, 'qty')
53
+
54
+ assert.equal(data.tokenType, 65)
55
+ assert.equal(data.mintBatonVout, 0)
56
+ assert.equal(data.qty, '1')
57
+ })
56
58
  })
57
- })
58
59
 
59
- describe('#tokenUtxoDetails', () => {
60
- it('should handle a range of UTXO types', async () => {
61
- const utxos = [
60
+ describe('#tokenUtxoDetails', () => {
61
+ it('should handle a range of UTXO types', async () => {
62
+ const utxos = [
63
+ // Malformed SLP tx
64
+ {
65
+ note: 'Malformed SLP tx',
66
+ tx_hash:
67
+ 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
68
+ tx_pos: 1,
69
+ value: 546
70
+ },
71
+ // Normal TX (non-SLP)
72
+ {
73
+ note: 'Normal TX (non-SLP)',
74
+ tx_hash:
75
+ '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
76
+ tx_pos: 0,
77
+ value: 400000
78
+ },
79
+ // Valid PSF SLP tx
80
+ {
81
+ note: 'Valid PSF SLP tx',
82
+ tx_hash:
83
+ 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
84
+ tx_pos: 1,
85
+ value: 546
86
+ },
87
+ // Valid SLP token not in whitelist
88
+ {
89
+ note: 'Valid SLP token not in whitelist',
90
+ tx_hash:
91
+ '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
92
+ tx_pos: 1,
93
+ value: 546
94
+ },
95
+ // Token send on BCHN network.
96
+ {
97
+ note: 'Token send on BCHN network',
98
+ tx_hash:
99
+ '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019',
100
+ tx_pos: 1,
101
+ value: 546
102
+ },
103
+ // Token send on ABC network.
104
+ {
105
+ note: 'Token send on ABC network',
106
+ tx_hash:
107
+ '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d',
108
+ tx_pos: 1,
109
+ value: 546
110
+ },
111
+ // Known invalid SLP token send of PSF tokens.
112
+ {
113
+ note: 'Known invalid SLP token send of PSF tokens',
114
+ tx_hash:
115
+ '2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74',
116
+ tx_pos: 1,
117
+ value: 546
118
+ }
119
+ ]
120
+
121
+ const data = await bchjs.SLP.Utils.tokenUtxoDetails(utxos)
122
+ // console.log(`data: ${JSON.stringify(data, null, 2)}`)
123
+
62
124
  // Malformed SLP tx
63
- {
64
- note: 'Malformed SLP tx',
65
- tx_hash:
66
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
67
- tx_pos: 1,
68
- value: 546
69
- },
125
+ assert.equal(data[0].tx_hash, utxos[0].tx_hash)
126
+ assert.equal(data[0].isValid, false)
127
+
70
128
  // 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
- })
129
+ assert.equal(data[1].tx_hash, utxos[1].tx_hash)
130
+ assert.equal(data[1].isValid, false)
152
131
 
153
- describe('#validateTxid3', () => {
154
- it('should invalidate a known invalid TXID', async () => {
155
- const txid =
156
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a'
132
+ // Valid PSF SLP tx
133
+ assert.equal(data[2].tx_hash, utxos[2].tx_hash)
134
+ assert.equal(data[2].isValid, true)
157
135
 
158
- const result = await bchjs.SLP.Utils.validateTxid3(txid)
159
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
136
+ // Valid SLP token not in whitelist
137
+ assert.equal(data[3].tx_hash, utxos[3].tx_hash)
138
+ assert.equal(data[3].isValid, true)
160
139
 
161
- assert.isArray(result)
140
+ // Token send on BCHN network
141
+ assert.equal(data[4].tx_hash, utxos[4].tx_hash)
142
+ assert.equal(data[4].isValid, true)
162
143
 
163
- assert.property(result[0], 'txid')
164
- assert.equal(result[0].txid, txid)
144
+ // Token send on ABC network
145
+ assert.equal(data[5].tx_hash, utxos[5].tx_hash)
146
+ assert.equal(data[5].isValid, null)
165
147
 
166
- assert.property(result[0], 'valid')
167
- assert.equal(result[0].valid, null)
148
+ // Known invalid SLP token send of PSF tokens
149
+ assert.equal(data[6].tx_hash, utxos[6].tx_hash)
150
+ assert.equal(data[6].isValid, false)
151
+ })
168
152
  })
169
153
 
170
- it('should validate a known valid TXID', async () => {
171
- const txid =
172
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd'
154
+ describe('#validateTxid3', () => {
155
+ it('should invalidate a known invalid TXID', async () => {
156
+ const txid =
157
+ 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a'
173
158
 
174
- const result = await bchjs.SLP.Utils.validateTxid3(txid)
175
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
159
+ const result = await bchjs.SLP.Utils.validateTxid3(txid)
160
+ // console.log(`result: ${JSON.stringify(result, null, 2)}`)
176
161
 
177
- assert.isArray(result)
162
+ assert.isArray(result)
178
163
 
179
- assert.property(result[0], 'txid')
180
- assert.equal(result[0].txid, txid)
164
+ assert.property(result[0], 'txid')
165
+ assert.equal(result[0].txid, txid)
181
166
 
182
- assert.property(result[0], 'valid')
183
- assert.equal(result[0].valid, true)
184
- })
167
+ assert.property(result[0], 'valid')
168
+ assert.equal(result[0].valid, null)
169
+ })
185
170
 
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
- ]
171
+ it('should validate a known valid TXID', async () => {
172
+ const txid =
173
+ 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd'
199
174
 
200
- const result = await bchjs.SLP.Utils.validateTxid3(txids)
201
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
175
+ const result = await bchjs.SLP.Utils.validateTxid3(txid)
176
+ // console.log(`result: ${JSON.stringify(result, null, 2)}`)
202
177
 
203
- assert.isArray(result)
178
+ assert.isArray(result)
204
179
 
205
- assert.equal(result[0].txid, txids[0])
206
- assert.equal(result[0].valid, null)
180
+ assert.property(result[0], 'txid')
181
+ assert.equal(result[0].txid, txid)
207
182
 
208
- assert.equal(result[1].txid, txids[1])
209
- assert.equal(result[1].valid, null)
183
+ assert.property(result[0], 'valid')
184
+ assert.equal(result[0].valid, true)
185
+ })
210
186
 
211
- assert.equal(result[2].txid, txids[2])
212
- assert.equal(result[2].valid, true)
187
+ it('should handle a mix of valid, invalid, and non-SLP txs', async () => {
188
+ const txids = [
189
+ // Malformed SLP tx
190
+ 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
191
+ // Normal TX (non-SLP)
192
+ '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
193
+ // Valid PSF SLP tx
194
+ 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
195
+ // Valid SLP token not in whitelist
196
+ '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
197
+ // Unprocessed SLP TX
198
+ '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019'
199
+ ]
213
200
 
214
- // True in validateTxid() but null in validateTxid3()
215
- assert.equal(result[3].txid, txids[3])
216
- assert.equal(result[3].valid, null)
201
+ const result = await bchjs.SLP.Utils.validateTxid3(txids)
202
+ // console.log(`result: ${JSON.stringify(result, null, 2)}`)
217
203
 
218
- // Note: This should change from null to true once SLPDB finishes indexing.
219
- assert.equal(result[4].txid, txids[4])
220
- assert.equal(result[4].valid, null)
221
- })
222
- })
223
-
224
- describe('#validateTxid', () => {
225
- it('should handle a mix of valid, invalid, and non-SLP txs', async () => {
226
- const txids = [
227
- // Malformed SLP tx
228
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
229
- // Normal TX (non-SLP)
230
- '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
231
- // Valid PSF SLP tx
232
- 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
233
- // Valid SLP token not in whitelist
234
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
235
- // Token send on BCHN network.
236
- '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019',
237
- // Token send on ABC network.
238
- '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d'
239
- ]
204
+ assert.isArray(result)
240
205
 
241
- const result = await bchjs.SLP.Utils.validateTxid(txids)
242
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
206
+ assert.equal(result[0].txid, txids[0])
207
+ assert.equal(result[0].valid, null)
243
208
 
244
- assert.isArray(result)
209
+ assert.equal(result[1].txid, txids[1])
210
+ assert.equal(result[1].valid, null)
245
211
 
246
- assert.equal(result[0].txid, txids[0])
247
- assert.equal(result[0].valid, null)
212
+ assert.equal(result[2].txid, txids[2])
213
+ assert.equal(result[2].valid, true)
248
214
 
249
- assert.equal(result[1].txid, txids[1])
250
- assert.equal(result[1].valid, null)
215
+ // True in validateTxid() but null in validateTxid3()
216
+ assert.equal(result[3].txid, txids[3])
217
+ assert.equal(result[3].valid, null)
251
218
 
252
- assert.equal(result[2].txid, txids[2])
253
- assert.equal(result[2].valid, true)
254
-
255
- // True in validateTxid() but null in validateTxid3()
256
- assert.equal(result[3].txid, txids[3])
257
- assert.equal(result[3].valid, true)
258
-
259
- assert.equal(result[4].txid, txids[4])
260
- assert.equal(result[4].valid, true)
219
+ // Note: This should change from null to true once SLPDB finishes indexing.
220
+ assert.equal(result[4].txid, txids[4])
221
+ assert.equal(result[4].valid, null)
222
+ })
223
+ })
261
224
 
262
- assert.equal(result[5].txid, txids[5])
263
- assert.equal(result[5].valid, null)
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
+ })
264
266
  })
265
267
  })
266
- })
267
- describe('#nft1', () => {
268
- describe('#listNFTGroupChildren', () => {
269
- it('should return array of children GENESIS transactions IDs', async () => {
270
- const groupId = '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a'
271
- const result = await bchjs.SLP.NFT1.listNFTGroupChildren(groupId)
272
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
273
- assert.property(result, 'nftChildren')
274
- assert.isArray(result.nftChildren)
268
+ describe('#nft1', () => {
269
+ describe('#listNFTGroupChildren', () => {
270
+ it('should return array of children GENESIS transactions IDs', async () => {
271
+ const groupId =
272
+ '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a'
273
+ const result = await bchjs.SLP.NFT1.listNFTGroupChildren(groupId)
274
+ // console.log(`result: ${JSON.stringify(result, null, 2)}`)
275
+ assert.property(result, 'nftChildren')
276
+ assert.isArray(result.nftChildren)
277
+ })
275
278
  })
276
- })
277
- describe('#parentNFTGroup', () => {
278
- it('should return parent NFT group information', async () => {
279
- const tokenId = '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9'
280
- const result = await bchjs.SLP.NFT1.parentNFTGroup(tokenId)
281
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
282
- assert.property(result, 'nftGroup')
283
- assert.property(result.nftGroup, 'id')
284
- assert.property(result.nftGroup, 'name')
285
- assert.property(result.nftGroup, 'symbol')
286
- assert.property(result.nftGroup, 'documentUri')
287
- assert.property(result.nftGroup, 'versionType')
288
- assert.property(result.nftGroup, 'initialTokenQty')
279
+ describe('#parentNFTGroup', () => {
280
+ it('should return parent NFT group information', async () => {
281
+ const tokenId =
282
+ '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9'
283
+ const result = await bchjs.SLP.NFT1.parentNFTGroup(tokenId)
284
+ // console.log(`result: ${JSON.stringify(result, null, 2)}`)
285
+ assert.property(result, 'nftGroup')
286
+ assert.property(result.nftGroup, 'id')
287
+ assert.property(result.nftGroup, 'name')
288
+ assert.property(result.nftGroup, 'symbol')
289
+ assert.property(result.nftGroup, 'documentUri')
290
+ assert.property(result.nftGroup, 'versionType')
291
+ assert.property(result.nftGroup, 'initialTokenQty')
292
+ })
289
293
  })
290
294
  })
291
- })
295
+ }
292
296
  })
293
297
 
294
298
  // Promise-based sleep function