mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
Added first unit tests for blockbook
This commit is contained in:
+1
-3
@@ -193,9 +193,7 @@ io.on("connection", socket => {
|
||||
|
||||
if (process.env.ZEROMQ_URL && process.env.ZEROMQ_PORT) {
|
||||
console.log(
|
||||
`Connecting to BCH ZMQ at ${process.env.ZEROMQ_URL}:${
|
||||
process.env.ZEROMQ_PORT
|
||||
}`
|
||||
`Connecting to BCH ZMQ at ${process.env.ZEROMQ_URL}:${process.env.ZEROMQ_PORT}`
|
||||
)
|
||||
const bitcoincashZmqDecoder = new BitcoinCashZMQDecoder(process.env.NETWORK)
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ async function balanceFromBlockbook(thisAddress) {
|
||||
//console.log(`BITCORE_URL: ${BITCORE_URL}`)
|
||||
|
||||
// Convert the address to a cashaddr without a prefix.
|
||||
const addr = BITBOX.Address.toCashAddress(thisAddress, false)
|
||||
const addr = BITBOX.Address.toCashAddress(thisAddress)
|
||||
|
||||
// Determine if we are working with the testnet or mainnet networks.
|
||||
let network = "mainnet"
|
||||
@@ -107,6 +107,8 @@ async function balanceSingle(req, res, next) {
|
||||
res.status(200)
|
||||
return res.json(retData)
|
||||
} catch (err) {
|
||||
console.log(`err: ${JSON.stringify(err, null, 2)}`)
|
||||
|
||||
// Attempt to decode the error message.
|
||||
const { msg, status } = routeUtils.decodeError(err)
|
||||
if (msg) {
|
||||
|
||||
+16
-6
@@ -19,7 +19,7 @@ let originalUrl // Used during transition from integration to unit tests.
|
||||
|
||||
// Mocking data.
|
||||
const { mockReq, mockRes } = require("./mocks/express-mocks")
|
||||
const mockData = require("./mocks/bitcore-mock")
|
||||
const mockData = require("./mocks/blockbook-mock")
|
||||
|
||||
// Used for debugging.
|
||||
const util = require("util")
|
||||
@@ -157,12 +157,22 @@ describe("#Blockbook Router", () => {
|
||||
|
||||
// Call the details API.
|
||||
const result = await balanceSingle(req, res)
|
||||
//console.log(`result: ${util.inspect(result)}`)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.hasAllKeys(result, ["confirmed", "unconfirmed", "balance"])
|
||||
assert.isNumber(result.confirmed)
|
||||
assert.isNumber(result.unconfirmed)
|
||||
assert.isNumber(result.balance)
|
||||
assert.hasAnyKeys(result, [
|
||||
"page",
|
||||
"totalPages",
|
||||
"itemsOnPage",
|
||||
"address",
|
||||
"balance",
|
||||
"totalReceived",
|
||||
"totalSent",
|
||||
"unconfirmedBalance",
|
||||
"unconfirmedTxs",
|
||||
"txs",
|
||||
"txids"
|
||||
])
|
||||
assert.isArray(result.txids)
|
||||
})
|
||||
})
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
This library contains mocking data for running unit tests on the blockbook route.
|
||||
*/
|
||||
|
||||
"use strict"
|
||||
|
||||
const mockBalance = {
|
||||
page: 1,
|
||||
totalPages: 1,
|
||||
itemsOnPage: 1000,
|
||||
address: "bchtest:qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4",
|
||||
balance: "10000000",
|
||||
totalReceived: "10000000",
|
||||
totalSent: "0",
|
||||
unconfirmedBalance: "0",
|
||||
unconfirmedTxs: 0,
|
||||
txs: 1,
|
||||
txids: ["5fe9b74056319a8c87f45cc745030715a6180758b94938dbf90d639d55652392"]
|
||||
}
|
||||
|
||||
const mockUtxos = [
|
||||
{
|
||||
_id: "5cf2c31a33bd46a95ec7e730",
|
||||
chain: "BCH",
|
||||
network: "testnet",
|
||||
coinbase: false,
|
||||
mintIndex: 1,
|
||||
spentTxid: "",
|
||||
mintTxid:
|
||||
"5fe9b74056319a8c87f45cc745030715a6180758b94938dbf90d639d55652392",
|
||||
mintHeight: 1265275,
|
||||
spentHeight: -2,
|
||||
address: "qq89kjkeqz9mngp8kl3dpmu43y2wztdjqu500gn4c4",
|
||||
script: "76a9140e5b4ad9008bb9a027b7e2d0ef958914e12db20788ac",
|
||||
value: 10000000,
|
||||
confirmations: -1
|
||||
}
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
mockBalance,
|
||||
mockUtxos
|
||||
}
|
||||
Reference in New Issue
Block a user