@psf/bch-js 4.20.28 → 5.1.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 +4 -4
- package/src/address.js +15 -0
- package/src/bch-js.js +5 -0
- package/src/ecash.js +47 -0
- package/src/psf-slp-indexer.js +332 -0
- package/src/slp/address.js +1 -1
- package/src/transaction.js +11 -2
- package/test/integration/blockchain.js +8 -0
- package/test/integration/chains/bchn/psf-slp-indexer.integration.js +105 -0
- package/test/integration/chains/bchn/slp.js +229 -225
- package/test/integration/slp.js +907 -901
- package/test/integration/transaction-integration.js +6 -5
- package/test/unit/ecash.js +56 -0
- package/test/unit/fixtures/psf-slp-indexer-mock.js +130 -0
- package/test/unit/psf-slp-indexer.js +264 -0
- package/test/unit/transaction-unit.js +19 -8
|
@@ -11,12 +11,12 @@ describe('#Transaction', () => {
|
|
|
11
11
|
if (process.env.IS_USING_FREE_TIER) await bchjs.Util.sleep(1000)
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
describe('#
|
|
14
|
+
describe('#getOld', () => {
|
|
15
15
|
it('should get details about a non-SLP transaction', async () => {
|
|
16
16
|
const txid =
|
|
17
17
|
'2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7'
|
|
18
18
|
|
|
19
|
-
const result = await bchjs.Transaction.
|
|
19
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
20
20
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
21
21
|
|
|
22
22
|
// Assert that there are stanardized properties.
|
|
@@ -37,7 +37,7 @@ describe('#Transaction', () => {
|
|
|
37
37
|
const txid =
|
|
38
38
|
'266844d53e46bbd7dd37134688dffea6e54d944edff27a0add63dd0908839bc1'
|
|
39
39
|
|
|
40
|
-
const result = await bchjs.Transaction.
|
|
40
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
41
41
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
42
42
|
|
|
43
43
|
// Assert that there are stanardized properties.
|
|
@@ -69,9 +69,10 @@ describe('#Transaction', () => {
|
|
|
69
69
|
// that is also a valid SLP tx, but is unrelated. Both TXs pass DAG validation,
|
|
70
70
|
// but for separate tokens.
|
|
71
71
|
it('should get problematic transaction', async () => {
|
|
72
|
-
const txid =
|
|
72
|
+
const txid =
|
|
73
|
+
'a19f2f395a8b0e15b6202944c56834367d128f1e3630486a4756de53424a46fe'
|
|
73
74
|
|
|
74
|
-
const result = await bchjs.Transaction.
|
|
75
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
75
76
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
76
77
|
|
|
77
78
|
// The token ID should equal the txid for this Vin.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Unit tests for eCash library.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Global npm libraries
|
|
6
|
+
const assert = require('chai').assert
|
|
7
|
+
const Ecash = require('../../src/ecash')
|
|
8
|
+
const uut = new Ecash()
|
|
9
|
+
|
|
10
|
+
describe('#eCash', () => {
|
|
11
|
+
describe('#toSatoshi', () => {
|
|
12
|
+
it('should convert XEC to satoshis', () => {
|
|
13
|
+
const xec = 10704.35
|
|
14
|
+
|
|
15
|
+
const result = uut.toSatoshi(xec)
|
|
16
|
+
|
|
17
|
+
assert.equal(result, 1070435)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('should throw an error if input is not a number', () => {
|
|
21
|
+
try {
|
|
22
|
+
uut.toSatoshi('test')
|
|
23
|
+
|
|
24
|
+
assert.fail('Unexpected code path')
|
|
25
|
+
} catch (err) {
|
|
26
|
+
assert.equal(
|
|
27
|
+
err.message,
|
|
28
|
+
'input must be a floating number representing XEC'
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('#toXec', () => {
|
|
35
|
+
it('should convert satoshis to XEC', () => {
|
|
36
|
+
const sats = 1070435
|
|
37
|
+
|
|
38
|
+
const result = uut.toXec(sats)
|
|
39
|
+
|
|
40
|
+
assert.equal(result, 10704.35)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('should throw an error if input is not a number', () => {
|
|
44
|
+
try {
|
|
45
|
+
uut.toXec('test')
|
|
46
|
+
|
|
47
|
+
assert.fail('Unexpected code path')
|
|
48
|
+
} catch (err) {
|
|
49
|
+
assert.equal(
|
|
50
|
+
err.message,
|
|
51
|
+
'input must be a floating number representing satoshis'
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
})
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Mocking data for unit tests for the PSF SLP INDEXER library.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
'use strict'
|
|
6
|
+
|
|
7
|
+
const tokenStats = {
|
|
8
|
+
tokenData: {
|
|
9
|
+
type: 1,
|
|
10
|
+
ticker: 'TP03',
|
|
11
|
+
name: 'Test Plugin 03',
|
|
12
|
+
tokenId: '13cad617d523c8eb4ab11fff19c010e0e0a4ea4360b58e0c8c955a45a146a669',
|
|
13
|
+
documentUri: 'fullstack.cash',
|
|
14
|
+
documentHash: '',
|
|
15
|
+
decimals: 0,
|
|
16
|
+
mintBatonIsActive: false,
|
|
17
|
+
tokensInCirculationBN: '1',
|
|
18
|
+
tokensInCirculationStr: '1',
|
|
19
|
+
blockCreated: 722420,
|
|
20
|
+
totalBurned: '0',
|
|
21
|
+
totalMinted: '1',
|
|
22
|
+
txs: [
|
|
23
|
+
{
|
|
24
|
+
txid: '13cad617d523c8eb4ab11fff19c010e0e0a4ea4360b58e0c8c955a45a146a669',
|
|
25
|
+
height: 722420,
|
|
26
|
+
type: 'GENESIS',
|
|
27
|
+
qty: '1'
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const txData = {
|
|
34
|
+
txData: {
|
|
35
|
+
txid: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
|
36
|
+
hash: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
|
37
|
+
version: 2,
|
|
38
|
+
size: 339,
|
|
39
|
+
locktime: 0,
|
|
40
|
+
vin: [
|
|
41
|
+
{
|
|
42
|
+
txid: '8370db30d94761ab9a11b71ecd22541151bf6125c8c613f0f6fab8ab794565a7',
|
|
43
|
+
vout: 0,
|
|
44
|
+
scriptSig: {
|
|
45
|
+
asm: '304402207e9631c53dfc8a9a793d1916469628c6b7c5780c01c2f676d51ef21b0ba4926f022069feb471ec869a49f8d108d0aaba04e7cd36e60a7500109d86537f55698930d4[ALL|FORKID] 02791b19a39165dbd83403d6df268d44fd621da30581b0b6e5cb15a7101ed58851',
|
|
46
|
+
hex: '47304402207e9631c53dfc8a9a793d1916469628c6b7c5780c01c2f676d51ef21b0ba4926f022069feb471ec869a49f8d108d0aaba04e7cd36e60a7500109d86537f55698930d4412102791b19a39165dbd83403d6df268d44fd621da30581b0b6e5cb15a7101ed58851'
|
|
47
|
+
},
|
|
48
|
+
sequence: 4294967295,
|
|
49
|
+
address: 'bitcoincash:qpvsg9vl9a5mlf37a7n3yce6pktdctn73qwgaqm3wq',
|
|
50
|
+
value: 0.00051303,
|
|
51
|
+
tokenQty: 0,
|
|
52
|
+
tokenQtyStr: '0',
|
|
53
|
+
tokenId: null
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
vout: [
|
|
57
|
+
{
|
|
58
|
+
value: 0,
|
|
59
|
+
n: 0,
|
|
60
|
+
scriptPubKey: {
|
|
61
|
+
asm: 'OP_RETURN 5262419 1 47454e45534953 54524f5554 54726f75742773207465737420746f6b656e 74726f757473626c6f672e636f6d 0 2 2 000000174876e800',
|
|
62
|
+
hex: '6a04534c500001010747454e455349530554524f55541254726f75742773207465737420746f6b656e0e74726f757473626c6f672e636f6d4c000102010208000000174876e800',
|
|
63
|
+
type: 'nulldata'
|
|
64
|
+
},
|
|
65
|
+
tokenQtyStr: '0',
|
|
66
|
+
tokenQty: 0
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
hex: '0200000001a7654579abb8faf6f013c6c82561bf51115422cd1eb7119aab6147d930db7083000000006a47304402207e9631c53dfc8a9a793d1916469628c6b7c5780c01c2f676d51ef21b0ba4926f022069feb471ec869a49f8d108d0aaba04e7cd36e60a7500109d86537f55698930d4412102791b19a39165dbd83403d6df268d44fd621da30581b0b6e5cb15a7101ed58851ffffffff040000000000000000476a04534c500001010747454e455349530554524f55541254726f75742773207465737420746f6b656e0e74726f757473626c6f672e636f6d4c000102010208000000174876e80022020000000000001976a914db4d39ceb7794ffe5d06855f249e1d3a7f1b024088ac22020000000000001976a914db4d39ceb7794ffe5d06855f249e1d3a7f1b024088accec20000000000001976a9145904159f2f69bfa63eefa712633a0d96dc2e7e8888ac00000000',
|
|
70
|
+
blockhash: '0000000000000000009f65225a3e12e23a7ea057c869047e0f36563a1f410267',
|
|
71
|
+
confirmations: 97398,
|
|
72
|
+
time: 1581773131,
|
|
73
|
+
blocktime: 1581773131,
|
|
74
|
+
blockheight: 622414,
|
|
75
|
+
isSlpTx: true,
|
|
76
|
+
tokenTxType: 'GENESIS',
|
|
77
|
+
tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
|
78
|
+
tokenType: 1,
|
|
79
|
+
tokenTicker: 'TROUT',
|
|
80
|
+
tokenName: "Trout's test token",
|
|
81
|
+
tokenDecimals: 2,
|
|
82
|
+
tokenUri: 'troutsblog.com',
|
|
83
|
+
tokenDocHash: '',
|
|
84
|
+
isValidSlp: true
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const balance = {
|
|
88
|
+
balance: {
|
|
89
|
+
utxos: [
|
|
90
|
+
{
|
|
91
|
+
txid: 'a24a6a4abf06fabd799ecea4f8fac6a9ff21e6a8dd6169a3c2ebc03665329db9',
|
|
92
|
+
vout: 1,
|
|
93
|
+
type: 'token',
|
|
94
|
+
qty: '1800',
|
|
95
|
+
tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
|
96
|
+
address: 'bitcoincash:qrqy3kj7r822ps6628vwqq5k8hyjl6ey3y4eea2m4s'
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
txs: [
|
|
100
|
+
{
|
|
101
|
+
txid: '078b2c48ed1db0d5d5996f2889b8d847a49200d0a781f6aa6752f740f312688f',
|
|
102
|
+
height: 717796
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
txid: 'a24a6a4abf06fabd799ecea4f8fac6a9ff21e6a8dd6169a3c2ebc03665329db9',
|
|
106
|
+
height: 717832
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
balances: [
|
|
110
|
+
{
|
|
111
|
+
tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
|
112
|
+
qty: '1800'
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const status = {
|
|
119
|
+
status: {
|
|
120
|
+
startBlockHeight: 543376,
|
|
121
|
+
syncedBlockHeight: 722860,
|
|
122
|
+
chainBlockHeight: 722679
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
module.exports = {
|
|
126
|
+
tokenStats,
|
|
127
|
+
txData,
|
|
128
|
+
balance,
|
|
129
|
+
status
|
|
130
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
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
|
+
it('should throw an error for improper input', async () => {
|
|
75
|
+
try {
|
|
76
|
+
const addr = 12345
|
|
77
|
+
|
|
78
|
+
await bchjs.PsfSlpIndexer.balance(addr)
|
|
79
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
80
|
+
} catch (err) {
|
|
81
|
+
// console.log(`err: `, err)
|
|
82
|
+
assert.include(err.message, 'Input address must be a string.')
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
it('should handle axios error', async () => {
|
|
86
|
+
try {
|
|
87
|
+
// Stub the network call.
|
|
88
|
+
sandbox.stub(axios, 'post').throws(new Error('test error'))
|
|
89
|
+
|
|
90
|
+
const addr = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
|
91
|
+
|
|
92
|
+
await bchjs.PsfSlpIndexer.balance(addr)
|
|
93
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
94
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
95
|
+
} catch (err) {
|
|
96
|
+
assert.include(err.message, 'test error')
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
it('should handle request error', async () => {
|
|
100
|
+
try {
|
|
101
|
+
// Stub the network call.
|
|
102
|
+
const testErr = new Error()
|
|
103
|
+
testErr.response = { data: { status: 422 } }
|
|
104
|
+
sandbox.stub(axios, 'post').throws(testErr)
|
|
105
|
+
|
|
106
|
+
const addr = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
|
107
|
+
|
|
108
|
+
await bchjs.PsfSlpIndexer.balance(addr)
|
|
109
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
110
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
111
|
+
} catch (err) {
|
|
112
|
+
assert.equal(err.status, 422)
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
describe('#tokenStats', () => {
|
|
118
|
+
it('should GET token stats', async () => {
|
|
119
|
+
// Stub the network call.
|
|
120
|
+
sandbox.stub(axios, 'post').resolves({ data: mockData.tokenStats })
|
|
121
|
+
|
|
122
|
+
const tokenId =
|
|
123
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
124
|
+
const result = await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
|
125
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
126
|
+
assert.property(result, 'tokenData')
|
|
127
|
+
assert.property(result.tokenData, 'type')
|
|
128
|
+
assert.property(result.tokenData, 'ticker')
|
|
129
|
+
assert.property(result.tokenData, 'name')
|
|
130
|
+
assert.property(result.tokenData, 'tokenId')
|
|
131
|
+
assert.property(result.tokenData, 'documentUri')
|
|
132
|
+
assert.property(result.tokenData, 'documentHash')
|
|
133
|
+
assert.property(result.tokenData, 'decimals')
|
|
134
|
+
assert.property(result.tokenData, 'mintBatonIsActive')
|
|
135
|
+
assert.property(result.tokenData, 'tokensInCirculationBN')
|
|
136
|
+
assert.property(result.tokenData, 'tokensInCirculationStr')
|
|
137
|
+
assert.property(result.tokenData, 'blockCreated')
|
|
138
|
+
assert.property(result.tokenData, 'totalBurned')
|
|
139
|
+
assert.property(result.tokenData, 'totalMinted')
|
|
140
|
+
assert.property(result.tokenData, 'txs')
|
|
141
|
+
})
|
|
142
|
+
it('should throw an error for improper input', async () => {
|
|
143
|
+
try {
|
|
144
|
+
const tokenId = 12345
|
|
145
|
+
|
|
146
|
+
await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
|
147
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
148
|
+
} catch (err) {
|
|
149
|
+
// console.log(`err: `, err)
|
|
150
|
+
assert.include(err.message, 'Input tokenId must be a string.')
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
it('should handle axios error', async () => {
|
|
154
|
+
try {
|
|
155
|
+
// Stub the network call.
|
|
156
|
+
sandbox.stub(axios, 'post').throws(new Error('test error'))
|
|
157
|
+
|
|
158
|
+
const tokenId =
|
|
159
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
160
|
+
await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
|
161
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
162
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
163
|
+
} catch (err) {
|
|
164
|
+
assert.include(err.message, 'test error')
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
it('should handle request error', async () => {
|
|
168
|
+
try {
|
|
169
|
+
// Stub the network call.
|
|
170
|
+
const testErr = new Error()
|
|
171
|
+
testErr.response = { data: { status: 422 } }
|
|
172
|
+
sandbox.stub(axios, 'post').throws(testErr)
|
|
173
|
+
|
|
174
|
+
const tokenId =
|
|
175
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
176
|
+
await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
|
177
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
178
|
+
} catch (err) {
|
|
179
|
+
assert.equal(err.status, 422)
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
describe('#tx', () => {
|
|
185
|
+
it('should GET transaction data', async () => {
|
|
186
|
+
// Stub the network call.
|
|
187
|
+
sandbox.stub(axios, 'post').resolves({ data: mockData.txData })
|
|
188
|
+
|
|
189
|
+
const txid =
|
|
190
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
191
|
+
const result = await bchjs.PsfSlpIndexer.tx(txid)
|
|
192
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
193
|
+
assert.property(result, 'txData')
|
|
194
|
+
assert.property(result.txData, 'txid')
|
|
195
|
+
assert.property(result.txData, 'hash')
|
|
196
|
+
assert.property(result.txData, 'version')
|
|
197
|
+
assert.property(result.txData, 'size')
|
|
198
|
+
assert.property(result.txData, 'locktime')
|
|
199
|
+
assert.property(result.txData, 'vin')
|
|
200
|
+
assert.property(result.txData, 'vout')
|
|
201
|
+
assert.property(result.txData, 'hex')
|
|
202
|
+
assert.property(result.txData, 'blockhash')
|
|
203
|
+
assert.property(result.txData, 'confirmations')
|
|
204
|
+
assert.property(result.txData, 'time')
|
|
205
|
+
assert.property(result.txData, 'blocktime')
|
|
206
|
+
assert.property(result.txData, 'blockheight')
|
|
207
|
+
assert.property(result.txData, 'isSlpTx')
|
|
208
|
+
assert.property(result.txData, 'tokenTxType')
|
|
209
|
+
assert.property(result.txData, 'tokenId')
|
|
210
|
+
assert.property(result.txData, 'tokenType')
|
|
211
|
+
assert.property(result.txData, 'tokenTicker')
|
|
212
|
+
assert.property(result.txData, 'tokenName')
|
|
213
|
+
assert.property(result.txData, 'tokenDecimals')
|
|
214
|
+
assert.property(result.txData, 'tokenUri')
|
|
215
|
+
assert.property(result.txData, 'tokenDocHash')
|
|
216
|
+
assert.property(result.txData, 'isValidSlp')
|
|
217
|
+
})
|
|
218
|
+
it('should throw an error for improper input', async () => {
|
|
219
|
+
try {
|
|
220
|
+
const txid = 12345
|
|
221
|
+
|
|
222
|
+
await bchjs.PsfSlpIndexer.tx(txid)
|
|
223
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
224
|
+
} catch (err) {
|
|
225
|
+
// console.log(`err: `, err)
|
|
226
|
+
assert.include(err.message, 'Input txid must be a string.')
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
it('should handle axios error', async () => {
|
|
230
|
+
try {
|
|
231
|
+
// Stub the network call.
|
|
232
|
+
sandbox.stub(axios, 'post').throws(new Error('test error'))
|
|
233
|
+
|
|
234
|
+
const txid =
|
|
235
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
236
|
+
await bchjs.PsfSlpIndexer.tx(txid)
|
|
237
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
238
|
+
assert.equal(true, false, 'Unexpected result!')
|
|
239
|
+
} catch (err) {
|
|
240
|
+
assert.include(err.message, 'test error')
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it('should get tx from full node if not available from slp indexer', async () => {
|
|
245
|
+
// Stub the call to the SLP indexer.
|
|
246
|
+
const testErr = {
|
|
247
|
+
response: { data: { error: 'Key not found in database' } }
|
|
248
|
+
}
|
|
249
|
+
sandbox.stub(axios, 'post').rejects(testErr)
|
|
250
|
+
|
|
251
|
+
// Stub the call to the full node
|
|
252
|
+
sandbox
|
|
253
|
+
.stub(bchjs.PsfSlpIndexer.rawTransaction, 'getTxData')
|
|
254
|
+
.resolves({ txid: 'fakeTxid' })
|
|
255
|
+
|
|
256
|
+
const txid =
|
|
257
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
258
|
+
const result = await bchjs.PsfSlpIndexer.tx(txid)
|
|
259
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
260
|
+
|
|
261
|
+
assert.equal(result.txData.txid, 'fakeTxid')
|
|
262
|
+
})
|
|
263
|
+
})
|
|
264
|
+
})
|
|
@@ -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
|
})
|