diff --git a/test/e2e/rate-limits/anonymous-rate-limits.js b/test/e2e/rate-limits/anonymous-rate-limits.js index 50643c7..3b3fcde 100644 --- a/test/e2e/rate-limits/anonymous-rate-limits.js +++ b/test/e2e/rate-limits/anonymous-rate-limits.js @@ -4,6 +4,7 @@ To Run Test: - Update the RESTURL for bch-api you want to test against. + - Ensure the BCHJSTOKEN environment variable is set to an empty string. */ const assert = require("chai").assert @@ -31,11 +32,11 @@ describe("#anonymous rate limits", () => { it("should throw error when rate limit exceeded", async () => { try { - for (let i = 0; i < 5; i++) await bchjs.Control.getNetworkInfo() + for (let i = 0; i < 22; i++) await bchjs.Control.getNetworkInfo() - assert.equal(true, false, "unexpected result") + assert.fail("Unexpected result") } catch (err) { assert.include(err.error, "Too many requests") } - }).timeout(5000) + }).timeout(20000) }) diff --git a/test/e2e/rate-limits/free-rate-limits.js b/test/e2e/rate-limits/free-rate-limits.js index 4a4b4dd..f31d1d4 100644 --- a/test/e2e/rate-limits/free-rate-limits.js +++ b/test/e2e/rate-limits/free-rate-limits.js @@ -10,7 +10,7 @@ const assert = require("chai").assert const JWT_TOKEN = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2YyMDIyMWMxMDAxMmFkOTQwMSIsImVtYWlsIjoiZGVtb0BkZW1vLmNvbSIsImFwaUxldmVsIjoxMCwicmF0ZUxpbWl0IjozLCJpYXQiOjE1OTA1Mjk2NzgsImV4cCI6MTU5MzEyMTY3OH0.4q5MFDCcVx0FusivJPiEIj3w8nhFG7ZV5IhJS7faUlc" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2YyMDIyMWMxMDAxMmFkOTQwMSIsImVtYWlsIjoiZGVtb0BkZW1vLmNvbSIsImFwaUxldmVsIjoxMCwicmF0ZUxpbWl0IjozLCJpYXQiOjE2MDQ4NTQ2OTEsImV4cCI6MTYwNzQ0NjY5MX0.iwse0z0KDKHx9graCxcOwj6lSlfKQAb1zLhmjvygvts" const BCHJS = require("../../../src/bch-js") const bchjs = new BCHJS({ @@ -28,19 +28,6 @@ describe("#free rate limits", () => { assert.property(result, "balance") }).timeout(5000) - // it("should throw error when rate limit exceeded 3 RPM for indexer endpoints", async () => { - // const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" - // - // try { - // for (let i = 0; i < 5; i++) await bchjs.Blockbook.balance(addr) - // - // assert.equal(true, false, "unexpected result") - // } catch (err) { - // // console.log(`err: `, err) - // assert.include(err.error, "Too many requests") - // } - // }).timeout(10000) - it("should allow up to 10 RPM to indexer, then throw error", async () => { try { const addr = "bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0" @@ -87,4 +74,15 @@ describe("#free rate limits", () => { assert.notInclude(err.error, 3) } }).timeout(20000) + + it("should throw error when rate limit exceeded 20 RPM for indexer endpoints", async () => { + try { + for (let i = 0; i < 22; i++) await bchjs.Control.getNetworkInfo() + + assert.fail("unexpected result") + } catch (err) { + // console.log(`err: `, err) + assert.include(err.error, "Too many requests") + } + }).timeout(20000) }) diff --git a/test/e2e/rate-limits/full-node-rate-limits.js b/test/e2e/rate-limits/full-node-rate-limits.js index 99c62b8..2e7deb9 100644 --- a/test/e2e/rate-limits/full-node-rate-limits.js +++ b/test/e2e/rate-limits/full-node-rate-limits.js @@ -4,17 +4,17 @@ To Run Test: - Update the restURL for bch-api you want to test against. - - Update the JWT_TOKEN value with a current full-node-level JWT token. + - Update the JWT_TOKEN value with a paid tier JWT token. */ const assert = require("chai").assert const JWT_TOKEN = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkYmY4MjA1YTYwODliMjliYTlhZjc1OSIsImlhdCI6MTU3MjgzMTgzOSwiZXhwIjoxNTc1NDIzODM5fQ.sFFS4AF04U2aUwmKkBIfnMQIUoygzV9UMVzzQuwctpY" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2JmMDIyMWMxMDAxMmFkOTNmZiIsImVtYWlsIjoiY2hyaXMudHJvdXRuZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjQwLCJyYXRlTGltaXQiOjMsImlhdCI6MTYwMzIyNzEwNCwiZXhwIjoxNjA1ODE5MTA0fQ.CV36grzdD36Ht3BwZGHG4XU40CVDzMRw9Ars1x1r27M" const BCHJS = require("../../../src/bch-js") const bchjs = new BCHJS({ - restURL: `https://api.bchjs.cash/v3/`, + restURL: `https://api.fullstack.cash/v3/`, // restURL: `http://localhost:3000/v3/`, apiToken: JWT_TOKEN }) @@ -28,21 +28,22 @@ describe("#full node rate limits", () => { assert.property(result, "balance") }).timeout(5000) - it("should throw error when rate limit exceeded 3 RPM for indexer endpoints", async () => { - const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" + // CT 11/8/20: New rate limits make this test invalid. + // it("should throw error when rate limit exceeded 20 RPM for indexer endpoints", async () => { + // const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" + // + // try { + // for (let i = 0; i < 22; i++) await bchjs.Electrumx.balance(addr) + // + // assert.fail("unexpected result") + // } catch (err) { + // // console.log(`err: `, err) + // assert.include(err.error, "Too many requests") + // } + // }).timeout(10000) - try { - for (let i = 0; i < 5; i++) await bchjs.Blockbook.balance(addr) - - assert.equal(true, false, "unexpected result") - } catch (err) { - // console.log(`err: `, err) - assert.include(err.error, "Too many requests") - } - }).timeout(10000) - - it("should allow more than 10 RPM to full node", async () => { - for (let i = 0; i < 20; i++) { + it("should allow more than 20 RPM to full node", async () => { + for (let i = 0; i < 22; i++) { const result = await bchjs.Control.getNetworkInfo() if (i === 5) { @@ -55,10 +56,11 @@ describe("#full node rate limits", () => { assert.property(result, "version", "more than 10 calls allowed") } } - }).timeout(10000) + }).timeout(20000) it("should throw error for more than 100 RPM to fullnode", async () => { try { + console.log(`This test usually doesn't pass, because of latency.`) for (let i = 0; i < 100; i++) await bchjs.Control.getNetworkInfo() } catch (err) { // console.log(`validating after 10th call`) @@ -66,5 +68,5 @@ describe("#full node rate limits", () => { assert.include(err.error, "Too many requests") assert.include(err.error, 100) } - }).timeout(30000) + }).timeout(45000) }) diff --git a/test/e2e/rate-limits/indexer-rate-limits.js b/test/e2e/rate-limits/indexer-rate-limits.js index 8207f29..a7262fd 100644 --- a/test/e2e/rate-limits/indexer-rate-limits.js +++ b/test/e2e/rate-limits/indexer-rate-limits.js @@ -10,7 +10,7 @@ const assert = require("chai").assert const JWT_TOKEN = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2JmMDIyMWMxMDAxMmFkOTNmZiIsImVtYWlsIjoiY2hyaXMudHJvdXRuZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjQwLCJyYXRlTGltaXQiOjMsImlhdCI6MTU5MDQzMjIxNywiZXhwIjoxNTkzMDI0MjE3fQ.R0Euhutd5FHCxLlSzjq1TYsGjI6iua_AguWIeLK2xCU" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2JmMDIyMWMxMDAxMmFkOTNmZiIsImVtYWlsIjoiY2hyaXMudHJvdXRuZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjQwLCJyYXRlTGltaXQiOjMsImlhdCI6MTYwMzIyNzEwNCwiZXhwIjoxNjA1ODE5MTA0fQ.CV36grzdD36Ht3BwZGHG4XU40CVDzMRw9Ars1x1r27M" const BCHJS = require("../../../src/bch-js") const bchjs = new BCHJS({ @@ -20,8 +20,8 @@ const bchjs = new BCHJS({ }) describe("#full node rate limits", () => { - it("should allow more than 10 RPM to full node", async () => { - for (let i = 0; i < 20; i++) { + it("should allow more than 20 RPM to full node", async () => { + for (let i = 0; i < 22; i++) { const result = await bchjs.Control.getNetworkInfo() if (i === 5) { @@ -34,12 +34,12 @@ describe("#full node rate limits", () => { assert.property(result, "version", "more than 10 calls allowed") } } - }).timeout(30000) + }).timeout(45000) - it("should allow more than 10 RPM to an indexer", async () => { + it("should allow more than 20 RPM to an indexer", async () => { const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" - for (let i = 0; i < 20; i++) { + for (let i = 0; i < 22; i++) { const result = await bchjs.Blockbook.balance(addr) if (i === 5) { @@ -52,5 +52,5 @@ describe("#full node rate limits", () => { assert.property(result, "balance", "more than 10 calls allowed") } } - }).timeout(30000) + }).timeout(45000) })