Merge pull request #40 from Permissionless-Software-Foundation/ct-unstable

fix(hydrateUtxos): Adding support for a corner case
This commit is contained in:
Chris Troutner
2020-10-06 13:23:02 -07:00
committed by GitHub
3 changed files with 37 additions and 1 deletions
+1 -1
View File
@@ -17,7 +17,7 @@
"test": "npm run lint && npm run test-v3", "test": "npm run lint && npm run test-v3",
"lint": "standard --env mocha --fix", "lint": "standard --env mocha --fix",
"test-v3": "export NETWORK=mainnet && nyc --reporter=text mocha --timeout 60000 test/v3/", "test-v3": "export NETWORK=mainnet && nyc --reporter=text mocha --timeout 60000 test/v3/",
"test:temp": "export NETWORK=mainnet && mocha --timeout 25000 test/v3/util.js", "test:temp": "export NETWORK=mainnet && mocha --timeout 25000 test/v3/slp.js",
"test:integration": "mocha test/v3/integration", "test:integration": "mocha test/v3/integration",
"test:integration:slpdb": "mocha --timeout 25000 test/v3/integration/slp*.js", "test:integration:slpdb": "mocha --timeout 25000 test/v3/integration/slp*.js",
"coverage": "nyc report --reporter=text-lcov | coveralls", "coverage": "nyc report --reporter=text-lcov | coveralls",
+8
View File
@@ -1570,6 +1570,13 @@ class Slp {
}) })
} }
if (!utxos[0].utxos) {
res.status(422)
return res.json({
error: 'Each element in array should have a utxos property'
})
}
// Loop through each address and query the UTXOs for that element. // Loop through each address and query the UTXOs for that element.
for (let i = 0; i < utxos.length; i++) { for (let i = 0; i < utxos.length; i++) {
const theseUtxos = utxos[i].utxos const theseUtxos = utxos[i].utxos
@@ -1586,6 +1593,7 @@ class Slp {
return res.json({ slpUtxos: utxos }) return res.json({ slpUtxos: utxos })
} catch (err) { } catch (err) {
wlogger.error('Error in slp.js/hydrateUtxos().', err) wlogger.error('Error in slp.js/hydrateUtxos().', err)
console.error('Error in slp.js/hydrateUtxos().', err)
// Decode the error message. // Decode the error message.
const { msg, status } = routeUtils.decodeError(err) const { msg, status } = routeUtils.decodeError(err)
+28
View File
@@ -1034,6 +1034,34 @@ describe('#SLP', () => {
assert.property(result.slpUtxos[0].utxos[1], 'tokenType') assert.property(result.slpUtxos[0].utxos[1], 'tokenType')
assert.property(result.slpUtxos[0].utxos[1], 'tokenQty') assert.property(result.slpUtxos[0].utxos[1], 'tokenQty')
}) })
it('should throw error for missing properties', async () => {
const utxos = [
{
height: 639443,
tx_hash:
'30707fffb9b295a06a68d217f49c198e9e1dbe1edc3874a0928ca1905f1709df',
tx_pos: 0,
value: 6000
},
{
height: 639443,
tx_hash:
'8962566e413501224d178a02effc89be5ac0d8e4195f617415d443dc4c38fe50',
tx_pos: 1,
value: 546
}
]
req.body.utxos = utxos
const result = await slpRoute.hydrateUtxos(req, res)
assert.hasAllKeys(result, ['error'])
assert.include(
result.error,
'Each element in array should have a utxos property'
)
})
}) })
}) })