Skip to content

currencyrate: propagate http errors to currencyrate rpc if a source is provided#9182

Merged
daywalker90 merged 1 commit into
ElementsProject:masterfrom
daywalker90:currencyrate-mock-liveapis
Jun 10, 2026
Merged

currencyrate: propagate http errors to currencyrate rpc if a source is provided#9182
daywalker90 merged 1 commit into
ElementsProject:masterfrom
daywalker90:currencyrate-mock-liveapis

Conversation

@daywalker90

@daywalker90 daywalker90 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

specifically coindesk was constantly hitting API rate limits causing our tests to fail
so lets unit tests all endpoints with a snapshot of real responses and only allow for http
error 429 in integration tests

Also fix a flake in test_bkpr_currencyrate_persisted that would pick up a cached rate from CLN's own caching

@daywalker90 daywalker90 force-pushed the currencyrate-mock-liveapis branch from b38af23 to ee1dae8 Compare June 1, 2026 10:08
@madelinevibes madelinevibes added this to the v26.09 milestone Jun 4, 2026
@madelinevibes madelinevibes added the Status::Ready for Review The work has been completed and is now awaiting evaluation or approval. label Jun 4, 2026
@madelinevibes madelinevibes requested a review from nGoline June 4, 2026 11:16
@nGoline

nGoline commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

I believe this level of mocking would fit a Unit Test better than an Integration Test. This error helps us tell, like you said:

If the actual API's change, break, or vanish...

Wouldn't it be better to catch and propagate the error back to the test? This way we would know it's a HTTP 429 Too Many Requests and safely disregard that one provider, whilst still testing the integration between all the moving parts for this test.

@daywalker90 daywalker90 force-pushed the currencyrate-mock-liveapis branch from ee1dae8 to e0dfd18 Compare June 8, 2026 11:11
@daywalker90 daywalker90 changed the title tests: mock all currencyrate endpoints tests: replace real currencyrate endpoints with unit tests and http error code checks Jun 8, 2026
@daywalker90

Copy link
Copy Markdown
Collaborator Author

I've reworked the PR to propagate http errors and replaced the mocked tests with unit tests. The integration tests now only error on errors that are not http errors.

@daywalker90 daywalker90 force-pushed the currencyrate-mock-liveapis branch 4 times, most recently from 7fee023 to a7d62ea Compare June 9, 2026 08:49
@daywalker90

Copy link
Copy Markdown
Collaborator Author

test_bkpr_currencyrate_persisted was flaky locally. CLN's caches the rate by looking up the last rate and allow for a 60s old rates to be used without lookup. What i don't understand is why the test would sometimes pass.

@daywalker90

daywalker90 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

Wouldn't it be better to catch and propagate the error back to the test? This way we would know it's a HTTP 429 Too Many Requests and safely disregard that one provider, whilst still testing the integration between all the moving parts for this test.

So cln-currencyrate always uses all sources since almost all commands are interested in them except for currencyrate and only if you provide an optional source argument which was added later on. I can't error all the commands just because one source failed, no one wants that. So to detect failures i opted for a higher log level that would make the tests fail, but currencyrate is used whenever bkpr-currency is enabled, which it is in a bunch of other tests in test_bookkeeper.py. So i'm restructuring cln-currencyrate a bit to let currencyrate report that error.

@daywalker90 daywalker90 force-pushed the currencyrate-mock-liveapis branch from a7d62ea to 25ee534 Compare June 9, 2026 11:51
@daywalker90 daywalker90 changed the title tests: replace real currencyrate endpoints with unit tests and http error code checks @daywalker90 currencyrate: propagate http errors to currencyrate rpc if a source is provided Jun 9, 2026
@daywalker90 daywalker90 changed the title @daywalker90 currencyrate: propagate http errors to currencyrate rpc if a source is provided currencyrate: propagate http errors to currencyrate rpc if a source is provided Jun 9, 2026
@daywalker90 daywalker90 force-pushed the currencyrate-mock-liveapis branch 2 times, most recently from a9f9e1a to 40fe657 Compare June 9, 2026 12:33

@nGoline nGoline left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good, just a few comments...

Comment thread plugins/currencyrate-plugin/src/oracle.rs
Comment thread plugins/currencyrate-plugin/src/oracle.rs Outdated
Comment thread plugins/currencyrate-plugin/src/oracle.rs Outdated
Comment thread tests/test_currencyrate.py
Comment thread plugins/currencyrate-plugin/src/oracle.rs
@daywalker90 daywalker90 force-pushed the currencyrate-mock-liveapis branch from 40fe657 to 6ef3620 Compare June 10, 2026 09:50
…s provided

specifically coindesk was constantly hitting API rate limits causing our tests to fail
so lets unit tests all endpoints with a snapshot of real responses and only allow for http
error 401/429 in integration tests

Also fix a flake in test_bkpr_currencyrate_persisted that would pick up a cached rate from CLN's own caching

Changelog-None
@daywalker90 daywalker90 force-pushed the currencyrate-mock-liveapis branch from 6ef3620 to b960a6a Compare June 10, 2026 10:40
@daywalker90

Copy link
Copy Markdown
Collaborator Author

Ugh now coindesk responded with HTTP error 401 Unauthorized API key required instead of 429. I added 401 to allowed errors as well. It's not that they actually require a API key, it works with my IP without it, but it is just their new way to say: API limit reached...

@nGoline nGoline left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@daywalker90 daywalker90 merged commit 9770077 into ElementsProject:master Jun 10, 2026
54 of 64 checks passed
@daywalker90 daywalker90 deleted the currencyrate-mock-liveapis branch June 10, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status::Ready for Review The work has been completed and is now awaiting evaluation or approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants