diff --git a/package.json b/package.json index 9dc04b8..be4d6b7 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "test:integration:testnet:local": "RESTURL=http://localhost:4000/v3/ mocha --timeout 30000 test/integration/testnet", "test:integration:free": "bash test/integration/test-free-tier.sh", "test:integration:free:testnet": "bash test/integration/testnet/test-free-tier.sh", - "test:temp": "mocha --timeout 30000 test/integration/slp.js", + "test:temp": "mocha --timeout 30000 -g '#tokenUtxoDetails' test/integration/slp.js", "test:integration:api": "RESTURL=https://api.fullstack.cash/v3/ mocha --timeout 30000 test/integration", "coverage": "nyc report --reporter=text-lcov | coveralls", "coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/", diff --git a/src/slp/utils.js b/src/slp/utils.js index eaed2b9..fb5474d 100644 --- a/src/slp/utils.js +++ b/src/slp/utils.js @@ -748,6 +748,7 @@ class Utils { return tokenData } catch (error) { + // console.log('decodeOpReturn error: ', error) if (error.response && error.response.data) throw error.response.data throw error } @@ -870,12 +871,29 @@ class Utils { slpData = await this.decodeOpReturn(utxo.txid) // console.log(`slpData: ${JSON.stringify(slpData, null, 2)}`) } catch (err) { - // console.log(`error: `, err) + // console.log(`error from decodeOpReturn(${utxo.txid}): `, err) + // An error will be thrown if the txid is not SLP. - // Mark as false and continue the loop. - // outAry.push(false) - utxo.isValid = false - outAry.push(utxo) + // If error is for some other reason, like a 429 error, mark utxo as 'null' + // to display the unknown state. + if ( + !err.message || + err.message.indexOf("scriptpubkey not op_return") === -1 + ) { + // console.log(`error from decodeOpReturn(${utxo.txid}): `, err) + + utxo.isValid = null + outAry.push(utxo) + + // If error is thrown because there is no OP_RETURN, then it's not + // an SLP UTXO. + // Mark as false and continue the loop. + } else { + utxo.isValid = false + outAry.push(utxo) + } + + // Halt the execution of the loop and increase to the next index. continue } diff --git a/test/integration/slp.js b/test/integration/slp.js index fb691e6..5e81e8e 100644 --- a/test/integration/slp.js +++ b/test/integration/slp.js @@ -582,7 +582,7 @@ describe(`#SLP`, () => { // console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`) const result = await bchjs.SLP.Utils.hydrateUtxos(utxos.utxos) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) + console.log(`result: ${JSON.stringify(result, null, 2)}`) // Test the general structure of the output. assert.isArray(result.slpUtxos) diff --git a/test/unit/slp-utils.js b/test/unit/slp-utils.js index 58ffe91..ed1175e 100644 --- a/test/unit/slp-utils.js +++ b/test/unit/slp-utils.js @@ -1695,6 +1695,46 @@ describe("#SLP Utils", () => { assert2.equal(data[2].isValid, false) }) + + it("should return null value when 429 recieved", async () => { + const utxos = [ + { + height: 654522, + tx_hash: + "072a1e2c2d5f1309bf4eef7f88684e4ecd544a903b386b07f3e04b91b13d8af1", + tx_pos: 0, + value: 6999, + satoshis: 6999, + txid: + "072a1e2c2d5f1309bf4eef7f88684e4ecd544a903b386b07f3e04b91b13d8af1", + vout: 0 + }, + { + height: 654522, + tx_hash: + "a72db6a0883ecb8e379f317231b2571e41e041b7b1107e3e54c2e0b3386ac6ca", + tx_pos: 1, + value: 546, + satoshis: 546, + txid: + "a72db6a0883ecb8e379f317231b2571e41e041b7b1107e3e54c2e0b3386ac6ca", + vout: 1 + } + ] + + sandbox.stub(slp.Utils, "decodeOpReturn").rejects({ + error: + "Too many requests. Your limits are currently 3 requests per minute. Increase rate limits at https://fullstack.cash" + }) + + const data = await slp.Utils.tokenUtxoDetails(utxos) + // console.log(`data: ${JSON.stringify(data, null, 2)}`) + + // Values should be 'null' to signal that a determination could not be made + // due to a throttling issue. + assert.equal(data[0].isValid, null) + assert.equal(data[1].isValid, null) + }) }) describe("#txDetails", () => {