Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Fix event handling - Closes #4208 #4211

Merged
merged 8 commits into from
Sep 6, 2019
Merged

Conversation

shuse2
Copy link
Collaborator

@shuse2 shuse2 commented Sep 5, 2019

What was the problem?

  • network:event was subscribed, but it shouldn't throw an error

How did I solve it?

  • wrap with try-catch, and expect the error to happen. Also, it should log.

How to manually test it?

  • Use P2P library and call the endpoint with invalid data

Review checklist

@shuse2 shuse2 requested review from lsilvs and ManuGowda September 5, 2019 14:56
@shuse2 shuse2 self-assigned this Sep 5, 2019
@shuse2 shuse2 requested review from ishantiw and removed request for lsilvs September 5, 2019 15:32
return;
}
} catch (error) {
this.logger.info(
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the log level of this error be debug or error?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can remove data to be logged as it clutters up the logs if someone constantly sends malformed data

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought error will be too much since it's handled properly, but user should know about those event.
Maybe info is too low on this case, so i increased it to warn

if (event === 'postBlock') {
await this.transport.postBlock(data);
return;
}
Copy link
Contributor

@ManuGowda ManuGowda Sep 6, 2019

Choose a reason for hiding this comment

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

Nit: return at the end instead of returning each condition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should be fine, but I think in this case it's bit more clear it doesn't go to other cases

Copy link

Choose a reason for hiding this comment

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

I agree with @ManuGowda. Using else if + 1 single return is cleaner.

framework/src/modules/chain/transport/transport.js Outdated Show resolved Hide resolved
if (event === 'postBlock') {
await this.transport.postBlock(data);
return;
}
Copy link

Choose a reason for hiding this comment

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

I agree with @ManuGowda. Using else if + 1 single return is cleaner.

@@ -32,7 +32,7 @@ describe('WS transport', () => {
let p2p;

function postTransaction(transactionToPost) {
p2p.send({
return p2p.send({
Copy link

Choose a reason for hiding this comment

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

Do we really need this return? I actually don't like the structure of the entire describe. I suggest to clean it:

  • Its beforeEach is misleading
  • Remove the use of done.
  • The inner describe block is not necessary
  • I would remove postTransaction() to ease the understanding of every test or move it to a more general handler. If you don't agree, we should follow this pattern later on and do the same thing when sending.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This PR is not intended to refactor the test.
All of the functional tests will be recovered in jest, so not needed to rewrite for this patch imo

@shuse2 shuse2 merged commit ca5f946 into hotfix/2.3.3 Sep 6, 2019
@shuse2 shuse2 deleted the 4208-fix_event_handling branch September 6, 2019 13:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants