mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
fix(util): Fixed failing integration test
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
"test": "npm run lint && npm run test-v3",
|
"test": "npm run lint && npm run test-v3",
|
||||||
"lint": "standard --env mocha --fix",
|
"lint": "standard --env mocha --fix",
|
||||||
"test-v3": "export NETWORK=mainnet && nyc --reporter=text mocha --timeout 60000 test/v3/",
|
"test-v3": "export NETWORK=mainnet && nyc --reporter=text mocha --timeout 60000 test/v3/",
|
||||||
"test:temp": "export NETWORK=mainnet && mocha --timeout 25000 test/v3/a01-electrumx.js",
|
"test:temp": "export NETWORK=mainnet && mocha --timeout 25000 test/v3/util.js",
|
||||||
"test:integration": "mocha test/v3/integration",
|
"test:integration": "mocha test/v3/integration",
|
||||||
"test:integration:slpdb": "mocha --timeout 25000 test/v3/integration/slp*.js",
|
"test:integration:slpdb": "mocha --timeout 25000 test/v3/integration/slp*.js",
|
||||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||||
|
|||||||
+31
-58
@@ -135,11 +135,12 @@ describe('#Util', () => {
|
|||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
nock(`${process.env.RPC_BASEURL}`)
|
nock(`${process.env.RPC_BASEURL}`)
|
||||||
.post(uri => uri.includes('/'))
|
.post((uri) => uri.includes('/'))
|
||||||
.reply(200, { result: mockData.mockAddress })
|
.reply(200, { result: mockData.mockAddress })
|
||||||
}
|
}
|
||||||
|
|
||||||
req.params.address = 'bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd'
|
req.params.address =
|
||||||
|
'bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd'
|
||||||
|
|
||||||
const result = await validateAddress(req, res)
|
const result = await validateAddress(req, res)
|
||||||
// console.log(`result: ${util.inspect(result)}`)
|
// console.log(`result: ${util.inspect(result)}`)
|
||||||
@@ -255,7 +256,7 @@ describe('#Util', () => {
|
|||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
nock(`${process.env.RPC_BASEURL}`)
|
nock(`${process.env.RPC_BASEURL}`)
|
||||||
.post(uri => uri.includes('/'))
|
.post((uri) => uri.includes('/'))
|
||||||
.reply(200, { result: mockData.mockAddress })
|
.reply(200, { result: mockData.mockAddress })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +282,7 @@ describe('#Util', () => {
|
|||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
nock(`${process.env.RPC_BASEURL}`)
|
nock(`${process.env.RPC_BASEURL}`)
|
||||||
.post(uri => uri.includes('/'))
|
.post((uri) => uri.includes('/'))
|
||||||
.times(2)
|
.times(2)
|
||||||
.reply(200, { result: mockData.mockAddress })
|
.reply(200, { result: mockData.mockAddress })
|
||||||
}
|
}
|
||||||
@@ -356,17 +357,11 @@ describe('#Util', () => {
|
|||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'balanceFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockBalance)
|
.resolves(mockData.mockBalance)
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'utxosFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockUtxos)
|
.resolves(mockData.mockUtxos)
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
@@ -389,51 +384,41 @@ describe('#Util', () => {
|
|||||||
|
|
||||||
assert.equal(result, 'test-txid')
|
assert.equal(result, 'test-txid')
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
it('should return balance if balance-only is true', async () => {
|
it('should return balance if balance-only is true', async () => {
|
||||||
// Mock the RPC call for unit tests.
|
// Mock the RPC call for unit tests.
|
||||||
if (process.env.TEST === 'unit') {
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'balanceFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockBalance)
|
.resolves(mockData.mockBalance)
|
||||||
}
|
|
||||||
|
|
||||||
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
||||||
// to the network.
|
// to the network.
|
||||||
sandbox
|
sandbox
|
||||||
.stub(utilRouteInst.bchjs.RawTransactions, 'sendRawTransaction')
|
.stub(utilRouteInst.bchjs.RawTransactions, 'sendRawTransaction')
|
||||||
.resolves('test-txid')
|
.resolves('test-txid')
|
||||||
|
|
||||||
req.body = {
|
req.body = {
|
||||||
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt',
|
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt',
|
||||||
balanceOnly: true
|
balanceOnly: true
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await utilRouteInst.sweepWif(req, res)
|
const result = await utilRouteInst.sweepWif(req, res)
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||||
|
|
||||||
assert.isNumber(result)
|
assert.isNumber(result)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Unit tests only
|
// Unit tests only
|
||||||
if (process.env.TEST === 'unit') {
|
if (process.env.TEST === 'unit') {
|
||||||
it('should generate transaction for valid BCH-only sweep', async () => {
|
it('should generate transaction for valid BCH-only sweep', async () => {
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'balanceFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockBalance)
|
.resolves(mockData.mockBalance)
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'utxosFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockUtxos)
|
.resolves(mockData.mockUtxos)
|
||||||
|
|
||||||
// Force token utxo to appear as regular BCH utxo.
|
// Force token utxo to appear as regular BCH utxo.
|
||||||
@@ -460,17 +445,11 @@ describe('#Util', () => {
|
|||||||
|
|
||||||
it('should throw 422 error if no non-token UTXOs', async () => {
|
it('should throw 422 error if no non-token UTXOs', async () => {
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'balanceFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockBalance)
|
.resolves(mockData.mockBalance)
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'utxosFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockUtxos)
|
.resolves(mockData.mockUtxos)
|
||||||
|
|
||||||
// Force token utxo to appear as regular BCH utxo.
|
// Force token utxo to appear as regular BCH utxo.
|
||||||
@@ -502,17 +481,11 @@ describe('#Util', () => {
|
|||||||
|
|
||||||
it('should detect and throw error for multiple token classes', async () => {
|
it('should detect and throw error for multiple token classes', async () => {
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'balanceFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockBalance)
|
.resolves(mockData.mockBalance)
|
||||||
|
|
||||||
sandbox
|
sandbox
|
||||||
.stub(
|
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||||
utilRouteInst.blockbook,
|
|
||||||
'utxosFromBlockbook'
|
|
||||||
)
|
|
||||||
.resolves(mockData.mockThreeUtxos)
|
.resolves(mockData.mockThreeUtxos)
|
||||||
|
|
||||||
// Force token utxo to appear as regular BCH utxo.
|
// Force token utxo to appear as regular BCH utxo.
|
||||||
|
|||||||
Reference in New Issue
Block a user