From eb78e919466c90545e7a1b3c5de676ab7c31e8d4 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sun, 29 Sep 2019 12:08:13 -0700 Subject: [PATCH 1/8] fix(blockbook-path): Added blockbook-path util lib --- src/routes/v3/blockbook.js | 15 +++++++++++--- src/util/blockbook-path.js | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/util/blockbook-path.js diff --git a/src/routes/v3/blockbook.js b/src/routes/v3/blockbook.js index 1b6d0a4..2acd759 100644 --- a/src/routes/v3/blockbook.js +++ b/src/routes/v3/blockbook.js @@ -10,6 +10,12 @@ const axios = require("axios") const routeUtils = require("./route-utils") const wlogger = require("../../util/winston-logging") +// Library for easily switching the API paths to use different instances of +// Blockbook. +const BlockbookPath = require("../../util/blockbook-path") +const BLOCKBOOKPATH = new BlockbookPath() +// BLOCKBOOKPATH.toOpenBazaar() + const router = express.Router() // Used for processing error messages before sending them to the user. @@ -44,7 +50,8 @@ async function balanceFromBlockbook(thisAddress) { // Convert the address to a cashaddr without a prefix. const addr = bchjs.Address.toCashAddress(thisAddress) - const path = `${process.env.BLOCKBOOK_URL}api/v2/address/${addr}` + const path = `${BLOCKBOOKPATH.addrPath}${addr}` + // console.log(`path: ${path}`) // Query the Blockbook Node API. const axiosResponse = await axios.get(path) @@ -211,7 +218,8 @@ async function utxosFromBlockbook(thisAddress) { // Convert the address to a cashaddr without a prefix. const addr = bchjs.Address.toCashAddress(thisAddress) - const path = `${process.env.BLOCKBOOK_URL}api/v2/utxo/${addr}` + const path = `${BLOCKBOOKPATH.utxoPath}${addr}` + // console.log(`path: ${path}`) // Query the Blockbook API. const axiosResponse = await axios.get(path) @@ -375,7 +383,8 @@ async function transactionsFromBlockbook(txid) { try { //console.log(`BLOCKBOOK_URL: ${BLOCKBOOK_URL}`) - const path = `${process.env.BLOCKBOOK_URL}api/v2/tx/${txid}` + const path = `${BLOCKBOOKPATH.txPath}${txid}` + // console.log(`path: ${path}`) // Query the Blockbook Node API. const axiosResponse = await axios.get(path) diff --git a/src/util/blockbook-path.js b/src/util/blockbook-path.js new file mode 100644 index 0000000..60ff0ce --- /dev/null +++ b/src/util/blockbook-path.js @@ -0,0 +1,40 @@ +/* + A utility library that allows bch-api to easily switch from a local or default + installation of Blockbook to the public Blockbook cloud service offered by + OpenBazaar. This will be expanded to other Blockbook indexer services. + + CT 9/29/19 - Switching to OpenBazaar does not work because the integration tests + use testnet and I don't think OpenBazaar has a testnet version of their BCH + Blockbook. +*/ + +"use strict" + +class BlockbookPath { + constructor() { + // defaults + this.addrPath = `${process.env.BLOCKBOOK_URL}api/v2/address/` + this.utxoPath = `${process.env.BLOCKBOOK_URL}api/v2/utxo/` + this.txPath = `${process.env.BLOCKBOOK_URL}api/v2/tx/` + } + + toOpenBazaar() { + if (process.env.NETWORK === "testnet") { + this.addrPath = `https://tbch.blockbook.api.openbazaar.org/api/address/` + this.utxoPath = `https://tbch.blockbook.api.openbazaar.org/api/utxo/` + this.txPath = `https://tbch.blockbook.api.openbazaar.org/api/tx/` + } else { + this.addrPath = `https://bch.blockbook.api.openbazaar.org/api/address/` + this.utxoPath = `https://bch.blockbook.api.openbazaar.org/api/utxo/` + this.txPath = `https://bch.blockbook.api.openbazaar.org/api/tx/` + } + } + + toDefault() { + this.addrPath = `${process.env.BLOCKBOOK_URL}api/v2/address/` + this.utxoPath = `${process.env.BLOCKBOOK_URL}api/v2/utxo/` + this.txPath = `${process.env.BLOCKBOOK_URL}api/v2/tx/` + } +} + +module.exports = BlockbookPath From 25568a5753c20a7d370e63f37df95b044fb5fe2d Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 3 Oct 2019 10:21:54 -0700 Subject: [PATCH 2/8] feat(tests): Switching tests to mainnet --- package.json | 2 +- test/v3/block.js | 10 +++++----- test/v3/blockbook.js | 45 ++++++++++++++++++++++---------------------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index bc1ac74..26ff804 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dev": "nodemon ./dist/app.js", "test": "npm run test-v3", "test-v2": "export NETWORK=testnet && nyc --reporter=text mocha --timeout 25000 test/v2/", - "test-v3": "export NETWORK=testnet && nyc --reporter=text mocha --timeout 25000 test/v3/", + "test-v3": "export NETWORK=mainnet && nyc --reporter=text mocha --timeout 25000 test/v3/", "test:integration": "mocha test/v3/integration", "coverage": "nyc report --reporter=text-lcov | coveralls", "coverage:report": "export NETWORK=testnet && nyc --reporter=html mocha test/v2/", diff --git a/test/v3/block.js b/test/v3/block.js index a78fb71..ff963cc 100644 --- a/test/v3/block.js +++ b/test/v3/block.js @@ -128,7 +128,7 @@ describe("#Block", () => { it("should GET /detailsByHash/:hash", async () => { req.params.hash = - "00000000000000645dec6503d3f5eafb0d2537a7a28f181d721dec7c44154c79" + "0000000000000000009ff8b38118d540e33c262bf6f78fc6863cc444526dc086" // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -183,7 +183,7 @@ describe("#Block", () => { it("should error on non-array single address", async () => { req.body = { hashes: - "00000000000000645dec6503d3f5eafb0d2537a7a28f181d721dec7c44154c79" + "0000000000000000009ff8b38118d540e33c262bf6f78fc6863cc444526dc086" } const result = await detailsByHashBulk(req, res) @@ -250,7 +250,7 @@ describe("#Block", () => { it("should get details for a single hash", async () => { req.body = { hashes: [ - "00000000000000645dec6503d3f5eafb0d2537a7a28f181d721dec7c44154c79" + "0000000000000000009ff8b38118d540e33c262bf6f78fc6863cc444526dc086" ] } @@ -291,8 +291,8 @@ describe("#Block", () => { it("should get details for multiple hashes", async () => { req.body = { hashes: [ - `00000000000000645dec6503d3f5eafb0d2537a7a28f181d721dec7c44154c79`, - `00000000c2b2c19cf499f57d5b0f724c6df753330d7acc7d4a8ebe412d427bd0` + `0000000000000000009ff8b38118d540e33c262bf6f78fc6863cc444526dc086`, + `0000000000000000009ff8b38118d540e33c262bf6f78fc6863cc444526dc086` ] } diff --git a/test/v3/blockbook.js b/test/v3/blockbook.js index b05407c..213910e 100644 --- a/test/v3/blockbook.js +++ b/test/v3/blockbook.js @@ -117,7 +117,7 @@ describe("#Blockbook Router", () => { }) it("should detect a network mismatch", async () => { - req.params.address = `bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3` + req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` const result = await balanceSingle(req, res) @@ -148,7 +148,7 @@ describe("#Blockbook Router", () => { }) it("should get balance for a single address", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -241,7 +241,7 @@ describe("#Blockbook Router", () => { it("should detect a network mismatch", async () => { req.body = { - addresses: [`bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3`] + addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] } const result = await balanceBulk(req, res) @@ -256,7 +256,7 @@ describe("#Blockbook Router", () => { try { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: [`bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3`] } // Switch the Insight URL to something that will error out. @@ -283,7 +283,7 @@ describe("#Blockbook Router", () => { it("should get details for a single address", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: ["bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf"] } // Mock the Insight URL for unit tests. @@ -317,8 +317,8 @@ describe("#Blockbook Router", () => { it("should get details for multiple addresses", async () => { req.body = { addresses: [ - `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`, - `bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr` + "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", + "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" ] } @@ -378,7 +378,7 @@ describe("#Blockbook Router", () => { }) it("should detect a network mismatch", async () => { - req.params.address = `bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3` + req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` const result = await utxosSingle(req, res) @@ -409,7 +409,8 @@ describe("#Blockbook Router", () => { }) it("should get utxos for a single address", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = + "bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7" // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -496,7 +497,7 @@ describe("#Blockbook Router", () => { it("should detect a network mismatch", async () => { req.body = { - addresses: [`bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3`] + addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] } const result = await utxosBulk(req, res) @@ -511,7 +512,7 @@ describe("#Blockbook Router", () => { try { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: [`bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf`] } // Switch the Insight URL to something that will error out. @@ -538,7 +539,7 @@ describe("#Blockbook Router", () => { it("should get details for a single address", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: [`bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`] } // Mock the Insight URL for unit tests. @@ -566,8 +567,8 @@ describe("#Blockbook Router", () => { it("should get details for multiple addresses", async () => { req.body = { addresses: [ - `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`, - `bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr` + `bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf`, + `bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf` ] } @@ -603,7 +604,7 @@ describe("#Blockbook Router", () => { it("should error on an array", async () => { req.params.txid = [ - `5fe9b74056319a8c87f45cc745030715a6180758b94938dbf90d639d55652392` + `6181c669614fa18039a19b23eb06806bfece1f7514ab457c3bb82a40fe171a6d` ] const result = await txSingle(req, res) @@ -630,7 +631,7 @@ describe("#Blockbook Router", () => { const savedUrl = process.env.BLOCKBOOK_URL try { - req.params.txid = `5fe9b74056319a8c87f45cc745030715a6180758b94938dbf90d639d55652392` + req.params.txid = `6181c669614fa18039a19b23eb06806bfece1f7514ab457c3bb82a40fe171a6d` // Switch the Insight URL to something that will error out. process.env.BLOCKBOOK_URL = "http://fakeurl/api/" @@ -649,7 +650,7 @@ describe("#Blockbook Router", () => { }) it("should get tx details for a single txid", async () => { - req.params.txid = `5fe9b74056319a8c87f45cc745030715a6180758b94938dbf90d639d55652392` + req.params.txid = `6181c669614fa18039a19b23eb06806bfece1f7514ab457c3bb82a40fe171a6d` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -722,7 +723,7 @@ describe("#Blockbook Router", () => { }) it("should error on non-array single address", async () => { - req.body.txids = `5fe9b74056319a8c87f45cc745030715a6180758b94938dbf90d639d55652392` + req.body.txids = `6181c669614fa18039a19b23eb06806bfece1f7514ab457c3bb82a40fe171a6d` const result = await txBulk(req, res) @@ -797,10 +798,10 @@ describe("#Blockbook Router", () => { } }) - it("should get details for a single address", async () => { + it("should get details for a single txid", async () => { req.body = { txids: [ - `5fe9b74056319a8c87f45cc745030715a6180758b94938dbf90d639d55652392` + `6181c669614fa18039a19b23eb06806bfece1f7514ab457c3bb82a40fe171a6d` ] } @@ -856,8 +857,8 @@ describe("#Blockbook Router", () => { it("should get details for multiple txid", async () => { req.body = { txids: [ - `5fe9b74056319a8c87f45cc745030715a6180758b94938dbf90d639d55652392`, - `5fe9b74056319a8c87f45cc745030715a6180758b94938dbf90d639d55652392` + `6181c669614fa18039a19b23eb06806bfece1f7514ab457c3bb82a40fe171a6d`, + `6181c669614fa18039a19b23eb06806bfece1f7514ab457c3bb82a40fe171a6d` ] } From aa1d050e30b489460c965a0ef4fd36e4490a065a Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 3 Oct 2019 13:29:14 -0700 Subject: [PATCH 3/8] Fixed block, blockbook, blockchain, and control integration tests --- test/v3/blockchain.js | 50 +++++++++++++++++++++++------------------- test/v3/control.js | 51 ------------------------------------------- 2 files changed, 28 insertions(+), 73 deletions(-) diff --git a/test/v3/blockchain.js b/test/v3/blockchain.js index b883f67..cd0cd58 100644 --- a/test/v3/blockchain.js +++ b/test/v3/blockchain.js @@ -272,15 +272,15 @@ describe("#BlockchainRouter", () => { } req.params.hash = - "00000000000008c3679777df34f1a09565f98b2400a05b7c8da72525fdca3900" + "000000000000000002fa9d7851b284c53a5831651b04211c266badf2ad2d8ef0" const result = await getBlockHeader(req, res) - //console.log(`result: ${util.inspect(result)}`) + // console.log(`result: ${util.inspect(result)}`) assert.isString(result) assert.equal( result, - "0000ff7f7d217c9b7845ea8b50d620c59a1bf7c276566406e9b7bc7e463e0000000000006d70322c0b697c1c81d2744f87f09f1e9780ba5d30338952e2cdc64e60456f8423bb0a5ceafa091a3e843526" + "000000202ed2723e7590e2b937f6821a99d6764cb8799bf30f8e300000000000000000001d311c02df9a1e3f57b8dbdcf97ec8dbc3109a26779724c63e560b29ad9ea501e2af955d286403183049e39c" ) }) @@ -294,7 +294,7 @@ describe("#BlockchainRouter", () => { req.query.verbose = true req.params.hash = - "00000000000008c3679777df34f1a09565f98b2400a05b7c8da72525fdca3900" + "000000000000000002fa9d7851b284c53a5831651b04211c266badf2ad2d8ef0" const result = await getBlockHeader(req, res) //console.log(`result: ${util.inspect(result)}`) @@ -398,7 +398,7 @@ describe("#BlockchainRouter", () => { it("should get concise block header for a single hash", async () => { req.body.hashes = [ - "00000000000008c3679777df34f1a09565f98b2400a05b7c8da72525fdca3900" + "000000000000000002fa9d7851b284c53a5831651b04211c266badf2ad2d8ef0" ] // Mock the RPC call for unit tests. @@ -410,20 +410,20 @@ describe("#BlockchainRouter", () => { // Call the details API. const result = await getBlockHeaderBulk(req, res) - //console.log(`result: ${util.inspect(result)}`) + // console.log(`result: ${util.inspect(result)}`) // Assert that required fields exist in the returned object. assert.isArray(result) assert.equal( result[0], - "0000ff7f7d217c9b7845ea8b50d620c59a1bf7c276566406e9b7bc7e463e0000000000006d70322c0b697c1c81d2744f87f09f1e9780ba5d30338952e2cdc64e60456f8423bb0a5ceafa091a3e843526" + "000000202ed2723e7590e2b937f6821a99d6764cb8799bf30f8e300000000000000000001d311c02df9a1e3f57b8dbdcf97ec8dbc3109a26779724c63e560b29ad9ea501e2af955d286403183049e39c" ) }) it("should get verbose block header for a single hash", async () => { req.body = { hashes: [ - "00000000000008c3679777df34f1a09565f98b2400a05b7c8da72525fdca3900" + "000000000000000002fa9d7851b284c53a5831651b04211c266badf2ad2d8ef0" ], verbose: true } @@ -461,8 +461,8 @@ describe("#BlockchainRouter", () => { it("should get details for multiple block heights", async () => { req.body.hashes = [ - "00000000000008c3679777df34f1a09565f98b2400a05b7c8da72525fdca3900", - "00000000000008c3679777df34f1a09565f98b2400a05b7c8da72525fdca3900" + "000000000000000002fa9d7851b284c53a5831651b04211c266badf2ad2d8ef0", + "000000000000000002fa9d7851b284c53a5831651b04211c266badf2ad2d8ef0" ] // Mock the RPC call for unit tests. @@ -840,7 +840,7 @@ describe("#BlockchainRouter", () => { .reply(200, { result: mockData.mockTxOut }) } - req.params.txid = `5747e6462e2c452a5d583fd6a5f82866cd8e4a86826c86d9a1842b7d023e0c0c` + req.params.txid = `2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266` req.params.n = 1 const result = await getTxOut(req, res) @@ -906,10 +906,10 @@ describe("#BlockchainRouter", () => { .reply(200, { result: mockData.mockTxOutProof }) } - req.params.txid = `d65881582ff2bff36747d7a0d0e273f10281abc8bd5c15df5d72f8f3fa779cde` + req.params.txid = `2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266` const result = await getTxOutProof(req, res) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isString(result) }) @@ -968,7 +968,7 @@ describe("#BlockchainRouter", () => { } req.body.txids = [ - `d65881582ff2bff36747d7a0d0e273f10281abc8bd5c15df5d72f8f3fa779cde` + `2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266` ] const result = await getTxOutProofBulk(req, res) @@ -988,8 +988,8 @@ describe("#BlockchainRouter", () => { } req.body.txids = [ - `d65881582ff2bff36747d7a0d0e273f10281abc8bd5c15df5d72f8f3fa779cde`, - `d65881582ff2bff36747d7a0d0e273f10281abc8bd5c15df5d72f8f3fa779cde` + `2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266`, + `2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266` ] const result = await getTxOutProofBulk(req, res) @@ -1037,7 +1037,7 @@ describe("#BlockchainRouter", () => { it("should GET /verifyTxOutProof", async () => { const expected = - "d65881582ff2bff36747d7a0d0e273f10281abc8bd5c15df5d72f8f3fa779cde" + "2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266" // Mock the RPC call for unit tests. if (process.env.TEST === "unit") { @@ -1046,7 +1046,8 @@ describe("#BlockchainRouter", () => { .reply(200, { result: [expected] }) } - req.params.proof = mockData.mockTxOutProof + req.params.proof = + "000000202ed2723e7590e2b937f6821a99d6764cb8799bf30f8e300000000000000000001d311c02df9a1e3f57b8dbdcf97ec8dbc3109a26779724c63e560b29ad9ea501e2af955d286403183049e39c1e000000067139f230701a2819a76795564bd2f67ded7eeae68596f368eddb3dd5bc54e59320e896f71d61cfc3ae3d4a90fca08b1aa35ba91256d8939d2cad11e638c0081f66724abdef55cf7b8b9fed064bce0369171434f8b289c1330ccef765f8e97a2c0d794d81aafb535855f7daa6bb51e40f77c6b59d7af7f62d0eb726a4fc4df82353d56fcbda7c7ea6bd935d61af8fb3b295637e6f323b10231135b3f10a034cfb238f635830c0595e52c6c31247cf677b555f7a287076e20cd0e1d3cc9af7260f02b700" const result = await verifyTxOutProof(req, res) //console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -1103,7 +1104,7 @@ describe("#BlockchainRouter", () => { it("should get single proof", async () => { const expected = - "d65881582ff2bff36747d7a0d0e273f10281abc8bd5c15df5d72f8f3fa779cde" + "2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266" // Mock the RPC call for unit tests. if (process.env.TEST === "unit") { @@ -1112,7 +1113,9 @@ describe("#BlockchainRouter", () => { .reply(200, { result: [expected] }) } - req.body.proofs = [mockData.mockTxOutProof] + req.body.proofs = [ + "000000202ed2723e7590e2b937f6821a99d6764cb8799bf30f8e300000000000000000001d311c02df9a1e3f57b8dbdcf97ec8dbc3109a26779724c63e560b29ad9ea501e2af955d286403183049e39c1e000000067139f230701a2819a76795564bd2f67ded7eeae68596f368eddb3dd5bc54e59320e896f71d61cfc3ae3d4a90fca08b1aa35ba91256d8939d2cad11e638c0081f66724abdef55cf7b8b9fed064bce0369171434f8b289c1330ccef765f8e97a2c0d794d81aafb535855f7daa6bb51e40f77c6b59d7af7f62d0eb726a4fc4df82353d56fcbda7c7ea6bd935d61af8fb3b295637e6f323b10231135b3f10a034cfb238f635830c0595e52c6c31247cf677b555f7a287076e20cd0e1d3cc9af7260f02b700" + ] const result = await verifyTxOutProofBulk(req, res) //console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -1124,7 +1127,7 @@ describe("#BlockchainRouter", () => { it("should get multiple proofs", async () => { const expected = - "d65881582ff2bff36747d7a0d0e273f10281abc8bd5c15df5d72f8f3fa779cde" + "2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266" // Mock the RPC call for unit tests. if (process.env.TEST === "unit") { @@ -1134,7 +1137,10 @@ describe("#BlockchainRouter", () => { .reply(200, { result: [expected] }) } - req.body.proofs = [mockData.mockTxOutProof, mockData.mockTxOutProof] + req.body.proofs = [ + "000000202ed2723e7590e2b937f6821a99d6764cb8799bf30f8e300000000000000000001d311c02df9a1e3f57b8dbdcf97ec8dbc3109a26779724c63e560b29ad9ea501e2af955d286403183049e39c1e000000067139f230701a2819a76795564bd2f67ded7eeae68596f368eddb3dd5bc54e59320e896f71d61cfc3ae3d4a90fca08b1aa35ba91256d8939d2cad11e638c0081f66724abdef55cf7b8b9fed064bce0369171434f8b289c1330ccef765f8e97a2c0d794d81aafb535855f7daa6bb51e40f77c6b59d7af7f62d0eb726a4fc4df82353d56fcbda7c7ea6bd935d61af8fb3b295637e6f323b10231135b3f10a034cfb238f635830c0595e52c6c31247cf677b555f7a287076e20cd0e1d3cc9af7260f02b700", + "000000202ed2723e7590e2b937f6821a99d6764cb8799bf30f8e300000000000000000001d311c02df9a1e3f57b8dbdcf97ec8dbc3109a26779724c63e560b29ad9ea501e2af955d286403183049e39c1e000000067139f230701a2819a76795564bd2f67ded7eeae68596f368eddb3dd5bc54e59320e896f71d61cfc3ae3d4a90fca08b1aa35ba91256d8939d2cad11e638c0081f66724abdef55cf7b8b9fed064bce0369171434f8b289c1330ccef765f8e97a2c0d794d81aafb535855f7daa6bb51e40f77c6b59d7af7f62d0eb726a4fc4df82353d56fcbda7c7ea6bd935d61af8fb3b295637e6f323b10231135b3f10a034cfb238f635830c0595e52c6c31247cf677b555f7a287076e20cd0e1d3cc9af7260f02b700" + ] const result = await verifyTxOutProofBulk(req, res) //console.log(`result: ${JSON.stringify(result, null, 2)}`) diff --git a/test/v3/control.js b/test/v3/control.js index c1c79f5..9149290 100644 --- a/test/v3/control.js +++ b/test/v3/control.js @@ -87,57 +87,6 @@ describe("#ControlRouter", () => { }) }) - describe("#GetInfo", () => { - const getInfo = controlRoute.testableComponents.getInfo - - it("should throw 500 when network issues", async () => { - // Save the existing RPC URL. - const savedUrl = process.env.RPC_BASEURL - - // Manipulate the URL to cause a 500 network error. - process.env.RPC_BASEURL = "http://fakeurl/api/" - - const result = await getInfo(req, res) - //console.log(`result: ${util.inspect(result)}`) - - // Restore the saved URL. - process.env.RPC_BASEURL = savedUrl - - assert.isAbove( - res.statusCode, - 499, - "HTTP status code 500 or greater expected." - ) - //assert.include(result.error, "ENOTFOUND", "Error message expected") - }) - - it("should get info on the full node", async () => { - // Mock the RPC call for unit tests. - if (process.env.TEST === "unit") { - nock(`${process.env.RPC_BASEURL}`) - .post(``) - .reply(200, { result: mockData.mockGetInfo }) - } - - const result = await getInfo(req, res) - //console.log(`result: ${util.inspect(result)}`) - - assert.hasAnyKeys(result, [ - "version", - "protocolversion", - "blocks", - "timeoffset", - "connections", - "proxy", - "difficulty", - "testnet", - "paytxfee", - "relayfee", - "errors" - ]) - }) - }) - describe("#GetNetworkInfo", () => { const getNetworkInfo = controlRoute.testableComponents.getNetworkInfo From b467ae29e2efb048e201bc79156d4af36884b602 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 3 Oct 2019 13:39:48 -0700 Subject: [PATCH 4/8] refactored insight-address integrationt tests --- test/v3/insight-address.js | 72 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/test/v3/insight-address.js b/test/v3/insight-address.js index 1652da3..e5a280b 100644 --- a/test/v3/insight-address.js +++ b/test/v3/insight-address.js @@ -143,7 +143,7 @@ describe("#Insight Address", () => { it("should detect a network mismatch", async () => { req.body = { - addresses: [`bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3`] + addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] } const result = await detailsBulk(req, res) @@ -185,7 +185,7 @@ describe("#Insight Address", () => { it("should default to page 0", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: [`bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`] } // Mock the Insight URL for unit tests. @@ -205,7 +205,7 @@ describe("#Insight Address", () => { it("should process the requested page", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`], + addresses: [`bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`], page: 5 } @@ -226,7 +226,7 @@ describe("#Insight Address", () => { it("should calculate the total number of pages", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: [`bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`] } // Mock the Insight URL for unit tests. @@ -245,7 +245,7 @@ describe("#Insight Address", () => { it("should get details for a single address", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: [`bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`] } // Mock the Insight URL for unit tests. @@ -283,8 +283,8 @@ describe("#Insight Address", () => { it("should get details for multiple addresses", async () => { req.body = { addresses: [ - `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`, - `bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr` + `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`, + `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` ] } @@ -344,7 +344,7 @@ describe("#Insight Address", () => { }) it("should detect a network mismatch", async () => { - req.params.address = `bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3` + req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` const result = await detailsSingle(req, res) @@ -375,7 +375,7 @@ describe("#Insight Address", () => { }) it("should default to page 0", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -393,7 +393,7 @@ describe("#Insight Address", () => { }) it("should process the requested page", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` req.query.page = 5 // Mock the Insight URL for unit tests. @@ -411,7 +411,7 @@ describe("#Insight Address", () => { }) it("should calculate the total number of pages", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -427,7 +427,7 @@ describe("#Insight Address", () => { }) it("should get details for a single address", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -510,7 +510,7 @@ describe("#Insight Address", () => { it("should detect a network mismatch", async () => { req.body = { - addresses: [`bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3`] + addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] } const result = await utxoBulk(req, res) @@ -545,7 +545,7 @@ describe("#Insight Address", () => { it("should get utxos for a single address", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: [`bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`] } // Mock the Insight URL for unit tests. @@ -583,8 +583,8 @@ describe("#Insight Address", () => { it("should get utxos for mulitple addresses", async () => { req.body = { addresses: [ - `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`, - `bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr` + `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`, + `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` ] } @@ -657,7 +657,7 @@ describe("#Insight Address", () => { }) it("should detect a network mismatch", async () => { - req.params.address = `bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3` + req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` const result = await utxoSingle(req, res) @@ -669,7 +669,7 @@ describe("#Insight Address", () => { const savedUrl = process.env.BITCOINCOM_BASEURL try { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` // Switch the Insight URL to something that will error out. process.env.BITCOINCOM_BASEURL = "http://fakeurl/api/" @@ -688,7 +688,7 @@ describe("#Insight Address", () => { }) it("should get details for a single address", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -740,7 +740,7 @@ describe("#Insight Address", () => { it("should error on non-array single address", async () => { req.body = { - address: `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + address: `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` } const result = await unconfirmedBulk(req, res) @@ -783,7 +783,7 @@ describe("#Insight Address", () => { it("should detect a network mismatch", async () => { req.body = { - addresses: [`bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3`] + addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] } const result = await unconfirmedBulk(req, res) @@ -818,7 +818,7 @@ describe("#Insight Address", () => { it("should get unconfirmed data for a single address", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: [`bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`] } // Mock the Insight URL for unit tests. @@ -843,8 +843,8 @@ describe("#Insight Address", () => { it("should get unconfirmed data for an array of addresses", async () => { req.body = { addresses: [ - `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`, - `bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr` + `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`, + `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` ] } @@ -905,7 +905,7 @@ describe("#Insight Address", () => { }) it("should detect a network mismatch", async () => { - req.params.address = `bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3` + req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` const result = await unconfirmedSingle(req, res) @@ -936,7 +936,7 @@ describe("#Insight Address", () => { }) it("should get details for a single address", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -1023,7 +1023,7 @@ describe("#Insight Address", () => { it("should detect a network mismatch", async () => { req.body = { - addresses: [`bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3`] + addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] } const result = await transactionsBulk(req, res) @@ -1058,7 +1058,7 @@ describe("#Insight Address", () => { it("should default to page 0", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: [`bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`] } // Mock the Insight URL for unit tests. @@ -1077,7 +1077,7 @@ describe("#Insight Address", () => { it("should process the requested page", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`], + addresses: [`bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`], page: 5 } @@ -1097,7 +1097,7 @@ describe("#Insight Address", () => { it("should get transactions for a single address", async () => { req.body = { - addresses: [`bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`] + addresses: [`bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`] } // Mock the Insight URL for unit tests. @@ -1123,8 +1123,8 @@ describe("#Insight Address", () => { it("should get transactions for an array of addresses", async () => { req.body = { addresses: [ - `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4`, - `bchtest:qzknfggae0av6yvxk77gmyq7syc67yux6sk80haqyr` + `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7`, + `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` ] } @@ -1185,7 +1185,7 @@ describe("#Insight Address", () => { }) it("should detect a network mismatch", async () => { - req.params.address = `bitcoincash:qqqvv56zepke5k0xeaehlmjtmkv9ly2uzgkxpajdx3` + req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` const result = await transactionsSingle(req, res) @@ -1216,7 +1216,7 @@ describe("#Insight Address", () => { }) it("should default to page 0", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -1233,7 +1233,7 @@ describe("#Insight Address", () => { }) it("should process the requested page", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` req.query.page = 5 // Mock the Insight URL for unit tests. @@ -1251,7 +1251,7 @@ describe("#Insight Address", () => { }) it("should get details for a single address", async () => { - req.params.address = `bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4` + req.params.address = `bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { From 1421fbdc1f38e534b703ff5c088609a22af330ae Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 3 Oct 2019 13:46:37 -0700 Subject: [PATCH 5/8] Refactored raw-transactions lib integration tests --- test/v3/raw-transactions.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/v3/raw-transactions.js b/test/v3/raw-transactions.js index 35f3467..a9fc216 100644 --- a/test/v3/raw-transactions.js +++ b/test/v3/raw-transactions.js @@ -478,7 +478,7 @@ describe("#Raw-Transactions", () => { } req.body.txids = [ - "bd320377db7026a3dd5c7ec444596c0ee18fc25c4f34ee944adc03e432ce1971" + "2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266" ] const result = await getRawTransactionBulk(req, res) @@ -497,7 +497,7 @@ describe("#Raw-Transactions", () => { } req.body.txids = [ - "bd320377db7026a3dd5c7ec444596c0ee18fc25c4f34ee944adc03e432ce1971" + "2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266" ] req.body.verbose = true @@ -566,7 +566,7 @@ describe("#Raw-Transactions", () => { } req.params.txid = - "bd320377db7026a3dd5c7ec444596c0ee18fc25c4f34ee944adc03e432ce1971" + "2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266" const result = await getRawTransactionSingle(req, res) //console.log(`result: ${util.inspect(result)}`) @@ -583,7 +583,7 @@ describe("#Raw-Transactions", () => { } req.params.txid = - "bd320377db7026a3dd5c7ec444596c0ee18fc25c4f34ee944adc03e432ce1971" + "2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266" req.query.verbose = "true" const result = await getRawTransactionSingle(req, res) @@ -679,11 +679,11 @@ describe("#Raw-Transactions", () => { } req.body.hexes = [ - "0200000001189f7cf4303e2e0bcc5af4be323b9b397dd4104ca2de09528eb90a1450b8a999010000006a4730440220212ec2ffce136a30cec1bc86a40b08a2afdeb6f8dbd652d7bcb07b1aad6dfa8c022041f59585273b89d88879a9a531ba3272dc953f48ff57dad955b2dee70e76c0624121030143ffd18f1c4add75c86b2f930d9551d51f7a6bd786314247022b7afc45d231ffffffff0230d39700000000001976a914af64a026e06910c59463b000d18c3d125d7e951a88ac58c20000000000001976a914af64a026e06910c59463b000d18c3d125d7e951a88ac00000000" + "020000000136697692fed77bc4f5b6885295d0c56d1d0280fb578f445ce42be4eb6db381f2010000006a4730440220473adba0e7da14f0abf4817bbd591741ecb8da6544b998f10341f6704f5f05280220405221c626cb7edcf333367ebd469aff3f5a2169e37ee58eebb811ffc2fbc9e0412102202ff86325c5d903171fa5a2895c4efb3765105115460dc96f113048ddb69b47feffffff027a621b00000000001976a914e0a8ffc3b91e35f46618d6db90f66397989abf0588ac38041300000000001976a914a741f282af390bc7ea8c4375a3a56401d668564288ac2c330900" ] const result = await sendRawTransaction(req, res) - //console.log(`result: ${util.inspect(result)}`) + // console.log(`result: ${util.inspect(result)}`) if (process.env.TEST === "unit") { assert.isArray(result) @@ -738,7 +738,7 @@ describe("#Raw-Transactions", () => { process.env.RPC_BASEURL = "http://fakeurl/api/" req.params.hex = - "0200000001189f7cf4303e2e0bcc5af4be323b9b397dd4104ca2de09528eb90a1450b8a999010000006a4730440220212ec2ffce136a30cec1bc86a40b08a2afdeb6f8dbd652d7bcb07b1aad6dfa8c022041f59585273b89d88879a9a531ba3272dc953f48ff57dad955b2dee70e76c0624121030143ffd18f1c4add75c86b2f930d9551d51f7a6bd786314247022b7afc45d231ffffffff0230d39700000000001976a914af64a026e06910c59463b000d18c3d125d7e951a88ac58c20000000000001976a914af64a026e06910c59463b000d18c3d125d7e951a88ac00000000" + "020000000136697692fed77bc4f5b6885295d0c56d1d0280fb578f445ce42be4eb6db381f2010000006a4730440220473adba0e7da14f0abf4817bbd591741ecb8da6544b998f10341f6704f5f05280220405221c626cb7edcf333367ebd469aff3f5a2169e37ee58eebb811ffc2fbc9e0412102202ff86325c5d903171fa5a2895c4efb3765105115460dc96f113048ddb69b47feffffff027a621b00000000001976a914e0a8ffc3b91e35f46618d6db90f66397989abf0588ac38041300000000001976a914a741f282af390bc7ea8c4375a3a56401d668564288ac2c330900" const result = await sendRawTransaction(req, res) //console.log(`result: ${util.inspect(result)}`) @@ -789,7 +789,7 @@ describe("#Raw-Transactions", () => { } req.params.hex = - "0200000001189f7cf4303e2e0bcc5af4be323b9b397dd4104ca2de09528eb90a1450b8a999010000006a4730440220212ec2ffce136a30cec1bc86a40b08a2afdeb6f8dbd652d7bcb07b1aad6dfa8c022041f59585273b89d88879a9a531ba3272dc953f48ff57dad955b2dee70e76c0624121030143ffd18f1c4add75c86b2f930d9551d51f7a6bd786314247022b7afc45d231ffffffff0230d39700000000001976a914af64a026e06910c59463b000d18c3d125d7e951a88ac58c20000000000001976a914af64a026e06910c59463b000d18c3d125d7e951a88ac00000000" + "020000000136697692fed77bc4f5b6885295d0c56d1d0280fb578f445ce42be4eb6db381f2010000006a4730440220473adba0e7da14f0abf4817bbd591741ecb8da6544b998f10341f6704f5f05280220405221c626cb7edcf333367ebd469aff3f5a2169e37ee58eebb811ffc2fbc9e0412102202ff86325c5d903171fa5a2895c4efb3765105115460dc96f113048ddb69b47feffffff027a621b00000000001976a914e0a8ffc3b91e35f46618d6db90f66397989abf0588ac38041300000000001976a914a741f282af390bc7ea8c4375a3a56401d668564288ac2c330900" const result = await sendRawTransaction(req, res) //console.log(`result: ${util.inspect(result)}`) From c890fce0d226c68aab3644c614fc990824de2976 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 3 Oct 2019 14:07:42 -0700 Subject: [PATCH 6/8] Refactored slp integration tests --- test/v3/slp.js | 79 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/test/v3/slp.js b/test/v3/slp.js index 5b4523c..530047b 100644 --- a/test/v3/slp.js +++ b/test/v3/slp.js @@ -189,7 +189,7 @@ describe("#SLP", () => { //assert.include(result.error,"Network error: Could not communicate with full node","Error message expected") }) - it("should return 'not found' for mainnet txid on testnet", async () => { + it("should return 'not found' for testnet txid on mainnet", async () => { // Mock the RPC call for unit tests. if (process.env.TEST === "unit") { nock(mockServerUrl) @@ -199,9 +199,9 @@ describe("#SLP", () => { req.params.tokenId = // testnet - //"650dea14c77f4d749608e36e375450c9ac91deb8b1b53e50cb0de2059a52d19a" - // mainnet - "259908ae44f46ef585edef4bcc1e50dc06e4c391ac4be929fae27235b8158cf1" + "d284e71227ec89f713b964d8eda595be6392bebd2fac46082bc5a9ce6fb7b33e" + // mainnet + //"259908ae44f46ef585edef4bcc1e50dc06e4c391ac4be929fae27235b8158cf1" const result = await listSingleToken(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -213,7 +213,7 @@ describe("#SLP", () => { it("should get token information", async () => { // testnet const tokenIdToTest = - "af8e10dd87e7092e5f0f3b9cf62e85e91f74395fbf22cd14f12bcdfbf1e8354f" + "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0" // Mock the RPC call for unit tests. if (process.env.TEST === "unit") { @@ -321,7 +321,7 @@ describe("#SLP", () => { //assert.include(result.error,"Network error: Could not communicate with full node","Error message expected") }) - it("should return 'not found' for mainnet txid on testnet", async () => { + it("should return 'not found' for testnet txid on mainnet", async () => { // Mock the RPC call for unit tests. if (process.env.TEST === "unit") { nock(mockServerUrl) @@ -331,9 +331,9 @@ describe("#SLP", () => { req.body.tokenIds = // testnet - //"650dea14c77f4d749608e36e375450c9ac91deb8b1b53e50cb0de2059a52d19a" - // mainnet - ["0b314bc2b2905b8844222871c6b665ae3494117c83b11302824561bb904efb6b"] + ["d284e71227ec89f713b964d8eda595be6392bebd2fac46082bc5a9ce6fb7b33e"] + // mainnet + // ["0b314bc2b2905b8844222871c6b665ae3494117c83b11302824561bb904efb6b"] const result = await listBulkToken(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -351,9 +351,9 @@ describe("#SLP", () => { .reply(200, mockData.mockSingleToken) } - req.body.tokenIds = - // testnet - ["af8e10dd87e7092e5f0f3b9cf62e85e91f74395fbf22cd14f12bcdfbf1e8354f"] + req.body.tokenIds = [ + "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0" + ] const result = await listBulkToken(req, res) //console.log(`result: ${util.inspect(result)}`) @@ -392,12 +392,10 @@ describe("#SLP", () => { .reply(200, mockData.mockSingleToken) } - req.body.tokenIds = - // testnet - [ - "af8e10dd87e7092e5f0f3b9cf62e85e91f74395fbf22cd14f12bcdfbf1e8354f", - "4902b6e8627f4c9a4fc5ebe1da19c8ae88526dbab877dfc9c74d23aaab2c7224" - ] + req.body.tokenIds = [ + "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0", + "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0" + ] const result = await listBulkToken(req, res) //console.log(`result: ${util.inspect(result)}`) @@ -450,8 +448,7 @@ describe("#SLP", () => { }) it("should throw 400 if address network mismatch", async () => { - req.params.address = - "simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk" + req.params.address = "slptest:qzcvpw3ah7r880d49wsqzrsl90pg0rqjjurmj3g4nk" const result = await balancesForAddress(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -467,7 +464,8 @@ describe("#SLP", () => { // Manipulate the URL to cause a 500 network error. process.env.SLPDB_URL = "http://fakeurl/api/" - req.params.address = "slptest:qz35h5mfa8w2pqma2jq06lp7dnv5fxkp2shlcycvd5" + req.params.address = + "simpleledger:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5me5fdrdn" const result = await balancesForAddress(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -496,7 +494,8 @@ describe("#SLP", () => { .reply(200, mockData.mockSingleAddress) } - req.params.address = "slptest:qz80hhc6eucgauzmcfjzglccspdqfpl0fqx7x3lshs" + req.params.address = + "simpleledger:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5me5fdrdn" const result = await balancesForAddress(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -535,7 +534,7 @@ describe("#SLP", () => { it("should throw 400 if address network mismatch", async () => { req.body.addresses = [ - "simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk" + "slptest:qzcvpw3ah7r880d49wsqzrsl90pg0rqjjurmj3g4nk" ] const result = await balancesForAddressBulk(req, res) @@ -553,7 +552,7 @@ describe("#SLP", () => { process.env.SLPDB_URL = "http://fakeurl/api/" req.body.addresses = [ - "slptest:qz35h5mfa8w2pqma2jq06lp7dnv5fxkp2shlcycvd5" + "simpleledger:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5me5fdrdn" ] const result = await balancesForAddressBulk(req, res) @@ -578,7 +577,7 @@ describe("#SLP", () => { if (process.env.TEST !== "unit") { it("should get token balance for an address", async () => { req.body.addresses = [ - "slptest:qz80hhc6eucgauzmcfjzglccspdqfpl0fqx7x3lshs" + "simpleledger:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5me5fdrdn" ] const result = await balancesForAddressBulk(req, res) @@ -636,8 +635,7 @@ describe("#SLP", () => { }) it("should throw 400 if address network mismatch", async () => { - req.params.address = - "simpleledger:qr5agtachyxvrwxu76vzszan5pnvuzy8duhv4lxrsk" + req.params.address = "slptest:qzcvpw3ah7r880d49wsqzrsl90pg0rqjjurmj3g4nk" const result = await balancesForAddressByTokenID(req, res) //console.log(`result: ${util.inspect(result)}`) @@ -653,9 +651,10 @@ describe("#SLP", () => { // Manipulate the URL to cause a 500 network error. process.env.SLPDB_URL = "http://fakeurl/api/" - req.params.address = "slptest:qz4qnxcxwvmacgye8wlakhz0835x0w3vtvxu67w0ac" + req.params.address = + "simpleledger:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5me5fdrdn" req.params.tokenId = - "7ac7f4bb50b019fe0f5c81e3fc13fc0720e130282ea460768cafb49785eb2796" + "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7" const result = await balancesForAddressByTokenID(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -683,9 +682,10 @@ describe("#SLP", () => { .reply(200, mockData.mockSingleAddress) } - req.params.address = "slptest:pz0qcslrqn7hr44hsszwl4lw5r6udkg6zqv7sq3kk7" + req.params.address = + "simpleledger:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5me5fdrdn" req.params.tokenId = - "6b081fcd1f78b187be1464313dac8ff257251b727a42b613552a4040870aeb29" + "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7" const result = await balancesForAddressByTokenID(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -717,7 +717,8 @@ describe("#SLP", () => { .reply(200, { result: mockData.mockConvert }) } - req.params.address = "slptest:qz35h5mfa8w2pqma2jq06lp7dnv5fxkp2shlcycvd5" + req.params.address = + "simpleledger:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5me5fdrdn" const result = await convertAddressSingle(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -836,7 +837,7 @@ describe("#SLP", () => { } req.body.txids = [ - "78d57a82a0dd9930cc17843d9d06677f267777dd6b25055bad0ae43f1b884091" + "77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d" ] const result = await validateBulk(req, res) @@ -855,8 +856,8 @@ describe("#SLP", () => { } req.body.txids = [ - "78d57a82a0dd9930cc17843d9d06677f267777dd6b25055bad0ae43f1b884091", - "82d996847a861b08b1601284ef7d40a1777d019154a6c4ed11571609dd3555ac" + "77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d", + "77872738b6bddee6c0cbdb9509603de20b15d4f6b26602f629417aec2f5d5e8d" ] const result = await validateBulk(req, res) @@ -896,7 +897,7 @@ describe("#SLP", () => { } req.params.tokenId = - "37279c7dc81ceb34d12f03344b601c582e931e05d0e552c29c428bfa39d39af3" + "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7" const result = await tokenStatsSingle(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -937,7 +938,7 @@ describe("#SLP", () => { assert.hasAllKeys(result, ["error"]) assert.include(result.error, "tokenId can not be empty") }) - // + it("should get balances for tokenId", async () => { // Mock the RPC call for unit tests. if (process.env.TEST === "unit") { @@ -949,7 +950,7 @@ describe("#SLP", () => { } req.params.tokenId = - "37279c7dc81ceb34d12f03344b601c582e931e05d0e552c29c428bfa39d39af3" + "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7" const result = await balancesForTokenSingle(req, res) // console.log(`result: ${util.inspect(result)}`) @@ -1002,7 +1003,7 @@ describe("#SLP", () => { } req.params.txid = - "57b3082a2bf269b3d6f40fee7fb9c664e8256a88ca5ee2697c05b9457822d446" + "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7" const result = await txDetails(req, res) //console.log(`result: ${JSON.stringify(result, null, 2)}`) From 31af645aed46972658986217e492dc7c7b2fac97 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 3 Oct 2019 14:14:36 -0700 Subject: [PATCH 7/8] Finished refactoring integration tests --- test/v3/transaction.js | 10 +++++----- test/v3/util.js | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/v3/transaction.js b/test/v3/transaction.js index 0c2ef79..2450134 100644 --- a/test/v3/transaction.js +++ b/test/v3/transaction.js @@ -145,7 +145,7 @@ describe("#Transactions", () => { }) it("should process a single txid", async () => { - const txid = `6f235bd3a689f03c11969cd649ccad592462ca958bc519a30194e7a67b349a40` + const txid = `2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -181,8 +181,8 @@ describe("#Transactions", () => { }) it("should process a multiple txids", async () => { - const txid1 = `6f235bd3a689f03c11969cd649ccad592462ca958bc519a30194e7a67b349a40` - const txid2 = `8d4fd4dcaa9d8051dc7d862dc23d8aa23e20b77b9c928c49380685459caa7043` + const txid1 = `2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266` + const txid2 = `2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266` // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { @@ -294,8 +294,8 @@ describe("#Transactions", () => { } }) - it("should get details for a single address", async () => { - const txid = `6f235bd3a689f03c11969cd649ccad592462ca958bc519a30194e7a67b349a40` + it("should get details for a single txid", async () => { + const txid = `2c7ae9f865f7ce0c33c189b2f83414176903ce4b06ed9f8b7bcf55efbd4a7266` req.params.txid = txid // Mock the Insight URL for unit tests. diff --git a/test/v3/util.js b/test/v3/util.js index 905157d..c1af49e 100644 --- a/test/v3/util.js +++ b/test/v3/util.js @@ -131,12 +131,12 @@ describe("#Util", () => { .reply(200, { result: mockData.mockAddress }) } - req.params.address = `bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y` + req.params.address = `bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd` const result = await validateAddress(req, res) //console.log(`result: ${util.inspect(result)}`) - assert.hasAllKeys(result, [ + assert.hasAnyKeys(result, [ "isvalid", "address", "scriptPubKey", @@ -206,7 +206,7 @@ describe("#Util", () => { it("should error on mainnet address when using testnet", async () => { req.body = { - addresses: [`bitcoincash:qrcc3jsqpgwqcdru70sk54sd0g3l04q7c53ycm6ucj`] + addresses: [`bchtest:qrls6vzjkkxlds7aqv9075u0fttwc7u9jvczn5fdt9`] } const result = await validateAddressBulk(req, res) @@ -227,7 +227,7 @@ describe("#Util", () => { process.env.RPC_BASEURL = "http://fakeurl/api/" req.body.addresses = [ - `bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y` + `bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd` ] const result = await validateAddressBulk(req, res) @@ -252,14 +252,14 @@ describe("#Util", () => { } req.body.addresses = [ - `bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y` + `bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd` ] const result = await validateAddressBulk(req, res) //console.log(`result: ${util.inspect(result)}`) assert.isArray(result) - assert.hasAllKeys(result[0], [ + assert.hasAnyKeys(result[0], [ "isvalid", "address", "scriptPubKey", @@ -279,15 +279,15 @@ describe("#Util", () => { } req.body.addresses = [ - `bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y`, - `bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y` + `bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd`, + `bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd` ] const result = await validateAddressBulk(req, res) //console.log(`result: ${util.inspect(result)}`) assert.isArray(result) - assert.hasAllKeys(result[0], [ + assert.hasAnyKeys(result[0], [ "isvalid", "address", "scriptPubKey", From 493d0174d421c9fbc23c9a091ed452cd1565bc1c Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 3 Oct 2019 18:29:04 -0700 Subject: [PATCH 8/8] Fixed unit tests --- src/routes/v3/slp.js | 2 ++ test/v3/blockbook.js | 26 +++++++++-------- test/v3/blockchain.js | 2 +- test/v3/mocks/blockbook-mock.js | 2 +- test/v3/mocks/blockchain-mock.js | 2 +- test/v3/mocks/slp-mocks.js | 2 +- test/v3/slp.js | 48 +++++++++++++++++--------------- 7 files changed, 47 insertions(+), 37 deletions(-) diff --git a/src/routes/v3/slp.js b/src/routes/v3/slp.js index 481eb76..c6eda94 100644 --- a/src/routes/v3/slp.js +++ b/src/routes/v3/slp.js @@ -400,6 +400,8 @@ async function lookupToken(tokenId) { const b64 = Buffer.from(s).toString("base64") const url = `${process.env.SLPDB_URL}q/${b64}` + // console.log(`url: ${url}`) + const tokenRes = await axios.get(url) //console.log(`tokenRes.data: ${util.inspect(tokenRes.data,null,2)}`) //console.log( diff --git a/test/v3/blockbook.js b/test/v3/blockbook.js index 213910e..60df68c 100644 --- a/test/v3/blockbook.js +++ b/test/v3/blockbook.js @@ -12,10 +12,20 @@ const chai = require("chai") const assert = chai.assert -const blockbookRoute = require("../../src/routes/v3/blockbook") const nock = require("nock") // HTTP mocking -let originalUrl // Used during transition from integration to unit tests. +let originalUrl, mockServerUrl // Used during transition from integration to unit tests. +originalUrl = process.env.BLOCKBOOK_URL + +// Set default environment variables for unit tests. +if (!process.env.TEST) process.env.TEST = "unit" +if (process.env.TEST === "unit") { + process.env.BLOCKBOOK_URL = "http://fakeurl/api/" + mockServerUrl = `http://fakeurl` +} + +// Only load blockbook library after setting BLOCKBOOK_URL env var. +const blockbookRoute = require("../../src/routes/v3/blockbook") // Mocking data. const { mockReq, mockRes } = require("./mocks/express-mocks") @@ -26,17 +36,9 @@ const util = require("util") util.inspect.defaultOptions = { depth: 1 } describe("#Blockbook Router", () => { - let req, res, mockServerUrl + let req, res before(() => { - originalUrl = process.env.BLOCKBOOK_URL - - // Set default environment variables for unit tests. - if (!process.env.TEST) process.env.TEST = "unit" - if (process.env.TEST === "unit") { - process.env.BLOCKBOOK_URL = "http://fakeurl/api/" - mockServerUrl = `http://fakeurl` - } // console.log(`Testing type is: ${process.env.TEST}`) if (!process.env.NETWORK) process.env.NETWORK = "testnet" @@ -150,6 +152,8 @@ describe("#Blockbook Router", () => { it("should get balance for a single address", async () => { req.params.address = `bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf` + // console.log(`process.env.BLOCKBOOK_URL: ${process.env.BLOCKBOOK_URL}`) + // Mock the Insight URL for unit tests. if (process.env.TEST === "unit") { nock(`${process.env.BLOCKBOOK_URL}`) diff --git a/test/v3/blockchain.js b/test/v3/blockchain.js index cd0cd58..c4b28b4 100644 --- a/test/v3/blockchain.js +++ b/test/v3/blockchain.js @@ -267,7 +267,7 @@ describe("#BlockchainRouter", () => { .post(``) .reply(200, { result: - "0000ff7f7d217c9b7845ea8b50d620c59a1bf7c276566406e9b7bc7e463e0000000000006d70322c0b697c1c81d2744f87f09f1e9780ba5d30338952e2cdc64e60456f8423bb0a5ceafa091a3e843526" + "000000202ed2723e7590e2b937f6821a99d6764cb8799bf30f8e300000000000000000001d311c02df9a1e3f57b8dbdcf97ec8dbc3109a26779724c63e560b29ad9ea501e2af955d286403183049e39c" }) } diff --git a/test/v3/mocks/blockbook-mock.js b/test/v3/mocks/blockbook-mock.js index 8246e80..d8a87db 100644 --- a/test/v3/mocks/blockbook-mock.js +++ b/test/v3/mocks/blockbook-mock.js @@ -8,7 +8,7 @@ const mockBalance = { page: 1, totalPages: 1, itemsOnPage: 1000, - address: "bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4", + address: "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", balance: "10000000", totalReceived: "10000000", totalSent: "0", diff --git a/test/v3/mocks/blockchain-mock.js b/test/v3/mocks/blockchain-mock.js index 6025583..527c9f7 100644 --- a/test/v3/mocks/blockchain-mock.js +++ b/test/v3/mocks/blockchain-mock.js @@ -218,7 +218,7 @@ const mockRawMempool = [ ] const mockBlockHeaderConcise = - "0000ff7f7d217c9b7845ea8b50d620c59a1bf7c276566406e9b7bc7e463e0000000000006d70322c0b697c1c81d2744f87f09f1e9780ba5d30338952e2cdc64e60456f8423bb0a5ceafa091a3e843526" + "000000202ed2723e7590e2b937f6821a99d6764cb8799bf30f8e300000000000000000001d311c02df9a1e3f57b8dbdcf97ec8dbc3109a26779724c63e560b29ad9ea501e2af955d286403183049e39c" const mockBlockHeader = { hash: "00000000000008c3679777df34f1a09565f98b2400a05b7c8da72525fdca3900", diff --git a/test/v3/mocks/slp-mocks.js b/test/v3/mocks/slp-mocks.js index ac4124c..fca6693 100644 --- a/test/v3/mocks/slp-mocks.js +++ b/test/v3/mocks/slp-mocks.js @@ -35,7 +35,7 @@ const mockSingleToken = { tokenDetails: { decimals: 0, tokenIdHex: - "af8e10dd87e7092e5f0f3b9cf62e85e91f74395fbf22cd14f12bcdfbf1e8354f", + "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0", timestamp: "2019-06-14 06:31:37", timestamp_unix: 1560493897, transactionType: "GENESIS", diff --git a/test/v3/slp.js b/test/v3/slp.js index 530047b..af0ba1c 100644 --- a/test/v3/slp.js +++ b/test/v3/slp.js @@ -16,14 +16,33 @@ const assert = chai.assert const nock = require("nock") // HTTP mocking const sinon = require("sinon") const proxyquire = require("proxyquire").noPreserveCache() +const axios = require("axios") + +// Save existing environment variables. +// Used during transition from integration to unit tests. +let originalEnvVars, mockServerUrl +originalEnvVars = { + BITDB_URL: process.env.BITDB_URL, + BITCOINCOM_BASEURL: process.env.BITCOINCOM_BASEURL, + SLPDB_URL: process.env.SLPDB_URL +} + +// Set default environment variables for unit tests. +if (!process.env.TEST) process.env.TEST = "unit" + +// Block network connections for unit tests. +if (process.env.TEST === "unit") { + process.env.BITDB_URL = "http://fakeurl/" + process.env.BITCOINCOM_BASEURL = "http://fakeurl/" + process.env.SLPDB_URL = "http://fakeurl/" + mockServerUrl = `http://fakeurl` +} // Prepare the slpRoute for stubbing dependcies on slpjs. const slpRoute = require("../../src/routes/v3/slp") const pathStub = {} // Used to stub methods within slpjs. const slpRouteStub = proxyquire("../../src/routes/v3/slp", { slpjs: pathStub }) -let originalEnvVars // Used during transition from integration to unit tests. - // Mocking data. const { mockReq, mockRes } = require("./mocks/express-mocks") const mockData = require("./mocks/slp-mocks") @@ -34,28 +53,10 @@ const util = require("util") util.inspect.defaultOptions = { depth: 1 } describe("#SLP", () => { - let req, res, mockServerUrl + let req, res let sandbox - before(() => { - // Save existing environment variables. - originalEnvVars = { - BITDB_URL: process.env.BITDB_URL, - BITCOINCOM_BASEURL: process.env.BITCOINCOM_BASEURL, - SLPDB_URL: process.env.SLPDB_URL - } - - // Set default environment variables for unit tests. - if (!process.env.TEST) process.env.TEST = "unit" - - // Block network connections for unit tests. - if (process.env.TEST === "unit") { - process.env.BITDB_URL = "http://fakeurl/" - process.env.BITCOINCOM_BASEURL = "http://fakeurl/" - process.env.SLPDB_URL = "http://fakeurl/" - mockServerUrl = `http://fakeurl` - } - }) + before(() => {}) // Setup the mocks before each test. beforeEach(() => { @@ -215,11 +216,14 @@ describe("#SLP", () => { const tokenIdToTest = "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0" + // console.log(`mockServerUrl: ${mockServerUrl}`) + // Mock the RPC call for unit tests. if (process.env.TEST === "unit") { nock(mockServerUrl) .get(uri => uri.includes("/")) .reply(200, mockData.mockSingleToken) + // sandbox.stub(axios, "get").resolves(mockData.mockSingleToken) } req.params.tokenId = tokenIdToTest