mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 17:22:04 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e96b9e7a44 | ||
|
|
d29f99965f | ||
|
|
9825ec1bab | ||
|
|
fb61cfeca3 | ||
|
|
5f9a635ab5 | ||
|
|
41c5504846 | ||
|
|
e5f9455fbb | ||
|
|
20cb48caff | ||
|
|
f241aed5b2 | ||
|
|
87c2faa6af | ||
|
|
10a840f48d | ||
|
|
61f9531046 | ||
|
|
1ab408a757 | ||
|
|
84df2be3b8 | ||
|
|
17376d9dba | ||
|
|
4289cf4f7c | ||
|
|
f04449be72 | ||
|
|
a0f9d065f9 | ||
|
|
20f2e20bcb | ||
|
|
b410b501a1 | ||
|
|
31d430e30e | ||
|
|
82d8e39ca4 | ||
|
|
e60f4ff144 | ||
|
|
156ea0ef30 |
+2
-2
@@ -24,8 +24,8 @@
|
|||||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||||
"coverage:report": "export NETWORK=mainnet && nyc --reporter=html mocha --timeout 25000 test/v4/",
|
"coverage:report": "export NETWORK=mainnet && nyc --reporter=html mocha --timeout 25000 test/v4/",
|
||||||
"docs": "./node_modules/.bin/apidoc -i src/routes/v4 -o docs",
|
"docs": "./node_modules/.bin/apidoc -i src/routes/v4 -o docs",
|
||||||
"test:temp1": "export NETWORK=mainnet && export TEST=integration && export SLPDB_URL=https://slpdb.fountainhead.cash/ && mocha --exit --timeout 25000 -g '#nft' test/v4/integration/",
|
"test:temp1": "export NETWORK=mainnet && export TEST=integration && mocha -g '#utxosBulk' --exit --timeout 30000 test/v5/",
|
||||||
"test:temp2": "mocha -g '#getNftGroup' --exit --timeout 30000 test/v4/"
|
"test:temp2": "export NETWORK=mainnet && mocha -g '#utxosBulk' --exit --timeout 30000 test/v5/"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.15.1"
|
"node": ">=10.15.1"
|
||||||
|
|||||||
+3
-2
@@ -46,6 +46,7 @@ const ControlV5 = require('./routes/v5/full-node/control')
|
|||||||
const MiningV5 = require('./routes/v5/full-node/mining')
|
const MiningV5 = require('./routes/v5/full-node/mining')
|
||||||
const networkV5 = require('./routes/v5/full-node/network')
|
const networkV5 = require('./routes/v5/full-node/network')
|
||||||
const RawtransactionsV5 = require('./routes/v5/full-node/rawtransactions')
|
const RawtransactionsV5 = require('./routes/v5/full-node/rawtransactions')
|
||||||
|
const DSProofV5 = require('./routes/v5/full-node/dsproof')
|
||||||
const UtilV5 = require('./routes/v5/util')
|
const UtilV5 = require('./routes/v5/util')
|
||||||
const SlpV5 = require('./routes/v5/slp')
|
const SlpV5 = require('./routes/v5/slp')
|
||||||
const xpubV5 = require('./routes/v5/xpub')
|
const xpubV5 = require('./routes/v5/xpub')
|
||||||
@@ -75,11 +76,10 @@ const miningV5 = new MiningV5()
|
|||||||
const rawtransactionsV5 = new RawtransactionsV5()
|
const rawtransactionsV5 = new RawtransactionsV5()
|
||||||
const slpV5 = new SlpV5()
|
const slpV5 = new SlpV5()
|
||||||
const electrumxv5 = new ElectrumXV5()
|
const electrumxv5 = new ElectrumXV5()
|
||||||
electrumxv5.connect()
|
|
||||||
const encryptionv5 = new EncryptionV5()
|
const encryptionv5 = new EncryptionV5()
|
||||||
const pricev5 = new PriceV5()
|
const pricev5 = new PriceV5()
|
||||||
const utilV5 = new UtilV5({ electrumx: electrumxv5 })
|
const utilV5 = new UtilV5({ electrumx: electrumxv5 })
|
||||||
|
const dsproofV5 = new DSProofV5()
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.locals.env = process.env
|
app.locals.env = process.env
|
||||||
@@ -188,6 +188,7 @@ app.use(`/${v5prefix}/` + 'electrumx', electrumxv5.router)
|
|||||||
app.use(`/${v5prefix}/` + 'encryption', encryptionv5.router)
|
app.use(`/${v5prefix}/` + 'encryption', encryptionv5.router)
|
||||||
app.use(`/${v5prefix}/` + 'price', pricev5.router)
|
app.use(`/${v5prefix}/` + 'price', pricev5.router)
|
||||||
app.use(`/${v5prefix}/` + 'util', utilV5.router)
|
app.use(`/${v5prefix}/` + 'util', utilV5.router)
|
||||||
|
app.use(`/${v5prefix}/` + 'dsproof', dsproofV5.router)
|
||||||
|
|
||||||
// const ninsight = new Ninsight()
|
// const ninsight = new Ninsight()
|
||||||
app.use(`/${v5prefix}/` + 'ninsight', ninsight.router)
|
app.use(`/${v5prefix}/` + 'ninsight', ninsight.router)
|
||||||
|
|||||||
+698
-961
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,95 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const express = require('express')
|
||||||
|
const router = express.Router()
|
||||||
|
|
||||||
|
const axios = require('axios')
|
||||||
|
const wlogger = require('../../../util/winston-logging')
|
||||||
|
|
||||||
|
const RouteUtils = require('../../../util/route-utils')
|
||||||
|
const routeUtils = new RouteUtils()
|
||||||
|
|
||||||
|
// Used to convert error messages to strings, to safely pass to users.
|
||||||
|
const util = require('util')
|
||||||
|
util.inspect.defaultOptions = { depth: 1 }
|
||||||
|
|
||||||
|
let _this
|
||||||
|
class DSProof {
|
||||||
|
constructor () {
|
||||||
|
_this = this
|
||||||
|
_this.axios = axios
|
||||||
|
_this.routeUtils = routeUtils
|
||||||
|
|
||||||
|
_this.router = router
|
||||||
|
_this.router.get('/', this.root)
|
||||||
|
_this.router.get('/getdsproof/:txid', _this.getDSProof)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DRY error handler.
|
||||||
|
errorHandler (err, res) {
|
||||||
|
// Attempt to decode the error message.
|
||||||
|
const { msg, status } = _this.routeUtils.decodeError(err)
|
||||||
|
if (msg) {
|
||||||
|
res.status(status)
|
||||||
|
return res.json({ error: msg })
|
||||||
|
}
|
||||||
|
|
||||||
|
res.status(500)
|
||||||
|
return res.json({ error: util.inspect(err) })
|
||||||
|
}
|
||||||
|
|
||||||
|
root (req, res, next) {
|
||||||
|
return res.json({ status: 'dsproof' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {get} /dsproof/getdsproof/:txid Get Double-Spend Proof.
|
||||||
|
* @apiName DS Proof.
|
||||||
|
* @apiGroup DSProof
|
||||||
|
* @apiDescription Get information for a double-spend proof.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @apiExample Example usage:
|
||||||
|
* curl -X GET "https://api.fullstack.cash/v5/dsproof/getdsproof/a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d" -H "accept: application/json"
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async getDSProof (req, res, next) {
|
||||||
|
try {
|
||||||
|
const txid = req.params.txid
|
||||||
|
|
||||||
|
let verbose = 2 // default
|
||||||
|
if (req.query.verbose === 'true') verbose = 3
|
||||||
|
|
||||||
|
if (!txid || txid === '') {
|
||||||
|
res.status(400)
|
||||||
|
return res.json({
|
||||||
|
success: false,
|
||||||
|
error: 'txid can not be empty'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (txid.length !== 64) {
|
||||||
|
res.status(400)
|
||||||
|
return res.json({
|
||||||
|
success: false,
|
||||||
|
error: `txid must be of length 64 (not ${txid.length})`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const options = _this.routeUtils.getAxiosOptions()
|
||||||
|
options.data.id = 'getdsproof'
|
||||||
|
options.data.method = 'getdsproof'
|
||||||
|
options.data.params = [txid, verbose]
|
||||||
|
|
||||||
|
const response = await _this.axios.request(options)
|
||||||
|
return res.json(response.data.result)
|
||||||
|
} catch (err) {
|
||||||
|
wlogger.error('Error in dsproof.js/getDSProof().', err)
|
||||||
|
|
||||||
|
return _this.errorHandler(err, res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = DSProof
|
||||||
+2667
-1320
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ const chai = require('chai')
|
|||||||
const assert = chai.assert
|
const assert = chai.assert
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
|
|
||||||
const Blockchain = require('../../src/routes/v4/full-node/blockchain')
|
const Blockchain = require('../../src/routes/v5/full-node/blockchain')
|
||||||
const uut = new Blockchain()
|
const uut = new Blockchain()
|
||||||
|
|
||||||
const util = require('util')
|
const util = require('util')
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const assert = chai.assert
|
const assert = chai.assert
|
||||||
const ControlRoute = require('../../src/routes/v4/full-node/control')
|
const ControlRoute = require('../../src/routes/v5/full-node/control')
|
||||||
const uut = new ControlRoute()
|
const uut = new ControlRoute()
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,190 @@
|
|||||||
|
/*
|
||||||
|
TESTS FOR THE DSPROOF.JS LIBRARY
|
||||||
|
|
||||||
|
This test file uses the environment variable TEST to switch between unit
|
||||||
|
and integration tests. By default, TEST is set to 'unit'. Set this variable
|
||||||
|
to 'integration' to run the tests against BCH mainnet.
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const chai = require('chai')
|
||||||
|
const assert = chai.assert
|
||||||
|
const DSProofRoute = require('../../src/routes/v5/full-node/dsproof')
|
||||||
|
const uut = new DSProofRoute()
|
||||||
|
|
||||||
|
// const nock = require('nock') // HTTP mocking
|
||||||
|
const sinon = require('sinon')
|
||||||
|
|
||||||
|
let originalEnvVars // Used during transition from integration to unit tests.
|
||||||
|
|
||||||
|
// Mocking data.
|
||||||
|
const { mockReq, mockRes } = require('./mocks/express-mocks')
|
||||||
|
const mockData = require('./mocks/dsproof-mocks')
|
||||||
|
|
||||||
|
// Used for debugging.
|
||||||
|
const util = require('util')
|
||||||
|
util.inspect.defaultOptions = { depth: 1 }
|
||||||
|
|
||||||
|
describe('#DSProof', () => {
|
||||||
|
let req, res
|
||||||
|
let sandbox
|
||||||
|
before(() => {
|
||||||
|
// Save existing environment variables.
|
||||||
|
originalEnvVars = {
|
||||||
|
BITCOINCOM_BASEURL: process.env.BITCOINCOM_BASEURL,
|
||||||
|
RPC_BASEURL: process.env.RPC_BASEURL,
|
||||||
|
RPC_USERNAME: process.env.RPC_USERNAME,
|
||||||
|
RPC_PASSWORD: process.env.RPC_PASSWORD
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set default environment variables for unit tests.
|
||||||
|
if (!process.env.TEST) process.env.TEST = 'unit'
|
||||||
|
if (process.env.TEST === 'unit') {
|
||||||
|
process.env.BITCOINCOM_BASEURL = 'http://fakeurl/api/'
|
||||||
|
process.env.RPC_BASEURL = 'http://fakeurl/api'
|
||||||
|
process.env.RPC_USERNAME = 'fakeusername'
|
||||||
|
process.env.RPC_PASSWORD = 'fakepassword'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Setup the mocks before each test.
|
||||||
|
beforeEach(() => {
|
||||||
|
// Mock the req and res objects used by Express routes.
|
||||||
|
req = mockReq
|
||||||
|
res = mockRes
|
||||||
|
|
||||||
|
// Explicitly reset the parmas and body.
|
||||||
|
req.params = {}
|
||||||
|
req.body = {}
|
||||||
|
req.query = {}
|
||||||
|
|
||||||
|
sandbox = sinon.createSandbox()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
// Restore Sandbox
|
||||||
|
sandbox.restore()
|
||||||
|
})
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
// Restore any pre-existing environment variables.
|
||||||
|
process.env.BITCOINCOM_BASEURL = originalEnvVars.BITCOINCOM_BASEURL
|
||||||
|
process.env.RPC_BASEURL = originalEnvVars.RPC_BASEURL
|
||||||
|
process.env.RPC_USERNAME = originalEnvVars.RPC_USERNAME
|
||||||
|
process.env.RPC_PASSWORD = originalEnvVars.RPC_PASSWORD
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('#root', async () => {
|
||||||
|
// root route handler.
|
||||||
|
it('should respond to GET for base route', async () => {
|
||||||
|
const result = uut.root(req, res)
|
||||||
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
|
|
||||||
|
assert.equal(result.status, 'dsproof', 'Returns static string')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('#getDSProof', async () => {
|
||||||
|
it('should throw 400 error if txid is missing', async () => {
|
||||||
|
const result = await uut.getDSProof(req, res)
|
||||||
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
|
|
||||||
|
assert.hasAllKeys(result, ['error', 'success'])
|
||||||
|
assert.isFalse(result.success)
|
||||||
|
assert.include(result.error, 'txid can not be empty')
|
||||||
|
})
|
||||||
|
it('should throw 400 error if txid is invalid', async () => {
|
||||||
|
req.params.txid = 'abc123'
|
||||||
|
|
||||||
|
const result = await uut.getDSProof(req, res)
|
||||||
|
|
||||||
|
assert.hasAllKeys(result, ['error', 'success'])
|
||||||
|
assert.isFalse(result.success)
|
||||||
|
|
||||||
|
assert.equal(res.statusCode, 400, 'HTTP status code 400 expected.')
|
||||||
|
assert.include(result.error, 'txid must be of length 64')
|
||||||
|
})
|
||||||
|
it('should throw 503 when network issues', async () => {
|
||||||
|
req.params.txid =
|
||||||
|
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||||
|
|
||||||
|
// Save the existing RPC URL.
|
||||||
|
const savedUrl2 = process.env.RPC_BASEURL
|
||||||
|
|
||||||
|
// Manipulate the URL to cause a 500 network error.
|
||||||
|
process.env.RPC_BASEURL = 'http://fakeurl/api/'
|
||||||
|
|
||||||
|
await uut.getDSProof(req, res)
|
||||||
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
|
|
||||||
|
// Restore the saved URL.
|
||||||
|
process.env.RPC_BASEURL = savedUrl2
|
||||||
|
|
||||||
|
assert.isAbove(
|
||||||
|
res.statusCode,
|
||||||
|
499,
|
||||||
|
'HTTP status code 500 or greater expected.'
|
||||||
|
)
|
||||||
|
// assert.include(result.error,"Network error: Could not communicate with full node","Error message expected")
|
||||||
|
})
|
||||||
|
it('returns proper error when downstream service stalls', async () => {
|
||||||
|
req.params.txid =
|
||||||
|
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||||
|
// Mock the timeout error.
|
||||||
|
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNABORTED' })
|
||||||
|
|
||||||
|
const result = await uut.getDSProof(req, res)
|
||||||
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||||
|
|
||||||
|
assert.isAbove(res.statusCode, 499, 'HTTP status code 503 expected.')
|
||||||
|
assert.include(
|
||||||
|
result.error,
|
||||||
|
'Could not communicate with full node',
|
||||||
|
'Error message expected'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns proper error when downstream service is down', async () => {
|
||||||
|
req.params.txid =
|
||||||
|
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||||
|
// Mock the timeout error.
|
||||||
|
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNREFUSED' })
|
||||||
|
|
||||||
|
const result = await uut.getDSProof(req, res)
|
||||||
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||||
|
|
||||||
|
assert.isAbove(res.statusCode, 499, 'HTTP status code 503 expected.')
|
||||||
|
assert.include(
|
||||||
|
result.error,
|
||||||
|
'Could not communicate with full node',
|
||||||
|
'Error message expected'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should GET double-spend proof', async function () {
|
||||||
|
req.params.txid =
|
||||||
|
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||||
|
// Mock the RPC call for unit tests.
|
||||||
|
if (process.env.TEST === 'unit') {
|
||||||
|
sandbox
|
||||||
|
.stub(uut.axios, 'request')
|
||||||
|
.resolves({ data: { result: mockData.mockGetDsProof } })
|
||||||
|
} else {
|
||||||
|
return this.skip()
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await uut.getDSProof(req, res)
|
||||||
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
|
|
||||||
|
assert.property(result, 'dspid')
|
||||||
|
assert.property(result, 'txid')
|
||||||
|
assert.property(result, 'outpoint')
|
||||||
|
assert.property(result, 'path')
|
||||||
|
assert.property(result, 'descendants')
|
||||||
|
|
||||||
|
assert.property(result.outpoint, 'txid')
|
||||||
|
assert.property(result.outpoint, 'vout')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -19,7 +19,7 @@ const sinon = require('sinon')
|
|||||||
if (!process.env.TEST) process.env.TEST = 'unit'
|
if (!process.env.TEST) process.env.TEST = 'unit'
|
||||||
|
|
||||||
// Only load blockbook library after setting BLOCKBOOK_URL env var.
|
// Only load blockbook library after setting BLOCKBOOK_URL env var.
|
||||||
const EncryptionRoute = require('../../src/routes/v4/encryption')
|
const EncryptionRoute = require('../../src/routes/v5/encryption')
|
||||||
const encryptionRoute = new EncryptionRoute()
|
const encryptionRoute = new EncryptionRoute()
|
||||||
|
|
||||||
// Mocking data.
|
// Mocking data.
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const assert = chai.assert
|
const assert = chai.assert
|
||||||
const MiningRoute = require('../../src/routes/v4/full-node/mining')
|
const MiningRoute = require('../../src/routes/v5/full-node/mining')
|
||||||
const uut = new MiningRoute()
|
const uut = new MiningRoute()
|
||||||
|
|
||||||
// const nock = require('nock') // HTTP mocking
|
// const nock = require('nock') // HTTP mocking
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
This library contains mocking data for running unit tests on the dsproof route.
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const mockGetDsProof = {
|
||||||
|
dspid: '6234fff2a9dbcaa50e2c50d74e1d725a2bed1757d7a05a2db7a82df659554397',
|
||||||
|
txid: 'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e',
|
||||||
|
outpoint: {
|
||||||
|
txid: '17ebef34f7e9a0692317dd6fbb43ffccff45b7d688a2a754dbccfc5e6d93ce3e',
|
||||||
|
vout: 1
|
||||||
|
},
|
||||||
|
path: ['ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'],
|
||||||
|
descendants: [
|
||||||
|
'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
mockGetDsProof
|
||||||
|
}
|
||||||
+110
-11
@@ -19,11 +19,63 @@ const utxos = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const balance = {
|
const utxosArray = {
|
||||||
confirmed: 7000,
|
success: true,
|
||||||
unconfirmed: 0
|
utxos: [
|
||||||
|
{
|
||||||
|
utxos: [
|
||||||
|
{
|
||||||
|
height: 601861,
|
||||||
|
tx_hash:
|
||||||
|
'6181c669614fa18039a19b23eb06806bfece1f7514ab457c3bb82a40fe171a6d',
|
||||||
|
tx_pos: 0,
|
||||||
|
value: 1000
|
||||||
|
}
|
||||||
|
],
|
||||||
|
address: 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
utxos: [
|
||||||
|
{
|
||||||
|
height: 604392,
|
||||||
|
tx_hash:
|
||||||
|
'7774e449c5a3065144cefbc4c0c21e6b69c987f095856778ef9f45ddd8ae1a41',
|
||||||
|
tx_pos: 0,
|
||||||
|
value: 1000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
height: 630834,
|
||||||
|
tx_hash:
|
||||||
|
'4fe60a51e0d8f5134bfd8e5f872d6e502d7f01b28a6afebb27f4438a4f638d53',
|
||||||
|
tx_pos: 0,
|
||||||
|
value: 6000
|
||||||
|
}
|
||||||
|
],
|
||||||
|
address: 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf'
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const balance = {
|
||||||
|
success: true,
|
||||||
|
balance: {
|
||||||
|
confirmed: 7000,
|
||||||
|
unconfirmed: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const balances = {
|
||||||
|
success: true,
|
||||||
|
balances: [
|
||||||
|
{
|
||||||
|
balance: { confirmed: 7000, unconfirmed: 0 },
|
||||||
|
address: 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
balance: { confirmed: 7000, unconfirmed: 0 },
|
||||||
|
address: 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
const txHistory = [
|
const txHistory = [
|
||||||
{
|
{
|
||||||
height: 601861,
|
height: 601861,
|
||||||
@@ -44,7 +96,8 @@ const txDetails = {
|
|||||||
blocktime: 1578327094,
|
blocktime: 1578327094,
|
||||||
confirmations: 31861,
|
confirmations: 31861,
|
||||||
hash: '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251',
|
hash: '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251',
|
||||||
hex: '020000000265d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667010000006441dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e4121020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309ffffffff65d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667000000006441347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f774121028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954ffffffff035ac355000000000017a914189ce02e332548f4804bac65cba68202c9dbf822878dfd0800000000001976a914285bb350881b21ac89724c6fb6dc914d096cd53b88acf9ef3100000000001976a91445f1f1c4a9b9419a5088a3e9c24a293d7a150e6488ac00000000',
|
hex:
|
||||||
|
'020000000265d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667010000006441dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e4121020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309ffffffff65d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667000000006441347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f774121028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954ffffffff035ac355000000000017a914189ce02e332548f4804bac65cba68202c9dbf822878dfd0800000000001976a914285bb350881b21ac89724c6fb6dc914d096cd53b88acf9ef3100000000001976a91445f1f1c4a9b9419a5088a3e9c24a293d7a150e6488ac00000000',
|
||||||
locktime: 0,
|
locktime: 0,
|
||||||
size: 392,
|
size: 392,
|
||||||
time: 1578327094,
|
time: 1578327094,
|
||||||
@@ -53,8 +106,10 @@ const txDetails = {
|
|||||||
vin: [
|
vin: [
|
||||||
{
|
{
|
||||||
scriptSig: {
|
scriptSig: {
|
||||||
asm: 'dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e[ALL|FORKID] 020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309',
|
asm:
|
||||||
hex: '41dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e4121020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309'
|
'dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e[ALL|FORKID] 020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309',
|
||||||
|
hex:
|
||||||
|
'41dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e4121020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309'
|
||||||
},
|
},
|
||||||
sequence: 4294967295,
|
sequence: 4294967295,
|
||||||
txid: '6796672c8f0342770e3d4ac2a3b0e4494daeb7af7997f3518a0c8402f43ed165',
|
txid: '6796672c8f0342770e3d4ac2a3b0e4494daeb7af7997f3518a0c8402f43ed165',
|
||||||
@@ -62,8 +117,10 @@ const txDetails = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
scriptSig: {
|
scriptSig: {
|
||||||
asm: '347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f77[ALL|FORKID] 028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954',
|
asm:
|
||||||
hex: '41347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f774121028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954'
|
'347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f77[ALL|FORKID] 028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954',
|
||||||
|
hex:
|
||||||
|
'41347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f774121028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954'
|
||||||
},
|
},
|
||||||
sequence: 4294967295,
|
sequence: 4294967295,
|
||||||
txid: '6796672c8f0342770e3d4ac2a3b0e4494daeb7af7997f3518a0c8402f43ed165',
|
txid: '6796672c8f0342770e3d4ac2a3b0e4494daeb7af7997f3518a0c8402f43ed165',
|
||||||
@@ -86,7 +143,8 @@ const txDetails = {
|
|||||||
n: 1,
|
n: 1,
|
||||||
scriptPubKey: {
|
scriptPubKey: {
|
||||||
addresses: ['bitcoincash: qq59hv6s3qdjrtyfwfxxldkuj9xsjmx48vrz882knz'],
|
addresses: ['bitcoincash: qq59hv6s3qdjrtyfwfxxldkuj9xsjmx48vrz882knz'],
|
||||||
asm: 'OP_DUP OP_HASH160 285bb350881b21ac89724c6fb6dc914d096cd53b OP_EQUALVERIFY OP_CHECKSIG',
|
asm:
|
||||||
|
'OP_DUP OP_HASH160 285bb350881b21ac89724c6fb6dc914d096cd53b OP_EQUALVERIFY OP_CHECKSIG',
|
||||||
hex: '76a914285bb350881b21ac89724c6fb6dc914d096cd53b88ac',
|
hex: '76a914285bb350881b21ac89724c6fb6dc914d096cd53b88ac',
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
type: 'pubkeyhash'
|
type: 'pubkeyhash'
|
||||||
@@ -97,7 +155,8 @@ const txDetails = {
|
|||||||
n: 2,
|
n: 2,
|
||||||
scriptPubKey: {
|
scriptPubKey: {
|
||||||
addresses: ['bitcoincash: qpzlruwy4xu5rxjs3z37nsj29y7h59gwvsu4ddp0u4'],
|
addresses: ['bitcoincash: qpzlruwy4xu5rxjs3z37nsj29y7h59gwvsu4ddp0u4'],
|
||||||
asm: 'OP_DUP OP_HASH160 45f1f1c4a9b9419a5088a3e9c24a293d7a150e64 OP_EQUALVERIFY OP_CHECKSIG',
|
asm:
|
||||||
|
'OP_DUP OP_HASH160 45f1f1c4a9b9419a5088a3e9c24a293d7a150e64 OP_EQUALVERIFY OP_CHECKSIG',
|
||||||
hex: '76a91445f1f1c4a9b9419a5088a3e9c24a293d7a150e6488ac',
|
hex: '76a91445f1f1c4a9b9419a5088a3e9c24a293d7a150e6488ac',
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
type: 'pubkeyhash'
|
type: 'pubkeyhash'
|
||||||
@@ -107,16 +166,56 @@ const txDetails = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const txDetailsBulk = {
|
||||||
|
success: true,
|
||||||
|
transactions: [{ details: txDetails }]
|
||||||
|
}
|
||||||
|
|
||||||
const blockHeaders = [
|
const blockHeaders = [
|
||||||
'010000008b52bbd72c2f49569059f559c1b1794de5192e4f7d6d2b03c7482bad0000000083e4f8a9d502ed0c419075c1abb5d56f878a2e9079e5612bfb76a2dc37d9c42741dd6849ffff001d2b909dd6',
|
'010000008b52bbd72c2f49569059f559c1b1794de5192e4f7d6d2b03c7482bad0000000083e4f8a9d502ed0c419075c1abb5d56f878a2e9079e5612bfb76a2dc37d9c42741dd6849ffff001d2b909dd6',
|
||||||
'01000000f528fac1bcb685d0cd6c792320af0300a5ce15d687c7149548904e31000000004e8985a786d864f21e9cbb7cbdf4bc9265fe681b7a0893ac55a8e919ce035c2f85de6849ffff001d385ccb7c'
|
'01000000f528fac1bcb685d0cd6c792320af0300a5ce15d687c7149548904e31000000004e8985a786d864f21e9cbb7cbdf4bc9265fe681b7a0893ac55a8e919ce035c2f85de6849ffff001d385ccb7c'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const blockHeadersBulk = {
|
||||||
|
success: true,
|
||||||
|
headers: [{ headers: blockHeaders }, { headers: blockHeaders }]
|
||||||
|
}
|
||||||
|
|
||||||
|
const transactions = [
|
||||||
|
{
|
||||||
|
height: 603416,
|
||||||
|
tx_hash: 'eef683d236d88e978bd406419f144057af3fe1b62ef59162941c1a9f05ded62c'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
height: 646894,
|
||||||
|
tx_hash: '4c695fae636f3e8e2edc571d11756b880ccaae744390f3950d798ce7b5e25754'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const transactionsBulk = {
|
||||||
|
success: true,
|
||||||
|
transactions: [
|
||||||
|
{
|
||||||
|
transactions,
|
||||||
|
address: 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
transactions,
|
||||||
|
address: 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
utxos,
|
utxos,
|
||||||
|
utxosArray,
|
||||||
balance,
|
balance,
|
||||||
txHistory,
|
txHistory,
|
||||||
mempool,
|
mempool,
|
||||||
txDetails,
|
txDetails,
|
||||||
blockHeaders
|
txDetailsBulk,
|
||||||
|
blockHeaders,
|
||||||
|
blockHeadersBulk,
|
||||||
|
balances,
|
||||||
|
transactions,
|
||||||
|
transactionsBulk
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ const chai = require('chai')
|
|||||||
const assert = chai.assert
|
const assert = chai.assert
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
|
|
||||||
const Price = require('../../src/routes/v4/price')
|
const Price = require('../../src/routes/v5/price')
|
||||||
let uut
|
let uut
|
||||||
|
|
||||||
// Mocking data.
|
// Mocking data.
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const assert = chai.assert
|
const assert = chai.assert
|
||||||
const Rawtransactions = require('../../src/routes/v4/full-node/rawtransactions')
|
const Rawtransactions = require('../../src/routes/v5/full-node/rawtransactions')
|
||||||
const uut = new Rawtransactions()
|
const uut = new Rawtransactions()
|
||||||
|
|
||||||
// const nock = require('nock') // HTTP mocking
|
// const nock = require('nock') // HTTP mocking
|
||||||
|
|||||||
+2
-2
@@ -40,11 +40,11 @@ if (process.env.TEST === 'unit') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the slpRoute for stubbing dependcies on slpjs.
|
// Prepare the slpRoute for stubbing dependcies on slpjs.
|
||||||
const SlpRoute = require('../../src/routes/v4/slp')
|
const SlpRoute = require('../../src/routes/v5/slp')
|
||||||
const slpRoute = new SlpRoute()
|
const slpRoute = new SlpRoute()
|
||||||
|
|
||||||
// const pathStub = {} // Used to stub methods within slpjs.
|
// const pathStub = {} // Used to stub methods within slpjs.
|
||||||
// const slpRouteStub = proxyquire('../../src/routes/v4/slp', { slpjs: pathStub })
|
// const slpRouteStub = proxyquire('../../src/routes/v5/slp', { slpjs: pathStub })
|
||||||
|
|
||||||
// Mocking data.
|
// Mocking data.
|
||||||
const { mockReq, mockRes } = require('./mocks/express-mocks')
|
const { mockReq, mockRes } = require('./mocks/express-mocks')
|
||||||
|
|||||||
+2
-2
@@ -19,8 +19,8 @@ const nock = require('nock') // HTTP mocking
|
|||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
|
|
||||||
// Local libraries
|
// Local libraries
|
||||||
const Electrumx = require('../../src/routes/v4/electrumx')
|
const Electrumx = require('../../src/routes/v5/electrumx')
|
||||||
const UtilRoute = require('../../src/routes/v4/util')
|
const UtilRoute = require('../../src/routes/v5/util')
|
||||||
|
|
||||||
let originalEnvVars // Used during transition from integration to unit tests.
|
let originalEnvVars // Used during transition from integration to unit tests.
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const assert = chai.assert
|
const assert = chai.assert
|
||||||
const xpubRoute = require('../../src/routes/v4/xpub')
|
const xpubRoute = require('../../src/routes/v5/xpub')
|
||||||
const nock = require('nock') // HTTP mocking
|
const nock = require('nock') // HTTP mocking
|
||||||
|
|
||||||
// let originalUrl // Used during transition from integration to unit tests.
|
// let originalUrl // Used during transition from integration to unit tests.
|
||||||
@@ -119,7 +119,8 @@ describe('#XPUBRouter', () => {
|
|||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
it('should create an address from xpub', async () => {
|
it('should create an address from xpub', async () => {
|
||||||
req.params.xpub = 'tpubDHTK2jqg73w3GwoiHfAMbMYML1HN8FhrUxD9rFgbSgHXdwwrY6pAFqKDfUHhqw7vreaZty5hPGjb1S7ZPQeMmu6TFHAKfY9tJpYbvaGjPRM'
|
req.params.xpub =
|
||||||
|
'tpubDHTK2jqg73w3GwoiHfAMbMYML1HN8FhrUxD9rFgbSgHXdwwrY6pAFqKDfUHhqw7vreaZty5hPGjb1S7ZPQeMmu6TFHAKfY9tJpYbvaGjPRM'
|
||||||
|
|
||||||
// Mock the Insight URL for unit tests.
|
// Mock the Insight URL for unit tests.
|
||||||
// TODO add unit test
|
// TODO add unit test
|
||||||
|
|||||||
Reference in New Issue
Block a user