Compare commits

..
Author SHA1 Message Date
Chris Troutner b8e22e1c99 Merge pull request #58 from Permissionless-Software-Foundation/ct-unstable
fix(price): Adding BCHA price
2020-11-17 14:47:47 -08:00
Chris Troutner 72d560e407 fix(price): Adding BCHA price 2020-11-17 14:41:04 -08:00
11 changed files with 159 additions and 502 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
"test:integration:local": "RESTURL=http://localhost:3000/v3/ mocha --timeout 30000 test/integration",
"test:integration:local:bchn": "RESTURL=http://localhost:3000/v3/ bash test/integration/test-free-tier-bchn.sh",
"test:integration:local:testnet": "RESTURL=http://localhost:4000/v3/ mocha --timeout 30000 test/integration/testnet",
"test:temp": "mocha --timeout 30000 -g '#Encryption' test/integration/",
"test:temp": "RESTURL=http://localhost:3000/v3/ mocha --timeout 30000 -g '#price' test/integration/",
"test:integration:api": "RESTURL=https://api.fullstack.cash/v3/ mocha --timeout 30000 test/integration",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/",
+82 -84
View File
@@ -68,10 +68,34 @@ class Ninsight {
*/
async utxo(address) {
try {
_this._validateParam(address)
return _this._callAxios(address, 'utxo')
} catch (e) {
_this._handleError(e)
// 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
}
}
@@ -113,10 +137,32 @@ class Ninsight {
*/
async unconfirmed(address) {
try {
_this._validateParam(address)
return _this._callAxios(address, 'unconfirmed')
} catch (e) {
_this._handleError(e)
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
}
}
@@ -167,10 +213,32 @@ class Ninsight {
*/
async transactions(address) {
try {
_this._validateParam(address)
return _this._callAxios(address, 'transactions')
} catch (e) {
_this._handleError(e)
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
}
}
@@ -220,7 +288,7 @@ class Ninsight {
try {
if (typeof txid === "string") {
const response = await axios.post(
`${_this.ninsightURL}/transaction/details`,
`${this.ninsightURL}/transaction/details`,
{
txids: [txid]
},
@@ -230,7 +298,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
},
@@ -246,76 +314,6 @@ 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
+35
View File
@@ -140,6 +140,41 @@ class Price {
else throw err
}
}
/**
* @api price.getBchaUsd() getBchaUsd()
* @apiName Price getBchaUsd()
* @apiGroup Price
* @apiDescription Return current price of BCHA in USD.
* This endpoint gets the USD price of BCHA from the Coinex API. The price
* comes from bch-api, so it has a better chance of working in Tor.
*
* @apiExample Example usage:
*(async () => {
* try {
* let current = await bchjs.Price.getBchaUsd();
* console.log(current);
* } catch(err) {
* console.err(err)
* }
*})()
*
* // 18.81
*/
async getBchaUsd() {
try {
const response = await this.axios.get(
`${this.restURL}price/bchausd`,
_this.axiosOptions
)
// console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
return response.data.usd
} catch (err) {
if (err.response && err.response.data) throw err.response.data
else throw err
}
}
}
module.exports = Price
-87
View File
@@ -126,91 +126,4 @@ 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")
}
*/
})
})
})
+9
View File
@@ -21,6 +21,15 @@ describe("#price", () => {
})
})
describe("#getBchaUsd", () => {
it("should get the USD price of BCHA", async () => {
const result = await bchjs.Price.getBchaUsd()
console.log(result)
assert.isNumber(result)
})
})
describe("#rates", () => {
it("should get the price of BCH in several currencies", async () => {
const result = await bchjs.Price.rates()
+1 -88
View File
@@ -3,9 +3,7 @@ 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
@@ -133,91 +131,6 @@ 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) {
+9
View File
@@ -25,6 +25,15 @@ describe("#price", () => {
})
})
describe("#getBchaUsd", () => {
it("should get the USD price of BCHA", async () => {
const result = await bchjs.Price.getBchaUsd()
console.log(result)
assert.isNumber(result)
})
})
describe("#rates", () => {
it("should get the price of BCH in several currencies", async () => {
const result = await bchjs.Price.rates()
+1 -89
View File
@@ -3,9 +3,7 @@ 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
@@ -141,92 +139,6 @@ 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) {
+1 -27
View File
@@ -158,30 +158,6 @@ 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,
@@ -190,7 +166,5 @@ module.exports = {
transactions,
transactionsPost,
details,
detailsPost,
addrDetail,
addrDetailArray
detailsPost
}
+8 -125
View File
@@ -31,9 +31,7 @@ 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"
@@ -59,9 +57,7 @@ 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",
@@ -100,9 +96,7 @@ 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"
@@ -127,9 +121,7 @@ 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",
@@ -167,9 +159,7 @@ 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"
@@ -187,9 +177,7 @@ 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",
@@ -224,9 +212,7 @@ 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"
@@ -250,9 +236,7 @@ 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",
@@ -268,105 +252,4 @@ 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")
}
*/
})
})
})
+12 -1
View File
@@ -5,7 +5,7 @@ const sinon = require("sinon")
const mockDataLib = require("./fixtures/price-mocks")
let mockData
describe("#Price", () => {
describe("#price", () => {
let sandbox
let bchjs
@@ -56,4 +56,15 @@ describe("#Price", () => {
assert.property(result, "CAD")
})
})
describe("#getBchaUsd", () => {
it("should get the USD price of BCHA", async () => {
sandbox.stub(bchjs.Price.axios, "get").resolves({ data: { usd: 18.87 } })
const result = await bchjs.Price.getBchaUsd()
// console.log(result)
assert.isNumber(result)
})
})
})