diff --git a/README.md b/README.md index e9ff2250abf..4baf220afb3 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ yarn add web3 | test | Uses `jest` to run unit tests in each package | | test:integration | Uses `jest` to run tests under `/test/integration` in each package | | test:unit | Uses `jest` to run tests under `/test/unit` in each package | +| test:manual | Runs manual tests under `test/manual` in the web3 package | [npm-url]: https://npmjs.org/package/web3 [downloads-image]: https://img.shields.io/npm/dm/web3?label=npm%20downloads diff --git a/package.json b/package.json index 6adc68ec73b..d8122891087 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,8 @@ "test:manual:stress:data": "packages/web3/test/stress/start.sh", "test:manual:stress:validation": "npx ts-node packages/web3/test/stress/validator.ts", "test:manual:stress": "yarn test:manual:stress:data && yarn test:manual:stress:validation", + "test:manual:long-connection-ws":"node ./packages/web3/test/manual/long_ws_tests/nodejs_test/long_connection_ws.js", + "test:manual":"yarn test:manual:stress && yarn test:manual:long-connection-ws", "husky:install": "husky install", "husky:uninstall": "husky uninstall", "postinstall": "yarn build", diff --git a/packages/web3/test/manual/long_ws_tests/browser_test/connection.html b/packages/web3/test/manual/long_ws_tests/browser_test/connection.html new file mode 100644 index 00000000000..8b3c8c346fd --- /dev/null +++ b/packages/web3/test/manual/long_ws_tests/browser_test/connection.html @@ -0,0 +1,94 @@ + + + + + + Manual browser tests + + + + + +

Manual browser test - for this test you will need to provide an ws infura endpoint in this html page. This will test the web3js ws provider by sending a request every 10 minutes for 10 hours

+

Have this html test open in a browser of your choice

+

Keep dev console open in case of any unintended errors occur

+ +

Start time:

+ + +

End Time:

+ + +

Number of requests sent:

+ + +

Has ran for minutes

+ + +

Block number:

+ + +

Result:

+ + + + + + + + diff --git a/packages/web3/test/manual/long_ws_tests/nodejs_test/long_connection_ws.js b/packages/web3/test/manual/long_ws_tests/nodejs_test/long_connection_ws.js new file mode 100644 index 00000000000..9abc2a4e9df --- /dev/null +++ b/packages/web3/test/manual/long_ws_tests/nodejs_test/long_connection_ws.js @@ -0,0 +1,70 @@ +/* +This file is part of web3.js. + +web3.js is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +web3.js is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with web3.js. If not, see . +*/ +/* eslint-disable */ +const { Web3 } = require('../../../../lib/commonjs'); +const secrets = require('../../../../../../.secrets.json'); + +let web3; +let attempt = 0; +let intervalId; +let start; +let end; + +// constantly send requests through WS for 10 hours +const sendRequests = () => { + start = new Date(); + console.log("start:",start) + return new Promise((resolve, reject) => { + // send a request in intervals of 10 minutes + intervalId = setInterval( async() => { + try{ + const block = await web3.eth.getBlock() + attempt++; + console.log(block) + console.log("successful calls:", attempt, "has ran for:", attempt*10, "minutes") + if (attempt === 144) { // after 10 hours + clearInterval(intervalId); + resolve(""); + } + } catch (error) { + clearInterval(intervalId); + reject(error); + } + },600000) // every 10 minutes + }) + +} + +const main = async () => { + + try { + // You will need to set mainnet infura provider + const provider = secrets.MAINNET.WS; + web3 = new Web3(provider); + const promise = sendRequests(); + await promise; + end = new Date(); + console.log("websocket test successful") + } catch (e) { + console.warn("error occured during ws test, on attempt: ", attempt, "program ran for: ", attempt ,"minutes with error: ", e) + } + console.log("start", start) + console.log("end", end) + process.exit(); +} + +main(); \ No newline at end of file