hashgraph / hedera-json-rpc-relay

Implementation of Ethereum JSON-RPC APIs for Hedera
Apache License 2.0
48 stars 62 forks source link

test: add helper method for overriding env variables #3022

Open victor-yanev opened 1 week ago

victor-yanev commented 1 week ago

Description:

In the current setup, there is no straightforward way to temporarily override environment variables for the duration of a test suite. This can lead to issues where tests inadvertently affect each other due to shared environment settings, making it difficult to isolate and reproduce test failures.

Additionally, in many tests environment variables are overridden without being reverted, propagating this behavior to other tests and making the tests dependent on their order and leading to chain-failures in cases where only one of the tests actually fails.

Changes:

This PR adds new helper methods overrideEnvs and withOverriddenEnvs which provide a mechanism to temporarily set environment variables for the duration of a test or a group of tests.

ℹ️ These methods ensure that the original environment settings are restored after the tests have run, maintaining the integrity of the global environment.

Related issue(s):

Fixes #3029

Checklist

github-actions[bot] commented 1 week ago

Acceptance Tests

  18 files  246 suites   30m 53s :stopwatch: 602 tests 595 :heavy_check_mark: 4 :zzz: 3 :x: 660 runs  653 :heavy_check_mark: 4 :zzz: 3 :x:

Results for commit 62cda738.

:recycle: This comment has been updated with latest results.

github-actions[bot] commented 1 week ago

Tests

       3 files     369 suites   18s :stopwatch: 1 361 tests 1 360 :heavy_check_mark: 1 :zzz: 0 :x: 1 370 runs  1 369 :heavy_check_mark: 1 :zzz: 0 :x:

Results for commit 62cda738.

:recycle: This comment has been updated with latest results.

sonarcloud[bot] commented 5 days ago

Quality Gate Failed Quality Gate failed

Failed conditions
10.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

codecov[bot] commented 5 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 82.71%. Comparing base (a3615c5) to head (62cda73).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #3022 +/- ## ========================================== - Coverage 84.91% 82.71% -2.21% ========================================== Files 58 63 +5 Lines 3905 4183 +278 Branches 784 837 +53 ========================================== + Hits 3316 3460 +144 - Misses 348 456 +108 - Partials 241 267 +26 ``` | [Flag](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3022/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | Coverage Δ | | |---|---|---| | [](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | `51.01% <ø> (?)` | | | [relay](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | `85.11% <ø> (ø)` | | | [server](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | `83.05% <ø> (ø)` | | | [ws-server](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | `33.91% <ø> (-63.96%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3022?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | Coverage Δ | | |---|---|---| | [.../lib/services/ethService/ethFilterService/index.ts](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3022?src=pr&el=tree&filepath=packages%2Frelay%2Fsrc%2Flib%2Fservices%2FethService%2FethFilterService%2Findex.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph#diff-cGFja2FnZXMvcmVsYXkvc3JjL2xpYi9zZXJ2aWNlcy9ldGhTZXJ2aWNlL2V0aEZpbHRlclNlcnZpY2UvaW5kZXgudHM=) | `82.50% <ø> (ø)` | | ... and [14 files with indirect coverage changes](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3022/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph)