mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
Got integration tests in BCH passing
This commit is contained in:
@@ -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')
|
||||
})
|
||||
|
||||
+73
-56
@@ -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)}`)
|
||||
|
||||
Reference in New Issue
Block a user