From 10452bb47eaa006ede67359395082b7007c19c5b Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 20 Mar 2020 20:28:50 -0700 Subject: [PATCH] fix(SLP list): Removing list endpoint, no scaleable --- src/routes/v3/slp.js | 60 +--------------------------------------- test/v3/slp.js | 66 ++++---------------------------------------- 2 files changed, 7 insertions(+), 119 deletions(-) diff --git a/src/routes/v3/slp.js b/src/routes/v3/slp.js index e1c4e70..46f7e6c 100644 --- a/src/routes/v3/slp.js +++ b/src/routes/v3/slp.js @@ -54,7 +54,7 @@ class Slp { _this.router = router _this.router.get('/', _this.root) - _this.router.get('/list', _this.list) + // _this.router.get('/list', _this.list) _this.router.get('/list/:tokenId', _this.listSingleToken) _this.router.post('/list', _this.listBulkToken) _this.router.get('/balancesForAddress/:address', _this.balancesForAddress) @@ -122,64 +122,6 @@ class Slp { return res.json({ status: 'slp' }) } - /** - * @api {get} /slp/list List all SLP tokens. - * @apiName List all SLP tokens. - * @apiGroup SLP - * @apiDescription Returns list all SLP tokens. - * - * - * @apiExample Example usage: - * curl -X GET "https://mainnet.bchjs.cash/v3/slp/list" -H "accept:application/json" - * - * - */ - async list (req, res, next) { - try { - const query = { - v: 3, - q: { - db: ['t'], - find: { - $query: {} - }, - project: { tokenDetails: 1, tokenStats: 1, _id: 0 }, - sort: { 'tokenStats.block_created': -1 }, - limit: 10000 - } - } - - const s = JSON.stringify(query) - const b64 = Buffer.from(s).toString('base64') - const url = `${process.env.SLPDB_URL}q/${b64}` - - // Request options - const opt = { - method: 'get', - baseURL: url - } - // Get data from SLPDB. - const tokenRes = await _this.axios.request(opt) - - const formattedTokens = [] - - if (tokenRes.data.t.length) { - tokenRes.data.t.forEach(token => { - token = _this.formatTokenOutput(token) - formattedTokens.push(token.tokenDetails) - }) - } - - res.status(200) - return res.json(formattedTokens) - } catch (err) { - wlogger.error('Error in slp.ts/list().', err) - return _this.errorHandler(err, res) - - // return res.json({ error: `Error in /list: ${err.message}` }) - } - } - /** * @api {get} /slp/list/{tokenId} List single SLP token by id. * @apiName List single SLP token by id. diff --git a/test/v3/slp.js b/test/v3/slp.js index deb125e..4109954 100644 --- a/test/v3/slp.js +++ b/test/v3/slp.js @@ -220,8 +220,7 @@ describe('#SLP', () => { }) describe('balancesForAddressBulk()', () => { - const balancesForAddressBulk = - slpRoute.balancesForAddressBulk + const balancesForAddressBulk = slpRoute.balancesForAddressBulk it('should throw 400 if addresses is empty', async () => { const result = await balancesForAddressBulk(req, res) @@ -555,8 +554,7 @@ describe('#SLP', () => { }) describe('balancesForTokenSingle()', () => { - const balancesForTokenSingle = - slpRoute.balancesForTokenSingle + const balancesForTokenSingle = slpRoute.balancesForTokenSingle it('should throw 400 if tokenID is empty', async () => { req.params.tokenId = '' @@ -664,7 +662,7 @@ describe('#SLP', () => { sandbox.stub(slpRoute.axios, 'request').throws({ code: 'ECONNABORTED' }) req.params.txid = - '57b3082a2bf269b3d6f40fee7fb9c664e8256a88ca5ee2697c05b94578223333' + '57b3082a2bf269b3d6f40fee7fb9c664e8256a88ca5ee2697c05b94578223333' const result = await txDetails(req, res) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -681,7 +679,7 @@ describe('#SLP', () => { sandbox.stub(slpRoute.axios, 'request').throws({ code: 'ECONNREFUSED' }) req.params.txid = - '57b3082a2bf269b3d6f40fee7fb9c664e8256a88ca5ee2697c05b94578223333' + '57b3082a2bf269b3d6f40fee7fb9c664e8256a88ca5ee2697c05b94578223333' const result = await txDetails(req, res) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -716,8 +714,7 @@ describe('#SLP', () => { }) describe('txsTokenIdAddressSingle()', () => { - const txsTokenIdAddressSingle = - slpRoute.txsTokenIdAddressSingle + const txsTokenIdAddressSingle = slpRoute.txsTokenIdAddressSingle it('should throw 400 if tokenId is empty', async () => { req.params.tokenId = '' @@ -738,6 +735,7 @@ describe('#SLP', () => { assert.hasAllKeys(result, ['error']) assert.include(result.error, 'address can not be empty') }) + it('returns proper error when downstream service stalls', async () => { // Mock the timeout error. sandbox.stub(slpRoute.axios, 'request').throws({ code: 'ECONNABORTED' }) @@ -778,58 +776,6 @@ describe('#SLP', () => { }) /* - describe("list()", () => { - // list route handler - const list = slpRoute.testableComponents.list - - it("should throw 500 when network issues", async () => { - // Save the existing SLPDB_URL. - const savedUrl2 = process.env.SLPDB_URL - - // Manipulate the URL to cause a 500 network error. - process.env.SLPDB_URL = "http://fakeurl/api/" - - const result = await list(req, res) - // console.log(`result: ${util.inspect(result)}`) - - // Restore the saved URL. - process.env.SLPDB_URL = savedUrl2 - - assert.isAbove( - res.statusCode, - 499, - "HTTP status code 500 or greater expected." - ) - //assert.include(result.error,"Network error: Could not communicate with full node","Error message expected") - }) - - it("should GET list", async () => { - // Mock the RPC call for unit tests. - if (process.env.TEST === "unit") { - const b64 = `eyJ2IjozLCJxIjp7ImRiIjpbInQiXSwiZmluZCI6eyIkcXVlcnkiOnt9fSwicHJvamVjdCI6eyJ0b2tlbkRldGFpbHMiOjEsInRva2VuU3RhdHMiOjEsIl9pZCI6MH0sImxpbWl0IjoxMDB9fQ==` - - nock(process.env.SLPDB_URL) - .get(uri => uri.includes("/")) - .reply(200, mockData.mockList) - } - - const result = await list(req, res) - // console.log(`test result: ${util.inspect(result)}`) - - assert.isArray(result) - assert.hasAnyKeys(result[0], [ - "id", - "timestamp", - "symbol", - "name", - "documentUri", - "documentHash", - "decimals", - "initialTokenQty" - ]) - }) - }) - describe("listSingleToken()", () => { const listSingleToken = slpRoute.testableComponents.listSingleToken