Compare commits

...
12 Commits
14 changed files with 548 additions and 120 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ class BCHJS {
// Generate a Basic Authentication token from an auth password
this.authToken = ""
if (this.authPass) {
console.log(`bch-js initialized with authPass: ${this.authPass}`)
// console.log(`bch-js initialized with authPass: ${this.authPass}`)
// Generate the header for Basic Authentication.
const combined = `fullstackcash:${this.authPass}`
var base64Credential = Buffer.from(combined).toString("base64")
+84 -82
View File
@@ -68,34 +68,10 @@ class Ninsight {
*/
async utxo(address) {
try {
// Handle single address.
if (typeof address === "string") {
const response = await axios.post(
`${this.ninsightURL}/address/utxo`,
{
addresses: [address]
},
_this.axiosOptions
)
return response.data
// Handle array of addresses.
} else if (Array.isArray(address)) {
const response = await axios.post(
`${this.ninsightURL}/address/utxo`,
{
addresses: address
},
_this.axiosOptions
)
return response.data
}
throw new Error(`Input address must be a string or array of strings.`)
} catch (error) {
if (error.response && error.response.data) throw error.response.data
else throw error
_this._validateParam(address)
return _this._callAxios(address, 'utxo')
} catch (e) {
_this._handleError(e)
}
}
@@ -137,32 +113,10 @@ class Ninsight {
*/
async unconfirmed(address) {
try {
if (typeof address === "string") {
const response = await axios.post(
`${this.ninsightURL}/address/unconfirmed`,
{
addresses: [address]
},
_this.axiosOptions
)
return response.data
} else if (Array.isArray(address)) {
const response = await axios.post(
`${this.ninsightURL}/address/unconfirmed`,
{
addresses: address
},
_this.axiosOptions
)
return response.data
}
throw new Error(`Input address must be a string or array of strings.`)
} catch (error) {
if (error.response && error.response.data) throw error.response.data
else throw error
_this._validateParam(address)
return _this._callAxios(address, 'unconfirmed')
} catch (e) {
_this._handleError(e)
}
}
@@ -213,32 +167,10 @@ class Ninsight {
*/
async transactions(address) {
try {
if (typeof address === "string") {
const response = await axios.post(
`${this.ninsightURL}/address/transactions`,
{
addresses: [address]
},
_this.axiosOptions
)
return response.data
} else if (Array.isArray(address)) {
const response = await axios.post(
`${this.ninsightURL}/address/transactions`,
{
addresses: address
},
_this.axiosOptions
)
return response.data
}
throw new Error(`Input address must be a string or array of strings.`)
} catch (error) {
if (error.response && error.response.data) throw error.response.data
else throw error
_this._validateParam(address)
return _this._callAxios(address, 'transactions')
} catch (e) {
_this._handleError(e)
}
}
@@ -288,7 +220,7 @@ class Ninsight {
try {
if (typeof txid === "string") {
const response = await axios.post(
`${this.ninsightURL}/transaction/details`,
`${_this.ninsightURL}/transaction/details`,
{
txids: [txid]
},
@@ -298,7 +230,7 @@ class Ninsight {
return response.data
} else if (Array.isArray(txid)) {
const response = await axios.post(
`${this.ninsightURL}/transaction/details`,
`${_this.ninsightURL}/transaction/details`,
{
txids: txid
},
@@ -314,6 +246,76 @@ class Ninsight {
else throw error
}
}
/**
* @api Ninsight.details() details()
* @apiName Ninsight Details
* @apiGroup Ninsight
* @apiDescription Return details of address.
*
* @apiExample Example usage:
* (async () => {
* try {
* let details = await bchjs.Ninsight.details('bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c');
* let details = await bchjs.Ninsight.details(['bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c','bitcoincash:qzs02v05l7qs5s24srqju498qu55dwuj0cx5ehjm2c']);
* console.log(details);
* } catch(error) {
* console.error(error)
* }
* })()
*
* // [
* // {
* //"balance": 0.00001,
* //"balanceSat": 1000,
* //"totalReceived": 0.00001,
* //"totalReceivedSat": 1000,
* //"totalSent": 0,
* //"totalSentSat": 0,
* //"unconfirmedBalance": 0,
* //"unconfirmedBalanceSat": 0,
* //"unconfirmedTxApperances": 0,
* //"txApperances": 1,
* //"transactions": [
* //"5f09d317e24c5d376f737a2711f3bd1d381abdb41743fff3819b4f76382e1eac" ],
* //"legacyAddress": "1FZrK8HohEKyKCTM24NkAzPnX9WD9Ujhw7",
* //"cashAddress": "bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr",
* //"slpAddress": "simpleledger:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ylynt40sa",
* //"currentPage": 0,
* //"pagesTotal": 1
* // }
* // ]
*
*/
async details(address) {
try {
_this._validateParam(address)
return _this._callAxios(address, 'details')
} catch (e) {
_this._handleError(e)
}
}
_validateParam(address) {
if (typeof address !== "string" && !Array.isArray(address))
throw new Error(`Input address must be a string or array of strings.`)
}
_handleError(error) {
if (error.response && error.response.data) throw error.response.data
else throw error
}
async _callAxios(address, type) {
const response = await axios.post(
`${_this.ninsightURL}/address/${type}`,
{
addresses: Array.isArray(address) ? address : [address]
},
_this.axiosOptions
)
//console.log(`SAMPLE: ${response.data}`);
return response.data
}
}
module.exports = Ninsight
+2 -6
View File
@@ -272,9 +272,7 @@ class RawTransactions {
txids: txid,
verbose: verbose
},
headers: {
authorization: `Token ${this.apiToken}`
}
headers: _this.axiosOptions.headers
}
const response = await axios(options)
@@ -347,9 +345,7 @@ class RawTransactions {
data: {
hexes: hex
},
headers: {
authorization: `Token ${this.apiToken}`
}
headers: _this.axiosOptions.headers
}
const response = await axios(options)
+17 -6
View File
@@ -18,17 +18,28 @@ class TokenType1 {
constructor(config) {
this.restURL = config.restURL
this.apiToken = config.apiToken
this.authToken = config.authToken
if (this.authToken) {
// Add Basic Authentication token to the authorization header.
this.axiosOptions = {
headers: {
authorization: this.authToken
}
}
} else {
// Add JWT token to the authorization header.
this.axiosOptions = {
headers: {
authorization: `Token ${this.apiToken}`
}
}
}
addy = new Address(config)
this.Script = new Script()
this.axios = axios
// Add JWT token to the authorization header.
this.axiosOptions = {
headers: {
authorization: `Token ${this.apiToken}`
}
}
// Instantiate the transaction builder.
TransactionBuilder.setAddress(addy)
+14 -4
View File
@@ -13,11 +13,21 @@ class Utils {
this.restURL = config.restURL
this.apiToken = config.apiToken
this.slpParser = slpParser
this.authToken = config.authToken
// Add JWT token to the authorization header.
this.axiosOptions = {
headers: {
authorization: `Token ${this.apiToken}`
if (this.authToken) {
// Add Basic Authentication token to the authorization header.
this.axiosOptions = {
headers: {
authorization: this.authToken
}
}
} else {
// Add JWT token to the authorization header.
this.axiosOptions = {
headers: {
authorization: `Token ${this.apiToken}`
}
}
}
@@ -15,7 +15,8 @@
const assert = require("chai").assert
// const RESTURL = `https://abc.fullstack.cash/v3/`
const RESTURL = `http://localhost:3000/v3/`
const RESTURL = `https://bchn.fullstack.cash/v3/`
// const RESTURL = `http://localhost:3000/v3/`
const BCHJS = require("../../../src/bch-js")
const bchjs = new BCHJS({ restURL: RESTURL })
@@ -29,7 +30,7 @@ describe("#anonymous rate limits", () => {
it("should allow an anonymous call to an indexer", async () => {
const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf"
const result = await bchjs.Blockbook.balance(addr)
const result = await bchjs.Electrumx.balance(addr)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, "balance")
@@ -13,12 +13,13 @@ const PRO_PASS = "testpassword"
const BCHJS = require("../../../src/bch-js")
const bchjs = new BCHJS({
// restURL: `https://api.fullstack.cash/v3/`,
restURL: `http://localhost:3000/v3/`,
// restURL: `https://bchn.fullstack.cash/v3/`,
restURL: `https://abc.fullstack.cash/v3/`,
// restURL: `http://localhost:3000/v3/`,
authPass: PRO_PASS
})
describe("#full node rate limits", () => {
describe("#Basic Authentication rate limits", () => {
it("should allow more than 20 RPM to full node", async () => {
for (let i = 0; i < 22; i++) {
const result = await bchjs.Control.getNetworkInfo()
@@ -18,7 +18,8 @@ const JWT_TOKEN =
const BCHJS = require("../../../src/bch-js")
const bchjs = new BCHJS({
restURL: `https://api.fullstack.cash/v3/`,
// restURL: `https://bchn.fullstack.cash/v3/`,
restURL: `https:/abc.fullstack.cash/v3/`,
// restURL: `http://localhost:3000/v3/`,
apiToken: JWT_TOKEN
})
@@ -26,7 +27,7 @@ const bchjs = new BCHJS({
describe("#full node rate limits", () => {
it("should allow an free call to an indexer", async () => {
const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf"
const result = await bchjs.Blockbook.balance(addr)
const result = await bchjs.Electrumx.balance(addr)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result, "balance")
+4 -3
View File
@@ -14,12 +14,13 @@ const JWT_TOKEN =
const BCHJS = require("../../../src/bch-js")
const bchjs = new BCHJS({
restURL: `https://api.fullstack.cash/v3/`,
// restURL: `https://bchn.fullstack.cash/v3/`,
restURL: `https://abc.fullstack.cash/v3/`,
// restURL: `http://localhost:3000/v3/`,
apiToken: JWT_TOKEN
})
describe("#full node rate limits", () => {
describe("#Indexer rate limits", () => {
it("should allow more than 20 RPM to full node", async () => {
for (let i = 0; i < 22; i++) {
const result = await bchjs.Control.getNetworkInfo()
@@ -40,7 +41,7 @@ describe("#full node rate limits", () => {
const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf"
for (let i = 0; i < 22; i++) {
const result = await bchjs.Blockbook.balance(addr)
const result = await bchjs.Electrumx.balance(addr)
if (i === 5) {
// console.log(`validating 5th call: ${i}`)
+87
View File
@@ -126,4 +126,91 @@ describe(`#Ninsight`, () => {
assert.property(result[0], "vout")
})
})
describe(`#detailsAddress`, () => {
it(`should throw an error for improper input`, async () => {
try {
const addr = 12345
await bchjs.Ninsight.details(addr)
assert.equal(true, false, "Unexpected result!")
} catch (err) {
//console.log(`err: `, err)
assert.include(
err.message,
`Input address must be a string or array of strings.`
)
}
})
it(`should POST address details for a single address`, async () => {
const addr = "bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7"
const result = await bchjs.Ninsight.details(addr)
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.property(result[0], "balance")
assert.property(result[0], "balanceSat")
assert.property(result[0], "totalReceived")
assert.property(result[0], "totalReceivedSat")
assert.property(result[0], "totalSent")
assert.property(result[0], "totalSentSat")
assert.property(result[0], "unconfirmedBalance")
assert.property(result[0], "unconfirmedBalanceSat")
assert.property(result[0], "unconfirmedTxApperances")
assert.property(result[0], "txApperances")
assert.property(result[0], "transactions")
assert.property(result[0], "legacyAddress")
assert.property(result[0], "cashAddress")
assert.property(result[0], "slpAddress")
assert.property(result[0], "currentPage")
assert.property(result[0], "pagesTotal")
})
it(`should POST address details for an array of addresses`, async () => {
const addr = [
"bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7",
"bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr"
]
const result = await bchjs.Ninsight.details(addr)
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.property(result[0], "balance")
assert.property(result[0], "balanceSat")
assert.property(result[0], "totalReceived")
assert.property(result[0], "totalReceivedSat")
assert.property(result[0], "totalSent")
assert.property(result[0], "totalSentSat")
assert.property(result[0], "unconfirmedBalance")
assert.property(result[0], "unconfirmedBalanceSat")
assert.property(result[0], "unconfirmedTxApperances")
assert.property(result[0], "txApperances")
assert.property(result[0], "transactions")
assert.property(result[0], "legacyAddress")
assert.property(result[1], "cashAddress")
assert.property(result[1], "slpAddress")
assert.property(result[1], "currentPage")
assert.property(result[1], "pagesTotal")
/*
If in any way possible, I would like to refactor this test
according to the DRY principle to share it with the integration tests too
Would that make sense or does that implicate anything unwanted?
assertDetails(result[0])
assertDetails(data) {
assert.property(data, "balance")
assert.property(data, "balanceSat")
assert.property(data, "totalReceived")
assert.property(data, "totalReceivedSat")
assert.property(data, "totalSent")
assert.property(data, "totalSentSat")
}
*/
})
})
})
+88 -1
View File
@@ -3,7 +3,9 @@ const assert = chai.assert
const sinon = require("sinon")
const BCHJS = require("../../src/bch-js")
const bchjs = new BCHJS({ ninsightURL: "https://rest.bitcoin.com/v2" })
const bchjs = new BCHJS({
ninsightURL: "https://rest.bitcoin.com/v2"
})
describe(`#Ninsight`, () => {
let sandbox
@@ -131,6 +133,91 @@ describe(`#Ninsight`, () => {
assert.property(result[0], "vout")
})
})
describe(`#detailsAddress`, () => {
it(`should throw an error for improper input`, async () => {
try {
const addr = 12345
await bchjs.Ninsight.details(addr)
assert.equal(true, false, "Unexpected result!")
} catch (err) {
//console.log(`err: `, err)
assert.include(
err.message,
`Input address must be a string or array of strings.`
)
}
})
it(`should POST address details for a single address`, async () => {
const addr = "bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7"
const result = await bchjs.Ninsight.details(addr)
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.property(result[0], "balance")
assert.property(result[0], "balanceSat")
assert.property(result[0], "totalReceived")
assert.property(result[0], "totalReceivedSat")
assert.property(result[0], "totalSent")
assert.property(result[0], "totalSentSat")
assert.property(result[0], "unconfirmedBalance")
assert.property(result[0], "unconfirmedBalanceSat")
assert.property(result[0], "unconfirmedTxApperances")
assert.property(result[0], "txApperances")
assert.property(result[0], "transactions")
assert.property(result[0], "legacyAddress")
assert.property(result[0], "cashAddress")
assert.property(result[0], "slpAddress")
assert.property(result[0], "currentPage")
assert.property(result[0], "pagesTotal")
})
it(`should POST address details for an array of addresses`, async () => {
const addr = [
"bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7",
"bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr"
]
const result = await bchjs.Ninsight.details(addr)
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.property(result[0], "balance")
assert.property(result[0], "balanceSat")
assert.property(result[0], "totalReceived")
assert.property(result[0], "totalReceivedSat")
assert.property(result[0], "totalSent")
assert.property(result[0], "totalSentSat")
assert.property(result[0], "unconfirmedBalance")
assert.property(result[0], "unconfirmedBalanceSat")
assert.property(result[0], "unconfirmedTxApperances")
assert.property(result[0], "txApperances")
assert.property(result[0], "transactions")
assert.property(result[0], "legacyAddress")
assert.property(result[1], "cashAddress")
assert.property(result[1], "slpAddress")
assert.property(result[1], "currentPage")
assert.property(result[1], "pagesTotal")
/*
If in any way possible, I would like to refactor this test
according to the DRY principle to share it with the integration tests too
Would that make sense or does that implicate anything unwanted?
assertDetails(result[0])
assertDetails(data) {
assert.property(data, "balance")
assert.property(data, "balanceSat")
assert.property(data, "totalReceived")
assert.property(data, "totalReceivedSat")
assert.property(data, "totalSent")
assert.property(data, "totalSentSat")
}
*/
})
})
})
function sleep(ms) {
+89 -1
View File
@@ -3,7 +3,9 @@ const assert = chai.assert
const sinon = require("sinon")
const BCHJS = require("../../../src/bch-js")
const bchjs = new BCHJS({ ninsightURL: "https://trest.bitcoin.com/v2" })
const bchjs = new BCHJS({
ninsightURL: "https://trest.bitcoin.com/v2"
})
describe(`#Ninsight`, () => {
let sandbox
@@ -139,6 +141,92 @@ describe(`#Ninsight`, () => {
assert.property(result[0], "vout")
})
})
describe(`#detailsAddress`, () => {
it(`should throw an error for improper input`, async () => {
try {
const addr = 12345
await bchjs.Ninsight.details(addr)
assert.equal(true, false, "Unexpected result!")
} catch (err) {
//console.log(`err: `, err)
assert.include(
err.message,
`Input address must be a string or array of strings.`
)
}
})
it(`should POST address details for a single address`, async () => {
const addr = "bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr"
const result = await bchjs.Ninsight.details(addr)
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.property(result[0], "balance")
assert.property(result[0], "balanceSat")
assert.property(result[0], "totalReceived")
assert.property(result[0], "totalReceivedSat")
assert.property(result[0], "totalSent")
assert.property(result[0], "totalSentSat")
assert.property(result[0], "unconfirmedBalance")
assert.property(result[0], "unconfirmedBalanceSat")
assert.property(result[0], "unconfirmedTxApperances")
assert.property(result[0], "txApperances")
assert.property(result[0], "transactions")
assert.property(result[0], "legacyAddress")
assert.property(result[0], "cashAddress")
assert.property(result[0], "slpAddress")
assert.property(result[0], "currentPage")
assert.property(result[0], "pagesTotal")
})
it(`should POST address details for an array of addresses`, async () => {
const addr = [
"bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr",
"bchtest:qp6hgvevf4gzz6l7pgcte3gaaud9km0l459fa23dul"
]
const result = await bchjs.Ninsight.details(addr)
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.property(result[0], "balance")
assert.property(result[0], "balanceSat")
assert.property(result[0], "totalReceived")
assert.property(result[0], "totalReceivedSat")
assert.property(result[0], "totalSent")
assert.property(result[0], "totalSentSat")
assert.property(result[0], "unconfirmedBalance")
assert.property(result[0], "unconfirmedBalanceSat")
assert.property(result[0], "unconfirmedTxApperances")
assert.property(result[0], "txApperances")
assert.property(result[0], "transactions")
assert.property(result[0], "legacyAddress")
assert.property(result[1], "cashAddress")
assert.property(result[1], "slpAddress")
assert.property(result[1], "currentPage")
assert.property(result[1], "pagesTotal")
/*
If in any way possible, I would like to refactor this test
according to the DRY principle to share it with the integration tests too
Would that make sense or does that implicate anything unwanted?
assertDetails(result[0])
assertDetails(data) {
assert.property(data, "balance")
assert.property(data, "balanceSat")
assert.property(data, "totalReceived")
assert.property(data, "totalReceivedSat")
assert.property(data, "totalSent")
assert.property(data, "totalSentSat")
}
*/
})
})
})
function sleep(ms) {
+27 -1
View File
@@ -158,6 +158,30 @@ const details = {
const detailsPost = [details, details]
const addrDetail =
{
"balance": 0.00001,
"balanceSat": 1000,
"totalReceived": 0.00001,
"totalReceivedSat": 1000,
"totalSent": 0,
"totalSentSat": 0,
"unconfirmedBalance": 0,
"unconfirmedBalanceSat": 0,
"unconfirmedTxApperances": 0,
"txApperances": 1,
"transactions": [
"5f09d317e24c5d376f737a2711f3bd1d381abdb41743fff3819b4f76382e1eac"
],
"legacyAddress": "1FZrK8HohEKyKCTM24NkAzPnX9WD9Ujhw7",
"cashAddress": "bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr",
"slpAddress": "simpleledger:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ylynt40sa",
"currentPage": 0,
"pagesTotal": 1
}
const addrDetailArray = [addrDetail, addrDetail]
module.exports = {
utxo,
utxoPost,
@@ -166,5 +190,7 @@ module.exports = {
transactions,
transactionsPost,
details,
detailsPost
detailsPost,
addrDetail,
addrDetailArray
}
+125 -8
View File
@@ -31,7 +31,9 @@ describe(`#Ninsight`, () => {
it(`should GET utxos for a single address`, async () => {
// Stub the network call.
sandbox.stub(axios, "post").resolves({ data: mockData.utxo })
sandbox.stub(axios, "post").resolves({
data: mockData.utxo
})
const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9"
@@ -57,7 +59,9 @@ describe(`#Ninsight`, () => {
it(`should POST utxo details for an array of addresses`, async () => {
// Mock the network call.
sandbox.stub(axios, "post").resolves({ data: mockData.utxoPost })
sandbox.stub(axios, "post").resolves({
data: mockData.utxoPost
})
const addr = [
"bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7",
@@ -96,7 +100,9 @@ describe(`#Ninsight`, () => {
it(`should POST utxos for a single address`, async () => {
// Stub the network call.
sandbox.stub(axios, "post").resolves({ data: mockData.unconfirmed })
sandbox.stub(axios, "post").resolves({
data: mockData.unconfirmed
})
const addr = "bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5"
@@ -121,7 +127,9 @@ describe(`#Ninsight`, () => {
it(`should POST utxo details for an array of addresses`, async () => {
// Mock the network call.
sandbox.stub(axios, "post").resolves({ data: mockData.unconfirmedPost })
sandbox.stub(axios, "post").resolves({
data: mockData.unconfirmedPost
})
const addr = [
"bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5",
@@ -159,7 +167,9 @@ describe(`#Ninsight`, () => {
})
it(`should POST transaction history for a single address`, async () => {
// Stub the network call.
sandbox.stub(axios, "post").resolves({ data: mockData.transactionsPost })
sandbox.stub(axios, "post").resolves({
data: mockData.transactionsPost
})
const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9"
@@ -177,7 +187,9 @@ describe(`#Ninsight`, () => {
})
it(`should POST transaction history for an array of addresses`, async () => {
// Mock the network call.
sandbox.stub(axios, "post").resolves({ data: mockData.transactionsPost })
sandbox.stub(axios, "post").resolves({
data: mockData.transactionsPost
})
const addr = [
"bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7",
@@ -212,7 +224,9 @@ describe(`#Ninsight`, () => {
})
it(`should POST transaction details for a single TxID`, async () => {
// Stub the network call.
sandbox.stub(axios, "post").resolves({ data: mockData.detailsPost })
sandbox.stub(axios, "post").resolves({
data: mockData.detailsPost
})
const txid = "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33"
@@ -236,7 +250,9 @@ describe(`#Ninsight`, () => {
})
it(`should POST transaction details for an array of TxIDs`, async () => {
// Stub the network call.
sandbox.stub(axios, "post").resolves({ data: mockData.detailsPost })
sandbox.stub(axios, "post").resolves({
data: mockData.detailsPost
})
const txid = [
"fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
@@ -252,4 +268,105 @@ describe(`#Ninsight`, () => {
assert.property(result[0], "vout")
})
})
describe(`#addrDetails`, () => {
it(`should throw an error for improper input`, async () => {
try {
const addr = 12345
await bchjs.Ninsight.details(addr)
assert.equal(true, false, "Unexpected result!")
} catch (err) {
//console.log(`err: `, err)
assert.include(
err.message,
`Input address must be a string or array of strings.`
)
}
})
it(`should POST address details for a single address`, async () => {
// Stub the network call.
sandbox.stub(axios, "post").resolves({
data: mockData.addrDetailArray
})
const result = await bchjs.Ninsight.details("addr")
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.property(result[0], "balance")
assert.property(result[0], "balanceSat")
assert.property(result[0], "totalReceived")
assert.property(result[0], "totalReceivedSat")
assert.property(result[0], "totalSent")
assert.property(result[0], "totalSentSat")
assert.property(result[0], "unconfirmedBalance")
assert.property(result[0], "unconfirmedBalanceSat")
assert.property(result[0], "unconfirmedTxApperances")
assert.property(result[0], "txApperances")
assert.property(result[0], "transactions")
assert.property(result[0], "legacyAddress")
assert.property(result[0], "cashAddress")
assert.property(result[0], "slpAddress")
assert.property(result[0], "currentPage")
assert.property(result[0], "pagesTotal")
})
it(`should call constructor with null args`, async () => {
new bchjs.Ninsight.constructor({})
})
it(`should POST address details for an array of addresses`, async () => {
// Mock the network call.
sandbox.stub(axios, "post").resolves({
data: mockData.addrDetailArray
})
const addr = [
"bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7",
"bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr"
]
const result = await bchjs.Ninsight.details(addr)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.property(result[0], "balance")
assert.property(result[0], "balanceSat")
assert.property(result[0], "totalReceived")
assert.property(result[0], "totalReceivedSat")
assert.property(result[0], "totalSent")
assert.property(result[0], "totalSentSat")
assert.property(result[0], "unconfirmedBalance")
assert.property(result[0], "unconfirmedBalanceSat")
assert.property(result[0], "unconfirmedTxApperances")
assert.property(result[0], "txApperances")
assert.property(result[0], "transactions")
assert.property(result[0], "legacyAddress")
assert.property(result[1], "cashAddress")
assert.property(result[1], "slpAddress")
assert.property(result[1], "currentPage")
assert.property(result[1], "pagesTotal")
/*
If in any way possible, I would like to refactor this test
according to the DRY principle to share it with the integration tests too
Would that make sense or does that implicate anything unwanted?
assertDetails(result[0])
assertDetails(data) {
assert.property(data, "satoshis")
assert.property(data, "height")
assert.property(data, "confirmations")
assert.property(data, "timestamp")
assert.property(data, "fees")
assert.property(data, "outputIndexes")
assert.property(data, "inputIndexes")
assert.property(data, "tx")
}
*/
})
})
})