mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 17:22:04 -07:00
fix(control/getnetworkinfo): Added getnetworkinfo endpoint
This commit is contained in:
@@ -137,4 +137,57 @@ describe("#ControlRouter", () => {
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("#GetNetworkInfo", () => {
|
||||
const getNetworkInfo = controlRoute.testableComponents.getNetworkInfo
|
||||
|
||||
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 getNetworkInfo(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.mockGetNetworkInfo })
|
||||
}
|
||||
|
||||
const result = await getNetworkInfo(req, res)
|
||||
//console.log(`result: ${util.inspect(result)}`)
|
||||
|
||||
assert.hasAnyKeys(result, [
|
||||
"version",
|
||||
"subversion",
|
||||
"protocolversion",
|
||||
"localservices",
|
||||
"localrelay",
|
||||
"timeoffset",
|
||||
"networkactive",
|
||||
"connections",
|
||||
"networks",
|
||||
"relayfee",
|
||||
"excessutxocharge",
|
||||
"localaddresses",
|
||||
"warnings"
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -22,6 +22,24 @@ const mockGetInfo = {
|
||||
errors: "Warning: unknown new rules activated (versionbit 28)"
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mockGetInfo
|
||||
const mockGetNetworkInfo = {
|
||||
version: 190700,
|
||||
subversion: "/Bitcoin ABC:0.19.7(EB32.0)/",
|
||||
protocolversion: 70015,
|
||||
localservices: "0000000000000425",
|
||||
localrelay: true,
|
||||
timeoffset: 0,
|
||||
networkactive: true,
|
||||
connections: 23,
|
||||
networks: [{}, {}, {}],
|
||||
relayfee: 0.00001,
|
||||
excessutxocharge: 0,
|
||||
localaddresses: [],
|
||||
warnings:
|
||||
"Warning: Unknown block versions being mined! It's possible unknown rules are in effect"
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mockGetInfo,
|
||||
mockGetNetworkInfo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user