From f5de593f8972f8d9477cba656eb2a91d91a2ebd4 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sat, 5 Dec 2020 20:42:07 -0800 Subject: [PATCH] fix(tests): Getting all tests passing --- package.json | 5 +- src/slp/utils.js | 35 +------------ test/integration/bchn/slp.js | 75 ++++++++++++++++++++++++---- test/integration/slp.js | 4 +- test/unit/fixtures/slp/mock-utils.js | 2 +- test/unit/slp-utils.js | 4 +- 6 files changed, 75 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index 901597d..e5df110 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,9 @@ "test:integration:local": "RESTURL=http://localhost:3000/v4/ mocha --timeout 30000 test/integration", "test:integration:local:bchn": "RESTURL=http://localhost:3000/v4/ bash test/integration/test-bchn-integration.sh", "test:integration:local:testnet": "RESTURL=http://localhost:4000/v4/ mocha --timeout 30000 test/integration/testnet", - "test:temp": "RESTURL=http://bchn.fullstack.cash/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/bchn/", - "test:temp2": "RESTURL=http://abc.fullstack.cash/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/", + "test:temp": "RESTURL=https://bchn.fullstack.cash/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/bchn/", + "test:temp2": "RESTURL=https://abc.fullstack.cash/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/", + "test:temp3": "ISBCHN=true RESTURL=http://localhost:3000/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/bchn/", "test:integration:api": "RESTURL=https://api.fullstack.cash/v4/ 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 4c3bc4d..694c27d 100644 --- a/src/slp/utils.js +++ b/src/slp/utils.js @@ -444,28 +444,10 @@ class Utils { }, _this.axiosOptions ) - console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) + // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) const validatedTxids = response.data - // CT 12/5/2020: Leaving this here for future reference. 'null' is a special - // value returned by SLPDB. It indicates that SLPDB is not aware of the TXID. - // It might mean that SLPDB has fallen behind. - // 'null' is distict from 'false'. 'false' firmly indicates that the TXID is - // not valid. 'null' indicates a lack of knowledge. - // Handle any null values - for (let i = 0; i < validatedTxids.length; i++) { - if (validatedTxids[i] === null) { - console.log(`i: ${i}`) - console.log(`validatedTxids: ${validatedTxids}`) - console.log(`txids: ${txids}`) - validatedTxids[i] = { - txid: txids[i], - valid: null - } - } - } - return validatedTxids } catch (error) { if (error.response && error.response.data) throw error.response.data @@ -669,21 +651,6 @@ class Utils { const validatedTxids = response.data - // CT 12/5/2020: Leaving this here for future reference. 'null' is a special - // value returned by SLPDB. It indicates that SLPDB is not aware of the TXID. - // It might mean that SLPDB has fallen behind. - // 'null' is distict from 'false'. 'false' firmly indicates that the TXID is - // not valid. 'null' indicates a lack of knowledge. - // Handle any null values - for (let i = 0; i < validatedTxids.length; i++) { - if (validatedTxids[i] === null) { - validatedTxids[i] = { - txid: txids[i], - valid: null - } - } - } - return validatedTxids } catch (error) { if (error.response && error.response.data) throw error.response.data diff --git a/test/integration/bchn/slp.js b/test/integration/bchn/slp.js index 57c3e42..e191eb6 100644 --- a/test/integration/bchn/slp.js +++ b/test/integration/bchn/slp.js @@ -681,7 +681,7 @@ describe(`#SLP`, () => { "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" const result = await bchjs.SLP.Utils.validateTxid3(txid) - console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) @@ -689,7 +689,7 @@ describe(`#SLP`, () => { assert.equal(result[0].txid, txid) assert.property(result[0], "valid") - assert.equal(result[0].valid, false) + assert.equal(result[0].valid, null) }) it("should validate a known valid TXID", async () => { @@ -718,13 +718,43 @@ describe(`#SLP`, () => { "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", // Valid SLP token not in whitelist "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", - // Unprocessed SLP TX - // "a0d6406eecfd8634158efa9314ff15b4cbf451938e9dc7b5678c46b41eabc6ed" // Mint baton - "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019" + // Token send on BCHN network. + "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019", + // Token send on ABC network. + "336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d", + // Known invalid SLP token send of PSF tokens. + "2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74" ] const result = await bchjs.SLP.Utils.validateTxid3(txids) // console.log(`result: ${JSON.stringify(result, null, 2)}`) + + assert.equal(result[0].txid, txids[0]) + assert.equal(result[0].valid, null) + + assert.equal(result[1].txid, txids[1]) + assert.equal(result[1].valid, null) + + assert.equal(result[2].txid, txids[2]) + assert.equal(result[2].valid, true) + + // True in validateTxid() but null in validateTxid3() + assert.equal(result[3].txid, txids[3]) + assert.equal(result[3].valid, null) + + // Note: This should change from null to true once SLPDB finishes indexing. + assert.equal(result[4].txid, txids[4]) + assert.equal(result[4].valid, null) + + assert.equal(result[5].txid, txids[5]) + assert.equal(result[5].valid, null) + + assert.equal(result[6].txid, txids[6]) + assert.equal(result[6].valid, false) + assert.include( + result[6].invalidReason, + "Token outputs are greater than valid token inputs" + ) }) }) @@ -739,16 +769,43 @@ describe(`#SLP`, () => { "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", // Valid SLP token not in whitelist "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", - // Unprocessed SLP TX - // "a0d6406eecfd8634158efa9314ff15b4cbf451938e9dc7b5678c46b41eabc6ed" // Token send on BCHN network. "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019", // Token send on ABC network. - "336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d" + "336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d", + // Known invalid SLP token send of PSF tokens. + "2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74" ] const result = await bchjs.SLP.Utils.validateTxid(txids) - console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) + + assert.equal(result[0].txid, txids[0]) + assert.equal(result[0].valid, null) + + assert.equal(result[1].txid, txids[1]) + assert.equal(result[1].valid, null) + + assert.equal(result[2].txid, txids[2]) + assert.equal(result[2].valid, true) + + // True in validateTxid() but null in validateTxid3() + assert.equal(result[3].txid, txids[3]) + assert.equal(result[3].valid, true) + + // Note: This should change from null to true once SLPDB finishes indexing. + assert.equal(result[4].txid, txids[4]) + assert.equal(result[4].valid, null) + + assert.equal(result[5].txid, txids[5]) + assert.equal(result[5].valid, null) + + assert.equal(result[6].txid, txids[6]) + assert.equal(result[6].valid, false) + assert.include( + result[6].invalidReason, + "Token outputs are greater than valid token inputs" + ) }) }) }) diff --git a/test/integration/slp.js b/test/integration/slp.js index 1a6580b..30413a0 100644 --- a/test/integration/slp.js +++ b/test/integration/slp.js @@ -652,7 +652,7 @@ describe(`#SLP`, () => { "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" const result = await bchjs.SLP.Utils.validateTxid3(txid) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) + console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) @@ -660,7 +660,7 @@ describe(`#SLP`, () => { assert.equal(result[0].txid, txid) assert.property(result[0], "valid") - assert.equal(result[0].valid, false) + assert.equal(result[0].valid, null) }) it("should validate a known valid TXID", async () => { diff --git a/test/unit/fixtures/slp/mock-utils.js b/test/unit/fixtures/slp/mock-utils.js index 865ee76..b0d0034 100644 --- a/test/unit/fixtures/slp/mock-utils.js +++ b/test/unit/fixtures/slp/mock-utils.js @@ -1140,7 +1140,7 @@ const mockValidateTxid3Valid = [ const mockValidateTxid3Invalid = [ { txid: "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", - valid: false + valid: null } ] diff --git a/test/unit/slp-utils.js b/test/unit/slp-utils.js index 70223ca..42f20db 100644 --- a/test/unit/slp-utils.js +++ b/test/unit/slp-utils.js @@ -1964,7 +1964,7 @@ describe("#SLP Utils", () => { assert2.equal(result[0].txid, txid) assert2.property(result[0], "valid") - assert2.equal(result[0].valid, false) + assert2.equal(result[0].valid, null) }) it("should handle a mix of valid, invalid, and non-SLP txs", async () => { @@ -2031,7 +2031,7 @@ describe("#SLP Utils", () => { assert2.equal(result[0].txid, txid) assert2.property(result[0], "valid") - assert2.equal(result[0].valid, false) + assert2.equal(result[0].valid, null) }) it("should handle an array with a single element", async () => {