From de5b5deace9b00ca7fc15b2bbc0459f3242e4d91 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 26 May 2020 15:02:46 -0700 Subject: [PATCH] fix(rate-limit e2e): Updating e2e tests for rate limits --- test/e2e/rate-limits/anonymous-rate-limits.js | 2 +- test/e2e/rate-limits/free-rate-limits.js | 47 +++++++++++++++---- test/e2e/rate-limits/indexer-rate-limits.js | 4 +- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/test/e2e/rate-limits/anonymous-rate-limits.js b/test/e2e/rate-limits/anonymous-rate-limits.js index 6bee35c..50643c7 100644 --- a/test/e2e/rate-limits/anonymous-rate-limits.js +++ b/test/e2e/rate-limits/anonymous-rate-limits.js @@ -8,7 +8,7 @@ const assert = require("chai").assert -const RESTURL = `https://api.bchjs.cash/v3/` +const RESTURL = `https://api.fullstack.cash/v3/` // const RESTURL = `http://localhost:3000/v3/` const BCHJS = require("../../../src/bch-js") diff --git a/test/e2e/rate-limits/free-rate-limits.js b/test/e2e/rate-limits/free-rate-limits.js index b1301f0..4a4b4dd 100644 --- a/test/e2e/rate-limits/free-rate-limits.js +++ b/test/e2e/rate-limits/free-rate-limits.js @@ -9,13 +9,12 @@ const assert = require("chai").assert -// const JWT_TOKEN = `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkYmM5ZTI3YWIwMDI4M2E1MDhkYzQ4OSIsImlhdCI6MTU3MjY0MjM1NCwiZXhwIjoxNTc1MjM0MzU0fQ.6dzUh10UXoQXjJujRZ0AMSBhz0ElM1Cc-rCyb50PDqI` const JWT_TOKEN = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkYmM5ZTI3YWIwMDI4M2E1MDhkYzQ4OSIsImlhdCI6MTU3MjgzMjAzNywiZXhwIjoxNTc1NDI0MDM3fQ.FygzeHYGH5vsXurFlI7ZFTmS2eyLDt3iglhFWgIZRxY" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2YyMDIyMWMxMDAxMmFkOTQwMSIsImVtYWlsIjoiZGVtb0BkZW1vLmNvbSIsImFwaUxldmVsIjoxMCwicmF0ZUxpbWl0IjozLCJpYXQiOjE1OTA1Mjk2NzgsImV4cCI6MTU5MzEyMTY3OH0.4q5MFDCcVx0FusivJPiEIj3w8nhFG7ZV5IhJS7faUlc" 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 }) @@ -29,18 +28,42 @@ 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" + // 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 { - for (let i = 0; i < 5; i++) await bchjs.Blockbook.balance(addr) + const addr = "bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0" + + for (let i = 0; i < 15; i++) { + const result = await await bchjs.Blockbook.balance(addr) - assert.equal(true, false, "unexpected result") + if (i === 5) { + // console.log(`validating 5th call: ${i}`) + assert.property(result, "address", "more than 3 calls allowed") + } + } } catch (err) { // console.log(`err: `, err) - assert.include(err.error, "Too many requests") + assert.include( + err.error, + "currently 10 requests", + "more than 10 not allowed" + ) + assert.include(err.error, 10) + assert.notInclude(err.error, 3) } - }).timeout(10000) + }).timeout(20000) it("should allow up to 10 RPM to full node, then throw error", async () => { try { @@ -55,7 +78,11 @@ describe("#free rate limits", () => { } catch (err) { // console.log(`validating after 10th call`) // console.log(`err: `, err) - assert.include(err.error, "Too many requests", "more than 10 not allowed") + assert.include( + err.error, + "currently 10 requests", + "more than 10 not allowed" + ) assert.include(err.error, 10) assert.notInclude(err.error, 3) } diff --git a/test/e2e/rate-limits/indexer-rate-limits.js b/test/e2e/rate-limits/indexer-rate-limits.js index 09d5be1..8207f29 100644 --- a/test/e2e/rate-limits/indexer-rate-limits.js +++ b/test/e2e/rate-limits/indexer-rate-limits.js @@ -10,11 +10,11 @@ const assert = require("chai").assert const JWT_TOKEN = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkYmY4MjA1YTYwODliMjliYTlhZjc1OSIsImlhdCI6MTU3MjgzMjEwNywiZXhwIjoxNTc1NDI0MTA3fQ.UD-36TKwN65-zePwNzujGmHeQ60fKqYPunawGxktwws" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2JmMDIyMWMxMDAxMmFkOTNmZiIsImVtYWlsIjoiY2hyaXMudHJvdXRuZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjQwLCJyYXRlTGltaXQiOjMsImlhdCI6MTU5MDQzMjIxNywiZXhwIjoxNTkzMDI0MjE3fQ.R0Euhutd5FHCxLlSzjq1TYsGjI6iua_AguWIeLK2xCU" 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 })