mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
feat(getTokenData): PS002 mutable data retrieval
This commit is contained in:
@@ -498,6 +498,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
assert.property(status, 'chainBlockHeight')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#errorHandler', () => {
|
||||
it('should handle unexpected errors', () => {
|
||||
sandbox.stub(uut.routeUtils, 'decodeError').returns({ msg: false })
|
||||
@@ -507,6 +508,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
assert.equal(res.statusCode, 400, 'HTTP status code 400 expected.')
|
||||
assert.property(result, 'error')
|
||||
})
|
||||
|
||||
it('should handle unknow errors', () => {
|
||||
sandbox.stub(uut.routeUtils, 'decodeError').returns({ msg: false })
|
||||
|
||||
@@ -516,6 +518,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
assert.property(result, 'error')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#checkEnvVar', () => {
|
||||
it('should throw errors if SLP_INDEXER_API env var is not provided', () => {
|
||||
const savedSlpIndexerUrl = process.env.SLP_INDEXER_API
|
||||
@@ -533,6 +536,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
process.env.SLP_INDEXER_API = savedSlpIndexerUrl
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getCIDData', () => {
|
||||
it('should throw errors if cid is not provided', async () => {
|
||||
try {
|
||||
@@ -546,6 +550,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('should handle axios error', async () => {
|
||||
try {
|
||||
sandbox.stub(uut.axios, 'get').throws(new Error('test error'))
|
||||
@@ -560,6 +565,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('should return cid object data', async () => {
|
||||
sandbox.stub(uut.axios, 'get').resolves({ data: mockData.immutableData })
|
||||
const cid = 'bafybeigp3bfmj6woms7pywb7s7r6npcdudvsabvzne2chyspxtdendrwmy'
|
||||
@@ -581,6 +587,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('should handle bchjs error', async () => {
|
||||
try {
|
||||
sandbox.stub(uut.bchjs.Electrumx, 'txData').throws(new Error('test error'))
|
||||
@@ -595,12 +602,14 @@ describe('#PsfSlpIndexer', () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('should return data', async () => {
|
||||
sandbox.stub(uut.bchjs.Electrumx, 'txData').resolves({ details: mockData.txData.txData })
|
||||
const txid = 'c37ba29f40ecc61662ea56324fdb72a5f1e66add2078854c2144765b9030358a'
|
||||
const result = await uut.decodeOpReturn(txid)
|
||||
assert.isString(result)
|
||||
})
|
||||
|
||||
it('should return false if data is not found', async () => {
|
||||
sandbox.stub(uut.bchjs.Electrumx, 'txData').resolves({ details: { vout: [] } })
|
||||
const txid = 'c37ba29f40ecc61662ea56324fdb72a5f1e66add2078854c2144765b9030358a'
|
||||
@@ -608,6 +617,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
assert.isFalse(result)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getTokenData', async () => {
|
||||
it('should throw 400 error if tokenId is missing', async () => {
|
||||
const result = await uut.getTokenData(req, res)
|
||||
@@ -715,6 +725,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
assert.property(genesisData, 'totalMinted')
|
||||
assert.property(genesisData, 'txs')
|
||||
})
|
||||
|
||||
it('should GET tokens data if immutableData data not found', async function () {
|
||||
req.body.tokenId =
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
@@ -752,6 +763,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
assert.property(genesisData, 'totalMinted')
|
||||
assert.property(genesisData, 'txs')
|
||||
})
|
||||
|
||||
it('should GET tokens data if mutable data not found', async function () {
|
||||
req.body.tokenId =
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
@@ -790,6 +802,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
assert.property(genesisData, 'txs')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getMutableData', () => {
|
||||
it('should throw errors if documentHash is not provided', async () => {
|
||||
try {
|
||||
@@ -803,6 +816,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw errors if cid is not provided in OP Return', async () => {
|
||||
try {
|
||||
sandbox.stub(uut, 'decodeOpReturn').resolves('{}')
|
||||
@@ -838,6 +852,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('should handle bchjs error', async () => {
|
||||
try {
|
||||
sandbox.stub(uut, 'decodeOpReturn').resolves(mockData.decodedOpReturn)
|
||||
@@ -854,6 +869,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('should skip mutable data if was not generated by the MDA private key', async () => {
|
||||
try {
|
||||
sandbox.stub(uut, 'decodeOpReturn').resolves(mockData.decodedOpReturn)
|
||||
@@ -873,6 +889,7 @@ describe('#PsfSlpIndexer', () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('should return mutable data', async () => {
|
||||
sandbox.stub(uut, 'decodeOpReturn')
|
||||
.onFirstCall().resolves(mockData.decodedOpReturn)
|
||||
|
||||
Reference in New Issue
Block a user