mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
Fixing integration tests
This commit is contained in:
@@ -45,23 +45,25 @@ class PsfSlpIndexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} /psf/slp/status/ Indexer Status.
|
* @api {get} /psf/slp/status/ Indexer Status.
|
||||||
* @apiName SLP indexer status.
|
* @apiName SLP indexer status.
|
||||||
* @apiGroup PSF SLP
|
* @apiGroup PSF SLP
|
||||||
* @apiDescription Return SLP indexer status
|
* @apiDescription Return SLP indexer status
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @apiExample Example usage:
|
||||||
* curl -H "Content-Type: application/json" -X GET localhost:3000/v5/psf/slp/status
|
* curl -H "Content-Type: application/json" -X GET localhost:3000/v5/psf/slp/status
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
async getStatus (req, res, next) {
|
async getStatus (req, res, next) {
|
||||||
try {
|
try {
|
||||||
// Verify env var is set for interacting with the indexer.
|
// Verify env var is set for interacting with the indexer.
|
||||||
_this.checkEnvVar()
|
_this.checkEnvVar()
|
||||||
|
|
||||||
const response = await _this.axios.get(`${_this.psfSlpIndexerApi}slp/status/`)
|
const response = await _this.axios.get(
|
||||||
|
`${_this.psfSlpIndexerApi}slp/status/`
|
||||||
|
)
|
||||||
|
|
||||||
res.status(200)
|
res.status(200)
|
||||||
return res.json(response.data)
|
return res.json(response.data)
|
||||||
@@ -71,17 +73,17 @@ class PsfSlpIndexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} /psf/slp/address/ SLP balance for address.
|
* @api {post} /psf/slp/address/ SLP balance for address.
|
||||||
* @apiName SLP balance for address.
|
* @apiName SLP balance for address.
|
||||||
* @apiGroup PSF SLP
|
* @apiGroup PSF SLP
|
||||||
* @apiDescription Return SLP balance for address
|
* @apiDescription Return SLP balance for address
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @apiExample Example usage:
|
* @apiExample Example usage:
|
||||||
* curl -H "Content-Type: application/json" -X POST -d '{ "address": "bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n" }' localhost:3000/v5/psf/slp/address
|
* curl -H "Content-Type: application/json" -X POST -d '{ "address": "bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n" }' localhost:3000/v5/psf/slp/address
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
async getAddress (req, res, next) {
|
async getAddress (req, res, next) {
|
||||||
try {
|
try {
|
||||||
// Verify env var is set for interacting with the indexer.
|
// Verify env var is set for interacting with the indexer.
|
||||||
|
|||||||
@@ -73,4 +73,7 @@ export LOG_MAX_FILES=5d
|
|||||||
# (Optional) if using a bcash node, set this variable. Otherwise leave it as-is.
|
# (Optional) if using a bcash node, set this variable. Otherwise leave it as-is.
|
||||||
export BCASH_SERVER=http://localhost
|
export BCASH_SERVER=http://localhost
|
||||||
|
|
||||||
|
# PSF SLP indexer
|
||||||
|
export SLP_INDEXER_API=https://psf-slp-indexer.fullstack.cash/
|
||||||
|
|
||||||
npm start
|
npm start
|
||||||
|
|||||||
+36
-30
@@ -86,16 +86,16 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||||
|
|
||||||
// Save the existing RPC URL.
|
// Save the existing RPC URL.
|
||||||
const savedUrl2 = process.env.RPC_BASEURL
|
const savedUrl2 = process.env.SLP_INDEXER_API
|
||||||
|
|
||||||
// Manipulate the URL to cause a 500 network error.
|
// Manipulate the URL to cause a 500 network error.
|
||||||
process.env.RPC_BASEURL = 'http://fakeurl/api/'
|
process.env.SLP_INDEXER_API = 'http://fakeurl/api/'
|
||||||
|
|
||||||
await uut.getTokenStats(req, res)
|
await uut.getTokenStats(req, res)
|
||||||
// console.log(`result: ${util.inspect(result)}`)
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
|
|
||||||
// Restore the saved URL.
|
// Restore the saved URL.
|
||||||
process.env.RPC_BASEURL = savedUrl2
|
process.env.SLP_INDEXER_API = savedUrl2
|
||||||
|
|
||||||
assert.isAbove(
|
assert.isAbove(
|
||||||
res.statusCode,
|
res.statusCode,
|
||||||
@@ -104,6 +104,7 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
)
|
)
|
||||||
// assert.include(result.error,"Network error: Could not communicate with full node","Error message expected")
|
// assert.include(result.error,"Network error: Could not communicate with full node","Error message expected")
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns proper error when downstream service stalls', async () => {
|
it('returns proper error when downstream service stalls', async () => {
|
||||||
req.body.tokenId =
|
req.body.tokenId =
|
||||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||||
@@ -145,9 +146,7 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
sandbox
|
sandbox.stub(uut.axios, 'post').resolves({ data: mockData.tokenStats })
|
||||||
.stub(uut.axios, 'post')
|
|
||||||
.resolves({ data: mockData.tokenStats })
|
|
||||||
} else {
|
} else {
|
||||||
return this.skip()
|
return this.skip()
|
||||||
}
|
}
|
||||||
@@ -190,21 +189,22 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
assert.isFalse(result.success)
|
assert.isFalse(result.success)
|
||||||
assert.include(result.error, 'This is not a txid')
|
assert.include(result.error, 'This is not a txid')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw 503 when network issues', async () => {
|
it('should throw 503 when network issues', async () => {
|
||||||
req.body.txid =
|
req.body.txid =
|
||||||
'f3e14cd871402a766e85045dc552f2c1e87857dd3ea1b15efab6334ccef5e315'
|
'f3e14cd871402a766e85045dc552f2c1e87857dd3ea1b15efab6334ccef5e315'
|
||||||
|
|
||||||
// Save the existing RPC URL.
|
// Save the existing RPC URL.
|
||||||
const savedUrl2 = process.env.RPC_BASEURL
|
const savedUrl2 = process.env.SLP_INDEXER_API
|
||||||
|
|
||||||
// Manipulate the URL to cause a 500 network error.
|
// Manipulate the URL to cause a 500 network error.
|
||||||
process.env.RPC_BASEURL = 'http://fakeurl/api/'
|
process.env.SLP_INDEXER_API = 'http://fakeurl/api/'
|
||||||
|
|
||||||
await uut.getTxid(req, res)
|
await uut.getTxid(req, res)
|
||||||
// console.log(`result: ${util.inspect(result)}`)
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
|
|
||||||
// Restore the saved URL.
|
// Restore the saved URL.
|
||||||
process.env.RPC_BASEURL = savedUrl2
|
process.env.SLP_INDEXER_API = savedUrl2
|
||||||
|
|
||||||
assert.isAbove(
|
assert.isAbove(
|
||||||
res.statusCode,
|
res.statusCode,
|
||||||
@@ -254,9 +254,7 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
'f3e14cd871402a766e85045dc552f2c1e87857dd3ea1b15efab6334ccef5e315'
|
'f3e14cd871402a766e85045dc552f2c1e87857dd3ea1b15efab6334ccef5e315'
|
||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
sandbox
|
sandbox.stub(uut.axios, 'post').resolves({ data: mockData.txData })
|
||||||
.stub(uut.axios, 'post')
|
|
||||||
.resolves({ data: mockData.txData })
|
|
||||||
} else {
|
} else {
|
||||||
return this.skip()
|
return this.skip()
|
||||||
}
|
}
|
||||||
@@ -306,7 +304,10 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
|
|
||||||
assert.hasAllKeys(result, ['error', 'success'])
|
assert.hasAllKeys(result, ['error', 'success'])
|
||||||
assert.isFalse(result.success)
|
assert.isFalse(result.success)
|
||||||
assert.include(result.error, 'Invalid BCH address. Double check your address is valid')
|
assert.include(
|
||||||
|
result.error,
|
||||||
|
'Invalid BCH address. Double check your address is valid'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
it('should throw 400 error for invalid network address', async () => {
|
it('should throw 400 error for invalid network address', async () => {
|
||||||
req.body.address = 'bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4'
|
req.body.address = 'bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4'
|
||||||
@@ -316,23 +317,27 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
|
|
||||||
assert.hasAllKeys(result, ['error', 'success'])
|
assert.hasAllKeys(result, ['error', 'success'])
|
||||||
assert.isFalse(result.success)
|
assert.isFalse(result.success)
|
||||||
assert.include(result.error, 'Invalid network. Trying to use a testnet address on mainnet, or vice versa.')
|
assert.include(
|
||||||
|
result.error,
|
||||||
|
'Invalid network. Trying to use a testnet address on mainnet, or vice versa.'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw 503 when network issues', async () => {
|
it('should throw 503 when network issues', async () => {
|
||||||
req.body.address = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
req.body.address =
|
||||||
|
'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
||||||
|
|
||||||
// Save the existing RPC URL.
|
// Save the existing RPC URL.
|
||||||
const savedUrl2 = process.env.RPC_BASEURL
|
const savedUrl2 = process.env.SLP_INDEXER_API
|
||||||
|
|
||||||
// Manipulate the URL to cause a 500 network error.
|
// Manipulate the URL to cause a 500 network error.
|
||||||
process.env.RPC_BASEURL = 'http://fakeurl/api/'
|
process.env.SLP_INDEXER_API = 'http://fakeurl/api/'
|
||||||
|
|
||||||
await uut.getAddress(req, res)
|
await uut.getAddress(req, res)
|
||||||
// console.log(`result: ${util.inspect(result)}`)
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
|
|
||||||
// Restore the saved URL.
|
// Restore the saved URL.
|
||||||
process.env.RPC_BASEURL = savedUrl2
|
process.env.SLP_INDEXER_API = savedUrl2
|
||||||
assert.isAbove(
|
assert.isAbove(
|
||||||
res.statusCode,
|
res.statusCode,
|
||||||
499,
|
499,
|
||||||
@@ -340,8 +345,10 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
)
|
)
|
||||||
// assert.include(result.error,"Network error: Could not communicate with full node","Error message expected")
|
// assert.include(result.error,"Network error: Could not communicate with full node","Error message expected")
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns proper error when downstream service stalls', async () => {
|
it('returns proper error when downstream service stalls', async () => {
|
||||||
req.body.address = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
req.body.address =
|
||||||
|
'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
||||||
|
|
||||||
// Mock the timeout error.
|
// Mock the timeout error.
|
||||||
sandbox.stub(uut.axios, 'post').throws({ code: 'ECONNABORTED' })
|
sandbox.stub(uut.axios, 'post').throws({ code: 'ECONNABORTED' })
|
||||||
@@ -358,7 +365,8 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns proper error when downstream service is down', async () => {
|
it('returns proper error when downstream service is down', async () => {
|
||||||
req.body.address = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
req.body.address =
|
||||||
|
'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
||||||
|
|
||||||
// Mock the timeout error.
|
// Mock the timeout error.
|
||||||
sandbox.stub(uut.axios, 'post').throws({ code: 'ECONNREFUSED' })
|
sandbox.stub(uut.axios, 'post').throws({ code: 'ECONNREFUSED' })
|
||||||
@@ -375,13 +383,12 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should GET address data', async function () {
|
it('should GET address data', async function () {
|
||||||
req.body.address = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
req.body.address =
|
||||||
|
'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
|
||||||
|
|
||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
sandbox
|
sandbox.stub(uut.axios, 'post').resolves({ data: mockData.balance })
|
||||||
.stub(uut.axios, 'post')
|
|
||||||
.resolves({ data: mockData.balance })
|
|
||||||
} else {
|
} else {
|
||||||
return this.skip()
|
return this.skip()
|
||||||
}
|
}
|
||||||
@@ -400,16 +407,16 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
describe('#getStatus', async () => {
|
describe('#getStatus', async () => {
|
||||||
it('should throw 503 when network issues', async () => {
|
it('should throw 503 when network issues', async () => {
|
||||||
// Save the existing RPC URL.
|
// Save the existing RPC URL.
|
||||||
const savedUrl2 = process.env.RPC_BASEURL
|
const savedUrl2 = process.env.SLP_INDEXER_API
|
||||||
|
|
||||||
// Manipulate the URL to cause a 500 network error.
|
// Manipulate the URL to cause a 500 network error.
|
||||||
process.env.RPC_BASEURL = 'http://fakeurl/api/'
|
process.env.SLP_INDEXER_API = 'http://fakeurl/api/'
|
||||||
|
|
||||||
await uut.getStatus(req, res)
|
await uut.getStatus(req, res)
|
||||||
// console.log(`result: ${util.inspect(result)}`)
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
|
|
||||||
// Restore the saved URL.
|
// Restore the saved URL.
|
||||||
process.env.RPC_BASEURL = savedUrl2
|
process.env.SLP_INDEXER_API = savedUrl2
|
||||||
assert.isAbove(
|
assert.isAbove(
|
||||||
res.statusCode,
|
res.statusCode,
|
||||||
499,
|
499,
|
||||||
@@ -417,6 +424,7 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
)
|
)
|
||||||
// assert.include(result.error,"Network error: Could not communicate with full node","Error message expected")
|
// assert.include(result.error,"Network error: Could not communicate with full node","Error message expected")
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns proper error when downstream service stalls', async () => {
|
it('returns proper error when downstream service stalls', async () => {
|
||||||
// Mock the timeout error.
|
// Mock the timeout error.
|
||||||
sandbox.stub(uut.axios, 'get').throws({ code: 'ECONNABORTED' })
|
sandbox.stub(uut.axios, 'get').throws({ code: 'ECONNABORTED' })
|
||||||
@@ -450,9 +458,7 @@ describe('#PsfSlpIndexer', () => {
|
|||||||
it('should GET indexer status', async function () {
|
it('should GET indexer status', async function () {
|
||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
sandbox
|
sandbox.stub(uut.axios, 'get').resolves({ data: mockData.status })
|
||||||
.stub(uut.axios, 'get')
|
|
||||||
.resolves({ data: mockData.status })
|
|
||||||
} else {
|
} else {
|
||||||
return this.skip()
|
return this.skip()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user