Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Test fetching indexer config from registry #976

Merged
merged 5 commits into from
Aug 5, 2024

Conversation

morgsmccauley
Copy link
Collaborator

Added tests for fetching individual indexer config from registry contract. This was mostly an exercise to understand the behaviour of parsing registry contract responses, as well as understanding the changes that were made recently. A thin wrapper (JsonRpcClientWrapper) has been created to allow mocking of the JSON RPC Client responses.

@morgsmccauley morgsmccauley requested a review from a team as a code owner August 4, 2024 22:35
@@ -196,32 +233,105 @@ impl RegistryImpl {
.context("Failed to fetch indexer")?;

if let QueryResponseKind::CallResult(call_result) = response.kind {
// Handle case where call returns successfully but returns null due to not matching
let raw_json: Value = serde_json::from_slice(&call_result.result)
Copy link
Collaborator Author

@morgsmccauley morgsmccauley Aug 4, 2024

Choose a reason for hiding this comment

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

I don't understand why this should be needed. If the returned response is set to null, either intentionally from the registry contract, or through some error in the RPC, parsing to an Option will handle it correctly. Added relevant tests to prove this.

@darunrs can you please provide some context here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

So the idea here was that the call has two successful responses, which are null and some indexer data. There's also edge cases where the call is successful but either incorrectly returns null, or incorrectly returns some invalid data. So, given that, I wanted to handle null and actual data separately. The reason is, if I do from_slice::Option<T> on something, the case where the returned data is null, and the case where the returned data is incorrect JSON, get combined. In both cases, we return Option. And as a result, we never have a change to log the invalid JSON or handle it in anyway. Which I think we should do, as returning incorrect JSON from a successful call to RPC is anomalous, and shouldn't happen in a perfect world. If this kind of thing causes more problems, we can at least know we have logs of the invalid JSON. We can't do much about correct/incorrect null responses though, so I still have it return None. But I changed some logic elsewhere to expect a non-Null where it makes sense.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Except based on the tests you added, it seems the parse failure does in fact still trigger the parse error. Which is odd, as my testing showed it didn't. Maybe I did something wrong in it. Anyway, you added a unit test which covers the case of successfully returning invalid JSON anyway. And it correctly threw an error. So, we should be good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My understanding is that serde should only ever succeed if the JSON is valid. So for an Option, that would either be null or a JSON object which matches the target type. I even tried parsing "" which still resulted in an error.

It seems the error we faced recently might be somewhere else 🤔

@morgsmccauley morgsmccauley merged commit 510b3fb into main Aug 5, 2024
4 checks passed
@morgsmccauley morgsmccauley deleted the test/registry-fetch branch August 5, 2024 21:11
@darunrs darunrs mentioned this pull request Aug 6, 2024
@morgsmccauley morgsmccauley linked an issue Aug 7, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unit tests for Coordinator
2 participants