diff --git a/package-lock.json b/package-lock.json index 5d9d5917..2bdddeab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,7 +45,6 @@ "perf_hooks": "^0.0.1", "prettier": "^2.8.4", "prettier-plugin-organize-imports": "^2.3.4", - "size-limit": "^7.0.8", "ts-jest": "^27.1.4", "ts-node": "^10.2.1", "typedoc": "^0.22.15", @@ -4509,6 +4508,7 @@ "version": "2.2.0", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=8" } @@ -4848,6 +4848,7 @@ "version": "3.1.1", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">= 0.8" } @@ -4997,6 +4998,7 @@ "url": "https://paulmillr.com/funding/" } ], + "peer": true, "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", @@ -5027,7 +5029,8 @@ "node_modules/ci-job-number": { "version": "1.2.2", "dev": true, - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/cids": { "version": "0.7.5", @@ -8105,6 +8108,7 @@ "version": "2.1.0", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "binary-extensions": "^2.0.0" }, @@ -10168,6 +10172,7 @@ "version": "1.1.0", "dev": true, "license": "ISC", + "peer": true, "dependencies": { "picocolors": "^1.0.0" } @@ -11723,6 +11728,7 @@ "version": "3.6.0", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "picomatch": "^2.2.1" }, @@ -12645,6 +12651,7 @@ "version": "7.0.8", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "bytes-iec": "^3.1.1", "chokidar": "^3.5.3", @@ -17368,7 +17375,8 @@ }, "binary-extensions": { "version": "2.2.0", - "dev": true + "dev": true, + "peer": true }, "blakejs": { "version": "1.2.1", @@ -17624,7 +17632,8 @@ }, "bytes-iec": { "version": "3.1.1", - "dev": true + "dev": true, + "peer": true }, "cacheable-lookup": { "version": "6.1.0", @@ -17717,6 +17726,7 @@ "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", "dev": true, + "peer": true, "requires": { "anymatch": "~3.1.2", "braces": "~3.0.2", @@ -17740,7 +17750,8 @@ }, "ci-job-number": { "version": "1.2.2", - "dev": true + "dev": true, + "peer": true }, "cids": { "version": "0.7.5", @@ -19871,6 +19882,7 @@ "is-binary-path": { "version": "2.1.0", "dev": true, + "peer": true, "requires": { "binary-extensions": "^2.0.0" } @@ -21291,6 +21303,7 @@ "nanospinner": { "version": "1.1.0", "dev": true, + "peer": true, "requires": { "picocolors": "^1.0.0" } @@ -22229,6 +22242,7 @@ "readdirp": { "version": "3.6.0", "dev": true, + "peer": true, "requires": { "picomatch": "^2.2.1" } @@ -22881,6 +22895,7 @@ "size-limit": { "version": "7.0.8", "dev": true, + "peer": true, "requires": { "bytes-iec": "^3.1.1", "chokidar": "^3.5.3", diff --git a/package.json b/package.json index 68f9ae2d..4841d9ef 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ } ], "scripts": { - "size": "size-limit", + "size": "npx size-limit", "test": "npm-run-all --parallel jest compile lint", "test:all-node-versions": "npx trevor", "lint": "eslint --cache --fix .", @@ -90,7 +90,6 @@ "perf_hooks": "^0.0.1", "prettier": "^2.8.4", "prettier-plugin-organize-imports": "^2.3.4", - "size-limit": "^7.0.8", "ts-jest": "^27.1.4", "ts-node": "^10.2.1", "typedoc": "^0.22.15", diff --git a/src/providers/FallthroughProvider.ts b/src/providers/FallthroughProvider.ts index dff472c2..e93fe374 100644 --- a/src/providers/FallthroughProvider.ts +++ b/src/providers/FallthroughProvider.ts @@ -2,13 +2,23 @@ import { logger } from '../logger/logger'; import { BaseProvider } from './BaseProvider'; // https://advancedweb.hu/how-to-add-timeout-to-a-promise-in-javascript/ -const promiseTimeout = (prom: Promise, time: number) => - Promise.race([ - prom, - new Promise((_r, reject) => - setTimeout(() => reject('Promise timed out'), time), - ), - ]); +const promiseTimeout = (prom: Promise, time: number): Promise => + new Promise((resolve, reject) => { + const timeout = setTimeout( + () => reject(new Error('Promise timed out')), + time, + ); + + prom + .then((result) => { + clearTimeout(timeout); + resolve(result); + }) + .catch((error) => { + clearTimeout(timeout); + reject(error); + }); + }); export interface ConstructorOptions { timeoutDuration?: number; diff --git a/src/providers/test/json-rpc-provider/get-block.test.ts b/src/providers/test/json-rpc-provider/get-block.test.ts index 75649c80..4ee2a5f9 100644 --- a/src/providers/test/json-rpc-provider/get-block.test.ts +++ b/src/providers/test/json-rpc-provider/get-block.test.ts @@ -134,13 +134,6 @@ describe('provider.getBlock', () => { ]); testBlockEquality(eeRandomBlock, ethersRandomBlock); }); - it(`should match web3.js -- random block as decimal integer & transactions. (block #${blockNumber})`, async () => { - const [eeRandomBlock, web3RandomBlock] = await Promise.all([ - essentialEthProvider.getBlock(blockNumber, true), - web3Provider.eth.getBlock(blockNumber, true), - ]); - testBlockEquality(eeRandomBlock, web3RandomBlock); - }); const blockHash = '0x4cbaa942e48a91108f38e2a250f6dbaff7fffe3027f5ebf76701929eed2b2970'; // Hash corresponds to block on RSK Mainnet