mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 01:02:05 -07:00
Updated tokenstats endpoint
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
These integration tests need to be run against a live SLPDB. They query
|
||||
against a live SLPDB and test the results against known token stats.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const assert = require('chai').assert
|
||||
// const axios = require('axios')
|
||||
|
||||
// Used for debugging.
|
||||
const util = require('util')
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
// Exit if SLPDB URL is not defined.
|
||||
if (!process.env.SLPDB_URL) {
|
||||
throw new Error('SLPDB_URL and SLPDB_PASS must be defined in order to run these tests.')
|
||||
}
|
||||
|
||||
const SLP = require('../../../src/routes/v3/slp')
|
||||
const slp = new SLP()
|
||||
|
||||
const { mockReq, mockRes } = require('../mocks/express-mocks')
|
||||
|
||||
describe('#slp', () => {
|
||||
let req, res
|
||||
|
||||
beforeEach(() => {
|
||||
// Mock the req and res objects used by Express routes.
|
||||
req = mockReq
|
||||
res = mockRes
|
||||
})
|
||||
|
||||
describe('#tokenStats', () => {
|
||||
it('should get token stats for token with no mint baton', async () => {
|
||||
req.params.tokenId =
|
||||
'497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7'
|
||||
// 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
|
||||
const result = await slp.tokenStats(req, res)
|
||||
console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
// Assert that expected properties exist.
|
||||
assert.property(result, 'decimals')
|
||||
assert.property(result, 'timestamp')
|
||||
assert.property(result, 'versionType')
|
||||
assert.property(result, 'documentUri')
|
||||
assert.property(result, 'symbol')
|
||||
assert.property(result, 'name')
|
||||
assert.property(result, 'containsBaton')
|
||||
assert.property(result, 'id')
|
||||
assert.property(result, 'documentHash')
|
||||
assert.property(result, 'initialTokenQty')
|
||||
assert.property(result, 'blockCreated')
|
||||
assert.property(result, 'blockLastActiveSend')
|
||||
assert.property(result, 'blockLastActiveMint')
|
||||
assert.property(result, 'txnsSinceGenesis')
|
||||
assert.property(result, 'validAddresses')
|
||||
assert.property(result, 'mintingBatonStatus')
|
||||
assert.property(result, 'timestampUnix')
|
||||
assert.property(result, 'totalMinted')
|
||||
assert.property(result, 'totalBurned')
|
||||
assert.property(result, 'circulatingSupply')
|
||||
|
||||
// baton was never created.
|
||||
assert.equal(result.containsBaton, false)
|
||||
})
|
||||
|
||||
it('should get token stats for token with a mint baton', async () => {
|
||||
req.params.tokenId =
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
|
||||
const result = await slp.tokenStats(req, res)
|
||||
console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
// Assert that expected properties exist.
|
||||
assert.property(result, 'decimals')
|
||||
assert.property(result, 'timestamp')
|
||||
assert.property(result, 'versionType')
|
||||
assert.property(result, 'documentUri')
|
||||
assert.property(result, 'symbol')
|
||||
assert.property(result, 'name')
|
||||
assert.property(result, 'containsBaton')
|
||||
assert.property(result, 'id')
|
||||
assert.property(result, 'documentHash')
|
||||
assert.property(result, 'initialTokenQty')
|
||||
assert.property(result, 'blockCreated')
|
||||
assert.property(result, 'blockLastActiveSend')
|
||||
assert.property(result, 'blockLastActiveMint')
|
||||
assert.property(result, 'txnsSinceGenesis')
|
||||
assert.property(result, 'validAddresses')
|
||||
assert.property(result, 'mintingBatonStatus')
|
||||
assert.property(result, 'timestampUnix')
|
||||
assert.property(result, 'totalMinted')
|
||||
assert.property(result, 'totalBurned')
|
||||
assert.property(result, 'circulatingSupply')
|
||||
|
||||
// baton was created.
|
||||
assert.equal(result.containsBaton, true)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
These integration tests need to be run against a live SLPDB. They query
|
||||
against a live SLPDB and test the results against known token stats.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
// const chai = require('chai')
|
||||
// const assert = chai.assert
|
||||
// const axios = require('axios')
|
||||
|
||||
// Used for debugging.
|
||||
const util = require('util')
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
// Exit if SLPDB URL is not defined.
|
||||
if (!process.env.SLPDB_URL) {
|
||||
throw new Error('SLPDB_URL and SLPDB_PASS must be defined in order to run these tests.')
|
||||
}
|
||||
|
||||
const SLPDB = require('../../../src/routes/v3/services/slpdb')
|
||||
const slpdb = new SLPDB()
|
||||
|
||||
describe('#slpdb', () => {
|
||||
describe('#getTotalCirculating', () => {
|
||||
it('should get circulating supply', async () => {
|
||||
const result = await slpdb.getTotalCirculating('b10677aef051b73e6b170c1c0824da33a3e0680ab5a01cd8d76aa77840fccfb4')
|
||||
console.log('result: ', result)
|
||||
})
|
||||
})
|
||||
})
|
||||
+5
-51
@@ -463,11 +463,9 @@ describe('#SLP', () => {
|
||||
})
|
||||
|
||||
describe('tokenStats()', () => {
|
||||
const tokenStats = slpRoute.tokenStats
|
||||
|
||||
it('should throw 400 if tokenID is empty', async () => {
|
||||
req.params.tokenId = ''
|
||||
const result = await tokenStats(req, res)
|
||||
const result = await slpRoute.tokenStats(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.hasAllKeys(result, ['error'])
|
||||
@@ -476,12 +474,12 @@ describe('#SLP', () => {
|
||||
|
||||
it('returns proper error when downstream service stalls', async () => {
|
||||
// Mock the timeout error.
|
||||
sandbox.stub(slpRoute.axios, 'request').throws({ code: 'ECONNABORTED' })
|
||||
sandbox.stub(slpRoute.slpdb, 'getTokenStats').throws({ code: 'ECONNABORTED' })
|
||||
|
||||
req.params.tokenId =
|
||||
'497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7'
|
||||
|
||||
const result = await tokenStats(req, res)
|
||||
const result = await slpRoute.tokenStats(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.isAbove(res.statusCode, 499, 'HTTP status code 503 expected.')
|
||||
@@ -494,12 +492,12 @@ describe('#SLP', () => {
|
||||
|
||||
it('returns proper error when downstream service is down', async () => {
|
||||
// Mock the timeout error.
|
||||
sandbox.stub(slpRoute.axios, 'request').throws({ code: 'ECONNREFUSED' })
|
||||
sandbox.stub(slpRoute.slpdb, 'getTokenStats').throws({ code: 'ECONNREFUSED' })
|
||||
|
||||
req.params.tokenId =
|
||||
'497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7'
|
||||
|
||||
const result = await tokenStats(req, res)
|
||||
const result = await slpRoute.tokenStats(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.isAbove(res.statusCode, 499, 'HTTP status code 503 expected.')
|
||||
@@ -509,50 +507,6 @@ describe('#SLP', () => {
|
||||
'Error message expected'
|
||||
)
|
||||
})
|
||||
|
||||
it('should get token stats for tokenId', async () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === 'unit') {
|
||||
sandbox.stub(slpRoute.axios, 'request').resolves({
|
||||
data: {
|
||||
t: [
|
||||
{
|
||||
tokenDetails: mockData.mockTokenDetails,
|
||||
tokenStats: mockData.mockTokenStats
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
req.params.tokenId =
|
||||
'497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7'
|
||||
|
||||
const result = await tokenStats(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.hasAnyKeys(result, [
|
||||
'blockCreated',
|
||||
'blockLastActiveMint',
|
||||
'blockLastActiveSend',
|
||||
'containsBaton',
|
||||
'initialTokenQty',
|
||||
'mintingBatonStatus',
|
||||
'circulatingSupply',
|
||||
'decimals',
|
||||
'documentHash',
|
||||
'versionType',
|
||||
'timestamp',
|
||||
'documentUri',
|
||||
'name',
|
||||
'symbol',
|
||||
'id',
|
||||
'totalBurned',
|
||||
'totalMinted',
|
||||
'txnsSinceGenesis',
|
||||
'validAddresses'
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('balancesForTokenSingle()', () => {
|
||||
|
||||
Reference in New Issue
Block a user