Compare commits

..
14 Commits
Author SHA1 Message Date
Chris Troutner 9a85a2a4ef Merge pull request #19 from Permissionless-Software-Foundation/ct-unstable
fix(util): Fixed failing integration test
2020-08-17 08:09:30 -07:00
Chris Troutner 443fb233ae fix(util): Fixed failing integration test 2020-08-17 08:08:54 -07:00
Chris Troutner 553d6fd4b0 Merge pull request #16 from Permissionless-Software-Foundation/ct-unstable
fix(slp-api): Adding increased rate limits for slp-api
2020-08-08 10:54:05 -07:00
Chris Troutner ab98bf05da fix(slp-api): Adding increased rate limits for slp-api 2020-08-08 10:48:12 -07:00
Chris Troutner 6806b4a197 Doing silent npm install 2020-08-08 10:27:34 -07:00
Chris Troutner 4ae74aed59 Merge pull request #15 from Permissionless-Software-Foundation/ct-unstable
fix(Docker): Updating dockerfile to PSF repo
2020-08-08 09:35:29 -07:00
Chris Troutner 98e1a5b40f fix(Docker): Updating dockerfile to PSF repo 2020-08-08 09:32:36 -07:00
Chris Troutner 279c9b7bea Merge pull request #14 from Permissionless-Software-Foundation/ct-unstable
Tracking origin of requests in logs
2020-08-08 08:27:52 -07:00
Chris Troutner 56be614980 Merge branch 'master' into ct-unstable 2020-08-08 08:22:33 -07:00
Chris Troutner 584037ebdd fix(origin): Tracking origin of requests in logs 2020-08-08 08:22:23 -07:00
Chris Troutner 44230b73f7 Merge pull request #13 from Permissionless-Software-Foundation/ct-unstable
fix(deploy): Testing deploy again
2020-08-07 17:18:08 -07:00
Chris Troutner b7f1eba6bd fix(deploy): Testing deploy again 2020-08-07 17:15:00 -07:00
Chris Troutner 35bc3025d6 Merge pull request #12 from Permissionless-Software-Foundation/ct-unstable
fix(deploy): Updating deploy script
2020-08-07 17:06:59 -07:00
Chris Troutner 6f6531428a fix(deploy): Updating deploy script 2020-08-07 17:00:57 -07:00
7 changed files with 47 additions and 66 deletions
-1
View File
@@ -1,6 +1,5 @@
# bch-api # bch-api
[![Greenkeeper badge](https://badges.greenkeeper.io/christroutner/bch-api.svg)](https://greenkeeper.io/)
[![Build Status](https://travis-ci.org/christroutner/bch-api.svg?branch=master)](https://travis-ci.org/christroutner/bch-api) [![Build Status](https://travis-ci.org/christroutner/bch-api.svg?branch=master)](https://travis-ci.org/christroutner/bch-api)
+2
View File
@@ -11,5 +11,7 @@ export DATA="{\"ref\":\"$DEPLOY_SECRET\"}"
curl -X POST http://fullstack.cash:9000/hooks/bch-api-mainnet -H "Content-Type: application/json" -d $DATA curl -X POST http://fullstack.cash:9000/hooks/bch-api-mainnet -H "Content-Type: application/json" -d $DATA
curl -X POST http://fullstack.cash:9000/hooks/bch-api-testnet -H "Content-Type: application/json" -d $DATA curl -X POST http://fullstack.cash:9000/hooks/bch-api-testnet -H "Content-Type: application/json" -d $DATA
curl -X POST http://$FREE_SERVER:9000/hooks/bch-api-testnet -H "Content-Type: application/json" -d $DATA
curl -X POST http://$FREE_SERVER:9000/hooks/bch-api-mainnet -H "Content-Type: application/json" -d $DATA
echo "...Finished deploying to production." echo "...Finished deploying to production."
+2 -2
View File
@@ -16,9 +16,9 @@ USER safeuser
# Clone the repository # Clone the repository
WORKDIR /home/safeuser 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 WORKDIR /home/safeuser/bch-api
RUN npm install RUN npm install --silent
# Generate documentation # Generate documentation
RUN npm run docs RUN npm run docs
+2 -2
View File
@@ -13,9 +13,9 @@ USER safeuser
# Clone the repository # Clone the repository
WORKDIR /home/safeuser 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 WORKDIR /home/safeuser/bch-api
RUN npm install RUN npm install --silent
# Generate documentation # Generate documentation
RUN npm run docs RUN npm run docs
+1 -1
View File
@@ -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",
+9 -2
View File
@@ -116,13 +116,20 @@ class RateLimits {
let pointsToConsume = _this.calcPoints(decoded) let pointsToConsume = _this.calcPoints(decoded)
res.locals.pointsToConsume = pointsToConsume // Feedback for tests. 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 // If the request originates from one of the approved wallet apps, then
// apply paid-access rate limits. // apply paid-access rate limits.
const origin = req.get('origin')
if ( if (
origin && origin &&
(origin.toString().indexOf('wallet.fullstack.cash') > -1 || (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 pointsToConsume = 1
res.locals.pointsToConsume = pointsToConsume // Feedback for tests. res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
+31 -58
View File
@@ -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.