mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 17:22:04 -07:00
fix(linting): Switching to standard linter. Fixed linting errors
This commit is contained in:
@@ -4,42 +4,42 @@
|
||||
in the tests below to match the rate limit setting in your own installation.
|
||||
*/
|
||||
|
||||
"use strict"
|
||||
'use strict'
|
||||
|
||||
const chai = require("chai")
|
||||
const chai = require('chai')
|
||||
const assert = chai.assert
|
||||
const axios = require("axios")
|
||||
const axios = require('axios')
|
||||
|
||||
// Used for debugging.
|
||||
const util = require("util")
|
||||
const util = require('util')
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
// const SERVER = `http://192.168.0.36:12400/v3/`
|
||||
const SERVER = `http://localhost:3000/v3/`
|
||||
const SERVER = 'http://localhost:3000/v3/'
|
||||
|
||||
const TEST_JWT =
|
||||
"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlM2EwNDE1ZWIyOWE5NjJkYTI3MDhiNCIsImFwaUxldmVsIjowLCJyYXRlTGltaXQiOjEwLCJpYXQiOjE1ODA4NjA0NjcsImV4cCI6MTU4MzQ1MjQ2N30.fuY5S-YrF0J11h5uyMjPe7wiVkYRnIyXi4dL9-V-C6pLJm33p0dSq_pSheVVWw78n5kAvL_9kFHngbnmQiOJYQ"
|
||||
'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlM2EwNDE1ZWIyOWE5NjJkYTI3MDhiNCIsImFwaUxldmVsIjowLCJyYXRlTGltaXQiOjEwLCJpYXQiOjE1ODA4NjA0NjcsImV4cCI6MTU4MzQ1MjQ2N30.fuY5S-YrF0J11h5uyMjPe7wiVkYRnIyXi4dL9-V-C6pLJm33p0dSq_pSheVVWw78n5kAvL_9kFHngbnmQiOJYQ'
|
||||
|
||||
describe("#rate limits", () => {
|
||||
it("should get control/getNetworkInfo() with no auth", async () => {
|
||||
describe('#rate limits', () => {
|
||||
it('should get control/getNetworkInfo() with no auth', async () => {
|
||||
const options = {
|
||||
method: "GET",
|
||||
method: 'GET',
|
||||
url: `${SERVER}control/getNetworkInfo`
|
||||
}
|
||||
|
||||
const result = await axios(options)
|
||||
//console.log(`result.status: ${result.status}`)
|
||||
// console.log(`result.status: ${result.status}`)
|
||||
// console.log(`result.data: ${util.inspect(result.data)}`)
|
||||
|
||||
assert.equal(result.status, 200)
|
||||
assert.hasAnyKeys(result.data, ["version"])
|
||||
assert.hasAnyKeys(result.data, ['version'])
|
||||
})
|
||||
|
||||
it("should trigger rate-limit handler if rate limits exceeds 30 request per minute", async () => {
|
||||
it('should trigger rate-limit handler if rate limits exceeds 30 request per minute', async () => {
|
||||
try {
|
||||
// Actual rate limit is 60 per minute X 4 nodes = 240 rpm.
|
||||
const options = {
|
||||
method: "GET",
|
||||
method: 'GET',
|
||||
url: `${SERVER}control/getNetworkInfo`
|
||||
}
|
||||
|
||||
@@ -51,29 +51,29 @@ describe("#rate limits", () => {
|
||||
|
||||
await Promise.all(promises)
|
||||
|
||||
assert.equal(true, false, "Unexpected result!")
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
//console.log(`err.response: ${util.inspect(err.response)}`)
|
||||
// console.log(`err.response: ${util.inspect(err.response)}`)
|
||||
|
||||
assert.equal(err.response.status, 429)
|
||||
assert.include(err.response.data.error, "Too many requests")
|
||||
assert.include(err.response.data.error, 'Too many requests')
|
||||
}
|
||||
})
|
||||
|
||||
it("should not trigger rate-limit handler if correct pro-tier password is used", async () => {
|
||||
it('should not trigger rate-limit handler if correct pro-tier password is used', async () => {
|
||||
try {
|
||||
const username = "BITBOX"
|
||||
const username = 'BITBOX'
|
||||
|
||||
// Pro-tier is accessed by using the right password.
|
||||
const password = "BITBOX"
|
||||
//const password = "something"
|
||||
const password = 'BITBOX'
|
||||
// const password = "something"
|
||||
|
||||
const combined = `${username}:${password}`
|
||||
const base64Credential = Buffer.from(combined).toString("base64")
|
||||
const base64Credential = Buffer.from(combined).toString('base64')
|
||||
const readyCredential = `Basic ${base64Credential}`
|
||||
|
||||
const options = {
|
||||
method: "GET",
|
||||
method: 'GET',
|
||||
url: `${SERVER}control/getNetworkInfo`,
|
||||
headers: { Authorization: readyCredential }
|
||||
}
|
||||
@@ -86,33 +86,33 @@ describe("#rate limits", () => {
|
||||
|
||||
await Promise.all(promises)
|
||||
|
||||
assert.equal(true, true, "Not throwing an error is a pass!")
|
||||
assert.equal(true, true, 'Not throwing an error is a pass!')
|
||||
} catch (err) {
|
||||
// console.log(`err.response: ${util.inspect(err.response)}`)
|
||||
|
||||
assert.equal(
|
||||
true,
|
||||
false,
|
||||
"This error handler should not have been triggered. Is the password correct?"
|
||||
'This error handler should not have been triggered. Is the password correct?'
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it("should trigger rate-limit handler if rate limits exceeds pro-tier limit", async () => {
|
||||
it('should trigger rate-limit handler if rate limits exceeds pro-tier limit', async () => {
|
||||
try {
|
||||
const username = "BITBOX"
|
||||
const username = 'BITBOX'
|
||||
|
||||
// Pro-tier is accessed by using the right password.
|
||||
const password = "BITBOX"
|
||||
//const password = "something"
|
||||
const password = 'BITBOX'
|
||||
// const password = "something"
|
||||
|
||||
const combined = `${username}:${password}`
|
||||
const base64Credential = Buffer.from(combined).toString("base64")
|
||||
const base64Credential = Buffer.from(combined).toString('base64')
|
||||
const readyCredential = `Basic ${base64Credential}`
|
||||
|
||||
// Actual rate limit is 60 per minute X 4 nodes = 240 rpm.
|
||||
const options = {
|
||||
method: "GET",
|
||||
method: 'GET',
|
||||
url: `${SERVER}control/getNetworkInfo`,
|
||||
headers: { Authorization: readyCredential }
|
||||
}
|
||||
@@ -125,20 +125,20 @@ describe("#rate limits", () => {
|
||||
|
||||
await Promise.all(promises)
|
||||
|
||||
assert.equal(true, false, "Unexpected result!")
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
} catch (err) {
|
||||
//console.log(`err.response: ${util.inspect(err.response)}`)
|
||||
// console.log(`err.response: ${util.inspect(err.response)}`)
|
||||
|
||||
assert.equal(err.response.status, 429)
|
||||
assert.include(err.response.data.error, "Too many requests")
|
||||
assert.include(err.response.data.error, 'Too many requests')
|
||||
}
|
||||
})
|
||||
|
||||
it("should unlock pro-tier for a valid JWT token", async () => {
|
||||
it('should unlock pro-tier for a valid JWT token', async () => {
|
||||
try {
|
||||
// Actual rate limit is 60 per minute X 4 nodes = 240 rpm.
|
||||
const options = {
|
||||
method: "GET",
|
||||
method: 'GET',
|
||||
url: `${SERVER}control/`,
|
||||
headers: {
|
||||
Authorization: `Token ${TEST_JWT}`
|
||||
@@ -153,12 +153,12 @@ describe("#rate limits", () => {
|
||||
|
||||
await Promise.all(promises)
|
||||
|
||||
//assert.equal(true, false, "Unexpected result!")
|
||||
assert.equal(true, true, "Not throwing an error is a pass!")
|
||||
// assert.equal(true, false, "Unexpected result!")
|
||||
assert.equal(true, true, 'Not throwing an error is a pass!')
|
||||
} catch (err) {
|
||||
console.log(`err.response: ${util.inspect(err.response)}`)
|
||||
|
||||
assert.equal(true, false, "Unexpected result!")
|
||||
assert.equal(true, false, 'Unexpected result!')
|
||||
}
|
||||
// Override default timeout for this test.
|
||||
}).timeout(20000)
|
||||
|
||||
@@ -9,129 +9,129 @@
|
||||
so it is omitted here.
|
||||
*/
|
||||
|
||||
"use strict"
|
||||
'use strict'
|
||||
|
||||
const chai = require("chai")
|
||||
const chai = require('chai')
|
||||
const assert = chai.assert
|
||||
const rawtransactions = require("../../../dist/routes/v2/rawtransactions")
|
||||
const rp = require("request-promise")
|
||||
// const rawtransactions = require('../../../dist/routes/v2/rawtransactions')
|
||||
const rp = require('request-promise')
|
||||
|
||||
// Used for debugging.
|
||||
const util = require("util")
|
||||
const util = require('util')
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
const mockData = require("../mocks/raw-transactions-mocks")
|
||||
// const mockData = require('../mocks/raw-transactions-mocks')
|
||||
|
||||
describe("#Raw-Transactions", () => {
|
||||
describe("#root", () => {
|
||||
it(`should return root`, async () => {
|
||||
describe('#Raw-Transactions', () => {
|
||||
describe('#root', () => {
|
||||
it('should return root', async () => {
|
||||
const options = {
|
||||
method: "GET",
|
||||
uri: `http://localhost:3000/v2/rawtransactions/`,
|
||||
method: 'GET',
|
||||
uri: 'http://localhost:3000/v2/rawtransactions/',
|
||||
resolveWithFullResponse: true,
|
||||
json: true
|
||||
}
|
||||
|
||||
const result = await rp(options)
|
||||
//console.log(`result: ${JSON.stringify(result, null, 0)}`)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 0)}`)
|
||||
|
||||
assert.equal(result.body.status, "rawtransactions")
|
||||
assert.equal(result.body.status, 'rawtransactions')
|
||||
})
|
||||
})
|
||||
|
||||
describe("#whCreateTx", () => {
|
||||
it(`should return tx hex`, async () => {
|
||||
describe('#whCreateTx', () => {
|
||||
it('should return tx hex', async () => {
|
||||
const minIn = {
|
||||
txid:
|
||||
"f7ed9cf23dee85910f6269c9a101a75fcfd2f3c6fc81f17fad824ff7aaf99ab2",
|
||||
'f7ed9cf23dee85910f6269c9a101a75fcfd2f3c6fc81f17fad824ff7aaf99ab2',
|
||||
vout: 1
|
||||
}
|
||||
|
||||
const options = {
|
||||
method: "PUT",
|
||||
uri: `http://localhost:3000/v2/rawtransactions/create`,
|
||||
method: 'PUT',
|
||||
uri: 'http://localhost:3000/v2/rawtransactions/create',
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
body: {
|
||||
//inputs: [mockData.mockWHCreateInput],
|
||||
// inputs: [mockData.mockWHCreateInput],
|
||||
inputs: [minIn],
|
||||
outputs: {}
|
||||
}
|
||||
}
|
||||
|
||||
const result = await rp(options)
|
||||
//console.log(`result.body: ${JSON.stringify(result.body, null, 0)}`)
|
||||
// console.log(`result.body: ${JSON.stringify(result.body, null, 0)}`)
|
||||
|
||||
assert.equal(
|
||||
result.body,
|
||||
"0200000001b29af9aaf74f82ad7ff181fcc6f3d2cf5fa701a1c969620f9185ee3df29cedf70100000000ffffffff0000000000"
|
||||
'0200000001b29af9aaf74f82ad7ff181fcc6f3d2cf5fa701a1c969620f9185ee3df29cedf70100000000ffffffff0000000000'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#whOpReturn", () => {
|
||||
it(`should return tx hex`, async () => {
|
||||
describe('#whOpReturn', () => {
|
||||
it('should return tx hex', async () => {
|
||||
const options = {
|
||||
method: "PUT",
|
||||
uri: `http://localhost:3000/v2/rawtransactions/opreturn`,
|
||||
method: 'PUT',
|
||||
uri: 'http://localhost:3000/v2/rawtransactions/opreturn',
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
body: {
|
||||
rawtx: "01000000000000000000",
|
||||
payload: "00000000000000020000000006dac2c0"
|
||||
rawtx: '01000000000000000000',
|
||||
payload: '00000000000000020000000006dac2c0'
|
||||
}
|
||||
}
|
||||
|
||||
const result = await rp(options)
|
||||
//console.log(`result.body: ${JSON.stringify(result.body, null, 0)}`)
|
||||
// console.log(`result.body: ${JSON.stringify(result.body, null, 0)}`)
|
||||
|
||||
assert.equal(
|
||||
result.body,
|
||||
"0100000000010000000000000000166a140877686300000000000000020000000006dac2c000000000"
|
||||
'0100000000010000000000000000166a140877686300000000000000020000000006dac2c000000000'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#whReference", () => {
|
||||
it(`should return tx hex`, async () => {
|
||||
describe('#whReference', () => {
|
||||
it('should return tx hex', async () => {
|
||||
const options = {
|
||||
method: "PUT",
|
||||
uri: `http://localhost:3000/v2/rawtransactions/reference`,
|
||||
method: 'PUT',
|
||||
uri: 'http://localhost:3000/v2/rawtransactions/reference',
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
body: {
|
||||
rawtx:
|
||||
"0100000001a7a9402ecd77f3c9f745793c9ec805bfa2e14b89877581c734c774864247e6f50400000000ffffffff03aa0a0000000000001976a9146d18edfe073d53f84dd491dae1379f8fb0dfe5d488ac5c0d0000000000004751210252ce4bdd3ce38b4ebbc5a6e1343608230da508ff12d23d85b58c964204c4cef3210294cc195fc096f87d0f813a337ae7e5f961b1c8a18f1f8604a909b3a5121f065b52aeaa0a0000000000001976a914946cb2e08075bcbaf157e47bcb67eb2b2339d24288ac00000000",
|
||||
destination: "bitcoincash:qrn60nerx5zug4u4hal06atep3lzhtecvy4pxk75lf",
|
||||
'0100000001a7a9402ecd77f3c9f745793c9ec805bfa2e14b89877581c734c774864247e6f50400000000ffffffff03aa0a0000000000001976a9146d18edfe073d53f84dd491dae1379f8fb0dfe5d488ac5c0d0000000000004751210252ce4bdd3ce38b4ebbc5a6e1343608230da508ff12d23d85b58c964204c4cef3210294cc195fc096f87d0f813a337ae7e5f961b1c8a18f1f8604a909b3a5121f065b52aeaa0a0000000000001976a914946cb2e08075bcbaf157e47bcb67eb2b2339d24288ac00000000',
|
||||
destination: 'bitcoincash:qrn60nerx5zug4u4hal06atep3lzhtecvy4pxk75lf',
|
||||
amount: 0.005
|
||||
}
|
||||
}
|
||||
|
||||
const result = await rp(options)
|
||||
//console.log(`result.body: ${JSON.stringify(result.body, null, 0)}`)
|
||||
// console.log(`result.body: ${JSON.stringify(result.body, null, 0)}`)
|
||||
|
||||
assert.isString(result.body)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#whChangeOutput", () => {
|
||||
it(`should return tx hex`, async () => {
|
||||
describe('#whChangeOutput', () => {
|
||||
it('should return tx hex', async () => {
|
||||
const options = {
|
||||
method: "PUT",
|
||||
uri: `http://localhost:3000/v2/rawtransactions/change`,
|
||||
method: 'PUT',
|
||||
uri: 'http://localhost:3000/v2/rawtransactions/change',
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
body: {
|
||||
rawtx:
|
||||
"0100000001b15ee60431ef57ec682790dec5a3c0d83a0c360633ea8308fbf6d5fc10a779670400000000ffffffff025c0d00000000000047512102f3e471222bb57a7d416c82bf81c627bfcd2bdc47f36e763ae69935bba4601ece21021580b888ff56feb27f17f08802ebed26258c23697d6a462d43fc13b565fda2dd52aeaa0a0000000000001976a914946cb2e08075bcbaf157e47bcb67eb2b2339d24288ac00000000",
|
||||
destination: "bitcoincash:qrn60nerx5zug4u4hal06atep3lzhtecvy4pxk75lf",
|
||||
'0100000001b15ee60431ef57ec682790dec5a3c0d83a0c360633ea8308fbf6d5fc10a779670400000000ffffffff025c0d00000000000047512102f3e471222bb57a7d416c82bf81c627bfcd2bdc47f36e763ae69935bba4601ece21021580b888ff56feb27f17f08802ebed26258c23697d6a462d43fc13b565fda2dd52aeaa0a0000000000001976a914946cb2e08075bcbaf157e47bcb67eb2b2339d24288ac00000000',
|
||||
destination: 'bitcoincash:qrn60nerx5zug4u4hal06atep3lzhtecvy4pxk75lf',
|
||||
prevtxs: [
|
||||
{
|
||||
txid:
|
||||
"6779a710fcd5f6fb0883ea3306360c3ad8c0a3c5de902768ec57ef3104e65eb1",
|
||||
'6779a710fcd5f6fb0883ea3306360c3ad8c0a3c5de902768ec57ef3104e65eb1',
|
||||
vout: 4,
|
||||
scriptPubKey:
|
||||
"76a9147b25205fd98d462880a3e5b0541235831ae959e588ac",
|
||||
'76a9147b25205fd98d462880a3e5b0541235831ae959e588ac',
|
||||
value: 0.00068257
|
||||
}
|
||||
],
|
||||
@@ -140,43 +140,43 @@ describe("#Raw-Transactions", () => {
|
||||
}
|
||||
|
||||
const result = await rp(options)
|
||||
//console.log(`result.body: ${JSON.stringify(result.body, null, 0)}`)
|
||||
// console.log(`result.body: ${JSON.stringify(result.body, null, 0)}`)
|
||||
|
||||
assert.isString(result.body)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#whInput", () => {
|
||||
it(`should return tx hex`, async () => {
|
||||
describe('#whInput', () => {
|
||||
it('should return tx hex', async () => {
|
||||
const options = {
|
||||
method: "PUT",
|
||||
uri: `http://localhost:3000/v2/rawtransactions/input`,
|
||||
method: 'PUT',
|
||||
uri: 'http://localhost:3000/v2/rawtransactions/input',
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
body: {
|
||||
txid:
|
||||
"b006729017df05eda586df9ad3f8ccfee5be340aadf88155b784d1fc0e8342ee",
|
||||
'b006729017df05eda586df9ad3f8ccfee5be340aadf88155b784d1fc0e8342ee',
|
||||
n: 0
|
||||
}
|
||||
}
|
||||
|
||||
const result = await rp(options)
|
||||
//console.log(`result.body: ${JSON.stringify(result.body, null, 0)}`)
|
||||
// console.log(`result.body: ${JSON.stringify(result.body, null, 0)}`)
|
||||
|
||||
assert.isString(result.body)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#getRawTransaction", () => {
|
||||
it(`should return tx hex`, async () => {
|
||||
describe('#getRawTransaction', () => {
|
||||
it('should return tx hex', async () => {
|
||||
const options = {
|
||||
method: "POST",
|
||||
uri: `http://localhost:3000/v2/rawtransactions/getRawTransaction`,
|
||||
method: 'POST',
|
||||
uri: 'http://localhost:3000/v2/rawtransactions/getRawTransaction',
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
body: {
|
||||
txids: [
|
||||
"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
|
||||
'0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098'
|
||||
],
|
||||
verbose: true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user