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

Add subscription ID recognition to tungstenite and ws-rpc client #662

Merged
merged 21 commits into from
Nov 9, 2023

Conversation

haerdib
Copy link
Contributor

@haerdib haerdib commented Nov 3, 2023

Updates the ws-rpc and tungstenite clients with the following features:

  • Removal of the warning message "Expected subscription, but received an ID response instead: Object"
  • The immediate subscription response (either the subscription ID or an error) is now interpreted by the client. All the following subscription messages are checked by the client if the ID matches, and only then are forwarded to the client. This now removes the need to ignore the "id" response that previously generated the responses, and does not allow mix-up of different subscription messages.
  • adds tests to the CI to test the following three cases:
    • Failed onchain extrinsic (Extrinsic went through successfully, only the Events indicate a failure of the xt)
    • Failed extrinsic before block submission (E.g. no subscription ID is returned but an immediate error response)
    • Successful extrinsic

closes #626

@haerdib haerdib self-assigned this Nov 3, 2023
@haerdib haerdib added F2-bug Something isn't working E1-breaksnothing labels Nov 3, 2023
@haerdib haerdib requested a review from masapr November 6, 2023 12:21
@haerdib haerdib marked this pull request as ready for review November 6, 2023 12:21
@haerdib haerdib changed the title Add subscirption id probing to tungstenite and ws rpc client Add subscription ID recognition to tungstenite and ws-rpc client Nov 6, 2023
Copy link
Collaborator

@masapr masapr left a comment

Choose a reason for hiding this comment

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

Just one comment. But overall looks good to me.

@@ -134,9 +134,25 @@ fn subscribe_to_server(
// Subscribe to server
socket.send(Message::Text(json_req))?;

// Read the first message response - must be the subscription id.
let msg = read_until_text_message(&mut socket)?;
let value: Value = serde_json::from_str(&msg)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I understand, all the following logic is analyzing a string. I would put this logic into its own function and write a test for each flow through. Then you know, that it's doing what you expect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, unit testing does make sense here. But not just here, but also in the ws_client and other functions of this client. Would you agree to do that in a separate issue and PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add tests for new logic from this PR in this PR. For adding tests to existing code, I would create a new issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added issue: #663, commit adding unit tests for changed code is incoming.

@haerdib haerdib requested a review from masapr November 8, 2023 17:36
src/rpc/helpers.rs Show resolved Hide resolved
@haerdib haerdib merged commit be3e1f7 into master Nov 9, 2023
43 checks passed
@haerdib haerdib deleted the bh/fix-error-tungstenite-ws-client branch November 9, 2023 08:34
haerdib added a commit that referenced this pull request Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E1-breaksnothing F2-bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Warning Expected subscription, but received an id response instead
2 participants