From b9873f7ed89c2d9744763b70f612f8e7dd24c9a9 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sun, 13 Dec 2020 08:56:09 -0800 Subject: [PATCH] Added additional corner case unit test for tokenUtxoDetails() --- test/unit/slp-utils.js | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/unit/slp-utils.js b/test/unit/slp-utils.js index c562fd7..16b09a2 100644 --- a/test/unit/slp-utils.js +++ b/test/unit/slp-utils.js @@ -1771,6 +1771,64 @@ describe("#SLP Utils", () => { // The UTXO should have been validated by the third validation source. assert.equal(data[0].isValid, true) }) + + it("should handle SLPDB returning null corner case", async () => { + // Mock the call to REST API + // Stub the calls to decodeOpReturn. + sandbox + .stub(uut.Utils, "decodeOpReturn") + .onCall(0) + .resolves({ + tokenType: 1, + txType: "SEND", + tokenId: + "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", + amounts: ["200000000", "99887500000000"] + }) + .onCall(1) + .resolves({ + tokenType: 1, + txType: "GENESIS", + ticker: "TOK-CH", + name: "TokyoCash", + tokenId: + "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", + documentUri: "", + documentHash: "", + decimals: 8, + mintBatonVout: 0, + qty: "2100000000000000" + }) + + // Force default SLPDB to return 'null' corner case. + sandbox.stub(uut.Utils, "validateTxid").resolves([null]) + + // Mock the response from slp-api + sandbox.stub(uut.Utils, "validateTxid2").resolves({ + txid: + "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + isValid: true, + msg: "" + }) + + const utxos = [ + { + txid: + "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + vout: 1, + amount: 0.00000546, + satoshis: 546, + height: 596089, + confirmations: 748 + } + ] + + const data = await uut.Utils.tokenUtxoDetails(utxos) + // console.log(`data: ${JSON.stringify(data, null, 2)}`) + + // The UTXO should have been validated by the third validation source. + assert.equal(data[0].isValid, true) + }) }) describe("#txDetails", () => {