mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-21 16:51:59 -07:00
fix(PsfSlpIndexer.tx): Renaming txId() to tx()
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Integration tests for the psf-slp-indexer.js library
|
||||
*/
|
||||
|
||||
const assert = require('chai').assert
|
||||
|
||||
const BCHJS = require('../../../../src/bch-js')
|
||||
let bchjs
|
||||
|
||||
describe('#psf-slp-indexer', () => {
|
||||
beforeEach(async () => {
|
||||
// Introduce a delay so that the BVT doesn't trip the rate limits.
|
||||
if (process.env.IS_USING_FREE_TIER) await sleep(3000)
|
||||
|
||||
bchjs = new BCHJS()
|
||||
})
|
||||
|
||||
describe('#status', () => {
|
||||
it('should return the status of the indexer.', async () => {
|
||||
const result = await bchjs.PsfSlpIndexer.status()
|
||||
// console.log('result: ', result)
|
||||
|
||||
assert.property(result.status, 'startBlockHeight')
|
||||
assert.property(result.status, 'syncedBlockHeight')
|
||||
assert.property(result.status, 'chainBlockHeight')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#balance', () => {
|
||||
it('should get balance data for an address.', async () => {
|
||||
const addr = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
||||
|
||||
const result = await bchjs.PsfSlpIndexer.balance(addr)
|
||||
// console.log('result: ', result)
|
||||
|
||||
assert.property(result.balance, 'utxos')
|
||||
assert.property(result.balance, 'txs')
|
||||
assert.property(result.balance, 'balances')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#tokenStats', () => {
|
||||
it('should get stats on a token', async () => {
|
||||
const tokenId =
|
||||
'38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0'
|
||||
|
||||
const result = await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
||||
console.log('result: ', result)
|
||||
|
||||
assert.property(result.tokenData, 'documentUri')
|
||||
assert.property(result.tokenData, 'txs')
|
||||
assert.property(result.tokenData, 'totalBurned')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// Promise-based sleep function
|
||||
function sleep (ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
@@ -35,10 +35,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
assert.include(
|
||||
err.message,
|
||||
'test error'
|
||||
)
|
||||
assert.include(err.message, 'test error')
|
||||
}
|
||||
})
|
||||
it('should handle request error', async () => {
|
||||
@@ -81,10 +78,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
// console.log(`err: `, err)
|
||||
assert.include(
|
||||
err.message,
|
||||
'Input address must be a string.'
|
||||
)
|
||||
assert.include(err.message, 'Input address must be a string.')
|
||||
}
|
||||
})
|
||||
it('should handle axios error', async () => {
|
||||
@@ -98,10 +92,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
assert.include(
|
||||
err.message,
|
||||
'test error'
|
||||
)
|
||||
assert.include(err.message, 'test error')
|
||||
}
|
||||
})
|
||||
it('should handle request error', async () => {
|
||||
@@ -127,7 +118,8 @@ describe('#PsfSlpIndexer', () => {
|
||||
// Stub the network call.
|
||||
sandbox.stub(axios, 'post').resolves({ data: mockData.tokenStats })
|
||||
|
||||
const tokenId = 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
const tokenId =
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
const result = await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
assert.property(result, 'tokenData')
|
||||
@@ -154,10 +146,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
// console.log(`err: `, err)
|
||||
assert.include(
|
||||
err.message,
|
||||
'Input tokenId must be a string.'
|
||||
)
|
||||
assert.include(err.message, 'Input tokenId must be a string.')
|
||||
}
|
||||
})
|
||||
it('should handle axios error', async () => {
|
||||
@@ -165,15 +154,13 @@ describe('#PsfSlpIndexer', () => {
|
||||
// Stub the network call.
|
||||
sandbox.stub(axios, 'post').throws(new Error('test error'))
|
||||
|
||||
const tokenId = 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
const tokenId =
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
assert.include(
|
||||
err.message,
|
||||
'test error'
|
||||
)
|
||||
assert.include(err.message, 'test error')
|
||||
}
|
||||
})
|
||||
it('should handle request error', async () => {
|
||||
@@ -183,7 +170,8 @@ describe('#PsfSlpIndexer', () => {
|
||||
testErr.response = { data: { status: 422 } }
|
||||
sandbox.stub(axios, 'post').throws(testErr)
|
||||
|
||||
const tokenId = 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
const tokenId =
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
await bchjs.PsfSlpIndexer.tokenStats(tokenId)
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
@@ -192,13 +180,14 @@ describe('#PsfSlpIndexer', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#txId', () => {
|
||||
describe('#tx', () => {
|
||||
it('should GET transaction data', async () => {
|
||||
// Stub the network call.
|
||||
sandbox.stub(axios, 'post').resolves({ data: mockData.txData })
|
||||
|
||||
const txid = 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
const result = await bchjs.PsfSlpIndexer.txId(txid)
|
||||
const txid =
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
const result = await bchjs.PsfSlpIndexer.tx(txid)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
assert.property(result, 'txData')
|
||||
assert.property(result.txData, 'txid')
|
||||
@@ -229,14 +218,11 @@ describe('#PsfSlpIndexer', () => {
|
||||
try {
|
||||
const txid = 12345
|
||||
|
||||
await bchjs.PsfSlpIndexer.txId(txid)
|
||||
await bchjs.PsfSlpIndexer.tx(txid)
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
// console.log(`err: `, err)
|
||||
assert.include(
|
||||
err.message,
|
||||
'Input txid must be a string.'
|
||||
)
|
||||
assert.include(err.message, 'Input txid must be a string.')
|
||||
}
|
||||
})
|
||||
it('should handle axios error', async () => {
|
||||
@@ -244,15 +230,13 @@ describe('#PsfSlpIndexer', () => {
|
||||
// Stub the network call.
|
||||
sandbox.stub(axios, 'post').throws(new Error('test error'))
|
||||
|
||||
const txid = 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
await bchjs.PsfSlpIndexer.txId(txid)
|
||||
const txid =
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
await bchjs.PsfSlpIndexer.tx(txid)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
assert.include(
|
||||
err.message,
|
||||
'test error'
|
||||
)
|
||||
assert.include(err.message, 'test error')
|
||||
}
|
||||
})
|
||||
it('should handle request error', async () => {
|
||||
@@ -262,8 +246,9 @@ describe('#PsfSlpIndexer', () => {
|
||||
testErr.response = { data: { status: 422 } }
|
||||
sandbox.stub(axios, 'post').throws(testErr)
|
||||
|
||||
const txid = 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
await bchjs.PsfSlpIndexer.txId(txid)
|
||||
const txid =
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
await bchjs.PsfSlpIndexer.tx(txid)
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
assert.equal(err.status, 422)
|
||||
|
||||
Reference in New Issue
Block a user