mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-22 09:02:01 -07:00
Compare commits
9
Commits
v4.18.1
...
grant/issue10
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bcbd7bfd8 | ||
|
|
788b07914e | ||
|
|
9aefdbf6be | ||
|
|
481c254061 | ||
|
|
bc62510b28 | ||
|
|
a71192257e | ||
|
|
0fd9f9ec89 | ||
|
|
97361b8edd | ||
|
|
263ee1b6e1 |
+84
-82
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
*/
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
@@ -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")
|
||||
}
|
||||
*/
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user