masa-finance / masa-oracle

Masa Oracle: Decentralized Data Protocol 🌐
https://developers.masa.ai/docs/masa-protocol/welcome
MIT License
24 stars 19 forks source link

chore(cleanup): Remove the AppConfig and KeyManager singletons #625

Closed mcamou closed 1 week ago

mcamou commented 2 weeks ago

Description

Singletons are a bad practice which makes it difficult to write proper tests for the code. This PR (almost) removes the two singletons we have:

We remove both singletons in one go since it is very complicated to remove just AppConfig without removing KeyManager. They are replaced either with functional options, by adding some fields to other objects (i.e. OracleNode) or, in cases where there are just one or config parameter needed in one place in the code, passing them directly as parameters.

This PR removes config.GetInstance() from everywhere except the Sentiment-related files, since those will be removed as part of a separate PR (see #626).

Notes to reviewers

If the full PR is a bit much, the commit history should be more manageable. If preferred, I could split this into multiple PRs.

Signed commits

codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 0.55866% with 178 lines in your changes missing coverage. Please review.

Project coverage is 8.92%. Comparing base (b5d1120) to head (d97c7a4). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/llmbridge/sentiment.go 0.00% 52 Missing :warning:
pkg/masacrypto/key_manager.go 0.00% 18 Missing :warning:
cmd/masa-node/config.go 0.00% 17 Missing :warning:
node/options.go 0.00% 16 Missing :warning:
cmd/masa-node/main.go 0.00% 9 Missing :warning:
node/oracle_node.go 0.00% 8 Missing :warning:
pkg/workers/options.go 0.00% 8 Missing :warning:
pkg/workers/handlers/llm.go 0.00% 6 Missing :warning:
cmd/masa-node/staking.go 0.00% 5 Missing :warning:
pkg/llmbridge/client.go 0.00% 5 Missing :warning:
... and 15 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #625 +/- ## ======================================== - Coverage 8.99% 8.92% -0.07% ======================================== Files 99 99 Lines 7761 7809 +48 ======================================== - Hits 698 697 -1 - Misses 6989 7039 +50 + Partials 74 73 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.