From c32fe7cd6356ba4228e5f66cf72d78d8dd3f2c7c Mon Sep 17 00:00:00 2001 From: Logan Nguyen Date: Tue, 23 Apr 2024 12:33:17 -0400 Subject: [PATCH] Revert "fix: fixes unit test heap memory issue (#2305)" This reverts commit f66da4e572354572735a19983595512deb8c1fae. --- .github/workflows/acceptance-workflow.yml | 5 +- docs/openrpc.json | 49 +- package-lock.json | 630 +----------------- packages/relay/package.json | 1 - .../src/lib/clients/cache/ICacheClient.ts | 1 - .../src/lib/clients/cache/localLRUCache.ts | 4 - .../relay/src/lib/clients/cache/redisCache.ts | 56 +- packages/relay/src/lib/precheck.ts | 1 + .../lib/services/cacheService/cacheService.ts | 8 +- .../tests/lib/clients/redisCache.spec.ts | 11 +- packages/relay/tests/lib/eth/eth_call.spec.ts | 170 +++-- .../tests/lib/eth/eth_estimateGas.spec.ts | 83 +-- .../lib/eth/eth_getBlockByNumber.spec.ts | 27 +- ..._getTransactionByBlockHashAndIndex.spec.ts | 15 +- ...etTransactionByBlockNumberAndIndex.spec.ts | 11 - .../lib/eth/eth_getTransactionReceipt.spec.ts | 8 - .../relay/tests/lib/ethGetBlockBy.spec.ts | 103 +-- packages/relay/tests/lib/openrpc.spec.ts | 11 - packages/relay/tests/lib/sdkClient.spec.ts | 52 ++ .../tests/lib/subscriptionController.spec.ts | 20 +- packages/relay/tests/redisInMemoryServer.ts | 74 -- packages/relay/tests/test.env | 2 +- packages/relay/tsconfig.json | 3 +- packages/server/tsconfig.json | 3 +- 24 files changed, 265 insertions(+), 1083 deletions(-) delete mode 100644 packages/relay/tests/redisInMemoryServer.ts diff --git a/.github/workflows/acceptance-workflow.yml b/.github/workflows/acceptance-workflow.yml index 1ff42e9f04..4eb21012db 100644 --- a/.github/workflows/acceptance-workflow.yml +++ b/.github/workflows/acceptance-workflow.yml @@ -42,10 +42,7 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18 - - - name: Install make - run: sudo apt-get update; sudo apt-get install build-essential -y - + - name: Checkout repo uses: actions/checkout@v3 diff --git a/docs/openrpc.json b/docs/openrpc.json index d75e3fc9db..0e3ba4dbb6 100644 --- a/docs/openrpc.json +++ b/docs/openrpc.json @@ -1288,53 +1288,6 @@ "type": "null", "pattern": "null" }, - "subcall": { - "type": "object", - "properties": { - "type": { - "type": "string", - "enum": ["CALL", "CREATE"], - "description": "The type of action (CALL for function calls or CREATE for contract creation)." - }, - "from": { - "$ref": "#/components/schemas/address", - "description": "The address of the sender." - }, - "to": { - "$ref": "#/components/schemas/address", - "description": "The address of the receiver. In the case of a contract creation, this might be null." - }, - "value": { - "$ref": "#/components/schemas/uint", - "description": "The value transferred with the call, in hexadecimal." - }, - "gas": { - "$ref": "#/components/schemas/uint", - "description": "The gas provided for the call, in hexadecimal." - }, - "gasUsed": { - "$ref": "#/components/schemas/uint", - "description": "The gas used during the call, in hexadecimal." - }, - "input": { - "$ref": "#/components/schemas/bytes", - "description": "The input data sent with the call." - }, - "output": { - "$ref": "#/components/schemas/bytes", - "description": "The output data returned by the call." - }, - "error": { - "type": "string", - "description": "Error encountered during the call, if any." - }, - "revertReason": { - "type": "string", - "description": "Solidity revert reason, if applicable." - } - }, - "required": ["from", "gas", "input"] - }, "Block": { "title": "Block object", "type": "object", @@ -2105,7 +2058,7 @@ "calls": { "type": "array", "items": { - "$ref": "#/components/schemas/subcall" + "$ref": "#/components/schemas/callframe" }, "description": "Sub-calls made during this call frame." } diff --git a/package-lock.json b/package-lock.json index 69349ee3d1..56329dbb96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4644,16 +4644,6 @@ "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.2.tgz", "integrity": "sha512-9GcLXF0/v3t80caGs5p2rRfkB+a8VBGLJZVih6CNFkx8IZ994wiKKLSRs9nuFwk1HevWs/1mnUmkApGrSGsShA==" }, - "node_modules/@types/yauzl": { - "version": "2.10.3", - "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz", - "integrity": "sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==", - "dev": true, - "optional": true, - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.5.0.tgz", @@ -5829,15 +5819,6 @@ "ieee754": "^1.2.1" } }, - "node_modules/buffer-crc32": { - "version": "0.2.13", - "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -8688,41 +8669,6 @@ "node": ">=0.6.0" } }, - "node_modules/extract-zip": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", - "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==", - "dev": true, - "dependencies": { - "debug": "^4.1.1", - "get-stream": "^5.1.0", - "yauzl": "^2.10.0" - }, - "bin": { - "extract-zip": "cli.js" - }, - "engines": { - "node": ">= 10.17.0" - }, - "optionalDependencies": { - "@types/yauzl": "^2.9.1" - } - }, - "node_modules/extract-zip/node_modules/get-stream": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", - "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", - "dev": true, - "dependencies": { - "pump": "^3.0.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/extsprintf": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", @@ -8808,15 +8754,6 @@ "resolved": "https://registry.npmjs.org/fclone/-/fclone-1.0.11.tgz", "integrity": "sha512-GDqVQezKzRABdeqflsgMr7ktzgF9CyS+p2oe0jJqUY6izSSbhPIQJDpoU4PtGcD7VPM9xh/dVrTu6z1nwgmEGw==" }, - "node_modules/fd-slicer": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", - "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", - "dev": true, - "dependencies": { - "pend": "~1.2.0" - } - }, "node_modules/figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -8908,12 +8845,6 @@ "node": ">= 0.12" } }, - "node_modules/find-package-json": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/find-package-json/-/find-package-json-1.2.0.tgz", - "integrity": "sha512-+SOGcLGYDJHtyqHd87ysBhmaeQ95oWspDKnMXBrnQ9Eq4OkLNqejgoaD8xVWu6GPa0B6roa6KinCMEMcVeqONw==", - "dev": true - }, "node_modules/find-replace": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz", @@ -12868,15 +12799,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lockfile": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/lockfile/-/lockfile-1.0.4.tgz", - "integrity": "sha512-cvbTwETRfsFh4nHsL1eGWapU1XFi5Ot9E85sWAwia7Y7EgB7vfqcZhTKZ+l7hCGxSPoushMv5GKhT5PdLv03WA==", - "dev": true, - "dependencies": { - "signal-exit": "^3.0.2" - } - }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", @@ -12900,12 +12822,6 @@ "integrity": "sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==", "dev": true }, - "node_modules/lodash.defaultsdeep": { - "version": "4.6.1", - "resolved": "https://registry.npmjs.org/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.1.tgz", - "integrity": "sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA==", - "dev": true - }, "node_modules/lodash.flattendeep": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", @@ -16315,11 +16231,11 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "node_modules/path-scurry": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.2.tgz", - "integrity": "sha512-7xTavNy5RQXnsjANvVvMkEjvloOinkAjv/Z6Ildz9v2RinZ4SBKTWFOVRbaF8p0vpHnyjV/UwNDdKuUv6M5qcA==", + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.1.tgz", + "integrity": "sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==", "dependencies": { - "lru-cache": "^10.2.0", + "lru-cache": "^9.1.1 || ^10.0.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" }, "engines": { @@ -16330,9 +16246,9 @@ } }, "node_modules/path-scurry/node_modules/lru-cache": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz", - "integrity": "sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==", + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz", + "integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==", "engines": { "node": "14 || >=16.14" } @@ -16374,12 +16290,6 @@ "node": ">=0.12" } }, - "node_modules/pend": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", - "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", - "dev": true - }, "node_modules/performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -17347,252 +17257,6 @@ "node": ">=4" } }, - "node_modules/redis-memory-server": { - "version": "0.10.0", - "resolved": "https://registry.npmjs.org/redis-memory-server/-/redis-memory-server-0.10.0.tgz", - "integrity": "sha512-D0CFfUzAOQv/64iYzRqxUs4MEV2LlaW227qDvuuiq2FR4FXLrxyfENFf7dj6v4IwGTcNSLxhDlNKQthYVncg3Q==", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "camelcase": "^6.3.0", - "cross-spawn": "^7.0.3", - "debug": "^4.3.4", - "extract-zip": "^2.0.1", - "find-cache-dir": "^3.3.2", - "find-package-json": "^1.2.0", - "get-port": "^5.1.1", - "https-proxy-agent": "^7.0.0", - "lockfile": "^1.0.4", - "lodash.defaultsdeep": "^4.6.1", - "mkdirp": "^3.0.1", - "rimraf": "^5.0.1", - "semver": "^7.5.3", - "tar": "^6.1.15", - "tmp": "^0.2.1", - "uuid": "^8.3.2" - }, - "bin": { - "redis-memory-server": "bin/index.js" - }, - "engines": { - "node": ">=16" - } - }, - "node_modules/redis-memory-server/node_modules/agent-base": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", - "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", - "dev": true, - "dependencies": { - "debug": "^4.3.4" - }, - "engines": { - "node": ">= 14" - } - }, - "node_modules/redis-memory-server/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/redis-memory-server/node_modules/camelcase": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", - "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/redis-memory-server/node_modules/foreground-child": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", - "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", - "dev": true, - "dependencies": { - "cross-spawn": "^7.0.0", - "signal-exit": "^4.0.1" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/redis-memory-server/node_modules/fs-minipass": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", - "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", - "dev": true, - "dependencies": { - "minipass": "^3.0.0" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/redis-memory-server/node_modules/fs-minipass/node_modules/minipass": { - "version": "3.3.6", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", - "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/redis-memory-server/node_modules/glob": { - "version": "10.3.12", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.12.tgz", - "integrity": "sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg==", - "dev": true, - "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", - "minimatch": "^9.0.1", - "minipass": "^7.0.4", - "path-scurry": "^1.10.2" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/redis-memory-server/node_modules/glob/node_modules/minipass": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", - "integrity": "sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==", - "dev": true, - "engines": { - "node": ">=16 || 14 >=14.17" - } - }, - "node_modules/redis-memory-server/node_modules/https-proxy-agent": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz", - "integrity": "sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==", - "dev": true, - "dependencies": { - "agent-base": "^7.0.2", - "debug": "4" - }, - "engines": { - "node": ">= 14" - } - }, - "node_modules/redis-memory-server/node_modules/minimatch": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", - "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/redis-memory-server/node_modules/mkdirp": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz", - "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", - "dev": true, - "bin": { - "mkdirp": "dist/cjs/src/bin.js" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/redis-memory-server/node_modules/rimraf": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.5.tgz", - "integrity": "sha512-CqDakW+hMe/Bz202FPEymy68P+G50RfMQK+Qo5YUqc9SPipvbGjCGKd0RSKEelbsfQuw3g5NZDSrlZZAJurH1A==", - "dev": true, - "dependencies": { - "glob": "^10.3.7" - }, - "bin": { - "rimraf": "dist/esm/bin.mjs" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/redis-memory-server/node_modules/signal-exit": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", - "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", - "dev": true, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/redis-memory-server/node_modules/tar": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz", - "integrity": "sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==", - "dev": true, - "dependencies": { - "chownr": "^2.0.0", - "fs-minipass": "^2.0.0", - "minipass": "^5.0.0", - "minizlib": "^2.1.1", - "mkdirp": "^1.0.3", - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/redis-memory-server/node_modules/tar/node_modules/mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "dev": true, - "bin": { - "mkdirp": "bin/cmd.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/redis-memory-server/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, - "bin": { - "uuid": "dist/bin/uuid" - } - }, "node_modules/redis-parser": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", @@ -20642,16 +20306,6 @@ "node": ">=12" } }, - "node_modules/yauzl": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", - "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", - "dev": true, - "dependencies": { - "buffer-crc32": "~0.2.3", - "fd-slicer": "~1.1.0" - } - }, "node_modules/ylru": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ylru/-/ylru-1.4.0.tgz", @@ -20708,7 +20362,6 @@ "@types/mocha": "^9.1.0", "@types/node": "^17.0.14", "chai": "^4.3.6", - "redis-memory-server": "^0.10.0", "sinon": "^14.0.0", "ts-mocha": "^9.0.2", "typescript": "^4.6.4" @@ -23329,7 +22982,6 @@ "pino": "^7.11.0", "pnpm": "^8.7.1", "redis": "^4.6.7", - "redis-memory-server": "^0.10.0", "rlp": "^3.0.0", "sinon": "^14.0.0", "ts-mocha": "^9.0.2", @@ -25971,16 +25623,6 @@ "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.2.tgz", "integrity": "sha512-9GcLXF0/v3t80caGs5p2rRfkB+a8VBGLJZVih6CNFkx8IZ994wiKKLSRs9nuFwk1HevWs/1mnUmkApGrSGsShA==" }, - "@types/yauzl": { - "version": "2.10.3", - "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz", - "integrity": "sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==", - "dev": true, - "optional": true, - "requires": { - "@types/node": "*" - } - }, "@typescript-eslint/eslint-plugin": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.5.0.tgz", @@ -26823,12 +26465,6 @@ "ieee754": "^1.2.1" } }, - "buffer-crc32": { - "version": "0.2.13", - "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", - "dev": true - }, "buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -28932,29 +28568,6 @@ } } }, - "extract-zip": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", - "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==", - "dev": true, - "requires": { - "@types/yauzl": "^2.9.1", - "debug": "^4.1.1", - "get-stream": "^5.1.0", - "yauzl": "^2.10.0" - }, - "dependencies": { - "get-stream": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", - "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", - "dev": true, - "requires": { - "pump": "^3.0.0" - } - } - } - }, "extsprintf": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", @@ -29033,15 +28646,6 @@ "resolved": "https://registry.npmjs.org/fclone/-/fclone-1.0.11.tgz", "integrity": "sha512-GDqVQezKzRABdeqflsgMr7ktzgF9CyS+p2oe0jJqUY6izSSbhPIQJDpoU4PtGcD7VPM9xh/dVrTu6z1nwgmEGw==" }, - "fd-slicer": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", - "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", - "dev": true, - "requires": { - "pend": "~1.2.0" - } - }, "figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -29111,12 +28715,6 @@ "user-home": "^2.0.0" } }, - "find-package-json": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/find-package-json/-/find-package-json-1.2.0.tgz", - "integrity": "sha512-+SOGcLGYDJHtyqHd87ysBhmaeQ95oWspDKnMXBrnQ9Eq4OkLNqejgoaD8xVWu6GPa0B6roa6KinCMEMcVeqONw==", - "dev": true - }, "find-replace": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz", @@ -31927,15 +31525,6 @@ "p-locate": "^5.0.0" } }, - "lockfile": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/lockfile/-/lockfile-1.0.4.tgz", - "integrity": "sha512-cvbTwETRfsFh4nHsL1eGWapU1XFi5Ot9E85sWAwia7Y7EgB7vfqcZhTKZ+l7hCGxSPoushMv5GKhT5PdLv03WA==", - "dev": true, - "requires": { - "signal-exit": "^3.0.2" - } - }, "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", @@ -31959,12 +31548,6 @@ "integrity": "sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==", "dev": true }, - "lodash.defaultsdeep": { - "version": "4.6.1", - "resolved": "https://registry.npmjs.org/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.1.tgz", - "integrity": "sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA==", - "dev": true - }, "lodash.flattendeep": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", @@ -34515,18 +34098,18 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "path-scurry": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.2.tgz", - "integrity": "sha512-7xTavNy5RQXnsjANvVvMkEjvloOinkAjv/Z6Ildz9v2RinZ4SBKTWFOVRbaF8p0vpHnyjV/UwNDdKuUv6M5qcA==", + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.1.tgz", + "integrity": "sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==", "requires": { - "lru-cache": "^10.2.0", + "lru-cache": "^9.1.1 || ^10.0.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" }, "dependencies": { "lru-cache": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz", - "integrity": "sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==" + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz", + "integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==" } } }, @@ -34558,12 +34141,6 @@ "sha.js": "^2.4.8" } }, - "pend": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", - "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", - "dev": true - }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -35282,175 +34859,6 @@ "integrity": "sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w==", "dev": true }, - "redis-memory-server": { - "version": "0.10.0", - "resolved": "https://registry.npmjs.org/redis-memory-server/-/redis-memory-server-0.10.0.tgz", - "integrity": "sha512-D0CFfUzAOQv/64iYzRqxUs4MEV2LlaW227qDvuuiq2FR4FXLrxyfENFf7dj6v4IwGTcNSLxhDlNKQthYVncg3Q==", - "dev": true, - "requires": { - "camelcase": "^6.3.0", - "cross-spawn": "^7.0.3", - "debug": "^4.3.4", - "extract-zip": "^2.0.1", - "find-cache-dir": "^3.3.2", - "find-package-json": "^1.2.0", - "get-port": "^5.1.1", - "https-proxy-agent": "^7.0.0", - "lockfile": "^1.0.4", - "lodash.defaultsdeep": "^4.6.1", - "mkdirp": "^3.0.1", - "rimraf": "^5.0.1", - "semver": "^7.5.3", - "tar": "^6.1.15", - "tmp": "^0.2.1", - "uuid": "^8.3.2" - }, - "dependencies": { - "agent-base": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", - "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", - "dev": true, - "requires": { - "debug": "^4.3.4" - } - }, - "brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "requires": { - "balanced-match": "^1.0.0" - } - }, - "camelcase": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", - "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", - "dev": true - }, - "foreground-child": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", - "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", - "dev": true, - "requires": { - "cross-spawn": "^7.0.0", - "signal-exit": "^4.0.1" - } - }, - "fs-minipass": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", - "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", - "dev": true, - "requires": { - "minipass": "^3.0.0" - }, - "dependencies": { - "minipass": { - "version": "3.3.6", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", - "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", - "dev": true, - "requires": { - "yallist": "^4.0.0" - } - } - } - }, - "glob": { - "version": "10.3.12", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.12.tgz", - "integrity": "sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg==", - "dev": true, - "requires": { - "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", - "minimatch": "^9.0.1", - "minipass": "^7.0.4", - "path-scurry": "^1.10.2" - }, - "dependencies": { - "minipass": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", - "integrity": "sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==", - "dev": true - } - } - }, - "https-proxy-agent": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz", - "integrity": "sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==", - "dev": true, - "requires": { - "agent-base": "^7.0.2", - "debug": "4" - } - }, - "minimatch": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", - "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", - "dev": true, - "requires": { - "brace-expansion": "^2.0.1" - } - }, - "mkdirp": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz", - "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", - "dev": true - }, - "rimraf": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.5.tgz", - "integrity": "sha512-CqDakW+hMe/Bz202FPEymy68P+G50RfMQK+Qo5YUqc9SPipvbGjCGKd0RSKEelbsfQuw3g5NZDSrlZZAJurH1A==", - "dev": true, - "requires": { - "glob": "^10.3.7" - } - }, - "signal-exit": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", - "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", - "dev": true - }, - "tar": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz", - "integrity": "sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==", - "dev": true, - "requires": { - "chownr": "^2.0.0", - "fs-minipass": "^2.0.0", - "minipass": "^5.0.0", - "minizlib": "^2.1.1", - "mkdirp": "^1.0.3", - "yallist": "^4.0.0" - }, - "dependencies": { - "mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "dev": true - } - } - }, - "uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true - } - } - }, "redis-parser": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", @@ -37737,16 +37145,6 @@ } } }, - "yauzl": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", - "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", - "dev": true, - "requires": { - "buffer-crc32": "~0.2.3", - "fd-slicer": "~1.1.0" - } - }, "ylru": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ylru/-/ylru-1.4.0.tgz", diff --git a/packages/relay/package.json b/packages/relay/package.json index caae66601f..1ab87ca726 100644 --- a/packages/relay/package.json +++ b/packages/relay/package.json @@ -14,7 +14,6 @@ "@types/mocha": "^9.1.0", "@types/node": "^17.0.14", "chai": "^4.3.6", - "redis-memory-server": "^0.10.0", "sinon": "^14.0.0", "ts-mocha": "^9.0.2", "typescript": "^4.6.4" diff --git a/packages/relay/src/lib/clients/cache/ICacheClient.ts b/packages/relay/src/lib/clients/cache/ICacheClient.ts index 4aeaf804f5..6f92c70720 100644 --- a/packages/relay/src/lib/clients/cache/ICacheClient.ts +++ b/packages/relay/src/lib/clients/cache/ICacheClient.ts @@ -30,5 +30,4 @@ export interface ICacheClient { ttl?: number | undefined, requestIdPrefix?: string, ): void; - disconnect(): Promise | void; } diff --git a/packages/relay/src/lib/clients/cache/localLRUCache.ts b/packages/relay/src/lib/clients/cache/localLRUCache.ts index e1103d987b..1d636252b6 100644 --- a/packages/relay/src/lib/clients/cache/localLRUCache.ts +++ b/packages/relay/src/lib/clients/cache/localLRUCache.ts @@ -192,8 +192,4 @@ export class LocalLRUCache implements ICacheClient { public clear(): void { this.cache.clear(); } - - public disconnect(): void { - return; - } } diff --git a/packages/relay/src/lib/clients/cache/redisCache.ts b/packages/relay/src/lib/clients/cache/redisCache.ts index a86b788d19..3811fc6ce8 100644 --- a/packages/relay/src/lib/clients/cache/redisCache.ts +++ b/packages/relay/src/lib/clients/cache/redisCache.ts @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * */ import { createClient, RedisClientType } from 'redis'; @@ -52,18 +51,8 @@ export class RedisCache implements ICacheClient { */ private readonly register: Registry; - /** - * The Redis client. - * @private - */ private readonly client: RedisClientType; - /** - * Boolean showing if the connection to the Redis client has finished. - * @private - */ - private readonly connected: Promise; - /** * Creates an instance of `RedisCache`. * @@ -76,6 +65,7 @@ export class RedisCache implements ICacheClient { const redisUrl = process.env.REDIS_URL!; const reconnectDelay = parseInt(process.env.REDIS_RECONNECT_DELAY_MS || '1000'); + this.client = createClient({ url: redisUrl, socket: { @@ -86,16 +76,12 @@ export class RedisCache implements ICacheClient { }, }, }); - this.connected = this.client - .connect() - .then(() => true) - .catch((error) => { - this.logger.error(error, 'Redis connection could not be established!'); - return false; - }); - this.client.on('ready', () => { + this.client.connect(); + + this.client.on('ready', function () { logger.info(`Connected to Redis server (${redisUrl}) successfully!`); }); + this.client.on('error', function (error) { const redisError = new RedisCacheError(error); if (redisError.isSocketClosed()) { @@ -106,10 +92,6 @@ export class RedisCache implements ICacheClient { }); } - async getConnectedClient(): Promise { - return this.connected.then(() => this.client); - } - /** * Retrieves a value from the cache. * @@ -119,8 +101,7 @@ export class RedisCache implements ICacheClient { * @returns {Promise} The cached value or null if not found. */ async get(key: string, callingMethod: string, requestIdPrefix?: string | undefined) { - const client = await this.getConnectedClient(); - const result = await client.get(key); + const result = await this.client.get(key); if (result) { this.logger.trace( `${requestIdPrefix} returning cached value ${key}:${JSON.stringify(result)} on ${callingMethod} call`, @@ -148,11 +129,10 @@ export class RedisCache implements ICacheClient { ttl?: number | undefined, requestIdPrefix?: string | undefined, ): Promise { - const client = await this.getConnectedClient(); const serializedValue = JSON.stringify(value); const resolvedTtl = (ttl ?? this.options.ttl) / 1000; // convert to seconds - await client.setEx(key, resolvedTtl, serializedValue); + await this.client.setEx(key, resolvedTtl, serializedValue); this.logger.trace(`${requestIdPrefix} caching ${key}: ${serializedValue} on ${callingMethod} for ${resolvedTtl} s`); // TODO: add metrics } @@ -166,19 +146,14 @@ export class RedisCache implements ICacheClient { * @returns {Promise} A Promise that resolves when the values are cached. */ async multiSet(keyValuePairs: Record, callingMethod: string, requestIdPrefix?: string): Promise { - const client = await this.getConnectedClient(); // Serialize values const serializedKeyValuePairs: Record = {}; for (const [key, value] of Object.entries(keyValuePairs)) { serializedKeyValuePairs[key] = JSON.stringify(value); } - try { - // Perform mSet operation - await client.mSet(serializedKeyValuePairs); - } catch (e) { - this.logger.error(e); - } + // Perform mSet operation + await this.client.mSet(serializedKeyValuePairs); // Log the operation const entriesLength = Object.keys(keyValuePairs).length; @@ -200,10 +175,9 @@ export class RedisCache implements ICacheClient { ttl?: number | undefined, requestIdPrefix?: string, ): Promise { - const client = await this.getConnectedClient(); const resolvedTtl = (ttl ?? this.options.ttl) / 1000; // convert to seconds - const pipeline = client.multi(); + const pipeline = this.client.multi(); for (const [key, value] of Object.entries(keyValuePairs)) { const serializedValue = JSON.stringify(value); @@ -227,8 +201,7 @@ export class RedisCache implements ICacheClient { * @returns {Promise} A Promise that resolves when the value is deleted from the cache. */ async delete(key: string, callingMethod: string, requestIdPrefix?: string | undefined): Promise { - const client = await this.getConnectedClient(); - await client.del(key); + await this.client.del(key); this.logger.trace(`${requestIdPrefix} delete cache for ${key} on ${callingMethod} call`); // TODO: add metrics } @@ -239,11 +212,6 @@ export class RedisCache implements ICacheClient { * @returns {Promise} A Promise that resolves when the cache is cleared. */ async clear(): Promise { - const client = await this.getConnectedClient(); - await client.flushAll(); - } - - async disconnect(): Promise { - await (await this.getConnectedClient()).disconnect(); + await this.client.flushAll(); } } diff --git a/packages/relay/src/lib/precheck.ts b/packages/relay/src/lib/precheck.ts index 9150cc1d9b..dc57a47b8a 100644 --- a/packages/relay/src/lib/precheck.ts +++ b/packages/relay/src/lib/precheck.ts @@ -284,6 +284,7 @@ export class Precheck { } if (hex.startsWith('0x') && hex.length == 2) { + console.log('Faiiiling here'); throw predefined.INTERNAL_ERROR('Hex cannot be 0x'); } else if (hex.startsWith('0x') && hex.length != 2) { hex = hex.slice(2); diff --git a/packages/relay/src/lib/services/cacheService/cacheService.ts b/packages/relay/src/lib/services/cacheService/cacheService.ts index 97a4c1262f..3b40d45642 100644 --- a/packages/relay/src/lib/services/cacheService/cacheService.ts +++ b/packages/relay/src/lib/services/cacheService/cacheService.ts @@ -115,10 +115,6 @@ export class CacheService { }); } - async disconnectRedisClient(): Promise { - await this.sharedCache.disconnect(); - } - /** * Checks whether Redis caching is enabled based on environment variables. * @private @@ -307,10 +303,10 @@ export class CacheService { * Else the internal cache clearing is attempted. * @param {boolean} shared - Whether to clear the shared cache (optional, default: false). */ - public async clear(requestIdPrefix?: string, shared: boolean = false): Promise { + public clear(requestIdPrefix?: string, shared: boolean = false): void { if (shared && this.isSharedCacheEnabled) { try { - await this.sharedCache.clear(); + return this.sharedCache.clear(); } catch (error) { const redisError = new RedisCacheError(error); this.logger.error( diff --git a/packages/relay/tests/lib/clients/redisCache.spec.ts b/packages/relay/tests/lib/clients/redisCache.spec.ts index 310faeba58..39b84eb793 100644 --- a/packages/relay/tests/lib/clients/redisCache.spec.ts +++ b/packages/relay/tests/lib/clients/redisCache.spec.ts @@ -23,12 +23,10 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; import { RedisCache } from '../../../src/lib/clients'; import { Registry } from 'prom-client'; -import { RedisInMemoryServer } from '../../redisInMemoryServer'; const logger = pino(); const registry = new Registry(); let redisCache: RedisCache; -let redisInMemoryServer: RedisInMemoryServer; const callingMethod = 'RedisCacheTest'; @@ -36,9 +34,7 @@ describe('RedisCache Test Suite', async function () { this.timeout(10000); const mock = sinon.createSandbox(); - this.beforeAll(async () => { - redisInMemoryServer = new RedisInMemoryServer(logger.child({ name: `in-memory redis server` }), 6379); - await redisInMemoryServer.start(); + this.beforeAll(() => { redisCache = new RedisCache(logger.child({ name: `cache` }), registry); }); @@ -51,11 +47,6 @@ describe('RedisCache Test Suite', async function () { mock.restore(); }); - this.afterAll(async () => { - await redisCache.disconnect(); - await redisInMemoryServer.stop(); - }); - describe('Get and Set Test Suite', async function () { it('should get null on empty cache', async function () { mock.stub(redisCache, 'get').returns(null); diff --git a/packages/relay/tests/lib/eth/eth_call.spec.ts b/packages/relay/tests/lib/eth/eth_call.spec.ts index c10e425498..3ba8958e9e 100644 --- a/packages/relay/tests/lib/eth/eth_call.spec.ts +++ b/packages/relay/tests/lib/eth/eth_call.spec.ts @@ -153,7 +153,6 @@ describe('@ethCall Eth Call spec', async function () { }); it('should execute "eth_call" against mirror node with a false ETH_CALL_DEFAULT_TO_CONSENSUS_NODE', async function () { - web3Mock.onPost('contracts/call').reply(200); const initialEthCallConesneusFF = process.env.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE; process.env.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE = 'false'; @@ -170,7 +169,6 @@ describe('@ethCall Eth Call spec', async function () { }); it('should execute "eth_call" against mirror node with an undefined ETH_CALL_DEFAULT_TO_CONSENSUS_NODE', async function () { - web3Mock.onPost('contracts/call').reply(200); const initialEthCallConesneusFF = process.env.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE; delete process.env.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE; @@ -202,6 +200,97 @@ describe('@ethCall Eth Call spec', async function () { process.env.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE = initialEthCallConesneusFF; }); + it('gas exceeds limit', async function () { + restMock.onGet(`contracts/${ACCOUNT_ADDRESS_1}`).reply(404); + restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); + + const excessiveGasLimit = '50000001'; + await ethCallFailing( + ethImpl, + { + from: ACCOUNT_ADDRESS_1, + to: CONTRACT_ADDRESS_2, + data: CONTRACT_CALL_DATA, + gas: excessiveGasLimit, + }, + 'latest', + (error) => { + expect(error).to.be.not.null; + expect(error.code).to.equal( + predefined.GAS_LIMIT_TOO_HIGH(excessiveGasLimit, constants.CONTRACT_CALL_GAS_LIMIT).code, + ); + }, + ); + }); + + it('block 0', async function () { + restMock.onGet(`contracts/${ACCOUNT_ADDRESS_1}`).reply(404); + restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); + + const block = '0'; + await ethCallFailing(ethImpl, ETH_CALL_REQ_ARGS, block, (error) => { + const predefineError = predefined.UNSUPPORTED_HISTORICAL_EXECUTION(block); + expect(error.code).to.equal(predefineError.code); + expect(error.name).to.equal(predefineError.name); + expect(error.message).to.equal(predefineError.message); + }); + }); + + it('block 1', async function () { + restMock.onGet(`contracts/${ACCOUNT_ADDRESS_1}`).reply(404); + restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); + + const block = '1'; + await ethCallFailing(ethImpl, ETH_CALL_REQ_ARGS, block, (error) => { + const predefineError = predefined.UNSUPPORTED_HISTORICAL_EXECUTION(block); + expect(error.code).to.equal(predefineError.code); + expect(error.name).to.equal(predefineError.name); + expect(error.message).to.equal(predefineError.message); + }); + }); + + it('block earliest', async function () { + restMock.onGet(`contracts/${ACCOUNT_ADDRESS_1}`).reply(404); + restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); + + const block = 'earliest'; + await ethCallFailing(ethImpl, ETH_CALL_REQ_ARGS, block, (error) => { + const predefineError = predefined.UNSUPPORTED_HISTORICAL_EXECUTION(block); + expect(error.code).to.equal(predefineError.code); + expect(error.name).to.equal(predefineError.name); + expect(error.message).to.equal(predefineError.message); + }); + }); + + it('block hash not supported', async function () { + restMock.onGet(`contracts/${ACCOUNT_ADDRESS_1}`).reply(404); + restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); + restMock.onGet(`blocks?limit=1&order=desc`).reply(202); + + await ethCallFailing(ethImpl, ETH_CALL_REQ_ARGS, BLOCK_HASH_TRIMMED, (error) => { + const predefineError = predefined.UNSUPPORTED_OPERATION( + `BlockParam: ${BLOCK_HASH_TRIMMED} is not a supported eth_call block identifier`, + ); + expect(error.code).to.equal(predefineError.code); + expect(error.name).to.equal(predefineError.name); + expect(error.message).to.equal(predefineError.message); + }); + }); + + it('latest block but not found for comparison', async function () { + restMock.onGet(`contracts/${ACCOUNT_ADDRESS_1}`).reply(404); + restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); + restMock.onGet(`blocks?limit=1&order=desc`).reply(404); + + const block = '0x10'; + await ethCallFailing(ethImpl, ETH_CALL_REQ_ARGS, block, (error) => { + const predefineError = predefined.RESOURCE_NOT_FOUND(`unable to retrieve latest block from mirror node`); + expect(error.code).to.equal(predefineError.code); + expect(error.name).to.equal(predefineError.name); + expect(error.message).to.equal(predefineError.message); + }); + }); + it('to field is not a contract or token', async function () { restMock.onGet(`contracts/${ACCOUNT_ADDRESS_1}`).reply(404); restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(404); @@ -405,6 +494,31 @@ describe('@ethCall Eth Call spec', async function () { expect((call as JsonRpcError).message).to.equal(expectedError.message); }); + describe('with gas > 15_000_000', async function () { + it('eth_call throws gasLimit too high error when gas exceeds limit', async function () { + restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); + + sdkClientStub.submitContractCallQueryWithRetry.returns(undefined); + + const args = [ + { + to: CONTRACT_ADDRESS_2, + data: CONTRACT_CALL_DATA, + gas: 50_000_001, + }, + 'latest', + ]; + + await RelayAssertions.assertRejection( + predefined.GAS_LIMIT_TOO_HIGH(50000000, constants.CONTRACT_CALL_GAS_LIMIT), + ethImpl.call, + false, + ethImpl, + args, + ); + }); + }); + it('SDK returns a precheck error', async function () { restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); sdkClientStub.submitContractCallQueryWithRetry.throws( @@ -415,7 +529,7 @@ describe('@ethCall Eth Call spec', async function () { expect(result).to.exist; expect((result as JsonRpcError).code).to.equal(-32008); - expect((result as JsonRpcError).name).to.equal(undefined); + expect((result as JsonRpcError).name).to.undefined; expect((result as JsonRpcError).message).to.equal(`execution reverted: ${defaultErrorMessageText}`); expect((result as JsonRpcError).data).to.equal(defaultErrorMessageHex); }); @@ -508,16 +622,14 @@ describe('@ethCall Eth Call spec', async function () { }; restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); - web3Mock - .onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }) - .reply(200, { result: `0x00` }); + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(200, { result: `0x00` }); web3Mock.history.post = []; const result = await ethImpl.call(callData, 'latest'); expect(web3Mock.history.post.length).to.gte(1); - expect(web3Mock.history.post[0].data).to.equal(JSON.stringify({ ...callData, estimate: false, block: 'latest' })); + expect(web3Mock.history.post[0].data).to.equal(JSON.stringify({ ...callData, estimate: false })); expect(result).to.equal('0x00'); }); @@ -530,9 +642,7 @@ describe('@ethCall Eth Call spec', async function () { gas: MAX_GAS_LIMIT, }; restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); - web3Mock - .onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }) - .reply(200, { result: `0x00` }); + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(200, { result: `0x00` }); const result = await ethImpl.call(callData, 'latest'); expect(result).to.equal('0x00'); @@ -546,9 +656,7 @@ describe('@ethCall Eth Call spec', async function () { gas: MAX_GAS_LIMIT, }; restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); - web3Mock - .onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }) - .reply(200, { result: `0x00` }); + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(200, { result: `0x00` }); const result = await ethImpl.call(callData, 'latest'); expect(result).to.equal('0x00'); }); @@ -562,9 +670,7 @@ describe('@ethCall Eth Call spec', async function () { gas: MAX_GAS_LIMIT, }; restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); - web3Mock - .onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }) - .reply(200, { result: `0x00` }); + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(200, { result: `0x00` }); const result = await ethImpl.call(callData, 'latest'); expect(result).to.equal('0x00'); }); @@ -597,9 +703,7 @@ describe('@ethCall Eth Call spec', async function () { gas: MAX_GAS_LIMIT, }; restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); - web3Mock - .onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }) - .reply(429, mockData.tooManyRequests); + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(429, mockData.tooManyRequests); const result = await ethImpl.call(callData, 'latest'); expect(result).to.be.not.null; expect((result as JsonRpcError).code).to.eq(-32605); @@ -615,13 +719,11 @@ describe('@ethCall Eth Call spec', async function () { gas: MAX_GAS_LIMIT, }; restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); - web3Mock - .onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }) - .reply(400, mockData.contractReverted); + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(400, mockData.contractReverted); const result = await ethImpl.call(callData, 'latest'); expect(result).to.be.not.null; expect((result as JsonRpcError).code).to.eq(-32008); - expect((result as JsonRpcError).name).to.eq(undefined); + expect((result as JsonRpcError).name).to.undefined; expect((result as JsonRpcError).message).to.contain(mockData.contractReverted._status.messages[0].message); }); @@ -635,9 +737,7 @@ describe('@ethCall Eth Call spec', async function () { }; restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); - web3Mock - .onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }) - .reply(501, mockData.notSuported); + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(501, mockData.notSuported); sdkClientStub.submitContractCallQueryWithRetry.returns({ asBytes: function () { @@ -668,15 +768,13 @@ describe('@ethCall Eth Call spec', async function () { }; restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); - web3Mock - .onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }) - .reply(400, mockData.contractReverted); + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(400, mockData.contractReverted); sinon.reset(); const result = await ethImpl.call(callData, 'latest'); sinon.assert.notCalled(sdkClientStub.submitContractCallQueryWithRetry); expect(result).to.not.be.null; expect((result as JsonRpcError).code).to.eq(-32008); - expect((result as JsonRpcError).name).to.eq(undefined); + expect((result as JsonRpcError).name).to.undefined; expect((result as JsonRpcError).message).to.contain(mockData.contractReverted._status.messages[0].message); }); @@ -691,7 +789,7 @@ describe('@ethCall Eth Call spec', async function () { restMock.onGet(`contracts/${CONTRACT_ADDRESS_2}`).reply(200, DEFAULT_CONTRACT_2); - web3Mock.onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }).reply(400, { + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(400, { _status: { messages: [ { @@ -707,7 +805,7 @@ describe('@ethCall Eth Call spec', async function () { expect(result).to.exist; expect((result as JsonRpcError).code).to.eq(-32008); - expect((result as JsonRpcError).name).to.eq(undefined); + expect((result as JsonRpcError).name).to.undefined; expect((result as JsonRpcError).message).to.equal(`execution reverted: ${defaultErrorMessageText}`); expect((result as JsonRpcError).data).to.equal(defaultErrorMessageHex); }); @@ -761,9 +859,7 @@ describe('@ethCall Eth Call spec', async function () { gas: MAX_GAS_LIMIT, }; - web3Mock - .onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }) - .reply(400, mockData.invalidTransaction); + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(400, mockData.invalidTransaction); const result = await ethImpl.call(callData, 'latest'); expect(result).to.be.not.null; expect(result).to.equal('0x'); @@ -778,9 +874,7 @@ describe('@ethCall Eth Call spec', async function () { gas: MAX_GAS_LIMIT, }; - web3Mock - .onPost('contracts/call', { ...callData, estimate: false, block: 'latest' }) - .reply(400, mockData.failInvalid); + web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(400, mockData.failInvalid); const result = await ethImpl.call(callData, 'latest'); expect(result).to.be.not.null; expect(result).to.equal('0x'); diff --git a/packages/relay/tests/lib/eth/eth_estimateGas.spec.ts b/packages/relay/tests/lib/eth/eth_estimateGas.spec.ts index 94e91694f2..c7fb94b506 100644 --- a/packages/relay/tests/lib/eth/eth_estimateGas.spec.ts +++ b/packages/relay/tests/lib/eth/eth_estimateGas.spec.ts @@ -44,10 +44,6 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { let { restMock, web3Mock, hapiServiceInstance, ethImpl, cacheService, mirrorNodeInstance, logger, registry } = generateEthTestEnv(); - function mockContractCall(callData, estimate = true, statusCode = 501, result) { - return web3Mock.onPost('contracts/call', { ...callData, estimate }).reply(statusCode, result); - } - const transaction = { from: '0x05fba803be258049a27b820088bab1cad2058871', data: '0x60806040523480156200001157600080fd5b50604051620019f4380380620019f48339818101604052810190620000379190620001fa565b818181600390816200004a9190620004ca565b5080600490816200005c9190620004ca565b5050505050620005b1565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620000d08262000085565b810181811067ffffffffffffffff82111715620000f257620000f162000096565b5b80604052505', @@ -85,7 +81,9 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { gasPrice: '0x0', data: null, }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); + web3Mock + .onPost('contracts/call', { ...callData, estimate: true }) + .reply(501, { errorMessage: '', statusCode: 501 }); const gas = await ethImpl.estimateGas(callData, null); expect(gas).to.equal(numberTo0x(constants.TX_DEFAULT_GAS_DEFAULT)); @@ -96,7 +94,9 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { data: '0x608060405234801561001057600080fd5b506040516107893803806107898339818101604052810190610032919061015a565b806000908051906020019061004892919061004f565b50506102f6565b82805461005b90610224565b90600052602060002090601f01602090048101928261007d57600085556100c4565b82601f1061009657805160ff19168380011785556100c4565b828001600101855582156100c4579182015b828111156100c35782518255916020019190600101906100a8565b5b5090506100d191906100d5565b5090565b5b808211156100ee5760008160009055506001016100d6565b5090565b6000610105610100846101c0565b61019b565b90508281526020810184848401111561011d57600080fd5b6101288482856101f1565b509392505050565b600082601f83011261014157600080fd5b81516101518482602086016100f2565b91505092915050565b60006020828403121561016c57600080fd5b600082015167ffffffffffffffff81111561018657600080fd5b61019284828501610130565b91505092915050565b60006101a56101b6565b90506101b18282610256565b919050565b6000604051905090565b600067ffffffffffffffff8211156101db576101da6102b6565b5b6101e4826102e5565b9050602081019050919050565b60005b8381101561020f5780820151818401526020810190506101f4565b8381111561021e576000848401525b50505050565b6000600282049050600182168061023c57607f821691505b602082108114156102505761024f610287565b5b50919050565b61025f826102e5565b810181811067ffffffffffffffff8211171561027e5761027d6102b6565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b610484806103056000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063a41368621461003b578063cfae321714610057575b600080fd5b6100556004803603810190610050919061022c565b610075565b005b61005f61008f565b60405161006c91906102a6565b60405180910390f35b806000908051906020019061008b929190610121565b5050565b60606000805461009e9061037c565b80601f01602080910402602001604051908101604052809291908181526020018280546100ca9061037c565b80156101175780601f106100ec57610100808354040283529160200191610117565b820191906000526020600020905b8154815290600101906020018083116100fa57829003601f168201915b5050505050905090565b82805461012d9061037c565b90600052602060002090601f01602090048101928261014f5760008555610196565b82601f1061016857805160ff1916838001178555610196565b82800160010185558215610196579182015b8281111561019557825182559160200191906001019061017a565b5b5090506101a391906101a7565b5090565b5b808211156101c05760008160009055506001016101a8565b5090565b60006101d76101d2846102ed565b6102c8565b9050828152602081018484840111156101ef57600080fd5b6101fa84828561033a565b509392505050565b600082601f83011261021357600080fd5b81356102238482602086016101c4565b91505092915050565b60006020828403121561023e57600080fd5b600082013567ffffffffffffffff81111561025857600080fd5b61026484828501610202565b91505092915050565b60006102788261031e565b6102828185610329565b9350610292818560208601610349565b61029b8161043d565b840191505092915050565b600060208201905081810360008301526102c0818461026d565b905092915050565b60006102d26102e3565b90506102de82826103ae565b919050565b6000604051905090565b600067ffffffffffffffff8211156103085761030761040e565b5b6103118261043d565b9050602081019050919050565b600081519050919050565b600082825260208201905092915050565b82818337600083830152505050565b60005b8381101561036757808201518184015260208101905061034c565b83811115610376576000848401525b50505050565b6000600282049050600182168061039457607f821691505b602082108114156103a8576103a76103df565b5b50919050565b6103b78261043d565b810181811067ffffffffffffffff821117156103d6576103d561040e565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f830116905091905056fea264697066735822122070d157c4efbb3fba4a1bde43cbba5b92b69f2fc455a650c0dfb61e9ed3d4bd6364736f6c634300080400330000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b696e697469616c5f6d7367000000000000000000000000000000000000000000', from: '0x81cb089c285e5ee3a7353704fb114955037443af', }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); + web3Mock + .onPost('contracts/call', { ...callData, estimate: true }) + .reply(501, { errorMessage: '', statusCode: 501 }); const gas = await ethImpl.estimateGas(callData, null); expect(gas).to.equal(numberTo0x(constants.TX_DEFAULT_GAS_DEFAULT)); @@ -107,7 +107,7 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { data: '0x608060405234801561001057600080fd5b506040516107893803806107898339818101604052810190610032919061015a565b806000908051906020019061004892919061004f565b50506102f6565b82805461005b90610224565b90600052602060002090601f01602090048101928261007d57600085556100c4565b82601f1061009657805160ff19168380011785556100c4565b828001600101855582156100c4579182015b828111156100c35782518255916020019190600101906100a8565b5b5090506100d191906100d5565b5090565b5b808211156100ee5760008160009055506001016100d6565b5090565b6000610105610100846101c0565b61019b565b90508281526020810184848401111561011d57600080fd5b6101288482856101f1565b509392505050565b600082601f83011261014157600080fd5b81516101518482602086016100f2565b91505092915050565b60006020828403121561016c57600080fd5b600082015167ffffffffffffffff81111561018657600080fd5b61019284828501610130565b91505092915050565b60006101a56101b6565b90506101b18282610256565b919050565b6000604051905090565b600067ffffffffffffffff8211156101db576101da6102b6565b5b6101e4826102e5565b9050602081019050919050565b60005b8381101561020f5780820151818401526020810190506101f4565b8381111561021e576000848401525b50505050565b6000600282049050600182168061023c57607f821691505b602082108114156102505761024f610287565b5b50919050565b61025f826102e5565b810181811067ffffffffffffffff8211171561027e5761027d6102b6565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b610484806103056000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063a41368621461003b578063cfae321714610057575b600080fd5b6100556004803603810190610050919061022c565b610075565b005b61005f61008f565b60405161006c91906102a6565b60405180910390f35b806000908051906020019061008b929190610121565b5050565b60606000805461009e9061037c565b80601f01602080910402602001604051908101604052809291908181526020018280546100ca9061037c565b80156101175780601f106100ec57610100808354040283529160200191610117565b820191906000526020600020905b8154815290600101906020018083116100fa57829003601f168201915b5050505050905090565b82805461012d9061037c565b90600052602060002090601f01602090048101928261014f5760008555610196565b82601f1061016857805160ff1916838001178555610196565b82800160010185558215610196579182015b8281111561019557825182559160200191906001019061017a565b5b5090506101a391906101a7565b5090565b5b808211156101c05760008160009055506001016101a8565b5090565b60006101d76101d2846102ed565b6102c8565b9050828152602081018484840111156101ef57600080fd5b6101fa84828561033a565b509392505050565b600082601f83011261021357600080fd5b81356102238482602086016101c4565b91505092915050565b60006020828403121561023e57600080fd5b600082013567ffffffffffffffff81111561025857600080fd5b61026484828501610202565b91505092915050565b60006102788261031e565b6102828185610329565b9350610292818560208601610349565b61029b8161043d565b840191505092915050565b600060208201905081810360008301526102c0818461026d565b905092915050565b60006102d26102e3565b90506102de82826103ae565b919050565b6000604051905090565b600067ffffffffffffffff8211156103085761030761040e565b5b6103118261043d565b9050602081019050919050565b600081519050919050565b600082825260208201905092915050565b82818337600083830152505050565b60005b8381101561036757808201518184015260208101905061034c565b83811115610376576000848401525b50505050565b6000600282049050600182168061039457607f821691505b602082108114156103a8576103a76103df565b5b50919050565b6103b78261043d565b810181811067ffffffffffffffff821117156103d6576103d561040e565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f830116905091905056fea264697066735822122070d157c4efbb3fba4a1bde43cbba5b92b69f2fc455a650c0dfb61e9ed3d4bd6364736f6c634300080400330000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b696e697469616c5f6d7367000000000000000000000000000000000000000000', from: '0x81cb089c285e5ee3a7353704fb114955037443af', }; - mockContractCall(callData, true, 200, { result: `0x61A80` }); + web3Mock.onPost('contracts/call', { ...callData, estimate: true }).reply(200, { result: `0x61A80` }); const gas = await ethImpl.estimateGas(callData, null); expect((gas as string).toLowerCase()).to.equal(numberTo0x(constants.TX_DEFAULT_GAS_DEFAULT).toLowerCase()); @@ -119,18 +119,13 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { from: '0x81cb089c285e5ee3a7353704fb114955037443af', value: 1, }; - mockContractCall(callData, true, 200, { result: `0x61A80` }); + web3Mock.onPost('contracts/call', { ...callData, estimate: true }).reply(200, { result: `0x61A80` }); const gas = await ethImpl.estimateGas({ ...callData, value: ONE_TINYBAR_IN_WEI_HEX }, null); expect((gas as string).toLowerCase()).to.equal(numberTo0x(constants.TX_DEFAULT_GAS_DEFAULT).toLowerCase()); }); it('should eth_estimateGas contract call returns default', async function () { - const callData = { - data: '0x01', - }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); - const gas = await ethImpl.estimateGas({ data: '0x01' }, null); expect(gas).to.equal(numberTo0x(constants.TX_DEFAULT_GAS_DEFAULT)); }); @@ -142,7 +137,10 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { to: RECEIVER_ADDRESS, value: '0x2540BE400', }; - mockContractCall({ ...callData, value: 1 }, true, 501, { errorMessage: '', statusCode: 501 }); + web3Mock + .onPost('contracts/call', { ...callData, estimate: true }) + .reply(501, { errorMessage: '', statusCode: 501 }); + restMock.onGet(`accounts/${RECEIVER_ADDRESS}${NO_TRANSACTIONS}`).reply(200, { address: RECEIVER_ADDRESS }); const gas = await ethImpl.estimateGas(callData, null); @@ -155,7 +153,9 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { from: '0x81cb089c285e5ee3a7353704fb114955037443af', to: RECEIVER_ADDRESS, }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); + web3Mock + .onPost('contracts/call', { ...callData, estimate: true }) + .reply(501, { errorMessage: '', statusCode: 501 }); restMock.onGet(`accounts/${RECEIVER_ADDRESS}${NO_TRANSACTIONS}`).reply(200, { address: RECEIVER_ADDRESS }); const result = await ethImpl.estimateGas(callData, null); @@ -165,11 +165,6 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { }); it('should eth_estimateGas transfer to existing account', async function () { - const callData = { - to: RECEIVER_ADDRESS, - value: 10, //in tinybars - }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); restMock.onGet(`accounts/${RECEIVER_ADDRESS}${NO_TRANSACTIONS}`).reply(200, { address: RECEIVER_ADDRESS }); const gas = await ethImpl.estimateGas( @@ -183,11 +178,6 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { }); it('should eth_estimateGas transfer to existing cached account', async function () { - const callData = { - to: RECEIVER_ADDRESS, - value: 10, //in tinybars - }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); restMock.onGet(`accounts/${RECEIVER_ADDRESS}${NO_TRANSACTIONS}`).reply(200, { address: RECEIVER_ADDRESS }); const gasBeforeCache = await ethImpl.estimateGas( @@ -212,11 +202,6 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { }); it('should eth_estimateGas transfer to non existing account', async function () { - const callData = { - to: RECEIVER_ADDRESS, - value: 10, //in tinybars - }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); restMock.onGet(`accounts/${RECEIVER_ADDRESS}${NO_TRANSACTIONS}`).reply(404); const hollowAccountGasCreation = await ethImpl.estimateGas( @@ -231,11 +216,6 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { }); it('should eth_estimateGas transfer with 0 value', async function () { - const callData = { - to: RECEIVER_ADDRESS, - value: 0, //in tinybars - }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); const result = await ethImpl.estimateGas( { to: RECEIVER_ADDRESS, @@ -268,11 +248,6 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { }); it('should eth_estimateGas transfer with invalid value', async function () { - const callData = { - to: RECEIVER_ADDRESS, - value: null, //in tinybars - }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); const result = await ethImpl.estimateGas( { to: RECEIVER_ADDRESS, @@ -290,59 +265,31 @@ describe('@ethEstimateGas Estimate Gas spec', async function () { }); it('should eth_estimateGas empty call returns transfer cost', async function () { - const callData = {}; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); - const gas = await ethImpl.estimateGas({}, null); expect(gas).to.equal(numberTo0x(constants.TX_DEFAULT_GAS_DEFAULT)); }); it('should eth_estimateGas empty call returns transfer cost with overridden default gas', async function () { - const callData = {}; - mockContractCall(callData, true, 200, { result: numberTo0x(defaultGasOverride) }); - const gas = await ethImplOverridden.estimateGas({}, null); expect(gas).to.equal(numberTo0x(defaultGasOverride)); }); it('should eth_estimateGas empty input transfer cost', async function () { - const callData = { - data: '', - }; - web3Mock - .onPost('contracts/call', { ...callData, estimate: true }) - .reply(501, { errorMessage: '', statusCode: 501 }); - const gas = await ethImpl.estimateGas({ data: '' }, null); expect(gas).to.equal(numberTo0x(constants.TX_DEFAULT_GAS_DEFAULT)); }); it('should eth_estimateGas empty input transfer cost with overridden default gas', async function () { - const callData = { - data: '', - }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); - const gas = await ethImplOverridden.estimateGas({ data: '' }, null); expect(gas).to.equal(numberTo0x(defaultGasOverride)); }); it('should eth_estimateGas zero input returns transfer cost', async function () { - const callData = { - data: '0x', - }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); - const gas = await ethImpl.estimateGas({ data: '0x' }, null); expect(gas).to.equal(numberTo0x(constants.TX_DEFAULT_GAS_DEFAULT)); }); it('should eth_estimateGas zero input returns transfer cost with overridden default gas', async function () { - const callData = { - data: '0x0', - }; - mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }); - const gas = await ethImplOverridden.estimateGas({ data: '0x' }, null); expect(gas).to.equal(numberTo0x(defaultGasOverride)); }); diff --git a/packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts b/packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts index e8dd08c2b7..19ceb180ca 100644 --- a/packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts +++ b/packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts @@ -114,17 +114,6 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () { registry, cacheService, ); - restMock.onGet('network/fees').reply(200, DEFAULT_NETWORK_FEES); - restMock.onGet(`accounts/${defaultContractResults.results[0].from}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultContractResults.results[1].from}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultContractResults.results[0].to}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultContractResults.results[1].to}?transactions=false`).reply(200); - restMock.onGet(`contracts/${defaultContractResults.results[0].from}`).reply(404, NOT_FOUND_RES); - restMock.onGet(`contracts/${defaultContractResults.results[1].from}`).reply(404, NOT_FOUND_RES); - restMock.onGet(`contracts/${defaultContractResults.results[0].to}`).reply(200); - restMock.onGet(`contracts/${defaultContractResults.results[1].to}`).reply(200); - restMock.onGet(`tokens/${defaultContractResults.results[0].contract_id}`).reply(200); - restMock.onGet(`tokens/${defaultContractResults.results[1].contract_id}`).reply(200); }); this.afterEach(() => { @@ -354,7 +343,6 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () { }); describe('eth_getBlockByNumber with tag', async function () { - const TOTAL_GET_CALLS_EXECUTED = 12; function confirmResult(result: Block | null) { expect(result).to.exist; expect(result).to.not.be.null; @@ -365,7 +353,6 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () { } this.beforeEach(() => { - restMock.resetHistory(); restMock.onGet(CONTRACT_RESULTS_LOGS_WITH_FILTER_URL).reply(200, DEFAULT_ETH_GET_BLOCK_BY_LOGS); for (const result of defaultContractResults.results) { restMock.onGet(`contracts/${result.to}/results/${result.timestamp}`).reply(404, NOT_FOUND_RES); @@ -377,7 +364,7 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () { it('eth_getBlockByNumber with latest tag', async function () { const result = await ethImpl.getBlockByNumber('latest', false); // check that we only made the expected number of requests with the expected urls - expect(restMock.history.get.length).equal(TOTAL_GET_CALLS_EXECUTED); + expect(restMock.history.get.length).equal(4); expect(restMock.history.get[0].url).equal(BLOCKS_LIMIT_ORDER_URL); expect(restMock.history.get[1].url).equal( 'contracts/results?timestamp=gte:1651560386.060890949×tamp=lte:1651560389.060890949&limit=100&order=asc', @@ -385,7 +372,7 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () { expect(restMock.history.get[2].url).equal( 'contracts/results/logs?timestamp=gte:1651560386.060890949×tamp=lte:1651560389.060890949&limit=100&order=asc', ); - expect(restMock.history.get[TOTAL_GET_CALLS_EXECUTED - 1].url).equal('network/fees'); + expect(restMock.history.get[3].url).equal('network/fees'); confirmResult(result); }); @@ -412,7 +399,7 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () { it('eth_getBlockByNumber with finalized tag', async function () { const result = await ethImpl.getBlockByNumber('finalized', false); // check that we only made the expected number of requests with the expected urls - expect(restMock.history.get.length).equal(TOTAL_GET_CALLS_EXECUTED); + expect(restMock.history.get.length).equal(4); expect(restMock.history.get[0].url).equal(BLOCKS_LIMIT_ORDER_URL); expect(restMock.history.get[1].url).equal( 'contracts/results?timestamp=gte:1651560386.060890949×tamp=lte:1651560389.060890949&limit=100&order=asc', @@ -420,14 +407,14 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () { expect(restMock.history.get[2].url).equal( 'contracts/results/logs?timestamp=gte:1651560386.060890949×tamp=lte:1651560389.060890949&limit=100&order=asc', ); - expect(restMock.history.get[TOTAL_GET_CALLS_EXECUTED - 1].url).equal('network/fees'); + expect(restMock.history.get[3].url).equal('network/fees'); confirmResult(result); }); it('eth_getBlockByNumber with safe tag', async function () { - const result = await ethImpl.getBlockByNumber('safe', false); + const result = await ethImpl.getBlockByNumber('finalized', false); // check that we only made the expected number of requests with the expected urls - expect(restMock.history.get.length).equal(TOTAL_GET_CALLS_EXECUTED); + expect(restMock.history.get.length).equal(4); expect(restMock.history.get[0].url).equal(BLOCKS_LIMIT_ORDER_URL); expect(restMock.history.get[1].url).equal( 'contracts/results?timestamp=gte:1651560386.060890949×tamp=lte:1651560389.060890949&limit=100&order=asc', @@ -435,7 +422,7 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () { expect(restMock.history.get[2].url).equal( 'contracts/results/logs?timestamp=gte:1651560386.060890949×tamp=lte:1651560389.060890949&limit=100&order=asc', ); - expect(restMock.history.get[TOTAL_GET_CALLS_EXECUTED - 1].url).equal('network/fees'); + expect(restMock.history.get[3].url).equal('network/fees'); confirmResult(result); }); diff --git a/packages/relay/tests/lib/eth/eth_getTransactionByBlockHashAndIndex.spec.ts b/packages/relay/tests/lib/eth/eth_getTransactionByBlockHashAndIndex.spec.ts index 1f62909d56..4ca121e6dc 100644 --- a/packages/relay/tests/lib/eth/eth_getTransactionByBlockHashAndIndex.spec.ts +++ b/packages/relay/tests/lib/eth/eth_getTransactionByBlockHashAndIndex.spec.ts @@ -41,9 +41,6 @@ import { DEFAULT_NETWORK_FEES, EMPTY_RES, NOT_FOUND_RES, - ACCOUNT_ADDRESS_1, - CONTRACT_ADDRESS_2, - CONTRACT_ID_2, } from './eth-config'; import { contractResultsByHashByIndexURL, generateEthTestEnv } from './eth-helpers'; @@ -65,7 +62,7 @@ function verifyAggregatedInfo(result: Transaction | null) { describe('@ethGetTransactionByBlockHashAndIndex using MirrorNode', async function () { this.timeout(10000); - let { restMock, web3Mock, hapiServiceInstance, ethImpl, cacheService } = generateEthTestEnv(); + let { restMock, hapiServiceInstance, ethImpl, cacheService } = generateEthTestEnv(); this.beforeEach(() => { // reset cache and restMock @@ -75,16 +72,6 @@ describe('@ethGetTransactionByBlockHashAndIndex using MirrorNode', async functio sdkClientStub = sinon.createStubInstance(SDKClient); getSdkClientStub = sinon.stub(hapiServiceInstance, 'getSDKClient').returns(sdkClientStub); restMock.onGet('network/fees').reply(200, DEFAULT_NETWORK_FEES); - restMock.onGet(`accounts/${defaultContractResults.results[0].from}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultContractResults.results[1].from}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultContractResults.results[0].to}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultContractResults.results[1].to}?transactions=false`).reply(200); - restMock.onGet(`contracts/${defaultContractResults.results[0].from}`).reply(404, NOT_FOUND_RES); - restMock.onGet(`contracts/${defaultContractResults.results[1].from}`).reply(404, NOT_FOUND_RES); - restMock.onGet(`contracts/${defaultContractResults.results[0].to}`).reply(200); - restMock.onGet(`contracts/${defaultContractResults.results[1].to}`).reply(200); - restMock.onGet(`tokens/${defaultContractResults.results[0].contract_id}`).reply(200); - restMock.onGet(`tokens/${defaultContractResults.results[1].contract_id}`).reply(200); }); this.afterEach(() => { diff --git a/packages/relay/tests/lib/eth/eth_getTransactionByBlockNumberAndIndex.spec.ts b/packages/relay/tests/lib/eth/eth_getTransactionByBlockNumberAndIndex.spec.ts index 1d12b676ef..8fd953bf5f 100644 --- a/packages/relay/tests/lib/eth/eth_getTransactionByBlockNumberAndIndex.spec.ts +++ b/packages/relay/tests/lib/eth/eth_getTransactionByBlockNumberAndIndex.spec.ts @@ -40,7 +40,6 @@ import { DEFAULT_BLOCKS_RES, DEFAULT_NETWORK_FEES, NO_SUCH_CONTRACT_RESULT, - NOT_FOUND_RES, } from './eth-config'; import { contractResultsByNumberByIndexURL, generateEthTestEnv } from './eth-helpers'; @@ -74,16 +73,6 @@ describe('@ethGetTransactionByBlockNumberAndIndex using MirrorNode', async funct sdkClientStub = sinon.createStubInstance(SDKClient); getSdkClientStub = sinon.stub(hapiServiceInstance, 'getSDKClient').returns(sdkClientStub); restMock.onGet('network/fees').reply(200, DEFAULT_NETWORK_FEES); - restMock.onGet(`accounts/${defaultContractResults.results[0].from}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultContractResults.results[1].from}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultContractResults.results[0].to}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultContractResults.results[1].to}?transactions=false`).reply(200); - restMock.onGet(`contracts/${defaultContractResults.results[0].from}`).reply(404, NOT_FOUND_RES); - restMock.onGet(`contracts/${defaultContractResults.results[1].from}`).reply(404, NOT_FOUND_RES); - restMock.onGet(`contracts/${defaultContractResults.results[0].to}`).reply(200); - restMock.onGet(`contracts/${defaultContractResults.results[1].to}`).reply(200); - restMock.onGet(`tokens/${defaultContractResults.results[0].contract_id}`).reply(200); - restMock.onGet(`tokens/${defaultContractResults.results[1].contract_id}`).reply(200); }); this.afterEach(() => { diff --git a/packages/relay/tests/lib/eth/eth_getTransactionReceipt.spec.ts b/packages/relay/tests/lib/eth/eth_getTransactionReceipt.spec.ts index fc7897361c..b8ec623552 100644 --- a/packages/relay/tests/lib/eth/eth_getTransactionReceipt.spec.ts +++ b/packages/relay/tests/lib/eth/eth_getTransactionReceipt.spec.ts @@ -161,14 +161,6 @@ describe('@ethGetTransactionReceipt eth_getTransactionReceipt tests', async func }); it('valid receipt on match', async function () { - restMock.onGet(`accounts/${defaultDetailedContractResultByHash.from}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultDetailedContractResultByHash.from}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultDetailedContractResultByHash.to}?transactions=false`).reply(200); - restMock.onGet(`accounts/${defaultDetailedContractResultByHash.to}?transactions=false`).reply(200); - restMock.onGet(`contracts/${defaultDetailedContractResultByHash.to}`).reply(200); - restMock.onGet(`contracts/${defaultDetailedContractResultByHash.to}`).reply(200); - restMock.onGet(`tokens/${defaultDetailedContractResultByHash.contract_id}`).reply(200); - restMock.onGet(`tokens/${defaultDetailedContractResultByHash.contract_id}`).reply(200); // mirror node request mocks restMock.onGet(`contracts/results/${defaultTxHash}`).reply(200, defaultDetailedContractResultByHash); restMock.onGet(`contracts/${defaultDetailedContractResultByHash.created_contract_ids[0]}`).reply(404); diff --git a/packages/relay/tests/lib/ethGetBlockBy.spec.ts b/packages/relay/tests/lib/ethGetBlockBy.spec.ts index 5966c4c745..4f11933529 100644 --- a/packages/relay/tests/lib/ethGetBlockBy.spec.ts +++ b/packages/relay/tests/lib/ethGetBlockBy.spec.ts @@ -21,8 +21,7 @@ import path from 'path'; import dotenv from 'dotenv'; import MockAdapter from 'axios-mock-adapter'; -import { expect, use } from 'chai'; -import chaiAsPromised from 'chai-as-promised'; +import { expect } from 'chai'; import { Registry } from 'prom-client'; dotenv.config({ path: path.resolve(__dirname, '../test.env') }); import { EthImpl } from '../../src/lib/eth'; @@ -36,10 +35,8 @@ import { Log, Transaction } from '../../src/lib/model'; import { nullableNumberTo0x, numberTo0x, nanOrNumberTo0x, toHash32 } from '../../../../packages/relay/src/formatters'; import { CacheService } from '../../src/lib/services/cacheService/cacheService'; import * as sinon from 'sinon'; -import { RedisInMemoryServer } from '../redisInMemoryServer'; -import { SinonSpy } from 'sinon'; -use(chaiAsPromised); +const LRU = require('lru-cache'); const logger = pino(); const registry = new Registry(); @@ -48,7 +45,6 @@ let restMock: MockAdapter; let mirrorNodeInstance: MirrorNodeClient; let hapiServiceInstance: HAPIService; let cacheService: CacheService; -let redisInMemoryServer: RedisInMemoryServer; let mirrorNodeCache; const blockHashTrimmed = '0x3c08bbbee74d287b1dcd3f0ca6d1d2cb92c90883c4acf9747de9f3f3162ad25b'; @@ -266,19 +262,8 @@ describe('eth_getBlockBy', async function () { this.timeout(10000); let ethImpl: EthImpl; const sandbox = sinon.createSandbox(); - let multiSetSpy: SinonSpy< - [keyValuePairs: Record, callingMethod: string, requestIdPrefix?: string], - Promise | void - >; - - this.beforeAll(async () => { - //done in order to be able to use cache - process.env.TEST = 'false'; - process.env.REDIS_ENABLED = 'true'; - process.env.MULTI_SET = 'true'; - redisInMemoryServer = new RedisInMemoryServer(logger.child({ name: `in-memory redis server` }), 5031); - await redisInMemoryServer.start(); - process.env.REDIS_URL = 'redis://127.0.0.1:5031'; + + this.beforeAll(() => { cacheService = new CacheService(logger.child({ name: `cache` }), registry); // @ts-ignore @@ -312,20 +297,12 @@ describe('eth_getBlockBy', async function () { cacheService.clear(); restMock.reset(); sandbox.spy(cacheService, 'set'); - multiSetSpy = sandbox.spy(cacheService, 'multiSet'); }); afterEach(function () { sandbox.restore(); }); - this.afterAll(async () => { - process.env.REDIS_ENABLED = 'false'; - process.env.MULTI_SET = 'false'; - await cacheService.disconnectRedisClient(); - await redisInMemoryServer.stop(); - }); - const mirrorLogToModelLog = (mirrorLog) => { const log = new Log({ address: mirrorLog.address, @@ -474,74 +451,30 @@ describe('eth_getBlockBy', async function () { } } - async function checkForSyntheticLogsInSharedCache() { - const syntheticLog1 = await cacheService.getAsync(cacheKeySyntheticLog1, '', ''); - const syntheticLog2 = await cacheService.getAsync(cacheKeySyntheticLog2, '', ''); - const syntheticLog3 = await cacheService.getAsync(cacheKeySyntheticLog3, '', ''); - - expect(syntheticLog1).to.be.null; - expect(syntheticLog2).to.be.null; - expect(syntheticLog3).to.be.null; - } - it('filterAndPopulateSyntheticContractResults showDetails=false sets cache', async function () { - checkForSyntheticLogsInSharedCache(); - - const expectedKeyValuePairs = { - [`${constants.CACHE_KEY.SYNTHETIC_LOG_TRANSACTION_HASH}${modelLog1.transactionHash}`]: modelLog1, - [`${constants.CACHE_KEY.SYNTHETIC_LOG_TRANSACTION_HASH}${modelLog2.transactionHash}`]: modelLog2, - [`${constants.CACHE_KEY.SYNTHETIC_LOG_TRANSACTION_HASH}${modelLog3.transactionHash}`]: modelLog3, - }; + expect(cacheService.get(cacheKeySyntheticLog1, '', '')).to.be.null; + expect(cacheService.get(cacheKeySyntheticLog2, '', '')).to.be.null; + expect(cacheService.get(cacheKeySyntheticLog3, '', '')).to.be.null; ethImpl.filterAndPopulateSyntheticContractResults(false, referenceLogs, [], '1'); - await expect(cacheService.getAsync(cacheKeySyntheticLog1, '', '')).to.eventually.be.fulfilled.and.satisfy( - (object) => { - return JSON.stringify(object) === JSON.stringify(modelLog1); - }, - ); - await expect(cacheService.getAsync(cacheKeySyntheticLog2, '', '')).to.eventually.be.fulfilled.and.satisfy( - (object) => { - return JSON.stringify(object) === JSON.stringify(modelLog2); - }, - ); - await expect(cacheService.getAsync(cacheKeySyntheticLog3, '', '')).to.eventually.be.fulfilled.and.satisfy( - (object) => { - return JSON.stringify(object) === JSON.stringify(modelLog3); - }, - ); - expect(multiSetSpy.callCount).to.equal(1); - expect(JSON.stringify(multiSetSpy.getCall(0).args[0])).to.equal(JSON.stringify(expectedKeyValuePairs)); + expect(cacheService.get(cacheKeySyntheticLog1, '', '')).to.be.equal(modelLog1); + expect(cacheService.get(cacheKeySyntheticLog2, '', '')).to.be.equal(modelLog2); + expect(cacheService.get(cacheKeySyntheticLog3, '', '')).to.be.equal(modelLog3); + verifySharedCacheWasUsed(); }); it('filterAndPopulateSyntheticContractResults showDetails=true sets cache', async function () { - checkForSyntheticLogsInSharedCache(); - - const expectedKeyValuePairs = { - [`${constants.CACHE_KEY.SYNTHETIC_LOG_TRANSACTION_HASH}${modelLog1.transactionHash}`]: modelLog1, - [`${constants.CACHE_KEY.SYNTHETIC_LOG_TRANSACTION_HASH}${modelLog2.transactionHash}`]: modelLog2, - [`${constants.CACHE_KEY.SYNTHETIC_LOG_TRANSACTION_HASH}${modelLog3.transactionHash}`]: modelLog3, - }; + expect(cacheService.get(cacheKeySyntheticLog1, '', '')).to.be.null; + expect(cacheService.get(cacheKeySyntheticLog2, '', '')).to.be.null; + expect(cacheService.get(cacheKeySyntheticLog3, '', '')).to.be.null; ethImpl.filterAndPopulateSyntheticContractResults(true, referenceLogs, [], '1'); - await expect(cacheService.getAsync(cacheKeySyntheticLog1, '', '')).to.eventually.be.fulfilled.and.satisfy( - (object) => { - return JSON.stringify(object) === JSON.stringify(modelLog1); - }, - ); - await expect(cacheService.getAsync(cacheKeySyntheticLog2, '', '')).to.eventually.be.fulfilled.and.satisfy( - (object) => { - return JSON.stringify(object) === JSON.stringify(modelLog2); - }, - ); - await expect(cacheService.getAsync(cacheKeySyntheticLog3, '', '')).to.eventually.be.fulfilled.and.satisfy( - (object) => { - return JSON.stringify(object) === JSON.stringify(modelLog3); - }, - ); - expect(multiSetSpy.callCount).to.equal(1); - expect(JSON.stringify(multiSetSpy.getCall(0).args[0])).to.equal(JSON.stringify(expectedKeyValuePairs)); + expect(cacheService.get(cacheKeySyntheticLog1, '', '')).to.be.equal(modelLog1); + expect(cacheService.get(cacheKeySyntheticLog2, '', '')).to.be.equal(modelLog2); + expect(cacheService.get(cacheKeySyntheticLog3, '', '')).to.be.equal(modelLog3); + verifySharedCacheWasUsed(); }); }); }); diff --git a/packages/relay/tests/lib/openrpc.spec.ts b/packages/relay/tests/lib/openrpc.spec.ts index 6c7965f1fe..64f800c9a9 100644 --- a/packages/relay/tests/lib/openrpc.spec.ts +++ b/packages/relay/tests/lib/openrpc.spec.ts @@ -66,7 +66,6 @@ import { getRequestId, signedTransactionHash, } from '../helpers'; -import { NOT_FOUND_RES } from './eth/eth-config'; import ClientService from '../../src/lib/services/hapiService/hapiService'; import HbarLimit from '../../src/lib/hbarlimiter'; import { numberTo0x } from '../../../../packages/relay/src/formatters'; @@ -201,16 +200,6 @@ describe('Open RPC Specification', function () { sdkClientStub.getContractByteCode.returns(Buffer.from(bytecode.replace('0x', ''), 'hex')); sdkClientStub.getAccountInfo.returns({ ethereumNonce: '0x1' }); sdkClientStub.submitEthereumTransaction.returns({}); - mock.onGet(`accounts/${defaultContractResults.results[0].from}?transactions=false`).reply(200); - mock.onGet(`accounts/${defaultContractResults.results[1].from}?transactions=false`).reply(200); - mock.onGet(`accounts/${defaultContractResults.results[0].to}?transactions=false`).reply(200); - mock.onGet(`accounts/${defaultContractResults.results[1].to}?transactions=false`).reply(200); - mock.onGet(`contracts/${defaultContractResults.results[0].from}`).reply(404, NOT_FOUND_RES); - mock.onGet(`contracts/${defaultContractResults.results[1].from}`).reply(404, NOT_FOUND_RES); - mock.onGet(`contracts/${defaultContractResults.results[0].to}`).reply(200); - mock.onGet(`contracts/${defaultContractResults.results[1].to}`).reply(200); - mock.onGet(`tokens/${defaultContractResults.results[0].contract_id}`).reply(200); - mock.onGet(`tokens/${defaultContractResults.results[1].contract_id}`).reply(200); }); const validateResponseSchema = (schema: any, response: any) => { diff --git a/packages/relay/tests/lib/sdkClient.spec.ts b/packages/relay/tests/lib/sdkClient.spec.ts index 34b83e08d1..ba5175321b 100644 --- a/packages/relay/tests/lib/sdkClient.spec.ts +++ b/packages/relay/tests/lib/sdkClient.spec.ts @@ -174,4 +174,56 @@ describe('SdkClient', async function () { sinon.assert.calledOnce(convertGasPriceToTinyBarsStub); }); }); + + describe('deleteFile', () => { + // states + const gasPrice = '0xad78ebc5ac620000'; + const callerName = 'eth_sendRawTransaction'; + const requestId = getRequestId(); + const transaction = { + type: 1, + value: 0, + chainId: 0x12a, + gasPrice, + gasLimit: MAX_GAS_LIMIT_HEX, + data: '0x' + '00'.repeat(5121), // large contract + }; + + before(() => { + // mock captureMetrics + sinon.stub(sdkClient, 'captureMetrics').callsFake(() => {}); + }); + + it('should execute deleteFile', async () => { + // prepare fileId + const signedTx = await signTransaction(transaction); + const transactionBuffer = Buffer.from(signedTx.substring(2), 'hex'); + const ethereumTransactionData: EthereumTransactionData = EthereumTransactionData.fromBytes(transactionBuffer); + const fileId = await sdkClient.createFile(ethereumTransactionData.callData, client, requestId, callerName, ''); + + const fileInfoPreDelete = await new FileInfoQuery().setFileId(fileId).execute(client); + expect(fileInfoPreDelete.fileId).to.deep.eq(fileId); + expect(fileInfoPreDelete.isDeleted).to.be.false; + expect(fileInfoPreDelete.size.toNumber()).to.not.eq(0); + + // delete a file + await sdkClient.deleteFile(client, fileId, requestId, callerName, ''); + const fileInfoPostDelete = await new FileInfoQuery().setFileId(fileId).execute(client); + expect(fileInfoPostDelete.fileId).to.deep.eq(fileId); + expect(fileInfoPostDelete.isDeleted).to.be.true; + expect(fileInfoPostDelete.size.toNumber()).to.eq(0); + }); + + it('should print a `warn` log when delete file with invalid fileId', async () => { + // random fileId + const fileId = new FileId(0, 0, 369); + + // spy on warn logs + const warnLoggerStub = sinon.stub(sdkClient.logger, 'warn'); + + // delete a file + await sdkClient.deleteFile(client, fileId, requestId, callerName, ''); + expect(warnLoggerStub.calledWithMatch('ENTITY_NOT_ALLOWED_TO_DELETE')).to.be.true; + }); + }); }); diff --git a/packages/relay/tests/lib/subscriptionController.spec.ts b/packages/relay/tests/lib/subscriptionController.spec.ts index 78d2880986..809c0fc643 100644 --- a/packages/relay/tests/lib/subscriptionController.spec.ts +++ b/packages/relay/tests/lib/subscriptionController.spec.ts @@ -107,8 +107,6 @@ describe('subscriptionController', async function () { expect(spy.getCall(0).args[0]).to.be.eq(`{"event":"logs"}`); expect(subId).to.be.length(34); - - subscriptionController.unsubscribe(wsConnection, subId); }); it('notifySubscribers should notify subscribers with data', async function () { @@ -121,10 +119,8 @@ describe('subscriptionController', async function () { subscriptionController.notifySubscribers(`{"event":"logs"}`, testData); expect(spy.getCall(0).args[0]).to.be.eq( - `{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"${testData}","subscription":"${subId}"}}`, + `{"method":"eth_subscription","params":{"result":"${testData}","subscription":"${subId}"}}`, ); - - subscriptionController.unsubscribe(wsConnection, subId); }); it('notifySubscribers should notify multiple subscribers with data', async function () { @@ -141,13 +137,11 @@ describe('subscriptionController', async function () { subscriptionController.notifySubscribers(`{"event":"logs"}`, testData); expect(spy1.getCall(0).args[0]).to.be.eq( - `{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"${testData}","subscription":"${subId1}"}}`, + `{"method":"eth_subscription","params":{"result":"${testData}","subscription":"${subId1}"}}`, ); expect(spy2.getCall(0).args[0]).to.be.eq( - `{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"${testData}","subscription":"${subId2}"}}`, + `{"method":"eth_subscription","params":{"result":"${testData}","subscription":"${subId2}"}}`, ); - subscriptionController.unsubscribe(wsConnection1, subId1); - subscriptionController.unsubscribe(wsConnection2, subId2); }); it('notifySubscribers should use cache to not send the data again', async function () { @@ -162,16 +156,15 @@ describe('subscriptionController', async function () { subscriptionController.notifySubscribers(`{"event":"logs"}`, testData); // should hit cache expect(spy.getCall(0).args[0]).to.be.eq( - `{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"${testData}","subscription":"${subId}"}}`, + `{"method":"eth_subscription","params":{"result":"${testData}","subscription":"${subId}"}}`, ); expect(spy.callCount).to.be.eq(1); // even after making 3 calls, only 1 time spy reports being called on send method - subscriptionController.unsubscribe(wsConnection, subId); }); it('notifySubscribers using a Tag that has no subscribers should not send anything to connection', async function () { const connectionId = '5'; const wsConnection = new MockWsConnection(connectionId); - const subId = subscriptionController.subscribe(wsConnection, 'logs'); + subscriptionController.subscribe(wsConnection, 'logs'); const spy = sandbox.spy(wsConnection, 'send'); const testData = 'test example data cached'; @@ -181,7 +174,6 @@ describe('subscriptionController', async function () { ); expect(spy.callCount).to.be.eq(0); - subscriptionController.unsubscribe(wsConnection, subId); }); it('Unsubscribing all subscriptions from same connection', async function () { @@ -260,7 +252,5 @@ describe('subscriptionController', async function () { const subId2 = subscriptionController.subscribe(wsConnection, tag1.event); expect(subId).to.be.eq(subId2); - subscriptionController.unsubscribe(wsConnection, subId); - subscriptionController.unsubscribe(wsConnection, subId2); }); }); diff --git a/packages/relay/tests/redisInMemoryServer.ts b/packages/relay/tests/redisInMemoryServer.ts deleted file mode 100644 index 01f5b3996e..0000000000 --- a/packages/relay/tests/redisInMemoryServer.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { RedisMemoryServer } from 'redis-memory-server'; -import { Logger } from 'pino'; -import { RedisInstanceDataT } from 'redis-memory-server/lib/RedisMemoryServer'; - -export class RedisInMemoryServer { - /** - * The instance of the in memory Redis server - * - * @private - */ - private inMemoryRedisServer: RedisMemoryServer; - - /** - * The logger used for logging all output from this class. - * @private - */ - private logger: Logger; - - /** - * The host of the in memory server. - * @private - */ - private host: string; - - /** - * The port of the in memory server. - * @private - */ - private port: number; - - /** - * The desired port to run on. - * @private - */ - private portToRunOn: number; - - constructor(logger: Logger, portToRunOn: number) { - this.logger = logger; - this.portToRunOn = portToRunOn; - } - - async start(): Promise { - this.inMemoryRedisServer = new RedisMemoryServer({ - instance: { - port: this.portToRunOn, - }, - }); - - this.port = await this.inMemoryRedisServer.getPort(); - this.host = await this.inMemoryRedisServer.getHost(); - } - - async getPort(): Promise { - return this.port; - } - - async getHost(): Promise { - return this.host; - } - - getInstanceInfo(): false | RedisInstanceDataT { - return this.inMemoryRedisServer.getInstanceInfo(); - } - - async stop(): Promise { - this.logger.info('Stopping Redis in-memory server....'); - const stopped = await this.inMemoryRedisServer.stop(); - if (stopped) { - this.logger.info('Stopped Redis in-memory server sucessfully.'); - } else { - this.logger.info('Couldnt stop Redis in-memory server sucessfully.'); - } - } -} diff --git a/packages/relay/tests/test.env b/packages/relay/tests/test.env index 8d047aa2df..5f33d2f7be 100755 --- a/packages/relay/tests/test.env +++ b/packages/relay/tests/test.env @@ -1,7 +1,7 @@ CHAIN_ID=0x12a MIRROR_NODE_URL=http://localhost:5551 MIRROR_NODE_URL_WEB3=http://127.0.0.1:8545 -REDIS_ENABLED=false +REDIS_ENABLED=true REDIS_URL=redis://127.0.0.1:6379 MIRROR_NODE_LIMIT_PARAM = 100 HEDERA_NETWORK={"127.0.0.1:50211":"0.0.3"} diff --git a/packages/relay/tsconfig.json b/packages/relay/tsconfig.json index 22cd79da81..3a4f9e6df1 100644 --- a/packages/relay/tsconfig.json +++ b/packages/relay/tsconfig.json @@ -14,8 +14,7 @@ "forceConsistentCasingInFileNames": true, "noImplicitAny": false, "declaration": true, - "strict": true, - "sourceMap": true + "strict": true }, "include": [ "src" diff --git a/packages/server/tsconfig.json b/packages/server/tsconfig.json index 22cd79da81..3a4f9e6df1 100644 --- a/packages/server/tsconfig.json +++ b/packages/server/tsconfig.json @@ -14,8 +14,7 @@ "forceConsistentCasingInFileNames": true, "noImplicitAny": false, "declaration": true, - "strict": true, - "sourceMap": true + "strict": true }, "include": [ "src"