Compare commits

...
21 Commits
Author SHA1 Message Date
Chris Troutner 54c299e7fe Merge pull request #87 from Permissionless-Software-Foundation/ct-unstable
Updating README, shell scripts, and dependencies.
2021-01-11 16:37:10 -08:00
Chris Troutner a06399cfda fix(dependencies): Removed unneeded dependencies. 2021-01-11 16:35:41 -08:00
Chris Troutner e49c488e06 Removing unneeded dependencies 2021-01-11 16:33:49 -08:00
Chris Troutner be07ffab33 Removing unneeded dependencies 2021-01-11 16:29:46 -08:00
Chris Troutner 41a5b24faf Updating README and shell script examples 2021-01-11 16:22:27 -08:00
Chris Troutner 2172d0feff Updating example shell script 2021-01-11 15:33:45 -08:00
Chris Troutner c4664ca173 Merge pull request #86 from Permissionless-Software-Foundation/ct-unstable
fix(bch-js): Bumped to v4.5.4
2021-01-10 15:40:28 -08:00
Chris Troutner 11a7915cb8 fix(bch-js): Bumped to v4.5.4 2021-01-10 15:37:15 -08:00
Chris Troutner 06b944f36a Merge pull request #85 from Permissionless-Software-Foundation/ct-unstable
feat(error handling): update to error handling to pass more information
2021-01-10 15:15:05 -08:00
Chris Troutner 9a8886121d feat(error handling): update to error handling to pass more information 2021-01-10 15:13:33 -08:00
Chris Troutner 89c6d48dfd fix(hydrateUtxos): Passing error message to bch-js 2021-01-09 20:48:10 -08:00
Chris Troutner 4525b99f33 Merge pull request #84 from Permissionless-Software-Foundation/ct-unstable
fix(generateSendOpReturn): Fixed poorly written integration test
2021-01-07 16:42:15 -08:00
Chris Troutner 3d04507948 fixing unit and integration test 2021-01-07 16:40:55 -08:00
Chris Troutner 7e3a447973 fix(generateSendOpReturn): Fixed poorly written integration test 2021-01-07 16:30:12 -08:00
Chris Troutner bdde3a271d Merge pull request #83 from Permissionless-Software-Foundation/ct-unstable
fix(bch-js): Updating to v4.5.2
2021-01-07 13:28:01 -08:00
Chris Troutner 9450c3969b fix(bch-js): Updating to v4.5.2 2021-01-07 13:26:38 -08:00
Chris Troutner 23d66da792 Merge pull request #82 from Permissionless-Software-Foundation/ct-unstable
fix(rate limits): Fixed bug with rate limits
2021-01-07 10:05:58 -08:00
Chris Troutner cb430c20e2 fix(rate limits): Fixed bug with rate limits 2021-01-07 10:04:25 -08:00
Chris Troutner 58ce0e0604 Merge pull request #81 from Permissionless-Software-Foundation/ct-unstable
Rate limits configured with environment variables
2021-01-07 09:13:52 -08:00
Chris Troutner 61485dfe99 fix(rate limits): Configuring rate limits with env vars 2021-01-07 09:11:35 -08:00
Chris Troutner ab4c80b674 Created rate limit isInWhitelist(). Needs tests 2021-01-03 18:20:49 -08:00
18 changed files with 3260 additions and 5037 deletions
+11 -8
View File
@@ -1,6 +1,9 @@
# bch-api
This is a node.js JavaScript REST API server using Express.js. The purpose of this code is to create a REST API server that provides a common interface for working with a Bitcoin Cash full node and various indexers. See [this article](https://troutsblog.com/research/bitcoin-cash/how-to-bch-full-stack-developer) to learn about the 'Cash Stack'. Visit [FullStack.cash](https://fullstack.cash), sign up for a free account, and use this REST API right away with the [bch-js](https://github.com/Permissionless-Software-Foundation/bch-js) JavaScript library.
[![License](https://img.shields.io/npm/l/@psf/bch-js)](https://github.com/Permissionless-Software-Foundation/bch-js/blob/master/LICENSE.md)
[![js-standard-style](https://img.shields.io/badge/javascript-standard%20code%20style-green.svg?style=flat-square)](https://github.com/feross/standard)
This is a REST API server, written in node.js JavaScript, using [Express.js](https://expressjs.com/) framework. The purpose of this code is to create a REST API server that provides a common interface for working with a Bitcoin Cash full node and various indexers. See [this article](https://psfoundation.cash/blog/cash-stack) to learn about the 'Cash Stack'. Visit [FullStack.cash](https://fullstack.cash), sign up for a free account, and use this REST API right away with the [bch-js](https://github.com/Permissionless-Software-Foundation/bch-js) JavaScript library.
This repository is intended to be paired with [bch-js](https://github.com/Permissionless-Software-Foundation/bch-js), an npm JavaScript library for building Bitcoin Cash apps.
@@ -20,7 +23,7 @@ The following features set this repository apart from rest.bitcoin.com:
- Fine grain access is controlled with a JWT token using
[this back end auth server](https://github.com/Permissionless-Software-Foundation/jwt-bch-api) and [this front end](https://github.com/Permissionless-Software-Foundation/jwt-bch-frontend). Can be used to monetize access to the REST API.
- Typescript removed and ES8 JavaScript used instead.
- npm audit run on all dependencies.
- `npm audit fix` frequently run to fix dependencies.
## Live Demo
You can test a live demo of the REST API by running the
@@ -31,17 +34,17 @@ You can bootstrap your own REST API server by downloading and installing the inf
### Configure bch-js
The live servers can be used by [bch-js](https://github.com/Permissionless-Software-Foundation/bch-js) by settings the `restURL` config property to one of these servers:
- BCHN Mainnet REST API server: https://bchn.fullstack.cash/v3/
- ABC Mainnet REST API server: https://abc.fullstack.cash/v3/
- Testnet3 REST API server: https://testnet3.fullstack.cash/v3/
- BCHN Mainnet REST API server: https://bchn.fullstack.cash/v4/
- ABC Mainnet REST API server: https://abc.fullstack.cash/v4/
- Testnet3 REST API server: https://testnet3.fullstack.cash/v4/
- Check server status: https://metrics.fullstack.cash
## Installation
There are two installation paths, depending if you want a *development* or
*production* environment. You'll also need to set up the underlying infrastructure
described on [this page](https://troutsblog.com/research/bitcoin-cash/how-to-bch-full-stack-developer).
described on [this page](https://psfoundation.cash/blog/cash-stack).
This code targets the Ubuntu 18.04 LTS Linux OS.
This code targets the Ubuntu 18.04 LTS Linux OS or higher.
### Development
This is a standard node.js project. The installation is as follows:
@@ -86,7 +89,7 @@ Have questions? Need help? Join our community support
## IPFS
Copies of this repository will occasionally be uploaded and hosted on [IPFS](https://ipfs.io):
- v1.15.4: QmSAerFmDJm6KQp2HC8jsRR5MdL5X39hoUsJYvWNDvrD8m
- v1.25.1: [QmXFzFJHenymhReDc9oGAxbpmvK2fJYnisQ2pJn3gGyKKX](https://ipfs.io/ipfs/QmXFzFJHenymhReDc9oGAxbpmvK2fJYnisQ2pJn3gGyKKX)
## License
[MIT](./LICENSE.md)
+12 -1
View File
@@ -1,11 +1,22 @@
/*
Common configuration settings.
Default settings in this file can be overridden by an environment variable.
*/
const config = {
// This is the same secret used by jwt-bch-api
apiTokenSecret: process.env.TOKENSECRET
? process.env.TOKENSECRET
: 'secret-jwt-token'
: 'secret-jwt-token',
// Rate Limits
anonRateLimit: process.env.ANON_RATE_LIMIT ? Number(process.env.ANON_RATE_LIMIT) : 50,
whitelistRateLimit: process.env.WHITELIST_RATE_LIMIT
? Number(process.env.WHITELIST_RATE_LIMIT)
: 10,
whitelistDomains: process.env.WHITELIST_DOMAINS
? process.env.WHITELIST_DOMAINS.split(',')
: ['fullstack.cash', 'psfoundation.cash']
}
module.exports = config
+31 -11
View File
@@ -1,21 +1,28 @@
#!/bin/bash
# test
# Docker containers for the below infrastructure is described here:
# https://psfoundation.cash/blog/cash-stack
# Pre-synced databases can be downloaded on the CashStrap page:
# https://fullstack.cash/cashstrap
# Which network are you using?
export NETWORK=mainnet
#export NETWORK=testnet
# Full node
export RPC_BASEURL=http://172.17.0.1:8332/
export RPC_IP=172.17.0.1:8332
export RPC_BASEURL=http://$RPC_IP/
export RPC_USERNAME=bitcoin
export RPC_PASSWORD=password
export NETWORK=mainnet
# SLPDB
export SLPDB_URL=http://172.17.0.1:12300/
export SLPDB_PASS=somelongpassword
# Blockbook Indexer
export BLOCKBOOK_URL=https://172.17.0.1:9131/
# Allow node.js to make network calls to https using self-signed certificate.
export NODE_TLS_REJECT_UNAUTHORIZED=0
# Use the same address as SLPDB_URL if you don't have a separate whitelist server.
export SLPDB_WHITELIST_URL=http://172.17.0.1:12300/
# slp-api alternative SLP validator using slp-validate:
# https://github.com/Permissionless-Software-Foundation/slp-api
export SLP_API_URL=http://10.0.0.5:5001/
# Mainnet Fulcrum / ElectrumX
export FULCRUM_URL=172.17.0.1
@@ -26,12 +33,25 @@ export REDIS_PORT=6379
export REDIS_HOST=172.17.0.1
# JWT Token Secret
# This is used to verify JWT tokens generated with jwt-bch-api:
# https://github.com/Permissionless-Software-Foundation/jwt-bch-api
export TOKENSECRET=somelongsecretvalue
# So that bch-api can call bch-js locally.
export LOCAL_RESTURL=http://127.0.0.1:3000/v3/
export LOCAL_RESTURL=http://127.0.0.1:3000/v4/
# slp-api alternative SLP validator.
export SLP_API_URL=http://10.0.0.5:5001/
# Basic Authentication password
export PRO_PASS=somerandomepassword:someotherrandompassword:aThirdPassword
# Whitelisted domains. Automatically give pro-tier rate limit access to apps
# that originate froma domain on the whitelist.
export WHITELIST_DOMAINS=fullstack.cash,psfoundation.cash,torlist.cash
# Rate Limits. Numbers are divided into 1000. e.g. 1000 / 50 = 20 RPM for ANON.
# Requests use the ANON rate limit if they fail to pass in a JWT token.
# ANON = 20 requests per minute (RPM)
export ANON_RATE_LIMIT=50
# 10 = 100 RPM
export WHITELIST_RATE_LIMIT=10
npm start
+32 -11
View File
@@ -1,22 +1,32 @@
#!/bin/bash
# Docker containers for the below infrastructure is described here:
# https://psfoundation.cash/blog/cash-stack
# Pre-synced databases can be downloaded on the CashStrap page:
# https://fullstack.cash/cashstrap
# Which network are you using?
#export NETWORK=mainnet
export NETWORK=testnet
# Full node
export RPC_BASEURL=http://172.17.0.1:18332/
export RPC_IP=172.17.0.1:18332
export RPC_BASEURL=http://$RPC_IP/
export RPC_USERNAME=bitcoin
export RPC_PASSWORD=password
export NETWORK=testnet
# SLPDB
export SLPDB_URL=http://172.17.0.1:13300/
# Blockbook Indexer
export BLOCKBOOK_URL=https://172.17.0.1:19131/
# Allow node.js to make network calls to https using self-signed certificate.
export NODE_TLS_REJECT_UNAUTHORIZED=0
export SLPDB_PASS=somelongpassword
# Use the same address as SLPDB_URL if you don't have a separate whitelist server.
export SLPDB_WHITELIST_URL=http://172.17.0.1:13300/
# slp-api alternative SLP validator using slp-validate:
# https://github.com/Permissionless-Software-Foundation/slp-api
export SLP_API_URL=http://10.0.0.5:5001/
# Mainnet Fulcrum / ElectrumX
export FULCRUM_URL=172.17.0.1
export FULCRUM_PORT=50002
export FULCRUM_PORT=60002
# Redis DB
export REDIS_PORT=6380
@@ -26,9 +36,20 @@ export REDIS_HOST=172.17.0.1
export TOKENSECRET=somelongsecretvalue
# So that bch-api can call bch-js locally.
export LOCAL_RESTURL=http://127.0.0.1:3000/v3/
export LOCAL_RESTURL=http://127.0.0.1:3000/v4/
# slp-api alternative SLP validator.
export SLP_API_URL=http://10.0.0.5:5001/
# Basic Authentication password (optional)
export PRO_PASS=somerandomepassword:someotherrandompassword:aThirdPassword
# Whitelisted domains. Automatically give pro-tier rate limit access to apps
# that originate froma domain on the whitelist.
export WHITELIST_DOMAINS=fullstack.cash,psfoundation.cash,torlist.cash
# Rate Limits. Numbers are divided into 1000. e.g. 1000 / 50 = 20 RPM for ANON.
# Requests use the ANON rate limit if they fail to pass in a JWT token.
# ANON = 20 requests per minute (RPM)
export ANON_RATE_LIMIT=50
# 10 = 100 RPM
export WHITELIST_RATE_LIMIT=10
npm start
+3030 -4950
View File
File diff suppressed because it is too large Load Diff
+9 -16
View File
@@ -17,20 +17,21 @@
"test": "npm run lint && npm run test-v4",
"lint": "standard --env mocha --fix",
"test-v4": "export NETWORK=mainnet && nyc --reporter=text mocha --timeout 60000 test/v4/",
"test:temp": "export NETWORK=mainnet && export TEST=integration && mocha --timeout 25000 test/v4/integration/price.js",
"test:integration": "mocha test/v4/integration",
"test:integration:slpdb": "mocha --timeout 25000 -g '#validate2Single' test/v4/integration/slp*.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"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 && mocha --timeout 25000 -g '#generateSendOpReturn()' test/v4/integration/",
"test:temp2": "mocha test/v4/rate-limits.js"
},
"engines": {
"node": ">=10.15.1"
},
"dependencies": {
"@psf/bch-js": "^4.2.5",
"apidoc": "^0.23.0",
"axios": "^0.19.0",
"@psf/bch-js": "^4.5.4",
"apidoc": "^0.26.0",
"axios": "^0.21.1",
"bitcore-lib-cash": "^8.23.1",
"body-parser": "^1.18.3",
"cookie-parser": "~1.4.3",
@@ -44,7 +45,6 @@
"helmet": "^3.21.2",
"ioredis": "^4.14.1",
"jsonwebtoken": "^8.5.1",
"level": "^6.0.0",
"mkdirp": "^1.0.0",
"mocha": "^7.1.1",
"morgan": "^1.9.1",
@@ -52,8 +52,6 @@
"passport": "^0.4.0",
"passport-anonymous": "^1.0.1",
"passport-http": "^0.3.0",
"pg": "^8.0.0",
"pg-hstore": "^2.3.2",
"rate-limiter-flexible": "^2.0.0",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^4.0.0"
@@ -68,17 +66,12 @@
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-standard": "^4.0.0",
"fs-extra": "^9.0.0",
"nock": "^12.0.0",
"node-mocks-http": "^1.7.0",
"nock": "^13.0.5",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"proxyquire": "^2.1.0",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"semantic-release": "^17.3.0",
"semantic-release": "^17.3.1",
"sinon": "^9.0.0",
"standard": "^14.3.1",
"typescript": "^3.1.4"
"standard": "^14.3.1"
},
"release": {
"publish": [
+2 -2
View File
@@ -262,11 +262,11 @@ function onError (error) {
case 'EACCES':
console.error(`${bind} requires elevated privileges`)
process.exit(1)
break
// break
case 'EADDRINUSE':
console.error(`${bind} is already in use`)
process.exit(1)
break
// break
default:
throw error
}
+37 -9
View File
@@ -12,12 +12,17 @@
'use strict'
// Public npm libraries.
const jwt = require('jsonwebtoken')
// local libraries.
const wlogger = require('../util/winston-logging')
const config = require('../../config')
const ANON_LIMITS = 50
const ANON_LIMITS = config.anonRateLimit
const WHITELIST_RATE_LIMIT = config.whitelistRateLimit
const WHITELIST_DOMAINS = config.whitelistDomains
const INTERNAL_RATE_LIMIT = 1
// Redis
const redisOptions = {
@@ -144,13 +149,11 @@ class RateLimits {
// If the request originates from one of the approved wallet apps, then
// apply paid-access rate limits.
if (
origin &&
(origin.toString().indexOf('fullstack.cash') > -1 ||
origin.toString().indexOf('splitbch.com') > -1 ||
origin.toString().indexOf('slp-api') > -1)
) {
pointsToConsume = 10
// console.log(`origin: ${JSON.stringify(origin, null, 2)}`)
// console.log(`whitelist: ${JSON.stringify(WHITELIST_DOMAINS, null, 2)}`)
const isInWhitelist = _this.isInWhitelist(origin)
if (isInWhitelist) {
pointsToConsume = WHITELIST_RATE_LIMIT
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
}
@@ -161,7 +164,7 @@ class RateLimits {
// Do not comment out this line.
key.toString().indexOf('172.17.') > -1
) {
pointsToConsume = 1
pointsToConsume = INTERNAL_RATE_LIMIT
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
}
@@ -263,6 +266,31 @@ class RateLimits {
throw err
}
}
// Returns a boolean if the origin of the request matches a domain in the
// whitelist.
isInWhitelist (origin) {
try {
const retVal = false // Default value.
if (!origin) return false
// console.log(`WHITELIST_DOMAINS: ${JSON.stringify(WHITELIST_DOMAINS, null, 2)}`)
for (let i = 0; i < WHITELIST_DOMAINS.length; i++) {
const thisDomain = WHITELIST_DOMAINS[i]
if (origin.toString().indexOf(thisDomain) > -1) {
return true
}
}
return retVal
} catch (err) {
wlogger.error('Error in route-ratelimit.js/isInWhitelist(). Returning false by default.')
return false
}
}
}
module.exports = RateLimits
+1 -1
View File
@@ -135,7 +135,7 @@ class Electrum {
const { msg, status } = _this.routeUtils.decodeError(err)
if (msg) {
res.status(status)
return res.json({ error: msg })
return res.json({ success: false, error: msg })
}
// Handle error patterns specific to this route.
+1 -1
View File
@@ -45,7 +45,7 @@ class Encryption {
const { msg, status } = _this.routeUtils.decodeError(err)
if (msg) {
res.status(status)
return res.json({ error: msg })
return res.json({ success: false, error: msg })
}
// Handle error patterns specific to this route.
+9
View File
@@ -175,8 +175,17 @@ function decodeError (err) {
}
}
// Handle general Error objects.
if (err.message) {
return {
message: err.message,
status: 422
}
}
return { msg: false, status: 500 }
} catch (err) {
console.error('unhandled error in route-utils.js/decodeError(): ', err)
wlogger.error('unhandled error in route-utils.js/decodeError(): ', err)
return { msg: false, status: 500 }
}
+6 -1
View File
@@ -1896,6 +1896,8 @@ class Slp {
})
}
// console.log('sendQty: ', sendQty)
// console.log(`tokenUtxos: `, tokenUtxos)
const opReturn = await _this.bchjs.SLP.TokenType1.generateSendOpReturn(
tokenUtxos,
sendQty
@@ -1907,6 +1909,7 @@ class Slp {
res.status(200)
return res.json({ script, outputs: opReturn.outputs })
} catch (err) {
console.log('err: ', err)
wlogger.error('Error in slp.js/generateSendOpReturn().', err)
// Decode the error message.
@@ -1996,9 +1999,11 @@ class Slp {
// Decode the error message.
const { msg, status } = routeUtils.decodeError(err)
console.log('msg: ', msg)
console.log('status: ', status)
if (msg) {
res.status(status)
return res.json({ error: msg })
return res.json({ error: msg, message: msg, success: false })
}
res.status(500)
+9
View File
@@ -154,8 +154,17 @@ class RouteUtils {
}
}
// Handle general Error objects.
if (err.message) {
return {
msg: err.message,
status: 422
}
}
return { msg: false, status: 500 }
} catch (err) {
console.error('unhandled error in route-utils.js/decodeError(): ', err)
wlogger.error('unhandled error in route-utils.js/decodeError(): ', err)
return { msg: false, status: 500 }
}
+32 -12
View File
@@ -1,37 +1,57 @@
#!/bin/bash
# Full node
export RPC_BASEURL=http://<full node ip>:8332/
export RPC_USERNAME=<RPC username>
export RPC_PASSWORD=<RPC password>
# Docker containers for the below infrastructure is described here:
# https://psfoundation.cash/blog/cash-stack
# Pre-synced databases can be downloaded on the CashStrap page:
# https://fullstack.cash/cashstrap
# Which network are you using?
export NETWORK=mainnet
#export NETWORK=testnet
# Full node
export RPC_IP=<ip>:8332
export RPC_BASEURL=http://$RPC_IP/
export RPC_USERNAME=bitcoin
export RPC_PASSWORD=password
# SLPDB
export SLPDB_URL=http://<SLPDB IP>:12300/
export SLPDB_PASS=somelongpassword
# Use the same address as SLPDB_URL if you don't have a separate whitelist server.
export SLPDB_WHITELIST_URL=http://<SLPDB IP>:12300/
# slp-api alternative SLP validator using slp-validate:
# https://github.com/Permissionless-Software-Foundation/slp-api
export SLP_API_URL=http://10.0.0.5:5001/
# Blockbook
export BLOCKBOOK_URL=https://<Blockbook IP>:9131/
# Allow node.js to make network calls to https using self-signed certificate.
export NODE_TLS_REJECT_UNAUTHORIZED=0
# Mainnet Fulcrum / ElectrumX
export FULCRUM_URL=192.168.0.6
export FULCRUM_PORT=50002
# Redis DB - Used for rate limiting - customize to your own Redis installation.
export REDIS_PORT=6379
export REDIS_HOST=172.17.0.1
# JWT Token Secret
# This is used to verify JWT tokens generated with jwt-bch-api:
# https://github.com/Permissionless-Software-Foundation/jwt-bch-api
export TOKENSECRET=somelongpassword
# So that bch-api can call bch-js locally.
export LOCAL_RESTURL=http://127.0.0.1:3000/v3/
export LOCAL_RESTURL=http://127.0.0.1:3000/v4/
# Basic Authentication password
export PRO_PASS=somerandomepassword:someotherrandompassword:aThirdPassword
# Whitelisted domains. Automatically give pro-tier rate limit access to apps
# that originate froma domain on the whitelist.
export WHITELIST_DOMAINS=fullstack.cash,psfoundation.cash,torlist.cash
# Rate Limits. Numbers are divided into 1000. e.g. 1000 / 50 = 20 RPM for ANON.
# Requests use the ANON rate limit if they fail to pass in a JWT token.
# ANON = 20 requests per minute (RPM)
export ANON_RATE_LIMIT=50
# 10 = 100 RPM
export WHITELIST_RATE_LIMIT=10
npm start
+9 -9
View File
@@ -199,11 +199,11 @@ describe('#Electrumx', () => {
})
describe('#getUtxos', () => {
it('should throw 400 if address is empty', async () => {
it('should throw 422 if address is empty', async () => {
const result = await electrumxRoute.getUtxos(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.equal(res.statusCode, 422, 'Expect 422 status code')
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
@@ -233,7 +233,7 @@ describe('#Electrumx', () => {
const result = await electrumxRoute.getUtxos(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.equal(res.statusCode, 422, 'Expect 422 status code')
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
@@ -1063,7 +1063,7 @@ describe('#Electrumx', () => {
const result = await electrumxRoute.getBalance(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.equal(res.statusCode, 422, 'Expect 422 status code')
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
@@ -1093,7 +1093,7 @@ describe('#Electrumx', () => {
const result = await electrumxRoute.getBalance(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.equal(res.statusCode, 422, 'Expect 422 status code')
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
@@ -1350,7 +1350,7 @@ describe('#Electrumx', () => {
const result = await electrumxRoute.getTransactions(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.equal(res.statusCode, 422, 'Expect 422 status code')
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
@@ -1380,7 +1380,7 @@ describe('#Electrumx', () => {
const result = await electrumxRoute.getTransactions(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.equal(res.statusCode, 422, 'Expect 422 status code')
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
@@ -1645,7 +1645,7 @@ describe('#Electrumx', () => {
const result = await electrumxRoute.getMempool(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.equal(res.statusCode, 422, 'Expect 422 status code')
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
@@ -1675,7 +1675,7 @@ describe('#Electrumx', () => {
const result = await electrumxRoute.getMempool(req, res)
// console.log(`result: ${util.inspect(result)}`)
assert.equal(res.statusCode, 400, 'Expect 400 status code')
assert.equal(res.statusCode, 422, 'Expect 422 status code')
assert.property(result, 'error')
assert.include(result.error, 'Unsupported address format')
+2 -2
View File
@@ -110,8 +110,8 @@ describe('#slp', () => {
req.body.tokenUtxos = [
{
tokenId:
'0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1',
decimals: 0,
'38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0',
decimals: 8,
tokenQty: 2
}
]
+24
View File
@@ -445,6 +445,30 @@ describe('#route-ratelimits & jwt-auth', () => {
assert.equal(res.locals.pointsToConsume, 50)
})
})
describe('#isInWhitelist', () => {
it('should return false when no argument is passed in', () => {
const result = rateLimits.isInWhitelist()
assert.equal(result, false)
})
it('should return false when origin is not in the whitelist', () => {
const origin = 'blah.com'
const result = rateLimits.isInWhitelist(origin)
assert.equal(result, false)
})
it('should return true when origin is in the whitelist', () => {
const origin = 'message.fullstack.cash'
const result = rateLimits.isInWhitelist(origin)
assert.equal(result, true)
})
})
})
// Generates a Basic authorization header.
+3 -3
View File
@@ -1287,7 +1287,7 @@ describe('#SLP', () => {
})
})
describe('generateSendOpReturn()', () => {
describe('#generateSendOpReturn()', () => {
const generateSendOpReturn = slpRoute.generateSendOpReturn
// Validate tokenUtxos input
it('should throw 400 if tokenUtxos is missing', async () => {
@@ -1363,8 +1363,8 @@ describe('#SLP', () => {
req.body.tokenUtxos = [
{
tokenId:
'0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1',
decimals: 0,
'38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0',
decimals: 8,
tokenQty: 2
}
]