@psf/bch-js 6.8.3 → 7.0.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/README.md +10 -28
- package/fix-docs-contrast.sh +38 -0
- package/package.json +37 -46
- package/src/address.js +12 -23
- package/src/bch-js.js +81 -48
- package/src/bitcoincash.js +10 -11
- package/src/blockchain.js +57 -68
- package/src/control.js +11 -22
- package/src/crypto.js +3 -3
- package/src/dsproof.js +6 -17
- package/src/ecash.js +1 -1
- package/src/ecpair.js +3 -3
- package/src/electrumx.js +32 -44
- package/src/encryption.js +8 -17
- package/src/generating.js +8 -19
- package/src/hdnode.js +5 -5
- package/src/mining.js +11 -22
- package/src/mnemonic.js +8 -11
- package/src/price.js +7 -108
- package/src/psf-slp-indexer.js +21 -32
- package/src/raw-transactions.js +22 -35
- package/src/schnorr.js +5 -16
- package/src/script.js +4 -2
- package/src/slp/address.js +4 -4
- package/src/slp/ecpair.js +4 -4
- package/src/slp/nft1.js +6 -6
- package/src/slp/slp.js +11 -22
- package/src/slp/tokentype1.js +11 -22
- package/src/slp/utils.js +9 -19
- package/src/transaction-builder.js +5 -5
- package/src/transaction.js +5 -5
- package/src/util.js +5 -98
- package/src/utxo.js +6 -6
- package/test/e2e/bch-js-e2e-tests.js +4 -3
- package/test/e2e/ipfs/ipfs-e2e.js +8 -2
- package/test/e2e/rate-limits/anonymous-rate-limits.js +5 -4
- package/test/e2e/rate-limits/basic-auth-rate-limits.js +4 -3
- package/test/e2e/rate-limits/free-rate-limits.js +4 -3
- package/test/e2e/rate-limits/full-node-rate-limits.js +4 -3
- package/test/e2e/rate-limits/indexer-rate-limits.js +4 -3
- package/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js +28 -18
- package/test/e2e/send-raw-transaction-single/sendrawtransaction.js +28 -18
- package/test/e2e/send-token/send-token.js +4 -4
- package/test/e2e/util/e2e-util.js +6 -3
- package/test/e2e/utxo/unsynced-indexer.js +1 -1
- package/test/integration/blockchain.js +5 -5
- package/test/integration/control.js +2 -2
- package/test/integration/{chains/bchn/dsproof.js → dsproof.js} +6 -2
- package/test/integration/electrumx.js +5 -12
- package/test/integration/price.js +3 -39
- package/test/integration/{chains/bchn/psf-slp-indexer.integration.js → psf-slp-indexer.integration.js} +5 -6
- package/test/integration/rawtransaction.js +39 -5
- package/test/integration/slp.js +147 -5
- package/test/integration/transaction-integration.js +27 -2
- package/test/integration/{chains/bchn/utxo-integration.js → utxo-integration.js} +3 -2
- package/test/unit/address.js +7 -4
- package/test/unit/bitcoin-cash.js +5 -3
- package/test/unit/blockchain.js +23 -22
- package/test/unit/control.js +6 -6
- package/test/unit/crypto.js +5 -3
- package/test/unit/dsproof.js +5 -4
- package/test/unit/ecash.js +3 -2
- package/test/unit/ecpairs.js +6 -4
- package/test/unit/electrumx.js +7 -7
- package/test/unit/encryption.js +6 -5
- package/test/unit/fixtures/bitcore-mock.js +1 -1
- package/test/unit/fixtures/block-mock.js +1 -1
- package/test/unit/fixtures/blockchain-mock.js +1 -1
- package/test/unit/fixtures/dsproof-mock.js +1 -1
- package/test/unit/fixtures/electrumx-mock.js +1 -1
- package/test/unit/fixtures/encryption-mock.js +1 -1
- package/test/unit/fixtures/ipfs-mock.js +1 -1
- package/test/unit/fixtures/openbazaar-mock.js +1 -1
- package/test/unit/fixtures/price-mocks.js +1 -1
- package/test/unit/fixtures/psf-slp-indexer-mock.js +1 -1
- package/test/unit/fixtures/rawtransaction-mock.js +1 -1
- package/test/unit/fixtures/slp/mock-utils.js +1 -1
- package/test/unit/fixtures/transaction-mock.js +1 -1
- package/test/unit/fixtures/utxo-mocks.js +1 -1
- package/test/unit/generating.js +5 -5
- package/test/unit/hdnode.js +6 -4
- package/test/unit/mining.js +8 -8
- package/test/unit/mnemonic.js +4 -2
- package/test/unit/price.js +5 -14
- package/test/unit/psf-slp-indexer.js +7 -7
- package/test/unit/raw-tranactions.js +14 -13
- package/test/unit/scripts.js +8 -6
- package/test/unit/slp-address.js +6 -4
- package/test/unit/slp-ecpair.js +5 -3
- package/test/unit/slp-nft1.js +7 -6
- package/test/unit/slp-tokentype1.js +7 -6
- package/test/unit/slp-utils.js +8 -7
- package/test/unit/transaction-builder.js +7 -4
- package/test/unit/transaction-unit.js +5 -4
- package/test/unit/util.js +11 -32
- package/test/unit/utxo-unit.js +6 -5
- package/test/unit/x402.js +193 -0
- package/test/integration/chains/abc/psf-slp-indexer-integration.js +0 -38
- package/test/integration/chains/abc/rawtransaction.js +0 -73
- package/test/integration/chains/abc/utxo-integration.js +0 -38
- package/test/integration/chains/bchn/rawtransaction.js +0 -71
- package/test/integration/chains/bchn/slp.js +0 -301
- package/test/integration/chains/bchn/transaction-integration.js +0 -37
- package/test/integration/chains/bchn/util.js +0 -103
- package/test/integration/chains/testnet/blockchain.js +0 -260
- package/test/integration/chains/testnet/control.js +0 -32
- package/test/integration/chains/testnet/electrumx.js +0 -376
- package/test/integration/chains/testnet/rawtransaction.js +0 -296
- package/test/integration/chains/testnet/slp.js +0 -172
- package/test/integration/chains/testnet/test-free-tier.sh +0 -9
- package/test/integration/chains/testnet/util.js +0 -109
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
tests.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import SLPSDK from '../../../lib/SLP.js'
|
|
7
|
+
|
|
8
|
+
export default {
|
|
7
9
|
openWallet,
|
|
8
10
|
sendToken,
|
|
9
11
|
getTestTokenBalance,
|
|
10
12
|
threeDecimals
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
const SLPSDK = require('../../../lib/SLP')
|
|
14
14
|
const slpsdk = new SLPSDK()
|
|
15
15
|
|
|
16
16
|
const testTokenId =
|
|
@@ -20,6 +20,9 @@ const testTokenId =
|
|
|
20
20
|
// token balance.
|
|
21
21
|
async function openWallet (filename) {
|
|
22
22
|
try {
|
|
23
|
+
// Note: Dynamic imports for JSON files - use createRequire
|
|
24
|
+
const { createRequire } = await import('module')
|
|
25
|
+
const require = createRequire(import.meta.url)
|
|
23
26
|
const walletInfo = require(filename)
|
|
24
27
|
|
|
25
28
|
// const walletBalance = await getBalance(walletInfo)
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
of an e2e test to be properly tested.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const BCHJS = require('../../src/bch-js')
|
|
13
|
-
const bchjs = new BCHJS()
|
|
10
|
+
import chai from 'chai'
|
|
11
|
+
import BCHJS from '../../src/bch-js.js'
|
|
14
12
|
|
|
15
13
|
// Inspect utility used for debugging.
|
|
16
|
-
|
|
14
|
+
import util from 'util'
|
|
15
|
+
const assert = chai.assert
|
|
16
|
+
const bchjs = new BCHJS()
|
|
17
17
|
util.inspect.defaultOptions = {
|
|
18
18
|
showHidden: true,
|
|
19
19
|
colors: true,
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Integration tests for bchjs control library.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import chai from 'chai'
|
|
6
|
+
import BCHJS from '../../src/bch-js.js'
|
|
6
7
|
const assert = chai.assert
|
|
7
|
-
const BCHJS = require('../../src/bch-js')
|
|
8
8
|
const bchjs = new BCHJS()
|
|
9
9
|
|
|
10
10
|
describe('#control', () => {
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Integration tests for bchjs dsproof library.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// Global npm libraries
|
|
6
|
+
import chai from 'chai'
|
|
7
|
+
|
|
8
|
+
// Local libraries
|
|
9
|
+
import BCHJS from '../../src/bch-js.js'
|
|
10
|
+
const { assert } = chai
|
|
6
11
|
|
|
7
|
-
const BCHJS = require('../../../../src/bch-js')
|
|
8
12
|
const bchjs = new BCHJS()
|
|
9
13
|
|
|
10
14
|
describe('#DSProof', () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon')
|
|
1
|
+
import chai from 'chai'
|
|
2
|
+
import sinon from 'sinon'
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
import BCHJS from '../../src/bch-js.js'
|
|
5
|
+
const assert = chai.assert
|
|
6
6
|
const bchjs = new BCHJS()
|
|
7
7
|
|
|
8
8
|
describe('#ElectrumX', () => {
|
|
@@ -359,20 +359,14 @@ describe('#ElectrumX', () => {
|
|
|
359
359
|
try {
|
|
360
360
|
await bchjs.Electrumx.broadcast(txHex)
|
|
361
361
|
} catch (err) {
|
|
362
|
-
// console.log('err: ', err)
|
|
363
|
-
|
|
364
|
-
assert.property(err, 'success')
|
|
365
|
-
assert.equal(err.success, false)
|
|
366
362
|
assert.include(
|
|
367
|
-
err.error
|
|
363
|
+
err.error,
|
|
368
364
|
'the transaction was rejected by network rules'
|
|
369
365
|
)
|
|
370
366
|
}
|
|
371
367
|
})
|
|
372
368
|
})
|
|
373
369
|
|
|
374
|
-
/*
|
|
375
|
-
CT 3/14/23 - This test is frequently failing in BVT due to 429 errors.
|
|
376
370
|
describe('#sortAllTxs', () => {
|
|
377
371
|
it('should GET transaction history for a single address', async () => {
|
|
378
372
|
// Add delay for this endpoint.
|
|
@@ -391,7 +385,6 @@ describe('#ElectrumX', () => {
|
|
|
391
385
|
assert.isAbove(sortedTransactions[0].height, sortedTransactions[1].height)
|
|
392
386
|
})
|
|
393
387
|
})
|
|
394
|
-
*/
|
|
395
388
|
})
|
|
396
389
|
|
|
397
390
|
function sleep (ms) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import chai from 'chai'
|
|
2
|
+
import BCHJS from '../../src/bch-js.js'
|
|
3
|
+
const { assert } = chai
|
|
3
4
|
const bchjs = new BCHJS()
|
|
4
5
|
|
|
5
6
|
describe('#price', () => {
|
|
@@ -7,33 +8,6 @@ describe('#price', () => {
|
|
|
7
8
|
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
|
|
8
9
|
})
|
|
9
10
|
|
|
10
|
-
// describe('#current', () => {
|
|
11
|
-
// describe('#single currency', () => {
|
|
12
|
-
// it('should get current price for single currency', async () => {
|
|
13
|
-
// const result = await bchjs.Price.current('usd')
|
|
14
|
-
// assert.notEqual(0, result)
|
|
15
|
-
// })
|
|
16
|
-
// })
|
|
17
|
-
// })
|
|
18
|
-
|
|
19
|
-
describe('#getUsd', () => {
|
|
20
|
-
it('should get the USD price of BCH', async () => {
|
|
21
|
-
const result = await bchjs.Price.getUsd()
|
|
22
|
-
// console.log(result)
|
|
23
|
-
|
|
24
|
-
assert.isNumber(result)
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
describe('#getBchaUsd', () => {
|
|
29
|
-
it('should get the USD price of BCHA', async () => {
|
|
30
|
-
const result = await bchjs.Price.getBchaUsd()
|
|
31
|
-
console.log(result)
|
|
32
|
-
|
|
33
|
-
assert.isNumber(result)
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
11
|
describe('#getBchUsd', () => {
|
|
38
12
|
it('should get the USD price of BCH', async () => {
|
|
39
13
|
const result = await bchjs.Price.getBchUsd()
|
|
@@ -43,16 +17,6 @@ describe('#price', () => {
|
|
|
43
17
|
})
|
|
44
18
|
})
|
|
45
19
|
|
|
46
|
-
describe('#rates', () => {
|
|
47
|
-
it('should get the price of BCH in several currencies', async () => {
|
|
48
|
-
const result = await bchjs.Price.rates()
|
|
49
|
-
// console.log(result)
|
|
50
|
-
|
|
51
|
-
assert.property(result, 'USD')
|
|
52
|
-
assert.property(result, 'CAD')
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
|
|
56
20
|
describe('#getPsffppPrice', () => {
|
|
57
21
|
it('should get the price of BCH in several currencies', async () => {
|
|
58
22
|
const result = await bchjs.Price.getPsffppPrice()
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// Global npm libraries
|
|
7
|
-
|
|
7
|
+
import chai from 'chai'
|
|
8
8
|
|
|
9
9
|
// Local libraries
|
|
10
|
-
|
|
10
|
+
import BCHJS from '../../src/bch-js.js'
|
|
11
|
+
const { assert } = chai
|
|
11
12
|
let bchjs
|
|
12
13
|
|
|
13
14
|
describe('#psf-slp-indexer', () => {
|
|
@@ -95,9 +96,7 @@ describe('#psf-slp-indexer', () => {
|
|
|
95
96
|
})
|
|
96
97
|
|
|
97
98
|
// FlexUSD transactions
|
|
98
|
-
//
|
|
99
|
-
// the wallet will burn them. There is a TODO in the code. This test will
|
|
100
|
-
// need to be changed when it is done.
|
|
99
|
+
// FlexUSD is blacklisted by the SLP indexer.
|
|
101
100
|
it('should mark blacklisted token as null', async () => {
|
|
102
101
|
const txid =
|
|
103
102
|
'302113c11b90edc5f36c073d2f8a75e1e0eaf59b56235491a843d3819cd6a85f'
|
|
@@ -108,7 +107,7 @@ describe('#psf-slp-indexer', () => {
|
|
|
108
107
|
assert.property(result.txData, 'vin')
|
|
109
108
|
assert.property(result.txData, 'vout')
|
|
110
109
|
assert.property(result.txData, 'isValidSlp')
|
|
111
|
-
assert.equal(result.txData.isValidSlp,
|
|
110
|
+
assert.equal(result.txData.isValidSlp, false)
|
|
112
111
|
})
|
|
113
112
|
|
|
114
113
|
it('should throw error for non-existent txid', async () => {
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
TODO
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const BCHJS = require('../../src/bch-js')
|
|
10
|
-
const bchjs = new BCHJS()
|
|
7
|
+
import chai from 'chai'
|
|
8
|
+
import BCHJS from '../../src/bch-js.js'
|
|
11
9
|
|
|
12
10
|
// Inspect utility used for debugging.
|
|
13
|
-
|
|
11
|
+
import util from 'util'
|
|
12
|
+
const assert = chai.assert
|
|
13
|
+
const bchjs = new BCHJS()
|
|
14
14
|
util.inspect.defaultOptions = {
|
|
15
15
|
showHidden: true,
|
|
16
16
|
colors: true,
|
|
@@ -231,6 +231,40 @@ describe('#rawtransaction', () => {
|
|
|
231
231
|
that the server is responding on those endpoints, and responds consistently.
|
|
232
232
|
*/
|
|
233
233
|
describe('#sendRawTransaction', () => {
|
|
234
|
+
it('should send a single transaction hex', async () => {
|
|
235
|
+
try {
|
|
236
|
+
const hex =
|
|
237
|
+
'01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
|
|
238
|
+
|
|
239
|
+
await bchjs.RawTransactions.sendRawTransaction(hex)
|
|
240
|
+
// console.log(`result ${JSON.stringify(result, null, 2)}`)
|
|
241
|
+
|
|
242
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
243
|
+
} catch (err) {
|
|
244
|
+
// console.log(`err: ${util.inspect(err)}`)
|
|
245
|
+
|
|
246
|
+
assert.hasAllKeys(err, ['error'])
|
|
247
|
+
assert.include(err.error, 'Missing inputs')
|
|
248
|
+
}
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
it('should send an array of tx hexes', async () => {
|
|
252
|
+
try {
|
|
253
|
+
const hexes = [
|
|
254
|
+
'01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000',
|
|
255
|
+
'01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
|
|
256
|
+
]
|
|
257
|
+
|
|
258
|
+
const result = await bchjs.RawTransactions.sendRawTransaction(hexes)
|
|
259
|
+
console.log(`result ${JSON.stringify(result, null, 2)}`)
|
|
260
|
+
} catch (err) {
|
|
261
|
+
// console.log(`err: ${util.inspect(err)}`)
|
|
262
|
+
|
|
263
|
+
assert.hasAllKeys(err, ['error'])
|
|
264
|
+
assert.include(err.error, 'Missing inputs')
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
|
|
234
268
|
it('should throw error on array size rate limit', async () => {
|
|
235
269
|
try {
|
|
236
270
|
const dataMock =
|
package/test/integration/slp.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Integration tests for the bchjs covering SLP tokens.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const assert = chai.assert
|
|
5
|
+
import chai from 'chai'
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
let bchjs
|
|
7
|
+
import BCHJS from '../../src/bch-js.js'
|
|
10
8
|
|
|
11
9
|
// Inspect utility used for debugging.
|
|
12
|
-
|
|
10
|
+
import util from 'util'
|
|
11
|
+
const assert = chai.assert
|
|
12
|
+
let bchjs
|
|
13
13
|
util.inspect.defaultOptions = {
|
|
14
14
|
showHidden: true,
|
|
15
15
|
colors: true,
|
|
@@ -524,6 +524,148 @@ describe('#SLP', () => {
|
|
|
524
524
|
})
|
|
525
525
|
})
|
|
526
526
|
})
|
|
527
|
+
|
|
528
|
+
describe('#validateTxid3', () => {
|
|
529
|
+
it('should invalidate a known invalid TXID', async () => {
|
|
530
|
+
const txid =
|
|
531
|
+
'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a'
|
|
532
|
+
|
|
533
|
+
const result = await bchjs.SLP.Utils.validateTxid3(txid)
|
|
534
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
535
|
+
|
|
536
|
+
assert.isArray(result)
|
|
537
|
+
|
|
538
|
+
assert.property(result[0], 'txid')
|
|
539
|
+
assert.equal(result[0].txid, txid)
|
|
540
|
+
|
|
541
|
+
assert.property(result[0], 'valid')
|
|
542
|
+
assert.equal(result[0].valid, null)
|
|
543
|
+
})
|
|
544
|
+
|
|
545
|
+
it('should validate a known valid TXID', async () => {
|
|
546
|
+
const txid =
|
|
547
|
+
'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd'
|
|
548
|
+
|
|
549
|
+
const result = await bchjs.SLP.Utils.validateTxid3(txid)
|
|
550
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
551
|
+
|
|
552
|
+
assert.isArray(result)
|
|
553
|
+
|
|
554
|
+
assert.property(result[0], 'txid')
|
|
555
|
+
assert.equal(result[0].txid, txid)
|
|
556
|
+
|
|
557
|
+
assert.property(result[0], 'valid')
|
|
558
|
+
assert.equal(result[0].valid, true)
|
|
559
|
+
})
|
|
560
|
+
|
|
561
|
+
it('should handle a mix of valid, invalid, and non-SLP txs', async () => {
|
|
562
|
+
const txids = [
|
|
563
|
+
// Malformed SLP tx
|
|
564
|
+
'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
|
|
565
|
+
// Normal TX (non-SLP)
|
|
566
|
+
'01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
|
|
567
|
+
// Valid PSF SLP tx
|
|
568
|
+
'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
|
|
569
|
+
// Valid SLP token not in whitelist
|
|
570
|
+
'3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
|
|
571
|
+
// Unprocessed SLP TX
|
|
572
|
+
'402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019'
|
|
573
|
+
]
|
|
574
|
+
|
|
575
|
+
const result = await bchjs.SLP.Utils.validateTxid3(txids)
|
|
576
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
577
|
+
|
|
578
|
+
assert.isArray(result)
|
|
579
|
+
|
|
580
|
+
assert.equal(result[0].txid, txids[0])
|
|
581
|
+
assert.equal(result[0].valid, null)
|
|
582
|
+
|
|
583
|
+
assert.equal(result[1].txid, txids[1])
|
|
584
|
+
assert.equal(result[1].valid, null)
|
|
585
|
+
|
|
586
|
+
assert.equal(result[2].txid, txids[2])
|
|
587
|
+
assert.equal(result[2].valid, true)
|
|
588
|
+
|
|
589
|
+
// True in validateTxid() but null in validateTxid3()
|
|
590
|
+
assert.equal(result[3].txid, txids[3])
|
|
591
|
+
assert.equal(result[3].valid, null)
|
|
592
|
+
|
|
593
|
+
// Note: This should change from null to true once SLPDB finishes indexing.
|
|
594
|
+
assert.equal(result[4].txid, txids[4])
|
|
595
|
+
assert.equal(result[4].valid, null)
|
|
596
|
+
})
|
|
597
|
+
})
|
|
598
|
+
|
|
599
|
+
describe('#validateTxid', () => {
|
|
600
|
+
it('should handle a mix of valid, invalid, and non-SLP txs', async () => {
|
|
601
|
+
const txids = [
|
|
602
|
+
// Malformed SLP tx
|
|
603
|
+
'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
|
|
604
|
+
// Normal TX (non-SLP)
|
|
605
|
+
'01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0',
|
|
606
|
+
// Valid PSF SLP tx
|
|
607
|
+
'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd',
|
|
608
|
+
// Valid SLP token not in whitelist
|
|
609
|
+
'3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
|
|
610
|
+
// Token send on BCHN network.
|
|
611
|
+
'402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019',
|
|
612
|
+
// Token send on ABC network.
|
|
613
|
+
'336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d'
|
|
614
|
+
]
|
|
615
|
+
|
|
616
|
+
const result = await bchjs.SLP.Utils.validateTxid(txids)
|
|
617
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
618
|
+
|
|
619
|
+
assert.isArray(result)
|
|
620
|
+
|
|
621
|
+
assert.equal(result[0].txid, txids[0])
|
|
622
|
+
assert.equal(result[0].valid, null)
|
|
623
|
+
|
|
624
|
+
assert.equal(result[1].txid, txids[1])
|
|
625
|
+
assert.equal(result[1].valid, null)
|
|
626
|
+
|
|
627
|
+
assert.equal(result[2].txid, txids[2])
|
|
628
|
+
assert.equal(result[2].valid, true)
|
|
629
|
+
|
|
630
|
+
// True in validateTxid() but null in validateTxid3()
|
|
631
|
+
assert.equal(result[3].txid, txids[3])
|
|
632
|
+
assert.equal(result[3].valid, true)
|
|
633
|
+
|
|
634
|
+
assert.equal(result[4].txid, txids[4])
|
|
635
|
+
assert.equal(result[4].valid, true)
|
|
636
|
+
|
|
637
|
+
assert.equal(result[5].txid, txids[5])
|
|
638
|
+
assert.equal(result[5].valid, null)
|
|
639
|
+
})
|
|
640
|
+
})
|
|
641
|
+
|
|
642
|
+
describe('#nft1', () => {
|
|
643
|
+
describe('#listNFTGroupChildren', () => {
|
|
644
|
+
it('should return array of children GENESIS transactions IDs', async () => {
|
|
645
|
+
const groupId =
|
|
646
|
+
'68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a'
|
|
647
|
+
const result = await bchjs.SLP.NFT1.listNFTGroupChildren(groupId)
|
|
648
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
649
|
+
assert.property(result, 'nftChildren')
|
|
650
|
+
assert.isArray(result.nftChildren)
|
|
651
|
+
})
|
|
652
|
+
})
|
|
653
|
+
describe('#parentNFTGroup', () => {
|
|
654
|
+
it('should return parent NFT group information', async () => {
|
|
655
|
+
const tokenId =
|
|
656
|
+
'45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9'
|
|
657
|
+
const result = await bchjs.SLP.NFT1.parentNFTGroup(tokenId)
|
|
658
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
659
|
+
assert.property(result, 'nftGroup')
|
|
660
|
+
assert.property(result.nftGroup, 'id')
|
|
661
|
+
assert.property(result.nftGroup, 'name')
|
|
662
|
+
assert.property(result.nftGroup, 'symbol')
|
|
663
|
+
assert.property(result.nftGroup, 'documentUri')
|
|
664
|
+
assert.property(result.nftGroup, 'versionType')
|
|
665
|
+
assert.property(result.nftGroup, 'initialTokenQty')
|
|
666
|
+
})
|
|
667
|
+
})
|
|
668
|
+
})
|
|
527
669
|
}
|
|
528
670
|
})
|
|
529
671
|
})
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Integration tests for the transaction.js library.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import chai from 'chai'
|
|
6
|
+
import BCHJS from '../../src/bch-js.js'
|
|
7
|
+
const { assert } = chai
|
|
7
8
|
const bchjs = new BCHJS()
|
|
8
9
|
|
|
9
10
|
describe('#Transaction', () => {
|
|
@@ -11,6 +12,30 @@ describe('#Transaction', () => {
|
|
|
11
12
|
if (process.env.IS_USING_FREE_TIER) await bchjs.Util.sleep(1000)
|
|
12
13
|
})
|
|
13
14
|
|
|
15
|
+
describe('#get', () => {
|
|
16
|
+
it('should get a tx details for a non-SLP TX with an OP_RETURN', async () => {
|
|
17
|
+
const txid =
|
|
18
|
+
'01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b'
|
|
19
|
+
|
|
20
|
+
const result = await bchjs.Transaction.get(txid)
|
|
21
|
+
// console.log('result: ', result)
|
|
22
|
+
|
|
23
|
+
assert.property(result.txData, 'txid')
|
|
24
|
+
assert.property(result.txData, 'vin')
|
|
25
|
+
assert.property(result.txData, 'vout')
|
|
26
|
+
assert.equal(result.txData.isValidSlp, false)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should handle a coinbase transaction', async () => {
|
|
30
|
+
const txid = 'cca1d2dd3a533d2f501448dec03face2cb2814afd59a533a611e9a2909f2302b'
|
|
31
|
+
|
|
32
|
+
const details = await bchjs.Transaction.get(txid)
|
|
33
|
+
// console.log(`details: ${JSON.stringify(details, null, 2)}`)
|
|
34
|
+
|
|
35
|
+
assert.property(details.txData, 'txid')
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
14
39
|
if (process.env.TESTSLP) {
|
|
15
40
|
describe('#getOld', () => {
|
|
16
41
|
it('should get details about a non-SLP transaction', async () => {
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Integration tests for the utxo.js library.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import chai from 'chai'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import BCHJS from '../../src/bch-js.js'
|
|
8
|
+
const { assert } = chai
|
|
8
9
|
const bchjs = new BCHJS()
|
|
9
10
|
// const bchjs = new BCHJS({ restURL: 'http://192.168.2.129:3000/v5/' })
|
|
10
11
|
|
package/test/unit/address.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
// Public npm libraries.
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import assert from 'assert'
|
|
3
|
+
// import { assert } from 'chai'
|
|
4
|
+
import Bitcoin from '@psf/bitcoincashjs-lib'
|
|
4
5
|
|
|
5
6
|
// Mocks
|
|
6
|
-
|
|
7
|
+
import { createRequire } from 'module'
|
|
7
8
|
|
|
8
9
|
// Unit under test (uut)
|
|
9
|
-
|
|
10
|
+
import BCHJS from '../../src/bch-js.js'
|
|
11
|
+
const require = createRequire(import.meta.url)
|
|
12
|
+
const fixtures = require('./fixtures/address.json')
|
|
10
13
|
let bchjs
|
|
11
14
|
|
|
12
15
|
function flatten (arrays) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Public npm libraries
|
|
2
|
-
|
|
2
|
+
import assert from 'assert'
|
|
3
3
|
|
|
4
4
|
// Mocks
|
|
5
|
-
|
|
5
|
+
import { createRequire } from 'module'
|
|
6
6
|
|
|
7
7
|
// Unit under test (uut)
|
|
8
|
-
|
|
8
|
+
import BCHJS from '../../src/bch-js.js'
|
|
9
|
+
const require = createRequire(import.meta.url)
|
|
10
|
+
const fixtures = require('./fixtures/bitcoincash.json')
|
|
9
11
|
// const bchjs = new BCHJS()
|
|
10
12
|
let bchjs
|
|
11
13
|
|