mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a85a2a4ef | ||
|
|
443fb233ae | ||
|
|
553d6fd4b0 | ||
|
|
ab98bf05da | ||
|
|
6806b4a197 | ||
|
|
4ae74aed59 | ||
|
|
98e1a5b40f | ||
|
|
279c9b7bea | ||
|
|
56be614980 | ||
|
|
584037ebdd | ||
|
|
44230b73f7 | ||
|
|
b7f1eba6bd |
@@ -1,6 +1,5 @@
|
||||
# bch-api
|
||||
|
||||
[](https://greenkeeper.io/)
|
||||
|
||||
[](https://travis-ci.org/christroutner/bch-api)
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ USER safeuser
|
||||
|
||||
# Clone the repository
|
||||
WORKDIR /home/safeuser
|
||||
RUN git clone https://github.com/christroutner/bch-api
|
||||
RUN git clone https://github.com/Permissionless-Software-Foundation/bch-api
|
||||
WORKDIR /home/safeuser/bch-api
|
||||
RUN npm install
|
||||
RUN npm install --silent
|
||||
|
||||
# Generate documentation
|
||||
RUN npm run docs
|
||||
|
||||
@@ -13,9 +13,9 @@ USER safeuser
|
||||
|
||||
# Clone the repository
|
||||
WORKDIR /home/safeuser
|
||||
RUN git clone https://github.com/christroutner/bch-api
|
||||
RUN git clone https://github.com/Permissionless-Software-Foundation/bch-api
|
||||
WORKDIR /home/safeuser/bch-api
|
||||
RUN npm install
|
||||
RUN npm install --silent
|
||||
|
||||
# Generate documentation
|
||||
RUN npm run docs
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
"test": "npm run lint && npm run test-v3",
|
||||
"lint": "standard --env mocha --fix",
|
||||
"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:slpdb": "mocha --timeout 25000 test/v3/integration/slp*.js",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
|
||||
@@ -116,13 +116,20 @@ class RateLimits {
|
||||
let pointsToConsume = _this.calcPoints(decoded)
|
||||
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
|
||||
|
||||
// Retrieve the origin.
|
||||
let origin = req.get('origin')
|
||||
if (origin === undefined && key.indexOf('10.0.0.5') > -1) {
|
||||
origin = 'slp-api'
|
||||
}
|
||||
wlogger.info(`origin: ${origin}`)
|
||||
|
||||
// If the request originates from one of the approved wallet apps, then
|
||||
// apply paid-access rate limits.
|
||||
const origin = req.get('origin')
|
||||
if (
|
||||
origin &&
|
||||
(origin.toString().indexOf('wallet.fullstack.cash') > -1 ||
|
||||
origin.toString().indexOf('sandbox.fullstack.cash') > -1)
|
||||
origin.toString().indexOf('sandbox.fullstack.cash') > -1 ||
|
||||
origin === 'slp-api')
|
||||
) {
|
||||
pointsToConsume = 1
|
||||
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
|
||||
|
||||
+31
-58
@@ -135,11 +135,12 @@ describe('#Util', () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === 'unit') {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(uri => uri.includes('/'))
|
||||
.post((uri) => uri.includes('/'))
|
||||
.reply(200, { result: mockData.mockAddress })
|
||||
}
|
||||
|
||||
req.params.address = 'bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd'
|
||||
req.params.address =
|
||||
'bitcoincash:qpujxqra3jmdlzzapwmmt7uspr7q0c9ff5hzljcrnd'
|
||||
|
||||
const result = await validateAddress(req, res)
|
||||
// console.log(`result: ${util.inspect(result)}`)
|
||||
@@ -255,7 +256,7 @@ describe('#Util', () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === 'unit') {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(uri => uri.includes('/'))
|
||||
.post((uri) => uri.includes('/'))
|
||||
.reply(200, { result: mockData.mockAddress })
|
||||
}
|
||||
|
||||
@@ -281,7 +282,7 @@ describe('#Util', () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === 'unit') {
|
||||
nock(`${process.env.RPC_BASEURL}`)
|
||||
.post(uri => uri.includes('/'))
|
||||
.post((uri) => uri.includes('/'))
|
||||
.times(2)
|
||||
.reply(200, { result: mockData.mockAddress })
|
||||
}
|
||||
@@ -356,17 +357,11 @@ describe('#Util', () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
|
||||
sandbox
|
||||
.stub(
|
||||
utilRouteInst.blockbook,
|
||||
'balanceFromBlockbook'
|
||||
)
|
||||
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||
.resolves(mockData.mockBalance)
|
||||
|
||||
sandbox
|
||||
.stub(
|
||||
utilRouteInst.blockbook,
|
||||
'utxosFromBlockbook'
|
||||
)
|
||||
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||
.resolves(mockData.mockUtxos)
|
||||
|
||||
sandbox
|
||||
@@ -389,51 +384,41 @@ describe('#Util', () => {
|
||||
|
||||
assert.equal(result, 'test-txid')
|
||||
})
|
||||
}
|
||||
|
||||
it('should return balance if balance-only is true', async () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === 'unit') {
|
||||
it('should return balance if balance-only is true', async () => {
|
||||
// Mock the RPC call for unit tests.
|
||||
|
||||
sandbox
|
||||
.stub(
|
||||
utilRouteInst.blockbook,
|
||||
'balanceFromBlockbook'
|
||||
)
|
||||
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||
.resolves(mockData.mockBalance)
|
||||
}
|
||||
|
||||
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
||||
// to the network.
|
||||
sandbox
|
||||
.stub(utilRouteInst.bchjs.RawTransactions, 'sendRawTransaction')
|
||||
.resolves('test-txid')
|
||||
// Mock sendRawTransaction() so that the hex does not actually get broadcast
|
||||
// to the network.
|
||||
sandbox
|
||||
.stub(utilRouteInst.bchjs.RawTransactions, 'sendRawTransaction')
|
||||
.resolves('test-txid')
|
||||
|
||||
req.body = {
|
||||
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt',
|
||||
balanceOnly: true
|
||||
}
|
||||
req.body = {
|
||||
wif: 'L5GEFg1tETLWBugmhSo9Zc4ms968qVmfmTroDxsJ982AiudAQGyt',
|
||||
balanceOnly: true
|
||||
}
|
||||
|
||||
const result = await utilRouteInst.sweepWif(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
const result = await utilRouteInst.sweepWif(req, res)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.isNumber(result)
|
||||
})
|
||||
assert.isNumber(result)
|
||||
})
|
||||
}
|
||||
|
||||
// Unit tests only
|
||||
if (process.env.TEST === 'unit') {
|
||||
it('should generate transaction for valid BCH-only sweep', async () => {
|
||||
sandbox
|
||||
.stub(
|
||||
utilRouteInst.blockbook,
|
||||
'balanceFromBlockbook'
|
||||
)
|
||||
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||
.resolves(mockData.mockBalance)
|
||||
|
||||
sandbox
|
||||
.stub(
|
||||
utilRouteInst.blockbook,
|
||||
'utxosFromBlockbook'
|
||||
)
|
||||
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||
.resolves(mockData.mockUtxos)
|
||||
|
||||
// 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 () => {
|
||||
sandbox
|
||||
.stub(
|
||||
utilRouteInst.blockbook,
|
||||
'balanceFromBlockbook'
|
||||
)
|
||||
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||
.resolves(mockData.mockBalance)
|
||||
|
||||
sandbox
|
||||
.stub(
|
||||
utilRouteInst.blockbook,
|
||||
'utxosFromBlockbook'
|
||||
)
|
||||
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||
.resolves(mockData.mockUtxos)
|
||||
|
||||
// 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 () => {
|
||||
sandbox
|
||||
.stub(
|
||||
utilRouteInst.blockbook,
|
||||
'balanceFromBlockbook'
|
||||
)
|
||||
.stub(utilRouteInst.blockbook, 'balanceFromBlockbook')
|
||||
.resolves(mockData.mockBalance)
|
||||
|
||||
sandbox
|
||||
.stub(
|
||||
utilRouteInst.blockbook,
|
||||
'utxosFromBlockbook'
|
||||
)
|
||||
.stub(utilRouteInst.blockbook, 'utxosFromBlockbook')
|
||||
.resolves(mockData.mockThreeUtxos)
|
||||
|
||||
// Force token utxo to appear as regular BCH utxo.
|
||||
|
||||
Reference in New Issue
Block a user