From fd51f82dbcc875dc93b356b258f14f577b2f6641 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sun, 9 May 2021 16:42:41 -0700 Subject: [PATCH] Got integration tests in BCH passing --- package.json | 4 +- test/v4/integration/nft.js | 28 ++++++-- test/v4/slp.js | 129 +++++++++++++++++++++---------------- 3 files changed, 97 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index 28846ef..144a27b 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "coverage": "nyc report --reporter=text-lcov | coveralls", "coverage:report": "export NETWORK=mainnet && nyc --reporter=html mocha --timeout 25000 test/v4/", "docs": "./node_modules/.bin/apidoc -i src/routes/v4 -o docs", - "test:temp1": "export NETWORK=mainnet && export TEST=integration && mocha --exit --timeout 25000 -g '#hydrateUtxos-' test/v4/integration/", - "test:temp2": "mocha -g '#rate-routelimit' --timeout 30000 test/v4/" + "test:temp1": "export NETWORK=mainnet && export TEST=integration && mocha --exit --timeout 25000 -g '#getNftChildren' test/v4/integration/", + "test:temp2": "mocha -g '#getNftGroup' --exit --timeout 30000 test/v4/" }, "engines": { "node": ">=10.15.1" diff --git a/test/v4/integration/nft.js b/test/v4/integration/nft.js index b8cfad5..f26e686 100644 --- a/test/v4/integration/nft.js +++ b/test/v4/integration/nft.js @@ -15,7 +15,9 @@ 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.') + throw new Error( + 'SLPDB_URL and SLPDB_PASS must be defined in order to run these tests.' + ) } const SLP = require('../../../src/routes/v4/slp') @@ -34,18 +36,29 @@ describe('#nft', () => { describe('#getNftChildren', () => { it('should get NFT children list', async () => { - req.params.tokenId = '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a' + req.params.tokenId = + '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a' + const result = await slp.getNftChildren(req, res) // console.log(`result: ${util.inspect(result)}`) + assert.isArray(result.nftChildren) assert.equal(result.nftChildren.length, 2) - assert.equal(result.nftChildren[0], '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9') - assert.equal(result.nftChildren[1], '928ce61fe1006b1325a0ba0dce700bf83986a6f0691ba26e121c9ac035d12a55') + assert.equal( + result.nftChildren[0], + '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9' + ) + assert.equal( + result.nftChildren[1], + '928ce61fe1006b1325a0ba0dce700bf83986a6f0691ba26e121c9ac035d12a55' + ) }) }) + describe('#getNftGroup', () => { it('should get NFT group token info', async () => { - req.params.tokenId = '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9' + req.params.tokenId = + '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9' // req.params.tokenId = '928ce61fe1006b1325a0ba0dce700bf83986a6f0691ba26e121c9ac035d12a55' const result = await slp.getNftGroup(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -53,7 +66,10 @@ describe('#nft', () => { assert.property(result.nftGroup, 'id') assert.property(result.nftGroup, 'versionType') assert.property(result.nftGroup, 'symbol') - assert.equal(result.nftGroup.id, '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a') + assert.equal( + result.nftGroup.id, + '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a' + ) assert.equal(result.nftGroup.versionType, 129) assert.equal(result.nftGroup.symbol, 'PSF.TEST.GROUP') }) diff --git a/test/v4/slp.js b/test/v4/slp.js index c4e1de7..9f4d403 100644 --- a/test/v4/slp.js +++ b/test/v4/slp.js @@ -1761,7 +1761,7 @@ describe('#SLP', () => { }) }) - describe('getNftChildren()', () => { + describe('#getNftChildren', () => { it('should throw 400 if tokenID is empty', async () => { req.params.tokenId = '' const result = await slpRoute.getNftChildren(req, res) @@ -1770,6 +1770,7 @@ describe('#SLP', () => { assert.hasAllKeys(result, ['error']) assert.include(result.error, 'tokenId 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' }) @@ -1786,6 +1787,7 @@ describe('#SLP', () => { 'Error message expected' ) }) + it('returns proper error when downstream service is down', async () => { // Mock the timeout error. sandbox.stub(slpRoute.axios, 'request').throws({ code: 'ECONNREFUSED' }) @@ -1803,33 +1805,34 @@ describe('#SLP', () => { 'Error message expected' ) }) + it('should return error on non-existing NFT group token', async () => { if (process.env.TEST === 'unit') { - sandbox.stub(slpRoute, 'lookupToken').resolves( - { id: 'not found' } - ) + sandbox.stub(slpRoute, 'lookupToken').resolves({ id: 'not found' }) } req.params.tokenId = - '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a' + '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0b' const result = await slpRoute.getNftChildren(req, res) // console.log(`result: ${JSON.stringify(result, null, 2)}`) + assert.include( result.error, 'NFT group does not exists', 'Error message expected' ) }) + it('should return error on non-group NFT token', async () => { if (process.env.TEST === 'unit') { - sandbox.stub(slpRoute, 'lookupToken').resolves( - mockData.mockNftChildren[0] - ) + sandbox + .stub(slpRoute, 'lookupToken') + .resolves(mockData.mockNftChildren[0]) } req.params.tokenId = - '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a' + '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0b' const result = await slpRoute.getNftChildren(req, res) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -1839,32 +1842,30 @@ describe('#SLP', () => { 'Error message expected' ) }) - it('should return error on invalid NFT group data', async () => { - if (process.env.TEST === 'unit') { - sandbox.stub(slpRoute, 'lookupToken').resolves( - mockData.mockNftGroup - ) + + if (process.env.TEST === 'unit') { + it('should return error on invalid NFT group data', async () => { + sandbox.stub(slpRoute, 'lookupToken').resolves(mockData.mockNftGroup) sandbox.stub(slpRoute.axios, 'request').resolves({ data: { u: 'invalid' } }) - } - req.params.tokenId = - '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a' + req.params.tokenId = + '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a' + + const result = await slpRoute.getNftChildren(req, res) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) + assert.include( + result.error, + 'No children data in the group', + 'Error message expected' + ) + }) + } - const result = await slpRoute.getNftChildren(req, res) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.include( - result.error, - 'No children data in the group', - 'Error message expected' - ) - }) it('should get NFT children IDs in given NFT group', async () => { if (process.env.TEST === 'unit') { - sandbox.stub(slpRoute, 'lookupToken').resolves( - mockData.mockNftGroup - ) + sandbox.stub(slpRoute, 'lookupToken').resolves(mockData.mockNftGroup) sandbox.stub(slpRoute.axios, 'request').resolves({ data: { t: [ @@ -1888,12 +1889,18 @@ describe('#SLP', () => { // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result.nftChildren) assert.equal(result.nftChildren.length, 2) - assert.equal(result.nftChildren[0], '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9') - assert.equal(result.nftChildren[1], '928ce61fe1006b1325a0ba0dce700bf83986a6f0691ba26e121c9ac035d12a55') + assert.equal( + result.nftChildren[0], + '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9' + ) + assert.equal( + result.nftChildren[1], + '928ce61fe1006b1325a0ba0dce700bf83986a6f0691ba26e121c9ac035d12a55' + ) }) }) - describe('getNftGroup()', () => { + describe('#getNftGroup', () => { it('should throw 400 if tokenID is empty', async () => { req.params.tokenId = '' const result = await slpRoute.getNftGroup(req, res) @@ -1902,6 +1909,7 @@ describe('#SLP', () => { assert.hasAllKeys(result, ['error']) assert.include(result.error, 'tokenId 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' }) @@ -1918,6 +1926,7 @@ describe('#SLP', () => { 'Error message expected' ) }) + it('returns proper error when downstream service is down', async () => { // Mock the timeout error. sandbox.stub(slpRoute.axios, 'request').throws({ code: 'ECONNREFUSED' }) @@ -1935,15 +1944,14 @@ describe('#SLP', () => { 'Error message expected' ) }) + it('should return error on non-existing NFT child token', async () => { if (process.env.TEST === 'unit') { - sandbox.stub(slpRoute, 'lookupToken').resolves( - { id: 'not found' } - ) + sandbox.stub(slpRoute, 'lookupToken').resolves({ id: 'not found' }) } req.params.tokenId = - '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9' + '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a8' const result = await slpRoute.getNftGroup(req, res) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -1953,15 +1961,14 @@ describe('#SLP', () => { 'Error message expected' ) }) + it('should return error on invalid NFT child token', async () => { if (process.env.TEST === 'unit') { - sandbox.stub(slpRoute, 'lookupToken').resolves( - mockData.mockNftGroup - ) + sandbox.stub(slpRoute, 'lookupToken').resolves(mockData.mockNftGroup) } req.params.tokenId = - '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9' + '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a8' const result = await slpRoute.getNftGroup(req, res) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -1971,33 +1978,43 @@ describe('#SLP', () => { 'Error message expected' ) }) - it('should return error on invalid parent', async () => { - req.params.tokenId = - '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9' - if (process.env.TEST === 'unit') { + if (process.env.TEST === 'unit') { + it('should return error on invalid parent', async () => { + req.params.tokenId = + '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9' + const callback = sandbox.stub(slpRoute, 'lookupToken') - callback.withArgs(req.params.tokenId).resolves(mockData.mockNftChildren[0]) + callback + .withArgs(req.params.tokenId) + .resolves(mockData.mockNftChildren[0]) // parent is non-valid NFT group (type != 129) - callback.withArgs(mockData.mockNftGroup.id).resolves(mockData.mockNftChildren[0]) - } + callback + .withArgs(mockData.mockNftGroup.id) + .resolves(mockData.mockNftChildren[0]) + + const result = await slpRoute.getNftGroup(req, res) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) + assert.include( + result.error, + 'NFT group does not exists', + 'Error message expected' + ) + }) + } - const result = await slpRoute.getNftGroup(req, res) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.include( - result.error, - 'NFT group does not exists', - 'Error message expected' - ) - }) it('should get NFT group information for tokenId', async () => { req.params.tokenId = '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9' if (process.env.TEST === 'unit') { const callback = sandbox.stub(slpRoute, 'lookupToken') - callback.withArgs(req.params.tokenId).resolves(mockData.mockNftChildren[0]) - callback.withArgs(mockData.mockNftGroup.id).resolves(mockData.mockNftGroup) + callback + .withArgs(req.params.tokenId) + .resolves(mockData.mockNftChildren[0]) + callback + .withArgs(mockData.mockNftGroup.id) + .resolves(mockData.mockNftGroup) } const result = await slpRoute.getNftGroup(req, res) // console.log(`result: ${JSON.stringify(result, null, 2)}`)